Functions

Get to know how function attributes can be created and look at the final version of your StepByStep class.

We'll cover the following

Creating function attributes

For convenience, sometimes it is useful to create attributes that are functions, which will be called somewhere else inside the class. In our case, we can create both train_step and val_step by using the higher-order functions we defined in the chapter, Rethinking the Training Loop (helper functions #1 and #3, respectively). Both of them take a model, a loss function, and an optimizer as arguments, and all of those are already known attributes of our StepByStep class at construction time.

The code below will be the final updated version of our constructor method:

Get hands-on with 1400+ tech skills courses.