Abstract
We provide the first exploration of sentence embeddings from text-to-text transformers (T5). Sentence embeddings are broadly useful for language processing tasks. While T5 achieves impressive performance on language tasks cast as sequence-to-sequence mapping problems, it is unclear how to produce sentence embeddings from encoder-decoder models. We investigate three methods for extracting T5 sentence embeddings: two utilize only the T5 encoder and one uses the full T5 encoder-decoder model. To support our investigation, we establish a new sentence representation transfer benchmark, SentGLUE, which extends the SentEval toolkit to nine tasks from the GLUE benchmark. Our encoder-only models outperform Sentence-BERT and SimCSE sentence embeddings on both SentEval and SentGLUE transfer tasks, including semantic textual similarity (STS). Scaling up T5 from millions to billions of parameters is found to produce consistent further improvements. Finally, our encoder-decoder method achieves a new state-of-the-art on STS when using sentence embeddings.
Introduction
While encoder-only models like BERT and RoBERTa have been successfully adapted into high-performance sentence encoders (e.g., SBERT, SimCSE), the T5 (Text-to-Text Transfer Transformer) model remained relatively unexplored for this purpose. T5's success in sequence-to-sequence tasks is well-documented, but its encoder-decoder architecture presents a challenge: unlike BERT, which features a dedicated [CLS] token for sentence-level representations, T5 is designed for text generation. This research investigates how to effectively condense T5's output into a single mathematical vector and whether the "bigger is better" scaling trend observed in generative models applies to sentence embeddings.
Methods: Extracting Embeddings from T5
The researchers explored three primary strategies to extract a single embedding vector from the T5 architecture:
- Encoder-only first: Utilizing the representation of the first token from the encoder.
- Encoder-only mean: Averaging all token representations from the encoder (mean pooling).
- Encoder-Decoder first: Feeding the input to the encoder and extracting the first output token from the decoder.
To optimize these embeddings, the models were trained using a Dual Encoder setup with a two-stage contrastive learning recipe. The first stage involves training on 2 billion question-answer pairs from community forums to learn semantic proximity. The second stage fine-tunes the model on Natural Language Inference (NLI) data, pulling "entailment" pairs together and pushing "contradiction" pairs apart in the vector space.
Evaluation and Benchmarking
The models were evaluated using two main frameworks:
- SentEval: The industry standard for evaluating sentence embeddings across transfer tasks (classification) and Semantic Textual Similarity (STS).
- SentGLUE: A new benchmark introduced in this paper that adapts the GLUE benchmark to a sentence embedding format. By requiring models to encode sentences independently before classification, SentGLUE prevents models from relying on cross-attention, providing a truer measure of embedding quality.
Key Results and Scaling
The study reveals that scaling T5 from millions to billions of parameters yields consistent performance gains. The ST5-EncDec (11B) model achieved a new state-of-the-art Spearman’s correlation of 84.96 on STS tasks, outperforming previous leaders like SimCSE-RoBERTa. For transfer tasks, the ST5-Enc (11B) variant proved superior, reaching an average accuracy of 91.63 on SentEval.
Key insights include:
- Mean Pooling Efficiency: For encoder-only variants, mean pooling significantly outperforms using the first token.
- The Decoder Advantage: While encoders excel at classification, the encoder-decoder structure acts as a sophisticated attention pooler, capturing more nuanced relationships for similarity tasks.
- Anisotropy Mitigation: Contrastive learning effectively addresses "embedding collapse," where embeddings occupy too narrow a space, ensuring a more uniform and discriminative embedding field.
Conclusion
Sentence-T5 demonstrates that the benefits of scaling large language models extend directly to sentence representation learning. By successfully adapting the T5 architecture, the researchers have provided a scalable, high-performance alternative to BERT-based encoders, setting new benchmarks for both semantic similarity and transfer learning tasks.
Summary updated