从官方用例中学到的函数用法
torch.manual_seed(int)
设置随机数种子,每次参数初始化结果都一样
torch.Tensor.item()
tensor只有一个元素才能调用item方法
torch.nn.Embedding(num_embedding, embedding_dim)
官方解释:
A simple lookup table that stores embeddings of a fixed dictionary and size.
This module is often used to store word embeddings and retrieve them using indices.
The input to the module is a list of indices, and the output is the corresponding word embeddings.
实际上: 调用后产生了size为(num_embedding, embedding_dim)的权重矩阵,把被作用的Tensor的内容当做索引,从权重矩阵里选出对应的行,如图:
其中,requires_grad: 用于说明当前量是否需要在计算中保留对应的梯度信息