logasanjeev commited on
Commit
0ccbd04
·
verified ·
1 Parent(s): 0ad5229

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +52 -197
README.md CHANGED
@@ -1,227 +1,82 @@
1
  ---
 
2
  license: apache-2.0
 
 
 
 
 
 
3
  datasets:
4
- - google-research-datasets/go_emotions
5
- language:
6
- - en
7
  metrics:
8
- - accuracy
9
- base_model:
10
- - google-bert/bert-base-uncased
11
- pipeline_tag: text-classification
 
 
 
 
 
 
12
  ---
13
- # Model Card for Model ID
14
 
15
- <!-- Provide a quick summary of what the model is/does. -->
16
 
17
- This modelcard aims to be a base template for new models. It has been generated using [this raw template](https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md?plain=1).
18
 
19
  ## Model Details
20
 
21
- ### Model Description
 
 
 
 
 
22
 
23
- <!-- Provide a longer summary of what this model is. -->
24
 
 
 
 
 
 
 
25
 
 
 
 
 
 
 
26
 
27
- - **Developed by:** [More Information Needed]
28
- - **Funded by [optional]:** [More Information Needed]
29
- - **Shared by [optional]:** [More Information Needed]
30
- - **Model type:** [More Information Needed]
31
- - **Language(s) (NLP):** [More Information Needed]
32
- - **License:** [More Information Needed]
33
- - **Finetuned from model [optional]:** [More Information Needed]
34
 
35
- ### Model Sources [optional]
36
-
37
- <!-- Provide the basic links for the model. -->
38
-
39
- - **Repository:** [More Information Needed]
40
- - **Paper [optional]:** [More Information Needed]
41
- - **Demo [optional]:** [More Information Needed]
42
-
43
- ## Uses
44
-
45
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
46
-
47
- ### Direct Use
48
-
49
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
50
 
 
51
  from transformers import BertForSequenceClassification, BertTokenizer
 
52
  import json
 
53
 
54
- model = BertForSequenceClassification.from_pretrained("logasanjeev/goemotions-bert")
55
- tokenizer = BertTokenizer.from_pretrained("logasanjeev/goemotions-bert")
 
 
56
 
57
  # Load thresholds
58
- import requests
59
- thresholds_url = "https://huggingface.co/logasanjeev/goemotions-bert/raw/main/thresholds.json"
60
  thresholds_data = json.loads(requests.get(thresholds_url).text)
61
  emotion_labels = thresholds_data["emotion_labels"]
62
  thresholds = thresholds_data["thresholds"]
63
 
64
- # Test prediction
65
  text = "I’m just chilling today."
66
  encodings = tokenizer(text, padding='max_length', truncation=True, max_length=128, return_tensors='pt')
67
  with torch.no_grad():
68
  logits = torch.sigmoid(model(**encodings).logits).numpy()[0]
69
  predictions = [(emotion_labels[i], logit) for i, (logit, thresh) in enumerate(zip(logits, thresholds)) if logit >= thresh]
70
- print("Predicted emotions:", sorted(predictions, key=lambda x: x[1], reverse=True))
71
-
72
- [More Information Needed]
73
-
74
- ### Downstream Use [optional]
75
-
76
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
77
-
78
- [More Information Needed]
79
-
80
- ### Out-of-Scope Use
81
-
82
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
83
-
84
- [More Information Needed]
85
-
86
- ## Bias, Risks, and Limitations
87
-
88
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
89
-
90
- [More Information Needed]
91
-
92
- ### Recommendations
93
-
94
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
95
-
96
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
97
-
98
- ## How to Get Started with the Model
99
-
100
- Use the code below to get started with the model.
101
-
102
- [More Information Needed]
103
-
104
- ## Training Details
105
-
106
- ### Training Data
107
-
108
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
109
-
110
- [More Information Needed]
111
-
112
- ### Training Procedure
113
-
114
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
115
-
116
- #### Preprocessing [optional]
117
-
118
- [More Information Needed]
119
-
120
-
121
- #### Training Hyperparameters
122
-
123
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
124
-
125
- #### Speeds, Sizes, Times [optional]
126
-
127
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
128
-
129
- [More Information Needed]
130
-
131
- ## Evaluation
132
-
133
- <!-- This section describes the evaluation protocols and provides the results. -->
134
-
135
- ### Testing Data, Factors & Metrics
136
-
137
- #### Testing Data
138
-
139
- <!-- This should link to a Dataset Card if possible. -->
140
-
141
- [More Information Needed]
142
-
143
- #### Factors
144
-
145
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
146
-
147
- [More Information Needed]
148
-
149
- #### Metrics
150
-
151
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
152
-
153
- [More Information Needed]
154
-
155
- ### Results
156
-
157
- [More Information Needed]
158
-
159
- #### Summary
160
-
161
-
162
-
163
- ## Model Examination [optional]
164
-
165
- <!-- Relevant interpretability work for the model goes here -->
166
-
167
- [More Information Needed]
168
-
169
- ## Environmental Impact
170
-
171
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
172
-
173
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
174
-
175
- - **Hardware Type:** [More Information Needed]
176
- - **Hours used:** [More Information Needed]
177
- - **Cloud Provider:** [More Information Needed]
178
- - **Compute Region:** [More Information Needed]
179
- - **Carbon Emitted:** [More Information Needed]
180
-
181
- ## Technical Specifications [optional]
182
-
183
- ### Model Architecture and Objective
184
-
185
- [More Information Needed]
186
-
187
- ### Compute Infrastructure
188
-
189
- [More Information Needed]
190
-
191
- #### Hardware
192
-
193
- [More Information Needed]
194
-
195
- #### Software
196
-
197
- [More Information Needed]
198
-
199
- ## Citation [optional]
200
-
201
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
202
-
203
- **BibTeX:**
204
-
205
- [More Information Needed]
206
-
207
- **APA:**
208
-
209
- [More Information Needed]
210
-
211
- ## Glossary [optional]
212
-
213
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
214
-
215
- [More Information Needed]
216
-
217
- ## More Information [optional]
218
-
219
- [More Information Needed]
220
-
221
- ## Model Card Authors [optional]
222
-
223
- [More Information Needed]
224
-
225
- ## Model Card Contact
226
-
227
- [More Information Needed]
 
