(self, hidden, encoder_hiddens)
| 122 | return output, hidden, attn_weights |
| 123 | |
| 124 | def get_att_weight(self, hidden, encoder_hiddens): |
| 125 | seq_len = len(encoder_hiddens) |
| 126 | |
| 127 | # Create variable to store attention energies |
| 128 | attn_scores = cuda_variable(torch.zeros(seq_len)) # B x 1 x S |
| 129 | |
| 130 | # Calculate energies for each encoder hidden |
| 131 | for i in range(seq_len): |
| 132 | attn_scores[i] = self.get_att_score(hidden, encoder_hiddens[i]) |
| 133 | |
| 134 | # Normalize scores to weights in range 0 to 1, |
| 135 | # resize to 1 x 1 x seq_len |
| 136 | # print("att_scores", attn_scores.size()) |
| 137 | return F.softmax(attn_scores).view(1, 1, -1) |
| 138 | |
| 139 | # score = h^T W h^e = h dot (W h^e) |
| 140 | # TODO: We need to implement different score models |
no test coverage detected