Jointly Modeling Intra- and Inter-transaction Dependencies with Hierarchical Attentive Transaction Embeddings for Next-item Recommendation

Shoujin Wang, Longbing Cao, Liang Hu, Shlomo Berkovsky, Xiaoshui Huang, Lin Xiao, Wenpeng Lu · DOI

Abstract

A transaction-based recommender system (TBRS) aims to predict the next item by modeling dependencies in transactional data. Generally, two kinds of dependencies considered are intra-transaction dependency and inter-transaction dependency. Most existing TBRSs recommend next item by only modeling the intra-transaction dependency within the current transaction while ignoring inter-transaction dependency with recent transactions that may also affect the next item. However, as not all recent transactions are relevant to the current and next items, the relevant ones should be identified and prioritized. In this paper, we propose a novel hierarchical attentive transaction embedding (HATE) model to tackle these issues. Specifically, a two-level attention mechanism integrates both item embedding and transaction embedding to build an attentive context representation that incorporates both intra- and inter-transaction dependencies. With the learned context representation, HATE then recommends the next item. Experimental evaluations on two real-world transaction datasets show that HATE significantly outperforms the state-of-the-art methods in terms of recommendation accuracy.

Introduction

Predicting what a customer will buy next requires looking at both their current shopping basket and their recent past baskets. Transaction-based recommender systems (TBRSs) aim to predict the next item a user will add to their cart. To do this well, a model needs to understand two types of dependencies:

  1. Intra-transaction dependency: How items within the current basket relate to each other (e.g., buying bread makes you more likely to buy milk).
  2. Inter-transaction dependency: How past baskets influence the current one (e.g., buying a coffee maker last week influences buying coffee filters today).

Historically, models like Markov Chains or Recurrent Neural Networks (RNNs) have been used for this task. However, they suffer from a major flaw: they assume a strict, rigid order of events. In reality, the order in which items are placed in a grocery cart is mostly arbitrary. Furthermore, existing models often treat all past transactions as equally important, failing to recognize that a basket from a month ago might be highly relevant to today's purchase, while yesterday's quick snack run is just noise.

Methodology: The HATE Model

To solve these issues, the authors propose HATE (Hierarchical Attentive Transaction Embedding), a "shallow and wide" neural network designed to efficiently learn context representations without assuming a rigid sequence.

The HATE model architecture featuring two-level attention for intra- and inter-transaction dependencies.

The architecture relies on a two-level attention mechanism:

  • Intra-transaction Attention: First, the model creates embeddings for individual items. It then uses an attention layer to learn which items in the current basket are actually relevant to the target item, assigning them higher weights and filtering out unrelated items.
  • Inter-transaction Attention: Next, the model looks at recent historical baskets. Instead of treating them as a strict sequence, it uses a second attention layer to score how relevant each past transaction is to the current context and the next predicted item.

Finally, the model combines these intra- and inter-transaction embeddings into a single context representation. To keep training computationally efficient over massive item catalogs, the authors use Noise-Contrastive Estimation (NCE) rather than calculating a full softmax over all possible items.

Datasets and Evaluation

The model was evaluated on two real-world grocery store transaction datasets:

  • Dunnhumby: A well-known public dataset containing transaction records from roughly 2,500 households shopping at a retailer over two years.
  • ANS (Australian National Supermarket): A proprietary dataset containing one year of transaction records from about 1,000 customers at an Australian supermarket chain.

Key Insights

  • Rigid order is a flawed assumption: Treating shopping baskets as "sets" rather than strict "sequences" better reflects real-world consumer behavior. Relaxing the sequential order assumption prevents the model from over-indexing on the most recently scanned item.
  • Not all history is equal: The hierarchical attention mechanism proves that filtering out noisy past transactions is just as important as remembering relevant ones. A user's next choice is often driven by a specific past purchase rather than their entire aggregate history.
  • Shallow networks can be highly competitive: While deep RNNs (like the baseline GRU4Rec) are popular for sequential recommendation, HATE demonstrates that a shallow, wide network equipped with smart attention mechanisms can be both more accurate and highly efficient for transaction data.

Experimental Results

HATE outperformed several state-of-the-art baselines (including pattern-based models, Markov Chains, and RNN-based models like GRU4Rec and SHAN) across both datasets. Specifically, HATE beat the best-performing baseline (SHAN) by an average of 4.64% on the Dunnhumby dataset and 6.24% on the ANS dataset (measured via REC@10, REC@50, and Mean Reciprocal Rank).

Performance comparison of HATE against baseline models on the Dunnhumby dataset.

Ablation studies tested stripped-down versions of the model (removing either the inter-transaction context or the attention mechanism). The full HATE model achieved at least a 10% accuracy improvement over these ablated versions, proving that both the historical context and the attention weights are critical to its success.

Conclusion and Future Work

While highly effective for grocery data, the model's current design is tailored to transactional shopping contexts. The authors suggest exploring HATE's architecture for other domains where data is grouped in sets or sessions, such as document analysis and multimedia recommendations. Future work will look into modeling even more complex, non-linear couplings and interactions between items and transactions beyond simple co-occurrence and attention weights.

Summary updated

BibTeX
@article{wang2021jointly,
  author = {Shoujin Wang and Longbing Cao and Liang Hu and Shlomo Berkovsky and Xiaoshui Huang and Lin Xiao and Wenpeng Lu},
  title = {{Jointly Modeling Intra- and Inter-transaction Dependencies with Hierarchical Attentive Transaction Embeddings for Next-item Recommendation}},
  journal = {IEEE Intell. Syst.},
  year = {2021},
  doi = {10.1109/mis.2020.2997362},
}
Figure