katrjohn commited on
Commit
92f6c08
·
verified ·
1 Parent(s): efceecc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +188 -1
README.md CHANGED
@@ -10,4 +10,191 @@ tags:
10
  - classification
11
  - NER
12
  - NewsArticle
13
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  - classification
11
  - NER
12
  - NewsArticle
13
+ ---
14
+
15
+ # Model Description
16
+ This model is finetuned version of [GreekBert](https://huggingface.co/nlpaueb/bert-base-greek-uncased-v1)
17
+
18
+ ## Dataset
19
+ The model finetuned on the [GreekNews-20k](https://huggingface.co/datasets/katrjohn/GreekNews-20k) dataset.
20
+
21
+ ### Results
22
+
23
+ Perfomance on the [GreekNews-20k dataset](https://huggingface.co/datasets/katrjohn/GreekNews-20k) :
24
+
25
+ | Class | Precision | Recall | F1-score | Support |
26
+ |-------------------------------------------------|-----------|--------|----------|---------|
27
+ | Αυτοκίνητο | 0.87 | 0.95 | 0.90 | 201 |
28
+ | Επιχειρήσεις και βιομηχανία | 0.68 | 0.76 | 0.72 | 369 |
29
+ | Έγκλημα και δικαιοσύνη | 0.86 | 0.87 | 0.87 | 314 |
30
+ | Ειδήσεις για καταστροφές και έκτακτες ανάγκες | 0.79 | 0.71 | 0.75 | 272 |
31
+ | Οικονομικά και χρηματοοικονομικά | 0.78 | 0.70 | 0.73 | 495 |
32
+ | Εκπαίδευση | 0.86 | 0.83 | 0.84 | 259 |
33
+ | Ψυχαγωγία και πολιτισμός | 0.68 | 0.79 | 0.73 | 251 |
34
+ | Περιβάλλον και κλίμα | 0.78 | 0.65 | 0.71 | 292 |
35
+ | Οικογένεια και σχέσεις | 0.80 | 0.81 | 0.81 | 294 |
36
+ | Μόδα | 0.84 | 0.91 | 0.87 | 259 |
37
+ | Τρόφιμα και ποτά | 0.65 | 0.75 | 0.70 | 262 |
38
+ | Υγεία και ιατρική | 0.74 | 0.64 | 0.68 | 346 |
39
+ | Μεταφορές και υποδομές | 0.78 | 0.82 | 0.80 | 321 |
40
+ | Ψυχική υγεία και ευεξία | 0.72 | 0.72 | 0.72 | 348 |
41
+ | Πολιτική και κυβέρνηση | 0.76 | 0.68 | 0.72 | 339 |
42
+ | Θρησκεία | 0.92 | 0.87 | 0.90 | 271 |
43
+ | Αθλητισμός | 0.97 | 0.98 | 0.97 | 212 |
44
+ | Ταξίδια και αναψυχή | 0.80 | 0.80 | 0.80 | 424 |
45
+ | Τεχνολογία και επιστήμη | 0.65 | 0.75 | 0.70 | 308 |
46
+ | **Accuracy** | | | 0.78 | 5837 |
47
+ | **Macro avg** | 0.79 | 0.79 | 0.79 | 5837 |
48
+ | **Weighted avg** | 0.78 | 0.78 | 0.78 | 5837 |
49
+
50
+ | Class | Precision | Recall | F1-score | Support |
51
+ |----------|-----------|--------|----------|---------|
52
+ | CARDINAL | 0.87 | 0.93 | 0.90 | 25656 |
53
+ | DATE | 0.87 | 0.90 | 0.88 | 15469 |
54
+ | EVENT | 0.60 | 0.59 | 0.59 | 1720 |
55
+ | FAC | 0.39 | 0.51 | 0.44 | 2118 |
56
+ | GPE | 0.88 | 0.86 | 0.87 | 16010 |
57
+ | LOC | 0.72 | 0.65 | 0.68 | 3547 |
58
+ | MONEY | 0.73 | 0.76 | 0.74 | 3882 |
59
+ | NORP | 0.89 | 0.84 | 0.86 | 1926 |
60
+ | ORDINAL | 0.92 | 0.96 | 0.94 | 3891 |
61
+ | ORG | 0.69 | 0.76 | 0.72 | 22184 |
62
+ | PERCENT | 0.72 | 0.78 | 0.75 | 7286 |
63
+ | PERSON | 0.79 | 0.85 | 0.82 | 16524 |
64
+ | PRODUCT | 0.48 | 0.48 | 0.48 | 2071 |
65
+ | QUANTITY | 0.64 | 0.68 | 0.66 | 2588 |
66
+ | TIME | 0.74 | 0.76 | 0.75 | 2390 |
67
+ | **Micro avg** | 0.78 | 0.83 | 0.81 | 127262 |
68
+ | **Macro avg** | 0.73 | 0.75 | 0.74 | 127262 |
69
+ | **Weighted avg** | 0.79 | 0.83 | 0.81 | 127262 |
70
+
71
+ Performance on the [elNER dataset](https://github.com/nmpartzio/elNER) :
72
+
73
+ | Class | Precision | Recall | F1-score | Support |
74
+ |----------|-----------|--------|----------|---------|
75
+ | CARDINAL | 0.90 | 0.93 | 0.91 | 911 |
76
+ | DATE | 0.90 | 0.92 | 0.91 | 838 |
77
+ | EVENT | 0.43 | 0.46 | 0.45 | 130 |
78
+ | FAC | 0.34 | 0.47 | 0.40 | 77 |
79
+ | GPE | 0.83 | 0.90 | 0.86 | 826 |
80
+ | LOC | 0.70 | 0.63 | 0.66 | 178 |
81
+ | MONEY | 0.93 | 0.95 | 0.94 | 111 |
82
+ | NORP | 0.81 | 0.87 | 0.84 | 141 |
83
+ | ORDINAL | 0.94 | 0.92 | 0.93 | 172 |
84
+ | ORG | 0.74 | 0.72 | 0.73 | 1388 |
85
+ | PERCENT | 0.93 | 0.99 | 0.96 | 206 |
86
+ | PERSON | 0.84 | 0.86 | 0.85 | 1051 |
87
+ | PRODUCT | 0.46 | 0.41 | 0.43 | 83 |
88
+ | QUANTITY | 0.70 | 0.75 | 0.73 | 65 |
89
+ | TIME | 0.88 | 0.81 | 0.84 | 137 |
90
+ | **Micro avg** | 0.82 | 0.83 | 0.82 | 6314 |
91
+ | **Macro avg** | 0.76 | 0.77 | 0.76 | 6314 |
92
+ | **Weighted avg** | 0.82 | 0.83 | 0.82 | 6314 |
93
+
94
+
95
+
96
+ #### To use this model
97
+ ```
98
+ pip install transformers, torch
99
+ ```
100
+
101
+ ```
102
+ from transformers import AutoModel
103
+
104
+ model = AutoModel.from_pretrained("katrjohn/TinyGreekNewsBERT", trust_remote_code=True)
105
+ tokenizer = AutoTokenizer.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
106
+ ```
107
+
108
+ ##### Example usage
109
+ ```
110
+ from transformers import AutoTokenizer, AutoModel
111
+ import torch
112
+
113
+ tokenizer = AutoTokenizer.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
114
+ model = AutoModel.from_pretrained("katrjohn/TinyGreekNewsBERT", trust_remote_code=True)
115
+
116
+ # Classification label dictionary (reverse)
117
+ classification_label_dict_reverse = {
118
+ 0: "Αυτοκίνητο", 1: "Επιχειρήσεις και βιομηχανία", 2: "Έγκλημα και δικαιοσύνη",
119
+ 3: "Ειδήσεις για καταστροφές και έκτακτες ανάγκες", 4: "Οικονομικά και χρηματοοικονομικά", 5: "Εκπαίδευση",
120
+ 6: "Ψυχαγωγία και πολιτισμός", 7: "Περιβάλλον και κλίμα", 8: "Οικογένεια και σχέσεις",
121
+ 9: "Μόδα", 10: "Τρόφιμα και ποτά", 11: "Υγεία και ιατρική", 12: "Μεταφορές και υποδομές",
122
+ 13: "Ψυχική υγεία και ευεξία", 14: "Πολιτική και κυβέρνηση", 15: "Θρησκεία",
123
+ 16: "Αθλητισμός", 17: "Ταξίδια και αναψυχή", 18: "Τεχνολογία και επιστήμη"
124
+ }
125
+
126
+ ner_label_set = ["PAD", "O",
127
+ "B-ORG", "I-ORG", "B-PERSON", "I-PERSON", "B-CARDINAL", "I-CARDINAL",
128
+ "B-GPE", "I-GPE", "B-DATE", "I-DATE", "B-ORDINAL", "I-ORDINAL",
129
+ "B-PERCENT", "I-PERCENT", "B-LOC", "I-LOC", "B-NORP", "I-NORP",
130
+ "B-MONEY", "I-MONEY", "B-TIME", "I-TIME", "B-EVENT", "I-EVENT",
131
+ "B-PRODUCT", "I-PRODUCT", "B-FAC", "I-FAC", "B-QUANTITY", "I-QUANTITY"
132
+ ]
133
+ tag2idx = {t:i for i,t in enumerate(ner_label_set)}
134
+ idx2tag = {i:t for t,i in tag2idx.items()}
135
+
136
+ sentence = "Ο Κυριάκος Μητσοτάκης επισκέφθηκε τη Θεσσαλονίκη για τα εγκαίνια της ΔΕΘ."
137
+ inputs = tokenizer(sentence, return_tensors="pt")
138
+
139
+ with torch.no_grad():
140
+ classification_logits, ner_logits = model(**inputs)
141
+
142
+ # Classification
143
+ classification_probs = torch.softmax(classification_logits, dim=-1)
144
+ predicted_class = torch.argmax(classification_probs, dim=-1).item()
145
+ predicted_class_label = classification_label_dict_reverse.get(predicted_class, "Unknown")
146
+
147
+ print(f"Predicted class index: {predicted_class}")
148
+ print(f"Predicted class label: {predicted_class_label}")
149
+
150
+ # NER
151
+ ner_predictions = torch.argmax(ner_logits, dim=-1).squeeze().tolist()
152
+ tokens = tokenizer.convert_ids_to_tokens(inputs['input_ids'].squeeze())
153
+
154
+ for token, pred_idx in zip(tokens, ner_predictions):
155
+ tag = idx2tag.get(pred_idx, "O")
156
+ if token in ["[CLS]", "[SEP]"]:
157
+ tag = "O"
158
+ print(f"{token}: {tag}")
159
+
160
+ ```
161
+
162
+ Output:
163
+ ```
164
+ Predicted class index: 14
165
+ Predicted class label: Πολιτική και κυβέρνηση
166
+ [CLS]: O
167
+ ο: O
168
+ κυριακος: B-PERSON
169
+ μητσοτακης: I-PERSON
170
+ επισκεφθηκε: O
171
+ τη: O
172
+ θεσσαλονικη: B-GPE
173
+ για: O
174
+ τα: O
175
+ εγκαινια: O
176
+ της: O
177
+ δεθ: B-EVENT
178
+ .: O
179
+ [SEP]: O
180
+
181
+ ```
182
+
183
+ #### Author
184
+ This model has been released along side with the article XXX. To use this model please cite the following:
185
+ ```
186
+ @inproceedings{XXX,
187
+ author = {XXX},
188
+ title = {XXX},
189
+ year = {XXX},
190
+ isbn = {XXX},
191
+ publisher = {XXX},
192
+ address = {XXX},
193
+ url = {XXX},
194
+ booktitle = {XXX},
195
+ pages = {XXX},
196
+ numpages = {XXX},
197
+ location = {XXX},
198
+ series = {XXX}
199
+ }
200
+ ```