Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
datasets:
|
| 3 |
+
- psytechlab/rus_rudeft_wcl-wiki
|
| 4 |
+
language:
|
| 5 |
+
- ru
|
| 6 |
+
base_model:
|
| 7 |
+
- DeepPavlov/rubert-base-cased
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# RuBERT base fine-tuned on ruDEFT and WCL Wiki Ru datasets for NER
|
| 11 |
+
The model aims to extract terms and defenitions in a text.
|
| 12 |
+
Labels:
|
| 13 |
+
- Term
|
| 14 |
+
- Definition
|
| 15 |
+
|
| 16 |
+
```python
|
| 17 |
+
import torch
|
| 18 |
+
import numpy as np
|
| 19 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
| 20 |
+
|
| 21 |
+
tokenizer = AutoTokenizer.from_pretrained("psytechlab/wcl-wiki_rudeft__ner-model")
|
| 22 |
+
model = AutoModelForTokenClassification.from_pretrained("psytechlab/wcl-wiki_rudeft__ner-model")
|
| 23 |
+
model.eval()
|
| 24 |
+
|
| 25 |
+
inputs = tokenizer('оромо — это африканская этническая группа, проживающая в эфиопии и в меньшей степени в кении.', return_tensors="pt")
|
| 26 |
+
with torch.no_grad():
|
| 27 |
+
outputs = model(**inputs)
|
| 28 |
+
|
| 29 |
+
logits = outputs.logits
|
| 30 |
+
predictions = torch.argmax(logits, dim=-1)[0].tolist()
|
| 31 |
+
|
| 32 |
+
tokens = inputs["input_ids"][0]
|
| 33 |
+
word_ids = inputs.word_ids(batch_index=0)
|
| 34 |
+
|
| 35 |
+
word_to_labels = {}
|
| 36 |
+
for token_id, word_id, label_id in zip(tokens, word_ids, predictions):
|
| 37 |
+
if word_id is None:
|
| 38 |
+
continue
|
| 39 |
+
if word_id not in word_to_labels:
|
| 40 |
+
word_to_labels[word_id] = []
|
| 41 |
+
word_to_labels[word_id].append(label_id)
|
| 42 |
+
|
| 43 |
+
word_level_predictions = [model.config.id2label[labels[0]] for labels in word_to_labels.values()]
|
| 44 |
+
|
| 45 |
+
print(word_level_predictions)
|
| 46 |
+
# ['B-Term', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O']
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
## Training procedure
|
| 50 |
+
|
| 51 |
+
### Training
|
| 52 |
+
The training was done with Trainier class that has next parameters:
|
| 53 |
+
```python
|
| 54 |
+
training_args = TrainingArguments(
|
| 55 |
+
eval_strategy="epoch",
|
| 56 |
+
save_strategy="epoch",
|
| 57 |
+
learning_rate=2e-5,
|
| 58 |
+
num_train_epochs=7,
|
| 59 |
+
weight_decay=0.01,
|
| 60 |
+
)
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
### Metrics
|
| 64 |
+
Metrics on combined set (ruDEFT + WCL Wiki Ru) `psytechlab/rus_rudeft_wcl-wiki`:
|
| 65 |
+
```python
|
| 66 |
+
precision recall f1-score support
|
| 67 |
+
|
| 68 |
+
I-Definition 0.75 0.90 0.82 3344
|
| 69 |
+
B-Definition 0.62 0.73 0.67 230
|
| 70 |
+
I-Term 0.80 0.85 0.82 524
|
| 71 |
+
O 0.97 0.91 0.94 11359
|
| 72 |
+
B-Term 0.96 0.93 0.94 2977
|
| 73 |
+
|
| 74 |
+
accuracy 0.91 18434
|
| 75 |
+
macro avg 0.82 0.87 0.84 18434
|
| 76 |
+
weighted avg 0.92 0.91 0.91 18434
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
Metrics only on `astromis/ruDEFT`:
|
| 80 |
+
```python
|
| 81 |
+
precision recall f1-score support
|
| 82 |
+
|
| 83 |
+
0 0.87 0.95 0.91 836
|
| 84 |
+
1 0.84 0.67 0.74 353
|
| 85 |
+
|
| 86 |
+
accuracy 0.86 1189
|
| 87 |
+
macro avg 0.85 0.81 0.82 1189
|
| 88 |
+
weighted avg 0.86 0.86 0.86 1189
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
Metrics only on `astromis/WCL_Wiki_Ru`:
|
| 92 |
+
```python
|
| 93 |
+
precision recall f1-score support
|
| 94 |
+
|
| 95 |
+
I-Definition 0.00 0.00 0.00 0
|
| 96 |
+
B-Definition 0.00 0.00 0.00 0
|
| 97 |
+
I-Term 0.72 0.78 0.75 135
|
| 98 |
+
O 1.00 0.93 0.96 9137
|
| 99 |
+
B-Term 0.99 0.95 0.97 2339
|
| 100 |
+
|
| 101 |
+
accuracy 0.93 11611
|
| 102 |
+
macro avg 0.54 0.53 0.54 11611
|
| 103 |
+
weighted avg 0.99 0.93 0.96 11611
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
```
|