fix: correct Bi-LSTM output shape comment (n_hidden*2 not n_hidden)#90
Open
Mukller wants to merge 1 commit into
Open
fix: correct Bi-LSTM output shape comment (n_hidden*2 not n_hidden)#90Mukller wants to merge 1 commit into
Mukller wants to merge 1 commit into
Conversation
Mukller
commented
Jul 10, 2026
Mukller
left a comment
Author
There was a problem hiding this comment.
Code Review: fix Bi-LSTM output shape comment
Summary
Corrects a misleading inline comment in the Bi-LSTM attention model. The comment described the LSTM output tensor as [batch_size, len_seq, n_hidden], which is the shape for a unidirectional LSTM. For a bidirectional LSTM (num_directions=2), the last dimension is n_hidden * 2.
Issues Found
| # | File | Line | Issue | Severity |
|---|---|---|---|---|
| 1 | Bi-LSTM(Attention).py |
~37 | Comment says n_hidden but correct shape is n_hidden * num_directions(=2) |
🟡 Minor (comment only) |
What the Fix Does
# Before
output = output.permute(1, 0, 2) # output : [batch_size, len_seq, n_hidden]
# After
output = output.permute(1, 0, 2) # output : [batch_size, len_seq, n_hidden * num_directions(=2)]This is a documentation-only fix. Readers following the code to understand tensor shapes would otherwise be confused when passing the output to attention_net, which operates on the full n_hidden * 2 dimension.
What Looks Good
- Single-line, zero-risk change
- Accurate dimension annotation helps readers trace tensor shapes through the attention mechanism
Verdict
Approve. Clean documentation fix that prevents a common point of confusion in bidirectional RNN code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Incorrect output shape comment in Bi-LSTM(Attention)
The comment for the LSTM output after
permute(1, 0, 2)incorrectly states[batch_size, len_seq, n_hidden]when it should be[batch_size, len_seq, n_hidden * num_directions(=2)].A bidirectional LSTM concatenates forward and backward hidden states, so the
last dimension is
n_hidden * 2, notn_hidden.Before (wrong comment):
After (correct comment):
This matches the existing comments on surrounding lines (e.g.,
attention_net'sdocstring already correctly states
n_hidden * num_directions(=2)).Closes #84