IT Vizag
← How LLMs Really Work
Loading video…

How LLMs Really Work · Lesson 2 of 15 · 2 min read · 5 min video

Embeddings: meaning as numbers

How words become points in space, and why similar meanings land close together.

📄 Download slides (PDF)

Neural networks only understand numbers. So before a model can read "Visakhapatnam beach", every piece of text has to become a list of numbers. Done well, those numbers capture meaning. That list is an embedding.

Words as points in space

An embedding is a vector: a list of, say, 768 or 1,536 numbers. Think of each word as a point in a space with that many directions.

Training pushes words that appear in similar contexts close together:

  • "beach", "coast" and "seashore" end up near each other
  • "Vizag", "Visakhapatnam" and "Waltair" cluster together
  • "beach" and "spreadsheet" end up far apart

Nobody hand-labels these directions. They emerge because words used the same way get pulled together.

Directions carry meaning

Famously, in good embedding spaces, directions mean something:

king − man + woman ≈ queen

The step from "man" to "woman" points roughly the same way as the step from "king" to "queen". Similar patterns appear for country → capital and present → past tense. It's not perfect, but it shows the space is organised by meaning, not spelling.

Measuring "close"

The usual measure is cosine similarity: the angle between two vectors.

  • Close to 1: same direction, similar meaning
  • Around 0: unrelated
  • Negative: pointing opposite ways
import numpy as np

def cosine(a, b):
    return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))

beach   = np.array([0.9, 0.1, 0.3])
coast   = np.array([0.8, 0.2, 0.35])
invoice = np.array([0.05, 0.9, 0.1])

print(cosine(beach, coast))    # high, ≈ 0.99
print(cosine(beach, invoice))  # low,  ≈ 0.19

Real embeddings have hundreds of dimensions, but the maths is identical.

Sentences and documents too

Embedding models can turn a whole sentence or paragraph into one vector. That's what makes semantic search possible:

  • "How do I reset my password?" and "I forgot my login" share almost no words
  • Their embeddings are still close, because they mean the same thing

This is the engine behind RAG and vector databases, later in this course.

Inside an LLM

An LLM starts by looking up an embedding for every token in its input. Those vectors are then refined layer by layer, so by the end, the vector for "bank" in "river bank" differs from "bank" in "bank loan". These are contextual embeddings, and attention (next lesson) is what makes them contextual.

In one line

An embedding turns text into a point in a high-dimensional space where distance means difference in meaning, which is what lets machines search and reason by meaning.

Saved on this device. Sign in to keep progress everywhere.

Share with a friend