Skip to content
ML Academy

Introduced on day 38

Contrastive learning

Training an encoder so that an anchor is closer to its positive example than to negatives, using a softmax-style loss over similarities.

In detail

The loss for an anchor aa, positive pp and negatives njn_j is −log⁡es(a,p)/τes(a,p)/τ+∑jes(a,nj)/τ-\log \frac{e^{s(a,p)/\tau}}{e^{s(a,p)/\tau} + \sum_j e^{s(a,n_j)/\tau}} with temperature τ\tau. What counts as a positive (paraphrase, query-answer pair, augmented view) defines the geometry learned, and the quality of negatives matters as much as their number.