Package: transition-neural-parser
Transition-based Neural ParserState-of-the-Art Abstract Meaning Representation (AMR) parsing, seepapers
with code. Models both
distribution over graphs and aligments with a transition-based approach. Parser
supports generic text-to-graph as long as it is expressed inPenman
notation.Some of the main featuresSmatchwrapper providingsignificance testingfor Smatch andMBSEensembling.Structured-BART(Zhou et al 2021b)withtrained checkpointsfor document-level AMR(Naseem et al 2022), MBSE(Lee et al 2022)and latent alignments training(Drozdov et al 2022)Structured-mBARTfor multi-lingual support (EN, DE, Zh, IT)(Lee et al 2022)Action-Pointer Transformer (APT)(Zhou et al 2021), checkoutaction-pointerbranchStack-Transformer(Fernandez Astudillo et al 2020), checkoutstack-TransformerbranchInstall Instructionscreate and activate a virtual environment with python 3.8, for exampleconda create -y -p ./cenv_x86 python=3.8
conda activate ./cenv_x86or alternatively usevirtualenvandpyenvfor python versions. Note that
all scripts source aset_environment.shscript that you can use to activate
your virtual environment as above and set environment variables. If not used,
just create an empty version# or e.g. put inside conda activate ./cenv_x86touchset_environment.shThen install the parser package using pip. You will need to manually installtorch-scattersince it is custom built for CUDA. Here we specify the
call fortorch 1.13.1andcuda 11.7. Seetorch-scatter
repositoryto find the appropriate
installation instructions.For MacOS users(Please install the cpu version of torch-scatter; and model training is not fully supported here.)pipinstalltransition-neural-parser# for linux userspipinstalltorch-scatter-fhttps://data.pyg.org/whl/torch-1.13.1+cu117.html# for cpu installation for MacOS# pip install torch-scatterIf you plan to edit the code, clone and install instead# clone this repo (see link above), thencdtransition-neural-parser
pipinstall--editable.
pipinstalltorch-scatter-fhttps://data.pyg.org/whl/torch-1.13.1+cu117.htmlIf you want to train a document-level AMR parser you will also needgitclonehttps://github.com/IBM/docAMR.gitcddocAMR
pipinstall.cd..Parse with a pretrained modelHere is an example of how to download and use a pretrained AMR parser in Pythonfromtransition_amr_parser.parseimportAMRParser# Download and save a model named AMR3.0 to cacheparser=AMRParser.from_pretrained('AMR3-structbart-L')tokens,positions=parser.tokenize('The girl travels and visits places')# Use parse_sentence() for single sentences or parse_sentences() for a batchannotations,machines=parser.parse_sentence(tokens)# Print Penman notationprint(annotations)# Print Penman notation without JAMR, with ISIamr=machines.get_amr()print(amr.to_penman(jamr=False,isi=True))# Plot the graph (requires matplotlib)amr.plot()Note that Smatch does not support ISI-type alignments and gives worse results.
Setisi=Falseto remove them.You can also use the command line to run a pretrained model to parse a file:amr-parse-c$in_checkpoint-i$input_file-ofile.amrDownload models can invoked with-m <config>can be used as well.Note that Smatch does not support ISI and gives worse results. Use--no-isito store alignments in::alignmentsmeta data. Also use--jamrto add JAMR
annotations in meta-data. Use--no-isito store alignments in::alignmentsmeta data. Also use--jamrto add JAMR annotations in meta-data.Document-level ParsingThis represents co-reference using:same-asedges. To change
the representation and merge the co-referent nodes as in the paper, please refer
tothe DocAMR repofromtransition_amr_parser.parseimportAMRParser# Download and save the docamr model to cacheparser=AMRParser.from_pretrained('doc-sen-conll-amr-seed42')# Sentences in the docdoc=["Hailey likes to travel.","She is going to London tomorrow.","She will walk to Big Ben when she goes to London."]# tokenize sentences if not already tokenizedtok_sentences=[]forsenindoc:tokens,positions=parser.tokenize(sen)tok_sentences.append(tokens)# parse docs takes a list of docs as inputannotations,machines=parser.parse_docs([tok_sentences])# Print Penman notationprint(annotations[0])# Print Penman notation without JAMR, with ISIamr=machines[0].get_amr()print(amr.to_penman(jamr=False,isi=True))# Plot the graph (requires matplotlib)amr.plot()To parse a document from the command line the input file$doc_input_fileis a
text file where each line is a sentence in the document and there is a newline
('\n') separating every doc (even at the end)amr-parse-c$in_checkpoint--in-doc$doc_input_file-ofile.docamrAvailable Pretrained Model CheckpointsThe models downloaded usingfrom_pretrained()will be stored to the pytorch
cache folder under:cache_dir=torch.hub._get_torch_home()This table shows you available pretrained model names to download;pretrained model namecorresponding file namepaperbeam10-SmatchAMR3-structbart-L-smplamr3.0-structured-bart-large-neur-al-sampling5-seed42(Drozdov et al 2022)PR82.9 (beam1)AMR3-structbart-Lamr3.0-structured-bart-large-neur-al-seed42(Drozdov et al 2022)MAP82.6AMR2-structbart-Lamr2.0-structured-bart-large-neur-al-seed42(Drozdov et al 2022)MAP84.0AMR2-joint-ontowiki-seed42amr2joint_ontowiki2_g2g-structured-bart-large-seed42(Lee et al 2022)(ensemble)85.9AMR2-joint-ontowiki-seed43amr2joint_ontowiki2_g2g-structured-bart-large-seed43(Lee et al 2022)(ensemble)85.9AMR2-joint-ontowiki-seed44amr2joint_ontowiki2_g2g-structured-bart-large-seed44(Lee et al 2022)(ensemble)85.9AMR3-joint-ontowiki-seed42amr3joint_ontowiki2_g2g-structured-bart-large-seed42(Lee et al 2022)(ensemble)84.4AMR3-joint-ontowiki-seed43amr3joint_ontowiki2_g2g-structured-bart-large-seed43(Lee et al 2022)(ensemble)84.4AMR3-joint-ontowiki-seed44amr3joint_ontowiki2_g2g-structured-bart-large-seed44(Lee et al 2022)(ensemble)84.4doc-sen-conll-amr-seed42both_doc+sen_trainsliding_ws400x100-seed4282.31/71.821 Smatch on AMR3.0 sentences2 Smatch on AMR3.0 Multi-Sentence datasetcontact authors to obtain the trainedibm-neural-aligner. For the
ensemble we provide the three seeds. Following fairseq conventions, to run the
ensemble just give the three checkpoint paths joined by:to the normal
checkpoint argument-c. Note that the checkpoints were trained with thev0.5.1tokenizer, this reduces performance by0.1onv0.5.2tokenized
data.Note that we allways report average of three seeds in papers while these are
individual models. A fast way to test models standalone isbash tests/standalone.sh configs/<config>.shTraining a modelYou first need to pre-process and align the data. For AMR2.0 docondaactivate./cenv_x86# activate parser environmentpythonscripts/merge_files.py/path/to/LDC2017T10/data/amrs/split/DATA/AMR2.0/corpora/You will also need to unzip the precomputed BLINK cache. See issues in this repository to get the cache file (or the link above for IBM-ers).unzip /path/to/linkcache.zipTo launch train/test use (this will also run the aligner)bash run/run_experiment.sh configs/amr2.0-structured-bart-large.shTraining will store and evaluate all checkpoints by default (see config'sEVAL_INIT_EPOCH) and select the one with best dev Smatch. This needs a lot of
space but you can launch a parallel job that will perform evaluation and delete
Checkpoints not in the top5bash run/run_model_eval.sh configs/amr2.0-structured-bart-large.shyou can check training status withpython run/status.py -c configs/amr2.0-structured-bart-large.shuse--resultsto check for scores once models are finished.We include code to launch parallel jobs in the LSF job schedules. This can be
adapted for other schedulers e.g. Slurm, seehereInitialize with WatBARTTo load WatBART instead of BART just uncomment and provide the path oninitialize_with_watbart=/path/to/checkpoint_best.pt