English (unofficial) translations of posts at kexue.fm
Source

Which Unsupervised Semantic Similarity Method is the Best? A Comprehensive Evaluation

Translated by DeepSeek V4 Pro. Translations can be inaccurate, please refer to the original post for important stuff.

In January, I wrote "You Might Not Need BERT-flow: A Simple Linear Transformation Matches BERT-flow", pointing out that the SOTA model for unsupervised semantic similarity, BERT-flow, can actually be matched by a simple linear transformation (whitening operation, BERT-whitening). Subsequently, we further refined the experimental results and wrote the paper "Whitening Sentence Representations for Better Semantics and Faster Retrieval". This blog post will provide a basic overview of the contents of that paper and supplement it with an evaluation of five Chinese semantic similarity tasks, including over 600 experimental results.

Github Link: https://github.com/bojone/BERT-whitening

Method Overview

The idea of BERT-whitening is very simple. After obtaining the sentence vectors \{x_i\}_{i=1}^N for each sentence, a whitening operation (i.e., PCA) is performed on these matrices so that the mean of each dimension is 0 and the covariance matrix is the identity matrix. Then, the top k principal components are retained. The process is shown in the figure below:

Basic process of BERT-whitening

Of course, theoretically, we can also view BERT-whitening as the simplest implementation of BERT-flow. As pointed out in previous blogs, such a simple implementation is sufficient to rival general BERT-flow models, and sometimes even perform better. At the same time, BERT-whitening ranks feature importance during the transformation, allowing us to reduce the dimensionality of sentence vectors to increase retrieval speed. Experimental results show that in most tasks, dimensionality reduction not only does not lead to a decrease in performance but actually brings about an improvement.

English Tasks

First, we introduce the test results of BERT-whitening on English tasks, which mainly consist of three charts, essentially achieving a strict comparison with BERT-flow.

Purely Unsupervised

The first table presents the results of extracting sentence vectors directly using pre-trained BERT in a completely unsupervised manner. In the BERT-flow paper, it was confirmed that without any post-processing, the best pooling method for extracting sentence vectors based on BERT is the average of all token vectors from the first and last layers, namely first-last-avg (the BERT-flow paper mistakenly identified this as the average of the last two layers and labeled it as last2avg, but it is actually the first and last layers). Therefore, the following results are based on first-last-avg with either flow or whitening applied.

Evaluation results of purely unsupervised semantic matching on English tasks

NLI Supervised

The second table presents the results of sentence vectors extracted from the Sentence-BERT model (SBERT) fine-tuned on the NLI dataset. In this case, first-last-avg is also the best, so the baseline for both flow and whitening is the sentence vector produced by first-last-avg. The NLI dataset is a natural language inference dataset, which is similar but not equivalent to semantic similarity. It can serve as supervised pre-training for semantic similarity tasks, but since it does not directly use semantic similarity data, it remains unsupervised relative to the semantic similarity task itself.

Evaluation results of semantic matching based on BERT-NLI on English tasks

Dimension vs. Performance

In these two tables, the bold values represent the best results. A green arrow \color{green}{\uparrow} means that the BERT-whitening result is superior to the BERT-flow model under the same conditions, while a red arrow \color{red}{\downarrow} means the opposite. In other words, more green arrows mean that BERT-whitening performs better. The numbers 256 and 384 following "whitening" refer to the dimensions retained after reduction. As seen from these two tables, BERT-whitening generally outperforms BERT-flow, achieving SOTA on most tasks, and in most cases, dimensionality reduction further improves performance.

To further confirm the effect of dimensionality reduction, we plotted the relationship between retained dimensions and performance:

Dimension-performance curves for various English tasks. The dimensions corresponding to the best performance are marked. It can be seen that for every task, dimensionality reduction can potentially bring some improvement.

