FFNN with nn.Module

Hi Team,

In the attached screenshot, i want to know how fn(X_train) is calling forward() function, as this function is not getting called explicitly anywhere. Please let me know after init function, how it’s calling forward () function._

fn = FirstNetwork()

Hi @shweta_s,
It happens with the help of dunder method __call__. You can read more about it here: GFG| Call in Python.

In simple words, __call__ works as a functionality to directly call a class instance similar to how we do a function call.

__call__ is defined in Pytorch’s nn.Module , and it directs every call to forward directly .

Hope this helps, let me know about any clarifications.