https://zhuanlan.zhihu.com/p/361431647
https://zhuanlan.zhihu.com/p/345450458
import torch
from torch import nn
embedding = nn.Embedding(5, 4) # 假定字典中只有5个词,词向量维度为4
word = [[1, 2, 3],
[2, 3, 4]] # 每个数字代表一个词,例如 {'!':0,'how':1, 'are':2, 'you':3, 'ok':4}
#而且这些数字的范围只能在0~4之间,因为上面定义了只有5个词
embed = embedding(torch.LongTensor(word))
print(embed)
print(embed.size())
# coding:utf8
import torch as t
from torch import nn
if __name__ == '__main__':
embedding = nn.Embedding(10, 2) # 10个词,每个词用2维词向量表示
input = t.arange(0, 6).view(3, 2).long() # 3个句子,每句子有2个词
input = t.autograd.Variable(input)
output = embedding(input)
print(output.size())
print(embedding.weight.size())



