T5 Task Formatting › Worked Example: Tracing a Full Task Formatting Pipeline
Language AI HandbookAll chapters T5 Task Formatting › Worked Example: Tracing a Full Task Formatting PipelineOne section · Sections in this chapter8 / 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
To solidify how all these pieces fit together, let us trace through a complete end-to-end example. We will take a natural language inference problem from raw input through formatting and generation, then parse its output.
The task: Given the premise "The professor wrote equations on the whiteboard," determine whether the hypothesis "Someone taught a class" is entailed, neutral, or a contradiction.
Step 1: Format the input. We concatenate the task prefix with the hypothesis and premise in the T5 NLI format:
mnli hypothesis: Someone taught a class. premise: The professor wrote equations on the whiteboard.
Step 2: Tokenize. The tokenizer converts this string to a sequence of SentencePiece token IDs. The prefix words "mnli," "hypothesis," and "premise" are common enough to be single tokens or short sequences. The full input might tokenize to roughly 25-30 tokens.
Step 3: Encode. The T5 encoder processes all input tokens with full bidirectional attention. The encoder learns representations that capture the individual words and the logical relationship between the hypothesis and premise. The encoder has access to both the task prefix and the content simultaneously, so the representation of "professor wrote equations" is influenced by the knowledge that we are performing NLI.
Step 4: Decode. The decoder generates the output token by token. At the first decoding step, it attends to the entire encoder output through cross-attention and generates a probability distribution over the vocabulary. The top candidates at this step should be "entailment," "neutral," and "contradiction," because the model has learned to associate the "mnli" prefix with these output labels.
Step 5: Parse. The generated text "entailment" is returned. Our output parser checks it against the set of valid NLI labels and returns the structured result.
Reasoning check. The correct answer is "entailment" because professors writing equations on whiteboards is a form of teaching, and writing equations is a common activity in educational settings. A model that has learned these associations will assign high probability to "entailment." This reasoning relies on world knowledge absorbed during pre-training, not just pattern matching in the immediate context.
This trace reveals something important: the text-to-text format is a convenient interface, and it also shapes the entire computational process from encoding to decoding. The task prefix is not a post-hoc label. It conditions every step of the computation.