db4c8744b0c7fa95502e1172dd4c597e62e55b0e,tensorrec/loss_graphs.py,WMRBLossGraph,loss_graph,#WMRBLossGraph#Any#Any#Any#,97

Before Change



    def loss_graph(self, tf_prediction, tf_interactions, tf_sample_predictions, **kwargs):

        positive_interaction_mask = tf.greater(tf_interactions.values, 0.0)
        positive_interaction_indices = tf.boolean_mask(tf_interactions.indices,
                                                       positive_interaction_mask)
        positive_predictions = tf.gather_nd(tf_prediction, indices=positive_interaction_indices)

        n_sampled_items = tf.cast(tf.shape(tf_sample_predictions)[1], dtype=tf.float32)

        predictions_sum_per_user = tf.reduce_sum(tf_sample_predictions, axis=1)
        mapped_predictions_sum_per_user = tf.gather(params=predictions_sum_per_user,
                                                    indices=tf.transpose(positive_interaction_indices)[0])

        // TODO smart irrelevant item indicator -- using n_items is an approximation for sparse interactions
        irrelevant_item_indicator = n_sampled_items  // noqa

        sampled_margin_rank = (n_sampled_items - (n_sampled_items * positive_predictions)
                               + mapped_predictions_sum_per_user + irrelevant_item_indicator)

        // JKirk - I am leaving out the log term due to experimental results
        // loss = tf.log(sampled_margin_rank + 1.0)
        return sampled_margin_rank


class WMRBAlignmentLossGraph(WMRBLossGraph):
    

After Change


        tanh_prediction = tf.nn.sigmoid(tf_prediction)
        tanh_sample_prediction = tf.nn.sigmoid(tf_sample_predictions)

        return self.weighted_margin_rank_batch(tf_prediction=tanh_prediction,
                                               tf_interactions=tf_interactions,
                                               tf_sample_predictions=tanh_sample_prediction)

    @classmethod
    def weighted_margin_rank_batch(cls, tf_prediction, tf_interactions, tf_sample_predictions):
        positive_interaction_mask = tf.greater(tf_interactions.values, 0.0)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


Project Name: jfkirk/tensorrec
Commit Name: db4c8744b0c7fa95502e1172dd4c597e62e55b0e
Time: 2018-02-27
Author: james.f.kirk@gmail.com
File Name: tensorrec/loss_graphs.py
Class Name: WMRBLossGraph
Method Name: loss_graph


Project Name: tensorflow/ranking
Commit Name: d3f1a5ad4507e88b016e0a829f4ba142294c16e6
Time: 2019-11-12
Author: xuanhui@google.com
File Name: tensorflow_ranking/python/losses.py
Class Name: _SoftmaxLoss
Method Name: _precompute


Project Name: tensorflow/models
Commit Name: 5cee7220217599ceccb191adf430eb914d148f87
Time: 2020-09-17
Author: tanzheny@google.com
File Name: official/vision/keras_cv/ops/box_matcher.py
Class Name: BoxMatcher
Method Name: __call__