Git Product home page Git Product logo

chineseqg's Introduction

ChineseQG

This project includes two ways to generate simple questions based on RDF triples in the knowledge base, template extraction method and template based sequence-to-sequence(seq2seq) model.

Model Overview

Template Extraction

As shown above, we extract templates for a specific predicate ("相关人物"/related people in this case) from training set. Then we randomly select one of those extracted templates to generate new questions of the given triples from testing set.

Template-based Seq2seq

For a given triple, the input for triple encoder is the concatenation of (SUBJECT, SEP, PREDICT). SEP here is '|||'.

For template decoder, instead of using the entire question for input, we replace the SUBJECT(topic words) in the question with '(SUB)' token.

Installation

For training tseq2seq, we strongly recommend using GPU for accelerating the speed.

Tensorflow

The code for tseq2seq is based on Tensorflow. You can find installation instructions here.

Dependencies

The code is based on Python 2.7. The dependencies are listed in the file requirements.txt. You can install these dependencies as follows:

pip install -r requirements.txt

Data

We focus on Chinese simple question generation based on open-domain Chinese knowledge base provided by NLPCC 2017 Shared Task 5. The training file nlpcc-iccpol-2016.kbqa.training-data in our experiments is from the KBQA challenge.

Format

KB-based simple questions are the questions which only involve one-hop inference on the knowledge graph. In other words, we generate simple questions in this work only by single triples.

The (question, triple, answer) triples in nlpcc-iccpol-2016.kbqa.training-data and nlpcc-iccpol-2016.kbqa.testing-data are formatted as follows:

<question id=5>	《线性代数》的isbn码是什么?
<triple id=5>	线性代数 ||| isbn ||| 978-7-111-36843-4
<answer id=5>	978-7-111-36843-4

Usage

Here we provide implementations for template extraction model and template-based seq2seq (tseq2seq) model.

Preprocess

First of all, we do some preprocessing work (using python3 instead of python2 to avoid chinese character encoding errors) on the original training and testing data, including creating vocabulary table, vectorizing input chinese characters and preparing for BLEU and ROUGE evaluations.

python3 preprocess.py

Template Extraction

Template extraction contains two phases: template collection and selective generation. You can implement the two phases in a pipeline by template.py and get automatic evaluation results:

python template-extraction/template.py

Template-based Seq2seq

We implement a general seq2seq framework that contains both vanilla seq2seq and tseqseq model. You can train with vanilla seq2seq model by setting tseq2seq to False.

python tseq2seq/Main.py

You can also adjust the learning rate if the loss is decreasing too slow or seems to over-fit. The dimension of word embedding and hidden units can also easily be changed in Main.py.

chineseqg's People

Contributors

tyliupku avatar

Stargazers

chen avatar  avatar Aaron Wu(吴礼斌) avatar  avatar  avatar Muhammad Sulaiman avatar Kunlun Zhu avatar  avatar  avatar  avatar Jiahang Li avatar  avatar peifeng_ren avatar nkandel avatar  avatar  avatar  avatar Edison Pan avatar Jia-Ying Lin avatar Yiheng Shu avatar  avatar  avatar Robin avatar  avatar Dawei Jin avatar Leslee avatar  avatar  avatar  avatar Hunter avatar  avatar finetuning avatar gangge avatar Neo avatar  avatar  avatar weiyujian avatar  avatar  avatar  avatar linjian avatar FEI Hao avatar Yuan Zhang avatar Jessie avatar  avatar  avatar  avatar  avatar poke avatar  avatar  avatar guwenyi avatar 猫猫 avatar 0x0000 avatar Forcus avatar yuanke avatar Shi Chenqi avatar  avatar sky_shine avatar Yang An avatar Fuli Luo avatar  avatar Jiangjie Chen avatar sun spy avatar  avatar Alex avatar Aolin Li avatar  avatar Zy avatar Ramsey avatar  avatar SimmerChan avatar  avatar  avatar yanqiangmiffy avatar Shuang avatar  avatar Ta Ko avatar IceMachine avatar Bowen Dong avatar  avatar  avatar  avatar Robert avatar  avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

chineseqg's Issues

ZeroDivisionError: float division by zero

mldl@ub1604:/ub16_prj/ChineseQG/template-extraction$ python template.py
Using TensorFlow backend.
extracting answer patterns from training set ...
done ...
number of questions in test set: 0
Traceback (most recent call last):
File "template.py", line 207, in
pattern_baseline()
File "template.py", line 175, in pattern_baseline
bleu = BLEU(pred_path, gold_path)
File "/home/mldl/ub16_prj/ChineseQG/template-extraction/bleu.py", line 124, in BLEU
pr, bp = count_ngram(candidate, references, i+1)
File "/home/mldl/ub16_prj/ChineseQG/template-extraction/bleu.py", line 79, in count_ngram
bp = brevity_penalty(c, r)
File "/home/mldl/ub16_prj/ChineseQG/template-extraction/bleu.py", line 112, in brevity_penalty
bp = math.exp(1-(float(r)/c))
ZeroDivisionError: float division by zero
mldl@ub1604:
/ub16_prj/ChineseQG/template-extraction$

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.