Trie-Aware Transformers for Generative Recommendation
Authors: Zhenxiang Xu, Jiawei Chen, Sirui Chen, Yong He, Jieyu Yang, Chuan Yuan, Ke Ding, Can Wang
Organizations: State Key Laboratory of Blockchain and Data Security, Zhejiang University. · College of Computer Science and Technology, Zhejiang University. · Zhejiang University Hangzhou, China · Hangzhou High-Tech Zone (Binjiang) Institute of Blockchain and Data Security. · Ant Group Hangzhou, China
Generative recommendation (GR) aligns with advances in generative AI by casting next-item prediction as token-level generation rather than score-based ranking. Most GR methods adopt a two-stage pipeline: (i) item tokenization, which maps each item to a sequence of discrete, hierarchically organized tokens; and (ii) autoregressive generation, which predicts the next item's tokens conditioned on the tokens of user's interaction history. Although hierarchical tokenization induces a prefix tree (trie) over items, standard autoregressive modeling with conventional Transformers often flattens item tokens into a linear stream and overlooks the underlying topology. To address this, we propose TrieRec, a trie-aware generative recommendation method that augments Transformers with structural inductive biases via two positional encodings. First, a trie-aware absolute positional encoding aggregates a token's (node's) local structural context (\eg depth, ancestors, and descendants) into the token representation. Second, a topology-aware relative positional encoding injects pairwise structural relations into self-attention to capture topology-induced semantic relatedness. TrieRec is also model-agnostic, efficient, and hyperparameter-free. In our experiments, we implement TrieRec within three representative GR backbones, achieving notably improvements of 8.83% on average across four real-world datasets.
Figures & tables
Figure 1. Generative recommendation pipeline. Item tokenization maps items to semantic token sequences via hierarchical quantization, forming a trie structure. Autoregressive generation employs a Transformer to predict the next item’s token sequence conditioned on user interaction history.
Figure 2. The illustration of our proposed trie-aware absolute positional encoding and topology-aware relative positional encoding in TrieRec.
Dataset
#Users
#Items
#Interactions
Amazon Beauty
22,332
12,086
198,215
Amazon Toys
19,124
11,758
165,247
Amazon Food
14,631
8,686
150,809
MovieLens-1M
6,040
3,416
999,611
Table 1. Statistics of the datasets.
Model
Amazon Beauty
Amazon Toys
Amazon Food
MovieLens-1M
N@5
N@10
R@5
R@10
N@5
N@10
R@5
R@10
N@5
N@10
R@5
R@10
N@5
N@10
R@5
R@10
Caser
0.0116
0.0137
0.0163
0.0227
0.0112
0.0135
0.0161
0.0234
0.0121
0.0171
0.0189
0.0343
0.0134
0.0217
0.0217
0.0482
GRU4Rec
0.0055
0.0079
0.0088
0.0163
0.0045
0.0066
0.0066
0.0131
0.0111
0.0154
0.0178
0.0312
0.0128
0.0199
0.0202
0.0417
SASRec
0.0177
0.0263
0.0346
0.0612
0.0229
0.0320
0.0458
0.0739
0.0210
0.0309
0.0411
0.0716
0.0440
0.0641
0.0765
0.1391
BERT4Rec
0.0196
0.0269
0.0317
0.0545
0.0207
0.0265
0.0326
0.0507
0.0245
0.0334
0.0399
0.0678
0.0420
0.0597
0.0679
0.1232
HSTU
0.0176
0.0264
0.0347
0.0622
0.0238
0.0328
0.0476
0.0754
0.0231
0.0310
0.0416
0.0662
0.0511
0.0719
0.0902
0.1553
Table 2. Overall performance comparison. The best results are bolded . Improv. indicates the relative gain of TrieRec over the vanilla backbone. Note that N and R denote NDCG and Recall, respectively.
Variant
Amazon Beauty
Amazon Toy
Amazon Food
MovieLens-1M
N@5
N@10
R@5
R@10
N@5
N@10
R@5
R@10
N@5
N@10
R@5
R@10
N@5
N@10
R@5
R@10
TrieRec
0.0385
0.0464
0.0548
0.0794
0.0403
0.0477
0.0569
0.0801
0.0373
0.0469
0.0561
0.0861
0.0914
0.1129
0.1363
0.2031
(1) w/o TAE
0.0360
0.0442
0.0528
0.0781
0.0383
0.0464
0.0562
0.0800
0.0361
0.0461
0.0539
0.0847
0.0740
0.0946
0.1138
0.1779
(2) w/o TRE
0.0363
0.0444
0.0527
0.0779
0.0381
0.0459
0.0549
0.0791
0.0348
0.0438
0.0524
0.0803
0.0847
0.1061
0.1287
0.1951
(3) TAE-Blocked
0.0362
0.0450
0.0531
0.0790
0.0375
0.0454
0.0559
0.0799
0.0346
0.0441
0.0531
0.0826
0.0762
0.0971
0.1166
0.1816
(4) TAE-Prefix
0.0343
0.0425
0.0513
0.0766
0.0339
0.0418
0.0515
0.0760
0.0351
0.0444
0.0534
0.0824
0.0734
0.0956
0.1127
0.1814
Table 3. Ablation study on four datasets (Backbone: LETTER).
Dataset
Model
N@5
N@10
R@5
R@10
Beauty
SEATER
0.0334
0.0413
0.0508
0.0572
TrieRec
0.0385
0.0464
0.0548
0.0794
Toy
SEATER
0.0351
0.0432
0.0523
0.0778
TrieRec
0.0403
0.0477
0.0569
0.0801
Food
SEATER
0.0342
0.0440
0.0516
0.0822
TrieRec
0.0373
0.0469
0.0561
0.0861
Table 4. Performance comparison between TrieRec and SEATER (Backbone: LETTER).
Figure 3. Efficiency comparison between TrieRec and baseline LETTER on Beauty and Toy datasets. The left panel shows the total training time, and the right panel shows the inference latency.
In web environments, user preferences are often refined progressively as users move from browsing broad categories to exploring specific items. However, existing generative recommenders overlook this natural refinement process. Generative recommendation formulates next-item prediction as autoregressive generation over tokenized user histories, where each item is represented as a sequence of discrete tokens. Prior models typically fuse heterogeneous attributes such as ID, category, title, and description into a single embedding before quantization, which flattens the inherent semantic hierarchy of items and fails to capture the gradual evolution of user intent during web interactions. To address this limitation, we propose CoFiRec, a novel generative recommendation framework that explicitly incorporates the Coarse-to-Fine nature of item semantics into the tokenization process. Instead of compressing all attributes into a single latent space, CoFiRec decomposes item information into multiple semantic levels, ranging from high-level categories to detailed descriptions and collaborative filtering signals. Based on this design, we introduce the CoFiRec Tokenizer, which tokenizes each level independently while preserving structural order. During autoregressive decoding, the language model is instructed to generate item tokens from coarse to fine, progressively modeling user intent from general interests to specific item-level interests. Experiments across multiple public benchmarks and backbones demonstrate that CoFiRec outperforms existing methods, offering a new perspective for generative recommendation. Theoretically, we prove that structured tokenization leads to lower dissimilarity between generated and ground truth items, supporting its effectiveness in generative recommendation. Our code is available at https://github.com/YennNing/CoFiRec.
Tianxin Wei, Xuying Ning, Xuxing Chen +6
University of Illinois Urbana-Champaign · Meta · University of California San Diego
Generative Retrieval (GR) offers a promising paradigm for recommendation through next-token prediction (NTP). However, scaling it to large-scale industrial systems introduces three challenges: (i) within a single request, the identical model inputs may produce inconsistent outputs due to the pagination request mechanism; (ii) the prohibitive cost of encoding long user behavior sequences with multi-token item representations based on semantic IDs, and (iii) aligning the generative policy with nuanced user preference signals. We present GenRec, a preference-oriented generative framework deployed on the JD App that addresses above challenges within a single decoder-only architecture. For training objective, we propose Page-wise NTP task, which supervises over an entire interaction page rather than each interacted item individually, providing denser gradient signal and resolving the one-to-many ambiguity of point-wise training. On the prefilling side, an asymmetric linear Token Merger compresses multi-token Semantic IDs in the prompt while preserving full-resolution decoding, reducing input length by ~2X with negligible accuracy loss. To further align outputs with user satisfaction, we introduce GRPO-SR, a reinforcement learning method that pairs Group Relative Policy Optimization with NLL regularization for training stability, and employs Hybrid Rewards combining a dense reward model with a relevance gate to mitigate reward hacking. In month-long online A/B tests serving production traffic, GenRec achieves 9.5% improvement in click count and 8.7% in transaction count over the existing pipeline.
Yanyan Zou, Junbo Qi, Lunsong Huang +7
JD.com Beijing, China · Waseda University Tokyo, Japan
Generative recommendation (GR) has emerged as a promising paradigm that predicts target items by autoregressively generating their semantic identifiers (SID). Most GR methods follow a quantization-representation-generation pipeline, first assigning each item a SID, then constructing input representations from SID-token embeddings, and finally predicting the target SID through autoregressive generation. Existing item-level representation constructions mainly take two forms: directly merging SID-token embeddings into a compact vector, or enriching item-level representations with external inputs through additional networks. However, these item-level constructors still expose two practical challenges: direct merging may amplify the information loss caused by quantization and ID collision while obscuring SID code relations, whereas external-input-based methods can strengthen item semantics but cannot reliably preserve the SID-structured evidence required for token-level generation. These limitations make representation construction an underexplored bottleneck, leading to two severe problems, \ie{} the Identity-Structure Preservation Conflict and Input-Output Granularity Mismatch. To this end, we propose ComeIR, a Conditional Memory enhanced Item Representation framework that reconstructs SID-token embeddings into item-aware inputs and restores the token granularity during SID decoding. Specifically, MM-guided token scoring adaptively estimates the contribution of each code within the SID, dual-level Engram memory captures intra-item code composition and inter-item transition patterns, and a memory-restoring prediction head reuses the memories during SID decoding. Extensive experiments demonstrate the effectiveness and flexibility of ComeIR, and further reveal scalable gains from enlarging conditional memory.
Ziwei Liu, Yejing Wang, Shengyu Zhou +2
City University of Hong Kong Hong Kong, China · Independent Researcher Beijing, China · Tsinghua University Beijing, China