Search

Search papers and lessons

Recommender Systems with Generative Retrieval

Shashank Rajput, Nikhil Mehta, Anima Singh et al. · 2023

TIGER recommends an item by generating its short learned code, token by token, so one Transformer both stores the catalogue and predicts what the user will pick next.

On this page

  • Colour = topic mix
  • Linear algebra
  • Neural network basics
  • Calculus
  • Discrete math
  • Probability
  • Architectures
  • ReadReady to readNot yet

TL;DR

TIGER (Transformer Index for GEnerative Recommenders) recommends by generating. Each item gets a Semantic ID, a short tuple of codes built from the item's text, so that similar items share their leading codes. A Transformer encoder-decoder reads a user's history as a sequence of these codes and writes out the code of the next item, one token at a time. No separate search index is built. On three Amazon review datasets the authors report gains over the strongest sequential recommenders of the time, and the same codes let the model suggest items that have almost no interaction history and let the operator tune how varied the suggestions are.

Builds on: Sequential Recommendation, Residual Vector Quantization, Transformer · Leads to: HSTU, a later generative recommender

Why it mattered

Most large recommenders still use retrieve-and-rank. A retrieval model maps users and items into one vector space, and an approximate nearest neighbor index returns the items closest to the user's vector. The paper asks whether the index can be dropped. TIGER stores the catalogue inside the model's parameters: the decoder's output vocabulary is the set of codes, and beam search over those codes returns candidate items.

The paper's framing is that this opens "a new area of research," titled Recommender Systems based on Generative Retrieval. The authors say it is the first Semantic ID-based generative model for recommendation. A concurrent paper from the same group, by Singh et al., used hierarchical Semantic IDs to replace item IDs in a ranking model, so the idea was being tried in more than one part of the pipeline.

The stakes are set by catalogue size. The authors note that the item corpus "can be in the order of billions" for real products. The experiments here use three Amazon review datasets, far smaller than that. The method's claims about memory and cold start matter most at the larger scale.

The problem

Sequential recommendation asks: given a user's items in time order, (item1,…,itemn)(\text{item}_1, \dots, \text{item}_n), which item comes next? The standard answer, covered in Sequential Recommendation, uses a self-attention network such as SASRec to produce one user vector and scores items by its dot product with an item embedding. That approach has three costs the paper targets.

  1. Every item has its own row in an embedding table. The table has one row per item, so its size grows with the catalogue. A new item has no row until it has interactions, so it is hard to recommend.
  2. Random IDs carry no meaning. Two near-identical products have unrelated IDs, so the model learns about each item separately. Items with few interactions are the worst served.
  3. Retrieval runs as a separate step. The index is built from item embeddings and searched with a second algorithm, so the model is not trained to output the item it recommends.

Generative retrieval, which earlier work applied to documents, removes the separate step: the model writes the identifier of the target itself. For documents, the identifier can be a title or a string. For recommendation, the authors need an identifier that is short, that is built from content, and that has enough capacity for every item. TIGER's answer is the Semantic ID.

How it works

The paper has two stages. Stage one turns each item into a Semantic ID. Stage two trains a generative recommender on sequences of those IDs.

flowchart LR
  A["Item text: title, brand, price, category"] --> B["Sentence-T5 embedding, 768 numbers"]
  B --> C["RQ-VAE encoder, 32 numbers"]
  C --> D["Three residual quantization levels"]
  D --> E["Semantic ID: three codes plus a collision code"]
  E --> F["Transformer encoder-decoder over the user history"]
  F --> G["Beam search decodes the next Semantic ID"]
  G --> H["Look up the item; drop IDs that match no item"]

