BEAR: Towards Beam-Search-Aware Optimization for Recommendation with Large Language Models

Weiqin Yang, Bohao Wang, Zhenxiang Xu, Jiawei Chen, Shengjia Zhang, Jingbang Chen, Canghong Jin, Can Wang

TL;DR

Large Language Models (LLMs) used for recommendation suffer from a critical training-inference mismatch: standard supervised fine-tuning (SFT) optimizes overall item probability, while inference relies on beam search, which greedily prunes items step-by-step. To fix this, BEAR (Beam-SEarch-Aware Regularization) introduces a computationally efficient regularization term ensuring that every token of a target item ranks within the top-$B$ candidates during training. This simple adjustment slashes premature pruning and boosts recommendation accuracy by an average of 12.50% with virtually zero computational overhead.

What Problem Does This Paper Address?

When adapting LLMs for recommender systems, researchers typically frame recommendation as a generative sequence task. The model is fed a user's interaction history as a text prompt and trained via Supervised Fine-Tuning (SFT) to output the exact text description of a target item (e.g., a movie title).

During inference, evaluating every single item in a massive catalog is too expensive. Instead, systems use beam search—a decoding strategy that maintains a small pool of the top-$B$ most probable token sequences at each step, discarding the rest.

The authors identify a fundamental flaw here: training-inference inconsistency. SFT maximizes the overall probability of the entire target sequence. However, beam search is locally greedy. If a highly relevant item happens to begin with a token that has a low initial probability, beam search will prematurely prune it at the very first step, regardless of how high its total probability would have been later on.

Beam search pruning comparison between SFT and BEAR. In SFT (left), a high-probability item is pruned early due to a low-probability prefix. BEAR (right) ensures prefix tokens remain in the top candidates.

Alarmingly, the authors found that over 80% of positive items that should be recommended based on their total SFT probability are accidentally killed off early by beam search pruning.

Methods

To bridge this gap, you could theoretically simulate the entire beam search process during training and penalize the model when a target item gets dropped. However, this naive approach requires multiple sequential forward passes per token, making training computationally prohibitive (over 4.45× slower than standard SFT).

Instead, the authors propose BEAR (Beam-SEarch-Aware Regularization), which optimizes a relaxed but highly effective necessary condition: each token of a positive item must rank within the top-$B$ candidate tokens at its respective decoding step.

Here is how BEAR works under the hood:

  1. Zero-Overhead Thresholding: During standard SFT, the model already computes the logits for all vocabulary tokens at each step. BEAR leverages these existing logits to find the $B$-th highest token probability, setting it as a dynamic threshold ($\beta_t^B$).
  2. Pruning Margin Minimization: It calculates a "pruning margin"—the difference between the threshold and the target token's log-probability. If the target token falls below the top-$B$ threshold, it incurs a penalty.
  3. Differentiable Smoothing: Because ranking is a discrete, non-differentiable operation, BEAR replaces the hard indicator function with a smooth sigmoid surrogate function, allowing for standard gradient-based optimization.

The final loss function simply combines standard cross-entropy SFT loss with the BEAR regularization term: $$\mathcal{L}_{BEAR} = \mathcal{L}_{SFT} + \lambda \mathcal{L}_{reg}$$

Datasets

The authors evaluated BEAR across four widely used real-world Amazon recommendation benchmarks:

  • Office Products (4,895 users, 2,414 items)
  • Books (16,559 users, 6,344 items)
  • Toys & Games (19,124 users, 11,758 items)
  • Clothing, Shoes & Jewelry (39,230 users, 22,948 items)

All datasets were preprocessed using a standard 5-core filtering approach (retaining users and items with at least 5 interactions) and segmented using a sliding window of size 11.

Key Insights and Ideas

  • The Root Cause of Pruning: Empirical analysis revealed that simply violating the token-level top-$B$ necessary condition accounts for over 70% of all incorrect pruning cases in real-world datasets.
  • The "Free Lunch" of Logits: You don't need to generate text or simulate complex search trees during training to align a model with beam search. The token distribution logits already contain all the information needed to enforce search-awareness, meaning alignment can be achieved with zero extra forward passes.
  • Model-Agnostic Flexibility: Because BEAR is purely a loss-function modification, it can be seamlessly integrated into any LLM backbone (e.g., Llama, Qwen) or combined with other alignment strategies like Direct Preference Optimization (DPO).

Key Results

  • Accuracy Boost: BEAR consistently outperformed nine state-of-the-art baselines (including advanced SFT and DPO variants), yielding an average relative improvement of 12.50% across all datasets in metrics like NDCG@10 and HitRatio@10.
  • Pruning Reduction: BEAR successfully mitigated the training-inference gap, reducing the incorrect pruning rate by an average of 24.86% compared to standard SFT.
The authors show that failing to meet BEAR's necessary condition is the overwhelming cause of premature pruning across datasets.
  • High Efficiency: Unlike pairwise preference methods (DPO) or beam-simulation methods which increase training times by 2× to 10×, BEAR runs at virtually the same speed as standard SFT, making it highly practical for production environments.

Limitations and Future Work

While BEAR effectively addresses token-level constraints, it optimizes a necessary condition rather than a sufficient one; it ensures tokens are locally competitive, but cannot fully guarantee that cumulative prefix probabilities won't cause an item to drop out of the beam later on.

For future work, the authors suggest exploring how BEAR can be paired with inference-side modifications, such as multi-token prediction architectures or diverse beam search algorithms, to further robustify generative retrieval.

Summary updated

BibTeX
@inproceedings{yang2026bear,
  author = {Weiqin Yang and Bohao Wang and Zhenxiang Xu and Jiawei Chen and Shengjia Zhang and Jingbang Chen and Canghong Jin and Can Wang},
  title = {{BEAR: Towards Beam-Search-Aware Optimization for Recommendation with Large Language Models}},
  booktitle = {International ACM SIGIR Conference on Research and Development in Information Retrieval},
  year = {2026},
  doi = {10.1145/3805712.3809533},
}
Figure