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.

01

Big picture

3 cards
01OverviewComplete scheme: from user text to next token

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.

Diagramtext
SIMPLE PHYSICS ONE ANSWER

Text
  "Explain transformer in simple words"

  ↓ tokenizer

Tokens
  ["Explain", "transformer", "in simple", "words"]

  ↓ lookup in the embeddings table

Vectors
  e1, e2, e3, e4

  ↓ + position signals

Transformer blocks × N
  attention → MLP → attention → MLP → ...

  ↓ take the state of the last position

LM head
  logits over the entire dictionary

  ↓ softmax/sampling

Next token
  "."

  ↓ this token is added to the input

The cycle repeats
if you compress it into one phrasetext
text → tokens → ids → vectors → contextual vectors → next-token scores → chosen token
step by steptext
Search 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
Diagramsql
WHAT DO WEIGHTS STORE?

Not so:
  weight_9281 = "Paris is the capital of France"

More like this:
  many scales together strengthen patterns
  "after 'the capital of France' often comes 'Paris'"
  "in SQL, after SELECT there is often a list of columns"
  "the pronoun 'she' is often associated with the nearest female subject"

Knowledge is distributed, and does not lie piecemeal

two things follow from this

  • the model can generalize to new combinations
  • the model can confidently mix similar patterns
02OverviewLLM does not “look for a ready-made phrase in the database”

The 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.

step by steptext
Search 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
03OverviewWhat really lives in the scales

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.

Diagramsql
WHAT DO WEIGHTS STORE?

Not so:
  weight_9281 = "Paris is the capital of France"

More like this:
  many scales together strengthen patterns
  "after 'the capital of France' often comes 'Paris'"
  "in SQL, after SELECT there is often a list of columns"
  "the pronoun 'she' is often associated with the nearest female subject"

Knowledge is distributed, and does not lie piecemeal

two things follow from this

  • the model can generalize to new combinations
  • the model can confidently mix similar patterns
02

How text becomes numbers

4 cards
04TokensTokenization: text is not cut into letters and not always into words

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.

Diagramtext
EXAMPLE OF TOKENIZATION

Text:
  "Neural networks explain text"

Possible parsing:
  ["Neuro", "networks", "explain", "nyayut", "text"]

Other text:
  "transformers are useful"

Possible parsing:
  ["transform", "ers", "are", "useful"]

The same symbolic world is cut into pieces of a dictionary
There are no letters inside the model, there are ID tokens
minimal chaintext
"Neural networks explain text"
→ tokenizer
→ [4811, 932, 18452, 77, 901]
→ then the network works only with numbers
05TokensEmbedding: Token ID turns into a dense vector

The 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.

what's literally happeningtext
vocab_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 row
06TokensPositional cues: word order doesn't appear on its own

If 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.

Diagramtext
WHY DO YOU NEED A POSITION

Phrase A:
  "The dog bit the man"

Phrase B:
  "a man was bitten by a dog"

Same words, but different meaning.

Without position:
  {dog, bitten, human} = almost the same thing

With position:
  token_vector + position_signal
  → the model knows who is earlier and who is later
07TokensContextualization: the word “bank” changes meaning according to its neighbors

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.

Diagramtext
ONE WORD, TWO CONTEXTS

Before the context:
  "bank" → e_bank

After blocks in a sentence:
  "I put the money in the bank"
  → h_bank_money

After blocks in another sentence:
  "the boat sailed to the river bank and the bank"
  → h_bank_river

The meaning changes not in the token dictionary, but inside hidden states
03

What it does Transformer Block do?

4 cards
08AttentionWhy was attention needed at all?

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.

Diagramtext
PROBLEM WITHOUT ATTENTION

"Marina came home because she was tired"

To understand "she", it is useful to see "Marina".

Weak scheme:
  token → token → token → token → ... → "she"
  long-distance communication is blurred

With attention:
  "she" ───────────────▶ "Marina"
  the necessary connection is made direct
09AttentionSelf-attention: each token asks who is useful to it 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”.

the essence of the formula without unnecessary mathematicssql
for 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 tokens
Diagramsql
INTUITION BY EXAMPLE

Phrase:
  "Marina came home because she was tired"

The "she" token builds the query:
  What kind of subject do you mean?

Other tokens offer keys:
  "Marina" → fits strongly
  "home" → fits weakly
  “tired” → helps in meaning, but not as a subject

After softmax:
  weight("Marina") = 0.62
  weight("home") = 0.05
  weight("tired") = 0.18
  ...

New vector "she" receives a lot of information from "Marina"
10BlockMLP: after context exchange there is local processing

Attention 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.

simple MLP roletext
attention:
  “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 collected
11BlockResidual + LayerNorm: the glue that holds the deep network

Transformer 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.

Diagramsql
ANATOMY OF ONE BLOCK

x

├─ self-attention(x) = a

├─ x + a ← residual

├─layernorm(...)

├─MLP(...)

├─ + previous path ← residual again

