Vector embeddings inside the LLM transformer

Vikas KumarVikas Kumar
4 min read

When we talk about large language models (LLMs) like ChatGPT, people often think of them as machines that just “know everything.” But the real secret of how they work comes down to something called vector embeddings📈. If you’ve never heard of this term, don’t worry. Let’s break it down step by step, using simple ideas and examples.

Remember - Words are numbers, not magic🪄

When we speak, we use words like cat, milk, or thirsty. A computer doesn’t understand words the way we do. It only understands numbers. So the first step is turning words into numbers.🔢

Think of it like this: imagine you want to explain the word cat to a robot. You can’t say “meow animal” because the robot doesn’t know what that means. Instead, you give the robot a list of numbers that represent the word.

For example:

  • cat → [0.2, 0.9, 0.1]

  • dog → [0.3, 0.8, 0.15]

Notice something? These numbers are not random. They are placed in such a way that similar words get similar numbers.

Vector embeddings are like a map🗺️

Think of embeddings like a giant map. Each word is a dot on this map. Words with similar meanings are placed close to each other

Example:

  • “King” is close to “Queen.”

  • “Paris” is close to “France.”

  • But “King” is far away from “Banana.”

This is why embeddings are powerful. They don’t just store words; they store meaning.

Why is this useful inside transformers?

Transformers (the engine behind LLMs) need to compare words, find patterns, and understand context. Embeddings make this possible. Without embeddings, the model would just see random IDs for words. With embeddings, it sees meaning.

For example, take the sentence:
“The cat drank milk because it was thirsty.”

Here, the word “it” needs to connect back to “cat.” The embeddings help the transformer figure out that “it” relates more to “cat” than to “milk,” because the meaning of “cat” is closer to “it” in the embedding space.

Embeddings are like fingerprints of words

You can think of an embedding as a fingerprint. Just like every human has a unique fingerprint, every word has a unique embedding. But here’s the cool part: words that mean similar things have similar fingerprints.

Example:

  • “Happy” and “Joyful” will have almost matching fingerprints.

  • “Happy” and “Car” will look totally different.

This similarity is what lets the model understand when two words are related.

Embeddings are not just for words

Embeddings aren’t only used for words. They can represent sentences, paragraphs, or even whole documents.

Think of it like this:

  • Word embedding: “cat” → fingerprint of one word.

  • Sentence embedding: “The cat drank milk” → fingerprint of the whole sentence.

This helps the model understand not just single words, but ideas and meanings across longer text.

Connecting dots: How embeddings power the LLM

When you ask a question to an LLM, here’s roughly what happens:

  1. Your words are converted into embeddings.

  2. These embeddings are passed into the transformer.

  3. The transformer looks at patterns, context, and relationships using attention.

  4. It predicts the most likely next word, also using embeddings.

So, embeddings are the foundation. Without them, the transformer can’t even begin to “understand” or “predict.”

Example:
If you type: “What is the capital of France?”

  • The embeddings make “France” close to “Paris.”

  • The transformer uses this closeness to predict “Paris” as the next word.

Why you should care

Even if you’re not technical, knowing about embeddings helps you appreciate how LLMs are different from old rule-based systems. They don’t memorize sentences word for word. Instead, they use this hidden map of meanings to reason and generate new answers.

Think of it like teaching a child:

  • You don’t just tell them “this is a cat.”

  • You show them patterns: a cat is small, furry, says meow.

  • Next time they see a different cat, they can still recognize it.

That’s exactly what embeddings allow LLMs to do: generalize and connect ideas.

Final dot

Embeddings are the hidden magic that turn raw words into meaning. They are the invisible bridge between human language and machine understanding. Without them, an LLM is just an empty shell. With them, it becomes a tool that can connect words, ideas, and knowledge in ways that feel natural to us.

0
Subscribe to my newsletter

Read articles from Vikas Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vikas Kumar
Vikas Kumar

As a Frontend Web Developer, I bring a unique blend of technical expertise and creative vision to design and implement robust web applications. My proficiency in core web technologies including HTML, CSS, and JavaScript, combined with hands-on experience in React and NodeJs, allows me to deliver high-performance, responsive, and intuitive user interfaces. I am also dedicated to continuous learning and community engagement, regularly publishing technical blogs to share insights and foster collaborative growth.