Awesome Open Source
Awesome Open Source


Paper data and code

This is the code for the AAAI 2019 Paper: Session-based Recommendation with Graph Neural Networks. We have implemented our methods in both Tensorflow and Pytorch.

Here are two datasets we used in our paper. After downloaded the datasets, you can put them in the folder datasets/:

There is a small dataset sample included in the folder datasets/, which can be used to test the correctness of the code.

We have also written a blog explaining the paper.


You need to run the file datasets/ first to preprocess the data.

For example: cd datasets; python --dataset=sample

usage: [-h] [--dataset DATASET]

optional arguments:
  -h, --help         show this help message and exit
  --dataset DATASET  dataset name: diginetica/yoochoose/sample

Then you can run the file pytorch_code/ or tensorflow_code/ to train the model.

For example: cd pytorch_code; python --dataset=sample

You can add the suffix --nonhybrid to use the global preference of a session graph to recommend instead of the hybrid preference.

You can also change other parameters according to the usage:

usage: [-h] [--dataset DATASET] [--batchSize BATCHSIZE]
               [--hiddenSize HIDDENSIZE] [--epoch EPOCH] [--lr LR]
               [--lr_dc LR_DC] [--lr_dc_step LR_DC_STEP] [--l2 L2]
               [--step STEP] [--patience PATIENCE] [--nonhybrid]
               [--validation] [--valid_portion VALID_PORTION]

optional arguments:
  -h, --help            show this help message and exit
  --dataset DATASET     dataset name:
  --batchSize BATCHSIZE
                        input batch size
  --hiddenSize HIDDENSIZE
                        hidden state size
  --epoch EPOCH         the number of epochs to train for
  --lr LR               learning rate
  --lr_dc LR_DC         learning rate decay rate
  --lr_dc_step LR_DC_STEP
                        the number of epochs after which the learning rate
  --l2 L2               l2 penalty
  --step STEP           gnn propogation steps
  --patience PATIENCE   the number of epoch to wait before early stop
  --nonhybrid           only use the global preference to predict
  --validation          validation
  --valid_portion VALID_PORTION
                        split the portion of training set as validation set


  • Python 3
  • PyTorch 0.4.0 or Tensorflow 1.9.0

Other Implementation for Reference

There are other implementation available for reference:

  • Implementation based on PaddlePaddle by Baidu [Link]
  • Implementation based on PyTorch Geometric [Link]
  • Another implementation based on Tensorflow [Link]
  • Yet another implementation based on Tensorflow [Link]


Please cite our paper if you use the code:

title = {{Session-based Recommendation with Graph Neural Networks}},
author = {Wu, Shu and Tang, Yuyuan and Zhu, Yanqiao and Wang, Liang and Xie, Xing and Tan, Tieniu},
year = 2019,
booktitle = {Proceedings of the Twenty-Third AAAI Conference on Artificial Intelligence},
location = {Honolulu, HI, USA},
month = jul,
volume = 33,
number = 1,
series = {AAAI '19},
pages = {346--353},
url = {},
doi = {10.1609/aaai.v33i01.3301346},
editor = {Pascal Van Hentenryck and Zhi-Hua Zhou},

Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Python (808,235
Machine Learning (37,158
Dataset (33,055
Graph (24,364
Tensorflow (22,352
Paper (18,801
Session (14,245
Recommendation (5,046
Recommender System (2,473
Graph Neural Networks (726
Session Based Recommendation (5