Index Ai Academy
Glossary · Phase 5 · Transformers

Length normalization

Also written: length penalty

Dividing a sequence's log probability by its length, so that a search doesn't always prefer the shortest output.

The usual repair is in the last column: divide the score by the length. Per word, "I think that it works" is the best of the three, at −0.43. Real systems use this length normalization, often with a tunable penalty.

Try it now

Press Next three times. The lit boxes are what the beam keeps; the pale ones are thrown away.

Learn it properly

Beam search and constrained decoding · Why the likeliest word isn't the likeliest sentence, beam search with log probabilities, its taste for short and repetitive text, and forcing output into a grammar: what that guarantees and what it doesn't. About 40 minutes.

Other terms from the same lesson

  • beam search: A way of choosing a model's output that keeps the few best partial sequences at every step, where greedy decoding keeps only one.
  • constrained decoding: Blocking, at each step, every token that would break a required format, so that the output is certain to fit it.
Keep learning

More in plain English.

1286 terms in the glossary, each with the lesson that teaches it.

1286 terms

The glossary

Every word you'll meet in AI and machine learning, explained in everyday language.

Phase 5 · lesson 40 min

Beam search and constrained decoding

Why the likeliest word isn't the likeliest sentence, beam search with log probabilities, its taste for short and repetitive text, and forcing output into a grammar: what that guarantees and what it doesn't.

Never trained an AI? Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account. Teach it to write