Year: 2021

Abstract:
In NLP, a large volume of tasks involve pairwise comparison between two sequences (e.g., sentence similarity and paraphrase identification). Predominantly, two formulations are used for sentence-pair tasks: bi-encoders and cross-encoders. Bi-encoders produce fixed-dimensional sentence representations and are computationally efficient, however, they usually underperform cross-encoders. Crossencoders can leverage their attention heads to exploit inter-sentence interactions for better performance but they require task finetuning and are computationally more expensive. In this paper, we present a completely unsupervised sentence-pair model termed as TRANS-ENCODER that combines the two learning paradigms into an iterative joint framework to simultaneously learn enhanced biand crossencoders. Specifically, on top of a pre-trained language model (PLM), we start with converting it to an unsupervised bi-encoder, and then alternate between the biand cross-encoder task formulations. In each alternation, one task formulation will produce pseudo-labels which are used as learning signals for the other task formulation. We then propose an extension to conduct such self-distillation approach on multiple PLMs in parallel and use the average of their pseudo-labels for mutual-distillation. TRANS-ENCODER creates, to the best of our knowledge, the first completely unsupervised cross-encoder and also a state-of-the-art unsupervised bi-encoder for sentence similarity. Both the bi-encoder and cross-encoder formulations of TRANSENCODER outperform recently proposed state-of-the-art unsupervised sentence encoders such as Mirror-BERT (Liu et al., 2021) and SimCSE (Gao et al., 2021) by up to 5% on the sentence similarity benchmarks.

text: In NLP, a large volume of tasks involve pairwise comparison between two sequences (e.g., sentence similarity and paraphrase identification). Predominantly, two formulations are used for sentence-pair tasks: bi-encoders and cross-encoders. Bi-encoders produce fixed-dimensional sentence representations and are computationally efficient, however, they usually underperform cross-encoders. Crossencoders can leverage their attention heads to exploit inter-sentence interactions for better performance but they require task finetuning and are computationally more expensive. In this paper, we present a completely unsupervised sentence-pair model termed as TRANS-ENCODER that combines the two learning paradigms into an iterative joint framework to simultaneously learn enhanced bi- and crossencoders. Specifically, on top of a pre-trained language model (PLM), we start with converting it to an unsupervised bi-encoder, and then alternate between the bi- and cross-encoder task formulations. In each alternation, one task formulation will produce pseudo-labels which are used as learning signals for the other task formulation. We then propose an extension to conduct such self-distillation approach on multiple PLMs in parallel and use the average of their pseudo-labels for mutual-distillation. TRANS-ENCODER creates, to the best of our knowledge, the first completely unsupervised cross-encoder and also a state-of-the-art unsupervised bi-encoder for sentence similarity. Both the bi-encoder and cross-encoder formulations of TRANSENCODER outperform recently proposed state-of-the-art unsupervised sentence encoders such as Mirror-BERT (Liu et al., 2021) and SimCSE (Gao et al., 2021) by up to 5% on the sentence similarity benchmarks.

heading: 1 INTRODUCTION
text: Comparing pairwise sentences is fundamental to a wide spectrum of tasks in NLP such as information retrieval (IR), natural language inference (NLI), semantic textual similarity (STS) and clustering. Two general architectures usually used for sentence-pair modelling are bi-encoders and cross-encoders.
In a cross-encoder, two sequences are concatenated and sent into the model (usually deep Transformers like BERT/RoBERTa; Devlin et al. 2019; Liu et al. 2019) in one pass. The attention heads of Transformers could directly model the inter-sentence interactions and output a classification/relevance score. However, a cross-encoder needs to recompute the encoding for different combinations of sentences in each unique sequence pair, resulting in a heavy computational overhead. It is thus impractical in tasks like IR and clustering where massive pairwise sentence comparisons are involved. Also, task finetuning is always required for converting PLMs to cross-encoders. By contrast, in a bi-encoder, each sequence is encoded separately and mapped to a common embedding space for similarity comparison. The encoded sentences can be cached and reused. A bi-encoder is thus much more efficient. Also, the output of a bi-encoder can be used off-the-shelf as sentence embeddings for other downstream tasks. That said, it is well-known that in supervised learning, bi-encoders underperform cross-encoders (Humeau et al., 2020; Thakur et al., 2021) since the former could not explicitly model the interactions between sentences but could only compare them in the embedding space in a post hoc manner.
In this work, we ask the question: can we leverage the advantages of both bi- and cross-encoders and bootstrap knowledge from them in an unsupervised manner? Our proposed TRANS-ENCODER addresses this question with the following intuition: As a starting point, we can use bi-encoder representations to tune a cross-encoder. With more powerful inter-sentence modelling, the crossencoder should resurface more knowledge from the PLMs than the bi-encoder given the same data. In turn, the more powerful cross-encoder can distil its knowledge back to the bi-encoder. We can repeat this cycle to iteratively bootstrap from both the bi- and cross-encoders.

heading: 2 TRANS-ENCODER
text: The general idea of TRANS-ENCODER is simple yet extremely effective. In §2.1, we first transform an off-the-shelf PLM to a strong bi-encoder, serving as an initialisation point. Then, the bi-encoder produces pseudo-labels and the PLM subsequently learns from these pseudo-labels in a cross-encoder manner (§2.2). Consecutively, the cross-encoder further produces more accurate pseudo-labels for bi-encoder learning (§2.3). This self-distillation process is visualised in Fig. 1. Then in, §2.4, we propose a further extension called mutual-distillation that stabilises the training process and boosts the encoder performance even more.

heading: 2.1 TRANSFORM PLMS INTO EFFECTIVE BI-ENCODERS
text: Off-the-shelf PLMs are unsatisfactory bi-encoders.1 To have a reasonably good starting point, we leverage a simple contrastive tuning procedure to transform existing PLMs to bi-encoders. This approach is concurrently proposed in both (Liu et al., 2021) and (Gao et al., 2021).
Let f(·) denote the encoder model (a Transformer-based model); X be a batch of randomly sampled raw sentences. For any sentence xi ∈ X , we send it to the encoder twice to create two views of the same data point: f(xi) and f(xi). Note that the two encodings slightly differ due to the dropout layers in the encoder.2 We then use the standard InfoNCE loss (Oord et al., 2018) to cluster the positive pairs together and push away the negative pairs in the mini-batch:
LinfoNCE = − |X |∑ i=1 log exp(cos(f(xi), f(xi))/τ)∑
xj∈Ni
exp(cos(f(xi), f(xj))/τ) . (1)
τ denotes a temperature parameter; Ni denotes all negatives of xi within the current data batch, which includes all xj , xj where i ̸= j (i.e., |Ni| = 2|X | − 2). Intuitively, the numerator is the similarity of the self-duplicated pair (the positive example) and the denominator is the sum of the similarities
1In this work, a bi-encoder is the same as a universal text encoder. When embedding a pair of sentences under the bi-encoder architecture, the same encoder is used (i.e., the two-branches of bi-encoder share weights).
2Mirror-BERT has the option to also randomly mask a span in xi and using drophead (Zhou et al., 2020) to replace dropout as hidden states augmentation.
between xi and all other negative strings besides xi. The loss encourages the positive pairs to be relatively close compared to the negative ones. In experiments, we use checkpoints released by SimCSE and Mirror-BERT. But in principle, any techniques could be used here as long as the method serves the purpose of transforming BERT to an effective bi-encoder and does not require additional labelled data (see §6).

heading: 2.2 SELF-DISTILLATION: BI- TO CROSS-ENCODER
text: After obtaining a sufficiently good bi-encoder, we leverage it to label sentence pairs sampled from the task of interest. Specifically, for a given sentence-pair (sent1, sent2), we input them to the bi-encoder separately and get two embeddings (we use the embedding of [CLS] from the last layer). The cosine similarity between them is regarded as their relevance score. In this way we have constructed a self-labelled sentence-pair scoring dataset in the format of (sent1, sent2, score).
We then employ the same model architecture to learn from these score, but with a cross-encoder formulation. The cross-encoder weights are initialised from the original PLM.3 For the sentence-pair (sent1, sent2), we concatenate them to produce “[CLS] sent1 [SEP] sent2 [SEP]” and input it to the cross-encoder. A linear layer (newly initialised) then map the sequence’s encoding (embedding of the [CLS] token) to a scalar. The learning objective of the cross-encoder is minimising the KL divergence between its predictions and the self-labelled scores from the bi-encoder. This is equivalent to optimising the (soft) binary cross-entropy (BCE) loss:
LBCE = − 1
N N∑ n=1 ( yn · log(σ(xn)) + (1− yn) · log(1− σ(xn)) ) (2)
where N is the data-batch size; σ(·) is the sigmoid activation; xn is the prediction of the cross-encoder; yn is the self-labelled ground-truth score from the bi-encoder.
Note that while the cross-encoder is essentially learning from the data produced by itself (in a bi-encoder form), usually, it outperforms the original bi-encoder on held-out data. The cross-encoder directly discovers the similarity between two sentences through its attention heads, finding more accurate cues to justify the relevance score. The ability of discovering such cues could then generalise to unseen data, resulting in stronger sentence-pair scoring capability than the original bi-encoder. From a knowledge distillation perspective, we can view the bi- and cross-encoder as the teacher and student respectively. In this case the student outperforms the teacher, not because of stronger model capacity, but smarter task formulation. By leveraging this simple yet powerful observation, we are able to design a learning scheme that iteratively boosts the performance of both bi- and cross-encoder.

