1.word Embedding的概念理解
首先,我们先理解一下什么是Embedding。Word Embedding翻译过来的意思就是词嵌入,通俗来讲就是将文字转换为一串数字。因为数字是计算机更容易识别的一种表达形式。我们词嵌入的过程,就相当于是我们在给计算机制造出一本字典的过程。计算机可以通过这个字典来间接地识别文字。词嵌入向量的意思也可以理解成:词在神经网络中的向量表示。
2.Pytorch中的Embedding
官方文档的定义:
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.
一个简单的存储固定大小的词典的嵌入向量的查找表,意思就是说,给一个编号,嵌入层就能返回这个编号对应的嵌入向量,嵌入向量反映了各个编号代表的符号之间的语义关系。该模块通常用于存储单词嵌入并使用索引检索它们。
模块的输入是索引列表,输出是相应的词嵌入。
官方文档参数说明:
def __init__(self, num_embeddings, embedding_dim, padding_idx=None, max_norm=None, norm_type=2., scale_grad_by_freq=False, sparse=False, _weight=None)
Args: num_embeddings (int): size of the dictionary of embeddings embedding_dim (int): the size of each embedding vector padding_idx (int, optional): If given, pads the output with the embedding vector at :attr:`padding_idx` (initialized to zeros) whenever it encounters the index. max_norm (float, optional): If given, each embedding vector with norm larger than :attr:`max_norm` is renormalized to have norm :attr:`max_norm`. norm_type (float, optional): The p of the p-norm to compute for the :attr:`max_norm` option. Default ``2``. scale_grad_by_freq (boolean, optional): If given, this will scale gradients by the inverse of frequency of the words in the mini-batch. Default ``False``. sparse (bool, optional): If ``True``, gradient w.r.t. :attr:`weight` matrix will be a sparse tensor. See Notes for more details regarding sparse gradients.
参数理解说明:
PyTorch之 torch.nn.Embedding 词嵌入层的理解
原文:https://www.cnblogs.com/luckyplj/p/13377672.html