BERT-style
encoder-only
Sees: left and right context.
Trains: reconstruct masked tokens.
Used for: classification, token labelling, embeddings, extractive QA, retrieval.
Language models predict likely language units from context. LLMs scale that idea with broad data, parameters, compute, and Transformer architecture.
A chat response is a visible surface over repeated next-token prediction—not the definition of a language model.
During pre-training, a language model adjusts its parameters to predict language patterns. At runtime, those learned parameters turn a prompt into one next-token decision at a time.
The next question is how a model can use a long prompt, examples, and instructions to make that next-token decision.
Both LSTMs and decoder Transformers can predict the next token. The difference is how they carry and retrieve context while training at scale.
A Transformer does not update its weights from a few-shot prompt. It temporarily uses the examples and instructions already present in that prompt to continue the pattern.
An LLM combines model capacity, broad data, substantial compute, and a training method that yields reusable language representations.
No universal parameter count defines “large.” The term describes the engineering regime in which a broadly trained language model can be prompted or adapted across many tasks.
An LLM is language-centred. A foundation model may span text, images, audio, and other modalities.
A tokenizer turns arbitrary text into a finite, reusable vocabulary of numeric units.
Illustrative example: unpredictable → un · predict · able → token IDs. Actual pieces and ID values are chosen by each model’s tokenizer.
Text → subword tokens → token IDs → model input.
When the model generates IDs, the tokenizer performs the reverse conversion back to text.
They avoid requiring a separate vocabulary entry for every rare word, identifier, spelling variant, or code fragment.
The embedding matrix turns every token ID into a learnable continuous representation that the network can transform.
The embedding says which token it is; positional information tells the model where it occurs. “Dog bites man” and “man bites dog” contain the same tokens in a different order.
The initial embedding for bank is the same lookup. Transformer layers produce different contextual vectors in “river bank” and “bank loan.”
It is the token budget a model can attend to while producing this response.
The window makes tokens available; it does not decide which available token matters for the current prediction.
Attention has memory and compute costs as sequences grow. The model cannot treat unlimited history as input.
Long context can contain more material; it does not guarantee that the model selects, interprets, or verifies it correctly.
The attention mechanism you just saw appears three ways: encoder self-attention, decoder masked self-attention, and decoder cross-attention.
The encoder reads the source. The decoder produces the target using earlier output and the encoder’s contextual representation.
The animal sleeps
Contextual source vectors: keys and values for cross-attention.
<BOS> · L’ · animal
Final decoder vector → one raw score (logit) for every vocabulary token.
Illustrative probabilities. Greedy decoding selects the top token; sampling may choose from the permitted candidates.
The context window exposes many tokens. Attention decides which of those available tokens should influence this token now.
Attention asks: among the available tokens, what context matters for this token now? To interpret it, animal should matter more than street.
“The animal did not cross the street because it was too tired.”
Question: Which earlier token should shape the representation of it?
animal → highly relevant
street → not the antecedent
The animal was tired, so it slept.
one focus Query
one Key per token
Single-head simplification: a full Transformer also applies an output projection and LayerNorm around the residual connection.
A Transformer runs several learned attention heads in parallel, so the same sentence can be examined through different relevance patterns at once.
Each head has its own learned Query, Key, and Value projections.
Sees: left and right context.
Trains: reconstruct masked tokens.
Used for: classification, token labelling, embeddings, extractive QA, retrieval.
Sees: earlier tokens only.
Trains: predict next token.
Used for: chat, text generation, code completion, open-ended continuation.
Sees: source in encoder; past target in decoder.
Trains: source-to-target reconstruction.
Used for: translation, summarisation, controlled transformation.
The model learns by comparing its prediction with a known training token. At runtime, it selects a token from a score distribution and repeats.
Temperature changes how concentrated the next-token distribution is; it is not a factuality control.
Top-k / top-p restrict candidate tokens before sampling. Max output / stop sequences bound when generation ends.
An LLM is a probabilistic sequence model with learned representations—not a reasoning oracle, database, or autonomous authority.
We now use this mental model to structure prompts, add constraints and evidence, and evaluate model outputs deliberately.
Open Chapter 03 →