D ialogue CSE : Dialogue-based Contrastive Learning of Sentence Embeddings (2021)

Abstract: Learning sentence embeddings from dialogues has drawn increasing attention due to its low annotation cost and high domain adaptability. Conventional approaches employ the siamese-network for this task, which obtains the sentence embeddings through modeling the context-response semantic relevance by applying a feed-forward network on top of the sentence encoders. However, as the semantic textual similarity is commonly measured through the element-wise distance metrics (e.g. cosine and L2 distance), such architecture yields a large gap between training and evaluating. In this paper, we propose DialogueCSE, a dialogue-based contrastive learning approach to tackle this issue. DialogueCSE first introduces a novel matching-guided embedding (MGE) mechanism, which generates a context-aware embedding for each candidate response embedding (i.e. the context-free embedding) according to the guidance of the multi-turn context-response matching matrices. Then it pairs each context-aware embedding with its corresponding context-free embedding and finally minimizes the contrastive loss across all pairs. We evaluate our model on three multi-turn dialogue datasets: the Microsoft Dialogue Corpus, the Jing Dong Dialogue Corpus, and the E-commerce Dialogue Corpus. Evaluation results show that our approach significantly outperforms the baselines across all three datasets in terms of MAP and Spearman’s correlation measures, demonstrating its effectiveness. Further quantitative experiments show that our approach achieves better performance when leveraging more dialogue context and remains robust when less training data is provided.

