What does the following code is doing?

The following code is from the SNLI example in Pytorch.

def forward(self, inputs):
batch_size = inputs.size()[1]
state_shape = self.config.n_cells, batch_size, self.config.d_hidden
h0 = c0 = Variable(inputs.data.new(*state_shape).zero_())
outputs, (ht, ct) = self.rnn(inputs, (h0, c0))

In the above code, why h0 and c0 is created through inputs.data.new()? What inputs.data.new() actually means? Can anyone explain this piece of code? I am not understanding why we can create the h0 and c0 variable of desired shape in a normal way?

input.data.new create a tensor whose type is same as input.data, and also you can create a variable in a normal way such as Variable(torch.zeros(*state_shape)), but in order to keep the tensor type consistent with inputs, you need to cast to the type of inputs. with type_as or type manually

ok, so only type information of the inputs is used to create the Variable, nothing else? like the inputs.data itself?

I think only the type information of inputs.data not the type of Variable inputs