What Is an Embedding in AI? Embeddings Explained With Examples

By LatestLLM Editorial · Published · Facts verified · 9 min read

Also called: embeddings, word vectors, token embedding, vector embedding, embedding layer

Before this: Token, Tokenizer

In one line

An embedding is a list of numbers, a vector, that represents a token or a piece of text so that things with similar meaning end up close together.

Embedding, simply and technically

In plain English

A computer cannot do maths on the word "cat", but it can do maths on numbers. An embedding is how a model gives every token a long list of numbers, such as a few thousand of them, that stands for what the token means. These numbers are not chosen by people. The model adjusts them during training until tokens used in similar ways get similar lists.

Once meaning is turned into numbers, closeness can be measured. "Cat" and "kitten" end up near each other, while "cat" and "carburettor" are far apart. Search engines, recommendation systems and chatbots that look things up in your documents all rely on this: they turn text into embeddings and look for the nearest ones.

Think of it like this: Imagine a huge map where every word has a pin. Words with related meanings are pinned in the same neighbourhood: animals in one area, vehicles in another, and "kitten" right next to "cat". An embedding is a word's map coordinates. The difference is that the real map has hundreds or thousands of directions instead of two, so it can keep many kinds of similarity apart at once.

Everyday example: Finding a recipe without the exact words

A cooking app uses embeddings to search its recipes. You type a request that shares no words with the recipe title.

Input:

something warm for a cold evening

Output:

Top result: Slow-cooked beef and vegetable stew

What it shows: Keyword search would find nothing, because none of your words appear in the title. Embedding search compares meanings instead: your request and the stew recipe land near each other on the meaning map, so the app can match them.

Technically

In a language model, the embedding layer is a learned matrix E of shape V x d, where V is the vocabulary size and d the model width. Embedding a token is a row lookup: token id t maps to the vector E[t]. For gpt-oss, E is 201,088 x 2,880; for DeepSeek-V3 it is 129,280 x 7,168. The rows are trained by backpropagation together with the rest of the network, so geometry emerges from the prediction task.

A separate but related use is the text embedding model, such as all-MiniLM-L6-v2 with 384 dimensions, which maps a whole sentence to one vector for search. Similarity is usually cosine similarity, the dot product of the vectors divided by their lengths, which ranges from -1 (opposite) through 0 (unrelated) to 1 (same direction).

Technical example: Cosine similarity between three toy vectors

Compare three hand-written 3-dimensional vectors standing in for learned embeddings.

Input:

cat = [0.8, 0.1, 0.3]
kitten = [0.7, 0.2, 0.4]
car = [-0.5, 0.9, 0.0]

Code (python):

import math

def cosine(a, b):
    dot = sum(x * y for x, y in zip(a, b))
    norm = math.sqrt(sum(x * x for x in a)) * math.sqrt(sum(y * y for y in b))
    return dot / norm

cat = [0.8, 0.1, 0.3]
kitten = [0.7, 0.2, 0.4]
car = [-0.5, 0.9, 0.0]

print("cat~kitten", round(cosine(cat, kitten), 2))  # 0.98
print("cat~car", round(cosine(cat, car), 2))        # -0.35

Output:

cat~kitten 0.98
cat~car -0.35

What it shows: Vectors pointing the same way score near 1 and opposing ones score below 0. Real embeddings work the same way, but with hundreds or thousands of dimensions and values learned from data rather than written by hand.

A map of real word embeddings. Fifty-six everyday words in seven groups, placed on a 2D map by projecting their real 384-dimensional embeddings from the all-MiniLM-L6-v2 model. Click any word to highlight its nearest neighbours by cosine similarity in the full 384 dimensions, and see how the flat map approximates them. Embeddings from sentence-transformers/all-MiniLM-L6-v2, reduced to two dimensions with PCA for display.

From token ids to vectors

In plain English: After the tokenizer has turned your text into numbers, each number is only a label, like a seat number in a stadium. The embedding step swaps each label for a rich description of that token, a long list of numbers the model has learned. From here on, the model works only with these lists.

Think of it like this: The token id is the name on a library card; the embedding is the full catalogue record behind it.

Technically:

A token id is a categorical value with no notion of distance: id 9059 (" cat") is not closer to 9060 than to 50000. The embedding layer turns ids into dense vectors in R^d, equivalent to multiplying a one-hot vector by E but implemented as an index lookup. The result is a sequence of n vectors, an n x d matrix, which is the input to the first transformer block.

Most decoder models add no separate position embedding at this step; position is injected later inside attention with rotary position embeddings (RoPE). Older models such as GPT-2 added a learned position vector to each token vector here.

Go deeper: details for practitioners
  • Some models scale the looked-up vector before the first block. Gemma, for example, multiplies embeddings by the square root of the model width so their magnitude matches the rest of the network.
What is a vector?

An ordered list of numbers. A 2,880-dimensional vector is a list of 2,880 numbers.

What is a one-hot vector?

A vector of zeros with a single 1 at the position of the token id; multiplying it by the embedding matrix selects one row.

Why similar meanings end up close

In plain English: Nobody tells the model that "cat" and "kitten" are related. It discovers this because the two words appear in similar sentences, such as "the ___ chased the mouse". To predict the next word well, it helps to treat them alike, so training nudges their number lists towards each other.

