embeddingsnlpvectorsmachine-learningfoundations

Embeddings & Word Vectors: How AI Turns Words Into Numbers

The hidden math that makes AI understand meaning — where 'king - man + woman = queen' actually works

AI Resources Team··10 min read

Ever wondered how a computer actually understands the difference between "bank" (a place for money) and "bank" (the side of a river)? Or how Netflix somehow knows you'll love a movie you've never heard of? The secret sits in the mathematical space behind the scenes: embeddings.

Think of embeddings as a translation layer. Words are symbols on a screen—"apple," "orange," "banana"—but your brain knows they're all fruits, and they have relationships. An embedding is how AI captures that same intuition, turning words into lists of numbers that preserve meaning and relationships. It's genuinely wild when you see it work.

What Is an Embedding, Actually?

An embedding is a vector—a list of numbers—that represents a word, phrase, or concept in a way that captures its meaning in context. Instead of storing "apple" as just the characters a-p-p-l-e, an embedding might store it as [0.2, -0.5, 0.8, 0.1, ...] with hundreds or thousands of dimensions.

The magic? Words with similar meanings end up with similar vectors. "King" and "queen" have embeddings that are close to each other in this numerical space. "Apple" and "orange" are also close. But "king" and "apple"? Far apart.

Here's the key insight: the distance between vectors encodes semantic similarity. If you measure how similar two embeddings are (using something called cosine similarity), you get a number between -1 and 1. Close to 1 means the words are similar. Close to -1 means they're opposites. Close to 0 means they're unrelated.


The Classic Examples: Word2Vec & GloVe

Word2Vec (2013)

Mikolov's Word2Vec was the breakthrough that made embeddings practical and popular. The model had a simple yet brilliant idea: you don't need labeled data. Just feed it text and let it learn that words appearing in similar contexts have similar meanings.

Word2Vec trained on Google News produced embeddings where something almost magical happened:

king - man + woman ≈ queen
Paris - France + Germany ≈ Berlin
good - bad + worse ≈ terrible

These relationships emerged automatically without anyone telling the model about analogies. The vector space had axes that represented concepts—gender, capital-city-ness, goodness—without explicit supervision. That was the "aha moment" for the field.

But Word2Vec had a limitation: it gave the same embedding to a word every time. "Bank" always had the same vector, whether you were talking about money or rivers. Different contexts? Same answer.

GloVe (2014)

Stanford's Global Vectors for Word Representation took a different approach: combine the local context window method of Word2Vec with global word co-occurrence statistics. Think of it as "Word2Vec but with a photographic memory of the whole corpus."

GloVe embeddings were often more stable and performed well on analogy tasks. Many NLP researchers switched to GloVe for their benchmarks. For a few years, if you wanted solid word embeddings, GloVe was the default choice.


The Context Revolution: Contextual Embeddings

Then BERT showed up in 2018 and everything changed.

The problem with Word2Vec and GloVe: they're static. One embedding per word. But meaning changes wildly with context. "I went to the bank" vs. "The river bank was beautiful." The same word needs different representations.

Contextual embeddings solve this by computing the embedding on the fly, taking the surrounding sentence into account. BERT (Bidirectional Encoder Representations from Transformers) reads the whole context, left and right, and generates an embedding for each word in that specific moment.

The result? BERT embeddings for "bank" in "I went to the bank to deposit money" are actually different from BERT embeddings for "bank" in "The river bank was beautiful." The model understands context.

Modern Contextual Embeddings in 2025

Today you've got:

  • BERT & RoBERTa: The workhorses. Still used everywhere. Free, open-source, mature.
  • GPT embeddings: OpenAI's embedding API turns text into 1536-dimensional vectors. Powers semantic search in thousands of apps.
  • Claude embeddings: Anthropic's embeddings capture meaning in their own way, sometimes better for certain tasks.
  • Sentence-BERT (SBERT): Fine-tuned BERT specifically for comparing whole sentences, not just words. Great for semantic search and clustering.

When you use tools like Pinecone, Weaviate, or Chroma for vector search, they're almost always using embeddings under the hood. You upload documents, they get turned into vectors, and when you search, your query becomes a vector too. The system finds the "closest" vectors. Boom—semantic search.


Why Embeddings Are Everywhere (And Why You Should Care)

Google's search engine has used embeddings for years. When you search for "how to train a dog," it doesn't just match keywords. It understands that "puppy training tips" and "young canine obedience" are related concepts. All through embeddings.

2. Recommendation Systems

Netflix, Spotify, Amazon—they all use embeddings. Movie embeddings capture genre, mood, era, actor style. User embeddings capture their taste profile. Recommendations come from finding users and movies with similar embeddings.

3. RAG (Retrieval-Augmented Generation)

This is huge right now. When Claude answers your question by "retrieving" documents first, here's what happens:

  1. Your question becomes an embedding
  2. All documents in the knowledge base are pre-embedded
  3. The system finds the documents with embeddings closest to your question
  4. Those documents are fed to the LLM for context

