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_icepahc", "is")\
.setInputCols(["document", "token"])\
.setOutputCol("pos")
pipeline = Pipeline(stages=[
document_assembler,
sentence_detector,
tokenizer,
posTagger
])
example = spark.createDataFrame([['Númerið blikkaði á skjánum eins og einmana vekjaraklukka um nótt á níundu hæð í gamalli blokk í austurbæ Reykjavíkur .']], ["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_icepahc", "is")
.setInputCols(Array("document", "token"))
.setOutputCol("pos")
val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector,tokenizer, pos))
val data = Seq("Númerið blikkaði á skjánum eins og einmana vekjaraklukka um nótt á níundu hæð í gamalli blokk í austurbæ Reykjavíkur .").toDF("text")
val result = pipeline.fit(data).transform(data)
import nlu
text = [""Númerið blikkaði á skjánum eins og einmana vekjaraklukka um nótt á níundu hæð í gamalli blokk í austurbæ Reykjavíkur .""]
token_df = nlu.load('is.pos.icepahc').predict(text)
token_df
Results
+----------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+
|text |result |
+----------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+
|Númerið blikkaði á skjánum eins og einmana vekjaraklukka um nótt á níundu hæð í gamalli blokk í austurbæ Reykjavíkur .|[NOUN, VERB, ADP, NOUN, ADV, ADP, ADJ, NOUN, ADP, NOUN, ADP, ADJ, NOUN, ADP, ADJ, NOUN, ADP, PROPN, PROPN, PUNCT]|
+----------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------+
Model Information
Model Name: | pos_icepahc |
Compatibility: | Spark NLP 2.7.5+ |
License: | Open Source |
Edition: | Official |
Input Labels: | [sentence, token] |
Output Labels: | [pos] |
Language: | is |
Data Source
The model was trained on the Universal Dependencies data set.
Benchmarking
| | precision | recall | f1-score | support |
|--------------|-----------|--------|----------|---------|
| ADJ | 0.81 | 0.74 | 0.78 | 5906 |
| ADP | 0.95 | 0.96 | 0.96 | 15548 |
| ADV | 0.90 | 0.90 | 0.90 | 10631 |
| AUX | 0.92 | 0.93 | 0.92 | 7416 |
| CCONJ | 0.96 | 0.97 | 0.96 | 8437 |
| DET | 0.89 | 0.87 | 0.88 | 7476 |
| INTJ | 0.95 | 0.77 | 0.85 | 131 |
| NOUN | 0.90 | 0.92 | 0.91 | 20726 |
| NUM | 0.75 | 0.83 | 0.79 | 655 |
| PART | 0.96 | 0.96 | 0.96 | 1703 |
| PRON | 0.94 | 0.96 | 0.95 | 16852 |
| PROPN | 0.89 | 0.89 | 0.89 | 4444 |
| PUNCT | 0.98 | 0.98 | 0.98 | 16434 |
| SCONJ | 0.94 | 0.94 | 0.94 | 5663 |
| VERB | 0.92 | 0.90 | 0.91 | 17329 |
| X | 0.60 | 0.30 | 0.40 | 346 |
| accuracy | | | 0.92 | 139697 |
| macro avg | 0.89 | 0.86 | 0.87 | 139697 |
| weighted avg | 0.92 | 0.92 | 0.92 | 139697 |