File size: 7,700 Bytes
8de1176
 
d27c613
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8de1176
 
 
 
d27c613
8de1176
 
 
 
 
d27c613
8de1176
d27c613
 
 
 
 
 
 
8de1176
 
 
 
 
d27c613
8de1176
 
 
 
 
 
d27c613
 
8de1176
 
 
 
d27c613
 
8de1176
 
 
d27c613
 
8de1176
 
 
d27c613
 
 
8de1176
 
 
d27c613
 
8de1176
 
 
d27c613
 
 
 
 
 
 
8de1176
 
 
 
 
 
d27c613
 
 
8de1176
 
 
d27c613
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8de1176
 
 
 
 
 
 
d27c613
8de1176
 
 
 
d27c613
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8de1176
 
 
 
d27c613
8de1176
 
 
 
d27c613
8de1176
d27c613
 
 
 
 
8de1176
 
 
 
 
d27c613
8de1176
 
d27c613
 
8de1176
d27c613
8de1176
 
 
d27c613
 
 
 
 
 
8de1176
 
 
 
d27c613
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
---
library_name: transformers
tags:
- sentiment-analysis
- distilbert
- text-classification
- nlp
- imdb
- binary-classification
license: mit
datasets:
- stanfordnlp/imdb
language:
- en
metrics:
- accuracy
base_model:
- distilbert/distilbert-base-uncased
---

# Model Card for Model ID

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.

## Model Details

### Model Description

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.

- **Developed by:** Daniel πŸ‡³πŸ‡¬ (@AfroLogicInsect)
- **Funded by:** [More Information Needed]
- **Shared by:** [More Information Needed]
- **Model type:** DistilBERT-based sequence classification
- **Language(s) (NLP):** English
- **License:** MIT
- **Finetuned from model:** distilbert-base-uncased

### Model Sources [optional]

<!-- Provide the basic links for the model. -->

- **Repository:** https://huggingface.co/AfroLogicInsect/sentiment-analysis-model_v2
- **Paper [optional]:** [More Information Needed]
- **Demo [optional]:** [More Information Needed]

## Uses

### Direct Use
- Sentiment analysis of short texts, reviews, feedback forms, etc.
- Embedding in web apps or chatbots to assess user mood or response tone


### Downstream Use [optional]

- Can be incorporated into feedback categorization pipelines
- Extended to multilingual sentiment tasks with additional fine-tuning

### Out-of-Scope Use

- Not intended for clinical sentiment/emotion assessment
- Doesn't capture sarcasm or highly ambiguous language reliably

## Bias, Risks, and Limitations

- Biases may be inherited from the IMDB dataset (e.g. genre or cultural bias)
- Model trained on movie reviews β€” performance may drop on domain-specific texts like legal or medical writing
- Scores represent probabilities, not certainty

### Recommendations

- Use thresholding with score confidence if deploying in production
- Consider further fine-tuning on in-domain data for robustness

## How to Get Started with the Model

```{python}
from transformers import pipeline

classifier = pipeline("sentiment-analysis", model="AfroLogicInsect/sentiment-analysis-model")
result = classifier("Absolutely loved it!")
print(result)
```


## Training Details

### Training Data

- Subset of stanfordnlp/imdb
- Balanced binary classes (positive and negative)
- Sample size: ~15,000 training / 1,500 validation

#### Training Hyperparameters

##### Training arguments
training_args = TrainingArguments(
    output_dir = "./sentiment-model-v2",
    num_train_epochs=3,
    per_device_train_batch_size=16,
    per_device_eval_batch_size=16,
    learning_rate=2e-5,  # Explicit learning rate
    warmup_steps=100,    # Reduced warmup
    weight_decay=0.01,
    logging_dir="./logs",
    logging_steps=50,
    eval_strategy="steps",
    eval_steps=200,      # < 500: More frequent evaluation
    save_strategy="steps",
    save_steps=200, # match eval_steps
    load_best_model_at_end=True,
    metric_for_best_model="f1",
    greater_is_better=True,
    seed=42,             # Reproducibility
    dataloader_drop_last=False,
    #remove_unused_columns=False,
)

##### Create trainer
trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=train_dataset,
    eval_dataset=val_dataset,
    tokenizer=tokenizer,
    data_collator=data_collator,
    compute_metrics=compute_metrics,
)

## Evaluation

### Testing Data, Factors & Metrics

#### Testing Data

- Validation set from IMDB subset

#### Metrics


Step	Training Loss	Validation Loss	Accuracy	F1	Precision	Recall
200	0.391100	0.344377	0.850000	0.863554	0.791991	0.949333
400	0.299000	0.304345	0.876000	0.865994	0.942006	0.801333
600	0.301700	0.298436	0.881333	0.888331	0.838863	0.944000
800	0.280700	0.260090	0.893333	0.897698	0.862408	0.936000
1000	0.173100	0.288142	0.899333	0.897766	0.911967	0.884000
1200	0.203700	0.263154	0.904667	0.905486	0.897772	0.913333
1400	0.186100	0.275240	0.904000	0.901370	0.926761	0.877333
1600	0.130400	0.291926	0.904667	0.903313	0.916324	0.890667
1800	0.158900	0.304814	0.908000	0.908488	0.903694	0.913333
2000	0.087900	0.332357	0.904000	0.905263	0.893506	0.917333
2200	0.119300	0.339073	0.908667	0.910399	0.893453	0.928000
2400	0.178100	0.366023	0.903333	0.905660	0.884371	0.928000
2600	0.072100	0.372015	0.909333	0.908356	0.918256	0.898667
2800	0.097700	0.368600	0.906667	0.908016	0.895078	0.921333

Final evaluation results: {
  'eval_loss': 0.3390733003616333, 
  'eval_accuracy': 0.9086666666666666, 
  'eval_f1': 0.9103989535644212, 
  'eval_precision': 0.8934531450577664, 
  'eval_recall': 0.928, 
  'eval_runtime': 9.9181, 
  'eval_samples_per_second': 151.239, 
  'eval_steps_per_second': 9.478, 'epoch': 3.0
}


### Results [Sample]

#### ============================================================
#### TESTING FIXED MODEL
#### ============================================================

Testing fixed model...
Text                                               Expected   Predicted  Confidence Match
==========================================================================================
I absolutely loved this movie! It was fantastic!   positive   positive   0.9959     βœ“
This movie was terrible and boring.                negative   negative   0.9969     βœ“
Amazing acting and great story!                    positive   positive   0.9959     βœ“
Worst film I've ever seen.                         negative   negative   0.9950     βœ“
Incredible cinematography and soundtrack.          positive   positive   0.9950     βœ“
Complete waste of time and money.                  negative   negative   0.9957     βœ“
The movie was okay, nothing special.               neutral    negative   0.9915     N/A
I enjoyed most of it.                              positive   positive   0.9912     βœ“
Pretty disappointing overall.                      negative   negative   0.9936     βœ“
Masterpiece of cinema!                             positive   positive   0.9939     βœ“

Overall Accuracy: 100.0% (9/9)

## πŸ§ͺ Live Demo

Try it out below!

πŸ‘‰ [Launch Sentiment Analyzer](https://huggingface.co/spaces/AfroLogicInsect/sentiment-analysis-model-gradio)


#### Summary

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.


## Environmental Impact

Carbon footprint estimated using [ML Impact Calculator](https://mlco2.github.io/impact#compute)

Hardware Type: GPU (single NVIDIA T4)
Hours used: ~2.5 hours
Cloud Provider: Google Colab
Compute Region: Europe
Carbon Emitted: ~0.3 kg COβ‚‚eq

## Technical Specifications [optional]

### Model Architecture and Objective

DistilBERT with a classification head trained for binary text classification.

### Compute Infrastructure
- Hardware: Google Colab (GPU-backed)
- Software: Python, PyTorch, πŸ€— Transformers, Hugging Face Hub

## Citation 

**BibTeX:**

[@misc{afrologicinsect2025sentiment,
  title = {AfroLogicInsect Sentiment Analysis Model},
  author = {Akan Daniel},
  year = {2025},
  howpublished = {\url{https://huggingface.co/AfroLogicInsect/sentiment-analysis-model_v2}},
}]


## Model Card Contact

- Name: Daniel (@AfroLogicInsect)
- Location: Lagos, Nigeria
- Contact: GitHub / Hugging Face / email (danielamahtoday@gmail.com)