AI301 — Original on-site preparation
Independent written study. All essential explanations and optional model reasoning for this chapter are on this page. References are optional further study. No degree, professional approval or observed competence is conferred.
From text to a conditional sequence model
A tokenizer maps text into a sequence of vocabulary identifiers. A word tokenizer, character tokenizer and learned subword tokenizer create different prediction units. Their vocabulary, normalization, treatment of spaces and unknown-input behavior belong to the model contract. A token ID is a lookup index, not a numerical measurement whose distance from another ID measures semantic similarity. An embedding table maps each identifier to a learned vector. Keep training-derived vocabulary construction within the evaluation boundary; do not let evaluation labels or prohibited documents enter fitting.
For a token sequence t₁,…,tₙ, the probability chain rule factors its joint probability as the product of P(tᵢ|t₁,…,tᵢ₋₁). A context-limited model approximates these conditionals using only the context its architecture and input contract permit. For a fictional two-token sequence with first-token probability .5 and second-token conditional probability .25, joint probability is .125. Natural-log negative likelihood is ln 8; mean loss per token is ln 8/2 and perplexity is √8. These quantities require the same tokenizer, sequence boundaries and weighting for comparisons. A lower token-level perplexity under a different tokenizer does not automatically mean a better model of identical events.
Teacher forcing supplies the observed prefix during training. Shift inputs and targets correctly: for [start,A,B,end], inputs [start,A,B] predict [A,B,end]. The representation predicting B may use start and A, but must not inspect B or later tokens through an unmasked attention path. During autoregressive generation, the model instead extends its own generated prefix. Errors can alter later context, so fitting conditional probabilities on observed prefixes and evaluating a free-running task answer different questions.
Architecture around the already explained attention head
The retained attention laboratory supplies Q/K/V dimensions, scaled scores, eligible-key normalization and complete changed-mask calculations. A multi-head layer first applies distinct learned projections for each head. Each head computes its own attention output; concatenate these outputs and project the result back to the intended model width. With sequence length 3, model width 4, two heads and head width 2, each head output has shape 3×2; concatenation is 3×4. A4×4 output projection retains 3×4. These are chosen teaching dimensions, not a requirement that every implementation use exactly this parameterization.
Token embeddings without any order-sensitive mechanism do not themselves distinguish all permutations. Position vectors added to embeddings, or another explicitly designed positional mechanism, supply order information. Self-attention can then combine representations across positions. An encoder block commonly combines self-attention with a positionwise feed-forward network. The same feed-forward weights transform each position separately; it does not perform an additional exchange between positions. Residual addition requires compatible widths. Layer normalization rescales a position's feature vector using its own feature statistics and learned affine parameters, differing from batch normalization across examples. Pre-normalization and post-normalization are different block conventions; name the one being traced.
In an encoder–decoder model, the encoder represents the source sequence. Decoder self-attention obeys the causal output boundary, while cross-attention uses decoder queries and encoder keys and values. A decoder-only model omits that separate encoder/cross-attention arrangement. A vocabulary projection converts a position's representation into logits; its softmax concerns candidate output tokens, rather than the attention distribution over input positions. The preserved logit-gradient example demonstrates why those two distributions must not be conflated.
Suppose a two-feature representation is x=[1,−1] and a sublayer produces [2,0]. A residual sum is [3,−1]. Its feature mean is 1 and population variance 4. Ignoring learned affine scaling and using ε=0 for this nonzero-variance arithmetic illustration, normalization gives[1,−1]. Real implementations include positive ε and may normalize before the sublayer; they need not produce this exact value. Compatible shapes establish the arithmetic's form, not correct masking or useful representations.
Generated text and source evidence
Pretraining changes weights using a broad training objective. Fine-tuning changes them using further training; prompting supplies input context; retrieval selects context from a separate corpus. These mechanisms can be combined, but one does not substitute for verifying another's boundary. A retrieved passage can be irrelevant, outdated, a quotation of a rejected claim or an instruction that the application should treat as untrusted data. Evaluate retrieval coverage separately from source support and generation quality. Low-temperature decoding changes a sampling policy; it does not turn token probabilities into factual proof.
Optional changed sequence and shape reasoning
Change the second-token conditional probability from .25 to .5 while retaining the first .5. Joint probability becomes .25, total negative log-likelihood ln 4, mean loss ln 2 and perplexity 2. This is a probability calculation under a stipulated model, not evidence that a sentence is true. Change sequence length to 5 with the same two heads: head outputs 5×2, concatenation 5×4 and projected output 5×4. Changing the output projection to 4×6 would produce 5×6, which cannot be added directly to a 5×4 residual input. Restore the intended width or define an explicit skip projection. If a retrieved sentence says that an obsolete rule is no longer effective, citing the quoted old rule as current fails support even when attention gives that sentence high weight.
Optional criteria, one point each: trace tokens, shifted targets and conditionals; reconcile sequence likelihood and loss units; track multi-head/residual shapes and masking roles; distinguish generated likelihood from current source support. Explain all four for four points.
Optional source references
These sources support the explanations; reading them is optional. Original Academy examples are fictional. Historical attributed readings remain preserved.