NeuroGenesys.
Transformers & Language ModelsAcademy • Frontier • Lesson 1 of 4

Next-token prediction: what a language model is

8 min read • By Will Schulz • NeuroGenesys AI Academy

A language model is a probability distribution over sequences of text. In practice it is built from one narrow skill: given everything so far, predict the next token. This lesson explains why that single objective is enough to train a chat assistant, a code generator and a reasoning model, and what it costs at inference time.

The chain rule is the whole idea

Any joint distribution over a sequence x1,…,xTx_1,\dots,x_T can be factored exactly by the chain rule of probability:

p(x1,…,xT)=∏t=1Tp(xt∣x1,…,xt−1).p(x_1,\dots,x_T) = \prod_{t=1}^{T} p(x_t \mid x_1,\dots,x_{t-1}).

This is an identity, not an approximation. Modelling the joint distribution is therefore the same task as modelling every conditional p(xt∣x<t)p(x_t\mid x_{<t}). An autoregressive language model is a single function fθf_\theta that maps a prefix to a probability vector over a vocabulary VV:

pθ(⋅∣x<t)=softmax(fθ(x<t))∈Δ∣V∣−1.p_\theta(\cdot \mid x_{<t}) = \mathrm{softmax}\big(f_\theta(x_{<t})\big) \in \Delta^{|V|-1}.

The framing is old. In 1951 Claude Shannon had people guess English text letter by letter and estimated that, with long-range context, printed English carries about one bit per letter.[1] A language model plays Shannon's guessing game at scale.

Tokens, not words

The vocabulary is a set of tokens: subword units learned from data. The standard method adapts byte-pair encoding. It starts from characters or bytes and repeatedly merges the most frequent adjacent pair until the vocabulary reaches a target size.[2] Frequent words become single tokens, rare words split into pieces, and no input is ever out of vocabulary. Llama 3, for example, uses a 128,000-token vocabulary.[3] Tokenization is a design choice, not a law. Meta's Byte Latent Transformer works directly on bytes. It groups them into variable-length patches according to how hard the next byte is to predict, and the authors report better scaling than token-based models at fixed inference cost in their tests up to 8B parameters.[4]

From counting to learning

Before neural models, the conditionals were estimated by counting n-grams. That approach runs into a combinatorial wall. With a 128,000-token vocabulary, a trigram table has 128,0003≈2.1×1015128{,}000^3 \approx 2.1\times10^{15} cells, and almost all of them are never observed. Bengio and colleagues proposed the fix in 2003. They mapped each word to a learned dense vector and let a neural network compute the conditional from those vectors. Similar words then get similar vectors, so evidence from one sentence generalizes to many sentences the model has never seen.[5] Every modern language model keeps that structure: an embedding table, a network that mixes the context (today a transformer), and a softmax over the vocabulary.

The training objective, worked through

Training is maximum likelihood. Over a corpus, minimize the average negative log-probability of each actual next token:

L(θ)=−1T∑t=1Tlog⁡pθ(xt∣x<t).\mathcal{L}(\theta) = -\frac{1}{T}\sum_{t=1}^{T} \log p_\theta(x_t \mid x_{<t}).

This is the cross-entropy between the data and the model, and it is measured in nats when the log is natural. Perplexity is eLe^{\mathcal{L}}: the effective number of equally likely choices the model is hedging between.

Worked example. Take the prefix "The capital of France is". Suppose the model assigns these probabilities:

next token" Paris"" a"" the"everything else
pθp_\theta0.500.100.050.35

If the corpus continues with " Paris", the loss on this position is −ln⁡0.5=0.693-\ln 0.5 = 0.693 nats, which is exactly 1 bit. Now average over a four-token span where the model assigned 0.5, 0.9, 0.2 and 0.05 to the true tokens:

L=14(0.693+0.105+1.609+2.996)=1.351 nats,e1.351≈3.9.\mathcal{L} = \tfrac14\big(0.693 + 0.105 + 1.609 + 2.996\big) = 1.351 \text{ nats}, \qquad e^{1.351} \approx 3.9 .

On this span the model is about as uncertain as a fair choice among four options. Notice that one confident miss (0.05) contributes more than half the total. The log loss punishes overconfidence heavily.

Training is efficient for a structural reason. A causal mask stops each position from seeing the future (see attention), so a single forward pass over a sequence of TT tokens yields TT prediction problems at once. This is called teacher forcing: during training the model always conditions on the true prefix, never on its own earlier guesses.

Check your understanding

A model assigns probability 0.25 to every true next token in a test set. What are its loss in nats, its loss in bits, and its perplexity?

Show answer +

Loss =−ln⁡0.25=1.386= -\ln 0.25 = 1.386 nats =2= 2 bits, and perplexity =e1.386=4= e^{1.386} = 4. A uniform guess among four options gives exactly this, which is why perplexity is read as an "effective branching factor".

Generation: one token at a time

To generate text, sample xt∼pθ(⋅∣x<t)x_{t}\sim p_\theta(\cdot\mid x_{<t}), append it to the context and repeat. A temperature τ\tau reshapes the distribution before sampling:

pτ(i)=exp⁡(zi/τ)∑jexp⁡(zj/τ).p_\tau(i) = \frac{\exp(z_i/\tau)}{\sum_j \exp(z_j/\tau)} .

As τ→0\tau\to0 this becomes greedy decoding (always take the argmax). At τ=1\tau=1 it samples the model's own distribution, and larger τ\tau flattens it. Training is parallel across positions, but generation is sequential: every new token needs another full forward pass. That asymmetry drives most of the engineering in inference economics.

Why such a narrow objective goes so far

