How to use Learner with my custom model and pass multiple args into it's "forward" method?

When using a custom model as such:

model = BasicSeq2SeqRnn(src_vocab_sz, src_emb_dim, trg_vocab_sz, trg_em_dim, n_hidden=nh, n_layers=nl)
learn = RNNLearner(data, model)

… is there a way to pass other arguments into the model's forward() method?

For example, here I’m building a Seq2Seq model and I’d like to pass in the target sequence as well so I can use teacher forcing. How would I do that?

You need your model to accept those and your dataset to sent them. Pytorch dataloader will do the rest for you.


Yah, you’re right … thanks!

I ultimately decided to simply follow the strategy presented here for teacher forcing. It just seemed a bit more straight-forward for my purposes than writing a bunch of custom DataBlock API code to achieve the same results.

Here’s my initial take on using the API to build seq2seq friendly datasets/dataloaders. If you have any suggestions on how it may be improved and/or how it could (should) be modified to include the ‘targets’ to support teacher forcing, I’m all ears.