Instructions to use aysangh/ModernBERT-base-fa-taghche with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use aysangh/ModernBERT-base-fa-taghche with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="aysangh/ModernBERT-base-fa-taghche")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("aysangh/ModernBERT-base-fa-taghche") model = AutoModelForSequenceClassification.from_pretrained("aysangh/ModernBERT-base-fa-taghche", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- fa
|
| 5 |
+
metrics:
|
| 6 |
+
- f1
|
| 7 |
+
- accuracy
|
| 8 |
+
base_model:
|
| 9 |
+
- myrkur/Persian-ModernBert-base
|
| 10 |
+
library_name: transformers
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# ModernBERT-base-fa-taghche
|
| 14 |
+
|
| 15 |
+
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 Taaghche Persian review dataset.
|
| 16 |
+
|
| 17 |
+
## Dataset
|
| 18 |
+
|
| 19 |
+
The model was trained on the Taaghche Persian reviews dataset available on Kaggle:
|
| 20 |
+
|
| 21 |
+
* [Taaghche Dataset](https://www.kaggle.com/saeedtqp/taaghche)
|
| 22 |
+
|
| 23 |
+
## Model Details
|
| 24 |
+
|
| 25 |
+
* **Base model:** `myrkur/Persian-ModernBert-base`
|
| 26 |
+
* **Task:** Sentiment Classification
|
| 27 |
+
* **Language:** Persian (Farsi)
|
| 28 |
+
* **Framework:** Transformers + PyTorch
|
| 29 |
+
|
| 30 |
+
## Usage
|
| 31 |
+
|
| 32 |
+
```python
|
| 33 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 34 |
+
import torch
|
| 35 |
+
|
| 36 |
+
model_name = "aysangh/ModernBERT-base-fa-taghche"
|
| 37 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 38 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 39 |
+
|
| 40 |
+
def predict_sentiment(text):
|
| 41 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256, padding=True)
|
| 42 |
+
with torch.no_grad():
|
| 43 |
+
outputs = model(**inputs)
|
| 44 |
+
probs = torch.softmax(outputs.logits, dim=-1)
|
| 45 |
+
pred = torch.argmax(probs, dim=-1).item()
|
| 46 |
+
confidence = probs[0][pred].item()
|
| 47 |
+
return {
|
| 48 |
+
"label": "positive" if pred == 0 else "negative",
|
| 49 |
+
"confidence": confidence
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
text = "خیلی بد بود، اصلاً پیشنهاد نمیکنم."
|
| 53 |
+
|
| 54 |
+
result = predict_sentiment(text)
|
| 55 |
+
print(result)
|
| 56 |
+
|
| 57 |
+
# Output:
|
| 58 |
+
# {'label': 'negative', 'confidence': 0.9999935626983643}
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
## Repository
|
| 62 |
+
|
| 63 |
+
Training and inference scripts are available on [GitHub](https://github.com/aysangh/persian-sentiment-analysis).
|