ResearchMethod
Semantic IDs: a catalog a model can read
A model can’t read a product number. Semantic IDs give every merchant and item a short code that carries meaning, so the model can predict an order the way it predicts a word.

The problem with product numbers
A catalog names its items with arbitrary numbers. Two burgers from two restaurants share nothing in their numbers, and a model that sees only those numbers has to learn each one from scratch. With millions of items, most of them rarely ordered, it never sees enough of any one to learn it.
From an item to a code
Profile
Each merchant and each item is described from what is known about it: its text, its picture, its place in the catalog.
Embed
The description is placed in a space where similar things lie close together.
Compress
Its place in that space is written as a short code of a few tokens. The first token names a broad family; each one after it narrows the meaning.
| Code | First token | Second token | Third token |
|---|---|---|---|
| <156><032><089> | Prepared food | Burgers | A smash burger |
| <156><032><013> | Prepared food | Burgers | A classic burger |
| <156><214><041> | Prepared food | Sushi | A salmon set |
Teaching the codes to speak
A code is useful once the model can move between it and language in both directions: given a code, say what it is; given a description, find the code. Pre-training therefore mixes histories with tasks that tie codes to text.
- Predicting the next code in a history.
- An item and its description, each from the other.
- An item and a description of its picture.
- A person’s profile and the history it summarizes.
- An item and its place in the catalog’s categories.
- A merchant and its menu.
General instruction data is mixed in as well, so the model stays fluent outside commerce while it learns the catalog.
What it makes possible
Because codes are tokens, an item, a merchant or a person can stand directly in the model’s context, in the middle of a sentence. An item the model has never seen ordered still has a code whose first tokens it knows, so it can be recommended on its first day. And the same model that writes a notification can name the item the notification is about.
Author
Magnet research