Guide

Tokens and sampling

Tokens

Models don't read letters or whole words. They read tokens: common words are one token, and rarer words split into pieces. On average a token is about 3/4 of an English word, so 750 words is about 1,000 tokens. Prices, speed and length limits are all counted in tokens. Words the model has rarely seen, and many other languages, often need more tokens per word.

Vocabulary and token ids

A tokenizer swaps each token for a number, its token id. The ids come from a fixed list, the model's vocabulary, often 30,000 to 200,000 tokens. The model only sees the ids. Each model has its own tokenizer, so always use the one that came with it.

Logits and softmax

To choose the next token, the model gives every token in the vocabulary a raw score, a logit. Softmax turns the logits into probabilities: chances from 0 to 1 that add up to 1.

Greedy and temperature

Greedy decoding always takes the top token. It is steady, but can be dull or repeat itself. Temperature reshapes the chances first. Low temperature makes the top token even more likely; temperature 0 acts like greedy. High temperature evens the chances out, for more varied but riskier text.

Top-k, top-p and stopping

Sampling picks a token at random, weighted by its chance. To skip the long tail of unlikely tokens:

  • Top-k keeps the k most likely tokens, like 40.
  • Top-p keeps the fewest tokens whose chances add up to p, like 0.9.

An answer ends when the model writes a stop token, or when it hits the max tokens limit.

Remember

  • 1 token is about 3/4 of an English word.
  • The tokenizer turns tokens into ids; the model sees only ids.
  • Logits are scores; softmax turns them into chances that add up to 1.
  • Low temperature is safe; high temperature is varied.
  • Top-k and top-p cut unlikely tokens; a stop token or max tokens ends the answer.