Part of Speech for Chinese

Description

A Part of Speech classifier predicts a grammatical label for every token in the input text. Implemented with an averaged perceptron architecture.

Predicted Entities

  • AUX
  • ADJ
  • PUNCT
  • ADV
  • VERB
  • NUM
  • NOUN
  • PRON
  • PART
  • ADP
  • DET
  • CCONJ
  • PROPN
  • X
  • SYM

Live Demo Open in Colab Download Copy S3 URI

How to use


document_assembler = DocumentAssembler() \
  .setInputCol("text") \
  .setOutputCol("document")

sentence_detector = SentenceDetector() \
  .setInputCols(["document"]) \
  .setOutputCol("sentence")

pos = PerceptronModel.pretrained("pos_ud_gsd_trad", "zh") \
  .setInputCols(["document", "token"]) \
  .setOutputCol("pos")

pipeline = Pipeline(stages=[
  document_assembler,
  sentence_detector,
  posTagger
])

example = spark.createDataFrame([['从John Snow Labs你好! ']], ["text"])

result = pipeline.fit(example).transform(example)



val document_assembler = DocumentAssembler()
        .setInputCol("text")
        .setOutputCol("document")

val sentence_detector = SentenceDetector()
        .setInputCols("document")
.setOutputCol("sentence")

val pos = PerceptronModel.pretrained("pos_ud_gsd_trad", "zh")
        .setInputCols(Array("document", "token"))
        .setOutputCol("pos")

val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector, pos))

val data = Seq("从John Snow Labs你好! ").toDF("text")
val result = pipeline.fit(data).transform(data)


import nlu
text = [""从John Snow Labs你好 ""]
token_df = nlu.load('zh.pos.ud_gsd_trad').predict(text)
token_df
    

Results

          token    pos
                      
0             从  PROPN
1  JohnSnowLabs      X
2             你   PRON
3             好    ADJ
4             !  PUNCT

Model Information

Model Name: pos_ud_gsd_trad
Compatibility: Spark NLP 3.0.0+
License: Open Source
Edition: Official
Input Labels: [document, token]
Output Labels: [pos]
Language: zh