Update Readme.md
Browse files
README.md
CHANGED
@@ -6,16 +6,14 @@ tags:
|
|
6 |
- generated_from_trainer
|
7 |
metrics:
|
8 |
- accuracy
|
9 |
-
- f1
|
|
|
10 |
model-index:
|
11 |
- name: roberta-base-with-tweet-eval-emoji-full
|
12 |
results: []
|
13 |
---
|
14 |
|
15 |
-
|
16 |
-
should probably proofread and complete it, then remove this comment. -->
|
17 |
-
|
18 |
-
# roberta-base-with-tweet-eval-emoji-full
|
19 |
|
20 |
This model is a fine-tuned version of [roberta-base](https://huggingface.co/roberta-base) on the tweet_eval/emoji dataset.
|
21 |
It achieves the following results on the evaluation set:
|
@@ -24,19 +22,84 @@ It achieves the following results on the evaluation set:
|
|
24 |
- F1: 0.3314
|
25 |
- Top3 Accuracy: 0.6504
|
26 |
|
27 |
-
##
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
## Training procedure
|
40 |
|
41 |
### Training hyperparameters
|
42 |
|
@@ -54,7 +117,7 @@ The following hyperparameters were used during training:
|
|
54 |
|
55 |
### Training results
|
56 |
|
57 |
-
| Training Loss | Epoch | Step | Validation Loss | Accuracy | F1 | Top3 Accuracy |
|
58 |
|:-------------:|:-----:|:----:|:---------------:|:--------:|:------:|:-------------:|
|
59 |
| 2.1291 | 1.0 | 352 | 2.4306 | 0.219 | 0.2126 | 0.405 |
|
60 |
| 2.1083 | 2.0 | 704 | 2.3812 | 0.2356 | 0.2411 | 0.43 |
|
|
|
6 |
- generated_from_trainer
|
7 |
metrics:
|
8 |
- accuracy
|
9 |
+
- f1 (macro)
|
10 |
+
- top3 accuracy
|
11 |
model-index:
|
12 |
- name: roberta-base-with-tweet-eval-emoji-full
|
13 |
results: []
|
14 |
---
|
15 |
|
16 |
+
# Model description
|
|
|
|
|
|
|
17 |
|
18 |
This model is a fine-tuned version of [roberta-base](https://huggingface.co/roberta-base) on the tweet_eval/emoji dataset.
|
19 |
It achieves the following results on the evaluation set:
|
|
|
22 |
- F1: 0.3314
|
23 |
- Top3 Accuracy: 0.6504
|
24 |
|
25 |
+
## Example of classification
|
26 |
+
|
27 |
+
```python
|
28 |
+
import torch
|
29 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
30 |
+
from peft import PeftModel
|
31 |
+
|
32 |
+
# Specify the same model ID pushed or trained locally
|
33 |
+
MODEL_ID = "roberta-base-tweet-emoji-lora"
|
34 |
+
|
35 |
+
# Load tokenizer + model
|
36 |
+
device = 0 if torch.cuda.is_available() else -1
|
37 |
+
tok = AutoTokenizer.from_pretrained(MODEL_ID)
|
38 |
+
base_model = AutoModelForSequenceClassification.from_pretrained(
|
39 |
+
"FacebookAI/roberta-base",
|
40 |
+
num_labels=20,
|
41 |
+
ignore_mismatched_sizes=True,
|
42 |
+
)
|
43 |
+
model = PeftModel.from_pretrained(base_model, MODEL_ID).eval()
|
44 |
+
|
45 |
+
pipe = pipeline(
|
46 |
+
task="text-classification",
|
47 |
+
model=model,
|
48 |
+
tokenizer=tok,
|
49 |
+
return_all_scores=True,
|
50 |
+
function_to_apply="softmax",
|
51 |
+
device=device,
|
52 |
+
)
|
53 |
+
|
54 |
+
# Map label IDs to emojis
|
55 |
+
id2label = {
|
56 |
+
0: "β€",
|
57 |
+
1: "π",
|
58 |
+
2: "π",
|
59 |
+
3: "π",
|
60 |
+
4: "π₯",
|
61 |
+
5: "π",
|
62 |
+
6: "π",
|
63 |
+
7: "β¨",
|
64 |
+
8: "π",
|
65 |
+
9: "π",
|
66 |
+
10: "π·",
|
67 |
+
11: "πΊπΈ",
|
68 |
+
12: "β",
|
69 |
+
13: "π",
|
70 |
+
14: "π",
|
71 |
+
15: "π―",
|
72 |
+
16: "π",
|
73 |
+
17: "π",
|
74 |
+
18: "πΈ",
|
75 |
+
19: "π",
|
76 |
+
}
|
77 |
+
|
78 |
+
|
79 |
+
def predict_emojis(text, top_k=2):
|
80 |
+
"""
|
81 |
+
Predict top k emojis for the given text.
|
82 |
+
|
83 |
+
Args:
|
84 |
+
text (str): Input string.
|
85 |
+
k (int): Number of top emojis to return.
|
86 |
+
|
87 |
+
Returns:
|
88 |
+
str: Space-separated top k emojis.
|
89 |
+
"""
|
90 |
+
probs = pipe(text)[0]
|
91 |
+
top = sorted(probs, key=lambda x: x["score"], reverse=True)[:top_k]
|
92 |
+
return " ".join(id2label[int(d["label"].split("_")[-1])] for d in top)
|
93 |
+
|
94 |
+
print(predict_emojis("Sunny days!"))
|
95 |
+
```
|
96 |
+
|
97 |
+
Output:
|
98 |
+
|
99 |
+
```
|
100 |
+
π β
|
101 |
+
```
|
102 |
|
|
|
103 |
|
104 |
### Training hyperparameters
|
105 |
|
|
|
117 |
|
118 |
### Training results
|
119 |
|
120 |
+
| Training Loss | Epoch | Step | Validation Loss | Accuracy | F1 (Macro) | Top3 Accuracy |
|
121 |
|:-------------:|:-----:|:----:|:---------------:|:--------:|:------:|:-------------:|
|
122 |
| 2.1291 | 1.0 | 352 | 2.4306 | 0.219 | 0.2126 | 0.405 |
|
123 |
| 2.1083 | 2.0 | 704 | 2.3812 | 0.2356 | 0.2411 | 0.43 |
|