Concepts / Introduction to Word Embeddings

Introduction to Word Embeddings

Embedding means converting data into a vector format, and it can be applied to video, audio, and text.

  • Programming

Can One Model Handle Every Input?

Once you learn that a neural network can turn text into a list of numbers, a tempting conclusion follows. If the numbers capture meaning, then the same network should be able to handle any kind of input. Sound, images, and video all carry information too, so why not feed them through the same machinery and collect the same kind of output? This article examines that idea, explains why it breaks down, and shows how the different families of text embeddings fit together.

What do you think happens?

A model has learned to turn English sentences into vectors that capture meaning. Can the same model turn an audio recording into useful vectors?

  • Yes, because numbers capture meaning no matter where they come from

  • No, because the model was built around the structure of text

Reveal answer
Answer:

No. The model should not be used for audio. An embedding model is shaped by the kind of data it was built to read, and the patterns it learned from text do not transfer to audio or video.

Vectors produced by a text model fed with audio look valid in form, but they carry no useful meaning for the audio they came from.

What Embedding Means

Definition

Embedding is the process of converting data into a vector format. A vector is a list of numbers that stands in for the original data inside a computation.

The conversion can be carried out in two ways. It can use a specific neural network layer, or it can use some other pretrained neural network model. Both routes produce the same kind of result: a numeric representation of the input. The important point is the output. Whatever the input was, the embedding is a vector that the rest of a computation can work with.

Embedding is not restricted to one kind of input. The same general idea applies to video, audio, and text. What changes from one kind to another is the model doing the conversion, not the idea of turning the data into a vector.

Why Each Data Type Needs Its Own Model

Each format has its own structure. Video has frames, sound has a waveform, and text has a sequence of symbols. An embedding model has to be built around the structure of the data it reads. This is why the source emphasizes that different data formats require distinct embedding models, and why a text model should not be used for audio or video.

Data typeStructure the model must readEmbedding model it needs
VideoFramesA model built for video
AudioWaveformA model built for audio
TextSequence of symbols in a sentenceA model built for text

Each data type has a structure, and each structure calls for its own embedding model.

The mistaken belief is that a single embedding model can be applied to any data type. Treating a text model as a universal converter does not fail loudly. It produces vectors that look perfectly valid in form but carry no useful meaning for the input they came from. This silent failure is what makes the mistake dangerous.

Word, Sentence, and Document Embeddings

Within the text domain, the unit being embedded can vary. The most common form is the word embedding, which gives a vector for an individual word. The source also describes embeddings for larger units of text: sentences, paragraphs, and whole documents. Choosing the unit is a design decision, because the size of the unit determines what the resulting vector summarizes.

An individual wordmost common formA sentence orparagraphused in retrieval-augmentedgenerationA whole documentlargest unit of text
The unit being embedded decides what the resulting vector summarizes: a single word, a sentence or paragraph, or a whole document.

The source gives one concrete use case. Sentence and paragraph embeddings are popular in retrieval-augmented generation, which combines two activities. Generation is producing text. Retrieval is searching an external knowledge base. The technique pulls in relevant information while text is being generated. The source treats the technique itself as beyond its scope, so this article only notes where it connects to embeddings. The source does not describe a specific use case for whole-document embeddings, so you should treat the document level as the largest unit of text rather than as a use case with its own method.

Tracing Text Through the Preparation Path

Suppose you have already split a piece of text into tokens and assigned each token an integer ID. You now have a list of numbers that stands in for the sentence. What does the model receive as its input once those integers exist? The short answer is that the integers are converted into embedding vectors, and those vectors are what the LLM works with during training.

The full preparation path runs from input text to tokenized text, then to token IDs, then to embedding vectors. Each stage changes the form of the data while keeping track of the same content. The last stage gives the model numeric input that it can adjust during learning. The diagram below follows one short sentence through all three stages.

Raw input textsentence as writtenTokenstext split into tokensToken IDsone integer per tokenEmbedding vectorsone vector per tokentokenizemap to IDsconvert to vectors
What happens to raw input text, step by step, before it becomes token embedding vectors, and what each stage outputs.

Token IDs Versus Embedding Vectors

The last transition is the least obvious, so it deserves a closer look. Each token ID is paired with its own embedding vector. The conversion keeps the identity of each token while changing its form. One ID leads to one embedding vector, and the pairing is the important idea to hold onto. The source does not describe the internal arithmetic of this lookup, so the diagram below shows only the correspondence.

