Embedding
Chunks of text are still just text, computers can't directly measure how "similar" two pieces of text are unless that meaning is turned into numbers. This lesson converts each chunk into an embedding: a vector of numbers that captures its meaning.
The real-world version
In production, you'd call an embedding model, most commonly a hosted API like OpenAI's:
from openai import OpenAI
client = OpenAI()
def embed(text):
response = client.embeddings.create(model='text-embedding-3-small', input=text)
return response.data[0].embedding # a list of ~1536 floats
This needs a real OpenAI API key and network access, so it's read-only here, every other block in this lesson runs directly in your browser. A real embedding model has learned, from enormous amounts of text, that phrases like "AI is powerful" and "machine intelligence is strong" should produce nearly identical vectors, even though they don't share a single word, that's what "captures semantic meaning" means in practice.
A toy embedding you can actually run here
Without a paid API, this course uses a much simpler stand-in: a bag-of-words vector, just a count of how often each word appears. It only catches exact word overlap, not true meaning, but it demonstrates the mechanism, text in, vector out, that every later lesson builds on:
Counter is a dictionary subclass from Python's standard library that counts items, here it counts how many times each lowercase word appears. Two chunks that share more of the same words will end up with more overlapping keys, which the next lessons use to measure similarity.
NOTE
A Counter mapping words to counts is a vector, mathematically, just a sparse one where most possible words have a count of zero and aren't stored at all. Real embedding vectors are dense (every one of their ~1536 numbers is meaningful) and capture meaning rather than exact wording, but the underlying idea, "text becomes a list of numbers you can compare", is exactly the same.