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.

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.
  • Rule Based Word Alignment of tokens to graph nodes
  • 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
  • Sentence paraphrasing - experimental

AMR Models

The system uses two different Neural Network models for parsing and generation.

The parsing (StoG) model comes from jcyk/AMR-gs, the details of which can be found in this paper. The version of the model used here eliminates much of the data abstraction (aka anonymization) used in the original code. During testing, this model achieves a 77 SMATCH score with LDC2020T02.

The generation (GtoS) model takes advantage of the pretrained HuggingFace T5 transformer. Details on using this type of model for generation can be found in this paper. The model is fine-tuned to translate AMR graphs to English sentences. The retrained model achieves a BLEU score of 43 with LDC2020T02.

Documentation

For the latest documentation, see ReadTheDocs.

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, disable_progress=True)
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 explanation 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.2.1.tar.gz (65.4 kB view details)

Uploaded Source

Built Distribution

amrlib-0.2.1-py3-none-any.whl (78.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: amrlib-0.2.1.tar.gz
  • Upload date:
  • Size: 65.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for amrlib-0.2.1.tar.gz
Algorithm Hash digest
SHA256 40a49a77dddcb325fee36c7329243b4f347120cadeb46f89e1a6192d702c1ebb
MD5 0012e31d20f69a6c5567ee7d9289cdf2
BLAKE2b-256 e4cd12939c3326a0733ac88850c16a566b1372b9d53c2d3e0340ec194ecca9aa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: amrlib-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 78.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for amrlib-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 93847f44325d7e1bfb6dd9478f7181cacf615270b04990811c184acaaa045654
MD5 9107e7c9a71c91afb27e425dd1e1a59f
BLAKE2b-256 cfcf3c6dd4be75660e3e75a481ee3796b111e1aab3ad6c7176c1612e08d4f5eb

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