moraix commited on
Commit
16811e9
·
verified ·
1 Parent(s): d7bbfc0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +65 -68
README.md CHANGED
@@ -1,68 +1,65 @@
1
- # SentimentBot: A Sentiment Analysis Chatbot with BERT 🤖
2
-
3
- ## Overview
4
- SentimentBot is a sentiment analysis chatbot built using BERT, fine-tuned on the SST-2 dataset. It predicts whether a given text expresses a positive or negative sentiment and responds interactively. This project was developed to enhance my NLP skills for an AI Engineer internship.
5
-
6
- - Model: BERT (bert-base-uncased)
7
- - Dataset: SST-2 (Stanford Sentiment Treebank)
8
- - Performance: Achieved 92.3% accuracy and 92.3% F1 score on the validation set after 2 epochs.
9
-
10
- ## Features
11
-
12
- - Analyzes sentiment of user input (positive/negative).
13
- - Interactive chatbot responses based on predicted sentiment.
14
- - Fine-tuned BERT model for high accuracy.
15
-
16
- ## Installation
17
- To run this project locally, follow these steps:
18
-
19
- 1. Clone the repository:
20
- ```
21
- git clone https://github.com/moraix/SentimentBot.git
22
- cd SentimentBot
23
- ```
24
-
25
-
26
- 2. Install dependencies:
27
- ```
28
- pip install torch transformers datasets sklearn
29
- ```
30
-
31
-
32
- ## Usage
33
-
34
- 1. Run the notebook:
35
-
36
- - Open SentimentBot.ipynb in Jupyter Notebook.
37
- - Follow the steps to train the model.
38
-
39
-
40
- 2. Test the chatbot:
41
-
42
- - Run the last cell in the notebook to interact with the chatbot.
43
- - Enter a sentence (e.g., "I love this movie!") and the bot will predict the sentiment and respond.
44
-
45
- Example:
46
- Text: I love this movie so much!
47
- Sentiment: positive (confidence: 0.95)
48
- I'm glad you liked it! 😊 Do you have any other comments?
49
-
50
-
51
- ## Results
52
- After fine-tuning BERT on SST-2 for 2 epochs:
53
-
54
- - Eval Loss: 0.311
55
- - Accuracy: 92.3%
56
- - F1 Score: 92.3%
57
- - Eval Runtime: 3.42 seconds
58
-
59
- ## Future Improvements
60
-
61
- - Add 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
-
65
- ## Contributing
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.