graykode / graykode/nlp-tutorial

3-3-bilstm-torch comment error

未关闭
#47 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Jupyter Notebook
星标
14.9k
派生
3.9k
PR 合并指标
30 天内没有已合并 PR

描述

class BiLSTM(nn.Module):
def __init__(self):
super(BiLSTM, self).__init__()

self.lstm = nn.LSTM(input_size=n_class, hidden_size=n_hidden, bidirectional=True)
self.W = nn.Parameter(torch.randn([n_hidden * 2, n_class]).type(dtype))
self.b = nn.Parameter(torch.randn([n_class]).type(dtype))

def forward(self, X):
input = X.transpose(0, 1) # input : [n_step, batch_size, n_class]

hidden_state = Variable(torch.zeros(1*2, len(X), n_hidden)) # [num_layers(=1) * num_directions(=1), batch_size, n_hidden]
cell_state = Variable(torch.zeros(1*2, len(X), n_hidden)) # [num_layers(=1) * num_directions(=1), batch_size, n_hidden]

outputs, (_, _) = self.lstm(input, (hidden_state, cell_state))
**outputs = outputs[-1] # [batch_size, n_hidden]**
model = torch.mm(outputs, self.W) + self.b # model : [batch_size, n_class]
return model

error: "outputs = outputs[-1] # [batch_size, n_hidden]"
the shape should be [batch_size,2*n_hidden]

贡献指南

打开贡献指南

调研方向

从 3-3-bilstm-torch 示例中的 BiLSTM.forward 开始,重现报告的形状错误。跟踪 self.lstm 返回的维度,并验证最终输出的形状是否与双向模型及后续矩阵乘法匹配。

由索引模型根据 Issue 内容生成。

评估

技术栈
python, pytorch
领域
machine-learning
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。