简体   繁体   English

Tensorflow 中嵌入层的工作

[英]Working of embedding layer in Tensorflow

Can someone please explain me the inputs and outputs along with the working of the layer mentioned below有人可以向我解释输入和输出以及下面提到的层的工作吗

model.add(Embedding(total_words, 64, input_length=max_sequence_len-1))

total_words = 263总字数 = 263

max_sequence_len=11 max_sequence_len=11

Is 64, the number of dimensions?是64,维数吗?

And why is the output of this layer (None, 10, 64)为什么这一层的输出是 (None, 10, 64)

Shouldn't it be a 64 dimension vector for each word, ie (None, 263, 64)不应该是每个词的 64 维向量,即 (None, 263, 64)

In the Embedding layer the first argument represents the input dimensions (which is typically of considerable dimensionality).Embedding层中,第一个参数表示输入维度(通常具有相当大的维度)。 The second argument represents the output dimensions, aka the dimensionality of the reduced vector.第二个参数表示输出维度,也就是缩减向量的维度。 The third argument is for the sequence length.第三个参数是序列长度。 In essence, an Embedding layer is simply learning a lookup table of shape (input dim, output dim) .本质上,嵌入层只是学习形状(input dim, output dim)的查找表。 The weights of this layer reflect that shape.该层的权重反映了该形状。 The output of the layer, however, will of course be of shape (output dim, seq length) ;然而,层的输出当然会是形状(output dim, seq length) one dimensionality-reduced embedding vector for each element in the input sequence.输入序列中每个元素的一维减少嵌入向量。 The shape you were expecting is actually the shape of the weights of an embedding layer.您期望的形状实际上是嵌入层权重的形状。

You can find all the information about the Embedding Layer of Tensorflow Here .您可以在此处找到有关 Tensorflow 嵌入层的所有信息。

The first two parameters are input_dimension and output_dimension .前两个参数是input_dimensionoutput_dimension

  • The input dimensions basically represents the vocabulary size of your model.输入维度基本上代表了模型的词汇量大小。 You can find this out by using the word_index function of the Tokenizer() function.您可以通过使用Tokenizer()函数的word_index函数找到这一点。
  • The output dimensions are going to be Dimensions of the input of the next Dense Layer输出维度将是下一个Dense Layer的输入维度

The output of the Embedding layer is of the form (batch_size, input_length, output_dim) . Embedding 层的输出格式为(batch_size, input_length, output_dim) But since you specified the input_length parameter, your layers input will be of the form (batch, input_length) .但是由于您指定了 input_length 参数,因此您的图层输入将采用(batch, input_length)形式。 That's why the output is of the form (None, 10 ,64).这就是为什么输出是 (None, 10 ,64) 形式的原因。

Hope that clears up your doubt ☺️希望能解开你的疑惑☺️

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM