Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Conversation

mingruimingrui
Copy link

This is a pull request to address the issue of tensors being incorrectly combined in combine_bidir.
This issue was raised in #138.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Apr 5, 2020
@OneDirection9
Copy link

Try to explain the bug more here,

It's used to concatenate the forward and backward hidden tensors from a bidirectional LSTM.

def combine_bidir(outs):
return torch.cat([
torch.cat([outs[2 * i], outs[2 * i + 1]], dim=0).view(1, bsz, self.output_units)
for i in range(self.num_layers)
], dim=0)
Here outs is a tensor of the shape [num_dir * num_layers, bsz, hidden_size].
The goal is to combine the tensor to the form [num_layers, bsz, num_dir * hidden_size].

denote the output of torch.cat([outs[2 * i], outs[2 * i + 1]], dim=0) as A and A has shape of 2 * batch_size, hidden_size

denote the output of res.view(1, bsz, self.output_units) as B and B[i] is equivalent to torch.cat([A[i], A[i + 1]]), (i in range [0, batch_size)). where A[i] and A[i + 1] are different entities from the same batch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants