Sub topic 1
Summarisation and Translation as Text-to-Text Problems
Prerequisites
This chapter assumes basic Python, familiarity with neural networks and loss functions, and a high-level understanding of Transformers and self-attention. You should also know that a token is a small piece of text, such as a word, part of a word, or punctuation mark.
One interface, two tasks
Summarisation and translation look different to a user, but an encoder-decoder model can treat both as the same kind of problem:
- Read a source sequence.
- Build an internal representation of that sequence.
- Generate a target sequence one token at a time.
A sequence is an ordered list of tokens. In summarisation, the source is usually a long document and the target is a shorter text in the same language. In translation, the source and target use different languages, but the input-output shape is the same.
The model learns a conditional probability:
P(target sequence | source sequence)
This means “the probability of a target, given the source.” During generation, the model chooses a likely next token based on the source and the target tokens it has already produced.
flowchart TD
A[Source text] --> B[Encoder-decoder model]
B --> C[Target text]
A --> D[Summarisation task]
D --> C
A --> E[Translation task]
E --> CThe same general model interface can therefore support both tasks. The task is defined by the training examples, the model checkpoint, or an instruction in the input.
The source and target sequences
Training data is commonly represented as pairs:
| Task | Source sequence | Target sequence |
|---|---|---|
| Summarisation | Full news article | Short article summary |
| Translation | English sentence | German sentence |
For summarisation, a training pair might contain a document about a council decision and a reference summary written by an editor. For translation, it might contain an English sentence and its professionally translated German equivalent.
The target is not necessarily a shortened or copied version of the source. A translation changes the language while preserving meaning. An abstractive summary can paraphrase the source and combine information from several sentences. This differs from extractive summarisation, which selects existing sentences or phrases.
A model does not receive a complete target during normal generation. It starts with a special beginning token, predicts the first target token, and then uses that prediction to help choose the next token. It continues until it produces an end token or reaches a length limit. The later chapter on decoding explains how different search strategies affect these choices.
Making the task explicit
Some model families use a task prefix. A prefix is text placed before the input to identify the requested operation. For example, T5 can use prefixes such as summarize: and translate English to German:.
Other checkpoints are trained for one main purpose. A BART checkpoint fine-tuned on news summarisation expects documents and produces summaries. A MarianMT checkpoint normally represents one specific language pair, such as English to German. The model name and documentation are therefore part of the task configuration.
The following example shows the data framing without loading a neural model:
examples = [
{
"task": "summarise",
"source": "The council approved a plan to add 40 kilometres of bike lanes.",
"target": "The council approved 40 km of new bike lanes.",
},
{
"task": "translate English to German",
"source": "The house is wonderful.",
"target": "Das Haus ist wunderbar.",
},
]
for example in examples:
print(f"Task: {example['task']}")
print(f"Input: {example['source']}")
print(f"Output: {example['target']}")
print()The source field is what the encoder reads. The target field is the desired output during training or evaluation. At prediction time, you provide the source and task information, but not the target.
This framing also clarifies evaluation. A summary is compared with one or more reference summaries. A translation is compared with reference translations in the target language. The next chapters will cover how the model architecture connects the source to the generated target.
Exercise
A model receives a French paragraph and produces an English paragraph. Which part is the source sequence, and which part is the target sequence?
Show answer
The French paragraph is the source sequence because it is the input. The English paragraph is the target sequence because it is the generated output.