└─ layernorm(...) → block output

The block does not write everything from scratch, but improves the current state
04

Encoder, Decoder and Encoder-Decoder

3 cards
12ArchitectureEncoder: read everything at once and show understanding

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.

Diagramtext
ENCODER-ONLY

Login:
  [token1] [token2] [token3] [token4]

Attention:
  everyone sees everyone

Output:
  h1 h2 h3 h4

Next:
  or take one common vector
  or read the label for each token

Strength: Understanding the entire input
13ArchitectureDecoder: write from left to right without looking into the future

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.

Diagramtext
DECODER-ONLY

Position 1 sees: [1]
Position 2 sees: [1,2]
Position 3 sees: [1,2,3]
Position 4 sees: [1,2,3,4]

You can't:
  token 2 look at token 4

You can:
  at each step predict token 5

GPT, Llama, Claude-like models are decoder-only
14ArchitectureEncoder-decoder: one reads the input, the other writes the output

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.

Diagramtext
ENCODER-DECODER

Source text
  "Translate: The cat is sleeping"


  ENCODER reads the whole thing


  h1 h2 h3 h4 ... hN


  DECODER writes:
  "Cat"
  "The cat is sleeping"
  ...

At each step, the decoder has two sources:
  1. already written part of the answer
  2. the entire input through cross-attention

Simple: reader + writer in one system

when it's especially appropriate

  • translation
  • summation
  • structural text transformation
  • for free chat today they often use decoder-only
05

How a model learns

3 cards
15TrainingHow to learn decoder-only LLM: guess the next token

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.

Diagramsql
EXAMPLE OF TEACHING WITH A PHRASE

Text:
  "The cat is sitting on the carpet"

The model is taught in many steps at once:
  "Cat" → predict "sits"
  "The cat is sitting" → predict "on"
  "The cat is sitting on" → predict "carpet"

During training:
  the model sees the correct prefix
  not your own past answer

From millions of such chains “language knowledge” is born
what is being optimizedpython
for each position:
  logits → softmax → P(next token)
  compare with the correct token
  calculate loss
  adjust the weights a little

repeat this on billions of examples
16TrainingHow an encoder learns: fill in gaps and understand the context

Encoder 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.

Diagramtext
SIMPLE MLM EXAMPLE

Original:
  "The cat is sitting on a warm carpet"

Broken input:
  "Cat [MASK] on warm [MASK]"

Task:
  guess "sits" and "carpet"

To fill in the blank, you need to understand the entire context around
17TrainingBackprop in simple words: error pushes weights in the right direction

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.

without formal gravitytext
1. 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 shifts
06

How the model responds

3 cards
18InferencePrefill: first the model “reads” the entire prompt

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.

what's going onsql
prompt = 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 from
19InferenceDecode: further response is generated one token at a time

After 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."

Diagramsql
AUTO REGRESSION

Context:
  "Explain attention"

Step 1:
  the model selects "simple"

Step 2:
  context = "Explain attention in simple terms"
  the model chooses "in words"

Step 3:
  context = "Explain attention in simple words"
  the model selects "."

The answer is built from left to right, and not a whole paragraph at once
20InferenceLogits, softmax and temperature: how the next word is chosen

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.

Diagramtext
NUMBERS IN THE LAST STEP

Last hidden state


LM head


logits:
  "yes" = 8.2
  "no" = 6.9
  "maybe" = 6.1
  "," = 4.4

softmax →
  P("yes") = 0.63
  P("no") = 0.17
  P("possible") = 0.08
  P(",") = 0.01

temperature ↓
  T = 0.2 → distribution is sharper, almost always “yes”
  T = 1.0 → balance between certainty and variability
  T = 1.5 → more rare variants

practical intuition

  • low temperature: code, formal answers
  • medium: normal chat
  • high: creative, but more risk of noise
07

Limits and common sense

3 cards
21LimitsWhy is the model hallucinating?

The model was trained to continue the text plausibly, and 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 scales, she can confidently give a beautiful but incorrect answer.

typical source of errortext
little context
or
there are too many similar patterns
or
required fact rare / fresh / controversial

→ the model selects a statistically plausible continuation
→ not a verified fact
22LimitsWhy prompt helps, but does not rewrite the model

Prompt 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.

Diagramtext
WEIGHTS vs CONTEXT

Weights:
  long-term model parameters
  change only by training/fine-tuning

Prompt:
  temporary input of the current request
  affects only through attention in this launch

Result:
  prompt = directs
  fine-tuning = rebuilds the model's habits
23LimitsShort selection card: encoder, decoder or encoder-decoder

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.

ArchitectureHow he looks at the textStrengthTypical tasks
Encoder-onlysees the entire input at onceunderstanding and comparisonclassification, embeddings, reranking, NER
Decoder-onlyonly sees left contextfree generationchat, code, letters, brainstorming
Encoder-decoderreads the entire input and writes the output step by steptransformation A→Btranslation, 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.