Thank you @alexis-jacq But your code got an error. And I updated my post using for.
TypeError: expand_as() takes 2 positional arguments but 6 were given

And I am not sure about torch.rand(30,4,1,1,1). 4 means embedding size? And what are last three 1?