Giter Site home page Giter Site logo

geohyeon / pfoodreq Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hugochan/pfoodreq

0.0 0.0 0.0 1.49 MB

Code & data accompanying the WSDM 2021 paper "Personalized Food Recommendation as Constrained Question Answering over a Large-scale Food Knowledge Graph"

License: Apache License 2.0

Python 100.00%

pfoodreq's Introduction

PFoodReq

Code & data accompanying the WSDM 2021 paper "Personalized Food Recommendation as Constrained Question Answering over a Large-scale Food Knowledge Graph".

Architecture

PFoodReq architecture.

Prerequisites

This code is written in python 3. You will need to install a few python packages in order to run the code. We recommend you to use virtualenv to manage your python packages and environments. Please take the following steps to create a python virtual environment.

  • If you have not installed virtualenv, install it with pip install virtualenv.
  • Create a virtual environment with virtualenv venv.
  • Activate the virtual environment with source venv/bin/activate.
  • Install the package requirements with pip install -r requirements.txt.

You will need to download the partial FoodKG used in our experiments from here and move the recipe_kg folder to the data folder in this repo.

Create a KBQA dataset

  • Go to data_builder/src folder, run the following cmd:

     python generate_all_qa.py -recipe ../../data/recipe_kg/recipe_kg.json -o ../../data/kbqa_data/ -out_of_domain_ratio 0.1 -split_ratio 0.6 0.2
    

You can also download our generated benchmark from here and move the kbqa_data folder to the data folder in this repo. In the downloaded kbqa_data folder, you will also see additional files used in the KBQA+RecipeSim setting.

Run a KBQA system

Preprocess the data

  • Download the pretrained Glove word ebeddings glove.840B.300d.zip and move it to the data folder in this repo.

  • Go to the BAMnet/src folder

  • Preprocess data

    • Vectorize data
     python build_all_data.py -data_dir ../../data/kbqa_data/ -kb_path ../../data/recipe_kg/recipe_kg.json -out_dir ../data/kbqa
    

    In the message printed out, your will see some data statistics such as vocab_size, num_ent_types, and num_relations. These numbers will be used later when modifying the config file.

    • Fetch the pretrained Glove vectors for our vocabulary.

      python build_pretrained_w2v.py -emb ../../data/glove.840B.300d.txt -data_dir ../data/kbqa/ -out ../data/kbqa/glove_pretrained_300d_w2v.npy
      
  • Preprocess data w/o kg augmentation

    • Vectorize data
     python build_all_data.py -data_dir ../../data/kbqa_data/ -kb_path ../../data/recipe_kg/recipe_kg.json -out_dir ../data/kbqa_no_ka  --no_kg_augmentation
    
    • Fetch the pretrained Glove vectors for our vocabulary.
    	 python build_pretrained_w2v.py -emb ../../data/glove.840B.300d.txt -data_dir ../data/kbqa_no_ka/ -out ../data/kbqa_no_ka/glove_pretrained_300d_w2v.npy
    
  • Preprocess data w/o query expansion

    • Vectorize data
    python build_all_data.py -data_dir ../../data/kbqa_data/ -kb_path ../../data/recipe_kg/recipe_kg.json -out_dir ../data/kbqa_no_qe --no_query_expansion
    
    • Fetch the pretrained Glove vectors for our vocabulary.
    python build_pretrained_w2v.py -emb ../../data/glove.840B.300d.txt -data_dir ../data/kbqa_no_qe/ -out ../data/kbqa_no_qe/glove_pretrained_300d_w2v.npy
    
  • Preprocess data w/o query expansion & kg augmentation

    • Vectorize data
     python build_all_data.py -data_dir ../../data/kbqa_data/ -kb_path ../../data/recipe_kg/recipe_kg.json -out_dir ../data/kbqa_no_qe_ka --no_query_expansion --no_kg_augmentation
    
    • Fetch the pretrained Glove vectors for our vocabulary.
    python build_pretrained_w2v.py -emb ../../data/glove.840B.300d.txt -data_dir ../data/kbqa_no_qe_ka/ -out ../data/kbqa_no_qe_ka/glove_pretrained_300d_w2v.npy
    

Tran/test a KBQA system

  • Modify the config file BAMnet/src/config/kbqa.yml to suit your needs. Note that you can start with modifying only the data folder and vocab size (e.g., data_dir, kb_path, pre_word2vec, vocab_size, num_ent_types, and num_relations), and leave other variables as they are.

  • Train the KBQA model.

     python train.py -config config/pfoodreq.yml
    
  • Test the KBQA model:

     python run_online.py -config config/pfoodreq.yml
    
  • Train the KBQA+RecipeSim model.

    python train.py -config config/pfoodreq_similar_recipes.yml
    
  • Test the KBQA+RecipeSim model:

    python run_online.py -config config/pfoodreq_similar_recipes.yml
    

Reference

If you found this code useful, please consider citing the following paper:

Yu Chen, Ananya Subburathinam, Ching-Hua Chen and Mohammed J. Zaki. "Personalized Food Recommendation as Constrained Question Answering over a Large-scale Food Knowledge Graph." In Proceedings of the 14th International Conference on Web Search and Data Mining (WSDM 2021), Mar. 8-12, 2021.

@inproceedings{chen2021personalized,
author    = {Chen, Yu and Subburathinam, Ananya and Chen, Ching-Hua and Zaki, Mohammed J.},
title     = {Personalized Food Recommendation as Constrained Question Answering over a Large-scale Food Knowledge Graph},
booktitle = {Proceedings of the 14th International Conference on Web Search and Data Mining},
month = {Mar. 8-12,},
year      = {2021}}

Note that we use the BAMnet model as our KBQA system in this application. For more details about the BAMnet model, please refer to the original paper. For more details about the FoodKG, please refer to the original paper.

pfoodreq's People

Contributors

hugochan 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.