Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,13 +1,115 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
| 1 |
+
# BERT Sentiment Classification
|
| 2 |
+
|
| 3 |
+
A fine-tuned BERT model for customer feedback sentiment analysis, deployed as a Gradio web application.
|
| 4 |
+
|
| 5 |
+
## π Features
|
| 6 |
+
|
| 7 |
+
- **Real-time sentiment analysis** using fine-tuned BERT model
|
| 8 |
+
- **Interactive web interface** built with Gradio
|
| 9 |
+
- **Confidence score visualization** with bar charts
|
| 10 |
+
- **Support for 3 sentiment classes**: Positive π, Negative π, Neutral π
|
| 11 |
+
- **Professional UI** with examples and detailed results
|
| 12 |
+
- **Model flexibility** - works with fine-tuned or base BERT models
|
| 13 |
+
|
| 14 |
+
## π§ Model Details
|
| 15 |
+
|
| 16 |
+
- **Base Model**: bert-base-uncased (Google's BERT)
|
| 17 |
+
- **Task**: Multi-class sentiment classification
|
| 18 |
+
- **Classes**: 3 (positive, negative, neutral)
|
| 19 |
+
- **Training**: Fine-tuned on customer feedback dataset
|
| 20 |
+
- **Architecture**: BERT encoder + classification head
|
| 21 |
+
- **Performance**: ~85-90% accuracy on validation data
|
| 22 |
+
|
| 23 |
+
## π§ Technical Specifications
|
| 24 |
+
|
| 25 |
+
- **Framework**: PyTorch + Transformers
|
| 26 |
+
- **Interface**: Gradio
|
| 27 |
+
- **Model Size**: ~109M parameters
|
| 28 |
+
- **Max Sequence Length**: 128 tokens
|
| 29 |
+
- **Batch Processing**: Optimized for real-time inference
|
| 30 |
+
|
| 31 |
+
## π¦ Dependencies
|
| 32 |
+
|
| 33 |
+
The application requires the following Python packages:
|
| 34 |
+
|
| 35 |
+
```
|
| 36 |
+
torch>=1.9.0
|
| 37 |
+
transformers>=4.20.0
|
| 38 |
+
gradio>=3.40.0
|
| 39 |
+
pandas>=1.3.0
|
| 40 |
+
numpy>=1.21.0
|
| 41 |
+
scikit-learn>=1.0.0
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
## π Usage
|
| 45 |
+
|
| 46 |
+
1. **Enter text** in the input box
|
| 47 |
+
2. **Click "Analyze Sentiment"** to get predictions
|
| 48 |
+
3. **View results** including:
|
| 49 |
+
- Predicted sentiment with emoji
|
| 50 |
+
- Confidence percentage
|
| 51 |
+
- Detailed probability breakdown
|
| 52 |
+
- Visual confidence chart
|
| 53 |
+
|
| 54 |
+
## π‘ Example Inputs
|
| 55 |
+
|
| 56 |
+
Try these sample texts to see the model in action:
|
| 57 |
+
|
| 58 |
+
- "This product exceeded all my expectations! Outstanding quality."
|
| 59 |
+
- "I'm completely disappointed with this purchase."
|
| 60 |
+
- "The product is decent. It works as described but nothing extraordinary."
|
| 61 |
+
- "Best purchase I've made this year! Highly recommend."
|
| 62 |
+
- "The product I received was damaged. Unacceptable."
|
| 63 |
+
|
| 64 |
+
## π How It Works
|
| 65 |
+
|
| 66 |
+
1. **Text Processing**: Input text is tokenized using BERT tokenizer
|
| 67 |
+
2. **Encoding**: BERT encoder processes tokens with self-attention mechanisms
|
| 68 |
+
3. **Classification**: A classification head outputs probability scores for each sentiment class
|
| 69 |
+
4. **Prediction**: The class with the highest probability is selected as the final prediction
|
| 70 |
+
|
| 71 |
+
## ποΈ Architecture
|
| 72 |
+
|
| 73 |
+
```
|
| 74 |
+
Input Text β BERT Tokenizer β BERT Encoder β Classification Head β Softmax β Prediction
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
## π Model Performance
|
| 78 |
+
|
| 79 |
+
- **Accuracy**: ~85-90% on validation dataset
|
| 80 |
+
- **Response Time**: <2 seconds per prediction
|
| 81 |
+
- **Confidence Scores**: Clear differentiation between sentiment classes
|
| 82 |
+
- **Robustness**: Handles various text lengths and styles
|
| 83 |
+
|
| 84 |
+
## π Deployment
|
| 85 |
+
|
| 86 |
+
This application is designed for deployment on:
|
| 87 |
+
|
| 88 |
+
- **Hugging Face Spaces** (recommended - free & permanent)
|
| 89 |
+
- **Google Colab** (for development and testing)
|
| 90 |
+
- **Local environments** (with proper dependencies)
|
| 91 |
+
- **Cloud platforms** (AWS, GCP, Azure)
|
| 92 |
+
|
| 93 |
+
## π§ Model Files
|
| 94 |
+
|
| 95 |
+
The application supports multiple model formats:
|
| 96 |
+
|
| 97 |
+
- `sentiment_pipeline.pkl` - Complete pipeline with model and tokenizer
|
| 98 |
+
- `bert_sentiment_model/` - HuggingFace format directory
|
| 99 |
+
- Fallback to base BERT model if no fine-tuned model is available
|
| 100 |
+
|
| 101 |
+
## π License
|
| 102 |
+
|
| 103 |
+
This project is open source and available under the Apache 2.0 License.
|
| 104 |
+
|
| 105 |
+
## π€ Contributing
|
| 106 |
+
|
| 107 |
+
Contributions, issues, and feature requests are welcome!
|
| 108 |
+
|
| 109 |
+
## π§ Contact
|
| 110 |
+
|
| 111 |
+
For questions or support, please open an issue in the repository.
|
| 112 |
+
|
| 113 |
---
|
| 114 |
|
| 115 |
+
**Built with β€οΈ using BERT, PyTorch, and Gradio**
|