What is a language model?
A language model is a model that assigns a probability to every possible next token given the tokens before it. Multiplying those next-token probabilities scores a whole sentence, and sampling from them one token at a time generates new text. It is trained by reading large amounts of text and minimizing cross-entropy on each next token.
Language models power autocomplete, speech recognition, machine translation, and chat assistants such as ChatGPT and Claude, which are large Transformer language models fine-tuned to follow instructions. Because predicting the next word well requires grammar, facts, and some reasoning, pretraining on this one objective produces models that can be adapted to summarization, coding, question answering, and many other tasks.
Key ideas
- A language model outputs a probability distribution over the next token given the previous ones.
- The chain rule turns next-token probabilities into the probability of a whole sequence.
- Generation is autoregressive: each sampled token is appended to the context.
- Training minimizes cross-entropy, which is −log p of the correct next token.
- Temperature, top-k, and top-p change how tokens are sampled, not what the model learned.
- Perplexity, the exponential of average cross-entropy, measures how well a model predicts held-out text.
Common questions
What is the difference between a language model and a large language model?
Nothing in the objective. A large language model (LLM) is a language model, almost always a decoder-only Transformer, with billions of parameters trained on trillions of tokens. Chat assistants add further training on instructions and human feedback on top of that base model.
What is the difference between causal and masked language modeling?
A causal language model predicts each token from the tokens before it, which is what GPT-style models do and what makes them able to generate text. A masked language model, like BERT, hides some tokens and predicts them from context on both sides. Masked models are better encoders for understanding tasks but cannot generate text left to right.
Why do language models make things up?
The training objective rewards text that is probable given the context, not text that is true. When the model lacks the fact it needs, a fluent and confident wrong continuation can still score as likely. Retrieval, tool use, and training that rewards saying "I don't know" reduce the problem but do not remove it.
What is bits per character?
It is cross-entropy measured in bits (log base 2) and divided by the number of characters instead of tokens. Because it does not depend on the tokenizer, it allows fair comparison between models that split text differently, which per-token perplexity does not.
Related explainers
- Tokenization & BPE — How text becomes numbers — from characters to subword tokens via byte-pair encoding
- Softmax, Logits & Temperature — Turning raw scores into probabilities
- Entropy & Cross-Entropy — Measuring surprise, uncertainty, and prediction quality
- Decoder-Only Transformers — The architecture behind GPT and modern LLMs
- The Transformer Architecture — A visual guide to 'Attention Is All You Need'
- BERT & Masked Language Modeling — Mask a word, predict it from both sides — how BERT learns deep bidirectional representations
References
- Bengio et al. (2003), "A Neural Probabilistic Language Model", JMLR
- Holtzman et al. (2019), "The Curious Case of Neural Text Degeneration"
- Kaplan et al. (2020), "Scaling Laws for Neural Language Models"
- Jurafsky & Martin, "Speech and Language Processing" (3rd ed. draft)
Last updated