Views
No views yet
| Metric | Value |
|---|---|
| Test Accuracy | 0.9590 |
| Test F1 Score | 0.9791 |
| Test Precision | 1.0000 |
| Test Recall | 0.9590 |
| Parameter | Value |
|---|---|
| Training epochs | 3 |
| Batch size | 16 |
| Learning rate | 5e-05 |
| Warmup steps | 500 |
| Weight decay | 0.01 |
| Max sequence length | 512 |
1from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
2
3# Using pipeline (recommended for quick inference)
4classifier = pipeline("sentiment-analysis",
5 model="nkadoor/sentiment-classifier-roberta",
6 tokenizer="nkadoor/sentiment-classifier-roberta")
7
8result = classifier("This movie was amazing!")
9print(result) # [{'label': 'POSITIVE', 'score': 0.99}]1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5tokenizer = AutoTokenizer.from_pretrained("nkadoor/sentiment-classifier-roberta")
6model = AutoModelForSequenceClassification.from_pretrained("nkadoor/sentiment-classifier-roberta")
7
8def predict_sentiment(text):
9 inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
10
11 with torch.no_grad():
12 outputs = model(**inputs)
13 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
14 predicted_class = torch.argmax(predictions, dim=-1).item()
15 confidence = predictions[0][predicted_class].item()
16
17 sentiment = "positive" if predicted_class == 1 else "negative"
18 return sentiment, confidence
19
20# Example usage
21text = "This movie was absolutely fantastic!"
22sentiment, confidence = predict_sentiment(text)
23print(f"Sentiment: {sentiment} (Confidence: {confidence:.4f})")1@misc{sentiment-classifier-roberta,
2 title={Fine-tuned RoBERTa for Sentiment Analysis},
3 author={Narayana Kadoor},
4 year={2025},
5 url={https://huggingface.co/nkadoor/sentiment-classifier-roberta}
6}