graykode / graykode/nlp-tutorial

3-3-bilstm-torch comment error

オープン
#47 コメント 1 件 リアクション 0 件 担当者 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]

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。