heading: 2.3 SELF-DISTILLATION: CROSS- TO BI-ENCODER
text: With the more powerful cross-encoder at hand, a natural next step is distilling the extra gained knowledge back to a bi-encoder form, which is more useful for downstream tasks. Besides, and more importantly, a better bi-encoder could produce even more self-labelled data for cross-encoder learning. In this way we could repeat §2.2 and §2.3, continually bootstrapping the encoder performance.
We create the self-labelled sentence-scoring dataset in the same way as §2.2 except that the crossencoder is used for producing the relevance score. The bi-encoder is initialised with the weights after SimCSE training from §2.1.4 For every sentence pair, two sentence embeddings are produced separately by the bi-encoder. The cosine similarity between the two embeddings are regarded as their predictions of the relevance score. The aim is to regress the predictions to the self-labelled scores by the cross-encoder. We use a mean square error (MSE) loss:
LMSE = − 1
N N∑ n=1 ( xn − yn )2 (3)
3We have a design choice to make here, we could either (1) directly use the weights of the bi-encoder or (2) use the weights of the original PLM. We will show in experiments (§5.2) that (2) is slightly better than (1).
4Again, we have the choice of using the cross-encoder weights from §2.2 (the extra linear layer is disregarded). We will discuss more in experiments.
where N is the batch size; xn is the cosine similarity between a sentence pair; yn is the self-labelled ground-truth. In experiments, we will show that this resulting bi-encoder is more powerful than the initial bi-encoder. Sometimes, the bi-encoder will even outperform its teacher (i.e., the cross-encoder).
Choice of loss functions: maintaining student-teacher discrepancy is the key. Intuitively, MSE allows for more accurate distillations since it punishes any numerical discrepancies between predicted scores and labels on the instance level. However, in practice, we found that using MSE for bi-tocross distillation aggravates the overfitting issue for cross-encoder: the cross-encoder, with its strong sentence-pair modelling capability, completely overfits to the mapping between concatenated sentence pairs and the pseudo scores. This elimination of discrepancy between model predictions and pseudo labels harms generalisation and the iterative learning cycle cannot continue (as the predicted scores by the student model will be the same as the teacher model). We thus use BCE loss for bi-to-cross since BCE is a more forgiving loss function compared with MSE. According to our gradient derivation (App. §A.2), BCE essentially is a temperature-sharpened version of MSE, which is more tolerant towards numerical discrepancies. This prevents cross-encoders from overfitting to the pseudo labels completely. Similar issue does not exist for the cross-to-bi distillation as for bi-encoders, two input sequences are separately encoded and the model does not easily overfit to the labels. We have a more thorough discussion in App. §A.2 and Tab. 8 to highlight the rationales of the current configuration.

heading: 2.4 MUTUAL-DISTILLATION
text: The aforementioned self-learning approach has a drawback: since the model regresses to its previous predictions, it tends to reinforce its errors. To mitigate this problem, we design a simple mutualdistillation approach to smooth out the errors/biases originated from PLMs. Specifically, we conduct self-distillation on multiple PLMs in parallel (for brevity, we use two in this paper: BERT and RoBERTa, however the framework itself is compatible with any number of PLMs). Each PLM does not communicate/synchronise with each other except when producing the self-labelled scores. In mutual-distillation, we use the average predictions of all models as the ground-truth for the next round of learning. A graphical illustration is shown in Fig. 2.5
In the following, we call all self-distillation models TRANS-ENCODER (or TENC for short); all mutual-distillation models TRANS-ENCODER-mutual (or TENC-mutual for short). Note that one TENC (-mutual) training produces one best bi-encoder, called TENC (-mutual) (bi), and one best cross-encoder, called TENC (-mutual) (cross), based on dev set. We report numbers of both.

heading: 3 EVALUATION TASKS
text: Evaluation task: semantic textual similarity (STS). Following prior works (Reimers & Gurevych, 2019; Liu et al., 2021; Gao et al., 2021), we consider seven STS datasets: SemEval STS 2012-2016
5We also experimented with a sequential ensemble strategy: initialising the cross- and bi-encoder with BERT/RoBERTa alternatively (1 cycle of BERT then 1 cycle of RoBERTa) but found the performance worse than mutual-distillation.
(STS12-16, Agirre et al. 2012; 2013; 2014; 2015; 2016), STS Benchmark (STS-B, Cer et al. 2017) and SICK-Relatedness (SICK-R, Marelli et al. 2014). In all these datasets, sentence pairs are given a human-judged relevance score from 1 to 5. We normalise them to 0 and 1 and models are asked to predict the scores. We report Spearman’s ρ rank correlation between the two.
Evaluation task: binary classification. We also test TRANS-ENCODER on sentence-pair binary classification tasks where the model has to decide if a sentence-pair has certain relations. We choose (1) the Quora Question Pair (QQP) dataset, requiring a model to judge whether two questions are duplicated; (2) a question-answering entailment dataset QNLI (Rajpurkar et al., 2016; Wang et al., 2019) in which given a question and a sentence the model needs to judge if the sentence answers the question; (3) the Microsoft Research Paraphrase Corpus (MRPC) which asks a model to decide if two sentences are paraphrases of each other. The ground truth labels of all datasets are either 0 or 1. Following (Li et al., 2020; Liu et al., 2021), we compute Area Under Curve (AUC) scores using the binary labels and the relevance scores predicted by models.

