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

Method __init__

word_language_model/model.py:110–120  ·  view source on GitHub ↗
(self, ntoken, ninp, nhead, nhid, nlayers, dropout=0.5)

Source from the content-addressed store, hash-verified

108 """Container module with an encoder, a recurrent or transformer module, and a decoder."""
109
110 def __init__(self, ntoken, ninp, nhead, nhid, nlayers, dropout=0.5):
111 super(TransformerModel, self).__init__(d_model=ninp, nhead=nhead, dim_feedforward=nhid, num_encoder_layers=nlayers)
112 self.model_type = 'Transformer'
113 self.src_mask = None
114 self.pos_encoder = PositionalEncoding(ninp, dropout)
115
116 self.input_emb = nn.Embedding(ntoken, ninp)
117 self.ninp = ninp
118 self.decoder = nn.Linear(ninp, ntoken)
119
120 self.init_weights()
121
122 def _generate_square_subsequent_mask(self, sz):
123 return torch.log(torch.tril(torch.ones(sz,sz)))

Callers

nothing calls this directly

Calls 3

init_weightsMethod · 0.95
PositionalEncodingClass · 0.70
__init__Method · 0.45

Tested by

no test coverage detected