All models

BERT4Rec

Bidirectional transformer that predicts a user's next item by filling in masked items in their history.

Tabular and recommender · 79 operations Checked

100%

Showing the top corner; full diagram not loaded yetShowing a small copy; full diagram not loaded yetLarge diagram, not loaded yet

Open SVG

Loading diagram (22 KB)

Open in a new tab

Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.

At a glance

Parameters
329.8K
Operations
79
Framework
PyTorch
Recurrent
No
Published
CIKM 2019
Cited by
251 (as of 19 October 2026)
Authors
Fei Sun, Jun Liu, Jian Wu and others
License
MIT
Checked
Passed: the trace was replayed operation by operation and matched the model's own output for this input.

Files

The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.

Details
Stable ID
m183
Graph hash
c2287701f153f706c711116279dc8ff05e0e0d32c94e94c11a543459d91d5bf3
Skeleton hash
eec7468a2f68c3c521711d734f3ca6843b93e91da60695ade502e1e9be468d37
Architecture hash
84869c0def34b286109bc3cb867c24f98170235e35dc8f99de9d60b66710c971
Diagram SHA-256
74903c1749c301b43f195682dcc9f3657603b6daea3a103ac7baae1584fb710a
TorchLens version
2.36.0
Renderer
graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
Check
Forward pass replayed in PyTorch

What it is

BERT4Rec is a sequential recommender that models a user's behavior sequence with deep bidirectional self-attention to predict the next item. Earlier neural recommenders read the history left to right, and the paper argues that such unidirectional models restrict what each item's hidden representation can encode and assume a rigid order that user behavior does not always follow. In the bidirectional model, every item in the history can fuse information from both its left and right sides.

To train it without leaking the target, the paper adopts the Cloze objective: some items in each input sequence are replaced by a special [mask] token and the model predicts their ids from the surrounding context. At test time, a [mask] token is appended to the end of the sequence and the recommendation is read from its final hidden vector. The item embedding matrix is shared between the input and output layers to limit overfitting and model size.

The paper describes SASRec as a left-to-right unidirectional version of BERT4Rec with single-head attention and a causal attention mask. Across Amazon Beauty, Steam, ML-1m and ML-20m, the paper reports average gains of 7.24% in HR at 10 and 11.03% in NDCG at 10 over the strongest baselines. The best mask proportion depended on the dataset: 0.6 for Beauty, 0.4 for Steam and 0.2 for the two MovieLens sets. The network on this page is RecBole's PyTorch port of the authors' TensorFlow implementation.

Key idea. BERT4Rec models user behavior sequences with bidirectional self-attention trained on a Cloze task, letting each item use both left and right context.

  • bert4rec
  • sequential recommendation
  • bidirectional transformer
  • cloze task
  • masked item prediction
  • next item recommendation
  • recbole bert4rec
  • self-attention recommender

AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.

Cite the paper

@misc{sun2019bert4recsequentialrecommendationbidirectional,
      title={BERT4Rec: Sequential Recommendation with Bidirectional Encoder Representations from Transformer}, 
      author={Fei Sun and Jun Liu and Jian Wu and Changhua Pei and Xiao Lin and Wenwu Ou and Peng Jiang},
      year={2019},
      eprint={1904.06690},
      archivePrefix={arXiv},
      primaryClass={cs.IR},
      url={https://arxiv.org/abs/1904.06690}, 
}