Skip to content
Source code for "Head-Driven Phrase Structure Grammar Parsing on Penn Treebank" published at ACL 2019
Python C Other
Branch: master
Clone or download
Latest commit 83caab2 Aug 19, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea update Aug 19, 2019
EVALB Initial commit of EVALB code from http://nlp.cs.nyu.edu/evalb/ May 28, 2019
data update Jun 2, 2019
models first commit May 27, 2019
src_division update Aug 19, 2019
src_joint update Aug 19, 2019
.DS_Store Initial commit of EVALB code from http://nlp.cs.nyu.edu/evalb/ May 28, 2019
LICENSE Create LICENSE May 28, 2019
README.md Add XLNet Setting Aug 19, 2019
parse.sh add parse sh Aug 4, 2019
run_bert.sh first commit May 27, 2019
run_single.sh first commit May 27, 2019
test.sh Update test.sh May 28, 2019

README.md

HPSG Neural Parser

This is a Python implementation of the parsers described in "Head-Driven Phrase Structure Grammar Parsing on Penn Treebank" from ACL 2019.

Contents

  1. Requirements
  2. Training
  3. Citation
  4. Credits

Requirements

  • Python 3.6 or higher.
  • Cython 0.25.2 or any compatible version.
  • PyTorch 0.4.0. This code has not been tested with PyTorch 1.0, but it should work.
  • EVALB. Before starting, run make inside the EVALB/ directory to compile an evalb executable. This will be called from Python for evaluation.
  • AllenNLP 0.7.0 or any compatible version (only required when using ELMo word representations)
  • pytorch-transformers PyTorch 1.0.0+ or any compatible version (only required when using BERT and XLNet, XLNet only for joint span version.)

Pre-trained Models (PyTorch)

The following pre-trained parser models are available for download:

The pre-trained model with Glove embeddings obtains 93.78 F-scores of constituent parsing and 96.09 UAS, 94.68 LAS of dependency parsing on the test set.

The pre-trained model with BERT obtains 95.84 F-scores of constituent parsing and 97.00 UAS, 95.43 LAS of dependency parsing on the test set.

To use ELMo embeddings, download the following files into the data/ folder (preserving their names):

There is currently no command-line option for configuring the locations/names of the ELMo files.

Pre-trained BERT weights will be automatically downloaded as needed by the pytorch-pretrained-bert package.

Training

Download the 3 PTB data files from https://github.com/nikitakit/self-attentive-parser/tree/master/data, and put them in the data/ folder. The dependency structures are mainly obtained by converting constituent structure with version 3.3.0 of Stanford Parser in the data/ folder:

java -cp stanford-parser_3.3.0.jar edu.stanford.nlp.trees.EnglishGrammaticalStructure -basic -keepPunct -conllx -treeFile 02-21.10way.clean > ptb_train_3.3.0.sd

For CTB, we use the same datasets and preprocessing from the Distance Parser. For PTB, we use the same datasets and preprocessing from the self-attentive-parser. GloVe embeddings are optional.

Training Instructions

Some of the available arguments are:

Argument Description Default
--model-path-base Path base to use for saving models N/A
--evalb-dir Path to EVALB directory EVALB/
--train-ptb-path Path to training constituent parsing data/02-21.10way.clean
--dev-ptb-path Path to development constituent parsing data/22.auto.clean
--dep-train-ptb-path Path to training dependency parsing data/ptb_train_3.3.0.sd
--dep-dev-ptb-path Path to development dependency parsing data/ptb_dev_3.3.0.sd
--batch-size Number of examples per training update 250
--checks-per-epoch Number of development evaluations per epoch 4
--subbatch-max-tokens Maximum number of words to process in parallel while training (a full batch may not fit in GPU memory) 2000
--eval-batch-size Number of examples to process in parallel when evaluating on the development set 30
--numpy-seed NumPy random seed Random
--use-words Use learned word embeddings Do not use word embeddings
--use-tags Use predicted part-of-speech tags as input Do not use predicted tags
--use-chars-lstm Use learned CharLSTM word representations Do not use CharLSTM
--use-elmo Use pre-trained ELMo word representations Do not use ELMo
--use-bert Use pre-trained BERT word representations Do not use BERT
--use-xlnet Use pre-trained BERT word representations Do not use XLNet
--bert-model Pre-trained BERT model to use if --use-bert is passed bert-large-uncased
--no-bert-do-lower-case Instructs the BERT tokenizer to retain case information (setting should match the BERT model in use) Perform lowercasing
--xlnet-model Pre-trained XLNet model to use if --use-xlnet is passed xlnet-large-cased
--no-xlnet-do-lower-case Instructs the XLNet tokenizer to retain case information (setting should match the XLNet model in use) Perform uppercasing
--const-lada Lambda weight 0.5
--model-name Name of model test
--embedding-path Path to pre-trained embedding N/A
--embedding-type Pre-trained embedding type glove
--dataset Dataset type ptb

Additional arguments are available for other hyperparameters; see make_hparams() in src/main.py. These can be specified on the command line, such as --num-layers 2 (for numerical parameters), --use-tags (for boolean parameters that default to False), or --no-partitioned (for boolean parameters that default to True).

For each development evaluation, the best_dev_score is the sum of F-score and LAS on the development set and compared to the previous best. If the current model is better, the previous model will be deleted and the current model will be saved. The new filename will be derived from the provided model path base and the development best_dev_score.

As an example, after setting the paths for data and embeddings, to train a Joint-Span parser, simply run:

sh run_single.sh

to train a Joint-Span parser with BERT, simply run:

sh run_bert.sh

Evaluation Instructions

A saved model can be evaluated on a test corpus using the command python src/main.py test ... with the following arguments:

Argument Description Default
--model-path-base Path base of saved model N/A
--evalb-dir Path to EVALB directory EVALB/
--test-ptb-path Path to test constituent parsing data/23.auto.clean
--dep-test-ptb-path Path to test dependency parsing data/ptb_test_3.3.0.sd
--embedding-path Path to pre-trained embedding data/glove.6B.100d.txt.gz
--eval-batch-size Number of examples to process in parallel when evaluating on the test set 100
--dataset Dataset type ptb

As an example, after extracting the pre-trained model, you can evaluate it on the test set using the following command:

sh test.sh

If you want to parse the sentences, after setting the input file and pre-trained model, run following command:

sh parse.sh

Citation

If you use this software for research, please cite our paper as follows:

@inproceedings{zhou-zhao-2019-head,
    title = "Head-Driven Phrase Structure Grammar Parsing on {P}enn Treebank",
    author = "Zhou, Junru  and Zhao, Hai",
    booktitle = "Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics",
    month = jul,
    year = "2019",
    address = "Florence, Italy",
    publisher = "Association for Computational Linguistics",
}

Credits

The code in this repository and portions of this README are based on https://github.com/nikitakit/self-attentive-parser

You can’t perform that action at this time.