def init_hidden(self, bsz, requires_grad=True):
weight = next(self.parameters())
if self.rnn_type == ‘LSTM’:
return (weight.new_zeros((self.nlayers, bsz, self.nhid), requires_grad=requires_grad),
weight.new_zeros((self.nlayers, bsz, self.nhid), requires_grad=requires_grad))
else:
return weight.new_zeros((self.nlayers, bsz, self.nhid), requires_grad=requires_grad)