gabrielloye / Attention_Seq2seq-Translation

34 stars 23 forks source link

bug in BahdanauDecoder #6

Closed moseshu closed 2 years ago

moseshu commented 2 years ago

`encoder = EncoderLSTM(input_size=1000, hidden_size=128, n_layers=2, drop_prob=0) input = torch.randint(0, 8, (3, 5)) #(batch, seq)=(3,5)

target = torch.randint(1, 20, (3, 9)) # (batch, seq)=(3,9) hidden = encoder.init_hidden(3)# hidden[0].shape = (n_layers, batch, dim) print(hidden[0].shape) encoder_output, hidden = encoder(input, hidden) print(output.shape)

attn = BahdanauDecoder(hidden_size=128, output_size=64) output, hidden, attn_weights = attn(target, hidden, encoder_output)`

the error happends in this line x = torch.tanh(self.fc_hidden(hidden[0])+self.fc_encoder(encoder_outputs)) RuntimeError: The size of tensor a (3) must match the size of tensor b (5) at non-singleton dimension 1

in class BahdanauDecoder, the hidden is a Tuple[Tensor,Tensor] type? I think hidden=(hn, cn), hn is the hidden state of last layer LSTM. it's shape is [batch, hidden_size]

moseshu commented 2 years ago

finished