# Contrastive Loss
Contrastive loss can visually be seen below. The `query123` and `doc456` go together. So we want our model, the encoder, to encode them to vectors that are nearby (with respect to, say, cosine similarity). On the other hand, `query123` is not a match with `doc137`, so we want their encodings to be *far apart*.

A contrastive loss can be thought of as a kind of *electromagnetic force*: it will *pull some examples together* while *pushing others apart*. Yannic talks about this [here](https://youtu.be/qlB0TPBQ7YY?t=718).
---
Date: 20230605
Links to:
Tags:
References:
* [https://arxiv.org/pdf/2202.06991.pdf](https://arxiv.org/pdf/2202.06991.pdf)