Part of Speech for Swedish

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

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

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

example = spark.createDataFrame([["' Medicinsk bildtolk ' också skall fungera som hjälpmedel för läkaren att klarlägga sjukdomsbilden utan att patienten behöver säga ett ord ."]], ["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_talbanken", "sv")
.setInputCols(Array("document", "token"))
.setOutputCol("pos")

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

val data = Seq(" Medicinsk bildtolk " också skall fungera som hjälpmedel för läkaren att klarlägga sjukdomsbilden utan att patienten behöver säga ett ord .").toDF("text")
val result = pipeline.fit(data).transform(data)
import nlu

text = [""' Medicinsk bildtolk ' också skall fungera som hjälpmedel för läkaren att klarlägga sjukdomsbilden utan att patienten behöver säga ett ord .""]
token_df = nlu.load('sv.pos.talbanken').predict(text)
token_df

Results

+---------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------+
|text                                                                                                                                         |result                                                                                                                            |
+---------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------+
|' Medicinsk bildtolk ' också skall fungera som hjälpmedel för läkaren att klarlägga sjukdomsbilden utan att patienten behöver säga ett ord . |[PUNCT, ADJ, NOUN, PUNCT, ADV, AUX, VERB, SCONJ, NOUN, ADP, NOUN, PART, VERB, NOUN, ADP, SCONJ, NOUN, AUX, VERB, DET, NOUN, PUNCT]|
+---------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------+

Model Information

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

Data Source

The model was trained on the Universal Dependencies data set.

Benchmarking

|              | precision | recall | f1-score | support |
|--------------|-----------|--------|----------|---------|
| ADJ          | 0.88      | 0.89   | 0.89     | 1826    |
| ADP          | 0.96      | 0.96   | 0.96     | 2298    |
| ADV          | 0.91      | 0.87   | 0.89     | 1528    |
| AUX          | 0.91      | 0.93   | 0.92     | 1021    |
| CCONJ        | 0.95      | 0.94   | 0.94     | 791     |
| DET          | 0.92      | 0.95   | 0.93     | 1015    |
| INTJ         | 1.00      | 0.33   | 0.50     | 3       |
| NOUN         | 0.94      | 0.95   | 0.95     | 4711    |
| NUM          | 0.98      | 0.96   | 0.97     | 357     |
| PART         | 0.93      | 0.94   | 0.94     | 406     |
| PRON         | 0.94      | 0.91   | 0.92     | 1449    |
| PROPN        | 0.88      | 0.83   | 0.85     | 243     |
| PUNCT        | 0.97      | 0.98   | 0.98     | 2104    |
| SCONJ        | 0.86      | 0.82   | 0.84     | 491     |
| SYM          | 0.50      | 1.00   | 0.67     | 1       |
| VERB         | 0.90      | 0.90   | 0.90     | 2142    |
| accuracy     |           |        | 0.93     | 20386   |
| macro avg    | 0.90      | 0.89   | 0.88     | 20386   |
| weighted avg | 0.93      | 0.93   | 0.93     | 20386   |