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

Method __init__

beginner_source/chatbot_tutorial.py:744–754  ·  view source on GitHub ↗
(self, method, hidden_size)

Source from the content-addressed store, hash-verified

742# Luong attention layer
743class Attn(nn.Module):
744 def __init__(self, method, hidden_size):
745 super(Attn, self).__init__()
746 self.method = method
747 if self.method not in ['dot', 'general', 'concat']:
748 raise ValueError(self.method, "is not an appropriate attention method.")
749 self.hidden_size = hidden_size
750 if self.method == 'general':
751 self.attn = nn.Linear(self.hidden_size, hidden_size)
752 elif self.method == 'concat':
753 self.attn = nn.Linear(self.hidden_size * 2, hidden_size)
754 self.v = nn.Parameter(torch.FloatTensor(hidden_size))
755
756 def dot_score(self, hidden, encoder_output):
757 return torch.sum(hidden * encoder_output, dim=2)

Callers

nothing calls this directly

Calls 1

__init__Method · 0.45

Tested by

no test coverage detected