Is there a recommended way to apply the same linear transformation to each of the outputs of an nn.LSTM layer? Suppose I have a decoder language model, and want a hidden size of X but I have a vocab size of Y.
With e.g. Torch’s rnn library 45 I might do something like:
local dec = nn.Sequential()
dec:add(nn.LookupTable(opt.vocabSize, opt.hiddenSize))
dec:add(nn.Sequencer(nn.LSTM(opt.hiddenSize, opt.hiddenSize))
dec:add(nn.Sequencer(nn.Linear(opt.hiddenSize, opt.vocabSize)))
dec:add(nn.Sequencer(nn.LogSoftMax()))

Now doing the LSTM and the softmax is easy in PyTorch - but what is the best way to add in the nn.Linear, or even several layers, e.g. nn.Linear(F.relu(nn.Linear(x)))? Do I just loop over the outputs in forward, or is there a more elegant way?
class Net(nn.Module):
    def __init__(self, vocabSz, hiddenSz):
        super(Net, self).__init__()
        self.emb = nn.Embedding(vocabSz, hiddenSz)
        self.dec = nn.LSTM(hiddenSz, hiddenSz)
        self.lin = nn.Linear(hiddenSz, vocabSz)
    def forward(self, input, hidden):
        embeddings = self.emb(input)
        out, hidden = self.dec(embeddings, hidden)
        # do the linear here for each lstm output.. what's the best way?
        return F.softmax(out), hidden