Embedding Pitfalls & Misunderstandings

Points in an embedding space illustrating that items may be more similar or more different than expected

Embeddings are an excellent tool for approximating aspects of large text datasets and their underlying semantics, be it in search, clustering, or text classification. They are often introduced with a hand-wavy definition that they are basically vectors that represent the meaning of the embedded text. Note that the fuzzy term meaning goes a long way here, and while I believe that this is a good working definition for becoming intrigued by the concept, it can also lead to oversimplifications if one never thinks more deeply about their actual construction and the technical details involved. Here are some of the typical misunderstandings I have encountered in discussions.

Misunderstanding: Low cosine similarity -> different semantics:

Sometimes people believe that if cos(embA,embB)\cos(\mathrm{emb}_A, \mathrm{emb}_B) is low, A and B discuss completely different semantic content. This is not true in general, as embedding models usually learn lexical and semantic patterns during training. For instance, given the sentences:

Sentence AA: Adults with type 2 diabetes who have persistent hyperglycemia despite metformin therapy were enrolled.

Sentence BB: Participants were middle-aged and older patients whose blood glucose remained poorly controlled on first-line biguanide treatment.

Both sentences describe a very similar clinical population: adults with poorly controlled type 2 diabetes despite first-line therapy. Nevertheless, their cosine similarity is low in general-purpose embeddings (MiniLM-L6, around 0.5) due to their vastly different surface forms. Thus, if we were interested in studies about type 2 diabetes patients, this might bite us.

Misunderstanding: High cosine similarity -> same semantics:

This is the inverse of the above and is also not always true. This is particularly a problem for negations or subtle inversions. For instance:

Sentence AA: The patient has no evidence of pulmonary embolism.

Sentence AnotA_{\mathrm{not}}: The patient has evidence of pulmonary embolism.

Sentence AparaA_{\mathrm{para}}: Imaging shows no signs of a blood clot in the pulmonary arteries.

For many embedding models, we are going to see results like cos(embA,embAnot)>cos(embA,embApara)\cos(\mathrm{emb}_A, \mathrm{emb}_{A_{\mathrm{not}}}) > \cos(\mathrm{emb}_A, \mathrm{emb}_{A_{\mathrm{para}}}). For instance, the similarity between A and the paraphrase is 0.57 for MiniLM-L6, versus 0.83 between the negated and original sentences. That is, the negated sentence is more similar in embedding space than the paraphrase, although it has a crucial semantic difference. This is one reason why clustering embeddings to generate evidence counts for questions can be dangerous, as we may count evidence as equivalent even though the statements contradict each other.

Misunderstanding: Numbers are well represented in embedding models

This is another specific case where meaning is too hand-wavy and might bite us if we aren’t careful. If we have statements like:

Sentence A: HbA1c was 6.2%

Sentence B: HbA1c was 12.6%

Those sentences can be close in embedding space, although the measurements describe completely different conditions that likely warrant very different treatments. Distinguishing exact numbers is a typical case where embeddings may not help us much.

Misunderstanding: Semantic similarity is transitive

In clustering, we frequently build equivalence classes, assigning one item to exactly one cluster. An equivalence class is usually reflexive, symmetric, and transitive. However, similarity between embeddings is not transitive and therefore does not always play nicely with clustering approaches. For instance, with MiniLM-L6:

Sentence AA: The patient has chronic knee pain caused by osteoarthritis.

Sentence BB: The patient reports chronic pain.

Sentence CC: The patient reports migraine headaches.

We get:

This feels intuitively right. However, transitivity would imply that if similarity between A and B is high and similarity between B and C is high, it is also high between A and C, which is not the case. In concrete cases, and for clustering methods that are susceptible to such chains, this means that sentences A and C might be clustered together because B forms a bridge through its similarity to A and C.

Misunderstanding: Embedding models are general purpose

One could assume that, as embeddings capture meaning, the meaning representation should be domain-independent. Thus, a good general-purpose model should transfer well to novel domains. This does not hold true in the general case, and domain-specific pretraining and fine-tuning of embeddings can certainly be worth it. Embedding similarity is learned from a corpus and, for instance, words like HEDGEHOG or APP can mean vastly different things in a biomedical corpus or a computer science corpus.

All these properties together also illustrate another point. Embedding similarity should not be confused with task relevance or semantic equivalence. It is one learned notion of similarity, optimized under a particular training objective. As such, embedding models are useful reductionist models of the world and, like all models, can be useful if one has the right task at hand and accounts for, or at least communicates about, their potential weaknesses and biases.