Skip to main content

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

Project description

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

  • Sentence to Graph (StoG) parsing to create AMR graphs from English sentences.
  • Graph to Sentence (GtoS) generation for turning AMR graphs into English sentences.
  • A QT based GUI to facilitate conversion of sentences to graphs and back to sentences
  • Methods to plot AMR graphs in both the GUI and as library functions
  • Training and test code for both the StoG and GtoS models.
  • A SpaCy extension that allows direct conversion of SpaCy Docs and Spans to AMR graphs.
  • Sentence to Graph alignment routines
    • FAA_Aligner (Fast_Align Algorithm), based on the ISI aligner code detailed in this paper.
    • RBW_Aligner (Rule Based Word) for simple, single token to single node alignment
  • An evaluation metric API including including...
    • Smatch (multiprocessed with enhanced/detailed scores) for graph parsing
    • BLEU for sentence generation
    • Alignment scoring metrics detailing precision/recall
  • There is also a related co-referencing project/model at amr_coref.

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.

  • Parse (StoG) model_parse_xfm_bart_large gives an 83.7 SMATCH score with LDC2020T02.

  • Generation (GtoS) generate_t5wtense gives a 54 BLEU with tense tags or 44 BLEU with un-tagged LDC2020T02.

  • CoReference resolution at amr_coref achieves a 0.548 CoNLL-2012 average score.

AMR View

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

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.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

amrlib-0.7.1.tar.gz (326.8 kB view details)

Uploaded Source

Built Distribution

amrlib-0.7.1-py3-none-any.whl (354.2 kB view details)

Uploaded Python 3

File details

Details for the file amrlib-0.7.1.tar.gz.

File metadata

  • Download URL: amrlib-0.7.1.tar.gz
  • Upload date:
  • Size: 326.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.26.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for amrlib-0.7.1.tar.gz
Algorithm Hash digest
SHA256 70205cd0b8cb6ca7e9e61dbe56b5d867e90c4fb8aa1439c72499ee481d070d70
MD5 85bfd24ca97d499925a6e1796bb19534
BLAKE2b-256 676f1763d437c5e17f86923b1dd58fe918859622f66fe34836adb70bae59aed4

See more details on using hashes here.

File details

Details for the file amrlib-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: amrlib-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 354.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.26.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for amrlib-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 44faa84799b5581ef493c5fee7204826885210e0fa0763654441af5c815796a5
MD5 825b0f408bcdf64502cef587cf018359
BLAKE2b-256 2632d00a9485159d90becb94ccddf0a3b71240d3f107fc0fac10ec5e5c7aa4c3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page