Part of Speech for Chinese

Description

This model annotates the part of speech of tokens in a text. The parts of speech annotated include PRON (pronoun), CCONJ (coordinating conjunction), and 15 others. The part of speech model is useful for extracting the grammatical structure of a piece of text automatically.

Open in Colab Download

How to use

...
pos = PerceptronModel.pretrained("pos_ud_gsd", "zh") \
    .setInputCols(["document", "token"]) \
    .setOutputCol("pos")
nlp_pipeline = Pipeline(stages=[document_assembler, sentence_detector, tokenizer, pos])
light_pipeline = LightPipeline(nlp_pipeline.fit(spark.createDataFrame([['']]).toDF("text")))
results = light_pipeline.fullAnnotate("除了担任北方国王之外,约翰·斯诺(John Snow)是一位英国医师,也是麻醉和医疗卫生发展的领导者。")
...
val pos = PerceptronModel.pretrained("pos_ud_gsd", "zh")
    .setInputCols(Array("document", "token"))
    .setOutputCol("pos")
val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector, tokenizer, pos))
val result = pipeline.fit(Seq.empty["除了担任北方国王之外约翰·斯诺John Snow是一位英国医师也是麻醉和医疗卫生发展的领导者。"].toDS.toDF("text")).transform(data)
import nlu

text = ["""除了担任北方国王之外,约翰·斯诺(John Snow)是一位英国医师,也是麻醉和医疗卫生发展的领导者。"""]
pos_df = nlu.load('zh.pos.ud_gsd').predict(text, output_level='token')
pos_df

Results

[Row(annotatorType='pos', begin=0, end=20, result='NOUN', metadata={'word': '除了担任北方国王之外,约翰·斯诺(John'}),
Row(annotatorType='pos', begin=22, end=50, result='X', metadata={'word': 'Snow)是一位英国医师,也是麻醉和医疗卫生发展的领导者。'}),
...]

Model Information

Model Name: pos_ud_gsd
Type: pos
Compatibility: Spark NLP 2.5.0+
Edition: Official
Input labels: [token]
Output labels: [pos]
Language: zh
Case sensitive: false
License: Open Source

Data Source

The model is imported from https://universaldependencies.org