Using Sequential module to build a neural network
In my previous post(follow link), I have talked about building your neural network using nn module offered by PyTorch.
In this article, I am going to show you how you can make the same neural network by using the Sequential module in PyTorch. But before that,
what is the Sequential module?
The nn.Sequential is a module that contains other modules and applies them in sequence to produce its output. Each Linear Module computes output from the input using a linear function and holds internal Tensors for its weight and bias. (reference: link)
Okay so now, let’s get started:
Step 1: Prepare data (the goal here is to train the model to subtract)
Step 2: We need Dataset and DataLoader for batch processing of our data
You can use iter and next to view the items in the dataloader like this:
Step 3: build the neural network
Step 4: Train the model
Step 5: Plot the losses with the epoch counts
Step 6: Model on the unknown data
Step 7: Print the model summary
Okay, that was easy! :)
Leave a comment with any suggestions. Thank you for taking your time to read this article.
*****************************The End***************************