codinglabsong commited on
Commit
ac1a611
Β·
verified Β·
1 Parent(s): 65c8ac6

Update Readme.md

Browse files
Files changed (1) hide show
  1. README.md +81 -18
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
- <!-- This model card has been generated automatically according to the information the Trainer had access to. You
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
- ## Model description
28
-
29
- More information needed
30
-
31
- ## Intended uses & limitations
32
-
33
- More information needed
34
-
35
- ## Training and evaluation data
36
-
37
- More information needed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 |