Building a sentiment analyzer using LSTMs
We will now look at how to build our own simple LSTM to categorize sentences based on their sentiment. We will train our model on a dataset of 3,000 reviews that have been categorized as positive or negative. These reviews come from three different sources—film reviews, product reviews, and location reviews—in order to ensure that our sentiment analyzer is robust. The dataset is balanced so that it consists of 1,500 positive reviews and 1,500 negative reviews. We will start by importing our dataset and examining it:
with open("sentiment labelled sentences/sentiment.txt") as f: reviews = f.read() data = pd.DataFrame([review.split('\t') for review in reviews.split('\n')]) data.columns = ['Review','Sentiment']...