DevPrep

All topics › AI fundamentals for developers

How an LLM generates text: tokens, attention, temperature

Middle PRO

Essence

An LLM generates text one token at a time. At each step the model looks at all the preceding text, computes a probability for every token in its vocabulary and picks one. The chosen token is appended, and the loop repeats. There is no explicit "answer plan": a long coherent answer is the result of thousands of such steps.

tokens → embeddings → [attention → MLP] × N layers → logits → probabilities → pick a token
                                                                                  ↓
                                                                append to the input and repeat

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store