ID 12token TheVector for ID 12row 12 of the embeddingmatrixID 7token catVector for ID 7row 7 of the embeddingmatrixID 31token satVector for ID 31row 31 of the embeddingmatrixselects rowselects rowselects row
A single integer token ID selects one specific row of the embedding weight matrix. The ID is a number that identifies a token; the row is the vector the model receives. These are different kinds of things.

The IDs in this diagram are illustrative values chosen for the example sentence The cat sat. The pairing is what matters. Each ID picks out one vector, and the vector is a different thing from the ID. The ID is an integer that names a token. The vector is a list of numbers the model can adjust during learning.

RepresentationWhat it isRole in the pipeline
Token IDA single integer that identifies a tokenOutput of the tokenization and lookup stage
Embedding vectorA representation of a token in a form the model can use for learningInput that the model learns from

Token IDs and embedding vectors both represent the same tokens, but they play different roles.

Where Embedding Weights Begin and End

The values inside the embedding vectors do not come from a dictionary of meanings. Embedding weights start with random values. They are then optimized during LLM training, which means the training process updates them so they become more useful for the task. At the start, a vector for a token carries no meaning. Over training, the same vector is adjusted.

Vector for catrandom starting valuesVector for catvalues adjusted by trainingLLM training optimizes weights
The same token's vector begins with random values and is updated as LLM training optimizes the embedding weights.

Mistakes Learners Make with Embeddings

  • Common mistake

    Reusing a text embedding model for audio or video

    What it looks like

    Feeding a sound recording through a model that was built to read sentences and expecting useful vectors.

    Why it fails

    An embedding model is shaped by the kind of data it was built to read. Text patterns do not transfer to audio or video.

    Do this instead

    Choose an embedding model built for the data type you have.

  • Common mistake

    Treating embedding as a single universal conversion

    Why it fails

    Embedding is a general idea, but the model doing the conversion must match the structure of the input.

    Do this instead

    Keep the idea of embedding separate from the model that performs it.

  • Common mistake

    Confusing a token ID with its embedding vector

    What it looks like

    Thinking the integer 7 for the token cat is itself the representation the model learns from.

    Why it fails

    The ID is an identifier. The embedding vector is the representation the model receives.

    Do this instead

    Treat the ID as the key that selects one vector, and the vector as the model input.

  • Common mistake

    Assuming random starting embedding values already carry meaning

    Why it fails

    Embedding weights start with random values and only become useful when they are optimized during LLM training.

    Do this instead

    Read initial embeddings as a starting point that training changes.

  • Common mistake

    Assuming the choice of embedding unit does not matter, when a word, a sentence, and a document each summarize different amounts of text.

Practice Tracing the Pipeline

EASY

Take the sentence The dog barked. Write the output of each preparation stage in order: first the tokens, then a made-up integer ID for each token, then describe what the embedding vector stage produces for each ID. For each stage, say whether the content of the sentence has changed or only its form.

Hints
  • Tokenizing splits text into pieces but keeps the same content.
  • Each token gets one integer ID, and the IDs are not yet vectors.
  • Each ID is converted into one embedding vector, and that vector is the input the model learns from.
  • The content is preserved at every stage; only the form changes.
MEDIUM

A colleague says that because a text model turns sentences into meaningful vectors, the same model can be used to embed a video clip for search. Explain in your own words why this reasoning fails, and name the one thing you would check before choosing a model for the video.

Hints
  • Think about what structure the model learned to read.
  • Video has its own structure, such as frames.

Recap of Embedding Concepts

  1. 1
    Embedding converts data into a vector, which is a list of numbers that stands in for the original data inside a computation, and it applies to video, audio, and text.
  2. 2
    Different data formats require distinct embedding models, so a text model should not be used for audio or video.
  3. 3
    Word embeddings are the most common text embedding, while sentence, paragraph, and document embeddings cover larger units of text.
  4. 4
    The preparation path runs from text to tokens, then to token IDs, then to embedding vectors. Each token ID picks out one embedding vector, and the vector is what the model learns from.
  5. 5
    Embedding weights start with random values and are optimized during LLM training.

Key Takeaways

  • Embedding converts data into a vector format, and it can be applied to video, audio, and text.
  • An embedding model is shaped by the data type it was built to read, so a text model should not be used for audio or video.
  • Word embeddings are the most common text embedding, and sentence, paragraph, and document embeddings exist for larger units of text.
  • Text becomes token embedding vectors through three stages: tokenizing, converting tokens to token IDs, and converting token IDs to embedding vectors.
  • Embedding weights start with random values and are optimized during LLM training.

Related concepts

More concepts starting with I