|
|
|
|
|
""" |
|
|
Bengali Sentiment Analysis - Inference Example |
|
|
=============================================== |
|
|
Usage: python inference_example.py |
|
|
""" |
|
|
|
|
|
from transformers import pipeline |
|
|
|
|
|
MODEL = "OsamaBinLikhon/bengali-code-mix-sentiment" |
|
|
|
|
|
def analyze(text): |
|
|
"""Analyze sentiment of Bengali/code-mixed text.""" |
|
|
classifier = pipeline("sentiment-analysis", model=MODEL) |
|
|
return classifier(text[:512])[0] |
|
|
|
|
|
if __name__ == "__main__": |
|
|
samples = [ |
|
|
"আজকের দিনটা খুবই ভালো গেছে!", |
|
|
"এই প্রোডাক্টটা একদম খারাপ", |
|
|
] |
|
|
|
|
|
for text in samples: |
|
|
print(f"Text: {text}") |
|
|
print(f"Sentiment: {analyze(text)} |
|
|
") |
|
|
|