MCPcopy Create free account
hub / github.com/pytorch/examples / Encoder

Class Encoder

legacy/snli/model.py:19–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17
18
19class Encoder(nn.Module):
20
21 def __init__(self, config):
22 super(Encoder, self).__init__()
23 self.config = config
24 input_size = config.d_proj if config.projection else config.d_embed
25 dropout = 0 if config.n_layers == 1 else config.dp_ratio
26 self.rnn = nn.LSTM(input_size=input_size, hidden_size=config.d_hidden,
27 num_layers=config.n_layers, dropout=dropout,
28 bidirectional=config.birnn)
29
30 def forward(self, inputs):
31 batch_size = inputs.size()[1]
32 state_shape = self.config.n_cells, batch_size, self.config.d_hidden
33 h0 = c0 = inputs.new_zeros(state_shape)
34 outputs, (ht, ct) = self.rnn(inputs, (h0, c0))
35 return ht[-1] if not self.config.birnn else ht[-2:].transpose(0, 1).contiguous().view(batch_size, -1)
36
37
38class SNLIClassifier(nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected