Update README.md
Browse files
README.md
CHANGED
@@ -63,4 +63,80 @@ By Language:
|
|
63 |
|
64 |

|
65 |
|
66 |
-

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |

|
65 |
|
66 |
+

|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
## Usage example
|
71 |
+
|
72 |
+
```python
|
73 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
74 |
+
import torch
|
75 |
+
|
76 |
+
tokenizer = AutoTokenizer.from_pretrained("LenDigLearn/formality-classifier-mdeberta-v3-base")
|
77 |
+
model = AutoModelForSequenceClassification.from_pretrained('LenDigLearn/formality-classifier-mdeberta-v3-base')
|
78 |
+
|
79 |
+
def get_result(text):
|
80 |
+
inputs = tokenizer(text, return_tensors="pt")
|
81 |
+
with torch.no_grad():
|
82 |
+
logits = model(**inputs).logits
|
83 |
+
predicted_class_id = logits.argmax().item()
|
84 |
+
return model.config.id2label[predicted_class_id]
|
85 |
+
|
86 |
+
|
87 |
+
print("DE:")
|
88 |
+
texts_de = [
|
89 |
+
"Verschwinde", "Nein", "Ja", "vielleicht", "Warum bist du so?",
|
90 |
+
"Können Sie mir spontan dabei helfen?", "Bitte senden Sie uns die nötigen Unterlagen zu.", "Dies müssen Sie selbst entscheiden, wenn Sie den entsprechenden Punkt erreicht haben.", "Sie sind also Herr Müller.", "Bitte helfen Sie mir!",
|
91 |
+
"Man muss schon wissen, was dann passiert.", "Als nächstes kommen 4g Champignons und 500g Mehl dazu.", "Bananen sind krumm.", "Das ist eine Tatsache, die unumstößlich ist.", "Hilfestellungen sind unter \"Hilfe\" zu finden."
|
92 |
+
]
|
93 |
+
for text in texts_de:
|
94 |
+
print(get_result(text))
|
95 |
+
|
96 |
+
print("-----------\nEN:")
|
97 |
+
texts_en = [
|
98 |
+
"Piss off", "No", "Yes", "maybe", "Why are you like this?",
|
99 |
+
"Could you help me spontaneously?", "Please send me the necessary documents.", "You will have to decide this individually as soon as you have reached the relevant point.", "I presume you are Mr. Müller?", "Please offer me your support!",
|
100 |
+
"One would have to know what happens then.", "Then, we add 4g Mushrooms and 500g flour.", "Bananas are usually curved.", "That is an irrefutable fact.", "You can find helpful tutorials under \"help\"."
|
101 |
+
]
|
102 |
+
for text in texts_en:
|
103 |
+
print(get_result(text))
|
104 |
+
```
|
105 |
+
|
106 |
+
**Outputs:**
|
107 |
+
|
108 |
+
```bash
|
109 |
+
DE:
|
110 |
+
informal
|
111 |
+
informal
|
112 |
+
informal
|
113 |
+
informal
|
114 |
+
informal
|
115 |
+
formal
|
116 |
+
formal
|
117 |
+
formal
|
118 |
+
formal
|
119 |
+
formal
|
120 |
+
neutral
|
121 |
+
neutral
|
122 |
+
neutral
|
123 |
+
neutral
|
124 |
+
neutral
|
125 |
+
-----------
|
126 |
+
EN:
|
127 |
+
informal
|
128 |
+
informal
|
129 |
+
informal
|
130 |
+
informal
|
131 |
+
informal
|
132 |
+
formal
|
133 |
+
formal
|
134 |
+
formal
|
135 |
+
formal
|
136 |
+
formal
|
137 |
+
neutral
|
138 |
+
neutral
|
139 |
+
neutral
|
140 |
+
neutral
|
141 |
+
neutral
|
142 |
+
```
|