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
- ADJ
- ADP
- ADV
- AUX
- CCONJ
- DET
- NOUN
- NUM
- PART
- PRON
- PROPN
- PUNCT
- VERB
- X
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")
tokenizer = Tokenizer()\
.setInputCols("sentence")\
.setOutputCol("token")
pos = PerceptronModel.pretrained("pos_vtb", "vi") \
.setInputCols(["document", "token"]) \
.setOutputCol("pos")
pipeline = Pipeline(stages=[
document_assembler,
sentence_detector,
tokenizer,
posTagger
])
example = spark.createDataFrame([['Thắng sẽ tìm nghề mới cho Lan .']], ["text"])
result = pipeline.fit(example).transform(example)
val document_assembler = DocumentAssembler()
.setInputCol("text")
.setOutputCol("document")
val sentence_detector = SentenceDetector()
.setInputCols("document")
.setOutputCol("sentence")
val tokenizer = Tokenizer()
.setInputCols("sentence")
.setOutputCol("token")
val pos = PerceptronModel.pretrained("pos_vtb", "vi")
.setInputCols(Array("document", "token"))
.setOutputCol("pos")
val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector,tokenizer, pos))
val data = Seq("Thắng sẽ tìm nghề mới cho Lan .").toDF("text")
val result = pipeline.fit(data).transform(data)
import nlu
text = [""Thắng sẽ tìm nghề mới cho Lan .""]
token_df = nlu.load('vi.pos.vtb').predict(text)
token_df
Results
+-------------------------------+--------------------------------------------+
|text |result |
+-------------------------------+--------------------------------------------+
|Thắng sẽ tìm nghề mới cho Lan .|[NOUN, X, VERB, NOUN, ADJ, ADP, NOUN, PUNCT]|
+-------------------------------+--------------------------------------------+
Model Information
Model Name: | pos_vtb |
Compatibility: | Spark NLP 2.7.5+ |
License: | Open Source |
Edition: | Official |
Input Labels: | [sentence, token] |
Output Labels: | [pos] |
Language: | vi |
Data Source
The model was trained on the Universal Dependencies data set.
Benchmarking
| | precision | recall | f1-score | support |
|--------------|-----------|--------|----------|---------|
| ADJ | 0.58 | 0.49 | 0.53 | 738 |
| ADP | 0.84 | 0.87 | 0.86 | 688 |
| AUX | 0.79 | 0.95 | 0.87 | 132 |
| CCONJ | 0.85 | 0.80 | 0.83 | 335 |
| DET | 0.95 | 0.85 | 0.90 | 232 |
| INTJ | 1.00 | 0.14 | 0.25 | 7 |
| NOUN | 0.84 | 0.86 | 0.85 | 3838 |
| NUM | 0.94 | 0.91 | 0.92 | 412 |
| PART | 0.53 | 0.30 | 0.38 | 87 |
| PROPN | 0.85 | 0.85 | 0.85 | 494 |
| PUNCT | 0.97 | 0.99 | 0.98 | 1722 |
| SCONJ | 0.99 | 0.98 | 0.98 | 122 |
| VERB | 0.73 | 0.76 | 0.74 | 2178 |
| X | 0.81 | 0.76 | 0.79 | 970 |
| accuracy | | | 0.83 | 11955 |
| macro avg | 0.83 | 0.75 | 0.77 | 11955 |
| weighted avg | 0.83 | 0.83 | 0.83 | 11955 |