https://github.com/deepmancer/tweet-disaster-detection
fine-tuned BERT and scikit-learn models for real-time classification of disaster-related tweets, using TensorFlow, Keras, and Transformers. .
https://github.com/deepmancer/tweet-disaster-detection
bert bert-fine-tuning classification fine-tuning huggingface-transformers keras keras-tensorflow natural-language-processing nlp scikit-learn tensorflow tensorflow2 tokenizer transformers
Last synced: over 1 year ago
JSON representation
fine-tuned BERT and scikit-learn models for real-time classification of disaster-related tweets, using TensorFlow, Keras, and Transformers. .
- Host: GitHub
- URL: https://github.com/deepmancer/tweet-disaster-detection
- Owner: deepmancer
- Created: 2023-10-22T09:41:45.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-16T11:29:17.000Z (almost 2 years ago)
- Last Synced: 2024-10-11T20:02:56.143Z (over 1 year ago)
- Topics: bert, bert-fine-tuning, classification, fine-tuning, huggingface-transformers, keras, keras-tensorflow, natural-language-processing, nlp, scikit-learn, tensorflow, tensorflow2, tokenizer, transformers
- Language: Jupyter Notebook
- Homepage:
- Size: 4.38 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# đŠī¸ Tweet Disaster Detection
---
## đ Introduction
Welcome to the **Tweet Disaster Detection** repository! This project is an advanced Natural Language Processing (NLP) solution designed to identify disaster-related tweets in real-time. By leveraging cutting-edge machine learning and deep learning techniques, this system empowers decision-makers with timely information to respond effectively to emergencies. đ
With the explosion of social media usage, the ability to rapidly detect disaster events through user-generated content has become critical. Our solution is optimized for accuracy and reliability, ensuring robust disaster identification.
---
## đ Key Features
- **State-of-the-Art Models**: Fine-tuned **BERT** transformer for high-precision tweet classification.
- **Real-Time Analysis**: Designed to process and classify tweets quickly and accurately.
- **Actionable Insights**: Focused on real-world applications, such as early disaster warnings and accurate reporting.
- **Scalable Solution**: Easily adaptable to different datasets or NLP tasks.
---
## đ§ Libraries and Frameworks
This project utilizes several powerful tools:
- **[TensorFlow](https://www.tensorflow.org/)** and **[Keras](https://keras.io/)**: Core frameworks for implementing and fine-tuning the BERT model.
- **[Huggingface Transformers](https://huggingface.co/transformers/)**: Pre-trained BERT models and tokenization utilities for NLP tasks.
- **[scikit-learn](https://scikit-learn.org/)**: For traditional ML tasks like Naive Bayes classification and evaluation metrics.
- **[Matplotlib](https://matplotlib.org/)**: Visualization tools for model performance analysis.
- **[Pandas](https://pandas.pydata.org/)**: Data manipulation and preprocessing for tweet analysis.
---
## đĄ Project Overview
In a flood of tweets generated every second, discerning disaster-related content is challenging. This system addresses this challenge by distinguishing tweets that indicate real disasters from irrelevant content, using a fine-tuned **BERT** model for exceptional performance.
### đ§ Model Overview
Our primary model is a fine-tuned **BERT** transformer with the following pipeline:
1. **Preprocessing**:
- Tweets are tokenized with BERT's tokenizer, converting text into token IDs, attention masks, and segment IDs.
2. **Model Architecture**:
- A dense layer is added to the pre-trained BERT model to classify tweets as disaster-related or not.
```python
input_word_ids = Input(shape=(self.max_seq_length,), dtype=tf.int32, name='input_word_ids')
input_mask = Input(shape=(self.max_seq_length,), dtype=tf.int32, name='input_mask')
segment_ids = Input(shape=(self.max_seq_length,), dtype=tf.int32, name='segment_ids')
pooled_output, sequence_output = self.bert_layer([input_word_ids, input_mask, segment_ids])
clf_output = sequence_output[:, 0, :]
out = Dense(1, activation='sigmoid')(clf_output)
model = Model(inputs=[input_word_ids, input_mask, segment_ids], outputs=out)
```
3. **Training**:
- Trained using **SGD optimizer** with learning rate `0.0001` and momentum `0.8`.
- Metrics tracked: accuracy, precision, recall, and F1-score.
---
## đ Results
| Model | Precision | Recall | Accuracy | F1-Score |
|----------------|:---------:|:------:|:--------:|:--------:|
| **BERT** | 86% | 84% | 85% | 86% |
| **Naive Bayes**| 82% | 70% | 56% | 75% |
### đ Visualizations
- **Learning Curves**: Visualize accuracy, precision, and recall across epochs.
- **Confusion Matrix**: Detailed analysis of model predictions.
---
## đ Real-World Applications
This system has several impactful applications:
1. **Early Warning Systems**: Provide timely disaster alerts for proactive interventions.
2. **Accurate Reporting**: Filter out irrelevant information for reliable disaster communication.
3. **Emergency Response**: Aid first responders with real-time disaster insights.
---
## đ ī¸ How to Use
### Prerequisites
- Python 3.7 or higher
- Recommended: NVIDIA GPU for faster training (optional)
### Installation Steps
1. **Clone the Repository**:
```bash
git clone https://github.com/deepmancer/tweet-disaster-detection.git
cd tweet-disaster-detection
```
2. **Install Dependencies**:
```bash
pip install -r requirements.txt
```
3. **Run the Jupyter Notebook**:
- Open `Advanced_Data_Science_Capstone.ipynb` to explore the code and see results.
4. **Predict Disaster Tweets**:
- Follow the notebook instructions to classify new tweets using the trained model.
---
## đ¤ Contributing
We welcome contributions to enhance this project! Here's how you can contribute:
1. Fork the repository.
2. Create a feature branch:
```bash
git checkout -b feature-name
```
3. Commit your changes:
```bash
git commit -m "Description of changes"
```
4. Push your branch:
```bash
git push origin feature-name
```
5. Open a Pull Request.
---
## đ License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
---
## đ Support & Feedback
If you find this project useful, please **star** this repository! â
Feel free to open issues for suggestions, feedback, or questions. Let's make disaster response smarter together!