Answers.Body: <p>These are not the same loss, but are often confused because many people use the term contrastive to refer to the triplet loss.</p>
  <ul>
  <li>Contrastive Loss is defined in the paper &quot;Dimensionality Reduction by Learning an Invariant Mapping&quot; (<a href="http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf" rel="nofollow noreferrer">link</a>) and works with similarity labels to learn a distance mapping.</li>
  <li>Triplet Loss is defined in the paper &quot;FaceNet: A Unified Embedding for Face Recognition and Clustering&quot; (<a href="https://arxiv.org/abs/1503.03832" rel="nofollow noreferrer">link</a>) and this is where the triplet concept appears, with a anchor and negative/positive samples defined with respect to the anchor. This is a form of contrastive learning, but its not the same as the contrastive loss.</li>
  </ul>
  <p>Many papers mistakenly confuse the Triplet loss with the Contrastive loss, and they are not the same.</p>
  <p>Note that these solve different problems, if you have known similarity relationships, then the Contrastive loss is appropriate, if you have negative/positive relationships (like for face recognition where people's identity is the anchor), then you should use the Triplet loss.</p>
  <p>Both of these losses can be used to train a siamese neural network, but mostly they are used for embedding learning.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-24T21:58:25.477Z
Answers.LastActivityDate: 2022-06-24T21:58:25.477Z
Answers.UserDisplayName: Dr. Snoopy
Body: <p>What is the difference between the <strong>triplet loss</strong> and the <strong>contrastive loss</strong>?</p>
  <p>They look same to me. I don't understand the nuances between the two. I have the following queries:</p>
  <ul>
  <li>When to use what?</li>
  <li>What are the use cases and advantages or disadvantages of the two?</li>
  <li>Also, how do they fit with the siamese network discussion?</li>
  </ul>
  
Tags: <comparison><objective-functions><siamese-neural-network><contrastive-learning><triplet-loss-function>
Title: What is the difference between the triplet loss and the contrastive loss?
UserDisplayName: Exploring
ThreadText: # What is the difference between the triplet loss and the contrastive loss?
  
  (Asked by: username_0 on 2022-06-18)
  
  What is the difference between the **triplet loss** and the **contrastive loss**?
  
  They look same to me. I don't understand the nuances between the two. I have the following queries:
  
  * When to use what?
  * What are the use cases and advantages or disadvantages of the two?
  * Also, how do they fit with the siamese network discussion?
  
  **Tags:** comparison, objective-functions, siamese-neural-network, contrastive-learning, triplet-loss-function
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-06-24. Score: 3
  
  These are not the same loss, but are often confused because many people use the term contrastive to refer to the triplet loss.
  
  * Contrastive Loss is defined in the paper "Dimensionality Reduction by Learning an Invariant Mapping" ([link](http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf)) and works with similarity labels to learn a distance mapping.
  * Triplet Loss is defined in the paper "FaceNet: A Unified Embedding for Face Recognition and Clustering" ([link](https://arxiv.org/abs/1503.03832)) and this is where the triplet concept appears, with a anchor and negative/positive samples defined with respect to the anchor. This is a form of contrastive learning, but its not the same as the contrastive loss.
  
  Many papers mistakenly confuse the Triplet loss with the Contrastive loss, and they are not the same.
  
  Note that these solve different problems, if you have known similarity relationships, then the Contrastive loss is appropriate, if you have negative/positive relationships (like for face recognition where people's identity is the anchor), then you should use the Triplet loss.
  
  Both of these losses can be used to train a siamese neural network, but mostly they are used for embedding learning.
  
  
  ---
  
  