Behavior Sequence Transformer for E-commerce Recommendation in Alibaba

Qiwei Chen, Huan Zhao, Wei Li, Pipei Huang, Wenwu Ou

TL;DR

Researchers at Alibaba have adapted the Transformer architecture—originally designed for natural language processing—to revolutionize how e-commerce platforms recommend products. By treating a user’s click history as a "sentence" and using self-attention to capture sequential dependencies, their Behavior Sequence Transformer (BST) achieved a 7.57% increase in online click-through rates (CTR) on Taobao compared to traditional deep learning baselines.

What Problem Does This Paper Address?

Most industrial recommendation systems follow an "Embedding & MLP" paradigm: they turn raw features into vectors and feed them into a Multi-Layer Perceptron. While effective, these models often treat a user’s history as a "bag of items," ignoring the chronological order of behaviors.

In the real world, order matters. A user who buys a smartphone is likely to look for a phone case next, but the reverse is rarely true. Previous attempts to solve this, like Alibaba’s own Deep Interest Network (DIN), used attention to match the "target item" against history, but they didn't fully capture the underlying "grammar" or sequential signals within the behavior sequence itself. BST aims to bridge this gap by modeling the complex dependencies between items in a user's journey.

Methods

The BST architecture is built on top of the Wide & Deep Learning (WDL) framework but replaces simple feature concatenation with a Transformer layer.

The architecture of the Behavior Sequence Transformer (BST) showing the flow from embeddings to the Transformer layer and final MLP.
  1. Embedding Layer: Features (User, Item, Context, and Cross-features) are embedded into low-dimensional vectors.
  2. Positional Encoding: Unlike the original Transformer paper which uses sine/cosine functions, BST uses a temporal position feature. The position of an item $v_i$ is calculated as the time difference between the current recommendation time and the time the user clicked that item: $pos(v_i) = t(v_{target}) - t(v_i)$.
  3. Transformer Layer: This is the "brain" of the model. It uses Multi-Head Self-Attention to allow each item in the sequence to "attend" to every other item. This helps the model learn a deeper representation of the user's intent. For example, it can learn that a click on a "charging cable" is highly dependent on a previous click on a "laptop."
  4. MLP & Output: The output of the Transformer is concatenated with other dense features and passed through three fully connected layers with LeakyReLU activations. A final Sigmoid layer predicts the probability of a click.

Datasets

The model was evaluated using a massive internal dataset from the Taobao App:

  • Scale: Approximately 298 million users, 12 million items, and a staggering 47.5 billion samples.
  • Structure: The authors used 7 days of logs for training and the following day for testing.
  • Features: Includes user profiles (age, city), item features (ID, category, shop), and context (display position, match type).

Key Insights and Ideas

  • Self-Attention vs. Target-Attention: While DIN focuses on how the current item relates to the past, BST focuses on how the past items relate to each other. This allows the model to extract a more robust "user state" before even considering the candidate item.
  • The "Simplicity" of Shopping: Interestingly, the authors found that stacking just one Transformer block ($b=1$) yielded the best results. They hypothesize that the "dependency" in shopping sequences is less complex than the syntactic structures found in human language, so deeper stacks lead to overfitting.
  • Time as Position: Using the actual time-delta as a positional feature is a clever adaptation for e-commerce. It captures the "decay" of interest—a click from five minutes ago is usually more relevant than one from five days ago.

Key Results

The BST was tested against standard Wide & Deep (WDL) and Deep Interest Network (DIN) models. As shown in the results table below, BST achieves superior performance across both offline and online metrics.

Performance comparison of BST against baselines, highlighting offline AUC and online CTR gains.
  • Offline Performance: BST achieved an AUC (Area Under Curve) of 0.7894, outperforming WDL (0.7734) and DIN (0.7866).
  • Online Impact: In live A/B testing on Taobao, BST delivered a +7.57% CTR gain over the WDL baseline.
  • Latency: Despite the complexity of the Transformer, the average response time (RT) was only 20ms, compared to 13ms for WDL. This demonstrates that the model is efficient enough for massive-scale real-time production.

Limitations and Future Work

  • Sequence Length: The paper uses a fixed sequence length of 20. In many e-commerce scenarios, users have much longer histories that might contain even richer signals if modeled efficiently.
  • Model Depth: While $b=1$ was optimal here, the authors suggest that with more data or different feature engineering, exploring deeper architectures remains a future possibility.
  • Feature Interaction: The current model relies on a standard MLP for final feature interaction; future iterations might explore more sophisticated ways to combine the Transformer's sequence output with static user/item features.

Summary updated

BibTeX
@misc{chen2019behavior,
  author = {Qiwei Chen and Huan Zhao and Wei Li and Pipei Huang and Wenwu Ou},
  title = {{Behavior Sequence Transformer for E-commerce Recommendation in Alibaba}},
  year = {2019},
  eprint = {1905.06874},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1905.06874},
}
Figure