tadejmagajna
commited on
Commit
β’
bf0e122
1
Parent(s):
4e8b9ed
Update README.md
Browse files
README.md
CHANGED
@@ -7,4 +7,114 @@ language: sl
|
|
7 |
widget:
|
8 |
- text: "Danes je lep dan."
|
9 |
---
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
widget:
|
8 |
- text: "Danes je lep dan."
|
9 |
---
|
10 |
+
|
11 |
+
## Slovene PoS Tagger for Flair
|
12 |
+
|
13 |
+
This is a Slovene PoS tagger trained on the [Slovenian UD Treebank](https://github.com/UniversalDependencies/UD_Slovenian-SSJ) using Flair NLP framework.
|
14 |
+
|
15 |
+
The tagger is trained using a combination of forward Slovene contextual string embeddings, backward Slovene contextual string embeddings and classic Slovene FastText embeddings.
|
16 |
+
|
17 |
+
F-score (micro): **94,96**
|
18 |
+
|
19 |
+
The model is trained on a large (500+) number of different tags that described at [https://universaldependencies.org/tagset-conversion/sl-multext-uposf.html](https://universaldependencies.org/tagset-conversion/sl-multext-uposf.html).
|
20 |
+
|
21 |
+
Based on [Flair embeddings](https://www.aclweb.org/anthology/C18-1139/) and LSTM-CRF.
|
22 |
+
|
23 |
+
---
|
24 |
+
### Demo: How to use in Flair
|
25 |
+
|
26 |
+
Requires: **[Flair](https://github.com/flairNLP/flair/)** (`pip install flair`)
|
27 |
+
```python
|
28 |
+
from flair.data import Sentence
|
29 |
+
from flair.models import SequenceTagger
|
30 |
+
|
31 |
+
# load tagger
|
32 |
+
tagger = SequenceTagger.load("tadejmagajna/flair-sl-pos")
|
33 |
+
|
34 |
+
# make example sentence
|
35 |
+
sentence = Sentence("Danes je lep dan.")
|
36 |
+
|
37 |
+
# predict PoS tags
|
38 |
+
tagger.predict(sentence)
|
39 |
+
|
40 |
+
# print sentence
|
41 |
+
print(sentence)
|
42 |
+
|
43 |
+
# print predicted PoS spans
|
44 |
+
print('The following PoS tags are found:')
|
45 |
+
# iterate over parts of speech and print
|
46 |
+
for tag in sentence.get_spans('pos'):
|
47 |
+
print(tag)
|
48 |
+
```
|
49 |
+
|
50 |
+
This prints out the following output:
|
51 |
+
```
|
52 |
+
Sentence: "Danes je lep dan ." [β Tokens: 5 β Token-Labels: "Danes <Rgp> je <Va-r3s-n> lep <Agpmsnn> dan <Ncmsn> . <Z>"]
|
53 |
+
The following PoS tags are found:
|
54 |
+
Span [1]: "Danes" [β Labels: Rgp (1.0)]
|
55 |
+
Span [2]: "je" [β Labels: Va-r3s-n (1.0)]
|
56 |
+
Span [3]: "lep" [β Labels: Agpmsnn (0.9999)]
|
57 |
+
Span [4]: "dan" [β Labels: Ncmsn (1.0)]
|
58 |
+
Span [5]: "." [β Labels: Z (1.0)]
|
59 |
+
```
|
60 |
+
|
61 |
+
---
|
62 |
+
### Training: Script to train this model
|
63 |
+
The following standard Flair script was used to train this model:
|
64 |
+
|
65 |
+
```python
|
66 |
+
from flair.data import Corpus
|
67 |
+
from flair.datasets import UD_SLOVENIAN
|
68 |
+
from flair.embeddings import WordEmbeddings, StackedEmbeddings, FlairEmbeddings
|
69 |
+
|
70 |
+
# 1. get the corpus
|
71 |
+
corpus: Corpus = UD_SLOVENIAN()
|
72 |
+
|
73 |
+
# 2. what tag do we want to predict?
|
74 |
+
tag_type = 'pos'
|
75 |
+
|
76 |
+
# 3. make the tag dictionary from the corpus
|
77 |
+
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
|
78 |
+
|
79 |
+
# 4. initialize embeddings
|
80 |
+
embedding_types = [
|
81 |
+
WordEmbeddings('sl'),
|
82 |
+
FlairEmbeddings('sl-forward'),
|
83 |
+
FlairEmbeddings('sl-backward'),
|
84 |
+
]
|
85 |
+
embeddings: StackedEmbeddings = StackedEmbeddings(embeddings=embedding_types)
|
86 |
+
|
87 |
+
# 5. initialize sequence tagger
|
88 |
+
from flair.models import SequenceTagger
|
89 |
+
|
90 |
+
tagger: SequenceTagger = SequenceTagger(hidden_size=256,
|
91 |
+
embeddings=embeddings,
|
92 |
+
tag_dictionary=tag_dictionary,
|
93 |
+
tag_type=tag_type)
|
94 |
+
|
95 |
+
# 6. initialize trainer
|
96 |
+
from flair.trainers import ModelTrainer
|
97 |
+
|
98 |
+
trainer: ModelTrainer = ModelTrainer(tagger, corpus)
|
99 |
+
|
100 |
+
# 7. start training
|
101 |
+
trainer.train('resources/taggers/pos-slovene',
|
102 |
+
train_with_dev=True,
|
103 |
+
max_epochs=150)
|
104 |
+
```
|
105 |
+
|
106 |
+
---
|
107 |
+
### Cite
|
108 |
+
Please cite the following paper when using this model.
|
109 |
+
```
|
110 |
+
@inproceedings{akbik2018coling,
|
111 |
+
title={Contextual String Embeddings for Sequence Labeling},
|
112 |
+
author={Akbik, Alan and Blythe, Duncan and Vollgraf, Roland},
|
113 |
+
booktitle = {{COLING} 2018, 27th International Conference on Computational Linguistics},
|
114 |
+
pages = {1638--1649},
|
115 |
+
year = {2018}
|
116 |
+
}
|
117 |
+
```
|
118 |
+
---
|
119 |
+
### Issues?
|
120 |
+
The Flair issue tracker is available [here](https://github.com/flairNLP/flair/issues/).
|