File size: 1,255 Bytes
ea0b984
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e2a350
 
 
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
ParsBERT digikala sentiment analysis model fine-tuned on around 600,000 Persian tweets.
# How to use
at least you need 650 megabytes of ram and disk in order to load the model.
tensorflow, transformers and numpy library

## Loading model
```python
import numpy as np
from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
#loading model
tokenizer = AutoTokenizer.from_pretrained("nimaafshar/parsbert-fa-sentiment-twitter")
  
model = TFAutoModelForSequenceClassification.from_pretrained("nimaafshar/parsbert-fa-sentiment-twitter")
classes = ["negative","neutral","positive"]
```
## Using Model
```python

#using model
sequences = [".غذا خیلی افتضاح بود متاسفم برای مدیریت رستورن خیلی بد بود.",
 "خیلی خوشمزده و عالی بود عالی",
"می‌تونم اسمتونو بپرسم؟"
]

for sequence in sequences:
  inputs = tokenizer(sequence, return_tensors="tf")
  classification_logits = model(inputs)[0]
  results = tf.nn.softmax(classification_logits, axis=1).numpy()[0]
  print(classes[np.argmax(results)])
  percentages = np.around(results*100)
  print(percentages)
```

note that this model is trained on persian corpus and is meant to be used on persian texts too.