MCPcopy
hub / github.com/hunkim/PyTorchZeroToAll / get_att_weight

Method get_att_weight

seq2seq_models.py:124–137  ·  view source on GitHub ↗
(self, hidden, encoder_hiddens)

Source from the content-addressed store, hash-verified

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

Callers 1

forwardMethod · 0.95

Calls 2

get_att_scoreMethod · 0.95
cuda_variableFunction · 0.85

Tested by

no test coverage detected