arXiv(opens in a new tab)Computer ScienceAug 2023Cited by 55 papers on PaperVantageClassic Paper

Manuscript Offprint

arXiv:2308.03281

Towards General Text Embeddings with Multi-stage Contrastive Learning

Zehan Li, Xin Zhang, Yanzhao Zhang, Dingkun Long, Pengjun Xie, Meishan Zhang

Abstract

We present GTE, a general-purpose text embedding model trained with multi-stage contrastive learning. In line with recent advancements in unifying various NLP tasks into a single format, we train a unified text embedding model by employing contrastive learning over a diverse mixture of datasets from multiple sources. By significantly increasing the number of training data during both unsupervised pre-training and supervised fine-tuning stages, we achieve substantial performance gains over existing embedding models. Notably, even with a relatively modest parameter count of 110M, GTEbase_{base} outperforms the black-box embedding API provided by OpenAI and even surpasses 10x larger text embedding models on the massive text embedding benchmark. Furthermore, without additional fine-tuning on each programming language individually, our model outperforms previous best code retrievers of similar size by treating code as text. In summary, our model achieves impressive results by effectively harnessing multi-stage contrastive learning, offering a powerful and efficient text embedding model with broad applicability across various NLP and code-related tasks.¹

1 Introduction

Text embeddings have become an indispensable component in many natural language processing tasks, such as text classification, text retrieval, question answering and dialogue systems (Karpukhin et al., 2020; Humeau et al., 2020; Choi et al., 2021; Izacard et al., 2022a; Long et al., 2022a; Rajapakse, 2023). These embedding models represent texts using low-dimensional vectors and capture their similarity through vector operations. The emergence of recent large language models (LLMs) (Radford et al., 2018; Touvron et al., 2023; OpenAI, 2023) has generated considerable interest in retrieval-

Figure

Figure 1: Illustration of the multi-stage contrastive learning pipeline used to train our text embedding model.

augmented systems based on text embedding models that integrate the reasoning and comprehension capabilities of LLMs (Izacard et al., 2022b; Ram et al., 2023; Shi et al., 2023). Consequently, there has been a growing focus on general text representation in both industry and academia.

The pursuit of developing a unified model to address a multitude of downstream tasks has been long-standing due to the diverse formats, domains and downstream applications of natural language. The emergence of pre-trained language models has further opened up possibilities for training such a universal model. Nonetheless, within the realm of text representation research, previous text embedding models have primarily focused on specific tasks, and their training strategies or models, tailored to a single task, may not perform optimally in other contexts. For example, the text representation model SimCSE (Gao et al., 2021), trained on symmetric text pairs, demonstrates limitations in text retrieval tasks. Similarly, certain text representation models specifically designed for dense retrieval tasks do not exhibit robust performance in sentence textual similarity tasks. Recently, there has been a shift in research focus towards developing more comprehensive models for text representation leveraging large quantities of unlabeled web data through unsupervised contrastive pre-training, coupled with task-specific data, prompts, or instructions to mitigate task conflicts during fine-tuning (Ni et al., 2022a,b; Neelakantan et al., 2022;

¹The GTE model is publicly available at https://huggingface.co/thenlper/gte-large

Wang et al., 2022b; Su et al., 2023). Additionally, the introduction of benchmarks, such as the Massive Text Embedding Benchmark (MTEB) (Muenighoff et al., 2023), has established a robust basis for assessing the universality of text representation models. However, a significant limitation in existing research is the reliance on in-house data for pre-training, creating a bottleneck in the utilization of pre-trained model weights or APIs. Furthermore, the formulation of prompts specifically tailored for each task requires extra human effort during implementation (Su et al., 2023).

This work presents a straightforward approach to construct a general text embedding (GTE) model solely using contrastive learning on open-source data, as illustrated in Figure 1. Specifically, we first gather a large-scale dataset comprising unsupervised text pairs extracted from various data sources for contrastive pre-training. Surprisingly, our model, pre-trained on this dataset, exhibits remarkable performance, surpassing BM25 and E5 model (Wang et al., 2022b) in zero-shot text retrieval tasks and surpassing many supervised models in the MTEB benchmark. To further enhance the quality of the learned text representations, we obtain high-quality text pairs with human labels from multiple sources for contrastive fine-tuning. After supervised fine-tuning, our 110M BERT-based (Devlin et al., 2019) model already outperforms the current commercial embedding API of OpenAI and ranks highly in the MTEB benchmark. Furthermore, since our model is trained using code data as well, we evaluate its code search capabilities on the CodeSearchNet benchmark, which encompasses six programming languages. Notably, even without language-specific fine-tuning on each subset, our model significantly outperforms state-of-the-art code retrievers of similar size that have been fine-tuned for each programming language.

In the rest of this paper, we provide a detailed account of the data sources and training configurations employed. Subsequently, we present the evaluation results on widely recognized text embedding benchmarks and compare them with the performance of previous state-of-the-art baselines that were specifically optimized for each individual task. Our model consistently demonstrates superior performance or, at the very least, comparable results to those achieved by larger models, owing to its incorporation of a more diverse mixture of training datasets. We aspire for our model to serve as a robust baseline for the research community investigating text and code embedding.

References (16)

Cited by (55)