Representation Learning

Representation Learning & Embedding Geometry

How models turn inputs into vectors whose geometry can expose useful factors, contextual meaning, and similarity structure.

status: publishedimportance: importantdifficulty 3/5math: undergraduateread: 18mlive demo
Editorial representation-learning illustration of embedding clusters, geometric neighborhoods, and feature directions.

Concept Structure

Representation Learning & Embedding Geometry

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

1prerequisites
3next concepts
2related links

Learning map

Representation Learning & Embedding Geometry
BeforeScaled Dot-Product Attention & Transformer LayersNow4/4 sections readyTryManipulate one control and predict the visible change.Nextsuperposition

Object flow

4/4 sections readyAsk about thisResearch room
ConceptRepresentation Learning & Embedding GeometryRepresentation Learning
3 sources attachedLocal snapshot ready
concept:representation-learning/representations

Conceptual Bridge

What should feel connected as you move through this page.

Carry inScaled Dot-Product Attention & Transformer Layers

Bring the mental model from Scaled Dot-Product Attention & Transformer Layers; this page will reuse it instead of restarting from zero.

Work hereRepresentation Learning & Embedding Geometry

How models turn inputs into vectors whose geometry can expose useful factors, contextual meaning, and similarity structure.

Carry outsuperposition

The next edge should feel earned: use the demo prediction here before following superposition.

Test the linkManipulate one control and predict the visible change.Then continue to superposition
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

A model can only "think" in the space it uses internally. In deep learning, that internal space is usually a vector space: an embedding.

A common goal of representation learning is to make learned features expose useful factors of variation. We want vectors where:

  • things that "mean the same" are close,
  • things that are different point in different directions,
  • and simple operations (dot products, distances, averages) line up with useful questions (retrieval, clustering, analogy, control).

When this works, embeddings become an interface. Depending on the model and training objective, they are often used for similarity search, lightweight classifiers, or analyses of directions in representation space. When it fails, vectors collapse into weird shapes (anisotropy, degenerate norms) and similarity becomes noisy.

Context matters too. A static word vector gives one vector to a word type, but a contextual representation lets the token "bank" move depending on whether the surrounding sentence is about rivers or money. That is the ELMo lesson: the useful feature is not only the token identity, but the token identity as interpreted through its context.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let an encoder map inputs to vectors. If a simple downstream predictor can recover a useful factor from the vector, the representation has made that factor easier to extract. For contextual word representations, the token vector can depend on the whole sentence:

z=fθ(x)Rd,a^=gψ(z),ELMoktask=γtaskj=0Lsjtaskhk,jLM(t1,,tN).\begin{aligned} z &= f_\theta(x)\in\mathbb R^d,\qquad \hat a = g_\psi(z),\\ \operatorname{ELMo}^{\mathrm{task}}_k &= \gamma^{\mathrm{task}}\sum_{j=0}^{L}s^{\mathrm{task}}_j\, h^{\mathrm{LM}}_{k,j}(t_1,\ldots,t_N). \end{aligned}

Here aa is a useful factor or label we hope is easy to read from zz, gψg_\psi is a simple extractor such as a classifier or probe, and hk,jLMh^{\mathrm{LM}}_{k,j} is the bidirectional language-model state for token position kk at layer jj. Peters et al. use task-specific softmax weights sjtasks_j^{\mathrm{task}} and scale γtask\gamma^{\mathrm{task}} to combine the biLM layers, so the same token position can receive a different vector in a different sentence.

Similarity as a dot product (often cosine)

A common choice is cosine similarity, which is just a dot product of normalized vectors:

