What does next(self.parameters()).data mean?
<SCODE>def init_weights(self, bsz):
    """Initialize weight parameters for the encoder."""
    weight = next(self.parameters()).data
    num_directions = 2 if self.bidirectional else 1
    if self.rnn_type == 'LSTM':
        return (Variable(weight.new(self.n_layers * num_directions, bsz, self.hidden_size).zero_()),
                Variable(weight.new(self.n_layers * num_directions, bsz, self.hidden_size).zero_()))
    else:
        return Variable(weight.new(self.n_layers * num_directions, bsz, self.hidden_size).zero_())
<ECODE> I have two question.
wasiahmad
Response777
<SCODE>class Model(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc = nn.Linear(10,1)
        
model = Model()
weight = next(model.parameters()).data

print(weight)
# Output :  tensor([[ 0.0398,  0.0729, -0.2676,  0.2354, -0.0853,  0.1141,  0.0297,  0.0257, \ 
         -0.1303,  0.2208]])

print(type(weight), weight.device, weight.dtype, weight.requires_grad)
# Output : (torch.Tensor, device(type='cpu'), torch.float32, False)

var = weight.new(4,5)

print(type(var), var.device, var.dtype,  var.requires_grad)
# Output : (torch.Tensor, device(type='cpu'), torch.float32, False)

<ECODE>
manal_elaidouni