Skip to main content

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
      see note at the bottom about smatch scoring
    • BLEU for sentence generation
    • Alignment scoring metrics detailing precision/recall

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.
    For a technical description of the parse model see its wiki-page

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

AMR View

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

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.

Metadata

Release files for amrlib 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for amrlib 0.8.1
File Size Uploaded
amrlib-0.8.1.tar.gz 329.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for amrlib 0.8.1
File Interpreter ABI Platform
amrlib-0.8.1-py3-none-any.whl Python 3 none any Details

Total release size: 682.6 kB

Release files / amrlib-0.8.1.tar.gz

Download URL amrlib-0.8.1.tar.gz
Size 329.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9bafc4bde8c61e3c9d4d809ec3865f597961b9a422bd69ccbb5f6981ff853871
BLAKE2b-256 checksum
How to use checksums
3899d4737c74a4a8212add786b66999aea317399007dbc360042b2eb2eadfc38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / amrlib-0.8.1-py3-none-any.whl

Download URL amrlib-0.8.1-py3-none-any.whl
Size 353.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c493b0bf25e700fbf81200271b5bf23dfa3773fb588e895dc6ed20988f0488df
BLAKE2b-256 checksum
How to use checksums
52d942c8617d2eb3431702e14eb7137321e5111ba71015b8abfc5a475f90c5c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.8.1 This release

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page