3b7c410840e6e8cb54e9290494acde04d2942c18,pyannote/audio/embedding/approaches/triplet_loss.py,TripletLoss,loss,#TripletLoss#Any#Any#,142

Before Change



                    // do not use += because autograd does not support it
                    loss = loss + self.triplet_loss_(fX[anchor, :],
                                                     fX[positive, :],
                                                     fX[negative, :])
                    n_comparisons = n_comparisons + 1

After Change


        loss = 0.
        n_comparisons = 0

        distance = self.metric_(fX)

        // consider every embedding as anchor
        for anchor, y_anchor in enumerate(y):

            // consider every other embedding with the same label as positive
            for positive, y_positive in enumerate(y):

                // if same embedding or different labels, skip
                if (anchor == positive) or (y_anchor != y_positive):
                    continue

                for negative, y_negative in enumerate(y):

                    // if same label, skip
                    if y_negative == y_positive:
                        continue

                    loss_ = distance[anchor, positive] - \
                            distance[anchor, negative] + \
                            self.margin * self.metric_max_

                    if self.clamp == "positive":
                        loss_ = ag_np.maximum(loss_, 0.)

                    elif self.clamp == "sigmoid":
                        loss_ = 1. / (1. + ag_np.exp(-loss_))

                    // do not use += because autograd does not support it
                    loss = loss + loss_

                    n_comparisons = n_comparisons + 1

        return loss / n_comparisons
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 6

Instances


Project Name: pyannote/pyannote-audio
Commit Name: 3b7c410840e6e8cb54e9290494acde04d2942c18
Time: 2017-05-03
Author: bredin@limsi.fr
File Name: pyannote/audio/embedding/approaches/triplet_loss.py
Class Name: TripletLoss
Method Name: loss


Project Name: interactiveaudiolab/nussl
Commit Name: 4f5bee81eeb9cecb9d040cb4436dd7f07e06b965
Time: 2020-03-22
Author: prem@u.northwestern.edu
File Name: nussl/separation/primitive/melodia.py
Class Name: Melodia
Method Name: create_harmonic_mask


Project Name: scipy/scipy
Commit Name: 9c735a23b2ebc40233c787ee706b007b63503a26
Time: 2020-03-31
Author: pete.mahler.larsen@gmail.com
File Name: scipy/spatial/_spherical_voronoi.py
Class Name: SphericalVoronoi
Method Name: _handle_geodesic_input