So far, we've applied CNNs to image data. As stated in the introduction, CNNs can also be applied to other types of input data. In the following recipe, we will show how you can apply a CNN to textual data. More specifically, we will use the structure of CNNs to classify text. Unlike images, which are 2D, text has 1D input data. Therefore, we will be using 1D convolutional layers in our next recipe. The Keras framework makes it really easy to pre-process the input data.
Applying a 1D CNN to text
How to do it...
- Let's start with importing the libraries as follows:
import numpy as np
from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras...