Skip to content

Lalith17/TweetSense

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TweetSense-AI 🐦🤖

A deep learning-powered web application for intelligent tweet classification using neural networks with attention mechanisms.

🌟 Features

  • 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

🚀 Quick Start

Prerequisites

  • Python 3.7+
  • TensorFlow 2.x
  • Flask
  • NumPy

Installation

  1. Clone the repository

    git clone <your-repo-url>
    cd TweetSense-AI
  2. Install dependencies

    pip install tensorflow flask numpy emoji
  3. Run the application

    python app.py
  4. Open your browser Navigate to http://localhost:5000

🏗️ Project Structure

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

🧠 Model Architecture

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

Custom Attention Layer

@keras.saving.register_keras_serializable()
class Attention(Layer):
    def __init__(self, return_sequences=True, **kwargs):
        super().__init__(**kwargs)
        self.return_sequences = return_sequences

📝 Text Preprocessing

The application automatically handles:

  • ✅ URL removal (https://, www.)
  • ✅ Emoji removal
  • ✅ Mention removal (@username)
  • ✅ HTML tag removal
  • ✅ Punctuation cleaning

🎯 Usage

  1. Enter a tweet in the text area on the web interface
  2. Click "Classify" to process the tweet
  3. View the prediction displayed below the form

Example Input:

"I love this new movie! It's absolutely amazing! 🎬✨"

Example Output:

Prediction: Positive

🛠️ Technical Details

  • 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

📊 Model Performance

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.

🔧 Configuration

Key parameters in app.py:

  • MAX_LEN = 40: Maximum sequence length for input processing
  • Model files: model.keras, tokenizer.pkl, label_encoder.pkl

🚀 Deployment

For production deployment:

  1. Set Flask to production mode:

    app.run(debug=False, host='0.0.0.0', port=5000)
  2. Use a production WSGI server like Gunicorn:

    pip install gunicorn
    gunicorn -w 4 -b 0.0.0.0:5000 app:app

📁 File Descriptions

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

🔍 How It Works

  1. Text Input: User enters tweet text through web interface
  2. Preprocessing: Text is cleaned using multiple preprocessing functions
  3. Tokenization: Text is converted to sequences using the pre-trained tokenizer
  4. Padding: Sequences are padded to consistent length (MAX_LEN=40)
  5. Prediction: Neural network with attention mechanism processes the sequence
  6. Output: Label encoder converts prediction to human-readable category

🎨 Web Interface

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

📈 Future Enhancements

  • 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

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors