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.