bjascob / amrlib

A python library that makes AMR parsing, generation and visualization simple.
MIT License
216 stars 33 forks source link
abstract-meaning-representation amr amr-graphs amr-parser amr-parsing neural-network python pytorch spacy spacy-extension text-generation transformer

amrlib

A python library that makes AMR parsing, generation and visualization simple.

For the latest documentation, see ReadTheDocs.

!! Note: The models must be downloaded and installed separately. See the Installation Instructions.

About

amrlib is a python module designed to make processing for Abstract Meaning Representation (AMR) simple by providing the following functions

AMR Models

The system includes different neural-network models for parsing and for generation. !! Note: Models must be downloaded and installed separately. See amrlib-models for all parse and generate model download links.

AMR View

The GUI allows for simple viewing, conversion and plotting of AMR Graphs.

AMRView

AMR CoReference Resolution

The library does not contain code for AMR co-reference resolution but there is a related project at amr_coref.

The following papers have GitHub projects/code that have similar or better scoring than the above..

Requirements and Installation

The project was built and tested under Python 3 and Ubuntu but should run on any Linux, Windows, Mac, etc.. system.

See Installation Instructions for details on setup.

Library Usage

To convert sentences to graphs

import amrlib
stog = amrlib.load_stog_model()
graphs = stog.parse_sents(['This is a test of the system.', 'This is a second sentence.'])
for graph in graphs:
    print(graph)

To convert graphs to sentences

import amrlib
gtos = amrlib.load_gtos_model()
sents, _ = gtos.generate(graphs)
for sent in sents:
    print(sent)

For a detailed description see the Model API.

Usage as a Spacy Extension

To use as an extension, you need spaCy version 2.0 or later. To setup the extension and use it do the following

import amrlib
import spacy
amrlib.setup_spacy_extension()
nlp = spacy.load('en_core_web_sm')
doc = nlp('This is a test of the SpaCy extension. The test has multiple sentences.')
graphs = doc._.to_amr()
for graph in graphs:
    print(graph)

For a detailed description see the Spacy API.

Paraphrasing

For an example of how to use the library to do paraphrasing, see the Paraphrasing section in the docs.

SMATCH Scoring

amrlib uses the smatch library for scoring. This is the library that is most commonly used for scoring AMR parsers and reporting results in literature. There are some cases where the code may give inconsistant or erroneous results. You may wish to look at smatchpp for an improved scoring algorithm.

Issues

If you find a bug, please report it on the GitHub issues list. Additionally, if you have feature requests or questions, feel free to post there as well. I'm happy to consider suggestions and Pull Requests to enhance the functionality and usability of the module.