A team needs sentence embeddings for semantic search from a pretrained encoder. What is the standard approach?
- Exam domain
- LLM Architecture6% of the exam
- Difficulty
- Medium
- In this mock
- 5 questions on this domainPractise this domain
Why the exam asks this
LLM Architecture (6% of the exam).
Objective in the exam guide: Develop code to extract embeddings from both encoder and decoder models.
Embeddings underpin RAG and search.
Why D is the answer
Encode sentences with a model trained for embeddings, such as a Sentence Transformers model, and compare vectors with cosine similarity
Embedding models map each sentence to one vector, and similarity between vectors measures semantic closeness.
How it works
An embedding is a vector that represents meaning.
Embedding models are trained so that similar texts get nearby vectors.
Calling encode on a sentence model returns embeddings directly.
Clues in the question
The words that point to the answer, and what each one tells you.
- Semantic search
- Meaning vectors.
In detail
- Pooling turns token vectors into one sentence vector.
- Use the same model for queries and documents.
Side by side with look-alikes
| Representation | Captures meaning? |
|---|---|
| Embedding model vectors | Yes |
| Token IDs | No |
| Next-token probabilities | Not a sentence vector |
| Word counts | Weakly |
Every option, checked
Knowing why each wrong option fails is how you rule it out on exam day.
A. Use the raw token IDs as the embeddingWrongMost tempting
Token IDs are arbitrary integers with no meaning.
Why it tempts: IDs are numbers. But they are arbitrary indexes with no meaning.
B. Take the model's output probabilities for the next tokenWrong
Next-token probabilities are not sentence representations.
C. Count words and use the counts as the embeddingWrong
Word counts miss meaning and synonyms.
D. Encode sentences with a model trained for embeddings, such as a Sentence Transformers model, and compare vectors with cosine similarityRight
Embedding models map each sentence to one vector, and similarity between vectors measures semantic closeness.
In practice
- Normalize embeddings so cosine similarity becomes a dot product.