Hello! I was reading the seq2seq tutorial, wondering how the following line of code works:
encoder_output, encoder_hidden = encoder(input_tensor[ei], encoder_hidden)
As I understand, encoder is a instance of class EncoderRNN, I thought the method here to call is forward in EncoderRNN, then why not call it as:
encoder_output, encoder_hidden = encoder.forward(input_tensor[ei], encoder_hidden)
encoder(...) are doing nearly the same thing.
You can check the doc where it is explained that:
Although the recipe for forward pass needs to be defined within this function, one should call the instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
This means that in practice you should use
encoder(...) because it will call
encoder.forward(...), but it will also do some other things (i.e. run registered hooks if any).
Thank you! And I found this solution to the similar question very helpful too.