To keep the arithmetic readable, the walkthrough uses one number per vector and codebooks of three entries. The paper uses 768 numbers per item, a 32-number latent, and codebooks of 256 entries at each of three levels.

  1. Start with a content embedding. A pretrained text encoder, Sentence-T5 in the paper, turns the item's text into a vector. Pretend the item's encoder output is the single number z=6.7z = 6.7.
  2. Quantize level 1. The first codebook is {0,5,10}\{0, 5, 10\}. The nearest entry to 6.76.7 is 55, which is code 1. The residual, the part not yet explained, is 6.7−5=1.76.7 - 5 = 1.7.
  3. Quantize level 2 on the residual. The second codebook is {−2,0,2}\{-2, 0, 2\}. The nearest entry to 1.71.7 is 22, code 2. The new residual is 1.7−2=−0.31.7 - 2 = -0.3.
  4. Quantize level 3. The third codebook is {−0.5,0,0.5}\{-0.5, 0, 0.5\}. The nearest entry to −0.3-0.3 is −0.5-0.5, code 0, since ∣−0.3−(−0.5)∣=0.2|-0.3 - (-0.5)| = 0.2 is less than ∣−0.3−0∣=0.3|-0.3 - 0| = 0.3. The residual is −0.3−(−0.5)=0.2-0.3 - (-0.5) = 0.2.
  5. Check the reconstruction. The Semantic ID is (1,2,0)(1, 2, 0). The decoded value is 5+2−0.5=6.55 + 2 - 0.5 = 6.5, and the error 6.7−6.5=0.26.7 - 6.5 = 0.2 equals the last residual. Each level only has to explain what the earlier levels missed.
  6. Resolve collisions. Two items can land on the same three codes. If a second item also gets (1,2,0)(1, 2, 0), the lookup table appends a fourth code to tell them apart: one gets (1,2,0,0)(1, 2, 0, 0) and the other (1,2,0,1)(1, 2, 0, 1). The paper uses 0 as the fourth code when there is no collision, so every item has a four-code ID.
  7. Turn a history into tokens. Suppose a user first chose item A with ID (1,2,0,0)(1, 2, 0, 0), then item B with ID (3,0,2,1)(3, 0, 2, 1). The model reads the flat sequence 1,2,0,0,3,0,2,11, 2, 0, 0, 3, 0, 2, 1, with a user token in front. The training target is the next item's ID, here C with (1,2,0,1)(1, 2, 0, 1). The model learns to produce 11, then 22, then 00, then 11, one token at a time, each conditioned on what it has already written.
  8. Decode at inference time. Beam search keeps the several most probable partial codes at each position. A finished code that matches an item becomes a recommendation. A code that matches no item is dropped, which is why the paper reports invalid IDs separately.

The math

Stage 1: residual quantization of the content embedding

Let x∈RD\mathbf{x} \in \mathbb{R}^{D} be an item's content embedding, with D=768D = 768 in the paper. An encoder E\mathcal{E} maps it to a latent vector z=E(x)\mathbf{z} = \mathcal{E}(\mathbf{x}), and the residual starts as r0=z\mathbf{r}_0 = \mathbf{z}.

At each level ℓ=0,…,m−1\ell = 0, \dots, m-1 there is a codebook Cℓ={ek(ℓ)}k=1K\mathcal{C}_\ell = \{\mathbf{e}^{(\ell)}_k\}_{k=1}^{K} of K=256K = 256 vectors, where m=3m = 3 is the number of levels. Level ℓ\ell chooses the nearest codeword to the current residual and passes the leftover to the next level.

cℓ=arg⁡min⁡k∥rℓ−ek(ℓ)∥,rℓ+1=rℓ−ecℓ(ℓ)c_\ell = \arg\min_{k} \left\| \mathbf{r}_\ell - \mathbf{e}^{(\ell)}_k \right\|, \qquad \mathbf{r}_{\ell+1} = \mathbf{r}_\ell - \mathbf{e}^{(\ell)}_{c_\ell}

This is the step from the walkthrough, written out. The Semantic ID is the tuple of indices (c0,…,cm−1)(c_0, \dots, c_{m-1}), one per level, and the collision code is appended after it. The quantized vector is the sum of the chosen codewords,

z^=∑ℓ=0m−1ecℓ(ℓ),\widehat{\mathbf{z}} = \sum_{\ell=0}^{m-1} \mathbf{e}^{(\ell)}_{c_\ell},

which the decoder maps back to a reconstruction x^\widehat{\mathbf{x}}. The paper uses a separate codebook for each level, not one codebook of size mKmK, because the norm of the residuals tends to fall at higher levels, so each level needs its own scale.

