Lawfare Group → Knowledge Institute → Lawfare Academy
← AI 301 — Machine Learning, Neural Networks and Language
Weeks 12–14
Language models, attention and generated claims
Learning objectives
- Explain and trace the mechanisms in language models, attention and generated claims.
- Apply the method to the worked example and changed-condition exercise.
- Identify assumptions, failure cases and the evidence needed to justify a result.
A language model estimates patterns over token sequences. Tokens are model-dependent pieces of text, not necessarily words. Predicting plausible continuations is different from verifying a claim about the world. Fluent explanations and formatted citations can be generated without corresponding evidence. Evaluate factual claims against reliable sources rather than treating style as a confidence measure.
Attention combines representations according to learned or computed compatibility scores. Queries, keys and values play different roles; softmax-normalized scores determine a weighted combination of value vectors. Positional information is needed to represent order. The mechanism supports contextual computation, but an attention weight is not automatically a faithful explanation of a final answer.
Separate pretraining, fine-tuning, prompting and retrieval. They change different parts of the system. Retrieval can supply current or private context without changing model weights, while still failing if retrieval misses the relevant passage or the model misuses it. Context windows are finite, and long inputs can obscure key evidence. Build evaluations that distinguish retrieval failures, unsupported generation, omissions and incorrect abstention. Avoid claiming that low-temperature output is guaranteed factual.
Worked reasoning The second score receives about 0.731 weight, the first about 0.269, producing a context near 17.31. Subtracting the maximum before exponentiation preserves softmax probabilities while reducing overflow risk. This scalar example illustrates normalized weighting, not a complete transformer, trained attention mechanism or explanation of a factual decision.
Extended teaching and laboratory
Attention forms a weighted combination of value representations using normalized scores. Softmax weights are positive and sum to one, but normalization is not a truth test. A high weight can reflect learned compatibility within the model rather than verified factual support. A generated sentence requires evidence beyond interpreting one internal weight.
Subtracting the maximum score before exponentiation preserves softmax ratios and helps numerical stability. This algebraic transformation changes neither the intended distribution nor the need to handle very large or invalid inputs carefully.
Worked problem Scores are [0, ln(3)] and values are [10,30]. Calculate the attention-weighted scalar, then explain what it does not establish.
Step-by-step reasoning 1. Exponentials are [1,3]; normalized weights are [.25,.75].
- The weighted value is .25×10+.75×30=25.
- Subtracting ln(3) gives exponentials [1/3,1], whose normalized weights remain [.25,.75].
- The result is a representation calculation. It does not establish that the second passage is true or supports a generated factual claim. That requires inspecting evidence and entailment.
Apply the idea
Scores are [0, ln(3)] and values are [10,30]. Calculate the attention-weighted scalar, then explain what it does not establish.
A model places .95 attention weight on a sentence that quotes a false claim in order to refute it. Can that weight justify citing the claim as true?
Read the worked reasoning
No. Attention strength does not encode the cited sentence’s argumentative role or prove entailment. Read the surrounding passage and distinguish quotation, negation and endorsement. An answer should cite the evidence for the conclusion it actually states, not treat a numerical attention weight as an authority score.
Check understanding
What does a fluent answer with a citation establish?
- Only that text was produced; source support still needs checking
Feedback
Generation quality is not evidence verification.
- That the cited source exists and supports the claim
Feedback
Citation strings can be fabricated or misapplied.
- That the model retrieved every relevant passage
Feedback
Fluency gives no retrieval completeness guarantee.
Further reading
Study the complete on-site source sections below, then work the original example, changed-condition problem and transfer laboratory. Study CS50 AI Language and Neural Networks; Dive into Deep Learning Attention Mechanisms and Transformers. Work attention-shape exercises and compare generated text with source evidence.
- 9.2. Converting Raw Text into Sequence Data Open the notebook in SageMaker Studio Lab
- 9.3. Language Models Open the notebook in SageMaker Studio Lab
- 11.1. Queries, Keys, and Values Open the notebook in SageMaker Studio Lab
- 11.3. Attention Scoring Functions Open the notebook in SageMaker Studio Lab
- 11.5. Multi-Head Attention Open the notebook in SageMaker Studio Lab
- 11.6. Self-Attention and Positional Encoding Open the notebook in SageMaker Studio Lab
- 11.7. The Transformer Architecture Open the notebook in SageMaker Studio Lab
- 8.2. Feature extraction