ParsiAI/snappfood-sentiment-analysis
Viewer • Updated • 69.5k • 399 • 6
How to use aysangh/ModernBERT-base-fa-snappfood with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="aysangh/ModernBERT-base-fa-snappfood") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("aysangh/ModernBERT-base-fa-snappfood")
model = AutoModelForSequenceClassification.from_pretrained("aysangh/ModernBERT-base-fa-snappfood")Fine-tuned Persian sentiment analysis model based on myrkur/Persian-ModernBert-base for binary sentiment classification on the Snappfood Persian review dataset.
The model was trained on the Snappfood Persian reviews dataset available on Hugging Face:
myrkur/Persian-ModernBert-basefrom transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name = "aysangh/ModernBERT-base-fa-snappfood"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
def predict_sentiment(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256, padding=True)
with torch.no_grad():
outputs = model(**inputs)
probs = torch.softmax(outputs.logits, dim=-1)
pred = torch.argmax(probs, dim=-1).item()
confidence = probs[0][pred].item()
return {
"label": "positive" if pred == 0 else "negative",
"confidence": confidence
}
text = "سفارش خیلی سریع رسید و کیفیت غذا خوب بود."
result = predict_sentiment(text)
print(result)
Training and inference scripts are available on GitHub.
Base model
answerdotai/ModernBERT-base