Semantic textual similarity

Semantic Textual Similarity

Measuring how close the meanings of two texts are. It is used in duplicate question detection, semantic search, plagiarism detection, text clustering and translation evaluation, and is usually solved with sentence embeddings and cosine.

Understanding and classification
InputTwo texts (usually two sentences)
OutputA continuous similarity score (for example 0–5) or an equivalence decision (paraphrase or not)
Evaluation metricsPearson and Spearman correlation with human judgments, and F1 for paraphrase detection

In brief

  • Lexical (Jaccard, character n-grams, Levenshtein) versus semantic (embeddings).
  • The Bi-encoder is fast; the Cross-encoder is more accurate and slower.
  • Translation and cross-lingual plagiarism need multilingual embeddings.

Example: why is lexical similarity not enough?

«اشتريت سيارة جديدة» ("I bought a new car") and «ابتعت مركبة حديثة» ("I purchased a modern vehicle"): no shared word, so Jaccard = 0, while the meaning is nearly identical. Conversely, «الكلب عض الرجل» ("the dog bit the man") and «الرجل عض الكلب» ("the man bit the dog"): Jaccard = 1 and the meaning differs. Contextual embeddings handle both cases better, but they are not immune to error in the second case.

Bi-encoder versus cross-encoder

  • Bi-encoder: each text is encoded separately into a vector, then cosine is computed. It allows millions of texts to be indexed in advance.
  • Cross-encoder: the two texts are fed into the model together, so each text sees the other in attention. It is more accurate but needs one pass per pair, so it is used only to rerank the top results.

References

  1. Reimers, N., & Gurevych, I. (2019). Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks. EMNLP-IJCNLP 2019 arxiv.org/abs/1908.10084
  2. Cer, D. et al. (2017). SemEval-2017 Task 1: Semantic Textual Similarity Multilingual and Crosslingual Focused Evaluation arxiv.org/abs/1708.00055