We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Generating Text Embeddings

Let's convert some text into embeddings.

Preprocessing

Unlike keyword search, embedding models handle many preprocessing tasks automatically:

  • Case-insensitive: "PADDINGTON" and "paddington" get similar embeddings.
  • Punctuation-robust: "Ted!" and "Ted" are nearly identical.
  • Context-aware: "bear" in "teddy bear" vs. "grizzly bear" gets different vectors.

Assignment

Add a function to the semantic search module that generates an embedding for a single text input, and verify that it works.

    1. print(f"Text: {text}")
      print(f"First 3 dimensions: {embedding[:3]}")
      print(f"Dimensions: {embedding.shape[0]}")
      

Run and submit the CLI tests.

Each embedding model is trained with a specific tokenizer. You must tokenize text the same way the model was trained, so models come packaged with their tokenizers. In other words, the library does it for you!