This project connects to a MongoDB database, retrieves messages, and performs sentiment analysis using a pre-trained BERT model. The analyzed messages are displayed along with their respective sentiments.
- ✅ Connects to a local MongoDB database (
alumni_database). - ✅ Retrieves messages from the
messagescollection. - ✅ Analyzes sentiment using the
nlptown/bert-base-multilingual-uncased-sentimentmodel. - ✅ Sorts messages by timestamp in descending order.
- ✅ Outputs the message details along with sentiment classification.
Stars Sentiment ⭐ Very Negative ⭐⭐ Negative ⭐⭐⭐ Neutral ⭐⭐⭐⭐ Positive ⭐⭐⭐⭐⭐ Very Positive
- If sentiment analysis fails, an error message is displayed instead of the sentiment label.
- If fields are missing in MongoDB documents, they are replaced with placeholder values.
Make sure you have the following installed before running the script:
- Python 3.8+
- MongoDB installed and running locally
- Required Python libraries:
pip install pymongo torch transformers
Ensure MongoDB is running. -Run the script:
python sentimentanalysis.py