Classifying Text Data into Multiple Categories

Original article was published on Artificial Intelligence on Medium

Part I: The Basics

Goal

Input & Output

We will import the Reuters news-wire data set that’s part of the keras datasets.

Encoding & Decoding

We’re also gonna encode our training labels into one-hot vectors. While the keras data set doesn’t provide any label strings. A very similar data set of Reuters newswires has labels such as:

wheat
corn
coffee
nat-gas
etc...

Decoding the result is simple, the highest probability value in the 46 vector is the network’s best guess.

Architecture

Our optimizer is rmsprop. Our loss function is categorical_crossentropy, which means our neural network is always trying to minimize the cross entropy between the actual label data and the network’s current best guess.

Regularization