Learn

Learning preferences

Make learning more comfortable. Changes apply immediately.

Enlarges page content, including diagrams and their labels. You can also use your browser’s zoom.

Choose the colours that are easiest for you to distinguish. Applies to lesson diagrams and lab plots. Labels, shapes, hatching and line patterns also distinguish meanings. Source photographs and raw image brightness stay unchanged; mask-only views are available for image overlays.

ExampleComparisonSample link

Saved in this browser on this device. Preferences are separate from progress backups.

Lesson 2 of 13 in this unit

Understand Neural Networks · SOURCE LESSON 05

Give words a place in space.

Explore vectors, similarity, and why a word’s representation can change with context.

By the end: Calculate a dot product, distinguish cosine similarity from distance, and explain the limits of embedding-based recall.

Start with the exampleJump to the experimentRead the explanation
Prerequisites and path options

Why learn this? Compare meanings represented as numbers so you can reason about search results and the information a representation loses.

01 · TRY

Start with something concrete.

A movie can have several numerical scores: comedy, action, and romance. Put those scores in a fixed order and you have a vector. A learned embedding also represents something with ordered numbers, but its coordinates usually do not have such convenient names.

Try the interactive model
02 · PREDICT
Before you experiment

We double vector B from (1,1) to (2,2). What happens to its cosine similarity with A = (1,0)?

We double vector B from (1,1) to (2,2). What happens to its cosine similarity with A = (1,0)?
03 · EXPERIMENT

Change one thing. Watch what follows.

Loading this browser experiment…

04 · UNDERSTAND
READ & CONNECT

Understand what changed.

Back to the experiment

A shorter explanation, with the original worked examples available below. Both explain the same experiment and its limits.

Same learning goal in both modes: Calculate a dot product, distinguish cosine similarity from distance, and explain the limits of embedding-based recall.

The idea in everyday terms

An embedding represents something using an ordered list of numbers, called a vector. Different comparison rules answer different questions. Distance measures how far apart two vectors are. A dot product multiplies matching entries and adds them. Cosine compares their direction while removing the effect of their lengths.

What to watch in the experiment

Move the points and compare the scores. Two arrows can point in the same direction while ending far apart. That is why a close match under one rule need not be a close match under another. Always name the comparison used by a search system.

What this does not establish

The lab’s geometry is supplied for teaching. A high similarity score does not show that a document is relevant, current or true; inspect the source and the requested fact separately.

Open the full worked examples, calculations and limitations

This is the same reference used in Technical mode. Expand it whenever you need the exact numbers, assumptions or further explanation.

A vector keeps numbers in a meaningful order

An embedding represents a token, image, object, or state as a vector: an ordered list of numbers. Order matters. The vector (1,0) is different from (0,1), just as swapping the latitude and longitude of a location changes its meaning.

Our two-dimensional drawing makes the geometry visible. Real embeddings usually have many more coordinates. The axes in this lab are simply coordinate 1 and coordinate 2. They are not universal “meaning axes,” and a real learned dimension need not correspond to a human-readable category.

Compare direction and distance

A dot product multiplies matching coordinates and adds the products. For (1,0) and (1,1), it is 1 × 1 + 0 × 1 = 1. Vector length is the square root of the sum of squared coordinates, so these lengths are 1 and √2.

Cosine similarity divides the dot product by both lengths. It compares directions: 1 means the same direction, 0 means perpendicular directions, and −1 means opposite directions. For the source example, cosine is 1/√2, about 0.7071. The zero vector has no direction, so its cosine similarity is undefined.

cos⁡(a,b)=a⋅b∥a∥∥b∥\cos(a,b)=\frac{a\cdot b}{\lVert a\rVert\lVert b\rVert}

Euclidean distance measures the straight-line gap between the endpoints. In the same example it is 1. If we stretch B to (2,2), its direction stays the same but its endpoint moves. Cosine stays about 0.7071 while distance becomes √5. Neither measure is universally best; the choice depends on how the representation was learned and what comparison is useful.

The same token can mean different things in context

“River bank” and “bank account” share the token “bank,” but their contexts favor different interpretations. A model can start from the same token embedding and produce different contextual representations after combining information from nearby positions.

The lab illustrates this with a fixed bank vector and a 50–50 average with a river or account vector. These are hand-chosen numbers, not a trained language model. The next lesson replaces that fixed average with query-dependent attention weights. Real contextual representations emerge through trained projections and multiple transformations.

Knowledge is distributed, and retrieval can be wrong

A distributed representation spreads useful distinctions across combinations of numbers. One concept need not live in one neuron, and one neuron can contribute to multiple features. In superposition, several features occupy different, potentially interfering directions in a shared space.

Similarity can retrieve useful related items, or provide weights for an associative memory that mixes stored values. But being close in an embedding space does not establish that a claim is correct, current, or an exact answer to your question. A model can reconstruct a plausible but wrong statement from learned patterns. Exact, inspectable databases and source verification remain valuable.

Entering from an application project

A retrieval system turns the query and candidate documents into comparable number lists, chooses a scoring rule, then inspects the returned text. A score is a ranking signal, not a probability that the answer is true. In the recap experiment, compare dot product, cosine and distance on the same three notices. Then check the organization, revision and exact sentence before choosing an answer. A current notice about the wrong building and an archived notice about the right building fail for different reasons.

The geometry is hand-assigned to expose these distinctions. Actual learned retrieval must also test whether its training objective produces useful rankings on different queries. Continue to keyword and learned retrieval or claim-to-source checks without completing the rest of the language course.

05 · APPLY
Check your understanding

A retrieved passage has a very high embedding similarity to your question. Which conclusion is justified?

A retrieved passage has a very high embedding similarity to your question. Which conclusion is justified?
06 · CONTINUE

Take this idea with you.

Embeddings make comparison and retrieval possible. Direction, length, and context matter—and numerical similarity is not proof of truth.

My Learning
Explore related topics and the topic map

How this topic connects

Explore this topic on the interactive map

Use these connections to review a foundation or choose where to go next. You can open any topic without completing the others.

What it builds on

  • Vectors and multiply-and-add

    Treat a list of numbers as one representation and trace weighted sums. These operations connect the lesson’s inputs to its outputs.

  • Hidden representations

    See why adding a hidden layer can solve patterns a straight boundary cannot, before paying for a larger model.

You are hereGive words a place in space

Explore vectors, similarity, and why a word’s representation can change with context.

What it enables

Show 2 more connections