Code Monkey home page Code Monkey logo

dbrl's Introduction

DBRL

English   简体中文   blog post


DBRL is a toolkit used for training reinforcement learning recommendation models. The name DBRL stands for : Dataset Batch Reinforcement Learning, which differs from traditional reinforcement learning in that it only uses static dataset to train a model, without any further interaction with the environment. See Offline Reinforcement Learning: Tutorial, Review, and Perspectives on Open Problems for a comprehensive introduction.

After the training, the model can be used for online serving. And indeed It has an online part, which mainly leverages Flink and the trained model for online recommendation. See FlinkRL for more details. The full system architecture is as follows :

Algorithms

DBRL currently contains three algorithms:

Data

The dataset comes from a competition held by Tianchi, a Chinese competition platform. Please refer to the original website for full description. Note that here we only use the round2 data.

You can also download the data from Google Drive.

Usage

Dependencies: python>=3.6, numpy, pandas, torch>=1.3, tqdm.

$ git clone https://github.com/massquantity/DBRL.git

After downloading the data, unzip and put them into the DBRL/dbrl/resources folder. The original dataset consists of three tables: user.csv, item.csv, user_behavior.csv . We'll first need to filter some users with too few interactions and merge all features together, and this is accomplished by run_prepare_data.py. Then we'll pretrain embeddings for every user and item by running run_pretrain_embeddings.py :

$ cd DBRL/dbrl
$ python run_prepare_data.py
$ python run_pretrain_embeddings.py --lr 0.001 --n_epochs 4

You can tune the lr and n_epochs hyper-parameters to get better evaluate loss. Then we begin to train the model. Currently there are three algorithms in DBRL, so we can choose one of them:

$ python run_reinforce.py --n_epochs 5 --lr 1e-5
$ python run_ddpg.py --n_epochs 5 --lr 1e-5
$ python run_bcq.py --n_epochs 5 --lr 1e-5

At this point, the DBRL/resources should contains at least 6 files:

  • model_xxx.pt, the trained pytorch model.
  • tianchi.csv, the transformed dataset.
  • tianchi_user_embeddings.npy, the pretrained user embeddings in numpy npy format.
  • tianchi_item_embeddings.npy, the pretrained item embeddings in numpy npy format.
  • user_map.json, a json file that maps original user ids to ids used in the model.
  • item_map.json, a json file that maps original item ids to ids used in the model.

dbrl's People

Contributors

massquantity avatar

Watchers

James Cloos 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.