Write the basic contrastive loss and when it's used.
mediumAnswer
- , 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
- Write info-NCE / NT-Xent and its role in SSL.
- What is triplet loss and its main challenge?
- Why compute softmax + cross-entropy jointly via log-sum-exp?
- How should the output head be designed for a regression task with a strictly positive target?
- How is the output head different for multi-label vs multi-class classification?
- What is label smoothing and why does it help?