The initialize function can have any number of parameters. All objects assigned to self$ will be available for other methods that you implement. Tensors wrapped with nn_parameter() or nn_buffer() and submodules are automatically tracked when assigned to self$.
The initialize function is optional if the module you are defining doesn't have weights, submodules or buffers.
Forward
The forward method is called whenever an instance of nn_module is called. This is usually used to implement the computation that the module does with the weights ad submodules defined in the initialize function.
The forward function can use the self$training attribute to make different computations depending wether the model is training or not, for example if you were implementing the dropout module.
Cloning
To finalize the cloning of a module, you can define a private finalize_deep_clone() method. This method is called on the cloned object when deep-cloning a module, after all the modules, parameters and buffers were already cloned.