sim(z,z)=zzz2z2=z^z^.\mathrm{sim}(z, z') = \frac{z^\top z'}{\lVert z\rVert_2\,\lVert z'\rVert_2} = \hat z^\top \hat z'.

Normalization matters because it makes similarity depend on direction instead of length.

Contrastive learning (InfoNCE)

Suppose we have "positive pairs" (xi,yi)(x_i, y_i) (two views of the same thing: two crops of an image, two versions of a sentence, etc.). Encode them:

zi=fθ(xi),ui=gθ(yi).z_i = f_\theta(x_i), \qquad u_i = g_\theta(y_i).

InfoNCE treats (zi,ui)(z_i, u_i) as the correct match among a batch of candidates:

L=1Ni=1Nlogexp(sim(zi,ui)/τ)j=1Nexp(sim(zi,uj)/τ).\mathcal L = -\frac{1}{N} \sum_{i=1}^N \log \frac{\exp\big(\mathrm{sim}(z_i, u_i)/\tau\big)}{\sum_{j=1}^N \exp\big(\mathrm{sim}(z_i, u_j)/\tau\big)}.
  • τ>0\tau > 0 is the temperature: smaller τ\tau makes the softmax sharper (harder negatives, bigger gradients).
  • In contrastive-learning setups, this kind of objective scores the intended pair above other candidates.

A useful geometry sanity check: anisotropy

Embeddings often become anisotropic (many points bunch along a few dominant directions). A practical check is the covariance of normalized embeddings:

C=1Ni=1N(z^izˉ)(z^izˉ).C = \frac{1}{N}\sum_{i=1}^N (\hat z_i - \bar z)(\hat z_i - \bar z)^\top.

If a few eigenvalues dominate, the embedding cloud is highly directional, which can affect cosine-based comparisons. Normalization or whitening-style preprocessing can change this geometry.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
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
04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

Use the demos to build geometric intuition:

  • how normalization changes similarity (direction vs length),
  • how "directions" in representation space can encode behaviors (task vectors),
  • and how geometric constraints like equivariance preserve structure.

Live Concept Demo

Explore Representation Learning & Embedding Geometry

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 3/5undergraduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Representation Learning & Embedding Geometry should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

How models turn inputs into vectors whose geometry can expose useful factors, contextual meaning, and similarity structure.

Prediction open01 / Intuition
Editorial representation-learning illustration of embedding clusters, geometric neighborhoods, and feature directions.
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Representation Learning & Embedding Geometry should make visible.

Visual Inquiry

Make the image answer a mathematical question

How models turn inputs into vectors whose geometry can expose useful factors, contextual meaning, and similarity structure.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Representation Learning & Embedding Geometry easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

paper · 2013Representation Learning: A Review and New PerspectivesBengio, Courville, and Vincent

Grounds representation learning as learning useful explanatory factors and feature geometry.

Open source
paper · 2018Deep contextualized word representationsPeters et al.

Grounds contextual embeddings as representations whose meaning changes with surrounding context.

Open source
paper · 2018Representation Learning with Contrastive Predictive Codingvan den Oord, Li, and Vinyals

Grounds contrastive predictive coding and InfoNCE-style losses that score positive pairs against negative samples.

Open source

Claim Review

How models turn inputs into vectors whose geometry can expose useful factors, contextual meaning, and similarity structure.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources3 references

bengio-2013-representation-learning, peters-2018-elmo, oord-2018-cpc

Witnesses4 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Substantively reviewedRepresentation learning trains encoders to transform raw inputs into internal features that make useful factors easier to extract; ELMo-style contextual embeddings make token representations depend on sentence context.Claim metadata: source checked

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 representations from biLM states that model word use and how it varies across linguistic context. Local math/code witness the extractor and contextual-token clauses.

Sources: Representation Learning: A Review and New Perspectives, Deep contextualized word representationsChecks only useful-factor extraction and ELMo-style contextual token dependence. It does not certify InfoNCE, retrieval quality, task vectors, anisotropy fixes, equivariance, parallel transport, or all representation-learning subfields.A bounded review summary is present; still check caveats and exact source scope.

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. Local math and code witness this bounded claim; broader geometry demos stay out of scope.

Reviewer: codex+oracle+codex-5.3; reviewed 2026-05-08

Practice Loop

Try the idea before it explains itself

How models turn inputs into vectors whose geometry can expose useful factors, contextual meaning, and similarity structure.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Representation Learning & Embedding Geometry.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptRepresentation Learning & Embedding GeometryRepresentation Learning

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptRepresentation Learning

Representation Learning & Embedding Geometry

Anchored question

What is the smallest example that makes Representation Learning & Embedding Geometry click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:representation-learning/representations.

No local draft saved.
Evidence to inspect
  • Source ids to inspect: bengio-2013-representation-learning, peters-2018-elmo, oord-2018-cpc
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Representation Learning & Embedding Geometry Object key: concept:representation-learning/representations Context: Representation Learning Anchor id: concept/concept-notebook/representation-learning/representations Open question: What is the smallest example that makes Representation Learning & Embedding Geometry click without losing the math? Evidence to inspect: - Source ids to inspect: bengio-2013-representation-learning, peters-2018-elmo, oord-2018-cpc - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

Open source object
concept/concept-notebook/representation-learning/representations concept:representation-learning/representations