Model
Explore how to build a simple linear regression model in PyTorch by defining model classes with parameters and a forward method. Understand the importance of using model instances for predictions and the role of model.train() for training mode.
Introduction to models
In PyTorch, a model is represented by a regular Python class that inherits from the Module class.
IMPORTANT: Are you comfortable with object-oriented programming (OOP) concepts like classes, constructors, methods, instances, and attributes?
If you are unsure about any of these terms, we strongly recommend that you first brush up your skills in OOP before proceeding.
Having a good understanding of OOP is key to benefit the most from PyTorch’s capabilities.
So, assuming you are already comfortable with OOP, let us dive into developing a model in PyTorch.
The most fundamental methods a model class needs to implement are:
__init__(self): It defines the parts that make up the model; in our case, two parameters ofbandw.
...
You are not limited to defining parameters though. Models can contain other models as their attributes as well, so you can easily nest them. We will ...