Sinanmz commited on
Commit
9089c9d
·
verified ·
1 Parent(s): 527e94f

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +98 -0
README.md ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: fa
3
+ license: mit
4
+ pipeline_tag: text-classification
5
+ ---
6
+
7
+
8
+ # SentenceFormalityClassifier
9
+
10
+ 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).
11
+
12
+
13
+ ## Evaluation Metrics
14
+
15
+ **INFORMAL**:
16
+
17
+ Precision: 0.99
18
+
19
+ Recall: 0.99
20
+
21
+ F1-Score: 0.99
22
+
23
+
24
+ **FORMAL**:
25
+
26
+ Precision: 0.99
27
+
28
+ Recall: 1.0
29
+
30
+ F1-Score: 0.99
31
+
32
+ **Accuracy**: 0.99
33
+
34
+
35
+ **Macro Avg**:
36
+
37
+ Precision: 0.99
38
+
39
+ Recall: 0.99
40
+
41
+ F1-Score: 0.99
42
+
43
+
44
+ **Weighted Avg**:
45
+
46
+ Precision: 0.99
47
+
48
+ Recall: 0.99
49
+
50
+ F1-Score: 0.99
51
+
52
+
53
+ ## Usage
54
+
55
+ ```python
56
+
57
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
58
+ import torch
59
+
60
+ labels = ["INFORMAL", "FORMAL"]
61
+
62
+ model = AutoModelForSequenceClassification.from_pretrained('parsi-ai-nlpclass/sentence_formality_classifier')
63
+ tokenizer = AutoTokenizer.from_pretrained('parsi-ai-nlpclass/sentence_formality_classifier')
64
+
65
+ def test_model(text):
66
+ inputs = tokenizer(text, return_tensors='pt')
67
+ outputs = model(**inputs)
68
+ predicted_label = labels[int(torch.argmax(outputs.logits))]
69
+ return predicted_label
70
+
71
+ # Test the model
72
+ text1 = "من فقط می‌خواستم بگویم که چقدر قدردان هستم."
73
+ print("Original:", text1)
74
+ print("Predicted Label:", test_model(text1))
75
+
76
+ # output: FORMAL
77
+
78
+ text2 = "آرزویش است او را یک رستوران ببرم."
79
+ print("\nOriginal:", text2)
80
+ print("Predicted Label:", test_model(text2))
81
+
82
+ # output: FORMAL
83
+
84
+ text3 = "گل منو اذیت نکنید"
85
+ print("\nOriginal:", text2)
86
+ print("Predicted Label:", test_model(text3))
87
+
88
+ # output: INFORMAL
89
+
90
+ text4 = "من این دوربین رو خالم برام کادو خرید"
91
+ print("\nOriginal:", text2)
92
+ print("Predicted Label:", test_model(text3))
93
+
94
+ # output: INFORMAL
95
+
96
+
97
+
98
+ ```