liveBook · Manning

Triplet margin loss

As explained in LLM Evaluation and Alignment, The Foundational Ideas

Triplet margin loss trains representations by requiring a preferred example to be closer to an anchor than a less-preferred example by a specified margin.

Triplet margin loss trains a ranking model to distinguish translation quality relatively: a preferred candidate must lie closer to the source and reference than a less-preferred candidate by a margin ε. section 3.3.3

In a COMET-style ranking model, the procedure is:

  • Encode the source, reference, better candidate, and worse candidate into sentence embeddings. section 3.3.3
  • Reduce the distance from the better candidate to the source and reference while increasing the worse candidate’s distance. section 3.3.3
  • Use ε to enforce a meaningful separation rather than allowing embeddings to collapse together. section 3.3.3

Translation ranking

Given a better and worse translation for the same source and reference, the loss pushes the better translation toward both meanings and pushes the worse translation away. At inference, distances are combined with a harmonic mean and converted into a similarity score bounded between 0 and 1. section 3.3.3

Figure 3.14 Left. Estimator model architecture. The candidate, source, and reference are independently encoded using a pretrained cross-lingual encoder. The resulting embeddings are then passed through a pooling layer to create a sentence embedding for each segment. Finally, the resulting sentence embeddings are concatenated into a vector to be passed to a feed-forward regressor. Right. Ranking model architecture. It uses source, reference, a ‘better’ candidate, and a ‘worse’ candidate. They are encoded, pooled, and minimize triplet margin loss to minimize the distance between ‘better’ candidates and the ‘anchors’.

The architecture figure shows the four encoded inputs, pooling, and the ranking objective that brings better candidates closer to the anchors. section 3.3.3

How LLM Evaluation and Alignment, The Foundational Ideas covers it

How deep it goes
Explains inputs, distance directions, margin purpose, and inference scoring without deriving the loss equation.
Examples
Uses better and worse translation candidates evaluated against the same source and reference.
What it assumes
Assumes familiarity with embeddings, distances, and source-reference-candidate inputs.
What you can do after
Understand how relative-quality training separates preferred and less-preferred translation embeddings.
How it connects
Connects source and reference embeddings with ranking models, semantic distance, harmonic mean, and similarity scores.

Also explained in

Compare how 2 books explain triplet margin loss →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of LLM Evaluation and Alignment, The Foundational Ideas. The section links point to the parts of the book it draws on.