On the Sentence Embeddings from Pre-trained Language Models (2020)

Abstract: Pre-trained contextual representations like BERT have achieved great success in natural language processing. However, the sentence embeddings from the pre-trained language models without fine-tuning have been found to poorly capture semantic meaning of sentences. In this paper, we argue that the semantic information in the BERT embeddings is not fully exploited. We first reveal the theoretical connection between the masked language model pre-training objective and the semantic similarity task theoretically, and then analyze the BERT sentence embeddings empirically. We find that BERT always induces a non-smooth anisotropic semantic space of sentences, which harms its performance of semantic similarity. To address this issue, we propose to transform the anisotropic sentence embedding distribution to a smooth and isotropic Gaussian distribution through normalizing flows that are learned with an unsupervised objective. Experimental results show that our proposed BERT-flow method obtains significant performance gains over the state-of-the-art sentence embeddings on a variety of semantic textual similarity tasks. The code is available at https://github.com/bohanli/BERT-flow .

## introduction recently, pre-trained language models and its variants @xcite @xcite like bert @xcite have been widely used as representations of natural language. despite their great success on many nlp tasks through fine-tuning, the sentence embeddings from bert without finetuning are significantly inferior in terms of semantic textual similarity @xcite -for example, they even underperform the glove @xcite embeddings which are not contextualized and trained with a much simpler model. such issues hinder applying bert sentence embeddings directly to many real-world scenarios where collecting labeled data is highlycosting or even intractable. in this paper, we aim to answer two major questions: (1) why do the bert-induced sentence embeddings perform poorly to retrieve semantically similar sentences? do they carry too little semantic information, or just because the semantic meanings in these embeddings are not exploited properly? (2) if the bert embeddings capture enough semantic information that is hard to be directly utilized, how can we make it easier without external supervision? towards this end, we first study the connection between the bert pretraining objective and the semantic similarity task. our analysis reveals that the sentence embeddings of bert should be able to intuitively reflect the semantic similarity between sentences, which contradicts with experimental observations. inspired by @xcite who find that the language modeling performance can be limited by the learned anisotropic word embedding space where the word embeddings occupy a narrow cone, and @xcite who find that bert word embeddings also suffer from anisotropy, we hypothesize that the sentence embeddings from bert -as average of context embeddings from last layers 1 -may suffer from similar issues. through empirical probing over the embeddings, we further observe that the bert sentence embedding space is semantically non-smoothing and poorly defined in some areas, which makes it hard to be used directly through simple similarity metrics such as dot product or cosine similarity. to address these issues, we propose to transform the bert sentence embedding distribution into a smooth and isotropic gaussian distribution through normalizing flows @xcite , which is an invertible function parameterized by neural networks. concretely, we learn a flow-based generative model to maximize the likelihood of generating bert sentence embeddings from a standard gaussian latent variable in a unsupervised fashion. during training, only the flow network is optimized while the bert parameters remain unchanged. the learned flow, an invertible mapping function between the bert sentence embedding and gaussian latent variable, is then used to transform the bert sentence embedding to the gaussian space. we name the proposed method as bert-flow. we perform extensive experiments on 7 standard semantic textual similarity benchmarks without using any downstream supervision. our empirical results demonstrate that the flow transformation is able to consistently improve bert by up to 12.70 points with an average of 8.16 points in terms of spearman correlation between cosine embedding similarity and human annotated similarity. when combined with external supervision from natural language inference tasks @xcite , our method outperforms the sentence-bert embeddings @xcite , leading to new state-of-theart performance. in addition to semantic similarity tasks, we apply sentence embeddings to a question-answer entailment task, qnli @xcite , directly without task-specific supervision, and demonstrate the superiority of our approach. moreover, our further analysis implies that bert-induced similarity can excessively correlate with lexical similarity compared to semantic similarity, and our proposed flow-based method can effectively remedy this problem. ## understanding the sentence embedding space of bert to encode a sentence into a fixed-length vector with bert, it is a convention to either compute an average of context embeddings in the last few layers of bert, or extract the bert context embedding at the position of the [cls] token. note that there is no token masked when producing sentence embeddings, which is different from pretraining. @xcite demonstrate that such bert sentence embeddings lag behind the state-of-the-art sentence embeddings in terms of semantic similarity. on the sts-b dataset, bert sentence embeddings are even less competitive to averaged glove @xcite embeddings, which is a simple and non-contextualized baseline proposed several years ago. nevertheless, this incompetence has not been well understood yet in existing literature. note that as demonstrated by @xcite , averaging context embeddings consistently outperforms the [cls] embedding. therefore, unless mentioned otherwise, we use average of context embeddings as bert sentence embeddings and do not distinguish them in the rest of the paper. ## proposed method: bert-flow to verify the hypotheses proposed in section 2.2, and to circumvent the incompetence of the bert sentence embeddings, we proposed a calibration method called bert-flow in which we take advantage of an invertible mapping from the bert embedding space to a standard gaussian latent space. the invertibility condition assures that the mutual information between the embedding space and the data examples does not change. ## experiments to verify our hypotheses and demonstrate the effectiveness of our proposed method, in this section we present our experimental results for various tasks related to semantic textual similarity under multiple configurations. for the implementation details of our siamese bert models and flow-based models, please refer to appendix b. ## conclusion and future work in this paper, we investigate the deficiency of the bert sentence embeddings on semantic textual similarity, and propose a flow-based calibration which can effectively improve the performance. in the future, we are looking forward to diving in representation learning with flow-based generative models from a broader perspective.