MCPcopy Create free account
hub / github.com/pytorch/tutorials / forward

Method forward

beginner_source/chatbot_tutorial.py:767–780  ·  view source on GitHub ↗
(self, hidden, encoder_outputs)

Source from the content-addressed store, hash-verified

765 return torch.sum(self.v * energy, dim=2)
766
767 def forward(self, hidden, encoder_outputs):
768 # Calculate the attention weights (energies) based on the given method
769 if self.method == 'general':
770 attn_energies = self.general_score(hidden, encoder_outputs)
771 elif self.method == 'concat':
772 attn_energies = self.concat_score(hidden, encoder_outputs)
773 elif self.method == 'dot':
774 attn_energies = self.dot_score(hidden, encoder_outputs)
775
776 # Transpose max_length and batch_size dimensions
777 attn_energies = attn_energies.t()
778
779 # Return the softmax normalized probability scores (with added dimension)
780 return F.softmax(attn_energies, dim=1).unsqueeze(1)
781
782
783######################################################################

Callers

nothing calls this directly

Calls 3

general_scoreMethod · 0.95
concat_scoreMethod · 0.95
dot_scoreMethod · 0.95

Tested by

no test coverage detected