Recommender systems
Sequential Recommendation and Next-Item Prediction
Understand recurrent and self-attentive sequential recommenders, sequence construction, masking, truncation, and reproducible evaluation.
By the end you can
- Explain recurrent and self-attentive approaches to sequential recommendation
- Design causal sequence examples, masks, targets, and truncation
- Identify chronology, funnel, padding, and sampled-evaluation failures
- Build reproducible comparisons with transition, GRU, and attention baselines
Visual
A sequential recommendation example
Everything here turns on one line. Only events from the historical prefix, before the target timestamp, may be used. Representation, model and scoring all follow from it. The temporal evaluation at the end is what proves it held.
The line is easier to state than to hold. A 2023 study ran four recommenders — BPR, NeuMF, SASRec and LightGCN — on MovieLens-25M, Yelp, Amazon-music and Amazon-electronic. The split was leave-last-one-out, the one the field reaches for by default. All four recommended items that did not yet exist at the test timestamp. And the prefix is never the whole history anyway. The SASRec timings everyone quotes were measured on sequences cut to the most recent 200 actions.
Historical prefix
Use only events available before the target timestamp.
Event representation
Encode item, event type, position, context, and optional time gaps.
Sequence model
Apply recurrence, convolution, or self-attention with causal masking.
Candidate scoring
Compare the sequence state with eligible item representations.
Temporal evaluation
Predict future items under a realistic serving and sampling protocol.
Example
The next-item model learned the checkout funnel
An e-commerce sequence model predicted the path from product view to cart page to checkout, and predicted it accurately. It looked like the strongest model the team had built. What it had memorized was interface transitions, not product preference. Each decision below has a published counterpart, and the published counterparts are sharper than the intuition.
- Sequence definition: Page events, item events and system-generated steps went into one vocabulary. A next-item metric has no way to mark which of them the product served and which the user chose. Admit navigation to the vocabulary and navigation becomes a correct answer.
- Position and time: Order mattered, but irregular time gaps carried meaning of their own. A 2021 AAAI paper states the task in exactly those terms: sequential recommendation “aims to model the dynamic preferences of users from their historical interactions and predict their next items”. Dynamic preference is what the gaps encode. Drop them and what is left is the sequence the interface produced.
- Truncation: Only the most recent 100 events were retained, for serving efficiency. The SASRec paper's own sweep on ML-1M puts NDCG@10 at 0.571 for a maximum length of 100 and 0.587 at 200. That window is a measured trade against quality, not a housekeeping detail.
- Leakage risk: Future-derived session features entered earlier sequence states. The leakage study's abstract records what that does to a leaderboard: “Their relative performance orders thus become unpredictable with different amount of leaked future data in training”. It is not one model's number that moves. It is the order.
- Benchmark sensitivity: Preprocessing and negative sampling changed reported model rankings. A 2021 case study trained four sequential models on five datasets. It set full-catalogue ranking against uniform-random and popularity-based candidate sets, at the target-set size of 100 the field conventionally uses. Its authors: “Overall, we find that both sampling strategies can produce inconsistent rankings compared with the full ranking of the models.”
Comparison
Recurrence and self-attention offer different sequence biases
Each carries a different assumption about which part of a history matters. GRU-style recurrence compresses everything into one evolving state. SASRec-style attention lets each position reach back to the items it needs. The simple transition baseline assumes only the last item counts — and it wins often enough that a comparison without it means very little.
That last sentence is a measurement, not a caution. In 2018 a sixty-page journal study set GRU4REC and factorized Markov models such as FISM and FOSSIL against simple nearest-neighbour schemes, across several datasets. Ludewig and Jannach reported of the neighbourhood methods: “Our experiments reveal that algorithms of this latter class, despite their sometimes almost trivial nature, often perform equally well or significantly better than today's more complex approaches based on deep neural networks.” That is why the grey column stays in the table.
GRU-style recurrence
Compresses history into an evolving hidden state.
- Natural streaming update
- Strong session baseline
- Long history can be compressed aggressively
- Sequential computation limits parallelism
SASRec-style attention
Lets each position attend to selected earlier items.
- Parallel training
- Adaptive access to history
- Quadratic cost in sequence length
- Needs careful positional and mask design
Simple transition baseline
Uses recent item or short Markov context.
- Cheap and interpretable
- Strong when behavior is local
- Misses long-range preferences
- Essential for fair comparison
Sequential recommenders model ordered interaction history
Recurrent networks, convolutional sequence models and self-attention architectures such as SASRec all estimate the next relevant item from prior actions. SASRec's authors describe their model as one that “seeks to identify which items are ‘relevant’ from a user's action history, and use them to predict the next item”. That framing belongs to the whole family. Recency, repetition, transitions and long-range dependencies become representable in a way an unordered profile cannot express.
The target is still a proxy. Predicting the next item may favour predictable navigation, replenishment or plain habit, even when the product is trying to produce discovery, satisfaction or long-term value. Note what the reported gains are gains in. SASRec's headline improvement is 6.9% Hit Rate and 9.6% NDCG against the strongest baseline. Both measure how well the next item was guessed. Neither measures whether guessing it served the user.
Accuracy on the next item rewards habit, so decide early whether habit, discovery, or long-term value is the outcome the product is after.
Case
SASRec’s numbers, and the 200-action window they were measured in
Two numbers from the 2018 SASRec paper carry this lesson, and both were measured in the same work. On accuracy: “Our method SASRec outperforms all baselines on both sparse and dense datasets, and gains 6.9% Hit Rate and 9.6% NDCG improvements (on average) against the strongest baseline.” On speed: one training epoch on MovieLens-1M took 1.7 seconds for SASRec, against 19.1 seconds for Caser and 30.7 seconds for GRU4Rec+.
That second number is what the familiar paraphrase compresses. The abstract says the model “is an order of magnitude more efficient than comparable CNN/RNN-based models”, and the sentence is true. But the timings behind it were taken “using complete training data or just the most recent 200 actions (as in SASRec)”. The 1.7, 19.1 and 30.7 second figures are all from the truncated condition. On complete training data the neighbours read 31.98 seconds per epoch for Caser and 46.9 for GRU4Rec+. So the efficiency claim is a truncated model against truncated neighbours. It is not a licence to serve whole histories.
Efficiency is not a detail here. A 2021 AAAI paper puts the serving constraint plainly: “The accumulated user behavior records on real systems could be very long … it has become intolerable to scan the entire behavior sequence when performing inference for each user, since real-world system requires short response time”. Both papers describe next-item predictors. A next-item predictor is narrower than a user's actual objective.
Example
Sequential-model traps
Chronology leakage inflates the number. Parameter-budget unfairness inflates the comparison. Random splits or future-derived features let later behaviour into training; an untuned small baseline lets a large attention model win without earning it. Each of the five below has been measured on named models.
- Chronology leakage: Random splits or future-derived features reveal later behavior. A 2023 study ran BPR, NeuMF, SASRec and LightGCN on MovieLens-25M, Yelp, Amazon-music and Amazon-electronic. The split was the standard leave-last-one-out: “Through carefully designed experiments, we show that all models indeed recommend future items that are not available at the time point of a test instance, as the result of data leakage.” That split is the field's default protocol, not a careless variant of it.
- Interface memorization: The model predicts the product funnel instead of user value. The metric cannot see the difference, because a served page and a chosen item are the same kind of row once both are in the vocabulary.
- Padding and mask bug: The network attends to padded or future positions. A chronological split governs the boundary between examples, not the boundary inside one. It will report a clean number for a model that is reading its own future.
- Negative-sampling artifact: Metrics depend more on sampled candidate difficulty than on ranking quality. A 2020 KDD paper showed that a sampled candidate set does not preserve the ordering between recommenders, even in expectation. As the sample shrinks, all ranking metrics converge to AUC. Krichene and Rendle: “This paper investigates sampled metrics in more detail and shows that they are inconsistent with their exact version, in the sense that they do not persist relative statements, e.g., recommender A is better than B, not even in expectation.” Their conclusion is that sampling should be avoided for metric calculation.
- Parameter-budget unfairness: A large attention model is compared with untuned small baselines. A 2019 audit could reproduce only 7 of 18 neural top-n recommendation methods published at top conferences, and 6 of those 7 were beaten by comparably simple heuristics. A later replication found the original BERT4Rec code needing up to 30x more training than its default configuration before it reproduced its own published results. Roughly 42 minutes stretched to about 21 hours.
Steps
Build a reproducible sequential benchmark
An event vocabulary that admits page navigation will produce a model of the checkout funnel. Defining it is step one. Steps three, four and five decide whether the eventual comparison means anything. Each of them rests on a published measurement rather than a rule of thumb.
Step three, tuning the simple baselines. The literature does not agree with itself about which of two well-known sequential models is stronger. A 2022 review read 370 papers citing BERT4Rec. It found 40 peer-reviewed publications making 134 BERT4Rec-versus-SASRec comparisons on 46 datasets. BERT4Rec won 86 of them (64%), SASRec won 32 (24%), and 16 tied (12%). Petrov and Macdonald then ran the replication themselves. At default settings the original BERT4Rec code did not reproduce its published results: “However, we are able to replicate the reported results with the original code if training for a much longer amount of time (up to 30x) compared to the default configuration.” That is roughly 42 minutes of training stretched to about 21 hours. A baseline's number can be an artefact of its training budget rather than of its architecture.
It can also be an artefact of whose code you ran. Hidasi and Czapp compared six unofficial reimplementations of GRU4Rec against the official code, on five public datasets. One implements a different and flawed algorithm. The remaining five lack accuracy-critical features, and four contain bugs. “In the most extreme case, out-of-the-box performance is 99.63% lower compared to the official version.” The GRU row in your comparison table may not be GRU4Rec at all.
Step four, standardizing negatives, is the sampled-metrics result applied. Sampled metrics do not persist relative statements, even in expectation, and they collapse toward AUC as the sample shrinks. The sequential-model version of that experiment used four models and five datasets. It set uniform-random and popularity-based candidate sets at the target set size of 100 the field defaults to. Both strategies produced rankings inconsistent with the full ranking.
Step five is not a hyperparameter shrug, because the sweep has been published. SASRec's own scalability table varies maximum sequence length n on ML-1M across 10, 50, 100, 200, 300, 400, 500 and 600. NDCG@10 runs 0.480, 0.557, 0.571, 0.587, 0.593, 0.594, 0.596, 0.595. Training time runs 75, 101, 157, 341, 613, 965, 1,406 and 1,895 seconds. That is a 25x cost increase across the sweep. The authors' own reading: “Performance is better with larger n, up to around n = 500 at which point performance saturates (possibly because 99.8% of actions have been covered).” Past n = 200 there is 0.009 NDCG@10 left to gain, and buying it costs 4.1x more training time: 341 seconds at n = 200 against 1,406 seconds at n = 500. That is the shape of the curve a team should be producing for its own data.
1. Define event vocabulary
Separate user choices from system-generated navigation.
2. Construct temporal prefixes
Ensure every feature and target respects event time.
3. Tune simple baselines
Include popularity, last-item, Markov, GRU, and SASRec-like models.
4. Standardize negatives
Report all-item or clearly documented sampled evaluation.
5. Test history limits
Measure quality, latency, and bias across truncation lengths.
Analogy
A detective reading a case file in order
Notes taken during an investigation carry their hypotheses in their order, so rearranging the pages destroys evidence. That order also records which questions the investigators chose to ask. Sequential recommendation reads history the same way, with the interface in the role of investigator. The next event a user can produce is one the product offered. That is how a next-item model ends up an expert on the checkout funnel.
Rearranging the pages is not a hypothetical failure either. Under leave-last-one-out — the split the field reaches for by default — BPR, NeuMF, SASRec and LightGCN were all found recommending items that did not exist at the test timestamp. That is a detective naming a suspect the file had not yet met.
Sequence models learn both user intent and the product pathways that shape it.
Key idea
The sequence gate
Sequential gains count only when they survive chronological splits and strong transition baselines, and only with evidence that the model predicts user-relevant items rather than interface mechanics.
The cost of skipping that gate has been counted. A 2019 audit took the Best Long Paper award at RecSys for counting it: “Specifically, we considered 18 algorithms that were presented at top-level research conferences in the last years. Only 7 of them could be reproduced with reasonable effort. For these methods, it however turned out that 6 of them can often be outperformed with comparably simple heuristic methods, e.g., based on nearest-neighbor or graph-based techniques.” Those 18 had cleared peer review at top-level conferences. The gate is what peer review did not supply.
A sequential model that clears neither bar is paying real latency and complexity to re-predict the product's own navigation.
Key takeaways
- Ordered history is a powerful signal, but every sequence is partly authored by the product that generated it — a vocabulary that admits page navigation makes the checkout funnel a correct answer.
- Recurrent networks, convolutional sequence models and self-attention architectures such as SASRec estimate the next relevant item from prior actions; SASRec's 2018 paper reports gains of 6.9% Hit Rate and 9.6% NDCG on average against the strongest baseline.
- Sequence order is informative only after system events, user events, timing and task boundaries are defined correctly. Until they are, an almost trivial neighbourhood scheme may match the neural model — Ludewig and Jannach found exactly that against GRU4REC, FISM and FOSSIL across several datasets.
- Historical prefix means only events available before the target timestamp, and the field's default protocol does not deliver it: under leave-last-one-out, BPR, NeuMF, SASRec and LightGCN were all found recommending items unavailable at the test instance.
- Chronology leakage moves leaderboards, not just numbers: relative performance orders become unpredictable with different amounts of leaked future data in training.
- Truncation length is a tunable with consequences. On ML-1M, NDCG@10 rises from 0.480 at n = 10 to 0.587 at n = 200 and saturates at 0.596 by n = 500, while training time rises from 75 to 1,895 seconds across the sweep. Measure quality, latency and bias across several history lengths before fixing one.