Tokens and Embeddings, lesson 9
Semantic search and clustering
Use embeddings to search, group and label text.
You can score two vectors with cosine similarity ("Cosine similarity and the dot product") and you know where that score misleads ("Blind spots of cosine similarity").
Part 1. Search: rank by cosine
A help centre has five articles. Someone types "I forgot my login". None of the article titles contain those words, yet the right one is obvious to you: "Reset your password".
Embeddings get there the same way you compared words. Turn every article into a vector once and store it. When a question comes in, turn it into a vector too, score it against every stored vector with cosine similarity, and sort.
Example 1.1
One search, start to finish
- Reset your password(0.9, 0.1, 0.0)Change your email address(0.6, 0.5, 0.1)Update your card(0.1, 0.9, 0.2)Download an invoice(0.0, 0.7, 0.6)Cancel your plan(0.2, 0.4, 0.8)
The articles, embedded ahead of time. Three made-up numbers each; a real model gives hundreds.
- "I forgot my login"→(0.8, 0.2, 0.1)
The question goes through the same embedding model.
- Reset your password 0.98Change your email address 0.90Cancel your plan 0.42Update your card 0.36Download an invoice 0.26
Score and sort. The password article wins without sharing a single word with the question.
Semantic search
Finding text by closeness of meaning (embedding similarity) instead of by shared words. The stored vectors are often called the index.
Your turn
The articles were embedded with model A. You upgrade and embed new questions with model B. What happens to the search?
Scoring every stored vector works fine for thousands of documents. At millions, systems use a special index that finds the near ones without checking every vector, at the cost of sometimes missing one.
Part 2. Classification: the nearest average
Keep going with Pro
You've done the first part. Pro opens the rest of this lesson, and every other one.
- Classification: the nearest average
- Clustering: let the groups appear
Tokens and Embeddings overviewSpotted a mistake? Tell us.