TL;DR
Hidasi and colleagues showed that a gated recurrent network can read a shopper's clicks in order and predict the next one. The usual recommender methods of the time needed a long user history, and most web shops do not have one: many visitors are anonymous and have only one short session. The authors trained the network with a pairwise ranking loss, which tells the model that the clicked item should score above sampled items the user did not click. On two real click datasets their best variants reached a Recall@20 roughly 20 to 25 percent above the strongest item-to-item baseline.
Builds on: Gated Recurrent Unit, Backpropagation Through Time, Recommender System, Negative Sampling, Pairwise Ranking Loss · Leads to: the family of sequence-based recommenders that followed it
Why it mattered
Session-based recommenders are the default for many small shops, news sites and video services, where the visitor is not logged in. The paper showed that a recurrent network trained on the whole click sequence beat the simple item-to-item rules that dominated that setting. It also set out practical choices, such as how to build mini-batches from sessions and how to sample negatives cheaply, that later sequence-based recommenders could build on. The paper is widely cited in recurrent recommendation work.
The problem
A recommender usually works by learning a vector for each user and each item and taking the dot product to score a pair. This is the Matrix Factorization approach, and it needs a user profile built from many past events. In a session there is no profile: the user is anonymous, and the session may contain only two or three clicks. The common fallback was item-to-item similarity, computed from co-occurrence counts. It uses only the last click, so it ignores what the visitor looked at earlier in the same session.
Two further problems follow. First, the catalogue can have tens of thousands to millions of items, so scoring every item at each step is too slow. Second, the training signal is sparse: the user did not click most items, but an unclicked item is not necessarily one the user dislikes. The paper has to model the order of clicks, scale to a large catalogue, and learn from positive clicks against negatives in a way that ranks the right items at the top.
How it works
The pipeline runs in this order. Each stage is shown on one event so the flow is clear.
-
Input encoding: each click is a one-hot vector over all items. If the catalogue has 37,483 items, the vector has that many entries, with a 1 at the clicked item and zeros elsewhere. The paper found that this was slightly better than using a learned embedding of the items. Check: a click on item 5 in a 10-item catalogue gives the vector .
-
Recurrent state: a single layer of GRU units reads the click and updates its hidden state , which summarises the session so far. The paper uses one GRU layer, with 100 or 1000 hidden units. Check: after the first click the state depends only on that click; after the second, it depends on both.
-
Output scores: a linear output layer turns the hidden state into one score per item. The paper found it helpful to apply to the output layer. Check: the output is one number per item, and a higher number means the item is predicted to come next.
-
Session-parallel mini-batches: many sessions are processed side by side. Each slot in the batch holds one session. When a session ends, the slot is given the next session and its hidden state is reset to zero, because sessions are independent. This keeps every batch full even though sessions have different lengths, from 2 events to a few hundred. Check: a session never sees the hidden state of the session before it.
-
Sampled output: scoring every item at every step is too costly, so the loss only uses the target item and a few negatives. The negatives are the targets of the other sessions in the same mini-batch. Because popular items appear more often as targets, these negatives are sampled roughly in proportion to popularity. Check: with a batch of 50 sessions there are 49 negatives per example at no extra sampling cost.
-
Ranking loss: the model is trained so that the target item scores above the negatives. The paper uses two losses: a pairwise BPR loss and a new loss, TOP1, described in the math below. Check: lowering the target's score or raising a negative's score must increase the loss.
flowchart LR A["Session clicks, one-hot"] --> B["GRU hidden state h_t"] B --> C["Score for every item, tanh output"] C --> D["Target item vs sampled negatives"] D --> E["Ranking loss, BPR or TOP1"] E -->|"gradients through time"| B
The math
The GRU update
A recurrent unit in the paper follows the gated update of Cho and colleagues. The update gate and reset gate are computed from the input and the previous state :
The candidate state is
and the new state is a weighted average of the old state and the candidate:
Here is the logistic sigmoid, is elementwise multiplication, and each and is a learned matrix. When is near zero the state is copied forward, which is how the unit keeps information over long spans.
Step 3 in symbols: the scores
The output for item at step is a score , computed from by a linear map followed by . The paper's choice of at the output layer is reported as beneficial.
Step 5 in symbols: the sampled loss
For one step of one session, let be the target item and the sampled negative items. The BPR loss from Bayesian personalised ranking compares the target with each negative:
Minimising this pushes above each . The TOP1 loss introduced in the paper approximates the relative rank of the target. The rank is the number of negatives that score above the target, and the paper replaces the indicator "negative scores above target" with a sigmoid. It adds a regulariser that pulls each negative score toward zero:
The first term is the sigmoid approximation of "negative beats target". The second term pulls the negative scores toward zero, which the paper added to stop scores drifting upward during training.
Results
The evaluation feeds each test session one click at a time and asks where the next clicked item ranks. The main metric is Recall@20, the share of test cases where the next item is in the top 20. The second metric is MRR@20, the average reciprocal rank, set to zero when the item is below rank 20.
The two datasets are RSC15, built from the RecSys Challenge 2015 e-commerce click stream, and VIDEO, from a video service. RSC15 has 7,966,257 training sessions with 31,637,239 clicks on 37,483 items, and its test set has 15,324 sessions with 71,222 events. VIDEO has about 3 million training sessions with about 13 million watch events on 330 thousand videos, and about 37 thousand test sessions.
Item-KNN, the strongest baseline, scores Recall@20 of 0.5065 and MRR@20 of 0.2048 on RSC15, and Recall@20 of 0.5508 and MRR@20 of 0.3381 on VIDEO. The paper's Table 3 shows the best GRU variants:
| Loss and units | RSC15 Recall@20 | RSC15 MRR@20 | VIDEO Recall@20 | VIDEO MRR@20 |
|---|---|---|---|---|
| TOP1, 100 | 0.5853 | 0.2305 | 0.6141 | 0.3511 |
| TOP1, 1000 | 0.6206 | 0.2693 | 0.6624 | 0.3891 |
| BPR, 1000 | 0.6322 | 0.2467 | 0.6311 | 0.3136 |
| Cross-entropy, 100 | 0.6074 | 0.2430 | 0.6372 | 0.3720 |
The best Recall@20 on RSC15 is BPR with 1000 units, at 0.6322 (+24.82 percent over Item-KNN). The best MRR@20 on RSC15 and the best results on VIDEO come from TOP1 with 1000 units, which reaches 0.6624 Recall@20 on VIDEO, 20.27 percent above Item-KNN. The paper's own summary is that the TOP1 loss gives "~20-30%" accuracy gain over the best baseline on these two datasets.
The limits are important. Cross-entropy was numerically unstable: only 10 of 100 random runs were stable on RSC15 and 6 of 100 on VIDEO, and the paper gives no result for cross-entropy with 1000 units on VIDEO. BPR was worse than Item-KNN on MRR@20 for VIDEO. Both datasets come from single services, the experiments are offline, and the baselines are the ones available in 2015. The results show that the approach is strong on these data, not that it wins everywhere.
Reading guide
- Abstract and Section 1, Introduction: why session data needs a different model from matrix factorization. Use Recommender System and Matrix Factorization.
- Section 2, Related work: item-to-item rules, factorization models and Markov decision processes. Read it after the problem section to see what was being replaced. The paper notes that Markov decision processes were another route to session data. Use Markov Decision Process for that model.
- Section 3, Recommendations with RNNs, equations: the GRU equations are the core of the method. Use Gated Recurrent Unit, Recurrent Neural Network and Sigmoid Function.
- Section 3.1.1, session-parallel mini-batches: a systems idea, easiest to read with the reset rule in mind. Use Backpropagation Through Time for why sequences are batched this way.
- Section 3.1.2, sampling on the output: the negatives trick. Use Negative Sampling.
- Section 3.1.3, ranking loss: BPR and TOP1. Use Pairwise Ranking Loss and BPR: Bayesian Personalized Ranking from Implicit Feedback.
- Section 4, Experiments: the datasets, metrics and tables. Use Stochastic Gradient Descent for the training setup and Dropout for the regularisation in Table 2.
Check yourself
QuestionRecall: why does the paper use session-parallel mini-batches instead of cutting sessions into fixed-length windows, as NLP models usually do?Show answer
Sessions vary in length, from 2 events to a few hundred, and the goal is to model how one session evolves over time. Cutting a session into windows would break that evolution. The paper therefore keeps each session whole and refills an empty slot with the next session, resetting the hidden state.
QuestionComputation: with the TOP1 loss, one target has score 2 and one sampled negative has score 0. What is the loss? Use .Show answer
The loss is . Since , the loss is about .
QuestionWhy: the TOP1 loss has a second term, , that pulls each negative score toward zero. What would go wrong without it?Show answer
The first term only asks the target to score above the negatives. Any item that is a target in one step is a negative in another, so without the second term its score would be pushed up in one step and not pushed down in the other, and the scores would keep growing. The paper found training unstable in that case. The regulariser keeps negative scores near zero, which is a natural reference point for them.
QuestionApplied: a small shop has only anonymous sessions of 2 to 4 clicks and a catalogue of 2,000 items. Should it expect GRU4Rec to beat item-to-item similarity?Show answer
The paper's setting is close to this one, since its main problem is anonymous sessions and item-to-item rules that use only the last click. The gain is most likely where the session order matters. But a small catalogue means fewer negatives and less training data, and the paper's gains were measured on millions of sessions. The shop should check the claim with a held-out test set of its own sessions, comparing Recall@20 against item-to-item similarity, and not assume the reported gains transfer.