Views
No views yet
{'eval_loss': 0.10526859760284424,
'eval_precision': 0.8299675891298928,
'eval_recall': 0.8870237143618439,
'eval_f1': 0.8575476558475013,
'eval_accuracy': 0.9717195641875889,
'eval_runtime': 18.2172,
'eval_samples_per_second': 80.967,
'eval_steps_per_second': 5.105,
'epoch': 10.0}{'eval_loss': 0.11170374602079391,
'eval_precision': 0.8178285159096429,
'eval_recall': 0.8823375262054507,
'eval_f1': 0.8488591957645278,
'eval_accuracy': 0.968742017138478,
'eval_runtime': 18.6202,
'eval_samples_per_second': 79.054,
'eval_steps_per_second': 4.941,
'epoch': 10.0}1from transformers import AutoTokenizer
2from transformers import AutoModelForTokenClassification
3from pythainlp.tokenize import word_tokenize # pip install pythainlp
4import torch
5
6name="Porameht/wangchanberta-thainer-corpus-v2-2"
7tokenizer = AutoTokenizer.from_pretrained(name)
8model = AutoModelForTokenClassification.from_pretrained(name)
9
10sentence="นายปรเมศ คุ้มสมบัติ 552/44 หมู่ 1 บ้านหนองบัว ต.ภูหอ อ.ภูหลวง จ.เลย 42230"
11cut=word_tokenize(sentence.replace(" ", "<_>"))
12inputs=tokenizer(cut,is_split_into_words=True,return_tensors="pt")
13
14ids = inputs["input_ids"]
15mask = inputs["attention_mask"]
16# forward pass
17outputs = model(ids, attention_mask=mask)
18logits = outputs[0]
19
20predictions = torch.argmax(logits, dim=2)
21predicted_token_class = [model.config.id2label[t.item()] for t in predictions[0]]
22
23def fix_span_error(words,ner):
24 _ner = []
25 _ner=ner
26 _new_tag=[]
27 for i,j in zip(words,_ner):
28 #print(i,j)
29 i=tokenizer.decode(i)
30 if i.isspace() and j.startswith("B-"):
31 j="O"
32 if i=='' or i=='<s>' or i=='</s>':
33 continue
34 if i=="<_>":
35 i=" "
36 _new_tag.append((i,j))
37 return _new_tag
38
39ner_tag=fix_span_error(inputs['input_ids'][0],predicted_token_class)
40ner_tag[('นาย', 'B-PERSON'),
('ปร', 'I-PERSON'),
('เม', 'I-PERSON'),
('ศ', 'I-PERSON'),
(' ', 'B-LOCATION'),
('คุ้ม', 'I-PERSON'),
('สมบัติ', 'I-PERSON'),
(' ', 'O'),
('55', 'O'),
('2/', 'O'),
('44', 'O'),
(' ', 'B-LOCATION'),
('หมู่', 'B-LOCATION'),
(' ', 'I-LOCATION'),
('1', 'I-LOCATION'),
(' ', 'B-LOCATION'),
('บ้าน', 'B-LOCATION'),
('หนอง', 'I-LOCATION'),
('บัว', 'I-LOCATION'),
(' ', 'B-LOCATION'),
('ต', 'B-LOCATION'),
('.', 'I-LOCATION'),
('ภู', 'I-LOCATION'),
('หอ', 'I-LOCATION'),
(' ', 'B-LOCATION'),
('อ', 'B-LOCATION'),
('.', 'I-LOCATION'),
('ภู', 'I-LOCATION'),
('หลวง', 'I-LOCATION'),
(' ', 'B-LOCATION'),
('จ', 'B-LOCATION'),
('.', 'I-LOCATION'),
('เลย', 'I-LOCATION'),
(' ', 'B-ZIP'),
('4', 'B-ZIP'),
('22', 'B-ZIP'),
('30', 'B-ZIP')]| Training Loss | Epoch | Step | Validation Loss | Precision | Recall | F1 | Accuracy |
|---|---|---|---|---|---|---|---|
| No log | 1.0 | 274 | 0.1790 | 0.6867 | 0.7908 | 0.7351 | 0.9484 |
| 0.2681 | 2.0 | 548 | 0.1331 | 0.7788 | 0.8463 | 0.8111 | 0.9650 |
| 0.2681 | 3.0 | 822 | 0.1135 | 0.8082 | 0.8766 | 0.8410 | 0.9692 |
| 0.0829 | 4.0 | 1096 | 0.1053 | 0.8300 | 0.8870 | 0.8575 | 0.9717 |
| 0.0829 | 5.0 | 1370 | 0.1136 | 0.8175 | 0.8868 | 0.8507 | 0.9704 |
| 0.0512 | 6.0 | 1644 | 0.1135 | 0.8408 | 0.8836 | 0.8616 | 0.9723 |
| 0.0512 | 7.0 | 1918 | 0.1162 | 0.8429 | 0.8894 | 0.8656 | 0.9725 |
| 0.037 | 8.0 | 2192 | 0.1205 | 0.8475 | 0.8916 | 0.8690 | 0.9730 |
| 0.037 | 9.0 | 2466 | 0.1237 | 0.8490 | 0.8942 | 0.8710 | 0.9732 |
| 0.0275 | 10.0 | 2740 | 0.1222 | 0.8480 | 0.8934 | 0.8701 | 0.9733 |