VarLenRec: Adaptive Tokenization for Recommendations
- The paper presents a framework that allocates variable-length IDs to items, addressing the inefficiencies of fixed-length tokenization in recommendation systems.
- It combines PIBA to weight encoding by popularity, HRQ to utilize hyperbolic geometry for residual quantization, and SLC for differentiable, content-adaptive length prediction.
- Experiments demonstrate improved performance, reduced collisions, and faster inference compared to fixed-length methods, especially for diverse head–tail item distributions.
Searching arXiv for the VarLenRec paper and closely related generative recommendation/tokenization work to ground the article. VarLenRec is a framework for learning variable-length tokenization for generative recommendation. It is motivated by a basic design choice in generative recommendation: existing methods employ fixed-length tokenization for all items, implicitly assuming uniform encoding capacity regardless of item characteristics. The framework combines Popularity-Weighted Information Budget Allocation (PIBA), Hyperbolic Residual Quantization (HRQ), and a Soft Length Controller (SLC), and is integrated with a Transformer-based generative recommender through collision-safe decoding and length-bias correction (Wang et al., 18 May 2026).
1. Problem setting and motivating paradox
Generative recommendation reformulates recommendation as autoregressive next-token prediction over discrete item semantic identifiers (IDs). Each item is mapped to a sequence of discrete tokens drawn from learned codebooks, and the model predicts the next item by generating its ID given the user’s past ID sequence. In prior quantization-based tokenizers, including RQ-VAE variants, the number of layers is fixed for all items, so every item receives the same encoding capacity (Wang et al., 18 May 2026).
VarLenRec is built around the observation that this assumption is suboptimal for long-tail catalogs. Popular items accumulate abundant collaborative signals and need little semantic detail, while tail items require richer content semantics to compensate for sparse interactions. The paper terms the resulting empirical pattern the Popularity-Length Paradox. When recommendation performance is evaluated by partitioning target items into Head (top 20%), Body (middle 60%), and Tail (bottom 20%) popularity groups and sweeping fixed ID lengths , performance for head items decreases as grows, while performance for tail items increases with . The overall optimal fixed is a compromise that underperforms for every individual popularity group. This pattern is reported across Beauty, Sports, Toys, and Yelp (Wang et al., 18 May 2026).
A concise view of the framework is as follows.
| Component | Core mechanism | Function |
|---|---|---|
| PIBA | popularity-weighted information allocation | induces a prior over ID lengths |
| HRQ | hyperbolic residual quantization | affords nonuniform capacity across code lengths |
| SLC | differentiable length prediction | trains variable-length IDs end-to-end |
This decomposition reflects the paper’s central claim: adaptive encoding capacity is necessary because the information required to discriminate items is not uniform across the catalog. This suggests that fixed-length semantic IDs are not merely inefficient; they are structurally misaligned with the head–tail asymmetry in collaborative and content signals.
2. Popularity-Weighted Information Budget Allocation
PIBA formalizes how much information each item’s ID should carry as a function of its popularity, under a global budget constraint (Wang et al., 18 May 2026). Each item has normalized popularity , with . The framework assumes that collaborative information grows submodularly with popularity,
0
with 1 and 2.
Semantic information is modeled through residual quantization. The 3-th layer contributes diminishing returns of approximately 4 bits, with 5 for codebook size 6. The total semantic information is
7
If 8 denotes the minimum information required to make an item discriminable, then the semantic ID must fill the gap
9
Under a total length budget 0,
1
a practical PIBA formulation maximizes total semantic information minus a linear length penalty while respecting both feasibility and budget constraints:
2
For items that bind the constraint 3, the minimum feasible 4 is optimal. The resulting KKT solution is
5
For 6, this becomes the closed-form power law
7
with
8
The paper presents this as the principal theoretical result of PIBA: optimal ID length should scale as a negative power of popularity. Intuitively, the exponent 9 emerges from balancing collaborative information, which is logarithmic in popularity, against semantic capacity, which is logarithmic in length.
PIBA also provides a prior over lengths. Popularity is measured from interaction counts 0 with smoothing,
1
where 2 prevents zero-popularity instability. In practice, the paper reports that rank-based quantile mapping improves robustness:
3
where 4 is the descending popularity rank and 5. This discrete prior is then used as supervision for SLC.
3. Hyperbolic Residual Quantization
Directly implementing variable-length allocation introduces a geometric difficulty: standard Euclidean residual quantization lacks geometric capacity to support diverse code lengths without distortion. In Euclidean space, ball volume grows polynomially, 6, whereas hierarchical item semantics exhibit exponential branch growth. As a result, longer residual stacks in Euclidean space must pack exponentially many fine-grained distinctions into polynomial capacity, leading to higher distortion and collisions for tail items (Wang et al., 18 May 2026).
HRQ addresses this by using hyperbolic geometry, specifically the Poincaré ball. For curvature 7 with 8, the 9-dimensional ball is
0
The framework uses hyperbolic distance, Möbius addition, and the exponential and logarithmic maps at the origin:
1
2
3
The geometric motivation is the exponential volume growth of hyperbolic space:
4
This provides natural stratification across radii: short codes are placed near the origin and correspond to coarse semantics, while long codes can expand toward the boundary and represent fine semantics.
The HRQ pipeline uses 5 residual layers. An encoder maps content features 6 to Euclidean 7 via 8, then projects them to the manifold:
9
At layer 0, the nearest code in codebook 1 is selected using hyperbolic distance,
2
and the residual is updated via Möbius subtraction,
3
The paper’s theoretical and empirical comparison is explicit. Hyperbolic embeddings preserve tree-like semantics with 4 distortion, while Euclidean embeddings suffer 5 distortion. Empirically, replacing hyperbolic HRQ with Euclidean RQ decreases Recall@10 by about 6–7 on Beauty and Toys; collision rates increase. HRQ reduces collisions, for example from 8 to 9 on average, improves tail discrimination, and works synergistically with variable-length allocation (Wang et al., 18 May 2026).
In computational terms, tokenization per item is 0, because each of 1 layers performs nearest-code selection over 2 codes in 3 dimensions. Hyperbolic distance adds constant overhead via 4 and 5, and approximate nearest neighbor search is optional.
4. Soft Length Controller and optimization objective
SLC makes length prediction differentiable through continuous layer retention probabilities and regularizes them with PIBA-derived priors (Wang et al., 18 May 2026). For each layer 6,
7
Prefix constraints are enforced by cumulative masks
8
so 9 loosely represents the probability that layer 0 is kept given all prior gates are open.
The gate is content-adaptive. At layer 1, the current residual and selected code are projected to tangent space and passed to a small 2 with sigmoid:
3
The gate closes early when residual semantics are already captured, and stays open for complex items.
PIBA supplies the supervisory prior. From popularity 4, a discrete target length 5 is computed via quantile mapping, and a binary target mask is formed as
6
The cumulative masks are regularized toward this target with cross-entropy:
7
HRQ and SLC are trained jointly with four losses. The reconstruction loss is
8
The quantization/commitment loss, using stop-gradient 9 as in VQ-VAE, is
0
with 1. The length cost is
2
The combined tokenizer objective is
3
At inference time, SLC uses 4-thresholding, for example 5, and the cumulative mask to select the truncation point:
6
The paper reports that calibration is minimal and 7 is tuned on validation. A notable ablation is that using hard PIBA lengths without SLC underperforms by 8–9, which indicates that the popularity prior alone is insufficient and that content-aware gating materially contributes to performance.
5. End-to-end architecture, training, and decoding
VarLenRec is an end-to-end pipeline from item features to a generative recommender (Wang et al., 18 May 2026). First, a content encoder maps item features, such as Sentence-T5 text embeddings, to the hyperbolic manifold. Second, HRQ with 0 residual layers and codebooks of size 1 performs layerwise hyperbolic quantization, while SLC predicts soft retention. Third, the tokenizer outputs variable-length discrete IDs as the selected code indices up to the learned truncation 2. Fourth, a Transformer/T5 decoder is trained on sequences of item IDs to predict next-item IDs.
The downstream generative objective is standard next-token loss:
3
Training proceeds in two stages. In the HRQ+SLC stage, item features are encoded, quantized layer by layer, masked through cumulative gates, softly reconstructed, and optimized with Riemannian Adam. In the GR stage, token sequences are built from HRQ IDs, with collision resolution and EOS, and the LLM is trained with cross-entropy.
The representative settings reported are: codebook size 4, maximum length 5, curvature 6, and gate threshold 7. Riemannian Adam is used for HRQ with learning rate 8 and batch size 9; Adam is used for GR with learning rate 00 and batch size 01; beam search size is 02 at inference.
Variable-length IDs create specific decoding issues, and the paper therefore emphasizes three mechanisms. First, collision handling reserves an auxiliary disambiguation range, for example IDs in 03, to append to colliding short IDs and avoid semantic interference. Second, trie-constrained decoding builds a prefix tree of all valid IDs to avoid hallucinations. Third, length bias correction rescales decoded candidates with the length-invariant odds ratio
04
The inference procedure is therefore: run constrained beam search over a prefix trie of valid IDs, decode until EOS, rescore candidates to correct length bias, and map decoded IDs to items.
6. Experimental results, practical considerations, and limitations
The experiments are conducted on Amazon Beauty, Sports and Outdoors, Toys and Games, and Yelp, with users and items having fewer than 05 interactions dropped. The splits are leave-one-out: last item as test, second last as validation, and the rest as train. Evaluation uses Recall@K and NDCG@K for 06 under a full ranking protocol (Wang et al., 18 May 2026).
Baselines include sequential recommenders—HGN, GRU4Rec, BERT4Rec, SASRec, FMLP, 07-Rec, and HSTU—as well as fixed-length GR tokenizers such as TIGER and ETEGRec, and enhanced GR tokenizers such as LETTER-TIGER and LETTER-LCRec. Across all datasets, VarLenRec consistently improves over fixed-length GR baselines and traditional sequential recommenders. With LCRec backbones, VarLenRec achieves top performance on Beauty, Sports, and Toys; with TIGER backbones, it tops Yelp. The reported gains reach up to about 08 in NDCG@10, and are strongest on semantically diverse catalogs such as Beauty and Toys.
The ablation results isolate the role of each component. No single fixed 09 is optimal; adaptive lengths outperform all fixed choices 10. Replacing hyperbolic HRQ with Euclidean RQ reduces Recall@10 by about 11–12 on Beauty and Toys. Removing 13 or 14 degrades results, and 15 prevents unnecessarily long IDs. Removing collision resolution, trie decoding, and length-normalized scoring leads to about an 16 Recall@10 drop. These findings indicate that VarLenRec is not only a variable-length tokenizer, but a coupled system whose theoretical allocation rule, geometry, gating, and decoding strategy interact.
The headline result for the motivating paradox is reported on Beauty at 17: VarLenRec simultaneously improves head 18, body 19, and tail 20 groups versus fixed-length TIGER. In efficiency terms, VarLenRec reduces training time by approximately 21 and inference time by approximately 22 versus TIGER, due to shorter IDs for popular items and early termination during decoding.
Several implementation details are emphasized. Stability on the Poincaré ball is maintained by setting 23 and enforcing a safety margin 24 from the boundary. Popularity smoothing 25 stabilizes 26, and rank-based mapping reduces sensitivity to outliers. The paper recommends tuning 27 and 28 per dataset. Riemannian Adam is used to keep codebook vectors on the manifold, with updates applied through the exponential map and projection back into the ball interior if parameters approach the boundary.
The stated limitations are tied to the assumptions of the framework. PIBA assumes collaborative information grows as 29; if popularity dynamics or interaction quality violate this submodular trend, the exponent may mis-specify length. The quality of the content encoder matters for tail items, because poor content features reduce the benefit of longer IDs. Curvature choice 30 and codebook size 31 interact with capacity, so mis-tuning may cause underfitting near the origin or crowding near the boundary. Proposed extensions include adaptive budgets over time, user-conditioned lengths, multimodal content, and category-aware priors (Wang et al., 18 May 2026).
The paper does not provide a public repository link at the time of writing. Its recommended setup is Sentence-T5 embeddings for item features; HRQ with 32, 33, and 34; a T5 decoder trained with Adam at learning rate 35; beam size 36; trie-constrained decoding with odds-rescoring; and popularity estimated from normalized interaction counts with small-37 smoothing and rank-based quantile mapping. Within that formulation, VarLenRec presents variable-length tokenization as a principled allocation problem, a hyperbolic quantization problem, and a differentiable control problem, unified within generative recommendation.