Embeddings are the retrieval mechanism. Without them, RAG doesn't work.

4. Duplicate Detection

Got a database of customer complaints? Convert them to embeddings. Find the ones that are similar—even if the wording is completely different. Detect duplicates. Cluster by theme.

5. Clustering & Analysis

Embed your entire dataset (emails, documents, tweets), then use clustering algorithms (k-means, UMAP, t-SNE) to visualize and group similar items. It's a wild way to explore large text collections.


Under the Hood: How Embeddings Are Created

The process varies by method, but here's the general idea:

Static Embeddings (Word2Vec Style)

  1. Initialize random vectors for each word
  2. Train on context: The model predicts surrounding words based on a word's vector (or vice versa)
  3. Update vectors to minimize prediction error
  4. After training, you've got embeddings that capture context patterns

Contextual Embeddings (BERT Style)

  1. Feed the entire sentence into a transformer model
  2. The transformer uses attention to understand relationships between all words
  3. Extract the hidden representations (usually from the last layer)
  4. Each word gets an embedding that incorporates the whole context

The transformer approach is more complex but yields better representations because it has more context to work with.


The Numbers Behind Embeddings

AspectWord2VecGloVeBERTGPT Embeddings
DimensionsTypically 300Typically 300768-10241536
Context-awareNoNoYesYes
Training costLowLowHigh(Proprietary)
Best forQuick experimentsGeneral NLPProduction systemsAPI-based apps
LicenseOpenOpenOpenProprietary

Vector Space Intuitions

Here's a mind-bending way to think about it: embeddings create a landscape where meaning is encoded as position.

Imagine a vast, high-dimensional space (say, 1536 dimensions if you're using GPT embeddings). Words are points in this space:

  • Synonyms cluster together
  • Antonyms are on opposite sides
  • Related concepts are nearby
  • Unrelated concepts are far apart
  • Analogies appear as shifts in the vector space

That "king - man + woman = queen" thing? It's because there's a vector that represents "going from man to woman." When you apply that same direction shift to "king," you land near "queen."


Common Use Cases in 2025

Built into Vercel AI, LangChain, and countless startups. Feed your documents, get smart search without traditional keywords.

AI Chat with Your Data

Uploading a PDF to ChatGPT or Claude and asking questions? That's RAG powered by embeddings.

Email Spam Detection

Gmail uses embeddings to understand the meaning of emails, not just keywords, to catch spam.

Content Recommendation

"Users who read this also read..." is almost always powered by embeddings.

Anomaly Detection

Embed your data and find outliers—points far from the cluster. Useful for fraud detection, network intrusion, etc.


Limitations & Gotchas

Embeddings don't contain truth. They're statistical patterns. A document about the moon landing being fake could have an embedding similar to actual moon-landing documents. Embeddings capture how things are talked about, not whether they're true.

Dimensionality trade-offs. More dimensions = more expressive power but slower comparisons. Fewer dimensions = faster but less nuance.

Language-specific. An embedding trained on English doesn't work well for Mandarin. You need multilingual models if you're working across languages.

Drift over time. As language evolves, embeddings trained on old data become less useful. "Tweet" meant something different in 2015 than it does now.


Quick Tips for Using Embeddings

Choose the right model:

  • Free and local: Use SBERT for sentence embeddings or distilBERT for efficiency
  • Production and accuracy: OpenAI or Anthropic embeddings via API
  • Custom domain: Fine-tune BERT on your specific data

Normalize your vectors. Most vector databases do this automatically, but make sure vectors have the same length before comparison.

Use cosine similarity. It's the standard for comparing embeddings. Many vector databases compute it automatically.

Monitor for drift. If your embeddings are trained on 2023 data and you're using them in 2025, you might need to retrain.


The Future

Embeddings aren't going away. In fact, they're becoming more important:

  • Multimodal embeddings: CLIP, for example, embeds both images and text in the same space. You can search images with text queries.
  • Sparse embeddings: GPT's new sparse embeddings use fewer dimensions but maintain accuracy. Cheaper, faster.
  • Domain-specific embeddings: More companies are fine-tuning embeddings for their specific industry.

The core concept—that meaning can be captured as numerical proximity in a high-dimensional space—is here to stay.


FAQ

Why "embedding" as the name? Because you're embedding words into a numerical space. Like embedding a gem in a setting—it's positioned within a structure.

Can you visualize embeddings? Sort of. Tools like t-SNE and UMAP project high-dimensional embeddings into 2D or 3D so you can see clusters. It's beautiful but note that the visualization distorts the actual distances.

Is training embeddings still important? For most people? No. Use existing embeddings (SBERT, GPT embeddings, etc.). Only fine-tune if you have a very specific domain.

How much storage do embeddings need? One embedding of 1536 dimensions with 32-bit floats is about 6KB. A million documents? About 6GB. Vector databases compress and optimize this.


Ready to dive deeper into how embeddings power modern AI? Next up: Large Language Models (LLMs) — the models that use embeddings and way more to understand and generate human language.


Keep Learning