## introduction sentence embeddings are used with success for a variety of nlp applications @xcite and many prior methods have been proposed with different learning schemes. @xcite ; logeswaran and lee (2018); @xcite train sentence encoders in a self-supervised manner with web pages and books. @xcite ; @xcite ; @xcite propose to learn sentence embeddings on the supervised datasets such as snli @xcite and mnli @xcite . although the supervised-learning approaches achieve better performance, they suffer from high cost of annotation in building the training dataset, which makes them hard to adapt to other domains or languages. recently, learning sentence embeddings from dialogues has begun to attract increasing attention. dialogues provide strong semantic relationships among conversational utterances and are usually easy to collect in large amounts. such advantages make the dialogue-based self-supervised learning methods promising to achieve competitive or even superior performance against the supervised-learning methods, especially under the low-resource conditions. while promising, the issue of how to effectively exploit the dialogues for this task has not been sufficiently explored. @xcite propose to train an input-response prediction model on reddit dataset @xcite . since they build their architecture based on the single-turn dialogue, the multi-turn dialogue history is not fully exploited. @xcite demonstrate that introducing the multi-turn dialogue context can improve the sentence embedding performance. however, they concatenate the multi-turn dialogue context into a long token sequence, failing to model intersentence semantic relationships among the utterances. recently, more advanced methods such as @xcite achieve better performance by employing bert @xcite as the sentence encoder. these works have in common that they employ a feed-forward network with a non-linear activation on top of the sentence en-coders to model the context-response semantic relevance, thereby learning the sentence embeddings. however, such architecture presents two limitations: (1) it yields a large gap between training and evaluating, since the semantic textual similarity is commonly measured by the element-wise distance metrics such as cosine and l2 distance. (2) concatenating all the utterances in the dialogue context inevitably introduces the noise as well as the redundant information, resulting in a poor result. in this paper, we propose dialoguecse, a dialogue-based contrastive learning approach to tackle these issues. we hold that the semantic matching relationships between the context and the response can be implicitly modeled through contrastive learning, thus making it possible to eliminate the gap between training and evaluating. to this end, we introduce a novel matching-guided embedding (mge) mechanism. specifically, mge first pairs each utterance in the context with the response and performs a token-level dot-product operation across all the utterance-response pairs to obtain the multi-turn matching matrices. then the multi-turn matching matrices are used as guidance to generate a context-aware embedding for the response embedding (i.e. the context-free embedding). finally, the context-aware embedding and the context-free embedding are paired as a training sample, whose label is determined by whether the context and the response are originally from the same dialogue. our motivation is that once the context semantically matches the response, it has the ability to distill the context-aware information from the context-free embedding, which is exactly the learning objective of the sentence encoder that aims to produce context-aware sentence embeddings. we train our model on three multi-turn dialogue datasets: the microsoft dialogue corpus (mdc) @xcite , the jing dong dialogue corpus (jddc) @xcite , and the e-commerce dialogue corpus (ecd) @xcite . to evaluate our model, we introduce two types of tasks: the semantic retrieval (sr) task and the dialogue-based semantic textual similarity (d-sts) task. here we do not adopt the standard semantic textual similarity (sts) task @xcite for two reasons: (1) as revealed in @xcite , the sentence embedding performance varies greatly as the domain of the training data changes. as a dialogue dataset is always about several certain domains, evaluating on the sts benchmark may mis-lead the evaluation of the model. (2) the dialoguebased sentence embeddings focus on context-aware rather than context-free semantic meanings, which may not be suitable to be evaluated through the context-free benchmarks. since previous dialoguebased works have not set up a uniform benchmark, we construct two evaluation datasets for each dialogue corpus. a total of 18,964 retrieval samples and 4,000 sentence pairs are annotated by seven native speakers through the crowd-sourcing platform foot_0 . the evaluation results indicate that dialoguecse significantly outperforms the baselines on the three datasets in terms of both map and spearman's correlation metrics, demonstrating its effectiveness. further quantitative experiments show that dia-loguecse achieves better performance when leveraging more dialogue context and remains robust when less training data is provided. to sum up, our contributions are threefold: ## problem formulation suppose that we have a dialogue dataset @xmath0, where to generate the contrastive training pairs, we introduce two embedding matrices for r, named context-free embedding matrix and context-aware turn aggregation … transformer transformer … … bert … … transformer transformer … … bert … … transformer transformer … … bert … … … … bert … … transformer transformer … … bert … … … transformer transformer + -… aggregation contrastive loss matching-guided embedding sentence encoding i was thinking kung fu panda 3 for tomorrow afternoon. how many tickets will you be purchasing? 2 adult and 1 child would you like the standard showing or 3d? standard. … … session anytime after 7pm. embedding matrix. specifically, we first encode r as an embedding matrix r. since r is encoded independently of the dialogue context, it is treated as the context-free embedding matrix. then we generate a corresponding embedding matrix r based on r according to the guidance of c. r is treated as the context-aware embedding matrix. as c and r are derived from the same dialogue, ( r, r) naturally forms a positive training pair. to construct a negative training pair, we first sample an utterance r from a dialogue randomly selected from d. r is encoded as the context-free embedding matrix r based on which a context-aware embedding matrix r is generated through the completely identical process. ( r , r ) is treated as a negative training pair. for each response r, we generate a positive training pair (since there is only one ground-truth response for each context) and multiple negative training pairs. all the training pairs are then passed through the contrastive learning module. it is worth to mention that there is no difference between sampling the response or the context as they are symmetrical in constructing the negative training pairs. but we prefer the former as it is more straightforward and in accordance with the previous retrieval-based works for dialogues. with all the training samples at hand, our goal is to minimize their contrastive loss, thus fine-tuning bert as a context-aware sentence encoder. ## our approach figure 1 shows the model architecture. our model is divided into three stages: sentence encoding, matching-guided embedding, and turn aggregation. we describe each part as below. ## experiments we conduct experiments on three multi-turn dialogue datasets: the microsoft dialogue corpus (mdc) @xcite , the jing dong dialogue corpus (jddc) @xcite , and the ecommerce dialogue corpus (ecd) @xcite . each utterance in these three datasets is originally assigned with an intent label, which is further leveraged by us in the heuristic strategy to construct the evaluation datasets. ## conclusion in this work, we propose dialoguecse, a dialoguebased contrastive learning approach to learn sentence embeddings from dialogues. we also propose uniform evaluation benchmarks for evaluating the quality of the dialogue-based sentence embeddings. evaluation results show that dialoguecse achieves the best result over the baselines while adding no additional parameters. in the next step, we will study how to introduce more interaction information to learn the sentence embeddings and try to incorporate the contrast learning method into the pre-training stage.