-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
If I understand the logic correctly then in Luong Decoders forward function:
def forward(self, inputs, hidden, encoder_outputs):
#Embed input words
embedded = self.embedding(inputs).view(1,1,-1)
embedded = self.dropout(embedded)
#Passing previous output word (embedded) and hidden state into LSTM cell
lstm_out, hidden = self.lstm(embedded, hidden)
#Calculating Alignment Scores - see Attention class for the forward pass function
alignment_scores = self.attention(lstm_out,encoder_outputs)
#Softmaxing alignment scores to obtain Attention weights
attn_weights = F.softmax(alignment_scores.view(1,-1), dim=1)
#Multiplying Attention weights with encoder outputs to get context vector
context_vector = torch.bmm(attn_weights.unsqueeze(0),encoder_outputs)
#Concatenating output from LSTM with context vector
output = torch.cat((lstm_out, context_vector),-1)
#Pass concatenated vector through Linear layer acting as a Classifier
output = F.log_softmax(self.classifier(output[0]), dim=1)
return output, hidden, attn_weights
alignment_scores = self.attention(lstm_out,encoder_outputs)
Shouldn't we pass hidden instead of lstm_output to self.attention ?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels