# Word vs Sentence Embeddings

> Word embeddings give each word one vector, sentence embeddings give a whole text one vector. Here is what each does, where averaging fails, and how to explain it for your AI interview.

**In short:** A word embedding gives each word one list of numbers, the same whatever sentence it sits in. A sentence embedding gives a whole question or document one list, so a search can compare what the text means.

AI and LLM interview question Q007, LLM fundamentals. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/word-embeddings-vs-sentence-embeddings

## Say it in 30 seconds

A word embedding gives each word one list of numbers. A sentence embedding gives a whole question or paragraph one list, so a search can match by meaning. The simple way to build a sentence vector is to average the word vectors, but that blends every word together, so a small word like 'not' barely moves the result and 'not approved' looks like 'approved'. Sentence models read the whole text instead. For a real search, I would use a sentence model and test it on refused chargebacks first.

## Say it in 2 minutes

Start with the word. A word embedding is one list of numbers for each word, learned from a large pile of text. Words used in similar places get similar lists. Word2vec, a method from 2013, learns them this way. The catch is that each word gets one list no matter the sentence, so a bank in a river story and a bank in a loan story share the same vector.

A sentence embedding is one list for a whole question, email or paragraph. That is what search needs, because a customer's question rarely uses the same words as the ticket that answers it. You compare the two lists with cosine similarity, which scores how much they point the same way. A simple way to build one is to average the word vectors. Averaging blends every word into one vector, so a small word like 'not' barely moves the result, and 'not approved' lands next to 'approved'. It also ignores word order, so 'approved not' and 'not approved' look the same.

Better sentence embeddings come from models that read the whole text. The 2019 SBERT paper tuned BERT so that similar sentences end up close together. It also showed the speed gain: finding the most similar pair among 10,000 sentences took about 65 hours with BERT, and about 5 seconds with SBERT. For a bank's ticket search, I would use a sentence model, keep one model for questions and tickets, and test it on refused chargebacks before trusting it.

Be honest about the limits. A vector can still miss a detail, and no model is perfect. Say how you would measure it.

## What are word and sentence embeddings, in plain words?

An embedding is a list of numbers that stands for a piece of text, so a computer can measure how close two pieces are. OpenAI describes embeddings the same way: a vector of numbers, where a small distance suggests the texts are closely related.

A word embedding gives each word one list. A sentence embedding gives a whole sentence, question or paragraph one list. It is the same idea at two sizes.

Picture a call-centre supervisor. Each keyword in a complaint gets its own tag, but the supervisor reads the whole complaint and gives it one tag for what it is about. Word embeddings are the keyword tags. A sentence embedding is the supervisor's tag.

- **Vector:** A list of numbers. Computers compare vectors by how closely they line up.
- **Word embedding:** One vector per word, the same whatever sentence the word sits in.
- **Sentence embedding:** One vector for a whole sentence, question or paragraph.
- **Cosine similarity:** A score from -1 to 1 for how much two vectors point the same way. Higher means more alike.

## How does a word embedding work, and where does it fall short?

Word2vec is a method from 2013 for learning one vector per word from a large amount of text. Its paper describes "continuous vector representations of words from very large data sets". Words that appear in similar contexts end up near each other.

Google's machine learning course calls these static embeddings. Each word gets one point, the same in every sentence, so the course warns that a single point "can be a limitation in some cases".

Newer models deal with that. BERT, from 2018, reads the words on both sides of each word, so its vectors depend on the sentence. ELMo, also from 2018, is built to model "how these uses vary across linguistic contexts".

> "Static embeddings like word2vec represent all meanings of a word with a single point, which can be a limitation in some cases." (Google, Machine Learning Crash Course)
>
> "An inherent limitation of word representations is their indifference to word order and their inability to represent idiomatic phrases." (Mikolov and colleagues, 2013)

- **Word: One vector per word.** Quick to build: one lookup per word, from a large pile of text. Good for keywords, synonyms and single-word tasks.
- **Sentence: One vector per text.** Needs a model that reads the whole text. Captures what a full question means.

## Why do search tools need one vector per sentence?

A customer's question rarely uses the same words as the ticket that answers it. A word-by-word match misses the link, but a sentence vector can catch the meaning. For example, a customer asks "Why was my chargeback refused?" and the closest ticket reads "Chargeback not approved, reason 4".

Comparing sentences pair by pair does not scale. The 2019 SBERT paper shows the gap: finding the most similar pair among 10,000 sentences took about 65 hours with BERT, and about 5 seconds once each sentence had its own vector.

*Diagram, How a question finds its ticket: The question and every stored ticket each become one vector. The closest vector wins, so the agent sees the matching ticket even though the words differ.*
1. The question becomes one vector, from the same model.
2. That vector is compared with every stored ticket vector.
3. The closest ticket goes back to the agent.

> "Finding the most similar pair in a collection of 10,000 sentences requires about 50 million inference computations (~65 hours) with BERT." (Reimers and Gurevych, SBERT (2019))

So the pattern is: make one vector per text, store it, then compare the question's vector with the stored ones using cosine similarity. That comparison is one quick step per ticket.

## How do you get one vector for a whole sentence?

There are two common routes. The first is averaging: add up the word vectors and divide by how many there are. The SBERT paper says averaging BERT's output was the most common approach, and that taking the output for the first token, a marker the model puts at the start of the input, was the other main choice.

Averaging is simple, and it has a clear flaw. It treats the sentence as a pile of words, so the order is lost. The chart shows both routes side by side, and the demo puts numbers on the problem.

*Diagram, Averaging words vs reading the sentence: Averaging gives a refusal a nearly identical vector to an approval. A model that reads the whole sentence keeps the difference, so the refusal is found.*
1. Averaging makes a refusal look like an approval.
2. Reading the whole sentence keeps the refusal's meaning.

Here it is in plain Python. The vectors are made up, and I set "not" close to zero on purpose, so this shows the mechanism, not a measured result. Real averaged vectors can show the same pattern, so test them.

```python
import math

# Made-up 2-number word vectors. A small, simplified space, not a real model.
WORD_VECTORS = {
    "chargeback": (0.9, 0.2),
    "approved": (0.8, 0.1),
    "rejected": (0.1, 0.9),
    "not": (0.05, 0.05),
}

def sentence_vector(text):
    # The simple way: average the word vectors. Word order is lost.
    vectors = [WORD_VECTORS[word] for word in text.split()]
    return tuple(sum(v[i] for v in vectors) / len(vectors) for i in range(2))

def cosine(a, b):
    # 1.0 means the same direction; lower means less alike.
    dot = sum(x * y for x, y in zip(a, b))
    return dot / (math.hypot(*a) * math.hypot(*b))

approved = sentence_vector("chargeback approved")
not_approved = sentence_vector("chargeback not approved")
rejected = sentence_vector("chargeback rejected")
print("approved vs not approved:", round(cosine(approved, not_approved), 4))
print("approved vs rejected:", round(cosine(approved, rejected), 4))
```

Output:

```text
approved vs not approved: 0.9997
approved vs rejected: 0.791
```

A sentence model avoids that by reading the whole text. SBERT, a sentence version of BERT, adds a pooling step (it squeezes BERT's many per-word outputs into one fixed-size list). It is then trained so that semantically similar sentences are close in vector space.

Once you use a sentence model, keep the same one for questions and tickets. Vectors from different models are not in the same space, so the distances between them cannot be compared.

- **Word vectors:** Quick, cheap and good for keywords and synonyms.
- **Sentence vectors:** Capture what a whole question means, so they suit search.
- **Averaged word vectors:** Easy to build, but they blur small words like "not", so negation is easy to miss.
- **Your own tickets:** Test on real refusals and negations before you trust the search.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: a word embedding is one vector per word, a sentence embedding is one vector per text.
- [ ] Why it matters: word order and negation get lost when you average word vectors.
- [ ] Sentence embeddings are what semantic search compares, usually with cosine similarity.
- [ ] The same embedding model for questions and documents, or the distances mean nothing.
- [ ] The cost trade-off: one model call per text, then fast comparisons.
- [ ] Honest limits: a vector can still miss a detail, so test on real examples.

**Common traps**

- Trap: "Word and sentence embeddings are the same thing." Better: Same idea at two sizes. A word vector is for one word, a sentence vector is for a whole text.
- Trap: "Just average the word vectors, it's good enough." Better: It blends every word, so a small word like 'not' barely moves the result, and 'not approved' lands next to 'approved'. Test refusals first.
- Trap: "Cosine similarity counts shared words." Better: It compares the direction of two vectors. Shared words only matter if the model maps them that way.

## Can you spot the problem?

**Spot the problem:** Your bank's ticket search turns each ticket into one vector. Which line makes refusals look like approvals?

A. vector = sum(word_vectors) / len(words)  # averaged per ticket
B. index = VectorIndex(metric='cosine')
C. top_k = 5  # the agent sees five closest tickets
D. model = sentence_encoder  # same model for questions and tickets

**Answer:** A. Averaging blends every word into one vector, so a small word like 'not' barely moves the result, and 'not approved' lands next to 'approved'. Use a sentence model that reads the whole text, and test it on refused chargebacks.

**Quick check:** A customer question and each stored ticket get sentence vectors. What must match so the distances mean something?

A. The length of each ticket
B. The same embedding model for both
C. The customer's spelling
D. The number of tickets stored

**Answer:** B. Vectors from different models sit in different spaces, so distances between them mean nothing. Use one model for questions and tickets.

## Can you answer these from memory?

**Flash cards**

- **What is a word embedding?** One vector per word, the same whatever sentence the word sits in.
- **What is a sentence embedding?** One vector for a whole question, email or paragraph.
- **Why does averaging word vectors fail?** A word like 'not' gets blended in, so 'not approved' lands next to 'approved'.
- **How are two embeddings compared?** Usually with cosine similarity: how much the two vectors point the same way.
- **What must questions and tickets share?** The same embedding model. Vectors from different models can't be compared.
- **What did SBERT change?** It tuned BERT so similar sentences end up close in vector space.

## Likely follow-up questions

- Q006 What is an embedding? https://designervenkat.online/interview/ai/what-is-an-embedding
- Q113 What is chunking, and why does size matter? https://designervenkat.online/interview/ai/what-is-chunking-in-rag
- Q116 How do you choose an embedding model? https://designervenkat.online/interview/ai/how-do-you-choose-an-embedding-model
- Q118 Cosine vs dot product vs Euclidean distance? https://designervenkat.online/interview/ai/cosine-vs-dot-product-vs-euclidean-distance
- Q123 What is hybrid search (BM25 + vectors)? https://designervenkat.online/interview/ai/what-is-hybrid-search
- Q154 Sparse vs dense embeddings? (full answer coming)

## Learn it in depth

- [Embeddings for builders](https://designervenkat.online/learn/ai-engineering/embeddings)
- [Choosing an embedding model](https://designervenkat.online/learn/ai-engineering/embedding-models)
