Reading preferences
Concept

Language Models and Attention

Connect next-token prediction, sequence-to-sequence tasks, and attention.

artificial intelligence, language models, attention, sequence

Predict a continuation

A language model estimates probabilities for tokens given context. If a toy model gives “tea” probability 0.6 and “milk” probability 0.4 after “drink”, “tea” is more likely under that model; the probabilities are illustrative, not universal facts. A generated sequence can be built one token at a time, although language models can also be used in other ways.

Translate with a sequence model

  1. An encoder represents an input sequence such as “red house”.
  2. A decoder produces an output sequence, one token at a time; it need not have the same number of tokens as the input.
  3. Attention can weight input representations differently at each output step, helping the decoder use relevant context. A high weight is not a complete explanation of the model's decision.

See the reasoning

Follow the example one step at a time

Follow a simplified sequence-to-sequence translation. This is a prepared teaching demonstration, not live code execution.

Encode

input: red | house
→ input representations

The encoder produces representations of the input sequence.

Why context matters

Sequence-to-sequence models are used for translation and other transformations. Earlier encoder-decoder models used recurrent networks; attention improved their ability to access different input positions. Transformers use attention as a central building block, explored later in this module.

Probable and fluent output is not necessarily accurate. Tokenisation, training data, context limits, decoding choices and language differences affect behaviour. Evaluate outputs against appropriate references and real task outcomes, including cases where the model should say it is unsure.

Reflect on the concept

Four fixed questions to reinforce the reasoning. Answers are not saved or scored.

1. What can a language model estimate?
2. What is a sequence-to-sequence task?
3. What can attention do while producing an output?
4. Does a likely next token guarantee a true answer?

References and further reading