Embedding层的初始值是多少?

What is the initial value of Embedding layer?

我正在研究词表示的嵌入。在许多 dnn 库中,它们支持嵌入层。这是非常好的教程。

Word Embeddings: Encoding Lexical Semantics

但我仍然不确定如何计算嵌入值。在下面的例子中,它甚至在任何训练之前就输出了一些值。它使用一些随机权重吗?我实现了 Embedding(2, 5) 的目的,但不确定其初始计算。而且我也不确定如何学习其嵌入的权重。

word_to_ix = {"hello": 0, "world": 1}
embeds = nn.Embedding(2, 5)  # 2 words in vocab, 5 dimensional embeddings
lookup_tensor = torch.LongTensor([word_to_ix["hello"]])
hello_embed = embeds(autograd.Variable(lookup_tensor))
print(hello_embed)
--------
Variable containing:
-2.9718  1.7070 -0.4305 -2.2820  0.5237
[torch.FloatTensor of size 1x5]

我打破了我的想法,以确保。首先,upperEmbedding(2, 5)是一个形状为(2, 5).

的矩阵
Embedding(2, 5) = 
 [[0.1,-0.2,0.3,0.4,0.1],
 [-0.2,0.1,0.8,0.2,0.3]] # initiated by some function, like random normal distribution

那么,hello就是[1, 0]。然后hello表示由[1, 0].dot(Embedding(2, 5)) = [0.1,-0.2,0.3,0.4,0.1]计算。这实际上是嵌入的第一行。我理解的对吗?


更新

我找到了一个嵌入的代码,它的值正是使用正态分布。是的,但这只是一个默认值,我们可以为嵌入层设置任意权重。 https://github.com/chainer/chainer/blob/adba7b846d018b9dc7d19d52147ef53f5e555dc8/chainer/links/connection/embed_id.py#L58

是的。你从随机权重开始。我认为使用截断正态分布而不是正态分布更为常见。但是,这可能并没有太大的区别。

Initializations 定义设置初始random weights层的方式。您可以使用任何值来做到这一点。但初始值会影响 Word EmbeddingPre-trained Word Embedding 有很多方法,他们尝试选择更好的初始值,如 this