A deep learning-powered web application for intelligent tweet classification using neural networks with attention mechanisms.
- Real-time Tweet Classification: Instantly classify tweets using a trained neural network model
- Attention Mechanism: Custom attention layer for better text understanding and context awareness
- Text Preprocessing: Comprehensive text cleaning including URL removal, emoji handling, and mention filtering
- Web Interface: Clean, responsive Flask web application for easy interaction
- Pre-trained Model: Ready-to-use trained model with tokenizer and label encoder
- Python 3.7+
- TensorFlow 2.x
- Flask
- NumPy
-
Clone the repository
git clone <your-repo-url> cd TweetSense-AI
-
Install dependencies
pip install tensorflow flask numpy emoji
-
Run the application
python app.py
-
Open your browser Navigate to
http://localhost:5000
TweetSense-AI/
├── app.py # Main Flask application
├── model.keras # Trained neural network model
├── tokenizer.pkl # Text tokenizer for preprocessing
├── label_encoder.pkl # Label encoder for predictions
├── templates/
│ └── index.html # Web interface template
└── README.md # Project documentation
The application uses a neural network with:
- Custom Attention Layer: Implements attention mechanism for better sequence understanding
- Text Preprocessing Pipeline: Comprehensive cleaning and normalization
- Sequence Processing: Tokenization and padding for consistent input format
@keras.saving.register_keras_serializable()
class Attention(Layer):
def __init__(self, return_sequences=True, **kwargs):
super().__init__(**kwargs)
self.return_sequences = return_sequencesThe application automatically handles:
- ✅ URL removal (
https://,www.) - ✅ Emoji removal
- ✅ Mention removal (
@username) - ✅ HTML tag removal
- ✅ Punctuation cleaning
- Enter a tweet in the text area on the web interface
- Click "Classify" to process the tweet
- View the prediction displayed below the form
"I love this new movie! It's absolutely amazing! 🎬✨"
Prediction: Positive
- Framework: TensorFlow/Keras for deep learning, Flask for web application
- Model Format: Keras HDF5 format (
.keras) - Text Processing: Custom preprocessing pipeline with regex and emoji handling
- Sequence Length: Maximum 40 tokens per input
- Architecture: Neural network with attention mechanism
The model is trained to classify tweets into predefined categories. Performance metrics depend on the specific training data and classification task used during model development.
Key parameters in app.py:
MAX_LEN = 40: Maximum sequence length for input processing- Model files:
model.keras,tokenizer.pkl,label_encoder.pkl
For production deployment:
-
Set Flask to production mode:
app.run(debug=False, host='0.0.0.0', port=5000)
-
Use a production WSGI server like Gunicorn:
pip install gunicorn gunicorn -w 4 -b 0.0.0.0:5000 app:app
| File | Description |
|---|---|
app.py |
Main Flask application with model loading and prediction logic |
model.keras |
Pre-trained TensorFlow/Keras model with attention mechanism |
tokenizer.pkl |
Serialized tokenizer for text preprocessing |
label_encoder.pkl |
Serialized label encoder for prediction decoding |
templates/index.html |
HTML template for the web interface |
- Text Input: User enters tweet text through web interface
- Preprocessing: Text is cleaned using multiple preprocessing functions
- Tokenization: Text is converted to sequences using the pre-trained tokenizer
- Padding: Sequences are padded to consistent length (MAX_LEN=40)
- Prediction: Neural network with attention mechanism processes the sequence
- Output: Label encoder converts prediction to human-readable category
The application features a clean, responsive design with:
- Centered layout with modern styling
- Large text area for tweet input
- Prominent classification button
- Clear prediction display
- Mobile-friendly design
- Add confidence scores for predictions
- Support for batch processing multiple tweets
- Real-time Twitter API integration
- Model retraining interface
- Additional text preprocessing options
- Export predictions to CSV/JSON
- Model performance metrics dashboard
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- TensorFlow/Keras for the deep learning framework
- Flask for the web application framework
- The open-source community for various preprocessing libraries
Built with ❤️ using TensorFlow, Flask, and Attention Mechanisms