Notes

Length Normalization (Decoding)

Ask a beam search for the best translation and it hands back something suspiciously terse. The reason is arithmetic, not taste: a sequence's score is a sum of log probabilities, every one of them negative, so each extra word makes the total worse. Length normalization is the correction that stops short sequences winning by default.

Dividing by the length
The fix is to score a candidate by its average log probability instead of its total — divide by the token count, or by the length raised to an exponent alpha between 0 and 1 to choose how much of the penalty survives. Alpha of 0 leaves the raw sum, alpha of 1 is a plain mean, and the GNMT formulation most systems inherit sits around 0.6 with a softened denominator. Hugging Face exposes the same knob as length_penalty, applied when beam candidates are ranked against each other.

What changes

  • Beam search stops collapsing onto truncated output — the classic symptom of a wider beam producing worse translations.
  • Candidates of different lengths become comparable, which matters because finished and unfinished hypotheses are ranked together.
  • Push the penalty too far and the output rambles: now length itself is rewarded.

Why it matters
This is one line of arithmetic sitting between a competent model and output a reader will accept, and it is a decoding-time choice — no retraining, no change to the weights. Translation and summarisation feel it most: BLEU and ROUGE both punish dropped content, so a system that quietly prefers brevity loses score with no visible defect to debug.

Length normalization divides a candidate sequence's log-probability score by its length, or by its length raised to a tuning exponent, so longer outputs are not penalised merely for having more negative terms to sum. Without it beam search systematically prefers truncated sequences, and widening the beam makes the bias worse. It is a decoding-time adjustment, decisive wherever hypotheses of different lengths are ranked together, as in translation and summarisation.

Imagine judging recipes by adding up a small penalty for every ingredient. The shortest recipe would always win, however badly it cooked. Text-generating software has the same quirk: it scores a sentence by adding a cost for each word, so longer sentences look worse automatically.

Length normalization fixes that by judging a sentence on its average cost per word instead of the total. The practical effect is translations and summaries that actually finish the thought, rather than stopping early because something short happened to score well. There is a dial for it, too — turned too far the other way, the writing starts to waffle.