epsilon-compositionality

Code for our paper Measuring Idiomaticity in Text Embedding Models with 𝜀-compositionality
git clone https://esimon.eu/repos/epsilon-compositionality.git
Log | Files | Refs | Submodules | README

commit 1569435e4c9674c02987d325b9baed018bf819f0
parent d7b80318340fa4315f6c693ffd592ebae8e6fdee
Author: Sondre Wold <sondrewold1@gmail.com>
Date:   Mon, 21 Jul 2025 16:26:01 +0200

remove word2vec

Diffstat:
Mexperiment.py | 35-----------------------------------
1 file changed, 0 insertions(+), 35 deletions(-)

diff --git a/experiment.py b/experiment.py @@ -12,8 +12,6 @@ import torch import pickle import tqdm -from gensim.models import KeyedVectors - from transformers import AutoTokenizer, AutoModel from sentence_transformers import SentenceTransformer @@ -95,39 +93,6 @@ class ModelFactory: return cls._factory[name](*args, **kwargs) -# @ModelFactory("Word2Vec") -class Word2vec(Model): - """ - It does not make conceptually sense to test Word2Vec, as sim(\mu(ac), \mu(bc)) will - be equal to sim(\mu(a), \mu(b)) by definition if \mu(ac) - is the sum of the embeddings of the subwords in a and c. - - But, maybe we can do something else with it, so here it is. - """ - - def __init__(self) -> None: - self.model_path: str = "./models/GoogleNews-vectors-negative300.bin.gz" - self.encoder = KeyedVectors.load_word2vec_format(self.model_path, binary=True) - - - def embed(self, string: str) -> torch.Tensor: - words: list[str] = string.split() - - # In He et.al (2025), they ignore OOV word word2vec. - present_words = [word for word in words if word in self.encoder] - - embeddings = [self.encoder[word] for word in present_words] - sentence_embedding = numpy.sum(embeddings, axis=0) - return torch.tensor(sentence_embedding) - - - def calculate_similarity(self, a: torch.Tensor, b: torch.Tensor) -> float: - return torch.nn.functional.cosine_similarity( - a, b, dim=0 - ).item() - - - @ModelFactory("BERT_cls") class BERT_cls(Model):