Decoding in Latent Spaces for Efficient Inference in LLM-based Recommendation

Chengbing Wang, Yang Zhang, Zhicheng Wang, Tianhao Shi, Keqin Bao, Fuli Feng, Tat-Seng Chua

Introduction

Large Language Models (LLMs) have revolutionized personalized recommendation systems (LLM4Rec) by leveraging their vast pretrained knowledge and reasoning capabilities. Typically, these models are fine-tuned to predict a user's next interaction by generating the item's title or description as text. However, this generative approach faces a critical bottleneck: autoregressive decoding.

Comparison between Language Space Decoding and the proposed Latent Space Decoding.

Generating a recommendation list token-by-token is computationally expensive and introduces significant latency, making real-time deployment nearly impossible. Furthermore, mapping generated text back to database IDs is error-prone due to potential hallucinations or minor textual variations. While adding a classification head is a common alternative, it often degrades the LLM's performance by deviating from its native next-token prediction objective.

Light Latent-space Decoding (L2D)

To address these challenges, we introduce Light Latent-space Decoding (L2D). L2D bypasses the text generation phase entirely by operating within the LLM's internal hidden states (the latent space). The core premise is that the LLM's final hidden state, after processing a user's prompt, already encodes the "intent" of the recommendation.

The complete L2D pipeline, from memory construction to item decoding.

The L2D framework consists of three primary stages:

1. Memory Construction

During the training phase, the system records the final hidden state of the LLM for every training sample. Each state is stored in a memory bank and paired with the ground-truth item ID that the user interacted with. This creates a rich repository of how the LLM "sees" items in different contexts.

2. Candidate Item Representation Generation

To represent a candidate item in the latent space, L2D aggregates the stored hidden states associated with that item. Two strategies are proposed:

  • Global Aggregation (L2D-G): Computes a static representation by averaging all hidden states for an item. This is particularly effective for sparse items where data is limited.
  • Local Aggregation (L2D-L): Dynamically selects the top-$M$ hidden states most similar to the current test sample's hidden state. This tailors the item representation to the specific user context, which is beneficial for items with many diverse interactions.

3. Item Decoding

At inference time, the LLM performs a single forward pass to generate a hidden state for the user's input. L2D then calculates the L2 distance between this state and the pre-computed candidate item representations. Items are ranked by similarity to form the final recommendation list. Crucially, L2D is a plug-and-play, training-free method that requires no additional parameters.

Evaluation and Results

The L2D method was evaluated on the Amazon CDs and Amazon Games datasets, which consist of chronological user-item interactions.

Performance and Efficiency

  • Inference Speed: L2D achieves a 10x speedup compared to traditional language-space decoding (e.g., beam search). Its overhead is comparable to non-LLM recommendation models, making it viable for real-time applications.
  • Recommendation Accuracy: L2D consistently outperformed state-of-the-art LLM-based recommenders (such as BIGRec and GPT4Rec) and traditional models (SASRec, GRU4Rec) across Recall@K and NDCG@K metrics.
  • Robustness to Data Sparsity: Unlike classification heads that struggle with sparse data, L2D maintains high performance by preserving the LLM's generative training objective.

Memory and Scalability

While storing hidden states requires memory, experiments showed that L2D is highly resilient to memory pruning. Randomly dropping 70% of the memory cache only resulted in minor performance dips, still allowing it to outperform most baselines. The method also scales effectively from smaller models (Llama 3.2-1B) to larger ones (Llama 3.1-8B).

Conclusion

Light Latent-space Decoding (L2D) provides a highly efficient and accurate alternative to autoregressive decoding for LLM-based recommendations. By shifting from the language space to the latent space, L2D eliminates the generation bottleneck and mapping errors while improving overall performance. Future work will focus on addressing cold-start scenarios and developing dynamic memory update strategies for streaming data.

Summary updated

BibTeX
@misc{wang2025decoding,
  author = {Chengbing Wang and Yang Zhang and Zhicheng Wang and Tianhao Shi and Keqin Bao and Fuli Feng and Tat-Seng Chua},
  title = {{Decoding in Latent Spaces for Efficient Inference in LLM-based Recommendation}},
  year = {2025},
  eprint = {2509.11524},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.11524},
}
Figure