T5 (Text-To-Text Transfer Transformer) Model
What is T5?
T5 is a revolutionary pre-trained language model proposed by Google that solves all NLP tasks through a unified text-to-text framework.
Full name: Text-To-Text Transfer Transformer
Core Features
1. Encoder-Decoder Architecture
Combines an encoder and a decoder to achieve powerful sequence-to-sequence learning.2. The "Grand Unification" Idea
Unifies all NLP tasks as text-to-text conversion problems.3. Pre-training + Fine-tuning
Acquires general language understanding through large-scale pre-training.Why is T5 So Important?
- Unified framework: Classification, translation, summarization, and other tasks share the same format.
- Strong performance: Achieved state-of-the-art (SOTA) results on multiple NLP benchmarks.
- Simplified development: A single unified interface greatly simplifies model deployment and application.
translate English to French:— English-to-French translationsummarize:— text summarizationcola sentence:— grammatical acceptability judgmentstsb sentence1:— semantic similaritymnli premise:— natural language inferencequestion:— question answering- Unified interface — all tasks use the same input/output format, simplifying model design
- Parameter sharing — different tasks share model parameters, improving training efficiency
- Transfer learning — pre-trained knowledge transfers easily to downstream tasks
- Multi-task learning — training multiple tasks simultaneously improves generalization
- Role: Understand the input semantics
- Mechanism: Bidirectional attention for comprehensive input understanding
- Advantages:
- Parallel processing, high training efficiency
- Strong feature extraction capability
- Role: Generate the target text
- Mechanism: Autoregressive generation with Cross-Attention
- Advantages:
- Ensures coherent output
- Effectively uses input information
- Suitable for a wide range of generation tasks
- Bidirectional learning — predicts using both left and right context, learning deeper semantics
- Unsupervised — no manual annotation needed; can be trained on large corpora
- Reversible and lossless — token sequences can be fully restored to the original text
- Strong generalization — handles out-of-vocabulary (OOV) words well
The Grand Unification Idea
T5's core innovation: all NLP tasks are unified into the form "text input → text output".
Task Examples
| Task Type | Input Example | Output Example | |---------|---------|---------| | Text classification | classify sentiment: This product is really great! | positive | | Machine translation | translate English to Chinese: How are you? | (Chinese translation) | | Summarization | summarize: [long text...] | [summary] | | Question answering | question: What is T5's full name? context: [...] | Text-To-Text Transfer Transformer | | Text generation | generate: write a poem about spring | (a poem) |
Task Prefix System
Through unified task prefixes, T5 can understand and execute many different NLP tasks:
Advantages of the Unified Framework
Encoder-Decoder Architecture
T5 adopts the classic Encoder-Decoder structure.
Encoder
Decoder
Data Flow
1. Tokenization — the input text is tokenized 2. Encoder processing — semantics are understood via Self-Attention 3. Encoder-Decoder interaction — the Decoder attends to Encoder outputs via Cross-Attention 4. Decoder generation — target tokens are generated one by one 5. Output — the complete translation/generation result is produced
Pre-training Task: MLM
T5 uses a masked language model (MLM) objective for pre-training.
How MLM Works
1. Initialize a character-level vocabulary — start from basic characters 2. Random masking — randomly select ~15% of tokens to mask 3. Model prediction — predict masked tokens using surrounding context 4. Iterative merging — count character-pair frequencies and merge the most common pairs