Update README.md
Browse files
README.md
CHANGED
|
@@ -1,68 +1,65 @@
|
|
| 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 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
-
|
| 56 |
-
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
-
|
| 62 |
-
- Expand the dataset with custom data.
|
| 63 |
-
- Deploy the chatbot as a web app using Flask or Streamlit.
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
Feel free to fork this repository, open issues, or submit pull requests. Feedback is always welcome!
|
| 67 |
-
Contact
|
| 68 |
-
For questions, reach out via mohammadmehdiomidi95@gmail.com or connect with me on LinkedIn.
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- sentiment-analysis
|
| 4 |
+
- bert
|
| 5 |
+
- pytorch
|
| 6 |
+
- text-classification
|
| 7 |
+
license: mit
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# SentimentBot: A Sentiment Analysis Chatbot with BERT 🤖
|
| 11 |
+
|
| 12 |
+
## Overview
|
| 13 |
+
SentimentBot is a fine-tuned BERT model (bert-base-uncased) designed for sentiment analysis, trained on the SST-2 (Stanford Sentiment Treebank) dataset. This model predicts whether a given text expresses a positive or negative sentiment with high accuracy, achieving 92.3% accuracy and 92.3% F1 score on the validation set after 2 epochs. It was developed as part of an AI Engineer internship project focusing on NLP.
|
| 14 |
+
|
| 15 |
+
## Model Details
|
| 16 |
+
- Base Model: bert-base-uncased
|
| 17 |
+
- Dataset: SST-2 (2 classes: 0 = negative, 1 = positive)
|
| 18 |
+
- Training: Fine-tuned for 2 epochs with a batch size of 16
|
| 19 |
+
- Performance:
|
| 20 |
+
Eval Loss: 0.311
|
| 21 |
+
Accuracy: 92.3%
|
| 22 |
+
F1 Score: 92.3%
|
| 23 |
+
|
| 24 |
+
## Usage
|
| 25 |
+
To use the SentimentBot model in your Python project, install the required libraries and load the model as follows:
|
| 26 |
+
```
|
| 27 |
+
pip install transformers torch
|
| 28 |
+
```
|
| 29 |
+
```
|
| 30 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 31 |
+
import torch
|
| 32 |
+
|
| 33 |
+
# Load the model and tokenizer
|
| 34 |
+
tokenizer = AutoTokenizer.from_pretrained("moraix/SentimentBot")
|
| 35 |
+
model = AutoModelForSequenceClassification.from_pretrained("moraix/SentimentBot").to("cuda")
|
| 36 |
+
|
| 37 |
+
# Example input
|
| 38 |
+
text = "I love this movie so much!"
|
| 39 |
+
inputs = tokenizer(text, return_tensors="pt", padding="max_length", truncation=True, max_length=128).to("cuda")
|
| 40 |
+
|
| 41 |
+
# Predict sentiment
|
| 42 |
+
model.eval()
|
| 43 |
+
with torch.no_grad():
|
| 44 |
+
outputs = model(**inputs)
|
| 45 |
+
predictions = torch.softmax(outputs.logits, dim=1)
|
| 46 |
+
predicted_class = torch.argmax(predictions, dim=1).item()
|
| 47 |
+
confidence = predictions[0, predicted_class].item()
|
| 48 |
+
|
| 49 |
+
label_map = {0: "negative", 1: "positive"}
|
| 50 |
+
sentiment = label_map[predicted_class]
|
| 51 |
+
print(f"Text: {text}")
|
| 52 |
+
print(f"Sentiment: {sentiment} (Confidence: {confidence:.2f})")
|
| 53 |
+
```
|
| 54 |
+
## Intended Uses
|
| 55 |
+
- Primary Use: Analyzing sentiment in English text (e.g., movie reviews, social media posts).
|
| 56 |
+
- Out-of-Scope: Multi-class sentiment (e.g., neutral) or non-English text (requires further fine-tuning).
|
| 57 |
+
## Limitations
|
| 58 |
+
- Trained only on SST-2, so performance may vary on other datasets.
|
| 59 |
+
- Limited to binary classification (positive/negative).
|
| 60 |
+
## Future Improvements
|
| 61 |
+
- dd support for more complex sentiments (e.g., neutral, angry).
|
| 62 |
+
- Expand the dataset with custom data.
|
| 63 |
+
- Deploy the chatbot as a web app using Flask or Streamlit.
|
| 64 |
+
## Contributing
|
| 65 |
+
Feel free to fork this repository, open issues, or submit pull requests. Feedback is always welcome! Contact For questions, reach out via mohammadmehdiomidi95@gmail.com or connect with me on LinkedIn.
|
|
|
|
|
|
|
|
|