heading: 4 EXPERIMENTAL SETUP
text: Training and evaluation details. For each task, we use all available sentence pairs (from train, development and test sets of all datasets combined) without their labels as training data. The original QQP and QNLI datasets are extremely large. We thus downsample QQP to have 10k, 1k and 10k pairs for train, dev and test; QNLI to have 10k train set. QNLI does not have public ground truth labels for testing. So, we use its first 1k examples in the official dev set as our dev data and the rest in the official dev set as test data. The dev set for MRPC is its official dev sets. The dev set for STS12-16, STS-B and SICK-R is the dev set of STS-B. We save one checkpoint for every 200 training steps and at the end of each epoch. We use the dev sets to select the best model for testing.6 Dev sets are also used to tune the hyperprameters in each task.
For clear comparison with SimCSE and Mirror-BERT, we use their released checkpoints as initialisation points (i.e., we do not train models in §2.1 ourselves). We consider four SimCSE variants. Two base variants: SimCSE-BERT-base, SimCSE-RoBERTa-base; and two large variants: SimCSE-BERTlarge, SimCSE-RoBERTa-large. We consider two Mirror-BERT variants: Mirror-RoBERTa-base and Mirror-RoBERTa-base-drophead.7 For brevity, our analysis in the main text focuses on SimCSE models. We list Mirror-BERT results in Appendix. We train TRANS-ENCODER models for 3 cycles on the STS task and 5 cycles on the binary classification tasks. Within each cycle, all bi- and cross-encoders are trained for 10 and 1 epochs respectively for the STS task; 15 and 3 epochs for binary classification.8 All models use AdamW (Loshchilov & Hutter, 2019) as the optimiser. In all tasks, unless noted otherwise, we create final representations using [CLS]. We train our base models on a server with 4 * V100 (16GB) GPUs and large models on a server with 8 * A100 (40GB) GPUs. All main experiments have the same fixed random seed. All other hparams are listed in Appendix.
Mutual-distillation setup. For the two models used for mutual-distillation, they are either (1) the base variant of SimCSE-BERT and SimCSE-RoBERTa or (2) the large variant of the two. Theoretically, we could mutually distil even more models but we keep the setup simple for fast and clear comparison. Also, since mutual-distillation models use information from both PLMs, we also list (in tables) ensemble results that use the average of the predictions from two TRANS-ENCODERs.

heading: 5 RESULTS AND DISCUSSION

heading: 5.1 MAIN RESULTS
text: STS results (Tab. 1). The main results for STS are listed in Tab. 1. Compared with the baseline SimCSE, TRANS-ENCODER has brought significant improvements across the board. With various variants of the SimCSE as the base model, TRANS-ENCODER consistently enhances the average score
6Note that checkpoints of bi- and cross-encoders are independently saved and evaluated on dev set. In the end, one best bi-encoder and one best cross-encoder are obtained.
7We do not consider BERT-based checkpoints by Liu et al. (2021) since they adopt mean pooling over all tokens. For brevity, we only experiment with encoders trained with [CLS].
8We use fewer epochs for cross-encoders since they usually converge much faster than bi-encoders.
distillation while TENC-mutual models use mutual-distillation as well. Blue and red denotes mutual-distillation models that are trained in the base and large group respectively. Models without colour are not co-trained with any other models. ∗Note that for base encoders, our results can slightly differ from numbers reported in (Gao et al., 2021) since different evaluation packages are used.
by approximately 4-5%.9 Self-distillation usually brings an improvement of 2-3% (e.g., compare line 1.1, 1.2 with 1 in Tab. 1). Further, mutual-distillation brings another boost of 1-3% (e.g., compare line 3.3, 3.4 with 3.1, 3.2 in Tab. 1). Besides single-model results, the ensemble of mutual-distilled models are clearly better than the ensemble models of either (1) naively averaging the two initial SimCSE models’ scores or (2) averaging predictions of two self-distilled models in a post hoc manner. This demonstrates the benefit of allowing models to communicate/synchronise with each other in all stages of the self-distillation training.
Binary classification results (Tab. 2). On QQP, QNLI, and MRPC, we observe similar trends as the STS tasks, and the improvement is sometimes even more significant (see full table in Appendix Tab. 11). We conjecture it is due to the fact that TRANS-ENCODER training also adapts models to the task domain (since tasks like QQP and QNLI are very different from Wikipedia data, which is where SimCSE models are trained on). We will discuss the domain adaptation effect in more details in analysis. Another point worth discussing is the benefit of mutual-distillation is more inconsistent on binary classification tasks, compared with STS tasks (again, see full table Tab. 11 in Appendix). We
9Similar trends observed on Mirror-BERT, see Appendix (App. §A.1).
suspect it is due to the performance imbalance between the BERT and RoBERTa variants on these tasks (a significant performance gap exists in the first place).
Domain transfer setup (Tab. 3). One of the key questions we are keen to find out is how much of TRANS-ENCODER’s success on in-domain tasks generalises/transfers to other tasks/domains. Specifically, does TRANS-ENCODER create universally better bi- and cross-encoders, or is it only task/domain-specific? To answer the question, we directly test models trained with the STS task data on binary classification tasks. For bi-encoders, i.e., TENC (bi), the results are inconsistent across setups. These results hint that training on in-domain data is important for optimal performance gains for unsupervised bi-encoders. This is in line with the finding of (Liu et al., 2021). However, for cross-encoders, surprisingly, we see extremely good transfer performance. W/ or w/o mutualdistillation, TENC (cross) models outperform the SimCSE baselines by large margins, despite the fact that tasks like QQP and QNLI are of a very different domain compared with STS. In fact, they are sometimes even better than models tuned on the in-domain task data (c.f. Tab. 11). This finding has deep implications. It hints that the cross-encoder architecture (cross-attention) is by design very suitable for sentence-pair modelling (i.e., strong inductive bias is already in the architecture design), and once its sentence-pair modelling capability is ‘activated’, it is an extremely powerful universal representation that can be transferred to other tasks. The reason that STS models outperform in-domain models in some tasks hint that more sentence-pairs as raw training data is welcome (since the STS train set is larger than the binary classification ones). As future work, we plan to explore mining sentence pairs for TRANS-ENCODER learning from a general corpus (such as Wikipedia). Both lexical- (such as BM25) and semantic-level (neural models such as bi-encoders) IR systems could be leveraged here.

