← All questions
Training & Fine-tuningMedium· DPO· Contrastive Learning· Loss Functions

How is DPO related to contrastive learning?

The DPO loss function is closely related to InfoNCE and noise-contrastive estimation. It functions by increasing the log-likelihood of chosen completions relative to rejected ones, weighted by the model’s prediction error. The primary distinction is that while standard contrastive learning often uses random negative samples, DPO uses specific rejected completions provided in a preference dataset to define the contrastive target.

Code playground (Python)