Reviews representation learning as learning transformations of the data that make useful explanatory factors easier to extract (IEEE TPAMI).
Representation Learning & Embedding Geometry
How models turn inputs into vectors whose geometry can expose useful factors, contextual meaning, and similarity structure.
Intuition
The idea in plain words, before the symbols.
A neural network turns each input into vectors: lists of numbers that later layers compute with. A vector produced this way is called a representation or an embedding. Representation learning is the study of how training shapes these vectors so that useful properties of the input become easy to read off (Bengio et al., 2013).
Ideally:
- inputs that mean similar things get nearby vectors,
- unrelated inputs point in different directions,
- and simple operations on the vectors, such as dot products, distances and averages, answer useful questions: which documents match a query, which images form a cluster, which label a small classifier should predict.
When this works, embeddings can be reused: for similarity search, as inputs to small classifiers, or to study which directions carry which information. It can also go wrong. Contextual embeddings from language models are often anisotropic: they share a common direction, so even unrelated words have high cosine similarity (Ethayarajh, 2019), which makes raw similarity scores less informative.
Context matters too. A static word vector gives the word "bank" one vector everywhere. A contextual representation gives the token a different vector depending on whether the sentence is about rivers or money. ELMo made this practical by building token vectors from the layers of a bidirectional language model (Peters et al., 2018).
Study prompts for this section: Intuition
Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.
Mathematics
Definitions, assumptions and the derivation.
Let an encoder map each input to a vector . If a simple predictor can recover a useful factor from , the representation has made that factor easy to extract. For contextual word representations, the vector for token can depend on the whole sentence :
Here is the predicted value of a factor or label , is a simple extractor such as a linear classifier (a "probe"), and is the bidirectional language model's state for token at layer , with the context-free token embedding. Peters et al. combine the layers with task-specific softmax weights and a scale . Because every with depends on the whole sentence, the same word receives different vectors in different sentences.
Similarity as a dot product (often cosine)
A common choice is cosine similarity, which is just a dot product of normalized vectors:
Normalization matters because it makes similarity depend on direction instead of length.
Contrastive learning (InfoNCE)
Suppose we have positive pairs : two views of the same thing, such as two crops of one image or an image and its caption. Encode them with the same encoder () or with two separate encoders:
InfoNCE treats as the correct match among a batch of candidates:
- Each term is a cross-entropy loss for picking the true partner out of the candidates in the batch; the other are the negatives.
- is the temperature. Smaller sharpens the softmax, so most of the gradient comes from the negatives most similar to .
- For independent pairs drawn from the joint distribution, with negatives drawn from the marginal distribution, van den Oord et al. (2018) bound the mutual information between the views by . The expectation is over sampled batches; the bound does not apply to every individual batch loss.
Checking for anisotropy
Two quick checks on a set of normalized embeddings with mean . First, the length : near when directions are spread out, near when all vectors point roughly the same way. Second, the covariance
If a few of its eigenvalues dominate, the vectors vary mainly along a few directions, which can dominate cosine comparisons. Subtracting the mean, or whitening with , changes this geometry.
Study prompts for this section: Mathematics
Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.
Code
The same calculation as runnable code, in the notation of the derivation.
import numpy as np
def unit(v):
return v / (np.linalg.norm(v) + 1e-9)
# Toy handcrafted features: axis 0 = water-vs-finance context,
# axis 1 = the token identity "bank", axis 2 = filler.
feat = {
"river": np.array([1.0, 0.0, 0.0]),
"shore": np.array([1.0, 0.0, 0.0]),
"money": np.array([-1.0, 0.0, 0.0]),
"loan": np.array([-1.0, 0.0, 0.0]),
"bank": np.array([0.0, 1.0, 0.0]),
}
def contextual(left, token, right):
return unit(0.55 * feat[token] + 0.35 * (feat[left] + feat[right]))
static_bank = unit(feat["bank"])
river_bank = contextual("river", "bank", "shore")
money_bank = contextual("money", "bank", "loan")
water_probe = unit(np.array([1.0, 0.0, 0.0]))
def water_score(z):
return float(z @ water_probe)
print("static bank:", round(water_score(static_bank), 3))
print("river bank: ", round(water_score(river_bank), 3))
print("money bank: ", round(water_score(money_bank), 3))
assert water_score(river_bank) > water_score(static_bank) > water_score(money_bank)
assert np.linalg.norm(river_bank - money_bank) > 1.4
The code builds a contextual vector for "bank" by mixing its own hand-chosen feature with those of its two neighbors, then reads the water-versus-finance axis with a fixed linear probe. The static vector scores , "river bank" about and "money bank" about : the same token, two different representations.
Study prompts for this section: Code
Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.
Demo
Change an input, predict the result, and see which quantities respond.
Explore Representation Learning & Embedding Geometry
Observation guide
Optional and ungraded. Opening a guide saves nothing.
Choose what to inspect in Representation Learning & Embedding Geometry, then open its guide.
The demo has four tabs:
- Normalization: LayerNorm and RMSNorm both remove a vector's overall scale, so only its direction is left to compare. LayerNorm also subtracts the mean first, which can change that direction; the demo measures the change with cosine similarity.
- Directions: task vectors, which are differences in weight space, not representation space: the weights of a fine-tuned model minus the pretrained weights. Adding or subtracting them edits behavior (Ilharco et al., 2023).
- Equivariance: feature maps that change predictably when the input is transformed. Rotate the input, and an equivariant output rotates with it, while an invariant output does not change.
- Geometry: moving a direction along a curved surface without twisting it (parallel transport).
Study prompts for this section: Demo
Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.
Concept: Representation Learning & Embedding Geometry
What is the smallest example of Representation Learning & Embedding Geometry you can work through by hand, and what does it show?
DetailsRepresentation Learning
Reference id
concept:representation-learning/representationsAfter the first pass
Go deeper
Optional material for a second reading. Sources are always shown; the other panels open from their headings or from these links, and closing one keeps what you wrote or revealed.What to look for in each sectionChoose a section and what you expect to see in it, then read short advice.
Section by section
Choose what to look for in each section
How models turn inputs into vectors whose geometry can expose useful factors, contextual meaning, and similarity structure.

