- 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_DATA
directory. 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.csv
obtain that stores inPATH_TO_PROCESSED_DATA
directory. 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.csv
and 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
-
inputSize
GRU Input Size = Number of Items In Dataset
outputSize
GRU output Size = Number of Items In Dataset
hiddenSize
Number of Neurons per GRU Layers (Default = 100)
nLayers
Number of GRU Layers (Default = 1)
batchSize
Mini Batch Size (Default = 32)
negative
Use Negative Sampling In Training Process Or Not (Default = True)
embeddingDim
Size Of The Embedding Used,embeddingDim <= 0
Means Not To Use Embedding (Default = -1)
dropoutHidden
Dropout at each hidden layer (Default = 0.0)
dropoutEmbed
Dropout 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)
initAsNormal
False: Initializations From Uniform Distribution On [-sigma,sigma]. True: Initializations From Normal Distribution On (0,sigma). (default: False)
cuda
Use GPU Or Not
finalAct
Activation Function (Default = Elu-1.0)
lossType
Type of loss function TOP1 / BPR / TOP1-max / BPR-max / Cross-Entropy/ NLL (Default: BPR-max)
optimizerType
Optimizer (Default = Adagrad)
lr
Learning rate (Default = 0.1).
weightDecay
Weight decay (Default = 0.0)
momentum
Momentum Value (Default = 0.0)
bpreg
Score Regularization Coefficient For The BPR-max Loss Function (Default: 1.0)
nEpochs
Number of epochs (Default = 10)
timeSort
Whether To Ensure The Order Of Sessions Is Chronological (Default: True)
trainRandomOrder
Whether To Randomize The Order Of Sessions In Each Epoch (Default: False)
sampleAlpha
The Probability Of An Item Used As An Additional Negative Sample (Default: 0.75)trainNSample
Number Of Additional Negative Samples To Be Used In Training Mini Batch Generator (Default: 2048)validNSample
Number Of Additional Negative Samples To Be Used In Validation Mini Batch Generator (Default: 2048)sampleStore
Number Of by Precomputing Batch Of Negative Samples (Default: 10000000)topN
Value 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.csv
and create test Dataset object - Load trained Model and testing
- Load