Files
2026-07-13 12:37:18 +08:00

1.3 KiB

jupytext, kernelspec
jupytext kernelspec
formats text_representation
ipynb,md:myst
extension format_name format_version jupytext_version
.md myst 0.8 1.4.2
display_name language name
Python 3 python python3

amr2text

AMR captures “who is doing what to whom” in a sentence. Each sentence is represented as a rooted, directed, acyclic graph with labels on edges (relations) and leaves (concepts). The goal of AMR-to-Text Generation is to recover the original sentence realization given an AMR. This task can be seen as the reverse of the structured prediction found in AMR parsing. Before loading an AMR model, make sure to install HanLP with the amr dependencies:

pip install hanlp[amr] -U

To generate a sentence given an AMR:

.. margin:: Batching is Faster

    .. Hint:: Generate multiple sentences at once for faster speed! 
:tags: [output_scroll]
import hanlp

generation = hanlp.load(hanlp.pretrained.amr2text.AMR3_GRAPH_PRETRAIN_GENERATION)
print(generation('''
(z0 / want-01
    :ARG0 (z1 / boy)
    :ARG1 (z2 / believe-01
              :ARG0 (z3 / girl)
              :ARG1 z1))
'''))

All the pre-trained parsers and their scores are listed below.


.. automodule:: hanlp.pretrained.amr2text
    :members: