Found it out by myself:
y = self.hidden2label(torch.cat((lstm_out[-1, :, :self.hidden_dim], lstm_out[0, :, self.hidden_dim:]), 1))
By replacing the secondlast line with that, I get the last hidden state from the forward output and the last (“first” position in the input) hidden state from the backward output and concatenate them. So yeah, works pretty well, thanks to that:

  
      
      Towards Data Science – 13 Nov 17
  
  
    

Understanding Bidirectional RNN in PyTorch – Towards Data Science 97

Quick Recap

  Reading time: 3 min read