Natural language processing
Language Modeling and Sequence Probability
Understand autoregressive and masked language objectives, perplexity, decoding interfaces, adaptation, and the limits of sequence probability.
By the end you can
- Explain autoregressive factorization and masked-token objectives at a conceptual level
- Interpret token likelihood and perplexity without equating them with truth
- Distinguish language modeling from generation policy and product decision
- Evaluate a language model by domain, tokenizer, sequence, and downstream behavior
Likely text is not necessarily correct text
A sentence can be common, grammatical, and false; another can be rare because it contains a new discovery, a specialist term, or an unusual name.
Language modeling estimates patterns of sequences under data and an objective. When a product needs factual support or safe action, it has to add evidence, task constraints and evaluation on top.
A court has priced that gap. Two lawyers filed a brief in Mata v. Avianca citing six judicial opinions that do not exist. On 22 June 2023 Judge P. Kevin Castel opened his sanctions order like this: “Peter LoDuca, Steven A. Schwartz and the law firm of Levidow, Levidow & Oberman P.C. (the “Levidow Firm”) (collectively, “Respondents”) abandoned their responsibilities when they submitted non-existent judicial opinions with fake quotes and citations created by the artificial intelligence tool ChatGPT, then continued to stand by the fake opinions after judicial orders called their existence into question.”
The six fabrications were the Varghese, Shaboon, Petersen, Martinez, Durden and Miller opinions. Of the invented Eleventh Circuit decision the court wrote “Its legal analysis is gibberish.” The penalty was $5,000, imposed jointly and severally on Peter LoDuca, Steven A. Schwartz and the Levidow Firm. They were also ordered to write to each real judge falsely named as the author of one of the fake decisions.
None of that text was improbable. It read like case law because case law is what the model had been fitted to continue. It passed a lawyer, an opposing party and a judge on that resemblance alone. Probability under a text model ranges over the form of a sentence. Nothing in it ranges over whether the case exists.
Probability under a text model is not probability that a claim is true.
Visual
Autoregressive factorization in plain language
A sequence probability is decomposed into a chain of next-token predictions.
Step 3 hides a decision. Taking the single most probable token at each step looks like the neutral reading of the model. It is a measured failure mode.
Five thousand continuations were generated from GPT-2 Large (762M) on held-out WebText, capped at 200 tokens. Greedy decoding scored perplexity 1.50 with 73.66% repetition. Beam search (b=16) scored 1.48 with 28.94%. The human continuations scored perplexity 12.38 with 0.28%. Holtzman and colleagues reported that in 2020. The most likely text was the most degenerate text, and the model gave the text a person had actually written a perplexity roughly eight times higher than its own worst output. Their abstract says it in a line: “maximization is an inappropriate decoding objective for open-ended text generation”.
A second group found the same failure independently in 2022, on a different corpus and with a different metric. On the Wikitext-103 test set, GPT-2 fine-tuned with the standard MLE objective repeated 69.21% of bigrams under greedy decoding and 71.94% under beam search, against 3.92% for human text. Diversity was 0.04 and 0.03, against 0.95. Two groups, two corpora, one direction. A decoding policy belongs in the system's specification, not in a default.
1. Start with a prefix
The model receives tokens already observed or generated.
2. Predict a distribution
It assigns scores to possible next tokens.
3. Observe or select one token
Training uses the recorded next token; generation applies a decoding policy.
4. Extend the prefix
The chosen token becomes context for the next step.
5. Repeat until a stopping rule
Length limits, end markers, or application policy terminate the sequence.
Comparison
Two common language-modeling views
The two views make different information visible during pretraining, and the size of that difference has been measured with everything else held fixed.
Swap BERT's masked objective for a left-to-right one, keeping the data, the hyperparameters and the fine-tuning procedure the same, and SQuAD 1.1 dev F1 falls from 87.9 to 77.8. MRPC dev accuracy falls from 86.5 to 77.5. That ablation is BERT's own, published in 2019, and Devlin and colleagues summarise it: “The LTR model performs worse than the MLM model on all tasks, with large drops on MRPC and SQuAD.” The corruption strategy is stated as plainly: “In all of our experiments, we mask 15% of all WordPiece tokens in each sequence at random.” A different team rebuilt both objectives at BERT-Base size, on the same data, for 1M steps. It reproduced the direction: 90.0 SQuAD 1.1 F1 for a Masked Language Model against 76.7 for a pure left-to-right Language Model. That is the BART paper, 2020.
What none of this licenses is a ranking of objectives in general. The same BART table sets six pretraining objectives side by side, all BERT-Base size, 1M steps, same data and same code base. In it the pure left-to-right Language Model produces the best ELI5 perplexity in the whole table, 21.40, alongside that worst SQuAD score of 76.7. The authors mark it themselves: “For example, a simple language model achieves the best ELI5 performance, but the worst SQUAD results.”
The comparison was run a third time for T5, by a separate group with a separate publisher. On SQuAD, prefix language modelling scored 77.99, BERT-style 80.65 and deshuffling 67.61 — the same task-dependence again. Their summary: “Overall, we find that the BERT-style objective performs best, though the prefix language modeling objective attains similar performance on the translation tasks.” The objective, not the model size, decides which task you are good at.
Autoregressive modeling
Predict each next token from preceding tokens.
- Causal context
- Natural generation interface
- Sequence likelihood
- Common in decoder models
Masked token modeling
Predict selected hidden tokens from visible left and right context.
- Bidirectional context
- Strong encoder representations
- Corruption strategy matters
- Not directly a left-to-right generator
Denoising sequence modeling
Reconstruct clean text from corrupted text with a sequence-to-sequence model.
- Flexible corruption
- Supports generation tasks
- Encoder and decoder roles
- Example: BART-style pretraining
Analogy
A musician anticipating the next note
A musician who has heard thousands of performances can anticipate plausible continuations. That skill captures style, rhythm, and recurring structures without proving knowledge of the story behind the music.
The musician plays with intention and hears the sound, while the model has neither intention nor access to sound. Sequence regularity and factual verification remain separate questions.
Language prediction can be powerful without being a truth procedure.
Key idea
Perplexity is comparable only under aligned conditions
Perplexity summarizes average token surprise under a model and its tokenizer. Change the tokenization, the vocabulary, the data filtering or the sequence handling, and raw values stop being comparable across systems.
A lower value on one corpus does not guarantee better retrieval, classification, dialogue, safety, or factual generation. Report the evaluation data, the unit, the preprocessing and the downstream behavior.
One famous perplexity number rests on three decisions taken before any model ran. The One Billion Word Benchmark was set out in 2014 by Chelba and colleagues. Duplicate sentences were removed, “dropping the number of words from about 2.9 billion to about 0.8 billion”. The vocabulary was “constructed by discarding all words with count below 3”. That left 793,471 types, including the two sentence-boundary markers, and everything outside it was mapped to one unknown token. The out-of-vocabulary rate on the test set was 0.28 per cent. Only after all of that does the headline hold: “The baseline unpruned Kneser-Ney 5-gram model achieves perplexity 67.6”. Change the deduplication, the count-of-three cutoff or the unknown-token policy, and 67.6 no longer names the same quantity.
That sensitivity is not hypothetical, and it has a size. Invertible de-tokenizers were applied to the evaluation sets alone, with no change to the model at all, and OpenAI reported: “We observe gains of 2.5 to 5 perplexity for GPT-2 with these de-tokenizers.” Points moved by preprocessing, on a scale where whole modelling contributions are argued over single points. The same report blames GPT-2's poor result on this very benchmark on the corpus's “most destructive pre-processing”, because “1BW's sentence level shuffling removes all long-range structure”.
The unit is no safer than the preprocessing. Bits-per-character is not a comparable unit, because it depends on the writing system. Cotterell and colleagues showed this in 2018, over n-gram and LSTM models on utterance-aligned translations in the 21 Europarl languages. Of the Czech word puč and its German equivalent Putsch they write, “Even if these words are both predicted with the same probability in a given context, German will end up with a lower BPC.” Equal predicted probability, unequal score, and nothing about the models involved explains the difference.
Even with the unit and the corpus fixed, the number does not settle the product question. In one controlled comparison the model with the better validation perplexity — −1.46 against −1.49 negative log-perplexity, at 3.6B parameters against 3.8B — lost on all three downstream scores reported: 85.1/76.5/88.1 against 86.9/79.9/89.5. Tay and colleagues state it flatly: “pretraining perplexity is not indicative of transfer performance”. The caption of that table is the sentence to carry: “A model with improved upstream quality (as measured by validation perplexity) can do significantly worse on transfer if the shape setting is not right.” Liu and colleagues reached the same conclusion from the opposite direction in 2023. They exhibit models matched to within 3.204–3.208 pretraining validation loss whose downstream accuracies differ, and state it plainly: “pre-training loss cannot fully explain downstream performance”.
Perplexity measures a language objective under a defined tokenization and corpus—not universal intelligence.
Figure
Example
Ways a language model enters an NLP system
The same pretrained model can support several roles with different risks — and the first two differ less in quality than the phrase "fine-tuned" suggests.
On CoNLL-2003 named-entity recognition, a frozen BERT-Base reached 96.1 dev F1 against 96.4 for fine-tuning the whole model. Nothing in the encoder was updated. The concatenated top four hidden layers were fed into a randomly initialised two-layer BiLSTM, and the score is an average over five random restarts. The other frozen variants ran from 91.0 for embeddings alone up to 95.9 for a weighted sum of the last four layers. Devlin and colleagues put the gap in one sentence: “The best performing method concatenates the token representations from the top four hidden layers of the pre-trained Transformer, which is only 0.3 F1 behind fine-tuning the entire model.”
An independent team, whose whole subject is this comparison, measured the same near-parity on that task's test set. Feature extraction scored 92.2 span F1 against 92.4 for fine-tuning BERT-Base, a gap of 0.2, as the mean of five seeds. Peters and colleagues found no fixed winner — “the relative performance of fine-tuning vs. feature extraction depends on the similarity of the pretraining and target tasks”. So the first two roles below are an engineering decision about cost and operations at a stated price in F1, not a quality tier.
- Feature source: use hidden states for classification, tagging, retrieval, or similarity — 96.1 dev F1 on CoNLL-2003 from BERT-Base's concatenated top four layers, with the expensive representation computed once.
- Fine-tuned task model: adapt parameters to a labeled NLP objective — 96.4 dev F1 on that same task, a margin of 0.3 dev F1 and 0.2 test span F1 over frozen features, and task-dependent in sign.
- Generator: produce text under a decoding policy, prompt, evidence set, and output controls.
- Scorer: compare candidate sequences or rerank hypotheses using conditional likelihood.
- Data assistant: propose labels, paraphrases, or synthetic examples under human review.
- Evaluator aid: support rubric application only after validation against qualified judgments.
Training and generation operate under different prefixes
During teacher-forced training, the model conditions on recorded previous tokens. During free generation, it conditions on its own selected outputs, so an early mistake can alter every later context.
This difference helps explain compounding errors, but it does not identify one universal cure. Decoding, training data, objective design, verification and task structure all influence behavior.
The gap was named in 2015, by Bengio and colleagues. Training maximises “the likelihood of each token in the sequence given the current (recurrent) state and the previous token”. Inference has no true previous token. There, “the unknown previous token is then replaced by a token generated by the model itself”. The consequence is theirs: “This discrepancy between training and inference can yield errors that can accumulate quickly along the generated sequence”. Their remedy, scheduled sampling, is a curriculum. It moves training “from a fully guided scheme using the true previous token”, towards “a less guided scheme which mostly uses the generated token instead”. A mitigation with a schedule to tune is not a cure.
A generator must be evaluated on complete trajectories, not only next-token loss.
Steps
Evaluate a language model for the role it will play
Separate intrinsic modeling evidence from product obligations.
Step 2 is where the evidence is worst and the assumption is strongest. Contamination is a measured condition of pretraining corpora, not a hypothetical. GPT-3 shipped with benchmark text in its training data, and its own paper says why: “Unfortunately, a bug in the filtering caused us to ignore some overlaps, and due to the cost of training it was not feasible to retrain the model.” The fallback was measurement rather than repair — flagging examples with a 13-gram overlap with the pretraining set and reporting clean subsets.
An outside audit then put percentages on a corpus everyone was training on. Dodge and colleagues searched C4.EN in 2021 for exact matches rather than n-gram overlap, and found GLUE test inputs present in the pretraining corpus at rates “from less than 2% to over 50%”. Generation target texts: 1.87–24.88%. LAMA T-REx and Google-RE examples reproduced verbatim: 4.6% and 5.7%. One shipped frontier model whose developers said in print they could not afford to fix it, and one independent audit with numbers on it.
Step 3 inherits the caution from the callout above. Report the tokenizer, the corpus, the length and the uncertainty, and remember that the better validation perplexity in Tay and colleagues' Table 3 lost on all three downstream scores reported. An intrinsic number is evidence about the objective. The role is what has to be tested at steps 4 and 5.
1. Define the role
Feature encoder, scorer, generator, assistant, or component of a larger workflow.
2. Match domain and chronology
Use future-like and in-domain text while controlling contamination.
3. Report intrinsic measures carefully
Include tokenizer, corpus, length, and uncertainty for loss or perplexity.
4. Run task and behavioral tests
Measure complete outputs, constraints, support, slices, and failure recovery.
5. Compare cost and simpler alternatives
Include latency, memory, throughput, data, and operational controls.
Separate likelihood from factual support
Collect ten fluent claims from a domain corpus, including common false statements and rare true statements. Compare language-model scores with independent evidence labels.
Document cases where probability tracks style or frequency rather than truth. Propose retrieval, citation, validation, or abstention controls for the intended application.
That exercise exists as a benchmark. TruthfulQA, presented in 2022, “comprises 817 questions that span 38 categories, including health, law, finance and politics”. The questions are written so that “some humans would answer falsely due to a false belief or misconception”. Its three authors ran it across GPT-3, GPT-Neo/J, GPT-2 and a T5-based model. “The best model was truthful on 58% of questions, while human performance was 94%”. The direction of the size effect is the part to keep. “The largest models were generally the least truthful. This contrasts with other NLP tasks, where performance improves with model size.”
A factual product needs an evidence channel beyond sequence probability.
Position
Waiting for a larger model is not a plan for this class of error
There is a reply that ends most arguments about language-model errors: the next model will be better. Notice that the reply is a prediction. On one class of error this lesson holds a measurement.
The class has to be described precisely first. TruthfulQA's 817 questions span 38 categories, among them health, law, finance and politics, and each one is written so that some humans would answer falsely due to a false belief or misconception. That construction picks out exactly the items where continuing human text and stating something true come apart. Not obscure facts — answers that are wrong and common at the same time. Nothing in a next-token objective separates those two properties. This lesson's opening section has already shown what that costs: six fabricated opinions, fluent enough to be filed in a federal court.
Then the measurement. Across GPT-3, GPT-Neo/J, GPT-2 and a T5-based model, the best model was truthful on 58 per cent of questions against 94 per cent for humans. The largest models were generally the least truthful — a contrast the authors draw themselves with other NLP tasks, where performance improves with model size. Hold that result at its real size: one benchmark, four model families, and the word is generally rather than always. It is still the wrong direction, and it was measured rather than argued.
Nothing else in this lesson would have shown it. The one intrinsic number here is the 67.6 perplexity of the One Billion Word Benchmark. It is specified by a deduplication, a count-of-three vocabulary cutoff and an unknown-token policy. It is specified too by the preprocessing that OpenAI later called the most destructive of any corpus it evaluated, worth 2.5 to 5 perplexity points on the evaluation side alone. Every term in that specification concerns a corpus and its handling. None of them ranges over whether a sentence is true. That is why the callout above warns that a lower value does not guarantee better factual generation. A better perplexity from a bigger model is not evidence about this class of error at all, and Tay and colleagues' Table 3 shows a better perplexity failing to buy even the downstream tasks it was supposed to predict.
So the reply is not merely optimistic. It is unbudgeted. A roadmap that books this failure as temporary is booking a saving that the only measurement pointed at it contradicts. Carry it instead as a standing property of the system for as long as the system ships, and revisit that when a measurement on this class of question moves the other way.
One benchmark here varied model size, and on it the largest models were generally the least truthful.
Key takeaways
- Autoregressive language models factor sequence probability into repeated next-token predictions from a prefix, and the decoding rule applied to those predictions is itself a specification: on GPT-2 Large, greedy decoding scored 73.66% repetition against 0.28% for the human continuations.
- Masked and denoising objectives expose different context and support different downstream interfaces. Swapping BERT's masked objective for a left-to-right one, everything else held fixed, moved SQuAD 1.1 dev F1 from 87.9 to 77.8 — yet in BART's table that same left-to-right objective took the best ELI5 perplexity (21.40) and the worst SQuAD F1 (76.7).
- Language-model probability reflects textual regularity rather than factual truth, authorization, or user benefit: Mata v. Avianca ended in a $5,000 penalty over six non-existent opinions fluent enough to be filed.
- Perplexity depends on tokenizer, corpus, sequence handling and unit. Invertible de-tokenizers alone moved GPT-2 by 2.5 to 5 perplexity points with no change to the model, and bits-per-character differs for puč and Putsch at equal predicted probability.
- Teacher-forced training and free generation use different prefixes, so complete trajectories require direct evaluation. Upstream quality does not settle it either: the better validation perplexity in Tay and colleagues' Table 3 lost on all three downstream scores reported.
- A language model can serve as a feature source, scorer, generator, assistant, or component under role-specific controls. On CoNLL-2003 NER frozen features came within 0.3 dev F1 (96.1 against 96.4) of fine-tuning the whole model, and within 0.2 test span F1 in an independent measurement.