diff --git a/easy_rec/python/model/esmm.py b/easy_rec/python/model/esmm.py index 50567ae63..a83e304a8 100644 --- a/easy_rec/python/model/esmm.py +++ b/easy_rec/python/model/esmm.py @@ -71,7 +71,7 @@ def build_loss_graph(self): tf.float32) cvr_losses = tf.keras.backend.binary_crossentropy( ctcvr_label, self._prediction_dict['probs_ctcvr']) - cvr_loss = tf.reduce_sum(cvr_losses, name='ctcvr_loss') + cvr_loss = tf.reduce_mean(cvr_losses, name='ctcvr_loss') # The weight defaults to 1. self._loss_dict['weighted_cross_entropy_loss_%s' % cvr_tower_name] = self._cvr_tower_cfg.weight * cvr_loss @@ -84,14 +84,15 @@ def build_loss_graph(self): cvr_loss = tf.losses.mean_squared_error( labels=ctcvr_label, predictions=self._prediction_dict['y_ctcvr'], - weights=self._sample_weight) + weights=self._sample_weight, + reduction=tf.losses.Reduction.MEAN) self._loss_dict['weighted_l2_loss_%s' % cvr_tower_name] = self._cvr_tower_cfg.weight * cvr_loss _labels = tf.cast(self._labels[ctr_label_name], tf.float32) _logits = self._prediction_dict['logits_%s' % ctr_tower_name] cross = tf.nn.sigmoid_cross_entropy_with_logits( labels=_labels, logits=_logits, name='ctr_loss') - ctr_loss = tf.reduce_sum(cross) + ctr_loss = tf.reduce_mean(cross) self._loss_dict['weighted_cross_entropy_loss_%s' % ctr_tower_name] = self._ctr_tower_cfg.weight * ctr_loss return self._loss_dict