Vectors are super sparse and “cat” and “dog” are exactly as similar as “cat” and “democracy”
No useful semantic information is encoded
Dimensionality grows with vocabulary
The distributional hypothesis
“You shall know a word by the company it keeps.” — J.R. Firth, 1957
Words that appear in similar contexts tend to carry similar meanings.
“I adopted a cat / dog / rabbit.” “The cat / dog / rabbit sat on the mat.”
Context statistics are semantic content. This one insight underlies every method we will cover today.
The thread running through this entire class:
Embeddings operationalise semantics and make similarity between texts directly and cheaply measurable. This powerful capability is the engine behind retrieval, attention, and behavioural measurement of AI.
Word2Vec: learning from context
Skip-gram objective: given a word, predict its neighbours.
Train a shallow neural network on this task across billions of word windows. The hidden layer weights become the embedding – a dense, low-dimensional vector.
This single number – easy to compute, cheap at scale – is what makes for example the following possible:
Retrieval: find the passage most similar to a query
Clustering: group texts by mutual similarity
Bias auditing: measure which concepts cluster near which groups
Semantic shift: track how the meaning of words changes over time by training embeddings on historical corpora from different periods
And it is the same operation inside the transformer’s famous attention mechanism.
From words to sentences
Word2Vec gives one vector per word type, regardless of context.
“I went to the bank to deposit money.” “We sat on the bank of the river.”
Same word. Different meaning. Same vector.
Transformer models (BERT, 2018) produce context-sensitive token representations. Each token’s embedding depends on all other tokens in the sequence.
Sentence transformers (Reimers & Gurevych, 2019) extend this to full sentences – fine-tuned so that semantically similar sentences are close in embedding space.
How do we know which embeddings are good?
MTEB: Massive Text Embedding Benchmark (Muennighoff et al., 2022) – 56 datasets across 8 task categories including retrieval, semantic similarity, clustering, classification, and reranking
Large models (7B+) dominate overall – but task type matters more than size.
Retrieval: use models fine-tuned on retrieval (bge-large, e5-mistral)
Semantic similarity: general sentence transformers often suffice
Speed at scale:all-MiniLM-L6-v2 (22M params) within a few points of SOTA
Don’t just pick any embedding model.
Check MTEB for your specific task type. In my own work on SQuID, MTEB ranking turned out to be a good guide even for psychometric tasks.
What else can you do with sentence embeddings?
Beyond retrieval and classification – Question: if meaning lives in embedding space, do psychological constructs also have geometric structure there?
We embedded the text of items from the Schwartz Portrait Values Questionnaire (PVQ-RR) using a sentence transformer.
Result: the Schwartz value structure (universalism, power, achievement, benevolence…) re-emerges from the geometry of the embedding space alone.
SQuID: Survey and Questionnaire Item Embeddings Differentials
The problem: raw embedding similarities are always positive – shared abstract linguistic features inflate pairwise similarity even between opposing items. Opposing values should be negatively correlated.
The fix: subtract the mean embedding over all questionnaire items
This removes shared linguistic features and recovers negative correlations.
Result: the circular Schwartz value structure emerges from embeddings on par with human data from 49 countries. No finetuning, no labels, any model.
Embeddings can be an instrument for representational and behavioural measurement of AI systems.
Now: a practical application
Let’s build something using an embedding approach.
Scenario: CEU DNDS has course descriptions, faculty pages, and research group texts.
A new master’s student asks: “Which courses or research groups work on network resilience?”
Keyword search: fails if the document says “robustness” or “cascading failures”
LLM without context: will hallucinate a confident, plausible, wrong answer
Retrieval-augmented generation (RAG) with sentence embeddings: retrieves semantically relevant passages, generates a grounded answer
RAG architecture
Student query
↓
Embed query
→
Retrieve top-k
↑
Vector store
↑
Embed chunks
↑
Chunk documents
→
Build prompt
↓
LLM
↓
Grounded answer
Four steps: chunk, embed, retrieve, generate.
Step 1 · Chunk the documents
# DNDS course descriptions and research group pagesdocuments = {"network_science_course": "This course introduces ...","css_course": "Students learn to apply ...","dnds_research_groups": "The department hosts ...",}chunk_size, overlap =400, 50all_chunks, all_labels = [], []for name, text in documents.items(): chunks = [ text[i : i + chunk_size]for i inrange(0, len(text), chunk_size - overlap) ] all_chunks.extend(chunks) all_labels.extend([name] *len(chunks))
Step 2 · Embed the chunks
from sentence_transformers import SentenceTransformer# MTEB retrieval-task pick for this scalemodel = SentenceTransformer("all-MiniLM-L6-v2")# Shape: (n_chunks, 384)chunk_embeddings = model.encode(all_chunks, show_progress_bar=True)
Step 3 · Retrieve by semantic similarity
import numpy as npdef retrieve(query: str, k: int=3) ->list[str]:# Embed the query in the same space as the chunks query_embedding = model.encode([query])# Cosine similarity -- the same geometry as the Schwartz analysis scores = np.dot(chunk_embeddings, query_embedding.T).squeeze() top_k_idx = np.argsort(scores)[::-1][:k]return [all_chunks[i] for i in top_k_idx]
“Which courses cover network resilience?” will surface passages mentioning “robustness”, “cascading failures”, “structural vulnerability” – because they live nearby in embedding space.
Step 4 · Generate a grounded answer
import anthropicclient = anthropic.Anthropic()def answer(query: str) ->str: context ="\n\n---\n\n".join(retrieve(query, k=3)) prompt =f"""You are a helpful assistant for CEU's Department ofNetwork and Data Science. Answer using only the context provided.If the answer is not in the context, say so clearly.Context:{context}Question: {query}""" r = client.messages.create( model="claude-opus-4-5", max_tokens=512, messages=[{"role": "user", "content": prompt}] )return r.content[0].textprint(answer("Which courses cover network resilience?"))
Based on the provided context, network resilience is most directly covered in
the Network Science and Applications course, which includes dedicated
sessions on robustness of complex networks, cascading failures, and targeted vs.
random attack tolerance. The course uses both analytical tools and empirical
network datasets to study how structural properties relate to a network's
ability to withstand perturbations.
The DNDS research groups page additionally mentions ongoing work on
systemic risk in financial and infrastructure networks within the Computational
Social Systems group. No direct match was found for the exact phrase
"network resilience" -- the above is based on semantically related content.
The unified picture
Everything today is the same operation: Text → vector → geometry
Use
What you embed
What the geometry gives you
Word2Vec
Words
Lexical similarity, analogies
Sentence transformers
Sentences
Semantic similarity
MTEB
Many tasks
Model quality, task fit
SQuID
Survey items
Psychological structure
RAG
Documents + query
Relevance, grounded generation
The representation shift the embeddings bring is the enabling substrate. The interesting question is always: what structure lives in this space?
Key takeaway: embeddings are a general-purpose representation of meaning. Every application is a different answer to: what is close to what, and why does that matter?
Open question for discussion: when does semantic similarity fail as a proxy for relevance – and what would you build with this for your own research?
Further reading: Mikolov et al. 2013 · Reimers & Gurevych 2019 · Muennighoff et al. 2022 · Lewis et al. 2020 · Pellert et al. 2026
Attention is learned similarity
In a transformer, each token asks: which other tokens are most relevant to me right now?
The answer is a similarity computation over learned query and key vectors: