Search⌘ K
AI Features

Model Types

Explore PyTorch model types by learning how to use nested models and sequential models in the context of a simple linear regression problem. Understand how parameters like weights and biases are managed within custom and built-in models, and how using Sequential simplifies model construction.

We'll cover the following...

Nested models

In our model, we manually created two parameters to perform a linear regression. Instead of defining individual parameters, what if we use PyTorch’s Linear model?

We are implementing a single feature linear regression, one input, and one output, so the corresponding linear model would look like this:

Python 3.5
import torch.nn as nn
linear = nn.Linear(1, 1)
print(linear)

Do we still have our b and w parameters? Sure we do!

Python 3.5
import torch.nn as nn
linear = nn.Linear(1, 1)
print(linear.state_dict())

So, our former parameter b is the bias, and our former parameter w is the weight. Your values will be different since random seed has not been set up for this example. ...