Embeddings as a lookup step
Add a pretrained sentence embedding of a text column in Prepare, and see why it's a lookup, not SQL.
You will be able to
- Add 384 meaning-based numbers per text with Add embeddings
- Explain why a frozen encoder needs no per-fold refit, while a learned vocabulary does
- Say what the lookup cache holds and when the app fills it
Read first
Why it isn't SQL
ReadEvery other Prepare step compiles to SQL. A transformer can't run in SQL, so Add embeddings is a lookup step:
- The model runs on this Mac, in the Python or R engine. Your texts aren't sent anywhere.
- Each vector is cached in the project, keyed by the text's fingerprint (its SHA-256).
- The step's SQL joins that cache:
LEFT JOIN … ON key = sha256(text).
Preview and Apply first compute any texts the cache doesn't have yet, so the first run on a big column takes a while and later runs are quick. The step form says "Lookup step: not pure SQL", and exported code reads the same cache (or recomputes it with the helpers).
Images and sounds
ReadAdd media features (the op picker's Media group) is the same kind of step for a folder of images or recordings added in Data. A frozen encoder, such as a small thumbnail, ResNet-50, CLIP or the loudness envelope, turns each file into numbers. The cache key is the file's media_id, the hash of its bytes, plus the encoder, its weights and how files are decoded (size, crop, sample rate). A changed file or a new setting never reuses old numbers, and a file that can't be read stays missing.
Does it leak?
PredictPredict first
You add embeddings to a dataset, then cross-validate a classifier on it. Should the embedding step be refit on each fold's training rows, as a learned vocabulary should?
Reveal
The answer: No, the model learns nothing from your rows
The encoder is frozen: its weights were fixed before it saw your data, and the same text always gets the same vector. Nothing is learned from your rows, so test rows can't leak into it. A text that states the outcome still leaks, but that's true of any feature built from it.
Try it
In the appAdd the customer list and start a recipe with Add embeddings on the notes column.
The step form shows the model's card: download it once (about 91 MB, it asks first). Then preview the step and look at the new columns. Missing notes stay missing.
In code
Readfrom codesplash.text.lookup import add_embeddings
df = add_embeddings(df, "notes", "notes_emb_") # 384 columns, computed on this computerdf <- codesplashr::cs_text_add_embeddings(df, "notes", "notes_emb_")Check your understanding
CheckpointCheck yourself
You apply a recipe with Add embeddings, add 50 new rows to the dataset and apply it again. What does the app compute?
Show the answer
Answer: a
The cache is keyed by each text's fingerprint, so only unseen texts run through the model. Repeated texts share one cached vector.
Check yourself
When is TF-IDF + SVD (Text embeddings) the better choice?
Show the answer
Answer: a
TF-IDF compares shared words and learns from your data (so learn it on training rows). A pretrained sentence embedding compares meaning and learns nothing from your rows.
Recap
Recap- Add embeddings gives 384 meaning-based numbers per text, computed on this Mac.
- It's a lookup step: cached by text fingerprint and joined in SQL.
- A frozen encoder needs no per-fold refit; a learned vocabulary does.
Concepts in this lesson