The figure above demonstrates the change in evaluation metrics relative to retained dimensions after whitening for various models on different tasks. It can be observed that for every task, the optimal performance is not achieved at full dimensionality. This means dimensionality reduction can bring performance gains. Furthermore, many tasks can even be reduced to 1/8 of the original dimensions or more while maintaining or even increasing performance. This fully demonstrates the engineering value of BERT-whitening, as dimensionality reduction significantly speeds up retrieval.

Chinese Tasks

Adhering to the philosophy that "a model not tested on Chinese has no soul," I have organized several Chinese semantic similarity datasets and evaluated them using different Chinese pre-trained models, pooling methods, and whitening configurations. The results are summarized here for comparison.

Evaluation Setup

This evaluation involves 11 models, 5 datasets, and 4 pooling methods. Each combination compares three post-processing methods: "no whitening," "whitening," and "whitening with dimensionality reduction." Thus, there are approximately 11 \times 5 \times 4 \times 3 = 660 experimental results, making it quite comprehensive. I say "approximately" because some pooling methods are not available for certain models. Since the computational cost of BERT-flow is significantly higher than BERT-whitening, we did not reproduce the BERT-flow results. However, as seen from the English tasks, the effects of BERT-whitening and BERT-flow are usually close, and BERT-whitening often outperforms BERT-flow, making whitening results representative.

The evaluation metric is the same as the English tasks: Spearman’s correlation coefficient. This is a ranking metric similar to AUC, which only depends on the order of predicted scores and is independent of thresholds, making it suitable for evaluating performance. The reason for not using the more familiar accuracy metric is twofold: first, accuracy depends on specific thresholds; second, the labels for the STS-B dataset are numbers from 1 to 5, not 0/1 labels, making accuracy impossible to calculate. Thus, Spearman’s correlation is used uniformly. If readers must understand it from an accuracy perspective, one can roughly assume "accuracy \approx 0.5 + \text{Spearman} / 2".

The 11 models are as follows:

  • BERT: Google’s open-source Chinese BERT base version.

  • RoBERTa: HFL’s open-source roberta_wwm_ext base version.

  • NEZHA: Huawei’s open-source BERT base version with relative position encoding (wwm).

  • WoBERT: A word-based BERT; the Plus version is used here.

  • RoFormer: BERT with a new type of position encoding (Rotary).

  • BERT_{large}: Tencent UER’s open-source BERT large version.

  • RoBERTa_{large}: HFL’s open-source roberta_wwm_ext large version.

  • NEZHA-large: Huawei’s open-source BERT large version with relative position encoding (wwm).

  • SimBERT: BERT base version trained on similar sentences.

  • SimBERT_{small}: BERT small version trained on similar sentences.

  • SimBERT_{tiny}: BERT tiny version trained on similar sentences.

The 5 tasks are as follows:

  • ATEC: ATEC Semantic Similarity Learning competition dataset, financial customer service scenario.

  • BQ: HIT BQ Corpus dataset, question matching in the banking and finance domain.

  • LCQMC: HIT LCQMC dataset, question matching covering multiple domains.

  • PAWSX: Google’s dataset containing multilingual paraphrase and non-paraphrase pairs. It features high lexical overlap, making it difficult for unsupervised methods. Only the Chinese portion is used.

  • STS-B: Calculates correlation between two sentences. Translated from the English version with manual corrections.

The 4 pooling methods are as follows:

  • P1: Extract the [CLS] vector from the last layer of the encoder.

  • P2: Extract the vector corresponding to the Pooler (used by BERT for NSP). The difference from P1 is an additional linear transformation.

  • P3: Average all vectors from the last layer of the encoder.

  • P4: Average all vectors from the first and last layers of the encoder.

Summary of Results

All experimental results are summarized in the following three tables. Each element in the tables is in the form a / b / c, representing the score for "no whitening" (a), "with whitening" (b), and "with whitening and appropriate dimensionality reduction" (c). If b \geq a, b is shown in green; otherwise, it is red. If c \geq a, c is shown in green; otherwise, it is red. "Appropriate dimensionality reduction" means reducing to 256 dimensions for base models, 384 for large models, and 128 for tiny and small models.