Technically:

This is the distributional hypothesis: words that occur in similar contexts have similar meanings. word2vec (Mikolov et al., 2013) showed that a shallow network trained to predict neighbouring words learns vectors with linear structure, where the offset from "man" to "woman" roughly matches the offset from "king" to "queen". LLM embedding layers learn similar structure as a by-product of next-token prediction.

Cosine similarity is preferred over raw distance because vector length often encodes frequency or confidence rather than meaning. Normalising to unit length and taking the dot product isolates direction, which is what similarity search compares.

Everyday example: Context changes meaning

Two sentences use the same word: "She sat on the river bank" and "She opened a bank account".

What it shows: The word starts with the same embedding in both, but after the model reads the surrounding words its internal numbers for "bank" move towards either nature or money. That is how the model tells the meanings apart.

Go deeper: details for practitioners
  • Inside a transformer the input embedding is only the starting point. Each layer rewrites the vectors using context, so the representation of "bank" after a few layers differs between "river bank" and "bank account". These are called contextual embeddings.
What is cosine similarity?

The dot product of two vectors divided by the product of their lengths. It measures how closely they point in the same direction, from -1 to 1.

Embeddings in real models

In plain English: In large chatbots the embedding table is big: one row of numbers for every token the model knows. For models in use today that alone can hold hundreds of millions to more than a billion numbers, yet it is still a small part of the whole model.

Technically:

Sizes follow V x d: gpt-oss stores 201,088 x 2,880 = 579,133,440 parameters in its input embedding; DeepSeek-V3 stores 129,280 x 7,168 = 926,679,040; Gemma 4 31B stores 262,144 x 5,376 = 1,409,286,144. gpt-oss and DeepSeek-V3 keep a separate output matrix of the same shape, while Gemma ties input and output, using one matrix for both.

At the output end, the final hidden state is multiplied by the unembedding matrix to give one score, a logit, per vocabulary entry, and a softmax turns the scores into next-token probabilities. Tying the two matrices forces a token's input vector and its output direction to be the same, which saves parameters and works well for smaller models.

Go deeper: details for practitioners
  • Gemma 4's smallest sizes also add per-layer embeddings: extra small lookups feeding each layer, stored so they can be kept off the accelerator. They are covered in the Gemma 4 architecture guide.
What is the unembedding?

The output matrix that turns the model's final vector into a score for every token in the vocabulary.

Common misconceptions

  • Myth: Each number in an embedding has a human meaning, like "animal-ness".

    Reality: Individual dimensions are rarely interpretable. Meaning lives in directions and distances across many dimensions at once.

  • Myth: The embeddings inside a chatbot are the same as the ones used for search.

    Reality: An LLM's token embeddings are per token and get rewritten by every layer; search uses a separate model that produces one vector per text.

  • Myth: Embeddings store the text so it can be read back.

    Reality: An embedding is a lossy summary of meaning. You cannot reliably reconstruct the exact original text from it.

Where you'll see this

  • Gemma 4 architecture: Gemma 4 ties its input embedding to the output layer and adds per-layer embeddings in small sizes.
  • gpt-oss architecture: gpt-oss looks up 2,880-dimensional vectors from a 201,088-row table.
  • DeepSeek-V3 architecture: DeepSeek-V3 embeds tokens into 7,168 dimensions with separate input and output matrices.

Key takeaways

  • An embedding turns a discrete token or text into a vector of numbers that the network can compute with.
  • Inside an LLM, embedding a token is just looking up one row of a learned V x d matrix.
  • Training shapes the space so that tokens used in similar contexts get nearby vectors, which is why closeness reflects meaning.
  • Text embedding models produce one vector per sentence or document and power semantic search and retrieval-augmented generation.

Frequently asked questions

What is an embedding in simple terms?

A list of numbers that represents the meaning of a word or text, arranged so that similar meanings get similar numbers.

How many dimensions does an embedding have?

It depends on the model: 384 for all-MiniLM-L6-v2, 2,880 inside gpt-oss and 7,168 inside DeepSeek-V3.

Are embeddings learned or designed?

Learned. They start random and are adjusted during training until they help the model make good predictions.

What are embeddings used for outside chatbots?

Semantic search, recommendations, clustering, duplicate detection and retrieval for RAG systems.

What is the difference between an embedding and a token?

A token is a piece of text with an id. Its embedding is the vector of numbers the model uses in place of that id.

Sources

Facts last verified November 23, 2026.

Next concept: Dimension

Learn next

  • Dimension (Intermediate): A dimension is one slot in a vector, and a model's dimension or hidden size is how many numbers it uses to represent every token at each layer.
  • Attention (Intermediate): Attention is the step where each token looks back at the earlier tokens, scores how relevant each one is, and blends in information from the most relevant.
  • RAG and vector search (Intermediate): Retrieval-augmented generation looks up the passages most relevant to a question using embeddings, then gives them to a language model so it answers from those sources.
  • Multimodal models (Intermediate): A multimodal model accepts more than text by cutting an image into small patches, turning each into a vector, and feeding those vectors to the transformer as if they were tokens.