Build a 1D convolutional neural network, part 1: Create a test data set
Skills:
Supervised Learning80%
Key Takeaways
This video teaches how to create a test data set for a 1D convolutional neural network
Full Transcript
we would really like to take our convolutional block out for a spin so in order to do that we need an appropriate data set we need a one dimensional data set so one dimensional array that has some kind of a pattern in it that's recognizable but that might fall in a different location each time this is what convolution is good at identifying so we'll create one a data set that's small enough that we can include it with cottonwood for testing but that's complicated enough that it'll show whether our algorithm is working as we hope we'll create a series of blips so in the data directory we'll create a module called data loader blips dot pi and we want this to be a block more specifically we want it to be two blocks we want to simulate having training data and having evaluation data so we'll create two blocks a training data block and an evaluation data block now for our purposes we don't actually care these will be exactly the same but this will set up a good pattern that we can use later when we actually do have data that's segmented into training and evaluation or training and tuning and evaluation so you can see here in our training data and our evaluation data classes these are both blocks and they have the minimum signature they each have a forward pass and a backward pass they also have the dunder str method that returns a string that describes them briefly and then they also have a dunder init method that initializes them this is all you need to create a block to create something that can be connected to other things i want to call out that both of the forward pass and the backward pass they accept an argument this is not because the data loader needs an argument but because the structure we'll expect to be able to pass an argument to forward and backward past functions of every block even if it's empty even if it's nonsense so we need to include an argument there to be able to accept that if it should be passed in our case we won't need it we won't use it here we rely on a get data sets function that returns two generators a training data generator and an evaluation data generator a generator is a python function that is special you can call next on it and it'll give you the next thing on the list that that generator has so you can think of a generator it's just like a tall stack a deck of cards next just deals off the next one off the top and so by having two generators that are get data sets function returns we can collect the first one and use it to initialize our training data block and we can peel off the second one and use it to initialize our evaluation data block and then on the forward pass we go to that generator and we pull off the first example each time so our next move is to actually write this get data sets function see what it does so here in get data sets we'll take and kick the can down the road a little bit we'll call a get blips function and these will be the actual data in our data set and we'll just pull those into something called examples this is a long list of possible data points in this case a one-dimensional signal plus a label we'll use this to create two generators a training set generator and an evaluation set generator in each of these we set up an infinite loop while true randomly choose some index from the length of this list of examples and then return the example that corresponds to that index so in each case we take our big bag of examples we randomly pull one out send a copy of it put it back in the bag and then do that over and over again the training set and the evaluation set are both pulling out of the same bag so we're not going to expect to see any difference there this is not what we're testing with this data set here we just want something that will put our convolutional block through its paces and then we take these two functions that we created within the function and return the functions themselves the training set and the valuation set and these then are what become the engines in our training data and evaluation data blocks that we just looked at now get blips this is where we generate our actual fake data so the way we do that is we seed our random number generator so that we'll get due to random results but the same ones every time we run it then we initialize an empty list of blips we specify that we want our signal to be 21 elements long but the blip that occurs will just be seven elements long so our entire signal will be zero except for this little island of seven elements that will be non-zero and we'll generate a hundred different ones of these for each flavor of blip now we defined our four different flavors they'll each be named after a capital letter m v n and h and these are very approximately named by the shape that they take if you plot them out on a line so if you look they're each seven numbers long if you look at the m for instance it jumps high with the first element one and then descends lower lower down to 0.1 and then back up higher 0.4.7 back up to 1 and then it'll drop down to 0 again because all the rest of the values are 0. so it kind of looks like the capital letter m sitting on a number line v starts the numbers before and after are zero it descends minus point one minus point four all the way down to minus one and then back up gradually on a ramp back up to zero so it kind of looks like a v or a notch or a divot in the number line the n starts at zero and then drops to minus point seven jumps to point seven slowly descends down to minus 0.7 jumps back up to 0.7 and then it'll settle back to zero and then the h doesn't really look like an h at all it has a peak up to one back down to zero and then at the other end another peak down to minus one and then back to zero so two isolated peaks in different directions these are our four different flavors of blip there's seven elements long and when we generate an example of a blip we'll start with a full example full of zeros so 21 zeros in a row we'll randomly choose a location in the middle and set those seven elements to be this particular flavor of blip and then we return that we make sure to modify it so that it's actually a two-dimensional array so it's uh in the column direction all in one row this is the format that the convolutional neural network will expect to see it in remember channels are across rows and the signal is across columns so this is a single channel signal and then we set up for the number of examples of each flavor we iterate through and generate one of each an m a v an n and an h we generate a tuple so a paired signal with a blip and then the label so a just a string capital letter m v n and h so that we know both the data and the label that should go with it so each of these is an example and then this set of blips this list of blips is what gets returned and used to fuel the generators that then form the engines for our training data and evaluation data blocks this means that each time we call forward pass on training data or evaluation data what we get is a two-dimensional array one row by 21 columns with a blip somewhere in there of seven elements that are non-zero and it'll be one of four flavors and then it'll also come in a tuple with the label for what flavor that should be m v n or h so we're getting two elements a two item tuple each time we call forward pass there's a little bit of code here at the bottom this i found particularly useful when writing the data loader just to be able to test the results as we go and i left it here because it's a good example of a simple end-to-end test it doesn't absolutely guarantee that every tiny part works as intended but it does show broadly that you can run it you can look at the result the result looks reasonable if anything were badly broken it would fail to run or produce very wild output so this lets us verify that everything's working as it should be and now we have data a set of training and evaluation data blocks to pair with our convolutional neural network
Original Description
Get the full course experience at https://e2eml.school/321
This course starts out with all the fundamentals of convolutional neural networks in one dimension for maximum clarity. We will extend Cottonwood to handle convolutional architectures and apply it to classifying electrically-measured heartbeats as healthy or irregular.
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Brandon Rohrer · Brandon Rohrer · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Robot Learning with a Biologically-Inspired Brain (BECCA)
Brandon Rohrer
BECCA talk at AGI 2011
Brandon Rohrer
Robot Learning with a Biologically-Inspired Brain (BECCA), The Sequel
Brandon Rohrer
BECCA listens to The Hobbit
Brandon Rohrer
Learning the building blocks of speech: BECCA extracts a hierarchy of audio features
Brandon Rohrer
BECCA listens for sound effects in The Hobbit
Brandon Rohrer
BECCA finds movie trailers while watching the Big Bang Theory
Brandon Rohrer
Listening for unexpected sounds: BECCA detects anomalies in audio data
Brandon Rohrer
Learning the building blocks of vision: BECCA extracts a spatio-temporal hierarchy of features
Brandon Rohrer
Watching for the unexpected: BECCA detects anomalies in video data
Brandon Rohrer
BECCA finds a stationary target
Brandon Rohrer
BECCA finds a stationary target at 3X speed
Brandon Rohrer
BECCA watches the X-men and Bruce Lee
Brandon Rohrer
BECCA plays Quidditch
Brandon Rohrer
BECCA chases a ball
Brandon Rohrer
BECCA chases a ball, part 2
Brandon Rohrer
Becca chases a ball, part 3
Brandon Rohrer
BECCA creates features from MNIST
Brandon Rohrer
How reinforcement learning works in Becca 7
Brandon Rohrer
Deep Learning Demystified
Brandon Rohrer
How Data Science Works
Brandon Rohrer
How Convolutional Neural Networks work
Brandon Rohrer
How Bayes Theorem works
Brandon Rohrer
How Deep Neural Networks Work
Brandon Rohrer
Recurrent Neural Networks (RNN) and Long Short-Term Memory (LSTM)
Brandon Rohrer
How Support Vector Machines work / How to open a black box
Brandon Rohrer
How autocorrelation works
Brandon Rohrer
Getting closer to human intelligence through robotics
Brandon Rohrer
A minimalist's guide to slicing and indexing pandas DataFrames
Brandon Rohrer
How decision trees work
Brandon Rohrer
Data scientist archetypes
Brandon Rohrer
How to use python's datetime package
Brandon Rohrer
How optimization for machine learning works, part 1
Brandon Rohrer
How optimization for machine learning works, part 2
Brandon Rohrer
How optimization for machine learning works, part 3
Brandon Rohrer
How optimization for machine learning works, part 4
Brandon Rohrer
How convolutional neural networks work, in depth
Brandon Rohrer
How to pick a machine learning model 4: Splitting the data
Brandon Rohrer
How to pick a machine learning model 3: Choosing a loss function
Brandon Rohrer
How to pick a machine learning model 2: Separating signal from noise
Brandon Rohrer
How to pick a machine learning model 1: Choosing between models
Brandon Rohrer
How to pick a machine learning model 5: Navigating assumptions
Brandon Rohrer
What do neural networks learn?
Brandon Rohrer
Interview with iRobot's Director of Data Science Angela Bassa
Brandon Rohrer
How Backpropagation Works
Brandon Rohrer
Evolutionary Powell's method: A discrete optimizer for hyperparameter optimization
Brandon Rohrer
1D convolution for neural networks, part 1: Sliding dot product
Brandon Rohrer
1D convolution for neural networks, part 2: Convolution copies the kernel
Brandon Rohrer
1D convolution for neural networks, part 3: Sliding dot product equations longhand
Brandon Rohrer
1D convolution for neural networks, part 4: Convolution equation
Brandon Rohrer
1D convolution for neural networks, part 5: Backpropagation
Brandon Rohrer
1D convolution for neural networks, part 6: Input gradient
Brandon Rohrer
1D convolution for neural networks, part 7: Weight gradient
Brandon Rohrer
1D convolution for neural networks, part 8: Padding
Brandon Rohrer
1D convolution for neural networks, part 9: Stride
Brandon Rohrer
The Four Grand Challenges of Robots in the Home
Brandon Rohrer
How Convolution Works
Brandon Rohrer
The Softmax neural network layer
Brandon Rohrer
Batch normalization
Brandon Rohrer
Getting ready to learn Python, Mac edition #1: Files and directories
Brandon Rohrer
More on: Supervised Learning
View skill →Related Reads
📰
📰
📰
📰
Help Choosing Neural Network Architecture for Matrix Classification
Reddit r/deeplearning
How to Choose the Best Deep Learning Model for Medical Imaging
Medium · Deep Learning
Another Way to Read Neural Geometry
Medium · Data Science
Another Way to Read Neural Geometry
Medium · Deep Learning
🎓
Tutor Explanation
DeepCamp AI