What an embedding is: meaning as a list of numbers
What it is
An embedding model reads a piece of text and outputs a fixed-length list of numbers, called a vector or an embedding.
- A typical one has 384, 768 or 1,536 numbers.
- The model is trained so that texts with similar meaning get vectors that are close together, and unrelated texts get vectors that are far apart.
- "I want my money back" and "how do I get a refund" share almost no words, yet their vectors land close to each other.
Why it matters
Computers cannot compare meanings, but they can compare numbers very quickly. Embeddings turn 'find the passage that means the same as this question' into 'find the nearest list of numbers', which is a problem with fast, well-understood solutions.
In the real world: A travel site lets customers search 'somewhere warm in December with kids' and matches it to hotel descriptions that never use those words.
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("all-MiniLM-L6-v2")
vecs = model.encode([
"I want my money back",
"How do I get a refund?",
"What time do you open?",
])
vecs.shape # (3, 384): three texts, 384 numbers each
sims = model.similarity(vecs, vecs)
# the first two texts score high with each other,
# the third scores low against bothTrying to read meaning into individual numbers. Position 17 is not 'refund-ness'. The meaning lives in the whole vector and in its direction relative to other vectors, never in a single entry. (The diagrams in this module use made-up three-number vectors with readable meanings only so the arithmetic can be followed.)
Practise it: Design a Semantic Search System