Still not clear for me…And still an error using expand insted of expand_as which is from gather.
Are there any way to implement Embedding? I would like to use nn.Embedding layer.
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-187-593f47b27cfe> in <module>()
     15 # align w with indices and pick values from w
     16 # and squeeze the fake dimention used for aligment:
---> 17 x_emb = w.expand(30,4,3,7,5).gather(0,idx).squeeze() # (4,3,7,5)
     18 print('x_embd', x_emb.size())

RuntimeError: Expected tensor [1 x 4 x 1 x 7 x 5], src [30 x 4 x 3 x 7 x 5] and index [1 x 4 x 1 x 7 x 5] to have the same size in dimension 0 at /pytorch/torch/lib/TH/generic/THTensorMath.c:445