heading: 5.2 DISCUSSIONS AND ANALYSIS
text: In this section we discuss some interesting phenomena we observed, justify design choices we made in an empirical way, and also show a more fine-grained understanding of what exactly happens when using TRANS-ENCODER.
Initialise with the original weights or train sequentially? (Fig. 3a) As mentioned in §2.2 and §2.3, we initialise bi-encoders with SimCSE/Mirror-BERT weights and cross-encoders with PLMs’ weights (we call this strategy refreshing). We have also tried maintaining the weights of bi- and cross-encoders sequentially. I.e., we initialise the cross-encoder’s weights with the bi-encoder which just created the pseudo labels and vice versa (we call this strategy sequential). The benefit of doing so is keeping all the legacy knowledge learned in the process of self-distillation in the weights. As
suggested in Fig. 3a (also in Appendix Tab. 13), refreshing is slightly better than sequential. We suspect it is because initialising with original weights alleviate catastrophic forgetting problem in self-supervised learning (SSL), similar to the moving average and stop-gradient strategy used in contrastive SSL methods such as MoCo (He et al., 2020).
Self-distillation without alternating between different task formulations? (Fig. 3b) If we disregard the bi- and cross-encoder alternating training paradigm but using the same bi-encoder architecture all along, the model is then similar to the standard self-distillation model (c.f. Figure 1 by Mobahi et al. (2020)). Theoretically, standard self-distillation could also have helped, especially considering that it adapts the model to in-domain data. However, as seen in Fig. 3b (and also Appendix Tab. 14), standard self-distillation lags behind TRANS-ENCODER by a significant amount, and sometimes underperforms the base model. Standard self-distillation essentially ensembles different checkpoints (i.e., the same model at different training phases provides different ‘views’ of the data). TRANSENCODER can be seen as a type of self-distillation model, but instead of using previous models to provide views of data, we use different task formulations (i.e., bi- and cross-encoder) to provide different views of the data. The fact that standard self-distillation underperforms TRANS-ENCODER by large margins suggests the effectiveness of our proposed bi- and cross-encoder training scheme.
How many cycles is optimal? (Fig. 4) Our approach iteratively bootstraps the performance of both bi- and cross-encoders. But how many iterations (cycles) are enough? We find that it heavily depends on the model and dataset, and could be unpredictable (since the ‘optimality’ depends on a relatively small dev set). In Fig. 4, we plot the TENC models’ (self-distillation only) performances on dev sets in three tasks: STS, QQP, and QNLI. In general, the patterns are different across datasets and models.
Does more training data help? (Fig. 5) We control the number of training samples drawn and test the TRANS-ENCODER model (using SimCSE-BERT-base) on STS test sets. The average performance on all STS tasks are reported in Fig. 5, with three runs of different random seeds. There are in total 37,081 data points from STS. We only draw from these in-domain data until there is none left. It can be seen that for in-domain training, more data points are usually always beneficial. Next, we test with more samples drawn from another task, SNLI (Bowman et al., 2015), containing abundant sentence-pairs. The performance of the model further increases till 30k extra data points and starts to gradually decrease after that point. However, it is worth mentioning that there will be discrepancy of such trends across tasks and models. And when needed, one can mine as many sentence-pairs as desired from a general corpus (such as Wikipedia) for TRANS-ENCODER learning.
10k 20k 30kfull+10k +30k +50k +100k #sample
76.0
76.5
77.0
77.5
78.0
78.5
79.0
79.5
80.0
Sp ea
rm an
's rh
o
legend SimCSE-BERT-base bi-encoder cross-encoder in-domain training
Figure 5: STS performance against number of training samples. ‘full’ means all STS in-domain data are used. After ‘full’, the samples are drawn from the SNLI dataset. Note that each point in the graph is an individual run.

