Building a CNN for text classification
Now that we know the basics of CNNs, we can begin to build one from scratch. In the previous chapter, we built a model for sentiment prediction, where sentiment was a binary classifier; 1
for positive and 0
for negative. However, in this example, we will aim to build a CNN for multi-class text classification. In a multi-class problem, a particular example can only be classified as one of several classes. If an example can be classified as many different classes, then this is multi-label classification. Since our model is multi-class, this means that our model will aim at predicting which one of several classes our input sentence is classified as. While this problem is considerably more difficult than our binary classification task (as our sentence can now belong to one of many, rather than one of two classes), we will show that CNNs can deliver good performance on this task. We will first begin by defining our data.