Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π¬ Sentiment-Analysis-for-Product-Release-Sentiment
|
| 2 |
+
|
| 3 |
+
A **BERT-based sentiment analysis model** fine-tuned on a product review dataset. It predicts the sentiment of a text as **Positive**, **Neutral**, or **Negative** with a confidence score. This model is ideal for analyzing customer feedback, reviews, or user comments.
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## β¨ Model Highlights
|
| 8 |
+
|
| 9 |
+
- π **Architecture**: Based on [`bert-base-uncased`](https://huggingface.co/bert-base-uncased) by Google
|
| 10 |
+
- π§ **Fine-tuned** on labeled product review data
|
| 11 |
+
- π **3-way sentiment classification**: `Negative (0)`, `Neutral (1)`, `Positive (2)`
|
| 12 |
+
- πΎ **Quantized version available** for faster inference
|
| 13 |
+
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
## π§ Intended Uses
|
| 17 |
+
|
| 18 |
+
- β
Classifying product feedback and user reviews
|
| 19 |
+
- β
Sentiment analysis for e-commerce platforms
|
| 20 |
+
- β
Social media monitoring and customer opinion mining
|
| 21 |
+
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
## π« Limitations
|
| 25 |
+
|
| 26 |
+
- β Designed for English texts only
|
| 27 |
+
- β May not perform well on sarcastic or ironic inputs
|
| 28 |
+
- β May struggle with domains very different from product reviews
|
| 29 |
+
- β Input texts longer than 128 tokens are truncated
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
## ποΈββοΈ Training Details
|
| 34 |
+
|
| 35 |
+
- **Base Model**: `bert-base-uncased`
|
| 36 |
+
- **Dataset**: Custom-labeled product review dataset
|
| 37 |
+
- **Epochs**: 5
|
| 38 |
+
- **Batch Size**: 8
|
| 39 |
+
- **Max Length**: 128 tokens
|
| 40 |
+
- **Optimizer**: AdamW
|
| 41 |
+
- **Loss Function**: CrossEntropyLoss (with class balancing)
|
| 42 |
+
- **Hardware**: Trained on NVIDIA GPU (CUDA-enabled)
|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
## π Evaluation Metrics
|
| 47 |
+
|
| 48 |
+
| Metric | Score |
|
| 49 |
+
|------------|-------|
|
| 50 |
+
| Accuracy | 0.90 |
|
| 51 |
+
| F1 | 0.90 |
|
| 52 |
+
| Precision | 0.90 |
|
| 53 |
+
| Recall | 0.90 |
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## π Label Mapping
|
| 58 |
+
|
| 59 |
+
| Label ID | Sentiment |
|
| 60 |
+
|----------|-----------|
|
| 61 |
+
| 0 | Negative |
|
| 62 |
+
| 1 | Neutral |
|
| 63 |
+
| 2 | Positive |
|
| 64 |
+
|
| 65 |
+
---
|
| 66 |
+
|
| 67 |
+
## π Usage Example
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TrainingArguments
|
| 71 |
+
from transformers import DataCollatorWithPadding
|
| 72 |
+
import torch
|
| 73 |
+
import torch.nn.functional as F
|
| 74 |
+
|
| 75 |
+
# Load model and tokenizer
|
| 76 |
+
model_name = "AventIQ-AI/Sentiment-Analysis-for-Product-Release-Sentiment"
|
| 77 |
+
tokenizer = BertTokenizer.from_pretrained(model_name)
|
| 78 |
+
model = BertForSequenceClassification.from_pretrained(model_name)
|
| 79 |
+
model.eval()
|
| 80 |
+
|
| 81 |
+
# Inference
|
| 82 |
+
def predict_sentiment(text):
|
| 83 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 84 |
+
inputs = {k: v.to(quantized_model.device) for k, v in inputs.items()}
|
| 85 |
+
with torch.no_grad():
|
| 86 |
+
logits = quantized_model(**inputs).logits
|
| 87 |
+
probs = F.softmax(logits, dim=1)
|
| 88 |
+
|
| 89 |
+
predicted_class_id = torch.argmax(probs, dim=1).item()
|
| 90 |
+
confidence = probs[0][predicted_class_id].item()
|
| 91 |
+
|
| 92 |
+
label_map = {0: "Negative", 1: "Positive"}
|
| 93 |
+
label = label_map[predicted_class_id]
|
| 94 |
+
confidence_str = f"confidence : {confidence * 100:.1f}%"
|
| 95 |
+
|
| 96 |
+
return label, confidence_str
|
| 97 |
+
|
| 98 |
+
# Example
|
| 99 |
+
print(predict_sentiment(
|
| 100 |
+
"The service was excellent and the staff was friendly.")
|
| 101 |
+
)
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
---
|
| 105 |
+
|
| 106 |
+
## π§ͺ Quantization
|
| 107 |
+
|
| 108 |
+
- Applied **post-training dynamic quantization** using PyTorch to reduce model size and speed up inference.
|
| 109 |
+
- Quantized model supports CPU-based deployments.
|
| 110 |
+
|
| 111 |
+
---
|
| 112 |
+
|
| 113 |
+
## π Repository Structure
|
| 114 |
+
|
| 115 |
+
```
|
| 116 |
+
.
|
| 117 |
+
βββ model/ # Quantized model files
|
| 118 |
+
βββ tokenizer/ # Tokenizer config and vocabulary
|
| 119 |
+
βββ model.safetensors/ # Fine-tuned full-precision model
|
| 120 |
+
βββ README.md # Model documentation
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
---
|
| 124 |
+
|
| 125 |
+
## π Limitations
|
| 126 |
+
|
| 127 |
+
- May not generalize to completely different domains (e.g., medical, legal)
|
| 128 |
+
- Quantized version may show slight drop in accuracy compared to full-precision model
|
| 129 |
+
|
| 130 |
+
---
|
| 131 |
+
|
| 132 |
+
## π€ Contributing
|
| 133 |
+
|
| 134 |
+
We welcome contributions! Please feel free to raise an issue or submit a pull request if you find a bug or have a suggestion.
|