Skip to content

About

Experience a deep-learning sentiment analyzer that tokenizes and embeds text before feeding it through LSTM layers to classify sentiments with precision. Explore the clean codebase—data preprocessing scripts, model training routines, and notebook-driven evaluation—to replicate and elevate your own NLP projects.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Sentiment Analysis with LSTM and GloVe Word Embeddings

This project demonstrates a sentiment analysis system for restaurant reviews, built using an LSTM (Long Short-Term Memory) model and GloVe word embeddings (200-dimensional). The project includes a Flask-based web application to provide a user-friendly interface for analyzing the sentiment of textual reviews.

Screenshot 2025-01-15 145805

Table of Contents


Overview

This project aims to classify restaurant reviews as either positive or negative using deep learning techniques. The application includes:

  • Preprocessing of input text.
  • An LSTM model trained with GloVe word embeddings for robust semantic understanding.
  • A Flask web application for providing predictions via a user-friendly UI.

Features

  • Sentiment Prediction: Analyze reviews and classify them as positive or negative.
  • Preprocessing: Text preprocessing to clean and standardize input text.
  • Interactive UI: A simple web interface to input and analyze reviews.
  • Bootstrap Integration: A responsive and visually appealing design.

Technologies Used

  • Python
  • Flask
  • TensorFlow/Keras
  • GloVe Word Embeddings (200-dimensional)
  • Bootstrap (UI Styling)

Dataset

The model was trained on a dataset of restaurant reviews. The dataset was preprocessed to clean text and prepare it for training. Preprocessing steps included:

  • Lowercasing text
  • Removing special characters
  • Tokenization and padding

Model Training

  • Word Embeddings: Used pre-trained GloVe embeddings (200 dimensions).
  • Neural Network: LSTM layers for capturing temporal dependencies in text.
  • Training Parameters:
    • Optimizer: Adam
    • Loss Function: Binary Crossentropy
    • Metrics: Accuracy

The trained model is saved as sentiment_model.h5 for deployment.


Understanding LSTM

LSTM (Long Short-Term Memory) networks are a type of Recurrent Neural Network (RNN) that excel in handling sequential data by maintaining long-term dependencies. This makes them particularly effective for tasks like sentiment analysis.

image

Key Components of LSTMs:

  1. Cell State:
    Acts as the memory of the LSTM, retaining information over time. It flows through the network, undergoing modifications via gates.
  2. Gates:
    LSTMs use gates to regulate the flow of information:
    • Forget Gate: Decides what information to discard from the cell state.
    • Input Gate: Updates the cell state with new information.
    • Output Gate: Determines the output and updates the hidden state.

These mechanisms allow LSTMs to capture both short-term and long-term dependencies in text data, making them ideal for sentiment analysis tasks where context matters.

For a more detailed explanation, refer to this excellent blog: Understanding LSTMs by Christopher Olah.


How to Run the Application

Prerequisites

Ensure you have the following installed:

  • Python 3.8 or later
  • TensorFlow
  • Flask
  • Numpy
  • GloVe embeddings

Installation Steps

  1. Clone the repository:
    git clone https://github.com/PavanKumar1207/SentimentAnalysis_LSTM.git
    cd sentiment-analysis-lstm
  2. Install dependencies:
    pip install -r requirements.txt
  3. Place the trained model (sentiment_model.h5) and tokenizer (tokenizer.pkl) in the root directory. Run the Flask application:
python app.py
  1. Open your browser and go to http://127.0.0.1:5000.

Folder Structure

sentiment-analysis-lstm/
│
├── app.py               # Flask application
├── preprocess.py           # Preprocessing utilities
├── Reviews.csv             # Dataset used to train
├── tokenizer.pkl           # Tokenizer for input text
├── sentiment_model.h5      # Trained LSTM model
├── templates/
│   └── index.html          # Frontend template
├── static/
│   ├── bg_1.jpeg           # Background image
├── requirements.txt        # Python dependencies
└── README.md  

Contributing

Contributions are welcome! If you'd like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch:
    git checkout -b feature-branch
  3. Make your changes and commit them:
git commit -m 'Add new feature'
  1. Push to the branch:
git push origin feature-branch
  1. Open a pull request and describe your changes.

We appreciate all contributions, from bug fixes and feature enhancements to documentation improvements. Thank you for helping make this project better!

License

This project is licensed under the MIT License.
You are free to use, modify, and distribute this software under the terms of the MIT License.


Acknowledgments

  • GloVe Word Embeddings: Used for vector representation of words in this project (GloVe website).
  • Bootstrap: Utilized for styling the Flask web application's interface (Bootstrap website).
  • TensorFlow: Employed for building and training the LSTM model (TensorFlow website).

Special thanks to the open-source community for providing tools and resources that made this project possible.

About

Experience a deep-learning sentiment analyzer that tokenizes and embeds text before feeding it through LSTM layers to classify sentiments with precision. Explore the clean codebase—data preprocessing scripts, model training routines, and notebook-driven evaluation—to replicate and elevate your own NLP projects.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages