RuntimeError: The expanded size of the tensor (1) must match the existing size (10) at non-singleton dimension 1. Target sizes: [1, 1]. Tensor sizes: [10]

I got a trouble with this…

p_h = F.sigmoid(
            F.linear(v.view(1, self.batch), 
                     self.W.view(1, self.batch).expand(1, self.batch), 
                     self.h_bias)
        )

help me plz

Could you post a runnable code snippet that reproduces this error? I can’t seem to reproduce this issue e.g.,

>>> import torch
>>> W = torch.randn(10)
>>> W.view(1, 10)
tensor([[ 0.0540,  0.6975,  0.9764, -2.3373,  1.4731, -0.4768,  0.8725,  1.1909,
         -0.3579, -1.1160]])
>>> W.view(1, 10).expand(1, 10)
tensor([[ 0.0540,  0.6975,  0.9764, -2.3373,  1.4731, -0.4768,  0.8725,  1.1909,
         -0.3579, -1.1160]])
1 Like

Hopefully I solved it myself. solutions was similar with your code.
My solutions is here.

I really thank you that u tried to help me.