1.3 KiB
1.3 KiB
jupytext, kernelspec
| jupytext | kernelspec | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
constituency
Constituency Parsing is the process of analyzing the sentences by breaking down it into sub-phrases also known as constituents.
To parse a tokenized sentence into constituency tree, first load a parser:
.. margin:: Batching is Faster
.. Hint:: To speed up, parse multiple sentences at once, and use a GPU.
:tags: [output_scroll]
import hanlp
con = hanlp.load(hanlp.pretrained.constituency.CTB9_CON_FULL_TAG_ELECTRA_SMALL)
Then parse a sequence or multiple sequences of tokens to it.
:tags: [output_scroll]
tree = con(["2021年", "HanLPv2.1", "带来", "最", "先进", "的", "多", "语种", "NLP", "技术", "。"])
The constituency tree is a nested list of constituencies:
:tags: [output_scroll]
tree
You can str or print it to get its bracketed form:
:tags: [output_scroll]
print(tree)
All the pre-trained parsers and their scores are listed below.
.. automodule:: hanlp.pretrained.constituency
:members: