Update README.md
Browse files
README.md
CHANGED
@@ -1,26 +1,118 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
```python
|
4 |
-
import torch
|
5 |
-
from torch.utils.data import Dataset, DataLoader
|
6 |
-
from torch.optim import AdamW
|
7 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
|
8 |
import torch.nn.functional as F
|
9 |
|
10 |
-
|
11 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
12 |
-
model = AutoModelForSequenceClassification.from_pretrained(
|
13 |
-
|
14 |
|
15 |
def predict(text):
|
16 |
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
|
17 |
with torch.no_grad():
|
18 |
-
outputs =
|
19 |
probs = F.softmax(outputs.logits, dim=1)
|
20 |
pred = torch.argmax(probs, dim=1).item()
|
21 |
-
label_map = {0: "Negative", 1: "
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
# Test predictions
|
25 |
-
print("\nTest Predictions:")
|
26 |
-
print(predict("the product quality is just so good"))
|
|
|
1 |
+
# π§ SentimentClassifier-RoBERTa-UserReviews
|
2 |
+
|
3 |
+
A RoBERTa-based sentiment analysis model fine-tuned on user review data. This model classifies reviews as **Positive** or **Negative**, making it ideal for analyzing product feedback, customer reviews, and other short user-generated content.
|
4 |
+
|
5 |
+
---
|
6 |
+
|
7 |
+
## β¨ Model Highlights
|
8 |
+
|
9 |
+
π Based on `cardiffnlp/twitter-roberta-base-sentiment` (from Cardiff NLP)
|
10 |
+
π Fine-tuned on binary-labeled user reviews (positive vs. negative)
|
11 |
+
β‘ Supports prediction of 2 classes: Positive, Negative
|
12 |
+
π§ Built using Hugging Face π€ Transformers and PyTorch
|
13 |
+
|
14 |
+
---
|
15 |
+
|
16 |
+
## π§ Intended Uses
|
17 |
+
|
18 |
+
- β
Customer review sentiment classification
|
19 |
+
- β
E-commerce product feedback analysis
|
20 |
+
- β
App review categorization
|
21 |
+
|
22 |
+
---
|
23 |
+
|
24 |
+
## π« Limitations
|
25 |
+
|
26 |
+
- β Not optimized for multi-class sentiment (Neutral, Sarcasm, etc.)
|
27 |
+
- π Trained primarily on English-language reviews
|
28 |
+
- π Performance may degrade for texts >128 tokens (due to max length truncation)
|
29 |
+
- π€ Not designed for domain-specific jargon (e.g., legal or medical texts)
|
30 |
+
|
31 |
+
---
|
32 |
+
|
33 |
+
## ποΈββοΈ Training Details
|
34 |
+
|
35 |
+
| Attribute | Value |
|
36 |
+
|-------------------|----------------------------------------|
|
37 |
+
| Base Model | cardiffnlp/twitter-roberta-base-sentiment |
|
38 |
+
| Dataset | Filtered user reviews (binary labeled) |
|
39 |
+
| Labels | Positive (1), Negative (0) |
|
40 |
+
| Max Token Length | 128 |
|
41 |
+
| Epochs | 3 |
|
42 |
+
| Batch Size | 8 |
|
43 |
+
| Optimizer | AdamW |
|
44 |
+
| Loss Function | CrossEntropyLoss |
|
45 |
+
| Framework | PyTorch + Hugging Face Transformers |
|
46 |
+
| Hardware | CUDA-enabled GPU |
|
47 |
+
|
48 |
+
---
|
49 |
+
|
50 |
+
## π Evaluation Metrics
|
51 |
+
|
52 |
+
| Metric | Score |
|
53 |
+
|------------|--------|
|
54 |
+
| Accuracy | 0.94 |
|
55 |
+
| Precision | 0.93 |
|
56 |
+
| Recall | 0.95 |
|
57 |
+
| F1 Score | 0.94 |
|
58 |
+
|
59 |
+
> π Replace with your final values after complete training if these were updated.
|
60 |
+
|
61 |
+
---
|
62 |
+
|
63 |
+
## π Label Mapping
|
64 |
+
|
65 |
+
| Label ID | Sentiment |
|
66 |
+
|----------|-----------|
|
67 |
+
| 0 | Negative |
|
68 |
+
| 1 | Positive |
|
69 |
+
|
70 |
+
---
|
71 |
+
|
72 |
+
## π Usage
|
73 |
|
74 |
```python
|
|
|
|
|
|
|
75 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
76 |
+
import torch
|
77 |
import torch.nn.functional as F
|
78 |
|
79 |
+
model_name = "your-username/sentiment-roberta-user-reviews"
|
80 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
81 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
82 |
+
model.eval()
|
83 |
|
84 |
def predict(text):
|
85 |
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
|
86 |
with torch.no_grad():
|
87 |
+
outputs = model(**inputs)
|
88 |
probs = F.softmax(outputs.logits, dim=1)
|
89 |
pred = torch.argmax(probs, dim=1).item()
|
90 |
+
label_map = {0: "Negative", 1: "Positive"}
|
91 |
+
return f"Sentiment: {label_map[pred]} (Confidence: {probs[0][pred]:.2f})"
|
92 |
+
|
93 |
+
# Example
|
94 |
+
print(predict("I really love this product, works great!"))
|
95 |
+
|
96 |
+
|
97 |
+
|
98 |
+
π Repository Structure
|
99 |
+
python
|
100 |
+
Copy
|
101 |
+
Edit
|
102 |
+
.
|
103 |
+
βββ model/ # Contains fine-tuned model files
|
104 |
+
βββ tokenizer/ # Tokenizer config and vocab
|
105 |
+
βββ config.json # Model configuration
|
106 |
+
βββ pytorch_model.bin # Fine-tuned model weights
|
107 |
+
βββ README.md # Model card
|
108 |
+
|
109 |
+
|
110 |
+
|
111 |
+
π€ Contributing
|
112 |
+
Contributions are welcome! Feel free to open an issue or submit a pull request if you have ideas to improve this model or documentation.
|
113 |
+
|
114 |
+
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
|
|
|
|
|
|