Update README.md
Browse filesupdated by handling data distro. and optimized training params.
README.md
CHANGED
@@ -1,199 +1,239 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
-
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
# Model Card for Model ID
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
|
12 |
## Model Details
|
13 |
|
14 |
### Model Description
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
19 |
|
20 |
-
- **Developed by:**
|
21 |
-
- **Funded by
|
22 |
-
- **Shared by
|
23 |
-
- **Model type:**
|
24 |
-
- **Language(s) (NLP):**
|
25 |
-
- **License:**
|
26 |
-
- **Finetuned from model
|
27 |
|
28 |
### Model Sources [optional]
|
29 |
|
30 |
<!-- Provide the basic links for the model. -->
|
31 |
|
32 |
-
- **Repository:**
|
33 |
- **Paper [optional]:** [More Information Needed]
|
34 |
- **Demo [optional]:** [More Information Needed]
|
35 |
|
36 |
## Uses
|
37 |
|
38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
39 |
-
|
40 |
### Direct Use
|
|
|
|
|
41 |
|
42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
43 |
-
|
44 |
-
[More Information Needed]
|
45 |
|
46 |
### Downstream Use [optional]
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
[More Information Needed]
|
51 |
|
52 |
### Out-of-Scope Use
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
[More Information Needed]
|
57 |
|
58 |
## Bias, Risks, and Limitations
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
|
64 |
### Recommendations
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
69 |
|
70 |
## How to Get Started with the Model
|
71 |
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
-
[More Information Needed]
|
75 |
|
76 |
## Training Details
|
77 |
|
78 |
### Training Data
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
### Training Procedure
|
85 |
-
|
86 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
87 |
-
|
88 |
-
#### Preprocessing [optional]
|
89 |
-
|
90 |
-
[More Information Needed]
|
91 |
-
|
92 |
|
93 |
#### Training Hyperparameters
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
## Evaluation
|
104 |
|
105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
-
|
107 |
### Testing Data, Factors & Metrics
|
108 |
|
109 |
#### Testing Data
|
110 |
|
111 |
-
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
-
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
-
|
119 |
-
[More Information Needed]
|
120 |
|
121 |
#### Metrics
|
122 |
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
-
[More Information Needed]
|
130 |
|
131 |
#### Summary
|
132 |
|
|
|
133 |
|
134 |
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
## Environmental Impact
|
142 |
|
143 |
-
|
144 |
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
|
153 |
## Technical Specifications [optional]
|
154 |
|
155 |
### Model Architecture and Objective
|
156 |
|
157 |
-
|
158 |
|
159 |
### Compute Infrastructure
|
|
|
|
|
160 |
|
161 |
-
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
|
175 |
**BibTeX:**
|
176 |
|
177 |
-
[
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
-
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
-
|
189 |
-
## More Information [optional]
|
190 |
-
|
191 |
-
[More Information Needed]
|
192 |
-
|
193 |
-
## Model Card Authors [optional]
|
194 |
|
195 |
-
[More Information Needed]
|
196 |
|
197 |
## Model Card Contact
|
198 |
|
199 |
-
|
|
|
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
+
tags:
|
4 |
+
- sentiment-analysis
|
5 |
+
- distilbert
|
6 |
+
- text-classification
|
7 |
+
- nlp
|
8 |
+
- imdb
|
9 |
+
- binary-classification
|
10 |
+
license: mit
|
11 |
+
datasets:
|
12 |
+
- stanfordnlp/imdb
|
13 |
+
language:
|
14 |
+
- en
|
15 |
+
metrics:
|
16 |
+
- accuracy
|
17 |
+
base_model:
|
18 |
+
- distilbert/distilbert-base-uncased
|
19 |
---
|
20 |
|
21 |
# Model Card for Model ID
|
22 |
|
23 |
+
A fine-tuned DistilBERT model for binary sentiment analysis — predicting whether input text expresses a positive or negative sentiment. Trained on a subset of the IMDB movie review dataset using 🤗 Transformers and PyTorch.
|
|
|
|
|
24 |
|
25 |
## Model Details
|
26 |
|
27 |
### Model Description
|
28 |
|
29 |
+
This model was trained by Daniel (AfroLogicInsect) for classifying sentiment on movie reviews. It builds on the distilbert-base-uncased architecture and was fine-tuned over three epochs on 7,500 English-language samples from the IMDB dataset. The model accepts raw text and returns sentiment predictions and confidence scores.
|
|
|
|
|
30 |
|
31 |
+
- **Developed by:** Daniel 🇳🇬 (@AfroLogicInsect)
|
32 |
+
- **Funded by:** [More Information Needed]
|
33 |
+
- **Shared by:** [More Information Needed]
|
34 |
+
- **Model type:** DistilBERT-based sequence classification
|
35 |
+
- **Language(s) (NLP):** English
|
36 |
+
- **License:** MIT
|
37 |
+
- **Finetuned from model:** distilbert-base-uncased
|
38 |
|
39 |
### Model Sources [optional]
|
40 |
|
41 |
<!-- Provide the basic links for the model. -->
|
42 |
|
43 |
+
- **Repository:** https://huggingface.co/AfroLogicInsect/sentiment-analysis-model_v2
|
44 |
- **Paper [optional]:** [More Information Needed]
|
45 |
- **Demo [optional]:** [More Information Needed]
|
46 |
|
47 |
## Uses
|
48 |
|
|
|
|
|
49 |
### Direct Use
|
50 |
+
- Sentiment analysis of short texts, reviews, feedback forms, etc.
|
51 |
+
- Embedding in web apps or chatbots to assess user mood or response tone
|
52 |
|
|
|
|
|
|
|
53 |
|
54 |
### Downstream Use [optional]
|
55 |
|
56 |
+
- Can be incorporated into feedback categorization pipelines
|
57 |
+
- Extended to multilingual sentiment tasks with additional fine-tuning
|
|
|
58 |
|
59 |
### Out-of-Scope Use
|
60 |
|
61 |
+
- Not intended for clinical sentiment/emotion assessment
|
62 |
+
- Doesn't capture sarcasm or highly ambiguous language reliably
|
|
|
63 |
|
64 |
## Bias, Risks, and Limitations
|
65 |
|
66 |
+
- Biases may be inherited from the IMDB dataset (e.g. genre or cultural bias)
|
67 |
+
- Model trained on movie reviews — performance may drop on domain-specific texts like legal or medical writing
|
68 |
+
- Scores represent probabilities, not certainty
|
69 |
|
70 |
### Recommendations
|
71 |
|
72 |
+
- Use thresholding with score confidence if deploying in production
|
73 |
+
- Consider further fine-tuning on in-domain data for robustness
|
|
|
74 |
|
75 |
## How to Get Started with the Model
|
76 |
|
77 |
+
```{python}
|
78 |
+
from transformers import pipeline
|
79 |
+
|
80 |
+
classifier = pipeline("sentiment-analysis", model="AfroLogicInsect/sentiment-analysis-model")
|
81 |
+
result = classifier("Absolutely loved it!")
|
82 |
+
print(result)
|
83 |
+
```
|
84 |
|
|
|
85 |
|
86 |
## Training Details
|
87 |
|
88 |
### Training Data
|
89 |
|
90 |
+
- Subset of stanfordnlp/imdb
|
91 |
+
- Balanced binary classes (positive and negative)
|
92 |
+
- Sample size: ~15,000 training / 1,500 validation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
#### Training Hyperparameters
|
95 |
|
96 |
+
##### Training arguments
|
97 |
+
training_args = TrainingArguments(
|
98 |
+
output_dir = "./sentiment-model-v2",
|
99 |
+
num_train_epochs=3,
|
100 |
+
per_device_train_batch_size=16,
|
101 |
+
per_device_eval_batch_size=16,
|
102 |
+
learning_rate=2e-5, # Explicit learning rate
|
103 |
+
warmup_steps=100, # Reduced warmup
|
104 |
+
weight_decay=0.01,
|
105 |
+
logging_dir="./logs",
|
106 |
+
logging_steps=50,
|
107 |
+
eval_strategy="steps",
|
108 |
+
eval_steps=200, # < 500: More frequent evaluation
|
109 |
+
save_strategy="steps",
|
110 |
+
save_steps=200, # match eval_steps
|
111 |
+
load_best_model_at_end=True,
|
112 |
+
metric_for_best_model="f1",
|
113 |
+
greater_is_better=True,
|
114 |
+
seed=42, # Reproducibility
|
115 |
+
dataloader_drop_last=False,
|
116 |
+
#remove_unused_columns=False,
|
117 |
+
)
|
118 |
+
|
119 |
+
##### Create trainer
|
120 |
+
trainer = Trainer(
|
121 |
+
model=model,
|
122 |
+
args=training_args,
|
123 |
+
train_dataset=train_dataset,
|
124 |
+
eval_dataset=val_dataset,
|
125 |
+
tokenizer=tokenizer,
|
126 |
+
data_collator=data_collator,
|
127 |
+
compute_metrics=compute_metrics,
|
128 |
+
)
|
129 |
|
130 |
## Evaluation
|
131 |
|
|
|
|
|
132 |
### Testing Data, Factors & Metrics
|
133 |
|
134 |
#### Testing Data
|
135 |
|
136 |
+
- Validation set from IMDB subset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
#### Metrics
|
139 |
|
|
|
|
|
|
|
140 |
|
141 |
+
Step Training Loss Validation Loss Accuracy F1 Precision Recall
|
142 |
+
200 0.391100 0.344377 0.850000 0.863554 0.791991 0.949333
|
143 |
+
400 0.299000 0.304345 0.876000 0.865994 0.942006 0.801333
|
144 |
+
600 0.301700 0.298436 0.881333 0.888331 0.838863 0.944000
|
145 |
+
800 0.280700 0.260090 0.893333 0.897698 0.862408 0.936000
|
146 |
+
1000 0.173100 0.288142 0.899333 0.897766 0.911967 0.884000
|
147 |
+
1200 0.203700 0.263154 0.904667 0.905486 0.897772 0.913333
|
148 |
+
1400 0.186100 0.275240 0.904000 0.901370 0.926761 0.877333
|
149 |
+
1600 0.130400 0.291926 0.904667 0.903313 0.916324 0.890667
|
150 |
+
1800 0.158900 0.304814 0.908000 0.908488 0.903694 0.913333
|
151 |
+
2000 0.087900 0.332357 0.904000 0.905263 0.893506 0.917333
|
152 |
+
2200 0.119300 0.339073 0.908667 0.910399 0.893453 0.928000
|
153 |
+
2400 0.178100 0.366023 0.903333 0.905660 0.884371 0.928000
|
154 |
+
2600 0.072100 0.372015 0.909333 0.908356 0.918256 0.898667
|
155 |
+
2800 0.097700 0.368600 0.906667 0.908016 0.895078 0.921333
|
156 |
+
|
157 |
+
Final evaluation results: {
|
158 |
+
'eval_loss': 0.3390733003616333,
|
159 |
+
'eval_accuracy': 0.9086666666666666,
|
160 |
+
'eval_f1': 0.9103989535644212,
|
161 |
+
'eval_precision': 0.8934531450577664,
|
162 |
+
'eval_recall': 0.928,
|
163 |
+
'eval_runtime': 9.9181,
|
164 |
+
'eval_samples_per_second': 151.239,
|
165 |
+
'eval_steps_per_second': 9.478, 'epoch': 3.0
|
166 |
+
}
|
167 |
+
|
168 |
+
|
169 |
+
### Results [Sample]
|
170 |
+
|
171 |
+
#### ============================================================
|
172 |
+
#### TESTING FIXED MODEL
|
173 |
+
#### ============================================================
|
174 |
+
|
175 |
+
Testing fixed model...
|
176 |
+
Text Expected Predicted Confidence Match
|
177 |
+
==========================================================================================
|
178 |
+
I absolutely loved this movie! It was fantastic! positive positive 0.9959 ✓
|
179 |
+
This movie was terrible and boring. negative negative 0.9969 ✓
|
180 |
+
Amazing acting and great story! positive positive 0.9959 ✓
|
181 |
+
Worst film I've ever seen. negative negative 0.9950 ✓
|
182 |
+
Incredible cinematography and soundtrack. positive positive 0.9950 ✓
|
183 |
+
Complete waste of time and money. negative negative 0.9957 ✓
|
184 |
+
The movie was okay, nothing special. neutral negative 0.9915 N/A
|
185 |
+
I enjoyed most of it. positive positive 0.9912 ✓
|
186 |
+
Pretty disappointing overall. negative negative 0.9936 ✓
|
187 |
+
Masterpiece of cinema! positive positive 0.9939 ✓
|
188 |
+
|
189 |
+
Overall Accuracy: 100.0% (9/9)
|
190 |
+
|
191 |
+
## 🧪 Live Demo
|
192 |
+
|
193 |
+
Try it out below!
|
194 |
+
|
195 |
+
👉 [Launch Sentiment Analyzer](https://huggingface.co/spaces/AfroLogicInsect/sentiment-analysis-model-gradio)
|
196 |
|
|
|
197 |
|
198 |
#### Summary
|
199 |
|
200 |
+
The model performs well on balanced sentiment data and generalizes across a variety of movie review tones. Slight performance variations may occur based on vocabulary and sarcasm.
|
201 |
|
202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
## Environmental Impact
|
204 |
|
205 |
+
Carbon footprint estimated using [ML Impact Calculator](https://mlco2.github.io/impact#compute)
|
206 |
|
207 |
+
Hardware Type: GPU (single NVIDIA T4)
|
208 |
+
Hours used: ~2.5 hours
|
209 |
+
Cloud Provider: Google Colab
|
210 |
+
Compute Region: Europe
|
211 |
+
Carbon Emitted: ~0.3 kg CO₂eq
|
|
|
|
|
212 |
|
213 |
## Technical Specifications [optional]
|
214 |
|
215 |
### Model Architecture and Objective
|
216 |
|
217 |
+
DistilBERT with a classification head trained for binary text classification.
|
218 |
|
219 |
### Compute Infrastructure
|
220 |
+
- Hardware: Google Colab (GPU-backed)
|
221 |
+
- Software: Python, PyTorch, 🤗 Transformers, Hugging Face Hub
|
222 |
|
223 |
+
## Citation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
**BibTeX:**
|
226 |
|
227 |
+
[@misc{afrologicinsect2025sentiment,
|
228 |
+
title = {AfroLogicInsect Sentiment Analysis Model},
|
229 |
+
author = {Akan Daniel},
|
230 |
+
year = {2025},
|
231 |
+
howpublished = {\url{https://huggingface.co/AfroLogicInsect/sentiment-analysis-model_v2}},
|
232 |
+
}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
|
|
|
234 |
|
235 |
## Model Card Contact
|
236 |
|
237 |
+
- Name: Daniel (@AfroLogicInsect)
|
238 |
+
- Location: Lagos, Nigeria
|
239 |
+
- Contact: GitHub / Hugging Face / email ([email protected])
|