techtree / Transformer

Next-token prediction and sampling

Turn the last vector into a score per token, softmax, and pick one.

51 seconds

probabilities=softmax(WxlastT)\text{probabilities} = \text{softmax}\left( \frac{W \mathbf{x}_{\text{last}}}{T} \right)
Transcript

After the last block, take the vector at the last position. Multiply it by one more matrix, with one row for every token in the vocabulary. Often this is the embedding table itself, reused.

Out comes one score for every token. Softmax turns the scores into probabilities: how likely each token is to come next.

Now pick one. Always taking the top one is called greedy. Or draw at random, following the probabilities. That is sampling.

A setting called temperature divides the scores first. Low temperature makes the top token more likely. High temperature spreads the chances out.

The chosen token is added to the end of the text, and the whole model runs again, for the token after that.

One token at a time, that is how the text gets written.