Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix combine_bidir function #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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 join this conversation on GitHub. Already have an account? Sign in to comment
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