Vol. 15 · LLM Foundations
LLMs in Plain English
Not the history of architectures or GPU micro-optimizations, but practical mechanics without academic fog: how text is cut into tokens, how transformer blocks recalculate the meaning, how the encoder and decoder differ, how the model learns and why it responds one token at a time.
Big picture
If you take away all the marketing, there is a repetitive computational chain going on inside the LLM. The text is divided into tokens, the tokens are turned into vectors, the stack of transformer blocks recalculates these vectors many times, after which the model evaluates the probabilities from the dictionary and selects the next token.
Source-complete notesif you compress it into one phrase
texttext → tokens → ids → vectors → contextual vectors → next-token scores → chosen tokenThe model does not open internal Wikipedia and pull out a paragraph from it. Each time, it re-calculates which token now looks the most plausible, given all the current context and trained weights.
Source-complete notesstep by step · useful formulations
textSearch the database:
query → index → found document → show to user
LLM:
prompt → forward pass network → logits by dictionary → token
Important:
the model doesn't know the "correct paragraph"
the model knows "which continuation is similar to the truth"useful formulations
- the model estimates probabilities
- the model compresses language statistics into weights
- the model stores articles as files
The weight of a neural network is not a “cell with knowledge”, but a small numerical coefficient. The meaning is distributed among billions of such coefficients: somewhere the tendency to associate a pronoun with a noun is stored, somewhere a code pattern, somewhere statistics of facts and style.
Source-complete notestwo things follow from this
two things follow from this
- the model can generalize to new combinations
- the model can confidently mix similar patterns
How text becomes numbers
The model does not see “text” like a human. It receives tokens as input: sometimes they are whole words, sometimes parts of words, sometimes punctuation marks or spaces. Such a compromise is needed so that the dictionary is not endless and does not break up into too long chains of letters.
Source-complete notesminimal chain
text"Neural networks explain text"
→ tokenizer
→ [4811, 932, 18452, 77, 901]
→ then the network works only with numbersThe token with ID `4811` does not mean anything by itself. Therefore, its index is used to pull out a row from the large embeddings table. The result is a vector of hundreds or thousands of numbers, which the network can already process with linear algebra.
Source-complete noteswhat's literally happening
textvocab_size = 128000
d_model = 4096
Embedding matrix E ∈ R^[128000 × 4096]
token_id = 4811
vector = E[4811]
This is not a calculation "by meaning"
This is a lookup: we took a ready-made table rowIf you simply add up a set of tokens, phrases with different word orders will look the same. Therefore, position information is added to the model: which token is first, which is second, who is closer, who is further.
The starting embedding for a word is usually the same. But after several transformer blocks, the representation of the word changes under the influence of neighboring tokens. This is why the same word can mean different things in different sentences.
What it does Transformer Block do?
To understand a token, it's helpful to take a quick look at other important tokens. In a long phrase, the word at the end may depend on the word at the beginning. Attention provides a direct mechanism: not to drag the whole meaning through a narrow neck, but to immediately choose what to look at now.
Self-attention is not magic, but a way to mix information between positions. Each token creates three versions of itself: query, key and value. Query says “what am I looking for”, key says “how can I help”, value is “what information I convey if I am selected”.
Source-complete notesthe essence of the formula without unnecessary mathematics
sqlfor token i:
q_i = W_Q x_i
k_i = W_K x_i
v_i = W_V x_i
score(i, j) = q_i · k_j
weights(i, :) = softmax(scores)
new_x_i = Σ_j weights(i, j) v_j
That is, token i collects a weighted mixture of value from other tokensAttention answers the question “from whom to get information.” But after this, the model must still transform the already collected meaning. This is what MLP does: a small two-layer block that is applied separately to each position.
Source-complete notessimple MLP role
textattention:
“she” realized that she was connected with “Marina”
MLP:
reworked this context
enhanced beneficial symptoms
reduced the noise
prepared a presentation for the next block
Attention = gather connections
MLP = transform collectedTransformer is not just attention and MLP. Residual connections and normalization are also important. Residual allows each block not to break an already useful representation, but to neatly add an improvement on top of the old one. LayerNorm keeps numbers in a stable range.
Encoder, Decoder and Encoder-Decoder
The encoder model sees the entire input. Each token can look both left and right. Therefore, encoder is especially good where you need to understand the text, rather than continue it: classification, search, reranking, NER, feature extraction.
The decoder-only model also uses transformer blocks, but with a causal mask. The token at position `i` sees only what came before it. It is this limitation that makes generation possible: the model honestly predicts the next token without knowing the future answer.
In the encoder-decoder architecture, the two roles are separated. Encoder reads all the source text and builds a representation of it. The decoder generates a response one token at a time, but at each step it can look at the encoder outputs through cross-attention. This is useful for translating, summarizing and converting text from format A to format B.
Source-complete noteswhen it's especially appropriate
when it's especially appropriate
- translation
- summation
- structural text transformation
- for free chat today they often use decoder-only
How a model learns
The main task of the decoder-only model is simple: to guess the next token using the left context. During training, she is shown the correct text in its entirety and is forced to predict the next token at each position. This is called next-token prediction.
Source-complete noteswhat is being optimized
pythonfor each position:
logits → softmax → P(next token)
compare with the correct token
calculate loss
adjust the weights a little
repeat this on billions of examplesEncoder models are usually trained differently. They corrupt the input: they hide some of the tokens or distort the text, and then ask them to restore what they missed. To cope, the model is forced to look at the left and right context simultaneously and learn to "understand" well.
After each prediction, the model is compared with the correct answer. If the probability of the correct token was too small, you need to slightly adjust the weights that led to this. Backprop is a way to neatly propagate an error back throughout the network.
Source-complete noteswithout formal gravity
text1. the model predicted the probabilities
2. saw the correct token
3. got the error value
4. calculated which weights increased the error
5. moved them a little in the opposite direction
Training = billions of micro-weight shiftsHow the model responds
When a user sends a request, the model first runs the entire prompt through itself. At this step, it builds context states for all existing tokens. This is a preparatory pass before the first new token is generated.
Source-complete noteswhat's going on
sqlprompt = system + history + user_text
tokenize(prompt)
embed(prompt_tokens)
pass all tokens through all blocks
get hidden states for all positions
This is where the understanding of the context before the first word of the answer comes fromAfter the first new token, the model adds it to the context and repeats the calculation. Then another one. And one more thing. Hence the feeling of flow when streaming. On the outside it looks like printing text, but on the inside it's a cycle of "evaluate probabilities → select token → add to context."
At the output of the generation block, the model does not output a word directly. It produces a set of numbers throughout the dictionary. These numbers are called logits. After softmax they turn into probabilities. Temperature changes the “sharpness” of this distribution: low makes the choice more conservative, high adds variety.
Source-complete notespractical intuition
practical intuition
- low temperature: code, formal answers
- medium: normal chat
- high: creative, but more risk of noise
Limits and common sense
The model was trained to continue the text plausibly, not to verify the truth of each statement. Therefore, if the context is weak, the question is ambiguous, or similar patterns are mixed in the weights, it can confidently give a polished but incorrect answer.
Source-complete notestypical source of error
textlittle context
or
there are too many similar patterns
or
required fact rare / fresh / controversial
→ the model selects a statistically plausible continuation
→ not a verified factPrompt works as a temporary context. It can direct the model's attention, set the role, give examples and push towards the desired style. But it does not change the weights themselves. Once the request completes, this temporary context disappears unless you save them in the next context.
If you remove the noise of terms, the choice of architecture depends on the type of task. Need to understand the input? More often encoder. Do you need to freely continue the text? Decoder-only LLM. Do you need to convert one text to another with a strict binding to the input? Often encoder-decoder.
Source-complete notestable · practical conclusion
| Architecture | How he looks at the text | Strength | Typical tasks |
|---|---|---|---|
| Encoder-only | sees the entire input at once | understanding and comparison | classification, embeddings, reranking, NER |
| Decoder-only | only sees left context | free generation | chat, code, letters, brainstorming |
| Encoder-decoder | reads the entire input and writes the output step by step | transformation A→B | translation, summarization, structured generation |
practical conclusion
- not everything related to text needs to be solved by LLM
- narrow task + a lot of traffic = often more profitable than encoder
- free generation almost always gravitates towards decoder-only
No dead end
Keep moving through the map.
Continue in sequence, switch to a related guide, or return to the seven-track learning map.