Embedding
Also Embeddings
A (word) embedding assigns to each element of a vocabulary V a dense vector in R^d, usually with d much smaller than |V|, such that semantically related words get similar vectors (high cosine similarity).
Properties#
| Property | One-Hot Encoding | Word embedding |
|---|---|---|
| Dimension | (very large) | , e.g. 300 (ES11: , ) |
| Density | sparse (one nonzero entry) | dense |
| cos-sim of distinct words | always | high for related words |
- Semantics in the direction: relatedness is encoded in the direction of the vectors, which is exactly what cos-sim compares; its length-invariance also means a summed document embedding (whose length grows with the number of words) is compared by what it is about, not by how long it is.
- How embeddings are learned is not covered in DBIS (see IR WS 22/23, Lecture 9); for ES11 they are provided as a dictionary
word → tensor. - Sum = bag of words: the summed text embedding, like the VSM document vector (sum of one-hot encodings), ignores word order because addition is commutative: “cute cats eating” and “eating cute cats” get the same vector and cos-sim .
- Sum vs. embedding model: Lecture 12 calls the sum “simplistic”, because not every word is equally relevant for a text. ES12 uses a dedicated embedding API (
mixedbread-ai/mxbai-embed-large-v1athttps://ad-llm.cs.uni-freiburg.de/v1/embeddings) that returns one embedding per input text; the same API must be used for chunks and queries. - Uses: similarity search over words or documents (ES11) and retrieving the chunks most similar to a query in Retrieval-Augmented Generation (ES12).
Example#
Sources#
- Slides 11, p. 20 (one-hot has no semantics), Slides 11, p. 21 (definition), Slides 11, p. 22 (embeddings in PyTorch, document embedding as sum)
- Slides 12, p. 15 (chunk embeddings), Slides 12, p. 16 (embedding API)
- DBIS_VL11 > Word embeddings, DBIS_VL11 > Using the embeddings for ES11, DBIS_VL12 > Computing the embeddings
- Exam: DBIS Exam WS2324 (not published) Task 5.1 (cos-sim of two embeddings), DBIS Exam WS2324-2 (not published) Task 5.2 (next-word model on embeddings)