mstrise / dep2label

Dependency Parsing as Sequence Labeling
MIT License
26 stars 1 forks source link

Dependency Parsing as Sequence Labeling

This repository contains the code with a collection of encodings proposed for Dependency Parsing as Sequence Labeling with NCRF++.

Dependency Parsing as Sequence Labeling is also available with BERT 🠊 repository

This is the source code for the following papers accepted at COLING2020:

Overview of the Encoding Family for Dependency Parsing in SL

Name Type of encoding supports non-projectivity?
rel-pos Relative Part-of-Speech-based :heavy_check_mark:
1-planar-brackets Bracketing-based :heavy_check_mark: / ✗
2-planar-brackets-greedy Second-Plane-Averse Greedy Plane Assignment :heavy_check_mark:
2-planar-brackets-propagation Second-Plane-Averse Plane Assignment based on Restriction Propagation on the Crossings Graph :heavy_check_mark:
arc-standard Arc Standard in Transition-based
arc-eager Arc Eager in Transition-based
arc-hybrid Arc Hybrid in Transition-based
covington Covington in Transition-based :heavy_check_mark:

Relative PoS-based and 1-planar bracketing-based encoding are described in "Viable Dependency Parsing as Sequence Labeling" (NAACL2019): [paper] | [code for results reproducibility].

In addition, one may be interested in using SL with:

Requirements

The code is based on NCRF++ and Constituency Parsing as Sequence Labeling code.

It is recommended to create a virtual environment in order to keep the installed packages separate to avoid conflicts with other programs.

pip install -r requirements.txt

Scripts for encoding and decoding dependency labels

To encode a CoNNL-X file to SL file:

python encode_dep2labels.py --input --output --encoding [--mtl] 

where

input=...    # file to encode (CoNNL-X format)
output=...   # output file with encoded dependency trees as labels (SL format)
encoding=... # encoding type= ["rel-pos", "1-planar-brackets", "2-planar-brackets-greedy","2-planar-brackets-propagation","arc-standard", "arc-eager","arc-hybrid", "covington","zero"]
mtl=...      # optionally, nb of multi-tasks= ["1-task","2-task","2-task-combined","3-task"]. By default, type that gives the best results is chosen

To decode a SL file to a CoNNL-X file:

python decode_labels2dep.py --input [--conllu_f] --output --encoding

where

input=...    # file to decode (SL format) 
conllu_f=... # optionally, the corresponding CoNNL-X file (in case of special indexing i.e. 1.1 or 1-2)
output=...   # output file with decoded dependency trees (CoNNL-X format)
encoding=... # encoding type= ["rel-pos", "1-planar-brackets", "2-planar-brackets-greedy","2-planar-brackets-propagation","arc-standard", "arc-eager","arc-hybrid", "covington"]

Training a model

Modify config file and run the following script:

python main.py --config 

where

config=...   # path to the config file 

Parsing with a trained model

run the following script:

python decode.py --test --gold [--predicted] --model --gpu --output --encoding --ncrfpp

where

test=...     # test file with encoded dependency trees (SL format)
gold=...     # gold test (CoNNL-X format)
predicted=...# optionally, CONNL-X file with with the predicted segmentation/tokenization/PoS in case the SL test file is also predicted
model=...    # path to the model (/mod)
gpu=...      # [True,False]
output=...   # output file with decoded trees (CoNNL-X format)
encoding=... # encoding type= ["rel-pos", "1-planar-brackets", "2-planar-brackets--greedy","2-planar-brackets-propagation","arc-standard", "arc-eager","arc-hybrid", "covington"]
ncrf=...     # path to NCRF

Acknowledgements

This work has received funding from the European Research Council (ERC), under the European Union's Horizon 2020 research and innovation programme (FASTPARSE, grant agreement No 714150).

Reference

If you wish to use our work for research purposes, please cite us!