Skip to main content
QUICK REVIEW

[Paper Review] Comparing in context: Improving cosine similarity measures with a metric tensor

Isa M. Apallius de Vos, Ghislaine L. van den Boogerd|arXiv (Cornell University)|Mar 28, 2022
Topic ModelingComputer Science4 citations
TL;DR

This paper proposes a context-aware metric tensor to enhance cosine similarity by learning context-specific inner products, improving word similarity correlation without modifying pre-trained embeddings. The method achieves significant gains—especially with contextualized models like BERT—demonstrating generalization to unseen datasets and improved interpretability through learned, dynamic similarity metrics.

ABSTRACT

Cosine similarity is a widely used measure of the relatedness of pre-trained word embeddings, trained on a language modeling goal. Datasets such as WordSim-353 and SimLex-999 rate how similar words are according to human annotators, and as such are often used to evaluate the performance of language models. Thus, any improvement on the word similarity task requires an improved word representation. In this paper, we propose instead the use of an extended cosine similarity measure to improve performance on that task, with gains in interpretability. We explore the hypothesis that this approach is particularly useful if the word-similarity pairs share the same context, for which distinct contextualized similarity measures can be learned. We first use the dataset of Richie et al. (2020) to learn contextualized metrics and compare the results with the baseline values obtained using the standard cosine similarity measure, which consistently shows improvement. We also train a contextualized similarity measure for both SimLex-999 and WordSim-353, comparing the results with the corresponding baselines, and using these datasets as independent test sets for the all-context similarity measure learned on the contextualized dataset, obtaining positive results for a number of tests.

Motivation & Objective

  • To improve word similarity evaluation by replacing the standard Euclidean inner product in cosine similarity with a learnable metric tensor.
  • To investigate whether context-specific similarity measures, learned on contextualized word-pair datasets, yield better performance than static baselines.
  • To enable generalization of learned similarity metrics to unrelated datasets, testing transferability across word-pair contexts.
  • To enhance interpretability and efficiency in similarity computation by decoupling metric learning from embedding retraining.
  • To explore the integration of learned metrics into compositional distributional semantics and tensor contraction frameworks.

Proposed method

  • Introduce a generalized cosine similarity using a symmetric positive-definite metric tensor G, replacing the standard Euclidean inner product with ⟨u,v⟩_G = u^T G v.
  • Learn the metric tensor G from contextualized word-pair similarity datasets (e.g., hypernymy relations) via optimization of correlation with human-annotated scores.
  • Train the metric on a unified dataset of hypernyms (e.g., 'Birds', 'Fishes') to capture cross-contextual similarity patterns.
  • Apply the learned metric to independent test sets (e.g., SimLex-999, WordSim-353) to evaluate zero-shot generalization performance.
  • Compare performance using the same pre-trained embeddings (e.g., BERT, GPT-2, Word2Vec) with both standard cosine similarity and the metric-tensor-enhanced version.
  • Use Pearson and Spearman correlation as evaluation metrics to assess improvement over baseline models.

Experimental results

Research questions

  • RQ1Can a context-aware metric tensor improve cosine similarity performance on word similarity benchmarks without retraining word embeddings?
  • RQ2Does learning the metric on a contextualized dataset (e.g., hypernyms) lead to better generalization than learning on unrelated word pairs (e.g., WS353, SL999)?
  • RQ3To what extent can a metric learned on one set of word-pairs generalize to unrelated, independent datasets like SimLex-999 and WordSim-353?
  • RQ4How does the performance of the metric tensor method compare across different pre-trained embedding models (e.g., BERT, GPT-2, Word2Vec)?
  • RQ5What is the impact of model architecture and context diversity on the stability and interpretability of learned metric tensors?

Key findings

  • The metric tensor method significantly improved correlation scores on SimLex-999 and WordSim-353 when tested with BERT embeddings, achieving a Pearson correlation of 0.487 and Spearman of 0.519, compared to baseline values of 0.239 and 0.267.
  • The best-performing model, trained on all hypernyms, generalized well to independent datasets, showing a 100% improvement in correlation for BERT on SimLex-999 (0.375 vs. 0.151 baseline).
  • Contextualized representations (e.g., BERT) showed the highest relative improvement after metric learning, with a 100% increase in correlation on SimLex-999, indicating a cumulative benefit from context in both embeddings and similarity measure.
  • The model trained on hypernyms outperformed individual hypernym-specific models, suggesting that exposure to diverse contexts during training improves generalization and transfer learning.
  • The method achieved state-of-the-art performance on SimLex-999 (0.658 Pearson) and WordSim-353 (0.704 Pearson) when using the best model, surpassing previous SOTA results.
  • The distribution of word vectors under the learned metric became more collinear and concentrated, indicating that the metric effectively aligns semantic relationships in vector space.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.