LSTM in Amazon Customer Sentiments

This Python notebook explores sentiment analysis on consumer reviews of Amazon products using Long Short-Term Memory (LSTM) neural networks.

Introduction:

This Python notebook delves into sentiment analysis applied to consumer reviews of Amazon products using Long Short-Term Memory (LSTM) neural networks. Sentiment analysis plays a crucial role in understanding customer feedback, which is invaluable for businesses seeking to enhance their products and services. In this project, we aim to predict the sentiment labels of Amazon product reviews, ranging from positive to negative, utilizing deep learning techniques. The notebook is structured to guide through the entire process, from importing and exploring the dataset to preprocessing the text data and implementing the LSTM classifier.

1.Importing Data:

This section focuses on loading the dataset containing Amazon product reviews into the notebook environment. It involves utilizing Python libraries such as Pandas to efficiently handle and manipulate the data. By importing the dataset, we lay the foundation for further analysis and model development.

2.Exploring Data:

Exploring the dataset is crucial for gaining insights into its structure, attributes, and potential patterns. This section involves examining the basic statistics of the dataset, such as the number of samples, features, and the distribution of sentiment labels. Exploratory data analysis techniques are employed to uncover any trends or anomalies within the data.

3.Distribution Plots (Word Cloud):

Visualizing the distribution of sentiment labels within the dataset provides a deeper understanding of the sentiment distribution across different categories of reviews. In this section, we utilize word clouds to visually represent the most frequently occurring words in positive, negative, and neutral sentiment reviews. This analysis aids in identifying common themes and sentiments expressed in the reviews.

4.Removing Stop Words from Text Data in English:

Text preprocessing is essential for preparing the textual data for model training. One common preprocessing step is the removal of stop words, which are commonly occurring words that typically do not carry significant meaning or sentiment. In this section, we leverage libraries like NLTK or SpaCy to remove stop words from the text data, ensuring that our model focuses on relevant information for sentiment analysis.

5.LSTM Classifier using PyTorch:

The LSTM classifier is implemented using the PyTorch deep learning framework. A custom neural network class is defined, utilizing LSTM layers to model the sequential nature of the text data. The model is trained on the preprocessed text data to predict the sentiment labels of Amazon product reviews.

Final Results:

              precision    recall  f1-score   support

           0       0.00      0.00      0.00       141
           1       0.00      0.00      0.00       215
           2       0.94      1.00      0.97      5185

    accuracy                           0.94      5541
   macro avg       0.31      0.33      0.32      5541
weighted avg       0.88      0.94      0.90      5541

Accuracy: 0.9357516693737592