Skip to content

fix: correct Bi-LSTM output shape comment (n_hidden*2 not n_hidden)#90

Open
Mukller wants to merge 1 commit into
graykode:masterfrom
Mukller:fix/bilstm-attention-output-shape-comment
Open

fix: correct Bi-LSTM output shape comment (n_hidden*2 not n_hidden)#90
Mukller wants to merge 1 commit into
graykode:masterfrom
Mukller:fix/bilstm-attention-output-shape-comment

Conversation

@Mukller

@Mukller Mukller commented Jul 9, 2026

Copy link
Copy Markdown

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, not n_hidden.

Before (wrong comment):

output = output.permute(1, 0, 2) # output : [batch_size, len_seq, n_hidden]

After (correct comment):

output = output.permute(1, 0, 2) # output : [batch_size, len_seq, n_hidden * num_directions(=2)]

This matches the existing comments on surrounding lines (e.g., attention_net's
docstring already correctly states n_hidden * num_directions(=2)).

Closes #84

@Mukller Mukller left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The comment in the Bi-LSTM (Attention) model has an issue.

1 participant