The convolutions that we have seen so far capture spatial relations in data as specific images. However, text has more of a sequential relationship, where words in the vicinity of a given account for more information for that particular word rather than any word appearing in a line right above them. Hence, for text data, we look at one-dimensional spatial relationships and leverage the Conv1D layer for this purpose. This is similar to going through n-grams, wherein there would be overlaps in consecutive n-gram windows. The value of n would be specified by the kernel size parameter you provide as input to the Conv1D layer.
The following diagram will help us understand how CNNs can be used to find patterns in text data:
The preceding diagram shows how word embeddings are sent across as inputs to the convolutional...