File size: 744 Bytes
1157ec3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
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)}
")