Giter Club home page Giter Club logo

bpr-1's Introduction

Bayesian Personalized Ranking from Implicit Feedback

The repository implement the Bayesian Personalized Ranking using pyTorch (https://arxiv.org/pdf/1205.2618)
Other repositories also implement this model, but the evaluation takes longer time.
So, I implement this model using pyTorch with GPU acceleration for evaluation.
Implementation detail will be explained in the following section.

Set up environment

You have to install the following package before executing this code.

  • python==3.6
  • pytorch==1.0.0
  • numpy==1.15.4
  • pandas==0.23.4

You can install these package by executing the following command or through anaconda.

pip install -r requirements.txt

Usage

0. Prepare data

This code support the movielens 1m data and movielens 20m data. You can get the dataset from the following list.

After downloading that file, unzip it.
We call the path for unzipped directory $data_dir.

1. Preprocess data

For basic usage, execute following command line to preprocess the data. It randomly split the whole dataset into two parts, training data and test data.

python preprocess.py --dataset ml-1m --data_dir $data_dir --output_data preprocess/ml-1m.pickle
python preprocess.py --dataset ml-20m --data_dir $data_dir --output_data preprocess/ml-20m.pickle

If you want to split training data and test data with time order, then execute the following command line. This code sorts the item list for each user using time order. After that, it splits the whole data into two parts, training data and test data. First 80% of the item list will become the training data and the last 20% of the item list will become test data.

python preprocess.py --dataset ml-1m --output_data preprocess/ml-1m.pickle --time_order
python preprocess.py --dataset ml-20m --output_data preprocess/ml-20m.pickle --time_order

Help message will give you more detail description for arguments.

python preprocess.py --help

2. Training MF model using BPR-OPT

Now, for real show, let's train MF model using BPR-OPT loss. You can execute the following command to train MF model using BPR-OPT.

python train.py --data preprocess/ml-1m.pickle
python train.py --data preprocess/ml-20m.pickle

Help message will give you more detail description for arguments. You can train MF model with different hyperparameter.

python train.py --help

Implementation detail

  • I didn't use regularization coefficient for each embedding matrix. If you want to tune each coefficient, then you need to add regularization term inside the loss value.

Result

The evaluation benchmark for movielens 1m is the following table. I think more tuning will get better result, but this value is reasonably around the statistic.

Dataset Preprocess P@1 P@5 P@10 R@1 R@5 R@10
Movielens-1m Random 0.2421 0.2058 0.1821 0.0096 0.0392 0.0674
Movielens-1m Time-order 0.1307 0.1133 0.1034 0.0052 0.0216 0.0388
Movielens-20m Random 0.2359 0.1790 0.1529 0.0118 0.0395 0.0652
Movielens-20m Time-order 0.1070 0.0887 0.0809 0.0059 0.0237 0.0431

More information will get from the result directory.

FAQ

Q. Loss doesn't decrease, why? A. I print the smoothing loss and the initial smoothing loss is 0, which cause this problem. Waiting just a moment, then loss will go down.

Q. Loss converge to 0.6931. A. Because weight decay is so strong that model cannot learn from dataset. Decrease the weight decay factor.

Contact

If you have any problem during simulating this code, open issue or contact me by sending email to [email protected]

bpr-1's People

Contributors

sh0416 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.