torch部分用法(一)

从官方用例中学到的函数用法

    • torch.manual_seed(int)
    • torch.Tensor.item()
    • torch.nn.Embedding(num_embedding, embedding_dim)

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的内容当做索引,从权重矩阵里选出对应的行,如图:
torch部分用法(一)_第1张图片
其中,requires_grad: 用于说明当前量是否需要在计算中保留对应的梯度信息

你可能感兴趣的:(torch学习,python,算法,深度学习)