Predicting text well requires modelling whatever produced the text: grammar, facts, arithmetic, the intentions of characters in a story. That is the prediction-is-compression argument made concrete. The empirical case arrived with scale. GPT-2, a 1.5-billion-parameter model trained only on next-token prediction over web text, reached state-of-the-art results on 7 of 8 language-modelling benchmarks zero-shot, with no task-specific training.[6] GPT-3, at 175 billion parameters, could perform many tasks from a few examples placed in the prompt, again with no gradient updates.[7]

A pretrained base model continues documents. It is not yet an assistant. Post-training reshapes its distribution toward helpful answers. In the InstructGPT work, human raters preferred outputs from a 1.3B-parameter model fine-tuned on human feedback over outputs from the 175B GPT-3.[8] The objective at the bottom of the stack did not change. Post-training only changes which continuations the model makes likely. The reasoning and RL course covers that step.

What is changing (as of November 2026)

Next-token prediction remains the dominant pretraining objective, but three variations are active.

  • Predicting several tokens at once. Gloeckle et al. trained models with extra output heads that predict the next nn tokens from a shared trunk. They reported higher sample efficiency (their 13B models solved 12% more HumanEval coding problems than next-token baselines) and up to 3× faster inference when the extra heads drive speculative decoding.[9] DeepSeek-V3 used a multi-token prediction objective and reports that it improved benchmark performance.[10]
  • Non-autoregressive generation. Diffusion language models such as LLaDA learn to fill in masked tokens across the whole sequence and generate by iterative unmasking. Its authors report an 8B model competitive with Llama 3 8B.[11] These are the authors' own evaluations, and diffusion models have not displaced autoregressive models at the frontier.
  • Reasoning models. These are still next-token predictors. They are trained to emit long intermediate chains of tokens before answering, which moves cost from training to inference (see reasoning models).
Check your understanding

Why can a transformer be trained on all TT positions of a sequence in parallel but must generate those TT tokens one after another?

Show answer +

In training the true prefix is known, so a causal mask lets every position predict its successor in one pass (teacher forcing). In generation the prefix for step t+1t+1 includes the token sampled at step tt, which does not exist until step tt finishes, so the passes are serially dependent.

Key takeaways

  • By the chain rule, modelling p(text)p(\text{text}) is exactly modelling every next-token conditional. Nothing is lost in the factorization.
  • The training loss is cross-entropy, or average negative log-likelihood. Perplexity eLe^{\mathcal{L}} is its effective branching factor.
  • Learned dense representations (Bengio et al., 2003) are what let these models beat count-based n-grams.
  • Training parallelizes across positions. Generation is serial, one forward pass per token, which is why inference cost scales with output length.
  • Multi-token prediction, diffusion LMs and byte-level models are active variations. None has replaced next-token pretraining at the frontier.

Sources

  1. C. E. Shannon (1951). "Prediction and Entropy of Printed English." Bell System Technical Journal 30(1), 50–64. https://sites.socsci.uci.edu/~rfutrell/teaching/itl-davis/readings/shannon1951prediction.pdf ↩

  2. R. Sennrich, B. Haddow and A. Birch (2016). "Neural Machine Translation of Rare Words with Subword Units." ACL 2016. arXiv:1508.07909. https://arxiv.org/abs/1508.07909 ↩

  3. Llama Team, AI @ Meta (2024). "The Llama 3 Herd of Models." arXiv:2407.21783. https://arxiv.org/abs/2407.21783 ↩

  4. A. Pagnoni et al. (2024). "Byte Latent Transformer: Patches Scale Better Than Tokens." arXiv:2412.09871 (ACL 2025). https://arxiv.org/abs/2412.09871 ↩

  5. Y. Bengio, R. Ducharme, P. Vincent and C. Jauvin (2003). "A Neural Probabilistic Language Model." Journal of Machine Learning Research 3, 1137–1155. https://www.jmlr.org/papers/v3/bengio03a.html ↩

  6. A. Radford, J. Wu, R. Child, D. Luan, D. Amodei and I. Sutskever (2019). "Language Models are Unsupervised Multitask Learners." OpenAI. https://d4mucfpksywv.cloudfront.net/better-language-models/language_models_are_unsupervised_multitask_learners.pdf ↩

  7. T. B. Brown et al. (2020). "Language Models are Few-Shot Learners." arXiv:2005.14165. https://arxiv.org/abs/2005.14165 ↩

  8. L. Ouyang, J. Wu, X. Jiang et al. (2022). "Training language models to follow instructions with human feedback." arXiv:2203.02155. https://arxiv.org/abs/2203.02155 ↩

  9. F. Gloeckle, B. Y. Idrissi, B. Rozière, D. Lopez-Paz and G. Synnaeve (2024). "Better & Faster Large Language Models via Multi-token Prediction." ICML 2024. arXiv:2404.19737. https://arxiv.org/abs/2404.19737 ↩

  10. DeepSeek-AI (2024). "DeepSeek-V3 Technical Report." arXiv:2412.19437. https://arxiv.org/abs/2412.19437 ↩

  11. S. Nie, F. Zhu, C. Li et al. (2025). "Large Language Diffusion Models." arXiv:2502.09992. https://arxiv.org/abs/2502.09992 ↩

Leadership

A word from the founder — on why the brain is the blueprint, and why the next decade of intelligence will be built here.

"The brain is the universe's only proof that general intelligence is possible. We treat it as the blueprint."

From cortical interfaces to photonic silicon, every program at NeuroGenesys exists to answer one question: how does intelligence arise — and how do we build it safely.

Will Schulz

Will Schulz

Founder, NeuroGenesys • AW3 Technology