Part of Speech for Bulgarian

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_btb", "bg")\
.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_btb", "bg")
.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('bg.pos.btb').predict(text)
token_df

Results

+--------------------------------------------+-------------------------------------------------+
|text                                        |result                                           |
+--------------------------------------------+-------------------------------------------------+
|Столица на Република България е град София .|[NOUN, ADP, NOUN, PROPN, AUX, NOUN, PROPN, PUNCT]|
+--------------------------------------------+-------------------------------------------------+

Model Information

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

Data Source

The model was trained on the Universal Dependencies data set.

Benchmarking

|              | precision | recall | f1-score | support |
|--------------|-----------|--------|----------|---------|
| ADJ          | 0.89      | 0.87   | 0.88     | 1377    |
| ADP          | 0.95      | 0.95   | 0.95     | 2238    |
| ADV          | 0.94      | 0.92   | 0.93     | 671     |
| AUX          | 0.98      | 0.97   | 0.97     | 916     |
| CCONJ        | 0.96      | 0.95   | 0.96     | 467     |
| DET          | 0.91      | 0.88   | 0.90     | 273     |
| INTJ         | 1.00      | 1.00   | 1.00     | 1       |
| NOUN         | 0.92      | 0.93   | 0.93     | 3486    |
| NUM          | 0.89      | 0.87   | 0.88     | 223     |
| PART         | 0.98      | 0.96   | 0.97     | 210     |
| PRON         | 0.97      | 0.97   | 0.97     | 981     |
| PROPN        | 0.88      | 0.89   | 0.89     | 805     |
| PUNCT        | 0.95      | 0.96   | 0.95     | 2268    |
| SCONJ        | 0.98      | 0.97   | 0.98     | 156     |
| VERB         | 0.95      | 0.94   | 0.94     | 1652    |
| accuracy     |           |        | 0.94     | 15724   |
| macro avg    | 0.94      | 0.94   | 0.94     | 15724   |
| weighted avg | 0.94      | 0.94   | 0.94     | 15724   |