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