Training uses two terms. The first is the reconstruction error, Lrecon=∥x−x^∥2\mathcal{L}_{\text{recon}} = \|\mathbf{x} - \widehat{\mathbf{x}}\|^2. The second ties the encoder to the codebook:

Lrqvae=∑ℓ=0m−1(∥sg[rℓ]−ecℓ(ℓ)∥2+β∥rℓ−sg[ecℓ(ℓ)]∥2),β=0.25.\mathcal{L}_{\text{rqvae}} = \sum_{\ell=0}^{m-1} \left( \left\| \text{sg}[\mathbf{r}_\ell] - \mathbf{e}^{(\ell)}_{c_\ell} \right\|^2 + \beta \left\| \mathbf{r}_\ell - \text{sg}[\mathbf{e}^{(\ell)}_{c_\ell}] \right\|^2 \right), \qquad \beta = 0.25.

Here sg[⋅]\text{sg}[\cdot] is the Stop-Gradient operator: its argument is used in the value but gets no gradient. The first part moves the codewords toward the residuals, and the second, weighted by β\beta, keeps the encoder from drifting far from its codewords. The total loss is L(x)=Lrecon+Lrqvae\mathcal{L}(\mathbf{x}) = \mathcal{L}_{\text{recon}} + \mathcal{L}_{\text{rqvae}}. The paper initializes each codebook with K-Means Clustering on the first batch, which prevents most inputs from collapsing onto a few codewords.

Stage 2: next-item prediction over Semantic ID tokens

Each item's full Semantic ID has T=4T = 4 tokens: the three quantizer codes and the collision code. Let the user's history be (item1,…,itemn)(\text{item}_1, \dots, \text{item}_n), each item with its ID (ci,0,…,ci,T−1)(c_{i,0}, \dots, c_{i,T-1}). The history is flattened into one token sequence, (c1,0,…,c1,T−1,…,cn,0,…,cn,T−1)(c_{1,0}, \dots, c_{1,T-1}, \dots, c_{n,0}, \dots, c_{n,T-1}), and the target is the ID of the next item. Writing the target as y=(y0,…,yT−1)\mathbf{y} = (y_0, \dots, y_{T-1}), the model's probability of the target is a product of token probabilities:

p(y∣history)=∏j=0T−1p(yj∣history,y0,…,yj−1).p(\mathbf{y} \mid \text{history}) = \prod_{j=0}^{T-1} p\left(y_j \mid \text{history}, y_0, \dots, y_{j-1}\right).

Training maximizes the log of this probability, which is the same as minimizing the sum of per-token Cross-Entropy Loss terms. Each token is predicted from the history and from the tokens already written for the same item, so the model learns the coarse-to-fine order of the code. Decoding keeps several partial codes at once with Beam Search.

Size and memory

Three levels of 256 codewords already give 2563=16,777,216256^3 = 16{,}777{,}216 distinct triples, far more than the items in any of the three datasets. Four positions give 2564=4,294,967,296256^4 = 4{,}294{,}967{,}296 IDs, about 4.3 billion, so most of the code space is unused; the paper reports that the model almost always lands on a valid one.

The embedding table of a conventional recommender has one row of length dd per item, so its size is NdNd. TIGER has one row per code value, 4×256=10244 \times 256 = 1024 rows, so its table costs 1024 d1024\,d regardless of NN. The two lookup tables that link items and codes together cost on the order of 64N64N bits: each item needs 32 bits for its four-code Semantic ID and 32 bits for its integer item ID.

Results

On the Amazon Beauty dataset, the paper reports up to 29% higher NDCG@5 than SASRec and 17.3% higher Recall@5 than S3-Rec. On Toys and Games, it reports 21% and 15% higher NDCG@5 and NDCG@10 than the second-best method. These are relative gains, not differences in absolute score. Recall@K asks whether the true next item is among the top K results. NDCG@K also rewards placing it near the top.

