SASRec

Also known as: Self-attentive sequential recommendation

On this page 7

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.

ComponentRoleTypical setting
Item embeddingRepresents each item as a vector50 to 256 dimensions
Positional embeddingEncodes the order of interactionsLearned, one per position
Causal self-attentionWeighs relevant earlier items1 or 2 heads in the original setup
Feed-forward networkAdds non-linear interactionsTwo layers with ReLU
Block stackBuilds deeper sequence features2 blocks in the original setup
Maximum lengthLimits the history considered50 for sparse data, 200 for dense data
Main components of the SASRec architecture

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.

ObjectiveNegatives per positiveCostTypical outcome
Binary cross-entropy1 sampledVery lowOriginal baseline, overconfident scores
Sampled softmaxHundreds to thousandsModerateClearly better ranking quality
Full softmaxEntire catalogHigh for large catalogsUsually the strongest results
Calibrated sampled lossTens to hundredsModerateClose to full softmax at lower cost
Effect of the training objective on SASRec

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.

ModelSequence encoderDirectionMain difference from SASRec
GRU4RecRecurrent networkLeft to rightProcesses items one step at a time, slower to train
CaserConvolutional filtersRecent windowCaptures short local patterns only
SASRecCausal self-attentionLeft to rightReference model
BERT4RecBidirectional self-attentionBoth directionsTrained by masked item prediction
Generative recommendersLarge Transformers or LLMsLeft to rightPredict semantic item IDs or text
SASRec and related sequential recommendation models

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.

SymptomLikely causeCommon fix
Weak results versus newer modelsOne-negative binary lossTrain with sampled or full softmax
Poor scores for new itemsNo interaction historyAdd content features to embeddings
Overfitting on small datasetsToo many layers or dimensionsIncrease dropout, reduce model size
Optimistic offline metricsSampled evaluation or random splitsUse full ranking and temporal splits
Popular items dominatePopularity bias in training dataReweight or rerank for diversity
Typical SASRec problems and their fixes

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.