Start studying
Module 4 · NLP Module contents
Module 4  ·  Card 12 / 20beginner

Semantic Similarity

Semantic similarity measures how close two pieces of text are in meaning.

It compares their embedding vectors rather than their literal words.

So car and automobile score high despite sharing no characters.

This is what powers semantic search, deduplication and recommendation.

It is the core idea behind retrieval in RAG systems.

Learn in depth ↓
Module 04 · NLP · 20 concepts
In depth  /  15 lines

Semantic Similarity, in more detail

Semantic similarity asks how close two pieces of text are in meaning.

Comparing the words themselves fails immediately on synonyms.

How do I reset my password and I forgot my login share almost no words.

They should score as nearly the same thing, and to a person they obviously are.

The route is to embed both into vectors and compare the vectors instead.

An embedding model puts text with the same meaning at nearby points.

Cosine similarity then measures the angle between them and returns a single number.

Sentence embedding models are trained for this specifically, unlike raw word vectors.

Averaging word vectors gives a weak sentence vector, which is why those models exist.

This is the engine under semantic search, deduplication and recommendation.

It is the retrieval step of every RAG system.

The scores are relative, so 0.8 means little on its own and only ranks against other scores.

It also has no notion of truth, since a sentence and its negation embed very close together.

The dog is friendly and the dog is not friendly are near neighbours.

That is why retrieval finds relevant text and cannot be trusted to find correct text.

Want the full technical article? Wikipedia ↗
Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
Why do car and automobile score as highly similar?
NLP

20 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close