The first table compares 6 base models. Note that WoBERT and RoFormer do not have NSP tasks, so they lack P2 weights:

ATEC BQ LCQMC PAWSX STS-B
BERT-P1 16.59 / / 29.35 / / 41.71 / / 15.15 / / 34.65 / /
BERT-P2 9.46 / / 16.97 / / 28.42 / / 13.93 / / 21.66 / /
BERT-P3 20.79 / / 33.08 / / 59.22 / / 16.68 / / 57.48 / /
BERT-P4 24.51 / / 38.81 / / 64.75 / / 15.12 / / 61.66 / /
RoBERTa-P1 24.61 / / 40.54 / / 70.55 / / 16.23 / / 66.91 / /
RoBERTa-P2 20.61 / / 31.14 / / 65.43 / / 15.71 / / 59.50 / /
RoBERTa-P3 26.94 / / 40.71 / / 66.80 / / 16.08 / / 61.67 / /
RoBERTa-P4 27.94 / / 43.09 / / 68.43 / / 15.02 / / 64.09 / /
NEZHA-P1 17.39 / / 29.63 / / 40.60 / / 14.90 / / 35.84 / /
NEZHA-P2 10.96 / / 17.38 / / 22.66 / / 13.45 / / 21.16 / /
NEZHA-P3 23.70 / / 35.44 / / 60.94 / / 18.35 / / 60.35 / /
NEZHA-P4 27.72 / / 44.18 / / 65.16 / / 13.98 / / 61.94 / /
WoBERT-P1 23.88 / / 43.08 / / 68.56 / / 18.15 / / 64.12 / /
WoBERT-P2 - - - - -
WoBERT-P3 24.62 / / 40.64 / / 64.89 / / 16.83 / / 59.43 / /
WoBERT-P4 25.97 / / 42.37 / / 66.53 / / 15.54 / / 61.37 / /
RoFormer-P1 24.29 / / 41.91 / / 64.87 / / 20.15 / / 59.91 / /
RoFormer-P2 - - - - -
RoFormer-P3 24.09 / / 39.09 / / 63.55 / / 16.53 / / 58.98 / /
RoFormer-P4 25.92 / / 41.75 / / 66.18 / / 15.30 / / 61.40 / /
SimBERT-P1 38.50 / / 48.54 / / 76.23 / / 15.10 / / 74.14 / /
SimBERT-P2 38.93 / / 49.93 / / 75.56 / / 14.52 / / 73.18 / /
SimBERT-P3 36.50 / / 45.78 / / 74.42 / / 15.33 / / 67.31 / /
SimBERT-P4 33.53 / / 45.28 / / 73.20 / / 14.16 / / 66.98 / /

The second table compares the 3 large models:

ATEC BQ LCQMC PAWSX STS-B
BERT_{large}-P1 13.15 / / 19.81 / / 23.45 / / 16.88 / / 25.93 / /
BERT_{large}-P2 8.16 / / 9.43 / / 16.66 / / 14.72 / / 15.82 / /
BERT_{large}-P3 24.31 / / 35.87 / / 59.29 / / 16.94 / / 60.22 / /
BERT_{large}-P4 25.62 / / 38.45 / / 65.43 / / 15.33 / / 62.02 / /
RoBERTa_{large}-P1 19.32 / / 34.21 / / 64.89 / / 17.78 / / 60.16 / /
RoBERTa_{large}-P2 19.32 / / 34.33 / / 65.00 / / 17.77 / / 60.09 / /
RoBERTa_{large}-P3 24.83 / / 39.23 / / 66.86 / / 17.67 / / 62.98 / /
RoBERTa_{large}-P4 25.69 / / 40.18 / / 68.58 / / 16.01 / / 63.75 / /
NEZHA_{large}-P1 18.91 / / 30.39 / / 41.68 / / 18.89 / / 39.04 / /
NEZHA_{large}-P2 7.92 / / 12.03 / / 12.33 / / 16.26 / / 16.59 / /
NEZHA_{large}-P3 22.74 / / 36.48 / / 59.65 / / 18.09 / / 59.66 / /
NEZHA_{large}-P4 27.45 / / 44.33 / / 66.19 / / 13.74 / / 62.91 / /

