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.
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3import torch.nn.functional as F
4
5model_name = "your-username/sentiment-roberta-user-reviews"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8model.eval()
9
10def predict(text):
11 inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
12 with torch.no_grad():
13 outputs = model(**inputs)
14 probs = F.softmax(outputs.logits, dim=1)
15 pred = torch.argmax(probs, dim=1).item()
16 label_map = {0: "Negative", 1: "Positive"}
17 return f"Sentiment: {label_map[pred]} (Confidence: {probs[0][pred]:.2f})"
18
19# Example
20print(predict("I really love this product, works great!"))
21
22
23
24📁 Repository Structure
25python
26Copy
27Edit
28.
29├── model/ # Contains fine-tuned model files
30├── tokenizer/ # Tokenizer config and vocab
31├── config.json # Model configuration
32├── pytorch_model.bin # Fine-tuned model weights
33├── README.md # Model card
34
35
36
37🤝 Contributing
38Contributions are welcome! Feel free to open an issue or submit a pull request if you have suggestions or improvements.
39
40
41
42
43
44