--- license: apache-2.0 datasets: - ParsiAI/snappfood-sentiment-analysis language: - fa metrics: - f1 - accuracy base_model: - myrkur/Persian-ModernBert-base library_name: transformers --- # ModernBERT-base-fa-snappfood Fine-tuned Persian sentiment analysis model based on [`myrkur/Persian-ModernBert-base`](https://huggingface.co/myrkur/Persian-ModernBert-base) for binary sentiment classification on the Snappfood Persian review dataset. ## Dataset The model was trained on the Snappfood Persian reviews dataset available on Hugging Face: * [Snappfood Dataset](https://huggingface.co/datasets/ParsiAI/snappfood-sentiment-analysis) ## Model Details * **Base model:** `myrkur/Persian-ModernBert-base` * **Task:** Sentiment Classification * **Language:** Persian (Farsi) * **Framework:** Transformers + PyTorch ## Usage ```python from 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) ``` ## Repository Training and inference scripts are available on [GitHub](https://github.com/aysangh/persian-sentiment-analysis).