Coder Social home page Coder Social logo

hongzhangmu / hetersumgraph Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dqwang122/hetersumgraph

0.0 1.0 0.0 73 KB

Code for ACL2020 paper "Heterogeneous Graph Neural Networks for Extractive Document Summarization"

Shell 1.02% Python 98.98%

hetersumgraph's Introduction

HeterSumGraph

Code for ACL 2020 paper: Heterogeneous Graph Neural Networks for Extractive Document Summarization

fastNLP version will come soon.

Some code are borrowed from PG and Transformer. Thanks for their work.

Dependency

  • python 3.5+

  • PyTorch 1.0+

  • DGL 0.4

  • rouge 1.0.0

    • A full Python Implementation of the ROUGE Metric which is used in validation phrase
  • pyrouge 0.1.3

  • others

    • nltk
    • numpy
    • sklearn

Data

We have preprocessed CNN/DailyMail, NYT50 and Multi-News datasets for TF-IDF features used in the graph creation, which you can find here.

For CNN/DailyMail and Multi-News, we also provide the json-format datasets in this link. However, due to the license, NYT(The New York Times Annotated Corpus) can only be available from LDC. And we follow the preprocessing code of Durrett et al. (2016) to get the NYT50 datasets.

The example looks like this:

{
  "text":["deborah fuller has been banned from keeping animals ... 30mph",...,"a dog breeder and exhibitor... her dogs confiscated"],
  "summary":["warning : ... at a speed of around 30mph",... ,"she was banned from ... and given a curfew "],
  "label":[1,3,6]
}

and each line in the file is an example. For the text key, the value can be list of string (single-document) or list of list of string (multi-document). The example in training set can ignore the summary key since we only use label during the training phrase. All strings need be lowercase and tokenized by Stanford Tokenizer, and nltk.sent_tokenize is used to get sentences.

After getting the standard json format, you can prepare the dataset for the graph by PrepareDataset.sh in the project directory. The processed files will be put under the cache directory.

The default file names for training, validation and test are: train.label.jsonl, val.label.jsonl and test.label.jsonl. If you would like to use other names, please change the corresponding names in PrepareDataset.sh, Line 321-322 in train.py and Line 188 in evaluation.py. (Default names is recommended)

Train

For training, you can run commands like this:

python train.py --cuda --gpu 0 --data_dir <data/dir/of/your/json-format/dataset> --cache_dir <cache/directory/of/graph/features> --embedding_path <glove_path> --model [HSG|HDSG] --save_root <model path> --log_root <log path> --lr_descent --grad_clip -m 3

We also provide our checkpoints on CNN/DailyMail, NYT50 and Multi-News in this link. Besides, the outputs can be found here(NYT50 has been removed due to its license).

Test

For evaluation, the command may like this:

python evaluation.py --cuda --gpu 0 --data_dir <data/dir/of/your/json-format/dataset> --cache_dir <cache/directory/of/graph/features> --embedding_path <glove_path>  --model [HSG|HDSG] --save_root <model path> --log_root <log path> -m 3 --test_model multi --use_pyrouge

Some options:

  • use_pyrouge: whether to use pyrouge for evaluation. Default is False (which means rouge).
    • Please change Line17-18 in tools/utils.py to your own ROUGE path and temp file path.
  • limit: whether to limit the output to the length of gold summaries. This option is only set for evaluation on NYT50 (which uses ROUGE-recall instead of ROUGE-f). Default is False.
  • blocking: whether to use Trigram blocking. Default is False.
  • save_label: only save label and do not calculate ROUGE. Default is False.

To load our checkpoint for evaluation, you should put it under the save_root/eval/ and make the name for test_model to start with eval. For example, if your save_root is "checkpoints", then the checkpoint "cnndm.ckpt" should be put under "checkpoints/eval" and the test_model is evalcnndm.ckpt.

ROUGE Installation

In order to get correct ROUGE scores, we recommend using the following commands to install the ROUGE environment:

sudo apt-get install libxml-perl libxml-dom-perl
pip install git+git://github.com/bheinzerling/pyrouge
export PYROUGE_HOME_DIR=the/path/to/RELEASE-1.5.5
pyrouge_set_rouge_path $PYROUGE_HOME_DIR
chmod +x $PYROUGE_HOME_DIR/ROUGE-1.5.5.pl

You can refer to https://github.com/andersjo/pyrouge/tree/master/tools/ROUGE-1.5.5 for RELEASE-1.5.5 and remember to build Wordnet 2.0 instead of 1.6 in RELEASE-1.5.5/data:

cd $PYROUGE_HOME_DIR/data/WordNet-2.0-Exceptions/
./buildExeptionDB.pl . exc WordNet-2.0.exc.db
cd ../
ln -s WordNet-2.0-Exceptions/WordNet-2.0.exc.db WordNet-2.0.exc.db

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.