def compile_model(model, params, learning_rate, gradient_clip_norm):
  """Compile keras model."""
  model.compile(
      optimizer=_get_optimizer(
          learning_rate=learning_rate, gradient_clip_norm=gradient_clip_norm),
      loss=losses.GlobalSoftmax(),
      metrics=_get_metrics(params['eval_top_k']))
def build_keras_model(params):
    """Construct and compile recommendation keras model."""
    model = recommendation_model.RecommendationModel(params)
    model.compile(optimizer=_get_optimizer(
        learning_rate=FLAGS.learning_rate,
        gradient_clip_norm=FLAGS.gradient_clip_norm),
                  loss=losses.GlobalSoftmax(),
                  metrics=_get_metrics(params['eval_top_k']))
    return model
Esempio n. 3
0
 def test_global_softmax_loss(self):
     global_softmax = keras_losses.GlobalSoftmax()
     true_label = tf.constant([[2], [0], [1]], dtype=tf.int32)
     logits = tf.constant(
         [[0.8, 0.1, 0.2, 0.3], [0.2, 0.7, 0.1, 0.5], [0.5, 0.4, 0.9, 0.2]],
         dtype=tf.float32)
     self.assertBetween(
         global_softmax.call(y_true=true_label, y_pred=logits).numpy(), 1.5,
         1.6)