Part of Speech for Slovak

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_snk", "sk")\
.setInputCols(["document", "token"])\
.setOutputCol("pos")

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

example = spark.createDataFrame([['Potom Maju nežne pohladila po hlávke a vraví : Spoznáš krásny veľký svet , Maja , hrejivé slniečko a nádherné lúky plné kvetov .']], ["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_snk", "sk")
.setInputCols(Array("document", "token"))
.setOutputCol("pos")

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

val data = Seq("Potom Maju nežne pohladila po hlávke a vraví : Spoznáš krásny veľký svet , Maja , hrejivé slniečko a nádherné lúky plné kvetov .").toDF("text")
val result = pipeline.fit(data).transform(data)
import nlu

text = [""Potom Maju nežne pohladila po hlávke a vraví : Spoznáš krásny veľký svet , Maja , hrejivé slniečko a nádherné lúky plné kvetov .""]
token_df = nlu.load('sk.pos.snk').predict(text)
token_df

Results

+--------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
|text                                                                                                                            |result                                                                                                                                          |
+--------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
|Potom Maju nežne pohladila po hlávke a vraví : Spoznáš krásny veľký svet , Maja , hrejivé slniečko a nádherné lúky plné kvetov .|[ADV, PROPN, ADV, VERB, ADP, NOUN, CCONJ, VERB, PUNCT, VERB, ADJ, ADJ, NOUN, PUNCT, PROPN, PUNCT, ADJ, NOUN, CCONJ, ADJ, NOUN, ADJ, NOUN, PUNCT]|
+--------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+

Model Information

Model Name: pos_snk
Compatibility: Spark NLP 2.7.5+
License: Open Source
Edition: Official
Input Labels: [sentence, token]
Output Labels: [pos]
Language: sk

Data Source

The model was trained on the Universal Dependencies data set.

Benchmarking

|              | precision | recall | f1-score | support |
|--------------|-----------|--------|----------|---------|
| ADJ          | 0.91      | 0.91   | 0.91     | 1711    |
| ADP          | 0.99      | 0.99   | 0.99     | 1188    |
| ADV          | 0.82      | 0.82   | 0.82     | 442     |
| AUX          | 0.96      | 0.93   | 0.94     | 302     |
| CCONJ        | 0.97      | 0.92   | 0.95     | 447     |
| DET          | 0.94      | 0.95   | 0.94     | 504     |
| NOUN         | 0.90      | 0.96   | 0.93     | 3287    |
| NUM          | 0.97      | 0.92   | 0.94     | 412     |
| PART         | 0.73      | 0.77   | 0.75     | 177     |
| PRON         | 0.97      | 0.97   | 0.97     | 380     |
| PROPN        | 0.90      | 0.79   | 0.84     | 879     |
| PUNCT        | 1.00      | 1.00   | 1.00     | 1806    |
| SCONJ        | 0.99      | 0.98   | 0.99     | 182     |
| SYM          | 1.00      | 0.14   | 0.25     | 14      |
| VERB         | 0.93      | 0.94   | 0.93     | 1176    |
| X            | 0.60      | 0.25   | 0.35     | 121     |
| accuracy     |           |        | 0.93     | 13028   |
| macro avg    | 0.91      | 0.83   | 0.84     | 13028   |
| weighted avg | 0.93      | 0.93   | 0.93     | 13028   |