A Think Again Media Group publication
Bot Stumper

Is T5 a decoder-only model like GPT?

T5 architecture: two stacks, one text-to-text method

By Phil Springer, Editor · Published · Bot Stumper

T5 architecture: two stacks, one text-to-text method

T5 architecture begins with two connected stacks: an encoder that processes incoming text and a decoder that generates outgoing text. Google's Colin Raffel and colleagues introduced their Text-to-Text Transfer Transformer research in 2019. Their experiment made translation, summarization and classification share a common interface: a sequence of text as input and another sequence as output. Generating language did not require abandoning the encoder.

The structural precedent is visible in Ashish Vaswani and colleagues' 2017 Transformer design. Its encoder maps input symbols into continuous numerical representations. The decoder uses those representations while producing output symbols one at a time, with previously generated symbols supplying additional context. Both halves contain attention and feedforward layers. In the original base configuration, each stack has six layers. An encoder layer includes self-attention over the input followed by a position-wise feedforward network. The decoder has those operations plus attention over the encoder's output, giving it a separate route to information from the source sequence.

The two attention patterns serve different purposes. Encoder self-attention can connect positions throughout the input. Decoder self-attention masks later output positions, so a prediction depends on earlier output symbols rather than future ones. A further attention operation takes its queries from the decoder and its keys and values from the encoder. Thus the T5 architecture inherits a practical division: processing the source and extending the target are connected computations with different visibility rules. The Transformer design permits parallel work during training while retaining sequential generation at inference, when each new output symbol becomes context for the next.

Raffel's team trained this arrangement to reconstruct missing spans of text. Consecutive tokens were replaced by special sentinel markers, and the target contained the removed spans separated by corresponding markers. The encoder therefore received an incomplete passage; the decoder produced its missing material. For downstream tasks, textual prefixes specified the operation. Classification could produce a label written as text. The original experiments also shared a 32,000-piece vocabulary between input and output. Text-to-text described the task interface, while encoder-decoder described the machinery implementing it. Those are separate design decisions within the same system.

That vocabulary depended on another documented piece of machinery: SentencePiece, described by Taku Kudo and John Richardson in 2018. Their tokenizer learns subword units directly from raw sentences rather than requiring a preliminary division into words. This matters for languages whose writing does not separate every word with spaces. The software supports both byte-pair encoding and a unigram language-model approach to segmentation. A predetermined vocabulary size constrains how text is represented before it reaches a neural model. The operation turns character strings into pieces and numerical identifiers; it does not perform the contextual language processing assigned to a Transformer encoder.

SentencePiece also preserves whitespace through a special visible marker, allowing its decoder to reconstruct the normalized text from the encoded pieces. Its components include a normalizer, trainer, encoder and decoder. Here, encoder and decoder name reversible text-processing operations. In T5 architecture, the same words name learned neural-network stacks. Tokenizing a sentence and computing contextual representations of that sentence occur at different levels. Kudo and Richardson's explicit reconstruction rule makes the distinction concrete: their decoding reverses tokenization, whereas a language model's decoder generates a target sequence conditioned on its inputs.

The multilingual successor mT5 retained the sequence-to-sequence design. Linting Xue and colleagues described pretraining on mC4, a Common Crawl-derived collection covering 101 languages, and increased the SentencePiece vocabulary to 250,000 pieces. Their 2020 research identified an additional failure during transfer: a model fine-tuned on English could translate part of a prediction into an unintended language. They called this accidental translation. Mixing unlabeled pretraining examples into fine-tuning reduced the problem. The intervention changed the training mixture while preserving an encoder and decoder. Its results concern the language of generated outputs, rather than a change to a decoder-only system.

ByT5 tested a more radical change at the text boundary. In their 2021 research, Xue and colleagues fed UTF-8 bytes directly into a Transformer, removing the learned subword tokenizer. Their default design made the encoder three times as deep as the decoder. Byte sequences were longer than subword sequences, so the experiments compared training computation and inference speed as well as task scores. They also tested spelling-sensitive work and resilience to noisy text, reporting advantages on those measures. The T5 architecture could therefore accommodate a different input representation and an unequal allocation of layers without losing its two-part organization. ByT5's heavy encoder processed the byte stream; its lighter decoder still generated the target. The research altered where capacity was concentrated, while retaining the source-to-target connection that made text-to-text generation possible.

The Question

Google's T5 is a language model. Is it a decoder-only architecture like GPT, or does it separately encode the input before generating text?

Show the answer

The Answer

The architecture has two distinct parts: an encoder and a decoder. T5 isn't decoder-only at all — it's an encoder-decoder Transformer, built like the original Transformer. Google AI introduced T5 in 2019. The encoder reads and processes your input text; the decoder generates the output. Two distinct jobs, two distinct halves. It encodes first, then decodes, rather than predicting forward from a prompt like GPT. The distinction is in those two stages.

Send this question to a friend

Read next

By clicking “Send me a stumper” you agree to Bot Stumper’s Terms of Use and Privacy Policy.