Going to this article (http://pytorch.org/tutorials/beginner/former_torchies/nn_tutorial.html) it looks like implementing a recurrence over a layer is just repeating the layer in the forward function while defining the network.
My question is:
Can I implement a Simple RNN this way? I couldn’t find any resources over this on the internet. For example, if I want to try a variant of LSTM or GRU could I define a class that has the new cell’s implementation and then just repeat it over time steps (i.e. sequence values in text).
Can I define recurrence over an arbitrary layer. Say, I want recurrence over a Linear layer. Could I just take the layer and implement recurrence over it by just looping through the layer outputs and applying the same layer again?
Thanks for the awesome library!
gr8, thanks! any links or implementations implementing RNNs this way or having recurrence over an arbitrary layer?
Perhaps the example here http://pytorch.org/docs/master/nn.html?highlight=cell#torch.nn.RNNCell ?
You can also write a custom Module that wraps the for loop in
forward as well.
thanks! but i don’t get how 1 or 2 are implemented there…the link is about different rnn cells.
Custom module to wrap the for loops in forward… i will try
I meant the examples in the doc for using RNNCells. They are essentially repeatedly applying a same module.
I assume that using a for loop would really slow things down. Is there any wrapper that would do something similar?
I don’t think there is another way to achieve the same.
You have to execute this sequentially since each iteration requires the result of the previous one.
The overhead of the loop should be neglectible, since GPUs work asynchronous and the loop only puts the kernel calls in a queue.