Sentiment Analysis
Text-এ positive না negative emotion আছে detect করা।
একটা product review পড়ে আপনি বুঝতে পারেন user খুশি না রাগী। কিন্তু Amazon এ daily কোটি কোটি review আসে — মানুষ পড়ে শেষ করতে পারবে না। Sentiment Analysis এর কাজ এখানেই — text এর emotion automatic detect করা।
Sentiment Analysis হলো text classification এর একটি বিশেষ form, যেখানে category হলো emotion/opinion — সাধারণত Positive, Negative, Neutral। কিছু advanced system fine-grained emotion (joy, anger, sadness, fear) ও detect করতে পারে। Aspect-based sentiment analysis specific feature (camera, battery) এর উপর opinion বের করে।
ভাবুন একটা restaurant review: 'খাবার ভালো ছিল কিন্তু service খুব slow'। Overall mixed — কিন্তু 'food' aspect এ positive, 'service' aspect এ negative। Sentiment analysis word level pattern (good, bad, love, hate, terrible) থেকে শুরু করে context (not good = negative) পর্যন্ত বুঝতে পারে।
from transformers import pipeline
sentiment = pipeline("sentiment-analysis")
reviews = [
"This phone has an amazing camera and great battery life!",
"Worst purchase ever. Broke within a week. Total waste of money.",
"It is okay, nothing special but does the job.",
"Absolutely love it! Best decision I made this year.",
]
for review in reviews:
result = sentiment(review)[0]
print(f"Text: {review}")
print(f" -> {result['label']} (score: {result['score']:.4f})\n")HuggingFace এর pipeline() function pre-trained sentiment model load করে (default: distilbert-base-uncased-finetuned-sst-2-english)। প্রতিটা text এ POSITIVE বা NEGATIVE label এর সাথে confidence score দেয়। কোনো training লাগে না — production ready।
একটি Python script যা CSV ফাইল থেকে product reviews পড়ে, HuggingFace pipeline দিয়ে sentiment predict করে, এবং final report এ দেখায় কতগুলো positive/negative/neutral, এবং top 5 most negative review highlight করে।