Sentence Embeddings
P10.transformer-architecture.02 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Encoder Block
Where next?
This module unlocks
Go up a level
P10.transformer-architecture.02 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Encoder Block
This module unlocks
Go up a level
The encoder block leaves us with one contextualised vector per token, but sentences have different lengths, and comparing, searching, or clustering them requires a single fixed-size vector per sentence. Pooling is the step that collapses the token rows into that one vector, and there is more than one defensible way to do it. This capstone module walks through the three classic strategies — take the first token, average them all, or keep each dimension's maximum — and then puts the result to work: every corpus sentence runs through the full pipeline, and the lab ranks them all by similarity to the query sentence you select.
Why it matters — Search, clustering, and semantic comparison all need ONE fixed-size vector per text — pooling is the bridge from token space to sentence space.
Reference: Reimers & Gurevych 2019 — Sentence-BERT
Reads /api/transformer/pooling/pipeline — loading
Computing…
Open in Labs: Pooling with and without the mask
Adapting a pre-trained model. BERT-style: fine-tune with a task head on [CLS] (or mean-pool for sentence tasks — SBERT). GPT-style: prompt with in-context/few-shot examples, no weight updates. Between them: parameter-efficient fine-tuning (LoRA/PEFT — train tiny adapters), instruction tuning, and RAG (retrieve with pooled embeddings exactly like step 6, then generate grounded on the hits).
Self-check
What is the encoder-output shape for 3 tokens with d_model = 8, and after pooling?
Self-check
Which token does BERT use as the sentence embedding?
Self-check
Which pooling strategy is most sensitive to a single highly-activated token?
Self-check
Two sentence vectors have cosine similarity 0.95 — similar or dissimilar?
Self-check
What advantage does mean pooling have over CLS without fine-tuning?
Practise this lesson's 5 self-checks
One per screen: you reveal each answer and mark it yourself. Nothing is recorded.
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
A scratch console for this page's ideas — ungraded, nothing you run here is recorded.
Scratch console
A scratch console with the scientific stack (pandas, numpy, scikit-learn). Runs on the server — no network, resource-limited and measured.
Output appears here.
Loading your notes...