-
y_preds = model_0(X_test) I can't understand why/how does this work; I must have a gap in my understanding of classes. If forward() is a method defined under the class, and model_0 is just an instance of that class, why is this not y_preds = model_0.forward(X_test). How does simply listing the input tensor cause forward() to act on it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes you're right it is a little confusing. However, behind the scenes every subclass of In regular Python classes this kind of functionality might go behind a However, for some reason the PyTorch developers chose to override this functionality with |
Beta Was this translation helpful? Give feedback.
Yes you're right it is a little confusing.
However, behind the scenes every subclass of
torch.nn.Module
callsforward()
by default when it's called.In regular Python classes this kind of functionality might go behind a
__call__()
method, see more here: https://stackoverflow.com/questions/9663562/what-is-the-difference-between-init-and-callHowever, for some reason the PyTorch developers chose to override this functionality with
forward()
, see more here: https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.forward