Code Monkey home page Code Monkey logo

rl-based-graph2seq-for-nqg's Introduction

RL-based-Graph2Seq-for-NQG

Code & data accompanying the ICLR 2020 paper "Reinforcement Learning Based Graph-to-Sequence Model for Natural Question Generation".

Get started

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.

Run the model

  • Download the preprocessed data from squad-split1 and squad-split2. And put the data under the root directory. So the file hierarchy will be like: data/squad-split1 and data/squad-split2.

  • Run the model

    python main.py -config config/squad_split1/graph2seq_static_bert_finetune_word_70k_0.4_bs_60.yml
    

    Note that you can specify the output path by modifying out_dir in a config file. If you want to finetune a pretrained model, you can specify the path to the pretrained model by modifying pretrained and you need to set out_dir to null. If you just want to load a pretrained model and evaluate it on a test set, you need to set both trainset and devset to null.

  • Finetune the model using RL

    python main.py -config config/squad_split1/rl_graph2seq_static_bert_finetune_word_70k_0.4_bs_60.yml
    

Reference

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

Yu Chen, Lingfei Wu and Mohammed J. Zaki. "Reinforcement Learning Based Graph-to-Sequence Model for Natural Question Generation." In Proceedings of the 8th International Conference on Learning Representations (ICLR 2020), Addis Ababa, Ethiopia, Apr. 26-30, 2020.

@inproceedings{chen2019reinforcement,
author    = {Chen, Yu and Wu, Lingfei and Zaki, Mohammed J.},
title     = {Reinforcement Learning Based Graph-to-Sequence Model for Natural Question Generation},
booktitle = {Proceedings of the 8th International Conference on Learning Representations},
month = {Apr. 26-30,},
year      = {2020}}

rl-based-graph2seq-for-nqg's People

Contributors

hugochan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rl-based-graph2seq-for-nqg's Issues

Question: which input fields are actually required for the model?

I am sending an example.

I trained a model. I would like to try it on my own data. Could you please clarify which fields are actually required for the model? It might be possible that I don't need to provide all of them while shaping my own data as per the format below.

{
  "text3": "Twins",
  "text1": "twins -lrb- 1988 -rrb- , a comedy with danny devito , also proved successful .",
  "text2": "What's the title of the comedy movie Schwarzenegger starred in with Danny DeVito in 1988?",
  "annotation3": {
    "raw_text": "Twins",
    "toks": "Twins",
    "POSs": "NNS",
    "positions": "0-0-5",
    "NERs": "O"
  },
  "id": "56de8c374396321400ee2a11",
  "annotation2": {
    "raw_text": "What's the title of the comedy movie Schwarzenegger starred in with Danny DeVito in 1988?",
    "toks": "What 's the title of the comedy movie Schwarzenegger starred in with Danny DeVito in 1988 ?",
    "POSs": "WP VBZ DT NN IN DT NN NN NNP VBD IN IN NNP NNP IN CD .",
    "positions": "0-0-4 1-4-6 2-7-10 3-11-16 4-17-19 5-20-23 6-24-30 7-31-36 8-37-51 9-52-59 10-60-62 11-63-67 12-68-73 13-74-80 14-81-83 15-84-88 16-88-89",
    "NERs": "O O O O O O O O PERSON O O O PERSON PERSON O DATE O"
  },
  "annotation1": {
    "raw_text": "twins -lrb- 1988 -rrb- , a comedy with danny devito , also proved successful .",
    "toks": "twins -lrb- 1988 -rrb- , a comedy with danny devito , also proved successful .",
    "POSs": "NNS JJ CD NN , DT NN IN JJ NN , RB VBD JJ .",
    "positions": "0-0-5 1-6-11 2-12-16 3-17-22 4-23-24 5-25-26 6-27-33 7-34-38 8-39-44 9-45-51 10-52-53 11-54-58 12-59-65 13-66-76 14-77-78",
    "NERs": "O O DATE O O O O O O O O O O O O",
    "graph": {
      "g_features": [
        "twins",
        "-lrb-",
        "1988",
        "-rrb-",
        ",",
        "a",
        "comedy",
        "with",
        "danny",
        "devito",
        ",",
        "also",
        "proved",
        "successful",
        "."
      ],
      "g_adj": {
        "0": [
          {
            "node": 1,
            "edge": "punct"
          },
          {
            "node": 2,
            "edge": "appos"
          },
          {
            "node": 3,
            "edge": "punct"
          },
          {
            "node": 4,
            "edge": "punct"
          },
          {
            "node": 6,
            "edge": "appos"
          },
          {
            "node": 10,
            "edge": "punct"
          }
        ],
        "6": [
          {
            "node": 5,
            "edge": "det"
          },
          {
            "node": 7,
            "edge": "prep"
          }
        ],
        "7": [
          {
            "node": 9,
            "edge": "pobj"
          }
        ],
        "9": [
          {
            "node": 8,
            "edge": "amod"
          }
        ],
        "12": [
          {
            "node": 0,
            "edge": "nsubj"
          },
          {
            "node": 11,
            "edge": "advmod"
          },
          {
            "node": 13,
            "edge": "oprd"
          },
          {
            "node": 14,
            "edge": "punct"
          }
        ]
      },
      "num_edges": 14
    }
  }
}

loss data

Hello, can you give me a copy of the output file corresponding to the running path after the main.py command?

`rl_wmd_ratio` not found

Hi, I tried to run the exact code in the readme, but encountered this error.

Read the paper, and it's a great work by the way. Thanks for sharing the code.

Traceback (most recent call last):
  File "main.py", line 57, in <module>
    main(config)
  File "main.py", line 22, in main
    model = ModelHandler(config)
  File "C:\Users\User\Desktop\G2S_NQG\RL-based-Graph2Seq-for-NQG\src\core\model_handler.py", line 73, in __init__
    self.model = Model(config, train_set)
  File "C:\Users\User\Desktop\G2S_NQG\RL-based-Graph2Seq-for-NQG\src\core\model.py", line 69, in __init__
    if config['rl_wmd_ratio'] > 0:
KeyError: 'rl_wmd_ratio'

Transformer2Seq not found

from .models.transformer2seq import Transformer2Seq
ModuleNotFoundError: No module named 'core.models.transformer2seq'

It would really help me if you could look into this. Thank you.

How to preprocess data?

Excuse me, could you please share the code of preprocessing the data? I'd like to preprocess my own data and my data format is like the
train.src
train.tgt
test.src
test.tgt
...
Thank you very much!

need graph constructed code

thanks for sharing your code.
by the way,can you share your graph constructed code?
im so intrested how to do it,
it would be so kind to u if reply me

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.