Code Monkey home page Code Monkey logo

dhgn's Introduction

DHGN

This is the pytorch code for our CCL 2021 paper Incorporating Commonsense Knowledge into Abstractive Dialogue Summarization via Heterogeneous Graph Networks [arXiv Preprint].

Outputs

Requirements

  • We use Conda python 3.7 and strongly recommend that you create a new environment: conda create -n dhgn python=3.7.
  • Run the following command: pip install -r requirements.txt.

* pytorch_geometric

pip install torch_spline_conv-latest+cu100-cp37-cp37m-linux_x86_64.whl
pip install torch_cluster-latest+cu100-cp37-cp37m-linux_x86_64.whl
pip install torch_sparse-latest+cu100-cp37-cp37m-linux_x86_64.whl
pip install torch_scatter-latest+cu100-cp37-cp37m-linux_x86_64.whl
pip install torch-geometric==1.4.3

Reproduce Results

You can follow the following steps to reproduce the best results in our paper.

* download checkpoints

Download checkpoints here. Put the checkpoint samsum.pt under the project dir DHGN/models/samsum.pt.

* translate

We can get summaries/summary.txt

python translate.py \
-src data/test.src.txt \
-edge_index data/test.edge_index.txt \
-edge_type data/test.edge_type.txt \
-node_type data/test.node_type.txt \
-max_length 1000 -min_length 19 -beta 1 -ignore_when_blocking "." "," -stepwise_penalty -coverage_penalty summary -n_best 4 -batch_size 64 -beam_size 10 -dynamic_dict -share_vocab  -block_ngram_repeat 3 -replace_unk \
-model models/samsum.pt \
-output summaries/summary.txt \
-gpu X

* rerank

  • python rerank.py -n 4 -c summaries/summary.txt

* test rouge score

  • python py_rouge_test.py -c summaries/summary_rerank.txt
  • Output >>> ROUGE 1-2-L F: 42.03-18.07-39.56

From Scratch

* preprocess

(1) Preprocess ICSI dataset.

python preprocess.py \
  -train_src data/train.src.txt \
  -train_edge_index data/train.edge_index.txt \
  -train_edge_type data/train.edge_type.txt \
  -train_node_type data/train.node_type.txt \
  -train_tgt data/train.tgt.txt \
  -valid_src data/valid.src.txt \
  -valid_edge_index data/valid.edge_index.txt \
  -valid_edge_type data/valid.edge_type.txt \
  -valid_node_type data/valid.node_type.txt \
  -valid_tgt data/valid.tgt.txt \
  -save_data data/samsum \
  -dynamic_dict \
  -share_vocab \
  -src_words_min_frequency 0 \
  -tgt_words_min_frequency 0 \
  -src_seq_length 10000 \
  -tgt_seq_length 10000 \
  -src_seq_length_trunc 10000 \
  -tgt_seq_length_trunc 10000 \
  -overwrite

(2) Create pre-trained word embeddings.

download glove.6B.100d.txt from here.

python embeddings_to_torch.py -emb_file_both data/glove.6B.100d.txt \
-dict_file data/samsum.vocab.pt \
-output_file data/samsum_embeddings

* train

CUDA_VISIBLE_DEVICES=x python train.py -config ./config/train.yml -save_config ./config/train.txt
CUDA_VISIBLE_DEVICES=x python train.py -config ./config/train.yml

* translate

python translate.py \
-src data/test.src.txt \
-edge_index data/test.edge_index.txt \
-edge_type data/test.edge_type.txt \
-node_type data/test.node_type.txt \
-max_length 1000 -min_length 19 -beta 1 -ignore_when_blocking "." "," -stepwise_penalty -coverage_penalty summary -n_best 4 -batch_size 64 -beam_size 10 -dynamic_dict -share_vocab  -block_ngram_repeat 3 -replace_unk \
-model models/xxxx.pt \
-output summaries/xxxx.txt \
-gpu X

* rerank

  • python rerank.py -n 4 -c summaries/xxxx.txt

* test rouge score

  • python py_rouge_test.py -c summaries/summary_rerank.txt

dhgn's People

Contributors

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