Blogs / How a Language Model Picks the Next Token

How a Language Model Picks the Next Token

What a Hugging Face post says about how a language model selects the next token, what greedy search does and why other strategies are used.

  • Learning
  • 1 min read

For: Learners who know what a language model is.

How the next token is chosen

Generating text with language models often involves selecting the next token based on a distribution of probabilities.[1]

What greedy search does

A straightforward approach like greedy search selects the most probable token, but this can result in generic or repetitive outputs.[1]

A distribution ofprobabilitiesover the next tokenGreedy searchselects the most probabletoken, which can be genericor repetitiveBeam search, nucleusand top-k samplingadd diversity and controlsimplest:refined by
How is the next token chosen?

Why other strategies are used

To add diversity and control, more advanced decoding strategies, such as beam search, nucleus sampling, and top-k sampling, are widely used.[1]

Sources

  1. Controlling Language Model Generation with LogitsProcessorZoo (huggingface.co · checked )

More articles