LongTensor gives me scientific notation and seems to influence embedding

Hi all,
I’ve been using LongTensor for my batches. and I transformed my list into Longtensor directly which gives me

Variable containing:
1.4000e+01 1.4000e+01 1.5300e+02 … 6.1000e+01 6.8000e+01 1.0700e+02
3.0160e+03 5.5880e+03 1.7000e+01 … 6.0000e+00 2.7514e+04 1.5000e+01
4.8000e+01 1.7000e+01 3.0000e+00 … 6.9000e+01 9.5000e+01 1.0000e+00
… ⋱ …
0.0000e+00 0.0000e+00 0.0000e+00 … 4.0980e+03 0.0000e+00 1.0830e+03
0.0000e+00 0.0000e+00 0.0000e+00 … 1.6600e+03 0.0000e+00 0.0000e+00
0.0000e+00 0.0000e+00 0.0000e+00 … 0.0000e+00 0.0000e+00 0.0000e+00
[torch.LongTensor of size 17x64]

I only have three batches that has scientific notation while others that processed in a same way remain normal(in the way I want):
Variable containing:
662 231 47893 … 231 1465 61
1 5766 17 … 8 2 742
17 54 106 … 102 15417 25
… ⋱ …
585 30 18 … 0 0 0
301 3 225 … 0 0 0
557 1755 28629 … 0 0 0
[torch.LongTensor of size 17x64]

And it seems that the first notation influence my embedding process, which throws me error as:
RuntimeError Traceback (most recent call last)
in ()
8 embed = nn.Embedding(len(s_index2word), 128)
9 print(input_var)
—> 10 embedded = embed(input_var)

/home/wenyanli/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
222 for hook in self._forward_pre_hooks.values():
223 hook(self, input)
–> 224 result = self.forward(*input, **kwargs)
225 for hook in self._forward_hooks.values():
226 hook_result = hook(self, input, result)

/home/wenyanli/anaconda3/lib/python3.6/site-packages/torch/nn/modules/sparse.py in forward(self, input)
92 input, self.weight,
93 padding_idx, self.max_norm, self.norm_type,
—> 94 self.scale_grad_by_freq, self.sparse
95 )
96

/home/wenyanli/anaconda3/lib/python3.6/site-packages/torch/nn/_functions/thnn/sparse.py in forward(cls, ctx, indices, weight, padding_idx, max_norm, norm_type, scale_grad_by_freq, sparse)
51 output = torch.index_select(weight, 0, indices)
52 else:
—> 53 output = torch.index_select(weight, 0, indices.view(-1))
54 output = output.view(indices.size(0), indices.size(1), weight.size(1))
55

RuntimeError: index out of range at /opt/conda/conda-bld/pytorch_1503965122592/work/torch/lib/TH/generic/THTensorMath.c:277

I’ve tried for several hours and still can’t fix this. Please help. Thx!

1 Like

I have the same problem! Do you find the way to convert LongTensor with scientific number to int?

Hi, that’s a long time agon. but I actually later figure out that my problem was my dictionary doesn’t match with my data(I have a wrong vocabulary size). Try check that. After I changed that, I don’t have that issue anymore.

Hi, I actually later figure out that my problem was my dictionary doesn’t
match with my data(I have a wrong vocabulary size). Try check that. After I
changed that, I don’t have that issue anymore.

Thanks a lot. I guess I have the same problem of indexing. The scientific notation for LongTensor in the error message is misleading. I thought the tensor was accidentally cast to FloatTensor, but it was actually still LongTensor just in scientific notation.

Glad it’s helpful. Yes it was kinda confusing and I didnt realize they are
still long tensors until I print them all out.