import torch
import torch.nn as nn
encoder = nn.Embedding(5, 5)
print(encoder.weight)
a=encoder(torch.tensor([[1,2]]))
print(a)
output:
Parameter containing:
tensor([[-1.3872, -0.0177, -0.4067, 0.6568, 1.7172],
[ 1.5127, 0.3096, -0.8209, 1.0901, 0.0220],
[ 0.1434, -0.0864, 0.0817, 0.1294, -0.3425],
[ 0.3291, -0.0037, -0.1281, -0.1561, 0.6285],
[ 0.0725, -2.3662, -1.5152, 0.0952, 0.9467]], requires_grad=True)
tensor([[[ 1.5127, 0.3096, -0.8209, 1.0901, 0.0220],
[ 0.1434, -0.0864, 0.0817, 0.1294, -0.3425]]],
grad_fn=)