Lawfare Academy

AI 301 — Machine Learning, Neural Networks and Language · Weeks 12–14

Language models, attention and generated claims

Full teaching sequence and cumulative subject work

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.

Train a logistic model and expose a changed mechanism — primary material, constructed-response tasks, complete worked model and changed-case examination →

Attention weights and unsupported factual conclusions

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.

Trace the complete reasoning
  1. Exponentials are [1,3]; normalized weights are [.25,.75].

  2. The weighted value is .25×10+.75×30=25.

  3. Subtracting ln(3) gives exponentials [1/3,1], whose normalized weights remain [.25,.75].

  4. 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.

Independent transfer problem

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?

Compare the transfer solution

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.

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.

Study the mechanism

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 example

import math
scores = [1.0, 2.0]
shift = max(scores)
weights = [math.exp(s - shift) for s in scores]
weights = [w / sum(weights) for w in weights]
values = [10.0, 20.0]
context = sum(w * v for w, v in zip(weights, values))
assert abs(sum(weights) - 1) < 1e-12
assert 17 < context < 18

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.

Check your understanding

What does a fluent answer with a citation establish?

  1. Only that text was produced; source support still needs checking
  2. That the cited source exists and supports the claim
  3. That the model retrieved every relevant passage
Answer and reasoning for every option

Correct: Only that text was produced; source support still needs checking Generation quality is not evidence verification.

Reconsider: That the cited source exists and supports the claim Citation strings can be fabricated or misapplied.

Reconsider: That the model retrieved every relevant passage Fluency gives no retrieval completeness guarantee.

Transfer laboratory: Token likelihood is not source support

A language model assigns a high probability to a familiar but obsolete policy sentence. A current retrieved document contradicts it. Explain which evidence should control a source-grounded answer.

Work through the full solution

The current authoritative document should govern the task if its scope and version are verified. Model likelihood reflects learned text patterns, not the truth of a current policy. Require a version-aware citation and acknowledge any unresolved conflict. A low generation temperature does not repair a wrong evidence hierarchy or guarantee factuality.

Evidence of understanding

Separate probabilistic text continuation from source authority and current applicability.

Complete on-site teaching readings

These are full attributed source sections, not previews. Read them alongside the original Academy explanation and code.

  1. 9.2. Converting Raw Text into Sequence Data Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  2. 9.3. Language Models Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  3. 11.1. Queries, Keys, and Values Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  4. 11.3. Attention Scoring Functions Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  5. 11.5. Multi-Head Attention Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  6. 11.6. Self-Attention and Positional Encoding Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  7. 11.7. The Transformer Architecture Open the notebook in SageMaker Studio Lab · Aston Zhang, Zachary C. Lipton, Mu Li and Alexander J. Smola
  8. 8.2. Feature extraction · The scikit-learn developers

Open in My Learning to record progress →