- PyTorch implementation of the algorithm of Session-based Recommendations with Recurrent Neural Networks(ICLR 2016). With the extensions introduced in Recurrent Neural Networks with Top-k Gains for Session-based Recommendations(CIKM 2018)
- This code is based on pyGRU4REC and original Theano code written by the authors of the GRU4REC paper
- This Version supports TOP1, BPR, TOP1-max, BPR-max, Negative Sampling, Cross-Entropy Losses and other parameters of original Theano code.
- Model achieves the same performance reported in original Theano code example for the Recsys Challenge 2015 (RSC15) dataset.
- PyTorch 1.3.1
- Python 3.7
- pandas 0.24.2
- numpy 1.16.2
- jupyter 4.4.0
-
Download RecSys Challenge 2015 Dataset from HERE
-
Extract Data and locate to
PATH_TO_ORIGINAL_DATAdirectory. Default( /Data )
For data preprocessing and data cleaning run Preprocessing.py or see Data Preprocessing section in Run_GRU4Rec.ipynb.
- The training set (
yoochoose-clicks.dat) itself is divided into training, validation and testing sets where the testing is the last day sessions. - After preprocessing,
rsc15Train.csv,rsc15Valid.csv,rsc15Test.csvobtain that stores inPATH_TO_PROCESSED_DATAdirectory. Default( /Data/Cleaned ) - for use only 1/N data before preprocessing change N parameter.
See ``Run_GRU4Rec.ipnyb` that contains:
-
Loads Data
- Load
rsc15Train.csv,rsc15Valid.csvand create Dataset object
- Load
-
Model Parameters
-
Set model parameters. in this section parameters set to default like original Theano code.
-
The following list of parameters
-
inputSizeGRU Input Size = Number of Items In Dataset
outputSizeGRU output Size = Number of Items In Dataset
hiddenSizeNumber of Neurons per GRU Layers (Default = 100)
nLayersNumber of GRU Layers (Default = 1)
batchSizeMini Batch Size (Default = 32)
negativeUse Negative Sampling In Training Process Or Not (Default = True)
embeddingDimSize Of The Embedding Used,embeddingDim <= 0Means Not To Use Embedding (Default = -1)
dropoutHiddenDropout at each hidden layer (Default = 0.0)
dropoutEmbedDropout Of The Input Units, Applicable Only If Embeddings Are Used (Default: 0.0)sigma"Width" Of Initialization. Either The standard Deviation Or The Min/Max Of The Initializations Interval (With Normal And Uniform Initializations Respectively). 0 Means Adaptive Normalization (Sigma Depends On The Size Of The Weight Matrix) (Default: 0.0)
initAsNormalFalse: Initializations From Uniform Distribution On [-sigma,sigma]. True: Initializations From Normal Distribution On (0,sigma). (default: False)
cudaUse GPU Or Not
finalActActivation Function (Default = Elu-1.0)
lossTypeType of loss function TOP1 / BPR / TOP1-max / BPR-max / Cross-Entropy/ NLL (Default: BPR-max)
optimizerTypeOptimizer (Default = Adagrad)
lrLearning rate (Default = 0.1).
weightDecayWeight decay (Default = 0.0)
momentumMomentum Value (Default = 0.0)
bpregScore Regularization Coefficient For The BPR-max Loss Function (Default: 1.0)
nEpochsNumber of epochs (Default = 10)
timeSortWhether To Ensure The Order Of Sessions Is Chronological (Default: True)
trainRandomOrderWhether To Randomize The Order Of Sessions In Each Epoch (Default: False)
sampleAlphaThe Probability Of An Item Used As An Additional Negative Sample (Default: 0.75)trainNSampleNumber Of Additional Negative Samples To Be Used In Training Mini Batch Generator (Default: 2048)validNSampleNumber Of Additional Negative Samples To Be Used In Validation Mini Batch Generator (Default: 2048)sampleStoreNumber Of by Precomputing Batch Of Negative Samples (Default: 10000000)topNValue of K used durig Recall@K and MRR@K Evaluation (Default = 20)
-
-
BPR-max, no embedding
- train and evaluate the model with best parameters for BPR-max,no embedding
-
BPR-max, constrained embedding
- train and evaluate the model with best parameters for BPR-max, constrained embedding
-
Cross-entropy
- train and evaluate the model with best parameters for Log Softmax and Negative Likelihood Loss(Cross Entropy Loss)
-
Testing
- Load
rsc15Test.csvand create test Dataset object - Load trained Model and testing
- Load