So in this lecture, we'll be introducing the next section of this course, which is all about convolutional
neural networks.
We also call these CNN's essentially this section is made up of two parts.
The first part will discuss the theory behind scenes and how they work.
This will make up a majority of this section, since the reasoning goes pretty deep.
The second part we'll look at how to apply CNN's to text.
Now, I want to make it explicit that the first part on the theory of CNN's is optional if you prefer
to skip straight to the code preparation.
You can feel free to do so and opt out of understanding how CNN's work.
There is a lot of math, so if you don't like math, then this is not for you or if you already know
how CNN's work.
Then again, feel free to skip this part.
So clearly, this idea of convolutional neural networks has something to do with convolution.
In fact, a convolutional neural network is nothing but a neural network with convolution in it.
So a majority of this section will be devoted to simply helping you understand what kind of solution
even is and why it works.
Now, it turns out that CNN's were originally invented for images.
Understanding how convolution works for images is much more intuitive, simply because we can see images
and visualize the effects of convolution.
As such, our discussion on convolution will start with images, even though this is, of course, about
NLP.
It simply makes more sense.
What you'll come to see is that an image is merely a two dimensional continuous signal.
On the other hand, something like a time series is a one dimensional continuous signal.
Furthermore, when we convert text into vectors, this is basically also a time series, but with multiple
features and thus using the CNN for NLP is the same as using a CNN for a time series.
So I want to expand on this idea a bit more that a sequence of word vectors is just a time series.
Firstly, I think it's helpful to think of an actual time series.
Consider a sequence of stock returns from the S&P.
Clearly, you and I can agree that this is a time series.
If we were to store these values inside an umpire, we would have a one dimensional sequence of length
T to turn this into a machine learning problem.
Suppose we want to predict whether tomorrow's stock price will go up or down.
Now, of course, we might want to include different inputs to our model like pass volume and perhaps
some technical indicators.
Clearly, each of these also forms a time series of lengthy.
Suppose we have such time series, then in total, if we were to put all these together, we would have
time series each of 9:30.
But if we combine them into a single array, we could store this in a matrix of size t by.
Of course, this is also exactly what we have when we convert text into vectors.
Suppose we have a sentence.
I like eggs and bacon.
This is a sequence of length.
Five.
So two years.
Five.
Suppose we then pass these through an embedding layer such that we have the vector for ie, the vector
for like the vector for eggs and so forth.
The result is that we get two vectors each of size.
In effect, we have a T by D matrix or, in other words, the time series.
Each of sequence length T, therefore a time series of word embeddings is no different than a time series
of stock returns or technical indicators, as a side note.
Although this might be a bit confusing, we do consider both of these time series to be one dimensional.
Even though they occupy a two dimensional array, this is because we consider things like time and space
to be indices over which we do convolution, but not different features.
Don't worry if this doesn't make perfect sense now, but be prepared to consider this thought as you
go through the CNN lectures.
As you'll see, images are considered two dimensional, even though they are stored in three dimensional
arrays.