Need help with joint-kg-recommender?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

TaoMiner
155 Stars 42 Forks 2 Commits 4 Opened issues

Services available

!
?

Need anything else?

Contributors list

Unifying Knowledge Graph Learning and Recommendation Towards a Better Understanding of User Preference

This is the code of the Unifying Knowledge Graph Learning and Recommendation Towards a Better Understanding of User Preference in WWW'19, which proposed a model that jointly train two tasks of item recommendation and KG representation learning.

Environment

python 3.6

Pytorch 0.3.x

visdom if visualization flag is set to True.

some required packages are included in requirements.txt.

Run our codes

We implement the models including our proposed TUP and KTUP as well as some baselines: BPRMF, FM, CFKG, CKE, CoFM, TransE, TransH and TransR. We split them into three types: Item recommendation, knowledge representation and the joint model of two tasks, which correspond to runitemrecommendation.py, runknowledgerepresentation.py and runknowledgablerecommendation.py, respectively. Each model has an example shell file to run the code.

Take item recommendation for example, to run each model, simply:

python run_item_recommendation.py -model_type REC_MODEL -dataset DATASET_NAME -data_path PATH_TO_DATASET_FOLDER -log_path PATH_TO_LOG -rec_test_files EVAL_FILENAMES -nohas_visualization

For knowledge representation, simply:

python run_knowledge_representation.py -model_type KG_MODEL -dataset DATASET_NAME -data_path PATH_TO_DATASET_FOLDER -log_path PATH_TO_LOG -kg_test_files EVAL_FILENAMES -nohas_visualization

For joint model, simplY:

python run_knowledgable_recommendation.py -model_type JOINT_MODEL -dataset DATASET_NAME -data_path PATH_TO_DATASET_FOLDER -log_path PATH_TO_LOG -rec_test_files REC_EVAL_FILENAMES -kg_test_files KG_EVAL_FILENAMES -nohas_visualization

we now describe the main flags: datasets, models and visualization:

Datasets

We use two datasets: movielens-1m (ml1m for short) and dbbook2014. We collect the related facts from DBPedia, where the triplets are directly related to the entities with mapped items, no matter which role (i.e. subject or object) the entity serves as. The processed datasets can be download here, and the original data is limited to their authority.

The flag '-data_path' is used to specify the root path to dataset.

The flag '-dataset' is used to specify the dataset, 'ml1m' for movielens-1m, 'dbbook2014' for dbbook2014, and any dataset folder names under the data path.

Thus, all dataset related files shall be put into the folder '/PATHTODATASETFOLDER/DATASETNAME/'.

Now, we detail the required files.

For item recommendation, the folder should contain the following files: train.dat, u_map.dat, i_map.dat, where each line in train.data is a triple: 'userid itemid rating' that separated by '\t', umap and imap specify the mapped userid to original userid. The evaluation files would be specified by flag '-rectestfiles', where multiple eval files separated by ':'. Note that the first eval file is used for validation.

For KG representation, the files should under the path: '/PATHTODATASETFOLDER/DATASETNAME/kg/'. The required files contain: train.dat, e_map.dat and r_map.dat. Similarly, each line in train.dat is a triple: 'headentityid tailentityid relationid' separated by '\t', emap and rmap specify the mapped entityid to original entity. The evaluation files would be specified by flag '-kgtestfiles', where multiple eval files separated by ':'. Note that the first eval file is used for validation.

The joint model requires all of the above files and i2kg_map.tsv, where each line consist of original item id, entity title, and original entity uri separated by tab.

For example, we run our KTUP by:

python run_knowledgable_recommendation.py -model_type jtransup -dataset ml1m -data_path ~/joint-kg-recommender/datasets/ -log_path ~/Github/joint-kg-recommender/log/ -rec_test_files valid.dat:test.dat -kg_test_files valid.dat:test.dat -nohas_visualization

Then, we need a folder '~/joint-kg-recommender/datasets/ml1m/' including the required files as:

ml1m
│   train.dat
│   valid.dat
│   test.dat
│   u_map.dat
│   i_map.dat
│   i2kg_map.tsv 
│
└───kg
│   │   train.dat
│   │   valid.dat
│   │   test.dat
│   │   e_map.dat
│   │   r_map.dat

Models

We use the flag '-model_type' to specify the model used, which has to be chosen from the following models: ['bpr','fm','trasne','transh','transr','cfkg','cke','cofm','transup','jtransup'].

Specifically, ['bpr','fm','transup'] is for item recommendation. 'transup' is our proposed TUP. ['trasne','trasnh','trasnr'] is for kg representation. ['cfkg','cke','cofm','jtransup'] is for item recommendation. 'jtransup' is our proposed KTUP.

Model Specific Flags

For TUP, there are two specific flags: '-numpreferences' and '-usest_gumbel', which denotes the number of user preferences and if we use hard strategy for preference induction, respectively.

For joint models, there are also two flags: '-jointratio' and '-shareembeddings', which denote the ratio of training data in each batch between item recommendation and KG representation, and if the two tasks share embeddings of aligned items and entities. Note that for model 'cfkg', it must be '-shareembeddings' due to the its basic idea of unified graph of items and entities. For models 'cke' and 'jtransup' (KTUP), it must be '-noshareembeddings'.

General Flags

We can also specify the general parameters by setting flags like optimizer or learning rate, which can be found in './models/base.py'.

Visualization

We use the package of visdom for visualization. If you decide to visualize the training and evaluation curve, the visdom environment is required (python -m visdom.server) and set '-hasvisualization', and even the port '-visualizationport 8097'. Then, one can moniter the training and evaluation curves using the brower by entering : "http://host_ip:8097".

Reference

If you use our code, please cite our paper:

@inproceedings{cao2018unifying,
  title={Unifying Knowledge Graph Learning and Recommendation: Towards a Better Understanding of User Preference},
  author={Cao, Yixin and Wang, Xiang and He, Xiangnan and Hu, Zikun and Chua Tat-seng},
  booktitle={WWW},
  year={2019}
}

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.