Jabbari commited on
Commit
332a2d7
·
1 Parent(s): 851ea61

Create model.py

Browse files
Files changed (1) hide show
  1. model.py +20 -0
model.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForSequenceClassification,AutoTokenizer
2
+ #import tensorflow as tf
3
+ #print(tf.__version__)
4
+ # replace "path/to/model/directory" with the path to the directory containing the model files
5
+ tokenizer = AutoTokenizer.from_pretrained("ALANZI/imamu_arabic_sentimentAnalysis")
6
+ model = AutoModelForSequenceClassification.from_pretrained("ALANZI/imamu_arabic_sentimentAnalysis")
7
+
8
+
9
+ def predict_sentiment(text):
10
+ # Tokenize input text
11
+ inputs = tokenizer(text, return_tensors="pt")
12
+
13
+ # Pass the tokenized inputs through the model
14
+ outputs = model(**inputs)
15
+
16
+ # Get predicted sentiment
17
+ predictions = outputs.logits.argmax(dim=1)
18
+ sentiment = "Negative" if predictions.item() == 1 else "Positive"
19
+
20
+ return sentiment