heading: 6 RELATED WORK
text: Our work is closely related to (1) unsupervised sentence representation learning; (2) sentence-pair tasks using bi- and cross-encoders; and (3) self-distillation. Each has a large body of work which we can only provide a highly selected summary below.
Unsupervised sentence representations. Prior to the emergence of large PLMs such as BERT, popular unsupervised sentence embedding methods included Skip-Thoughts (Kiros et al., 2015), FastSent (Hill et al., 2016), and Quick-Thoughts (Logeswaran & Lee, 2018). They all exploit the co-occurrence statistics of sentences in large corpora (i.e., sentences under similar contexts have similar meanings). A recent paper DeCLUTR (Giorgi et al., 2021) follows such idea and formulate the training as a contrastive learning task. Very recently, there has been a growing interest in using individual raw sentences for self-supervised contrastive learning on top of PLMs. Contrastive Tension (Carlsson et al., 2021), Mirror-BERT (Liu et al., 2021), SimCSE (Gao et al., 2021), Self-Guided Contrastive Learning (Kim et al., 2021), ConSERT (Yan et al., 2021), BSL (Zhang et al., 2021), inter alia, all follow such an idea. Specifically, data augmentations on either input or feature space are used to create two views of the same sentence for contrastive learning. In our experiments, we use such methods as an initial step for creating a reasonably strong bi-encoder.
Cross- and bi-encoder for pairwise sentence tasks. Sentence-BERT (Reimers & Gurevych, 2019) points out the speed advantage of bi-encoders and proposes to train BERT with a siamese architecture for sentence-pair tasks. Poly-encoder (Humeau et al., 2020) proposes a hybrid architecture in which intermediate encodings are cached and a final layer of cross-attention is used to exploit intersentence interactions. Conceptually similar to our work, Di-pair (Chen et al., 2020), augmented Sentence-BERT (Thakur et al., 2021), RocketQA (Qu et al., 2021), and DvBERT (Cheng, 2012) distil knowledge in supervised cross-encoders to bi-encoders. We show that it is also possible to distil knowledge from bi- to cross-encoders.
Self-distillation. In standard self-distillation, models of the same architecture train on predictions by previous checkpoint(s) with the same task formulation (Furlanello et al., 2018; Mobahi et al., 2020). However, the standard approach does not alter the training paradigm (task formulation) as we do (biand cross-encoder training). In experiments, we have shown that alternating task formulation is the key to the success of our method.

heading: 7 CONCLUSION
text: We propose TRANS-ENCODER, an unsupervised approach of training bi- and cross-encoders for sentence-pair tasks. The core idea of TRANS-ENCODER is self-distillation in a smart way: alternatively training a bi-encoder and a cross-encoder (of the same architecture) with pseudo-labels created from the other. We also propose a mutual-distillation extension to mutually bootstrap two self-distillation models trained in parallel. On sentence-pair tasks including sentence similarity, question de-duplication, question-answering entailment, and paraphrase identification, we show strong empirical evidence verifying the effectiveness of TRANS-ENCODER. We also found the surprisingly strong generalisation capability of our trained cross-encoders across domains and tasks. Finally, we conduct thorough ablation studies and analysis to verify our design choices and shed insight on the model mechanism.

heading: A APPENDIX

heading: A.1 RESULTS WITH OTHER CONTRASTIVE LEARNING METHODS
text: In the main text, we experimented with SimCSE, but in theory TRANS-ENCODER is compatible with any unsupervised contrastive bi-encoder learning models. In this section, we experiment with Mirror-BERT (which is similar to SimCSE) and also two additional unsupervised contrastive models Contrastive-Tension (Carlsson et al., 2021) and DeCLUTR (Giorgi et al., 2020) to verify the robustness of TRANS-ENCODER.
As seen in Tab. 4 and Tab. 5, TRANS-ENCODER brings consistent and significant improvements to all base models, similar to what we have observed on SimCSE models. After TRANS-ENCODER training, the Mirror-BERT-based models perform even slightly better than SimCSE-based models, on both the STS and binary classification tasks. We suspect it is due to that SimCSE checkpoints are trained for more iterations (with the contrastive learning objective) and thus are more prone to overfit the training corpus.

