Highlights

Contents

Back matter

Interview question bank

Explain the mechanism and why it is useful before naming an equation. Answer aloud, then check the response.

What does a language model predict?

A distribution over the next token, conditioned on the prefix. Generation selects a token, appends it, and repeats. A fluent continuation is not evidence that its claims are true.

Why tokenize instead of using whole words?

Whole words leave unfamiliar words unrepresentable. Reusable byte or subword pieces cover new text while avoiding the long sequences of character-only input.

Why replace token IDs with embeddings?

IDs are arbitrary labels. A learned vector gives the network features it can compare and transform; numerical closeness between IDs means nothing.

Where does an embedding get its meaning?

Training adjusts it to help predict surrounding text. Similar usage can produce similar directions, but an input embedding is still context-independent. Later layers build contextual representations.

Why does attention need position information?

Content comparisons alone do not describe order. Position tells the model which arrangement of the same words it is reading.

Why rotate queries and keys with RoPE?

Their relative angle changes with the position gap. Moving both positions together leaves the positional part of the comparison unchanged. Values carry content without this rotation.

Why have separate queries, keys, and values?

Queries describe what a token seeks, keys describe how other tokens can find it, and values describe what they contribute. Separate projections let matching and content learn different features.

What does softmax do in attention?

It converts visible scores into positive weights that sum to one. The output blends values using those weights; it does not select a single word or prove a linguistic relationship.

Why scale scores and mask before softmax?

Scaling prevents large dot products from making the distribution too sharp during learning. Masking first removes future positions from both the weights and their normalization.

Why use multiple heads?

A single weight pattern must compromise between different relationships. Heads form separate comparisons, and an output projection combines their results.

Why can generation cache keys and values?

A causal prefix cannot change when a later token arrives. Its stored keys and values remain valid. Old queries are unnecessary because generation needs only the new position’s output.

Why are attention, an MLP, and residual connections all needed?

Attention exchanges information between positions. The MLP transforms each position’s features nonlinearly. Residual additions preserve the existing representation and give gradients a direct route through depth.

Back matter

Exercises

One filled dot is a short explanation, two require diagnosis, and three require a system design. Draw the relevant mechanism before checking the solution.

E1. ●○○ Explain why changing a token ID without changing its embedding row breaks a model.

E2. ●○○ Draw how the token “it” can obtain information about “cat”. Label the roles without calculating a score.

E3. ●●○ A training model has very low loss but fails when generating. How would you test for future leakage?

E4. ●●○ A cached decoder disagrees with a full forward pass. Describe the first checks.

E5. ●●● Design a small demonstration of why separate attention heads help.

E6. ●●● Explain the complete route from text to a generated continuation.

Back matter

Worked solutions

Follow the reasoning, including the assumption that makes each answer valid.

E1. The tokenizer and embedding table agree on which row represents each token. A changed ID selects another learned meaning. Renumbering is safe only if every dependent mapping is permuted consistently.

E2. The query from “it” compares with the key from “cat”. If the resulting attention weight is strong, the value from “cat” contributes strongly to the output for “it”. The key makes the match; the value supplies the content.

E3. Change a later input token while holding its prefix fixed. Earlier logits must remain unchanged. If they move, inspect the causal mask and every operation that could mix future information into earlier positions.

E4. Use identical weights, input IDs, evaluation mode, and positions. Compare the same next-token logits. Check that keys were rotated once at their true positions, that the new query sees the entire allowed prefix, and that padding was excluded consistently.

E5. Choose a sentence where a pronoun needs its referent while another feature needs the preceding word. Draw separate weight patterns for those relationships, then show their outputs being combined. Label the patterns as illustrative rather than asserting that trained heads must specialize this way.

E6. The tokenizer produces IDs, embeddings supply features, and position information makes order available. Decoder blocks alternate causal information exchange and nonlinear feature transformation, with norms and residual paths. The output head scores possible next tokens. A decoding policy chooses one and repeats until a stop condition.