This is the problem:
out
has shape of (seq_len, batch, num_directions * hidden_size)
. You cannot simply reshape it like you do. It completely messes up you tensor.
By the way, this is a problem as well:
x.view(x.size(0), self.sequence_length, self.input_size)
See this post.