So far, we have built a neural network by defining a class where we define the layers and how the layers are connected with each other. In this section, we will learn about a simplified way of defining the neural network architecture using the Sequential class. We will perform the same steps as we have done in the previous sections, except that the class that was used to define the neural network architecture manually will be substituted with a Sequential class for creating a neural network architecture.
Let's code up the network for the same toy data that we have worked on in this chapter:
The following code is available as Sequential_method_to_build_a_neural_network.ipynb in the Chapter02 folder of this book's GitHub repository - https://tinyurl.com/mcvp-packt
- Define the toy dataset:
x = [[1,2],[3,4],[5,6],[7,8]]
y = [[3],[7],[11],[15]]
- Import the relevant packages and define the device we will work on:
import torch...