Skip to main content

Morphological Evaluation of NLG

L'AMBRE is a tool to measure the grammatical well-formedness of texts generated by NLG systems. It analyzes the dependency parses of the text using morpho-syntactic rules, and returns a well-formedness score. This tool utilizes the Surface Syntactic Universal Dependency (SUD) project both for extracting rules as well as parsing, and is therefore applicable across languages. See our EMNLP 2021 paper for more details.

Getting Started

Install from PyPI

python -m pip install lambre

Try L'AMBRE

For a given input text file, lambre computes a morpho-syntactic well-formedness score [0-1]. The following method first downloads the parsers and rule sets for the specified language before computing the document-level score. See the output folder (out) for error visualizations.

>>> import lambre
>>> with open("data/txt/ru.txt", "r") as rf:
...     data = rf.readlines()
>>> lambre.score("ru", data)
0.9962

L'AMBRE can also be used from command line. See lambre --help for more options.

lambre ru data/txt/ru.txt

Morpho-syntactic Rules

lambre currently supports two rule sets, chaudhary-etal-2021 (see Chaudhary et al., 2020, 2021) and pratapa-etal-2021 (see Pratapa et al., 2021). The former is the default, but the rule set can be specified using --rule-set option.

Visualization Examples

Along with the overall L'AMBRE score, we write the erroneous sentences to the output folder out/errors. We provide two visualizations, i) plain text (errors.txt), ii) HTML (errors/*.html). For plain text visualization, we use the ipymarkup tool. We use brat and Universal Dependencies for HTML visualizations.

Below is a sample run on 1000 example Hindi sentences from the Samanantar corpus.

>>> import lambre
>>> with open("examples/hi_sents_1k.txt", "r") as rf:
...     data = rf.readlines()
>>> lambre.score("hi", data)
0.8821

A few erroneous sentences from this corpus (as detected by L'AMBRE):

Input sentence: संख्या की स्टाफ प्रशिक्षित में हिंदी/वाले जानने हिंदी
                 (Stenography Hindi in trained persons of No.)
                 
                 तीनवर्षतक अग्रनीत किए| जाने के बाद व्यपगत हुए| आरक्षणों की| संख्या
                 (of after forward No. reservations lapsed carrying for 3 years)

Below, we show the visualizations of word order related errors for the above two sentences. We also generate separate files for agreement and case marking (see examples/ for full HTML outputs).

errors in word order

errors in word order

Parser

We provide SUD parsers trained using Stanza toolkit. See section 4 in our paper for more details.

Supported Languages

We currently support the following languages. lambre automatically downloads the necessary language-specific resources (when available).

Language Code Language Code Language Code Language Code
Catalan ca Spanish es Italian it Russian ru
Czech cs Estonian et Latvian lv Slovenian sl
Danish da Persian fa Dutch nl Swedish sv
German de French fr Polish pl Ukrainian uk
Greek el Hindi hi Portuguese pt Urdu ur
English en Indonesian id Romanian ro

To manually download rules or parsers for a given language,

>>> import lambre
>>> lambre.download("ru") # Russian

Reference

If you find this toolkit helpful in your research, consider citing our paper,

@inproceedings{pratapa-etal-2021-evaluating,
    title = "Evaluating the Morphosyntactic Well-formedness of Generated Texts",
    author = "Pratapa, Adithya  and
      Anastasopoulos, Antonios  and
      Rijhwani, Shruti  and
      Chaudhary, Aditi  and
      Mortensen, David R.  and
      Neubig, Graham  and
      Tsvetkov, Yulia",
    booktitle = "Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing",
    month = nov,
    year = "2021",
    address = "Online and Punta Cana, Dominican Republic",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2021.emnlp-main.570",
    pages = "7131--7150",
}

We also encourage you to cite the original works for the chaudhary-etal-2021 ruleset, Chaudhary et al., 2020 and Chaudhary et al., 2021.

License

L'AMBRE is available under MIT License. The code for training parsers is adapted from stanza, which is available under Apache License, Version 2.0.

Issues

For any issues, questions or requests, please use the Github Issue Tracker.

Release files for lambre 2.0.2

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

Source distribution (sdist)

Source distribution for lambre 2.0.2
File Size Uploaded
lambre-2.0.2.tar.gz 28.7 kB Details

Built distribution (wheel)

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

Total release size: 58.0 kB

Release files / lambre-2.0.2.tar.gz

Download URL lambre-2.0.2.tar.gz
Size 28.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0d0fff7222772239fc0288b8939aa30acff0a27f48da1991d12bfd6b6424da83
BLAKE2b-256 checksum
How to use checksums
9d40275d0b8a9da3290e02e0cf76818eacee8ae09564340fa3f08b8664583a05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.13

Release files / lambre-2.0.2-py3-none-any.whl

Download URL lambre-2.0.2-py3-none-any.whl
Size 29.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e858ef29681b1c2ae37e463c029842cb97d448079282f919f0d6ac62c61cade
BLAKE2b-256 checksum
How to use checksums
e49285d5562e5c322f487fec8f338c833a812a694c4f67721a347e8896b226c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.13

Release history Release notifications | RSS feed

This release

2.0.2 This release

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.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