Start with the picture, metaphor, or geometric mechanism.
Choose what you expect to see in this section of Representation Learning & Embedding Geometry.
Questions to ask of the pictureChoose a part of the picture and what you expect, then read short advice.
Looking at the picture
Questions to ask of the picture
How models turn inputs into vectors whose geometry can expose useful factors, contextual meaning, and similarity structure.
Which part of the picture should you look at first?
Pick the part of the picture you expect to explain Representation Learning & Embedding Geometry.
Sources
References for this page
A reference shows where an idea comes from; it does not vouch for every step on this page.Introduces ELMo, contextual word vectors computed from all layers of a bidirectional language model, so a word's vector depends on its sentence (NAACL 2018).
Introduces contrastive predictive coding and the InfoNCE loss, which scores a positive pair against negative samples, and shows that minimizing it maximizes a lower bound on mutual information.
Finds that contextual word representations are anisotropic in every layer of ELMo, BERT and GPT-2, and that upper layers produce more context-specific representations (EMNLP-IJCNLP 2019).
Defines a task vector as the weights of a fine-tuned model minus the pretrained weights, and edits behavior by adding, negating or combining task vectors (ICLR 2023).
What each claim rests on1 claim, each with its sources, where it appears on this page, and its caveats.
Claims and sources
How models turn inputs into vectors whose geometry can expose useful factors, contextual meaning, and similarity structure.
The checks were made by this site, not by an independent reviewer.
Bengio et al. frame representation learning as learning transformations that expose useful explanatory factors and make useful information easier to extract. Peters et al. introduce ELMo contextual word repr...
Covers only useful-factor extraction and ELMo-style contextual token vectors. It does not cover InfoNCE, retrieval quality, task vectors, anisotropy fixes, equivariance, parallel transport, or all representa...
Bengio et al. support representation learning as learned features that make useful information or explanatory factors easier for predictors to extract. Peters et al. support ELMo as sentence-contextual token representations from biLM layer states, including task-specific layer weighting and polysemy disambiguation. The equations and the code on this page illustrate this claim; the geometry demos are not covered.
Explain it without the pageWrite your own explanation before asking for feedback. Your draft and any hints stay while this page is open.
Practice · Representation Learning & Embedding Geometry
Try the idea in your own words
How models turn inputs into vectors whose geometry can expose useful factors, contextual meaning, and similarity structure.
Concept · Selected for practice
Representation Learning & Embedding Geometry
What it rests on: Sources: Representation Learning: A Review and New Perspectives; Deep contextualized word representations; Representation Learning with Contrastive...
Context and links
Representation Learning
Explain the mechanism
For Representation Learning & Embedding Geometry: What is the smallest example of Representation Learning & Embedding Geometry you can work through by hand, and what does it show? Explain your answer, including what changes, why, and which assumption matters.
A rough first thought is enough. Your draft stays when you change tasks.
Your draft stays on this page and is cleared when you leave or reload.
A little help · Explain
Open one hint at a time. These are suggestions, not your answer or a grade.
0 of 3 hints shown for this question.
Clearing your answer keeps this help record. Outside help is your own report; this page cannot check it.
Where am I stuck? (optional)
Take your draft to a feedback conversation
No AI feedback runs here. You can copy a prompt to use elsewhere; nothing is sent automatically. Review the text before sharing, and leave out private information.
Write an attempt before copying a feedback prompt.
A draft, or an AI reply to it, is not a test of what you have learned. To check that, try a different case later without help.
Ask about this pagePick one item on this page and copy a prompt about it into an AI assistant you already use. Notes you write here stay in this browser.
assert water_score(river_bank) > water_score(static_bank) > water_score(money_bank)Your question
Choose what your question is about
Pick the idea, equation, source, code, claim, misconception or demo state you want to ask about. The prompt you copy includes it, so the answer can stay on that item.Open the draft below to save one note and next action in this browser.
Representation Learning & Embedding Geometry
What is the smallest example of Representation Learning & Embedding Geometry you can work through by hand, and what does it show?
Fixed prompts generated from this item. They are not comments from people or independent reviews.
The 5 cited sources must support this exact item, not just the surrounding topic.
Connect the definition to one equation, piece of code or demo before widening the discussion.
Change one input, then check that the same relationship holds in the mathematics, the code and the demo.
You can state the mechanism in your own words
Local action draftNo local draft saved yetOpen when you are ready to write one next action
This draft stays in this browser and is attached to this item only.
- What the 5 cited sources say about this exact item
- The definition, its prerequisites, and a contrasting concept
- The equation or code that makes the concept concrete
- One demo state that shows what stays the same as the inputs change
- You can state the mechanism in your own words
- You can name the prerequisite that would clear up the confusion
- You can predict how the result changes when one input changes
Reference id
concept/concept-notebook/representation-learning/representations
concept:representation-learning/representations