EasyDeepLearn

Write the basic contrastive loss and when it's used.

medium

Answer

  • L  =  y    d2  +  (1y)    max(margin    d,  0)2L\; = \;y\; \cdot \;d^{2}\; + \;(1 - y)\; \cdot \;\operatorname{max}(\mathrm{margin}\; - \;d, \;0)^{2}, where y=1 for a positive pair (same class) and y=0 for a negative pair, d is a distance in the embedding space.
  • Pulls positives together, pushes negatives apart at least by a margin.
  • Used in Siamese nets, verification (faces, signatures), and metric learning.
  • Modern SSL uses info-NCE (below) instead.
Check yourself — multiple choice
  • Only cross-entropy
  • Pull positives together, push negatives apart by a margin — Siamese / metric learning basis
  • Same as MSE
  • Only for images

Contrastive loss: attract positives, repel negatives past a margin.

#losses#contrastive#self-supervised

Practise Deep Learning

214 interview questions in this topic.

Related questions