SASRec, short for self-attentive sequential recommendation, is a neural model that predicts the next item a user will interact with by applying causal self-attention to the ordered history of that user’s past interactions. In recommender systems, it is the reference Transformer-based baseline for sequential recommendation and one of the most widely reproduced models in the field of artificial intelligence applied to ranking.
Introduced by Wang-Cheng Kang and Julian McAuley in 2018, SASRec showed that a small decoder-style Transformer could outperform recurrent and convolutional models on next-item prediction while training faster. It remains a strong baseline that newer models must beat.
How SASRec models a user sequence
SASRec treats each user as a chronological sequence of item IDs, such as products viewed or films rated. The sequence is truncated or left-padded to a fixed maximum length, and each position is mapped to an item embedding plus a learnable positional embedding that tells the model where in the history the item occurred.
The embeddings pass through a stack of self-attention blocks, each containing multi-head attention, a point-wise feed-forward network, residual connections, layer normalization and dropout. A causal mask lets each position attend only to earlier positions, so the output at position t summarizes the history up to t and is used to predict the item at t + 1.
Scoring is a dot product between the sequence representation and item embeddings. The same embedding table is shared between the input and the output layer, which reduces parameters and helps generalization on sparse catalogs. The table below lists the main components.
| Component | Role | Typical setting |
|---|---|---|
| Item embedding | Represents each item as a vector | 50 to 256 dimensions |
| Positional embedding | Encodes the order of interactions | Learned, one per position |
| Causal self-attention | Weighs relevant earlier items | 1 or 2 heads in the original setup |
| Feed-forward network | Adds non-linear interactions | Two layers with ReLU |
| Block stack | Builds deeper sequence features | 2 blocks in the original setup |
| Maximum length | Limits the history considered | 50 for sparse data, 200 for dense data |
Training objective and negative sampling
SASRec is trained with next-item prediction at every position of the sequence, which yields many training signals from a single user history. The original paper uses a binary cross-entropy loss in which each true next item is contrasted with one randomly sampled negative item the user has not interacted with.
This choice is cheap, but later research has shown that it produces overconfident scores and leaves accuracy on the table. Replacing it with a full softmax cross-entropy over the catalog, or with many sampled negatives and a calibrated loss, often improves SASRec substantially. Several studies found that a properly trained SASRec matches or exceeds BERT4Rec, which changed how older benchmark comparisons are read.
| Objective | Negatives per positive | Cost | Typical outcome |
|---|---|---|---|
| Binary cross-entropy | 1 sampled | Very low | Original baseline, overconfident scores |
| Sampled softmax | Hundreds to thousands | Moderate | Clearly better ranking quality |
| Full softmax | Entire catalog | High for large catalogs | Usually the strongest results |
| Calibrated sampled loss | Tens to hundreds | Moderate | Close to full softmax at lower cost |
SASRec compared with other sequential recommenders
SASRec belongs to the family of sequential recommendation models, which use the order of interactions rather than an unordered user-item matrix. Its position in that family is best understood against its predecessors and successors.
| Model | Sequence encoder | Direction | Main difference from SASRec |
|---|---|---|---|
| GRU4Rec | Recurrent network | Left to right | Processes items one step at a time, slower to train |
| Caser | Convolutional filters | Recent window | Captures short local patterns only |
| SASRec | Causal self-attention | Left to right | Reference model |
| BERT4Rec | Bidirectional self-attention | Both directions | Trained by masked item prediction |
| Generative recommenders | Large Transformers or LLMs | Left to right | Predict semantic item IDs or text |
Compared with matrix factorization, SASRec captures short-term intent and transitions between items, such as buying a phone case after a phone. Compared with recurrent models, attention can jump directly to any earlier item, so a relevant purchase from twenty steps ago is not diluted by intermediate clicks.
Using SASRec in a production ranking stack
In practice, SASRec is most often used as a candidate generation model in multi-stage ranking. The final sequence representation acts as a user vector, and an approximate nearest-neighbor index over item embeddings retrieves a few hundred candidates in milliseconds for a heavier ranking model to reorder.
- Short, dense sessions in e-commerce and streaming suit SASRec well, because recent behavior predicts the next action.
- Side information such as category, price or time gaps can be added as extra embeddings summed with the item embedding.
- Real-time recommendation is possible because the model only needs the latest interactions to update the user vector.
- Evaluation should use full ranking over the catalog with metrics such as NDCG@10 and Recall@10, not only 100 sampled negatives, which can distort model comparisons.
Operational quality depends heavily on data preparation: deduplicating repeated events, choosing a sensible maximum length, and splitting data by time rather than at random to avoid leakage from future interactions.
Limitations and common pitfalls
SASRec has well-known limitations that practitioners must plan for. It relies on item IDs, so new items with no interactions have no useful embedding, which is the classic cold start problem. Attention cost grows with the square of the sequence length, which limits very long histories.
| Symptom | Likely cause | Common fix |
|---|---|---|
| Weak results versus newer models | One-negative binary loss | Train with sampled or full softmax |
| Poor scores for new items | No interaction history | Add content features to embeddings |
| Overfitting on small datasets | Too many layers or dimensions | Increase dropout, reduce model size |
| Optimistic offline metrics | Sampled evaluation or random splits | Use full ranking and temporal splits |
| Popular items dominate | Popularity bias in training data | Reweight or rerank for diversity |
Finally, SASRec optimizes next-click accuracy, not long-term satisfaction. Without beyond-accuracy metrics and diversity controls, it can reinforce a recommendation feedback loop that narrows what users see.
Put simply
SASRec looks at the list of things a person has recently watched, bought or clicked, in the order they happened, and guesses what they will want next. It focuses on the past items that best explain the next choice. Those items may be recent or much older.
Think of a shop assistant who remembers everything a customer picked up today. A tent, then a sleeping bag, usually leads to a camping stove. The order of actions is the main clue, and SASRec is a fast, reliable way for software to read it.
In practice
An online bookstore with about 400,000 titles wants better suggestions on its home page. Its older system recommends books bought by similar customers, but it ignores what a visitor did in the current week. The team trains SASRec on purchase and browsing sequences, keeping the last 50 interactions per user and using a sampled softmax loss with several hundred negatives.
SASRec runs as the candidate generator: each visit produces a user vector, and a nearest-neighbor search returns 300 candidate books for the existing ranking model. In an offline test with a temporal split, Recall@10 improves clearly over the previous approach. A two-week online test then shows more clicks on home page recommendations, especially for readers following a series or a single author, where the order of past purchases carries the strongest signal.