The third table compares SimBERT models of different sizes:

ATEC BQ LCQMC PAWSX STS-B
SimBERT-P1 38.50 / / 48.54 / / 76.23 / / 15.10 / / 74.14 / /
SimBERT-P2 38.93 / / 49.93 / / 75.56 / / 14.52 / / 73.18 / /
SimBERT-P3 36.50 / / 45.78 / / 74.42 / / 15.33 / / 67.31 / /
SimBERT-P4 33.53 / / 45.28 / / 73.20 / / 14.16 / / 66.98 / /
SimBERT_{small}-P1 30.68 / / 43.41 / / 74.73 / / 15.89 / / 70.54 / /
SimBERT_{small}-P2 31.00 / / 43.76 / / 74.21 / / 16.17 / / 70.10 / /
SimBERT_{small}-P3 30.03 / / 43.72 / / 72.12 / / 16.93 / / 66.55 / /
SimBERT_{small}-P4 29.52 / / 43.52 / / 70.33 / / 15.39 / / 64.73 / /
SimBERT_{tiny}-P1 30.51 / / 44.25 / / 74.27 / / 16.01 / / 70.11 / /
SimBERT_{tiny}-P2 30.01 / / 44.47 / / 73.98 / / 16.55 / / 70.35 / /
SimBERT_{tiny}-P3 28.47 / / 42.04 / / 69.16 / / 16.18 / / 64.41 / /
SimBERT_{tiny}-P4 27.77 / / 41.76 / / 67.55 / / 15.06 / / 62.92 / /

Experimental Conclusions

Similar to the English task tables, green indicates that the whitening operation improved the quality of sentence vectors, while red indicates a decrease. More green indicates that the whitening method is more effective. From the tables above, we can draw several conclusions:

  1. The test results for Chinese tasks are much more complex and irregular than those for English tasks. For example, in English tasks, P4 pooling is generally better than others, and large models generally outperform base models, but these trends are not obvious in Chinese tasks.

  2. Except for SimBERT, there is generally more green than red, indicating that whitening has a positive effect on improving sentence vectors. Specifically, in the a/b/c format, c has significantly more green than b, showing that dimensionality reduction further improves performance. This means whitening is an algorithm that truly improves both speed and efficiency.

  3. In the BQ task, the whitening method almost always led to a decrease. This is similar to the SICK-R task in English, illustrating that "there is no free lunch." Some tasks will cause the "isotropy" assumption to fail, in which case neither BERT-whitening nor BERT-flow will bring improvements.

  4. SimBERT is the SOTA for all tasks except PAWSX. Of course, SimBERT is trained with supervised semantic similarity data (though theoretically, there is no overlap between training and test data), so comparing it with other models is not entirely fair. Regardless, SimBERT is open-source and available for everyone to use as a baseline.

  5. Applying whitening to SimBERT either leads to a performance drop or brings negligible improvement. This suggests that for sentence vectors trained via supervised methods, further whitening is unnecessary and generally does not help.

  6. PAWSX is indeed very difficult; the road for semantic similarity tasks is still long...

Summary

This article introduced our comprehensive evaluation of unsupervised semantic similarity methods on both Chinese and English tasks. For English tasks, we restated the results from our BERT-whitening paper, including a direct comparison with BERT-flow. For Chinese tasks, we collected 5 tasks and evaluated over 600 combinations of 11 pre-trained models, 4 pooling methods, and 3 post-processing methods to provide a convenient reference for comparison.

In one sentence: the BERT-whitening method indeed achieves current SOTA for unsupervised semantics, while SimBERT serves as a high-performance open-source baseline for Chinese semantic similarity.

Reprinting: Please include the original address of this article: https://kexue.fm/archives/8321

For more details on reprinting, please refer to: "Scientific Space FAQ"