heading: A.2 MORE DISCUSSIONS AND ANALYSIS
text: How robust is TRANS-ENCODER? (Tab. 6) As mentioned, our main experiments used one fixed random seed. Due to the scale of the experiments, performing multiple runs with different random seeds for all setups is overly expensive. We pick STS and the base variants of BERT and RoBERTa
as two examples for showing results of five runs (shown in Tab. 6). In general, the TRANS-ENCODER approach is quite robust and stable.
STS and SICK-R as different tasks (Tab. 7, Fig. 6). It is worth noting that in the STS main results table (Tab. 1), SICK-R is the only dataset where TRANS-ENCODER models lead to performance worse than the baselines in some settings (e.g., on SimCSE-BERT-large). We believe it is due to that SICK-R is essentially a different task from STS2012-2016 and STS-B since SICK-R is labelled with a different aim in mind. It focuses specifically on compositional distributional semantics.10 To verify our claim, we train SICK-R as a standalone task using its official dev set instead of STS-B. All sentence pairs from SICK-R are used as raw training data. The results are shown in Tab. 7 and Fig. 6. As shown, around 3-4% gain can be obtained by switching to training on SICK-R only, confirming the different nature of the two tasks. This suggests that generalisation is also dependent on the standard of how relevance is defined between sequences in the target dataset, and training with an in-domain dev set maybe crucial when the domain shift between training and testing data is significant.
Gradient derivation of BCE and MSE loss. We show that BCE is essentially a normalised version of MSE where the gradient of xi is scaled by the sigmoid function (σ(·)). Here are the gradients of the two loss functions:
∂LBCE ∂xi = − 1 N
( yi(σ(xi)− 1) + (1− yi)σ(xi) ) = − 1
N
( σ(xi)− yi ) ∂LMSE ∂xi = − 2 N ( xi − yi ) .
(4)
As can be seen, the only difference lies in whether xi is scaled by σ(·). This gives a greater degree of freedom to LBCE especially at the areas in the two ends (close to 0 or 1): a large change of xi results
10SICK-R “includes a large number of sentence pairs that are rich in the lexical, syntactic and semantic phenomena that Compositional Distributional Semantic Models (CDSMs) are expected to account for (e.g., contextual synonymy and other lexical variation phenomena, active/passive and other syntactic alternations, impact of negation, determiners and other grammatical elements), but do not require dealing with other aspects of existing sentential data sets (e.g., STS, RTE) that are not within the scope of compositional distributional semantics.” (see http://marcobaroni.org/composes/sick.html).
in a small change of σ(xi), making the approximation of yi an easier task. In other words, in LBCE, it is in general easier for the model to push the gradient to 0, while in LMSE, only a strict numerical match leads to 0 gradient.
Loss function configurations (Tab. 8). We experimented with loss function configurations comprehensively and found that it requires caution when choosing learning objectives for cross- to bi-encoder and bi- to cross-encoder distillation. As mentioned in the main text and the paragraph above, choosing MSE for bi-to-cross distillation causes severe overfitting to the pseudo scores and choosing BCE for cross-to-bi distillation fail to make the model converge. As a result, our configuration of using BCE and MSE for bi-to-cross and cross-to-bi distillations respectively becomes the only plausible solution (see Tab. 8).
For the regression loss used for cross-to-bi distillation, besides MSE, we also experimented with several other regression loss functions such as Log-Cosh but found no improvement.
Do sentence pairs leak label information? (Tab. 9) TRANS-ENCODER has leveraged the sentence pairs given by the task. One concern is that the sentence pairs may be positively correlated and the model may have exploited this naı̈ve bias. We highlight that this work does not have this concern as the tasks in our study test the relative similarity ranking of sentence pairs under the evaluation metrics (both spearman’s rank used in STS and AUC used in binary classification are ranking-based). Therefore, the overall correlation distribution of sentence pairs does not reveal what is tested by the tasks in this study. To further verify the model has not learned label distribution from the task, we run a controlled setting where we treat all sentence pairs from the tasks as (pseudo-)positive pairs and apply a standard contrastive finetuning framework (i.e. Mirror-BERT and SimCSE finetuning) with Eq. (1) as the loss on these pairs. Performance improvement from this finetuning setup will indicate that the overall positive correlation from the sentence pairs can be exploited by the model. Results are shown in Tab. 9. Contrastive methods on pseudo-positive pairs almost always11 underperform the original SimCSE and Mirror-BERT checkpoints significantly while TRANS-ENCODER models improve the checkpoints by large margins.
11The only exception is QNLI. We suspect it is because QNLI is from the QA domain and contrastive tuning on QNLI sentence pairs has some domain adaptation effect. According to Liu et al. (2021), contrastive tuning on randomly sampled sentences from the target domain can also achieve domain adaptation, and sentence pairs from the task are thus not a must.

heading: A.3 TRAINING TIME
text: Overall runtime. We list the runtime of TRANS-ENCODER models on different tasks and configurations in Tab. 10. All base models can be trained under 2.5 hours and large models can be trained within 5 hours. TENC-mutual models usually take twice the amount of time training a self-distillation model. Also, TENC-mutual models require two GPUs while self-distillation models need only one. We have tested running TRANS-ENCODER on three types of Nvidia GPUs: V100 (16 GB), A100 (40 GB) and 3090 (24 GB). The runtimes are similar.
Cross-encoder vs. bi-encoder. For training one epoch, bi-encoder takes significantly less time than cross-encoders. However, bi-encoders take much longer time to converge (15 epochs vs. 3 epochs on binary classification tasks and 10 epochs vs. 1 epoch on STS; see Tab. 16). As a result, in practice, bi-to-cross and cross-to-bi distillations take similar amount of time.

heading: A.4 FULL TABLES
text: Here, we list the full tables of SimCSE binary classification results (Tab. 11); SimCSE domain transfer results (Tab. 12); and full tables for ablation studies (Tab. 13, Tab. 14), which are presented as figures in the main texts in Fig. 3.

heading: A.5 DATA STATISTICS
text: A complete listing of train/dev/test stats of all used datasets can be found in Tab. 15. Note that for STS 2012-2016, we dropped all sentence-pairs without a valid score. And the train sets include all sentence pairs (w/o labels) regardless of split in each task.

heading: A.6 HYPERPARAMETERS
text: The full listing of hyperparameters is shown in Tab. 16. Since performing a grid-search for all these hparams is ultra-expensive, we mainly used the default hparams from the sentence-BERT library.12 The hparams for TENC and TENC-mutual are the same.

heading: A.7 PRE-TRAINED ENCODERS
text: A complete listing of URLs for all used PLMs is provided in Tab. 17.
12www.sbert.net

Review summaries:
This paper focuses on the unsupervised training of bi-encoder and cross-encoder for sentences. A self-distillation framework is proposed, in which the bi-encoder and cross-encoder may iteratively distill knowledge from each other. The experiments are performed with typical sentence pair datasets like STS, QQP, QNLI, MRPC, where improvements are achieved over SimCSE and mirror-BERT. 

# Summary  - This paper highlights the fact that bi-encoders (sentence encoders) and cross-encoders (sentence-pair encoders) have been considered somewhat separately in the literature of sentence-pair modeling, and that cyclic knowledge distillation from one to another (and vice versa) can be effective for improving the performance of both the encoder stereotypes. - The authors combine the two sentence modeling paradigms into an iterative joint framework, which is called TRANS-ENCODER, to simultaneously learn enhanced bi- and cross-encoders. - Specifically, given the original SimCSE or Mirror-BERT checkpoints provided by prior work, the proposed framework first (pseudo-)labels sentence pairs sampled from the task of interest by utilizing the off-the-shelf sentence encoders. And then, the labeled sentence pairs are utilized to improve the quality of cross-encoders. Further, the fine-tuned cross-encoders can also be exploited to label other sentence pairs which are again able to be used as a dataset for tuning the bi-encoders (sentence encoders). The framework repeats this process until both the bi- and cross-encoders become satisfactory in terms of their performance. - The proposed method is evaluated on semantic textual similarity (STS) tasks and binary classification datasets such as QQP, QNLI, and MRPC. The results demonstrate that the method improves both the bi- and cross-encoders to be more suitable for sentence-pair modeling tasks.

This paper proposes TRANS-ENCODER, an unsupervised approach to training bi-encoders and cross-encoders for sentence similarity tasks such as information retrieval, natural language inference, semantic textual similarity and clustering. The core idea of TRANS-ENCODER is self-distillation that alternatively trains a bi-encoder and a cross-encoder with pseudo-labels created from the other. The authors also propose a mutual-distillation extension to mutually bootstrap two self-distillation models trained in parallel. The effectiveness of TRANS-ENCODER is verified by empirical evidence.

This paper deals with tasks where we need to do pairwise comparison between two sequences. Specifically, the paper experimented on STS, QQP, QNLI, MRPC. The paper proposes integrating two models together: bi-encoders and cross-encoders.   A bi-encoder encodes each of the two sequences separately and maps to a common embedding space. A cross-encoder first concatenates two sequences, and the concatenation is sent to the model. There’s more computation for the cross-encoder case, but the cross-encoder usually outperforms the bi-encoder.   Figure 1 illustrates the authors’ proposal well. First, start with a pretrained language model. Then, the bi-encoder generates pseudo-labels for the cross-encoder to learn. Next, the cross-encoder generates (more accurate) pseudo-labels for the bi-encdoer to learn. We reiterate this process. This approach is named self-distillation.   The author proposes an extension called mutual distillation where the authors do self-distillation on multiple pretrained language models in parallel (but the paper only experiments with two--BERT and RoBERTa).   On STS, QQP, QNLI, MRPC, the mutual distillation approach archives good performances (much better than the bi-encoder baseline SimCSE).