Multi Class Text Classification with Keras and LSTM

Ferry Djaja
7 min readJun 9, 2020

In this tutorial, we will build a text classification with Keras and LSTM to predict the category of the BBC News articles.

LSTM (Long Short Term Memory)

LSTM was designed to overcome the problems of simple Recurrent Network (RNN) by allowing the network to store data in a sort of memory that it can access at a later times. LSTM is a special type of Recurrent Neural Network (RNN) that can learn long term patterns.


The key to LSTMs is the cell state, the horizontal line running through the top of the diagram. The cell state is updated twice with few computations that resulting stabilize gradients. It has also a hidden state that acts like a short term memory.

In LSTM there are Forget Gate, Input Gate and Output Gate that we will walk through it shortly.

Forget Gate

The first step is to decide what information we’re going to throw away from the cell state. This decision is made by a sigmoid layer called the “Forget…