Skip to content
/ KBRD Public

Towards Knowledge-Based Recommender Dialog System @ EMNLP 2019


Notifications You must be signed in to change notification settings


Repository files navigation

GitHub stars GitHub license

Paper accepted at EMNLP-IJCNLP 2019. Latest version at arXiv.

  • New: code and README are improved.
  • We curated a paper list for NLP + Recommender System at THUDM/NLP4Rec-Papers. Contributions are welcome.


  • Linux
  • Python 3.6
  • PyTorch >= 1.2.0

Getting Started


Clone this repo.

git clone

Please install dependencies by

pip install -r requirements.txt


  • We use the ReDial dataset, which will be automatically downloaded by the script.
  • Download the refined knowledge base (dbpedia) used in this paper [Google Drive]. Decompress it and get the <path/to/KBRD/dbpedia/> folder, which should contain two files mappingbased_objects_en.ttl and short_abstracts_en.ttl.
  • Download the proprocessed extracted entities set [Google Drive] and put it under <path/to/KBRD/data/redial/.


  1. To train the recommender part, run:
bash scripts/ <num_exps> <gpu_id>
(optional) bash scripts/ <num_exps> <gpu_id>
  1. To train the dialog part, run:
bash scripts/ <num_exps> <gpu_id>

The test results are displayed at the end of training and can also be found at saved/<model_name>.test.


Training outputs, TensorBoard logs and models files are be saved in saved/ folder.


  1. scripts/ is used to hypothesis testing the significance of improvement between different models. To use, first run multiple experiments with num_exps > 1, for example:
bash scripts/ 2 <gpu_id>
bash scripts/ 2 <gpu_id>


python scripts/ --name-1 saved/release_baseline --name-2 saved/both_rgcn --num 2 --metric recall@50

where you should remove the trailing _0, _1 automatically added to the model names, nums should be set the same as num_exps above, and recall@50 can be replaced with other evaluation metrics in the paper.

Sample output:

[0.298, 0.2918]
[0.3417, 0.3369]
Ttest_indResult(statistic=-11.325204070341204, pvalue=0.007706635327863829)
  1. scripts/ is used to generate responses.
python scripts/ -t redial -mf saved/transformer_rec_both_rgcn_0 -dt test

Example output ([TorchAgent] is our model output):

[eval_labels_choice]: Oh, you like scary movies?
I recently watched __unk__
What kind of movies do you like?
I am looking for a movie recommendation.   When I was younger I really enjoyed the __unk__
[label_candidates: 3|37993|50395||Oh, you like scary movies?
I recently watched __unk__]
[eval_labels: Oh, you like scary movies?
I recently watched __unk__]
   [TorchAgent]: have you seen "The Shining  (1980)" ?
  1. scripts/ is used to show the vocabulary bias of a specific movie (like the qualitative analysis in Table 4)
python scripts/ -mf saved/transformer_rec_both_rgcn_0

❗ Common Q&A

  1. Understanding model outputs. Please see #15 (comment).

  2. Adapting this code to other datasets. It is not straightforward for this code to be run on other datasets currently. The main reason is that we cached the entity linking process in KBRD for ReDial. Please see #10 (comment) for details.

  3. Why the recommender and the dialog part are trained separatedly? Please refer to #9 (comment) for detailed explanation.

If you have additional questions, please let us know.


Please cite our paper if you use this code in your own work:

  title={Towards Knowledge-Based Recommender Dialog System},
  author={Chen, Qibin and Lin, Junyang and Zhang, Yichang and Ding, Ming and Cen, Yukuo and Yang, Hongxia and Tang, Jie},
  journal={arXiv preprint arXiv:1908.05391},