Introduction
Sequential recommendation is a critical task in modern information systems, aiming to predict a user's next interaction based on their historical behavior. Traditional approaches have largely relied on unidirectional models, which process sequences from left to right. However, these models often fail to capture the complex, non-linear dependencies inherent in user behavior. This paper, presented at CIKM 2019, introduces BERT4Rec, a novel recommendation model that leverages the bidirectional power of the Transformer architecture.
The Limitation of Unidirectional Models
Existing sequential recommendation systems typically employ Recurrent Neural Networks (RNNs) or unidirectional Transformers (like SASRec). These models assume a strict chronological order, where an item's representation is only influenced by its predecessors.
The authors argue that this approach has two primary drawbacks:
- Restricted Representation: By only looking "backwards," the model misses out on the global context of the user's history.
- Rigid Order Assumption: User interactions are often driven by unobserved factors, and the sequence might not follow a strict "natural order" similar to language.
Methodology: BERT4Rec Architecture
To overcome these limitations, BERT4Rec adopts a bidirectional Transformer encoder. Unlike unidirectional models that use causal masking to prevent "looking ahead," BERT4Rec allows each item in the sequence to attend to all other items, both past and future.
The Cloze Task
A significant challenge in training bidirectional models for recommendation is preventing the model from "cheating" by seeing the target item during training. BERT4Rec solves this by using the Cloze task (Masked Language Modeling). During training, a random subset of items in the input sequence is replaced with a special [mask] token. The model is then trained to predict the original IDs of these masked items based on the surrounding context.
Inference for Recommendation
For the actual recommendation task, where the goal is to predict the next item, the authors append a [mask] token to the end of the user's interaction sequence. The model's output for this final token provides a probability distribution over all items, which is used to generate the top-N recommendations.
Experimental Results
The authors evaluated BERT4Rec against several state-of-the-art baselines, including GRU4Rec+ and SASRec, across four diverse datasets: Amazon Beauty, Steam, MovieLens 1m, and MovieLens 20m.
Performance Gains
BERT4Rec consistently outperformed all baselines. On average, it achieved improvements of:
- 7.24% in HR@10 (Hit Ratio)
- 11.03% in NDCG@10 (Normalized Discounted Cumulative Gain)
- 11.46% in MRR (Mean Reciprocal Rank)
Notably, on the large-scale MovieLens 20m dataset, BERT4Rec showed a 35.22% improvement in HR@1 over the next best model, highlighting its effectiveness in high-density scenarios.
Ablation and Hyperparameters
A key finding was the sensitivity of the masking proportion ($\rho$). The optimal $\rho$ varies with sequence length: shorter sequences (Amazon Beauty) benefit from higher masking rates (~0.6), while longer sequences (MovieLens) perform better with lower rates (~0.2). Furthermore, the "One-Mask" experiment confirmed that the architectural advantage of bidirectional self-attention is the primary driver of performance, even when the data augmentation benefits of the Cloze task are minimized.
Conclusion and Future Directions
BERT4Rec demonstrates that bidirectional modeling is superior for sequential recommendation, even for the task of predicting the next item. By utilizing the Cloze task, the model learns richer item representations from global context. Future work includes integrating auxiliary features (e.g., item categories), explicitly modeling long-term user preferences, and addressing the quadratic computational complexity of self-attention for extremely long sequences.
Summary updated