/Torch-GRU4Rec

PyTorch implementation GRU4Rec model

Primary LanguagePython

Torch-GRU4REC

Requirements

  • PyTorch 1.3.1
  • Python 3.7
  • pandas 0.24.2
  • numpy 1.16.2
  • jupyter 4.4.0

Usage

Dataset

  • Download RecSys Challenge 2015 Dataset from HERE

  • Extract Data and locate to PATH_TO_ORIGINAL_DATA directory. Default ( /Data )

Data Preprocessing

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 in PATH_TO_PROCESSED_DATA directory. Default ( /Data/Cleaned )
  • for use only 1/N data before preprocessing change N parameter.

Training And Testing Using Jupyter Notebook

See ``Run_GRU4Rec.ipnyb` that contains:

  1. Loads Data

    • Load rsc15Train.csv , rsc15Valid.csv and create Dataset object
  2. 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)

  3. BPR-max, no embedding

    • train and evaluate the model with best parameters for BPR-max,no embedding
  4. BPR-max, constrained embedding

    • train and evaluate the model with best parameters for BPR-max, constrained embedding
  5. Cross-entropy

    • train and evaluate the model with best parameters for Log Softmax and Negative Likelihood Loss(Cross Entropy Loss)
  6. Testing

    • Load rsc15Test.csv and create test Dataset object
    • Load trained Model and testing