Downloads · 30 days
49
0% of all-time downloads
Muddassar/longformer-base-sentiment-5-classes
longformer-base-sentiment-5-classes is a machine learning model from Muddassar. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This model is a fine-tuned version of the Longformer base model for sentiment analysis. It classifies text into 5 sentiment categories.
Downloads · 30 days
49
0% of all-time downloads
All-time downloads
52.4K
Public
Parameters
149M
595 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors595 MB · 100%
From the Hugging Face model README
This model is a fine-tuned version of the Longformer base model for sentiment analysis. It classifies text into 5 sentiment categories.
Classification Report:
precision recall f1-score support
0 0.75 1.00 0.86 98
1 0.67 0.55 0.60 87
2 0.84 0.75 0.79 108
3 0.83 0.43 0.57 79
4 0.70 0.91 0.79 105
accuracy 0.75 477
macro avg 0.76 0.73 0.72 477
weighted avg 0.76 0.75 0.73 477
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
hf_model_name= 'Muddassar/longformer-base-sentiment-5-classes'
model = AutoModelForSequenceClassification.from_pretrained(hf_model_name)
tokenizer = AutoTokenizer.from_pretrained(hf_model_name)
text = "Your text here"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=1500)
with torch.no_grad():
outputs = model(**inputs)
prediction = torch.argmax(outputs.logits, dim=1).item()
sentiment_map = {0: "Very Negative", 1: "Negative", 2: "Neutral", 3: "Positive", 4: "Very Positive"}
print(f"Predicted sentiment: {sentiment_map[prediction]}")
MIT