The ablations support the design choices.

  • Quantizer. Semantic IDs from RQ-VAE beat IDs from locality-sensitive hashing (the paper uses LSH with eight hyperplanes and four codewords) and beat random IDs. The paper says the gap holds consistently; the comparison table holds the exact figures.
  • Depth. Recall@5 rises slightly as the encoder and decoder grow from three to five layers. In the paper's table the Beauty rows are 0.04499 Recall@5 for three layers, 0.0454 for four, and 0.04633 for five, so the gains are small. NDCG@5 rises from three to four layers and then does not improve at five (0.03062, 0.0321, 0.03206). The authors used four layers.
  • Variance. The main tables give single-run numbers. Across three random seeds the paper reports Beauty Recall@5 of 0.0441 with a standard error of 0.00069, slightly below the single-run 0.0454. The authors describe the spread as small compared with the gap to the baselines.
  • Scalability. Building Semantic IDs on all three datasets together, then training on Beauty, lowers Beauty Recall@5 from 0.0454 to 0.04355 and Recall@10 from 0.0648 to 0.06314. The paper calls this a small decrease.

Two capabilities follow from the design, and the paper tests both.

  • Cold start. The authors hold out 5% of test items from training. Because each unseen item shares the first three codes with related items, a predicted code can retrieve it. The paper caps the share of unseen items in the output with a parameter ϵ\epsilon; with ϵ=0.1\epsilon = 0.1 the method beats a nearest-neighbour baseline on the semantic embedding space at every Recall@K.
  • Diversity. Sampling the first code gives items from coarse categories, and sampling a later code varies items within one category. Raising the decoding temperature increases the entropy of the categories in the top-K list.

The main limits are these. The model can produce invalid IDs: for the top 10 predictions the paper reports 0.1% to 1.6% invalid, and for the top 20, about 0.3% to 6%. Inference is more expensive than an index lookup because beam search runs a decoder for every position. The P5 numbers use a preprocessing the authors changed for consistency with the other baselines, so that comparison rests on their choice. Everything is on three product-review datasets, not a live system.

Reading guide

Read the paper in this order, with the lessons that cover each section.

Check yourself

QuestionWhat is a Semantic ID, and why is it made of several codes rather than one?Show answer
A Semantic ID is a tuple of codewords, one drawn from each level of a residual quantizer, applied to an item's content embedding. Several levels let the codes go from coarse to fine: the first code picks a broad region of the embedding space, and later codes refine it. Similar items therefore share leading codes. The product of the codebook sizes also gives far more distinct IDs than one codebook of the same total size would.
QuestionWith codebooks {0, 5, 10} and {-2, 0, 2}, what are the first two codes for z = 8.2, and what residual is left after level 2?Show answer
Level 1: the nearest entry to 8.2 is 10, since ∣8.2−10∣=1.8|8.2 - 10| = 1.8 is less than ∣8.2−5∣=3.2|8.2 - 5| = 3.2, so the code is 2 and the residual is 8.2−10=−1.88.2 - 10 = -1.8. Level 2: the nearest entry to −1.8-1.8 is −2-2, since ∣−1.8−(−2)∣=0.2|-1.8 - (-2)| = 0.2 is less than ∣−1.8−0∣=1.8|-1.8 - 0| = 1.8, so the code is 0. The residual is −1.8−(−2)=0.2-1.8 - (-2) = 0.2. The first two codes are (2, 0), and the residual left after level 2 is 0.2.
QuestionWhy does TIGER not need a separate approximate nearest neighbor index, and what does it pay for that?Show answer
The model's output is the item's code, so the decoder performs retrieval itself, using its own parameters as the index. The cost is inference time: beam search runs the decoder once per code position, which is more expensive than a single nearest-neighbour lookup. The paper also notes that the decoder can output IDs that match no item, so the system must filter them.
QuestionA new product is added with no interaction history. Why can TIGER recommend it when an ID-based sequential model cannot?Show answer
The new item gets a code from its text, so it shares leading codes with related items that users already chose. The model can predict those shared codes, and the new item is among the retrieved candidates. An ID-based model has no learned row for the new item, so it has nothing to score it with. The paper caps the share of unseen items in the output with the parameter epsilon.

Sources

Read the full paper

Shashank Rajput, Nikhil Mehta, Anima Singh et al., 2023. arXiv:2305.05065