1
  ---
2
+ language: en
3
  license: apache-2.0
4
+ tags:
5
+ - text-classification
6
+ - multi-label
7
+ - bert
8
+ - goemotions
9
+ - emotion-classification
10
  datasets:
11
+ - goemotions
 
 
12
  metrics:
13
+ - f1
14
+ - precision
15
+ - recall
16
+ widget:
17
+ - text: "I’m just chilling today."
18
+ example_title: "Neutral Example"
19
+ - text: "Thank you for saving my life!"
20
+ example_title: "Gratitude Example"
21
+ - text: "I’m nervous about my exam tomorrow."
22
+ example_title: "Nervousness Example"
23
  ---
 
24
 
25
+ # GoEmotions BERT Classifier
26
 
27
+ This is a fine-tuned **BERT-base-uncased** model for multi-label emotion classification on the [GoEmotions dataset](https://huggingface.co/datasets/goemotions), predicting 28 emotions (e.g., admiration, anger, joy, neutral).
28
 
29
  ## Model Details
30
 
31
+ - **Architecture**: BERT-base-uncased (110M parameters)
32
+ - **Training Data**: GoEmotions (58k Reddit comments, 28 emotions)
33
+ - **Loss Function**: Focal Loss (gamma=2)
34
+ - **Optimizer**: AdamW (lr=2e-5, weight_decay=0.01)
35
+ - **Epochs**: 5
36
+ - **Hardware**: Kaggle T4 x2 GPUs
37
 
38
+ ## Performance
39
 
40
+ - **Micro F1**: 0.6025 (optimized thresholds)
41
+ - **Macro F1**: 0.5266
42
+ - **Precision**: 0.5425
43
+ - **Recall**: 0.6775
44
+ - **Hamming Loss**: 0.0372
45
+ - **Avg Positive Predictions**: 1.4564
46
 
47
+ **Class-wise Performance** (selected):
48
+ - Gratitude: F1 0.9120
49
+ - Love: F1 0.8032
50
+ - Neutral: F1 0.6827
51
+ - Nervousness: F1 0.2564
52
+ - Relief: F1 0.2857
53
 
54
+ ## Usage
 
 
 
 
 
 
55
 
56
+ The model uses optimized thresholds stored in `thresholds.json` for predictions. Example in Python:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
+ ```python
59
  from transformers import BertForSequenceClassification, BertTokenizer
60
+ import torch
61
  import json
62
+ import requests
63
 
64
+ # Load model and tokenizer
65
+ repo_id = "logasanjeev/goemotions-bert"
66
+ model = BertForSequenceClassification.from_pretrained(repo_id)
67
+ tokenizer = BertTokenizer.from_pretrained(repo_id)
68
 
69
  # Load thresholds
70
+ thresholds_url = f"https://huggingface.co/{repo_id}/raw/main/thresholds.json"
 
71
  thresholds_data = json.loads(requests.get(thresholds_url).text)
72
  emotion_labels = thresholds_data["emotion_labels"]
73
  thresholds = thresholds_data["thresholds"]
74
 
75
+ # Predict
76
  text = "I’m just chilling today."
77
  encodings = tokenizer(text, padding='max_length', truncation=True, max_length=128, return_tensors='pt')
78
  with torch.no_grad():
79
  logits = torch.sigmoid(model(**encodings).logits).numpy()[0]
80
  predictions = [(emotion_labels[i], logit) for i, (logit, thresh) in enumerate(zip(logits, thresholds)) if logit >= thresh]
81
+ print(sorted(predictions, key=lambda x: x[1], reverse=True))
82
+ # Output: [('neutral', 0.8147)]