I might be missing something but I’m confused about the init_hidden method here,

  
      github.com
  
  
    pytorch/examples/blob/master/word_language_model/model.py#L52 50

    self.decoder.bias.data.fill_(0)
    self.decoder.weight.data.uniform_(-initrange, initrange)


def forward(self, input, hidden):
    emb = self.drop(self.encoder(input))
    output, hidden = self.rnn(emb, hidden)
    output = self.drop(output)
    decoded = self.decoder(output.view(output.size(0)*output.size(1), output.size(2)))
    return decoded.view(output.size(0), output.size(1), decoded.size(1)), hidden


def init_hidden(self, bsz):
    weight = next(self.parameters()).data
    if self.rnn_type == 'LSTM':
        return (Variable(weight.new(self.nlayers, bsz, self.nhid).zero_()),
                Variable(weight.new(self.nlayers, bsz, self.nhid).zero_()))
    else:
        return Variable(weight.new(self.nlayers, bsz, self.nhid).zero_())



  
  
    
    
  
  


In the first line it seems to be grabbing the first item produced by the generator self.parameters() and returning a Variable filled with zeros based on the data shape.  My question is, how do we know what set of parameters will be returned by the line,
weight = next(self.parameters()).data
some testing on my local machine shows that when I instanciate a model and call next(model.parameters()) I get the embedding layer data (i.e. a Tensor of shape (num_tokens, embedding_size)).  I don’t understand what the line,
Variable(weight.new(self.nlayers, bsz, self.nhid).zero_())
has to do with the embedding layer?  Are we just trying to get data that is the same type as weight?