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_mtg", "te") \
.setInputCols(["document", "token"]) \
.setOutputCol("pos")
pipeline = Pipeline(stages=[
document_assembler,
sentence_detector,
tokenizer,
posTagger
])
example = spark.createDataFrame([['ఆయన వస్తున్నారా , లేదా ?']], ["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_mtg", "te")
.setInputCols(Array("document", "token"))
.setOutputCol("pos")
val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector,tokenizer, pos))
val data = Seq("ఆయన వస్తున్నారా , లేదా ?").toDF("text")
val result = pipeline.fit(data).transform(data)
import nlu
text = [""ఆయన వస్తున్నారా , లేదా ?""]
token_df = nlu.load('te.pos.mtg').predict(text)
token_df
Results
+------------------------+--------------------------------+
|text                    |result                          |
+------------------------+--------------------------------+
|ఆయన వస్తున్నారా , లేదా ?|[PRON, VERB, PUNCT, VERB, PUNCT]|
+------------------------+--------------------------------+
Model Information
| Model Name: | pos_mtg | 
| Compatibility: | Spark NLP 2.7.5+ | 
| License: | Open Source | 
| Edition: | Official | 
| Input Labels: | [sentence, token] | 
| Output Labels: | [pos] | 
| Language: | te | 
Data Source
The model was trained on the Universal Dependencies data set.
Benchmarking
|              | precision | recall | f1-score | support |
|--------------|-----------|--------|----------|---------|
| ADJ          | 0.50      | 0.40   | 0.44     | 5       |
| ADP          | 0.75      | 0.43   | 0.55     | 7       |
| ADV          | 0.78      | 0.68   | 0.72     | 31      |
| CCONJ        | 0.00      | 0.00   | 0.00     | 1       |
| DET          | 0.89      | 0.89   | 0.89     | 18      |
| INTJ         | 0.00      | 0.00   | 0.00     | 0       |
| NOUN         | 0.82      | 0.76   | 0.79     | 171     |
| NUM          | 0.83      | 0.42   | 0.56     | 12      |
| PART         | 0.00      | 0.00   | 0.00     | 2       |
| PRON         | 0.88      | 0.93   | 0.91     | 122     |
| PROPN        | 0.69      | 0.86   | 0.77     | 21      |
| PUNCT        | 0.99      | 0.99   | 0.99     | 165     |
| SCONJ        | 0.71      | 1.00   | 0.83     | 5       |
| VERB         | 0.84      | 0.92   | 0.88     | 161     |
| accuracy     |           |        | 0.87     | 721     |
| macro avg    | 0.62      | 0.59   | 0.59     | 721     |
| weighted avg | 0.87      | 0.87   | 0.86     | 721     |