项目作者: SapienzaNLP

项目描述 :
SPRING is a seq2seq model for Text-to-AMR and AMR-to-Text (AAAI2021).
高级语言: Python
项目地址: git://github.com/SapienzaNLP/spring.git
创建时间: 2020-12-03T11:47:46Z
项目社区:https://github.com/SapienzaNLP/spring

开源协议:Other

下载


SPRING

PWC

PWC

PWC

PWC

This is the repo for SPRING (Symmetric ParsIng aNd Generation), a novel approach to semantic parsing and generation, presented at AAAI 2021.

With SPRING you can perform both state-of-the-art Text-to-AMR parsing and AMR-to-Text generation without many cumbersome external components.
If you use the code, please reference this work in your paper:

  1. @inproceedings{bevilacqua-etal-2021-one,
  2. title = {One {SPRING} to Rule Them Both: {S}ymmetric {AMR} Semantic Parsing and Generation without a Complex Pipeline},
  3. author = {Bevilacqua, Michele and Blloshmi, Rexhina and Navigli, Roberto},
  4. booktitle = {Proceedings of AAAI},
  5. year = {2021}
  6. }

Pretrained Checkpoints

Here we release our best SPRING models which are based on the DFS linearization.

Text-to-AMR Parsing

AMR-to-Text Generation

If you need the checkpoints of other experiments in the paper, please send us an email.

Installation

```shell script
cd spring
pip install -r requirements.txt
pip install -e .

  1. The code only works with `transformers` < 3.0 because of a disrupting change in positional embeddings.
  2. The code works fine with `torch` 1.5. We recommend the usage of a new `conda` env.
  3. ## Train
  4. Modify `config.yaml` in `configs`. Instructions in comments within the file. Also see the [appendix](docs/appendix.pdf).
  5. ### Text-to-AMR
  6. ```shell script
  7. python bin/train.py --config configs/config.yaml --direction amr

Results in runs/

AMR-to-Text

```shell script
python bin/train.py —config configs/config.yaml —direction text

  1. Results in `runs/`
  2. ## Evaluate
  3. ### Text-to-AMR
  4. ```shell script
  5. python bin/predict_amrs.py \
  6. --datasets <AMR-ROOT>/data/amrs/split/test/*.txt \
  7. --gold-path data/tmp/amr2.0/gold.amr.txt \
  8. --pred-path data/tmp/amr2.0/pred.amr.txt \
  9. --checkpoint runs/<checkpoint>.pt \
  10. --beam-size 5 \
  11. --batch-size 500 \
  12. --device cuda \
  13. --penman-linearization --use-pointer-tokens

gold.amr.txt and pred.amr.txt will contain, respectively, the concatenated gold and the predictions.

To reproduce our paper’s results, you will also need need to run the BLINK
entity linking system on the prediction file (data/tmp/amr2.0/pred.amr.txt in the previous code snippet).
To do so, you will need to install BLINK, and download their models:
```shell script
git clone https://github.com/facebookresearch/BLINK.git
cd BLINK
pip install -r requirements.txt
sh download_blink_models.sh
cd models
wget http://dl.fbaipublicfiles.com/BLINK//faiss_flat_index.pkl
cd ../..

  1. Then, you will be able to launch the `blinkify.py` script:
  2. ```shell
  3. python bin/blinkify.py \
  4. --datasets data/tmp/amr2.0/pred.amr.txt \
  5. --out data/tmp/amr2.0/pred.amr.blinkified.txt \
  6. --device cuda \
  7. --blink-models-dir BLINK/models

To have comparable Smatch scores you will also need to use the scripts available at https://github.com/mdtux89/amr-evaluation, which provide
results that are around ~0.3 Smatch points lower than those returned by bin/predict_amrs.py.

AMR-to-Text

shell script python bin/predict_sentences.py \ --datasets <AMR-ROOT>/data/amrs/split/test/*.txt \ --gold-path data/tmp/amr2.0/gold.text.txt \ --pred-path data/tmp/amr2.0/pred.text.txt \ --checkpoint runs/<checkpoint>.pt \ --beam-size 5 \ --batch-size 500 \ --device cuda \ --penman-linearization --use-pointer-tokens
gold.text.txt and pred.text.txt will contain, respectively, the concatenated gold and the predictions.
For BLEU, chrF++, and Meteor in order to be comparable you will need to tokenize both gold and predictions using JAMR tokenizer.
To compute BLEU and chrF++, please use bin/eval_bleu.py. For METEOR, use https://www.cs.cmu.edu/~alavie/METEOR/ .
For BLEURT don’t use tokenization and run the eval with https://github.com/google-research/bleurt. Also see the appendix.

Linearizations

The previously shown commands assume the use of the DFS-based linearization. To use BFS or PENMAN decomment the relevant lines in configs/config.yaml (for training). As for the evaluation scripts, substitute the --penman-linearization --use-pointer-tokens line with --use-pointer-tokens for BFS or with --penman-linearization for PENMAN.

License

This project is released under the CC-BY-NC-SA 4.0 license (see LICENSE). If you use SPRING, please put a link to this repo.

Acknowledgements

The authors gratefully acknowledge the support of the ERC Consolidator Grant MOUSSE No. 726487 and the ELEXIS project No. 731015 under the European Union’s Horizon 2020 research and innovation programme.

This work was supported in part by the MIUR under the grant “Dipartimenti di eccellenza 2018-2022” of the Department of Computer Science of the Sapienza University of Rome.