shikhararyan's picture
Update README.md
eaca97b verified
metadata
license: mit
language:
  - en
pipeline_tag: text-classification
tags:
  - NLP
  - Sentiment_analysis

Sentiment Analysis Flask App

This Flask web application uses a pre-trained Transformer model to perform sentiment analysis on user-provided text. The model predicts whether the sentiment of the input text is positive, negative, or neutral.

Model Architecture

The implemented model leverages a Transformer architecture for sentiment analysis. The Transformer block consists of multiple self-attention mechanisms applied iteratively (num_heads). Each attention mechanism captures different aspects of the input sequence, allowing the model to efficiently learn complex patterns. A subsequent 1D convolutional layer is employed to capture local patterns, followed by global average pooling for dimensionality reduction. Dropout is used for regularization, and the final layers include a dense layer with ReLU activation and a sigmoid activation for binary sentiment classification.

Usage

  1. Installation: Install the required Python packages using the following command:

    pip install -r requirements.txt

Run the Flask App: Execute the Flask app by running the following command: python app.py

This will start the Flask development server, and the app will be accessible at http://localhost:5000.

Enter Text: Enter your text in the input field and click the "Predict" button.

View Prediction: The app will display the predicted sentiment (Positive, Negative, or Neutral) based on the input text.

Dependencies

  • Flask
  • Keras
  • TensorFlow
  • NLTK

Model Training

  1. Load the Dataset: Read the IMDB dataset from a CSV file and preprocess the text data.

  2. Data Cleaning and Preprocessing: Clean and preprocess the text data by removing non-alphabetic characters, converting text to lowercase, and removing stopwords.

  3. Data Splitting: Split the dataset into training and testing sets.

  4. Label Encoding for Sentiment Column: Encode the categorical sentiment labels into numerical format using LabelEncoder.

  5. Tokenization and Padding: Tokenize and pad the text sequences for input into the Transformer model.

  6. Transformer Model Building: Define a Transformer model architecture using Keras.

  7. Model Training: Compile and train the Transformer model on the training data.

  8. Save the Model: Save the trained model in the HDF5 format for future use.

  9. Evaluate the Model: Evaluate the model on the test set, compute accuracy, and generate a classification report.