Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: transformers
|
| 4 |
+
pipeline_tag: text-classification
|
| 5 |
+
tags:
|
| 6 |
+
- sentiment-analysis
|
| 7 |
+
- text-classification
|
| 8 |
+
- distilbert
|
| 9 |
+
- fine-tuned
|
| 10 |
+
- nlp
|
| 11 |
+
language:
|
| 12 |
+
- en
|
| 13 |
+
datasets:
|
| 14 |
+
- sentiment140
|
| 15 |
+
metrics:
|
| 16 |
+
- accuracy
|
| 17 |
+
- f1
|
| 18 |
+
base_model: distilbert-base-uncased
|
| 19 |
+
model-index:
|
| 20 |
+
- name: my-sentiment-model
|
| 21 |
+
results:
|
| 22 |
+
- task:
|
| 23 |
+
type: text-classification
|
| 24 |
+
name: Text Classification
|
| 25 |
+
dataset:
|
| 26 |
+
name: sentiment140
|
| 27 |
+
type: sentiment140
|
| 28 |
+
metrics:
|
| 29 |
+
- name: Accuracy
|
| 30 |
+
type: accuracy
|
| 31 |
+
value: 0.85
|
| 32 |
+
- name: F1 Score (Macro)
|
| 33 |
+
type: f1
|
| 34 |
+
value: 0.84
|
| 35 |
+
---
|
| 36 |
+
|
| 37 |
+
# My DistilBERT Sentiment Model
|
| 38 |
+
|
| 39 |
+
Fine-tuned DistilBERT for 3-class sentiment classification (negative, neutral, positive).
|
| 40 |
+
|
| 41 |
+
## Model Description
|
| 42 |
+
|
| 43 |
+
This model is a fine-tuned version of DistilBERT-base-uncased for sentiment analysis. It has been trained to classify text into three sentiment categories:
|
| 44 |
+
|
| 45 |
+
- **Negative** (0)
|
| 46 |
+
- **Neutral** (1)
|
| 47 |
+
- **Positive** (2)
|
| 48 |
+
|
| 49 |
+
## Intended Uses
|
| 50 |
+
|
| 51 |
+
This model is intended for sentiment analysis tasks on English text. It can be used to:
|
| 52 |
+
- Analyze customer feedback and reviews
|
| 53 |
+
- Monitor social media sentiment
|
| 54 |
+
- Classify emotions in text data
|
| 55 |
+
- Support content moderation systems
|
| 56 |
+
|
| 57 |
+
## Limitations
|
| 58 |
+
|
| 59 |
+
- Trained primarily on English text
|
| 60 |
+
- May not perform well on domain-specific jargon
|
| 61 |
+
- Performance may vary on very short or very long texts
|
| 62 |
+
- Potential bias from training data
|
| 63 |
+
|
| 64 |
+
## Training Details
|
| 65 |
+
|
| 66 |
+
- **Base Model**: distilbert-base-uncased
|
| 67 |
+
- **Training Epochs**: 2
|
| 68 |
+
- **Batch Size**: 8
|
| 69 |
+
- **Learning Rate**: 3e-5
|
| 70 |
+
- **Max Sequence Length**: 128
|
| 71 |
+
- **Optimizer**: AdamW
|
| 72 |
+
- **Weight Decay**: 0.01
|
| 73 |
+
|
| 74 |
+
## Model Performance
|
| 75 |
+
|
| 76 |
+
The model achieves the following performance on the test set:
|
| 77 |
+
|
| 78 |
+
- **Accuracy**: 85%
|
| 79 |
+
- **F1-Score (Macro)**: 84%
|
| 80 |
+
- **F1-Score (Weighted)**: 85%
|
| 81 |
+
|
| 82 |
+
## Usage
|
| 83 |
+
|
| 84 |
+
Install the required dependencies:
|
| 85 |
+
|
| 86 |
+
```bash
|
| 87 |
+
pip install transformers torch
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
Load and use the model:
|
| 91 |
+
|
| 92 |
+
```python
|
| 93 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 94 |
+
import torch
|
| 95 |
+
|
| 96 |
+
# Load model and tokenizer
|
| 97 |
+
model_name = "your-username/my-sentiment-model"
|
| 98 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 99 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 100 |
+
|
| 101 |
+
# Prepare text
|
| 102 |
+
text = "I love this product!"
|
| 103 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128)
|
| 104 |
+
|
| 105 |
+
# Get prediction
|
| 106 |
+
with torch.no_grad():
|
| 107 |
+
outputs = model(**inputs)
|
| 108 |
+
probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 109 |
+
predicted_class = torch.argmax(probabilities, dim=-1).item()
|
| 110 |
+
|
| 111 |
+
# Map prediction to label
|
| 112 |
+
labels = {0: "negative", 1: "neutral", 2: "positive"}
|
| 113 |
+
confidence = probabilities[0][predicted_class].item()
|
| 114 |
+
|
| 115 |
+
print(f"Text: {text}")
|
| 116 |
+
print(f"Sentiment: {labels[predicted_class]} (confidence: {confidence:.2%})")
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
## Citation
|
| 120 |
+
|
| 121 |
+
If you use this model in your research, please cite:
|
| 122 |
+
|
| 123 |
+
```bibtex
|
| 124 |
+
@misc{my-sentiment-model,
|
| 125 |
+
author = {Your Name},
|
| 126 |
+
title = {Fine-tuned DistilBERT for Sentiment Analysis},
|
| 127 |
+
year = {2025},
|
| 128 |
+
publisher = {Hugging Face},
|
| 129 |
+
url = {https://huggingface.co/your-username/my-sentiment-model}
|
| 130 |
+
}
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
## License
|
| 134 |
+
|
| 135 |
+
This model is released under the MIT License.
|