Detect Text Sentiment With An LSTM Neural Network In C#

Mark Farragher
8 min readDec 3, 2019

In this article I’m going to build an app that can automatically detect the sentiment of an English text.

Three possible sentiment outcomes. You usually want the one on the right…

I actually tried this already in this article where I used a 1-dimensional convolutional neural network to analyze the movie review text. That approach worked quite well with a final accuracy of 86%, but unfortunately my solution started overfitting right away.

A much better way to analyze English text is by using a specialized type of recurrent neural network called an LSTM network.

All recurrent neural networks have an internal state (a type of memory) that helps them make sense of written language. But an LSTM network actually has two types of memory: long-term and short-term memory. That makes the network well-suited to process language.

So how will an LSTM network do? Will it perform better than the 1-dimensional convolutional network?

Let’s find out!

I will use the same IMDB Movie Dataset again, this is a dataset with 25,000 positive movie reviews and 25,000 negative movie reviews. The reviews look like this:

--

--