File size: 989 Bytes
ccd7e96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# تثبيت المكتبات المطلوبة
# !pip install transformers torch

from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline

# نختار موديل فارسي جاهز
model_name = "HooshvareLab/bert-fa-base-uncased-sentiment-snappfood"

# تحميل التوكنيزر والموديل
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

# نعمل Pipeline للتحليل
sentiment_pipeline = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)

# نجرب نصوص بالفارسية
texts = [
    "من این فیلم را خیلی دوست دارم",   # جملة إيجابية
    "این غذا افتضاح بود",              # جملة سلبية
    "امروز یک روز معمولی است"         # جملة محايدة
]

for t in texts:
    result = sentiment_pipeline(t)
    print(f"متن: {t}")
    print(f"نتیجه: {result}\n")