File size: 1,942 Bytes
205140f f4b3e33 205140f f4b3e33 205140f f4b3e33 408f2f3 f4b3e33 408f2f3 f4b3e33 0d100d6 f4b3e33 0d100d6 f4b3e33 0d100d6 f4b3e33 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
---
language: fa
license: mit
pipeline_tag: text-classification
---
# SentenceFormalityClassifier
This model is fine-tuned to classify text based on formality. It has been fine-tuned on [Mohavere Dataset] (Takalli vahideh, Kalantari, Fateme, Shamsfard, Mehrnoush, Developing an Informal-Formal Persian Corpus, 2022.) using the pretrained model [persian-t5-formality-transfer](https://huggingface.co/HooshvareLab/bert-base-parsbert-uncased).
## Evaluation Metrics
**INFORMAL**:
Precision: 0.99
Recall: 0.99
F1-Score: 0.99
**FORMAL**:
Precision: 0.99
Recall: 1.0
F1-Score: 0.99
**Accuracy**: 0.99
**Macro Avg**:
Precision: 0.99
Recall: 0.99
F1-Score: 0.99
**Weighted Avg**:
Precision: 0.99
Recall: 0.99
F1-Score: 0.99
## Usage
```python
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
labels = ["INFORMAL", "FORMAL"]
model = AutoModelForSequenceClassification.from_pretrained('parsi-ai-nlpclass/sentence_formality_classifier')
tokenizer = AutoTokenizer.from_pretrained('parsi-ai-nlpclass/sentence_formality_classifier')
def test_model(text):
inputs = tokenizer(text, return_tensors='pt')
outputs = model(**inputs)
predicted_label = labels[int(torch.argmax(outputs.logits))]
return predicted_label
# Test the model
text1 = "من فقط میخواستم بگویم که چقدر قدردان هستم."
print("Original:", text1)
print("Predicted Label:", test_model(text1))
# output: FORMAL
text2 = "آرزویش است او را یک رستوران ببرم."
print("\nOriginal:", text2)
print("Predicted Label:", test_model(text2))
# output: FORMAL
text3 = "گل منو اذیت نکنید"
print("\nOriginal:", text2)
print("Predicted Label:", test_model(text3))
# output: INFORMAL
text4 = "من این دوربین رو خالم برام کادو خرید"
print("\nOriginal:", text2)
print("Predicted Label:", test_model(text3))
# output: INFORMAL
``` |