1/34
Practice exam flashcards covering sequence modeling, causality, the Transformer architecture, decoding methods, evaluation metrics, and inference optimization based on the lecture 'GPT from scratch'.
How is next-token prediction framed as a classification task for a vocabulary V?
At each position, the model predicts a probability distribution pθ(xt=v∣x<t), producing V=∣V∣ scores over the vocabulary V.
What trade-offs are associated with character, word, and subword tokenization units?
Character tokenization uses a small vocabulary but produces long sequences; word tokenization results in a large vocabulary; subword tokenization balances sequence length and vocabulary size.
According to the chain rule of probability, how is the probability of an entire sequence pθ(x1,…,xT) expressed?
It is the product of all conditional next-token probabilities: pθ(x1,…,xT)=∏t=1Tpθ(xt∣x<t).
What is the maximum likelihood objective used for training a language model on a corpus D?
θmin−x∈D∑t∑log(pθ(xt∣x<t))
What is the cross-entropy loss value for a target token probability of 0.5, and what is it for a uniform prediction over vocabulary V?
A target probability of 0.5 gives a loss of approximately 0.693 nats, whereas a uniform prediction gives a loss of log(V).
What is teacher forcing during training, and what computational benefit does it provide?
Training supplies ground-truth prefix tokens directly from the corpus rather than generated tokens, allowing all sequence positions to be evaluated simultaneously in parallel.
In the tensor contract of the small GPT model, what are the shapes for Token IDs, Shifted targets, Hidden states, and Logits?
Token IDs have shape (B,T), Shifted targets have shape (B,T), Hidden states have shape (B,T,C), and Logits have shape (B,T,V), where B is batch size, T is context length, C is hidden width, and V is vocabulary size.
How many next-token predictions are evaluated in a full unpadded batch of shape (B,T)?
There are BT predictions in a full unpadded batch.
How is the causal mask Mij defined, and why does it keep the diagonal?
The causal mask is defined as Mij=0 for j≤i and Mij=−∞ for j>i. The diagonal is kept because the current input at position i is known.
How does the bigram baseline compute next-token logits zt, and how many trainable logits does it have?
It computes logits via lookup zt=W[xt,:] where W∈RV×V, using V2 trainable logits.
What fundamental limitation does a bigram baseline exhibit when processing sequences such as 'go' and 'goo'?
Because both prefixes end with the same final character, the bigram model produces identical next-token logits for both, being unable to distinguish preceding context.
How are input representations Xi constructed from token and position embeddings in the small GPT?
They are combined by vector addition after lookup: Xi=E[xi]+P[i], where E∈RV×C and P∈RTmax×C, preserving hidden width C.
What are the primary differences between a BERT-style encoder and a GPT-style language model?
BERT uses bidirectional attention, a masked-token objective, and can attend to right context; GPT uses causal attention, an autoregressive next-token objective, and accesses only the prefix.
In the causal self-attention formula Y=AU where A=softmaxrow(dhQK⊤+M), why is U used for values instead of V?
U is used to denote value representations because V is reserved for vocabulary size.
In multi-head attention with hidden width C and number of heads H, what is the dimension dh of each head?
dh=HC, where H must divide C.
What are the two equations defining a pre-normalization Transformer block?
X′=X+Attention(LN1(X)) and X′′=X′+MLP(LN2(X′)), where the MLP operates with an internal expansion of C→4C→C.
What formal test checks that an implementation satisfies causality without future-token leakage?
Given two input sequences sharing a prefix x≤k=x≤k′, the model in evaluation mode must produce matching prefix logits z≤k≃z≤k′ within a small floating-point tolerance.
Why does future-token leakage produce misleadingly low training loss?
Without proper causal masking, position i can attend directly to input token xi+1, which is its exact prediction target, making training artificially easy while failing completely at generation time.
What diagnostic test should be performed on a small fixed batch before corpus-level training?
Overfit a separate diagnostic model on a small fixed batch with dropout disabled to verify that loss decreases strongly with repeated updates, confirming optimization correctness.

