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.
- Overview
- Features
- Technologies Used
- Dataset
- Model Training
- Understanding LSTM
- How to Run the Application
- Folder Structure
- Contributing
- License
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.
- 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.
- Python
- Flask
- TensorFlow/Keras
- GloVe Word Embeddings (200-dimensional)
- Bootstrap (UI Styling)
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
- 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.
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.
- Cell State:
Acts as the memory of the LSTM, retaining information over time. It flows through the network, undergoing modifications via gates. - 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.
Ensure you have the following installed:
- Python 3.8 or later
- TensorFlow
- Flask
- Numpy
- GloVe embeddings
- Clone the repository:
git clone https://github.com/PavanKumar1207/SentimentAnalysis_LSTM.git cd sentiment-analysis-lstm - Install dependencies:
pip install -r requirements.txt
- Place the trained model (sentiment_model.h5) and tokenizer (tokenizer.pkl) in the root directory. Run the Flask application:
python app.py- Open your browser and go to http://127.0.0.1:5000.
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 Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch:
git checkout -b feature-branch
- Make your changes and commit them:
git commit -m 'Add new feature'- Push to the branch:
git push origin feature-branch- 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!
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.
- 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.

