T5 Task Formatting › Multitask Training

Michael BrenndoerferOctober 15, 20255 min read
Language AI HandbookAll chapters
Part 25 of 67Encoder-Decoder Models
Chapter 179T5 Task Formatting › Multitask Training
Reading section 11 of 15 · Multitask Training · 5 minSection 11 of 15 · 5 min

Book contents

Section 11 of 15 · 5 min read

T5 Task Formatting › Multitask TrainingOne section · Sections in this chapter11 / 15 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

A key consequence of unified task formatting is the ability to train on multiple tasks simultaneously. This forms a different training paradigm: learning one task can improve performance on others through positive transfer. When all tasks use the same input-output format, they can be mixed freely in the same training batch without any changes to the training loop.

Think of multitask training as cross-training for a language model. A runner who only trains on flat ground may be fast on flat courses but struggle on hills. A runner who trains on both hills and flat surfaces develops leg strength and cardiovascular fitness that transfers between environments. Similarly, a model that trains only on sentiment classification learns to identify opinion words and sentence-level sentiment polarity. A model that also trains on translation develops a deeper understanding of semantic equivalence across languages, which benefits its sentiment understanding. A model that trains on QA develops reasoning skills that benefit its comprehension across all tasks.

In[37]:
Code
# Multitask training batch
multitask_batch = [
    # Translation
    {
        "input": "translate English to German: Hello world",
        "output": "Hallo Welt",
    },
    # Classification
    {"input": "sst2 sentence: Great movie!", "output": "positive"},
    # Summarization
    {
        "input": "summarize: Long article about climate change...",
        "output": "Climate change accelerates...",
    },
    # QA
    {
        "input": "question: What year? context: Founded in 1998.",
        "output": "1998",
    },
]

# All examples use the same model, loss function, and update procedure
Out[38]:
Visualization
Pie chart showing the proportional distribution of tasks in T5's multitask training data, including translation, summarization, question answering, classification, and other tasks.
Approximate task proportions in T5's multitask training data, showing that translation and summarization receive larger data shares while classification and NLI contribute smaller but important fractions.
Horizontal bar chart illustrating the composition of a sample training batch, showing the counts of translation, classification, summarization, and question-answering examples.
Composition of a sample training batch illustrating how different tasks are mixed together, with translation and classification examples appearing more frequently than summarization and QA in this batch.

T5's original training mixed examples from many tasks, with task proportions tuned to balance learning across all tasks. This multitask setup lets the model to develop reliable representations that transfer across tasks. Skills learned from translation help summarization because both require understanding semantic equivalence. Reasoning developed through QA improves NLI performance because both require logical inference. The shared encoder learns representations that capture linguistic information useful across all tasks, while the decoder learns flexible generation strategies that adapt to different output formats based on the prefix.

The intuition behind why multitask learning helps is that different tasks emphasize different aspects of language understanding. Translation forces the model to deeply understand semantics in order to preserve meaning across languages. Summarization teaches the model to identify salient information and compress it without losing key facts. QA develops fact retrieval and reasoning. Classification hones sensitivity to document-level properties such as sentiment and topic, including stylistic properties. When these tasks share parameters, the model must develop representations that serve all these needs simultaneously. Such representations tend to be richer and more generalizable than those learned for any single task.

Task proportions in multitask training are not arbitrary. T5's authors experimented with different mixing strategies and found that equal mixing does not necessarily yield the best results. Tasks with large datasets, like translation, can dominate if examples are mixed uniformly, potentially causing the model to over-optimize for those tasks at the expense of smaller tasks. Strategies like temperature-based mixing, where task sampling probability is adjusted by a temperature parameter, allow practitioners to balance learning across tasks of different sizes. This is an important hyperparameter in T5-style multitask training that deserves careful tuning for any custom application.