How to declare a torch with unknown value in one dimension
I have a list of sentences and I am convert the list to a 3d tensor. The first dimension represents number of sentences, second dimension represents number of words and third dimension represents word embedding size. The problem is, number of words can vary in sentences. I tried to create a 3d tensor as follows. <SCODE>all_sentences1 = torch.FloatTensor(len(instances), None, args.emsize)
<ECODE> But this gives me the following error. <SCODE>TypeError: torch.FloatTensor constructor received an invalid combination of arguments - got (int, NoneType, int), but expected one of:
 * no arguments
 * (int ...)
      didn't match because some of the arguments have invalid types: (int, NoneType, int)
 * (torch.FloatTensor viewed_tensor)
 * (torch.Size size)
 * (torch.FloatStorage data)
 * (Sequence data)
<ECODE> How can I declare a 3d tensor?
wasiahmad
jekbradbury
Edit
wasiahmad
jekbradbury
You need to understand that PyTorch works differently than static graph frameworks. You can’t define “placeholders” with unspecified sizes, but you can pass in tensors of different sizes to your model without any modifications. Instead of reusing a single placeholder, you always have to operate on real data.
apaszke