What phenomenon is illustrated by the diverging relationship between training and validation loss curves over updates?
It illustrates overfitting, demonstrating that a decreasing training loss alone is insufficient and checkpoints must be chosen using validation performance.
How is perplexity (PPL) mathematically defined from sequence log-probabilities?
PPL=exp(−N1∑t=1Nlog(pθ(xt∣x<t))), representing the geometric-mean inverse target probability.
In the recorded notebook comparison, what were the validation cross-entropy per character scores for the Bigram, Count bigram, and Small GPT models?
The Bigram baseline achieved 2.5492 (500 updates), the add-one smoothed Count bigram achieved 2.4720, and the Small GPT achieved 2.3989 (1,500 updates).
In the ablation experiment comparing Small GPT with and without learned position embeddings over 1,000 updates, what were the recorded cross-entropy results?
The model with learned positions scored 2.4752 nats/char (112,577 parameters) while the model without positions scored 2.4312 nats/char (108,481 parameters), a difference of −0.0440 nats/char.
Why does greedy decoding fail to find the globally optimal sequence probability?
Greedy decoding chooses the single locally most probable token at each step (xt+1=argmaxvzv), which can miss sequences whose initial tokens have lower individual probability but lead to a higher cumulative product.
How does temperature τ>0 affect the logit distribution qτ(v)=∑uezu/τezv/τ, and how does it impact greedy decoding?
τ<1 concentrates probability on larger logits while τ>1 flattens the distribution; because positive temperature preserves relative rankings, greedy decoding output remains completely unchanged.
What does entropy H(q)=−∑vq(v)log(q(v)) indicate about a model's prediction distribution?
Entropy measures the spread or dispersion of token probabilities (uncertainty), not factual correctness; a low-entropy distribution indicates high confidence but can still be factually incorrect.
How does top-p (nucleus) sampling select candidate tokens compared to top-k sampling?
Top-k selects a fixed count k of highest-probability tokens, whereas top-p dynamically selects the smallest set of ranked tokens whose cumulative probability meets or exceeds threshold ρ.
What is the standard convention regarding the order of operations for temperature scaling, filtering, and sampling?
Divide logits by temperature τ>0, apply the filtering rule (top-k or top-p), normalize the retained probabilities, and sample the next token.
What scoring metric does beam search maximize across candidate prefixes?
It ranks hypotheses by cumulative log-probability: score(x1:t)=∑i=1tlog(pθ(xi∣x<i)), maintaining up to b hypotheses.
What is the operational distinction between prefill and incremental decoding in language model inference?
Prefill processes all prompt positions simultaneously in parallel to build the initial key-value cache, whereas incremental decoding processes one newly chosen token per step to extend the cache sequentially.
What is the approximate formula for the total number of elements stored in a standard multi-head attention KV cache?
≈2LBTHKVdh elements, where L is layers, B is batch size, T is cached positions, and HKVdh=C.
How does computational complexity scale for full-window attention recomputation versus a single query step using a KV cache?
Full-window attention recomputation scales quadratically as O(T2) per head, whereas a single cached query scores linearly against roughly O(T) past keys.
Why does a sliding window cache fail when paired naively with learned absolute position embeddings?
Reindexing position embeddings inside the sliding window alters the positional representations assigned to past tokens, causing cached key-value states to diverge from recomputed values.
What is the key limitation of constrained decoding using formal grammars or schemas?
Constrained decoding strictly guarantees syntactic and schema conformity, but valid structure does not ensure that the generated content contains correct factual statements.
What training steps are used to adapt a base pre-trained language model into an assistant model?
Base pre-training learns corpus continuation, supervised instruction tuning teaches dialogue format and response patterns, and preference-based training shapes alignment and conversational behaviour.