File size: 2,671 Bytes
2358766
 
 
 
 
 
 
 
8c3e4b6
594a61d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
language: en
license: apache-2.0
tags:
  - sentiment-analysis
  - text-classification
model_name: "Your Model Name"
datasets: "dataset-used"
---

---

# **Fine-Tuned Sentiment Analysis Model**
  
[![Hugging Face Model](https://img.shields.io/badge/Hugging%20Face-Sentiment%20Model-yellow)](https://huggingface.co/ktr008/sentiment)  
πŸ”— **Model ID:** `ktr008/sentiment`  
πŸ“… **Last Updated:** `2025-02-25`  
πŸš€ **Framework:** PyTorch | Transformers  

## **πŸ“Œ Model Description**
This is a **fine-tuned RoBERTa model** for **sentiment analysis** based on the **Twitter RoBERTa Base** model. It classifies text into **Positive, Neutral, or Negative** sentiments.  

## **πŸ› οΈ How to Use**
### **Install Dependencies**  
```sh
pip install transformers torch scipy
```
### **Load Model & Tokenizer**
```python
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import numpy as np
from scipy.special import softmax

model = AutoModelForSequenceClassification.from_pretrained("ktr008/sentiment")
tokenizer = AutoTokenizer.from_pretrained("ktr008/sentiment")

def predict_sentiment(text):
    encoded_input = tokenizer(text, return_tensors='pt')
    output = model(**encoded_input)
    scores = output[0][0].detach().numpy()
    scores = softmax(scores)
    
    labels = ["Negative", "Neutral", "Positive"]
    ranking = np.argsort(scores)[::-1]
    
    return {labels[i]: round(float(scores[i]), 4) for i in ranking}

# Example usage
print(predict_sentiment("I love this product!"))
```

## **πŸ’‘ Training Details**
- **Base Model:** `cardiffnlp/twitter-roberta-base-sentiment-latest`  
- **Dataset:** Custom dataset with labeled sentiment texts  
- **Fine-Tuning:** Performed on AWS EC2 with PyTorch  
- **Batch Size:** 16  
- **Optimizer:** AdamW  
- **Learning Rate:** 5e-5  

## **πŸ“ Example Predictions**
| Text | Prediction |
|-------|------------|
| `"I love this product!"` | Positive (98.3%) |
| `"It's an okay experience."` | Neutral (67.4%) |
| `"I hate this! Never buying again."` | Negative (92.1%) |

## **πŸ“ˆ Performance**
- **Accuracy:** `0.9344`  

## **πŸ“Œ Model Limitations**
- May struggle with **sarcasm or ambiguous phrases**.  
- Can be **biased** towards the training dataset.  
- Not suitable for **long texts** without truncation.  

## **πŸ“ Citation**
If you use this model, please cite:  
```
@model{ktr008_sentiment_2025,
  author    = {ktr008},
  title     = {Fine-Tuned Sentiment Analysis Model},
  year      = {2025},
  publisher = {Hugging Face},
  version   = {1.0}
}
```

## **πŸ“¬ Contact**
For issues or suggestions, reach out to me on [Hugging Face](https://huggingface.co/ktr008) πŸš€

---