nimaafshar
commited on
Commit
•
ea0b984
1
Parent(s):
d816f9e
readme created
Browse files
README.md
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
ParsBERT digikala sentiment analysis model fine-tuned on around 600,000 Persian tweets.
|
2 |
+
# How to use
|
3 |
+
at least you need 650 megabytes of ram and disk in order to load the model.
|
4 |
+
tensorflow, transformers and numpy library
|
5 |
+
|
6 |
+
## Loading model
|
7 |
+
```python
|
8 |
+
import numpy as np
|
9 |
+
from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
|
10 |
+
#loading model
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained("nimaafshar/parsbert-fa-sentiment-twitter")
|
12 |
+
|
13 |
+
model = TFAutoModelForSequenceClassification.from_pretrained("nimaafshar/parsbert-fa-sentiment-twitter")
|
14 |
+
classes = ["negative","neutral","positive"]
|
15 |
+
```
|
16 |
+
## Using Model
|
17 |
+
```python
|
18 |
+
|
19 |
+
#using model
|
20 |
+
sequences = [".غذا خیلی افتضاح بود متاسفم برای مدیریت رستورن خیلی بد بود.",
|
21 |
+
"خیلی خوشمزده و عالی بود عالی",
|
22 |
+
"میتونم اسمتونو بپرسم؟"
|
23 |
+
]
|
24 |
+
|
25 |
+
for sequence in sequences:
|
26 |
+
inputs = tokenizer(sequence, return_tensors="tf")
|
27 |
+
classification_logits = model(inputs)[0]
|
28 |
+
results = tf.nn.softmax(classification_logits, axis=1).numpy()[0]
|
29 |
+
print(classes[np.argmax(results)])
|
30 |
+
percentages = np.around(results*100)
|
31 |
+
print(percentages)
|
32 |
+
```
|