TensorFlow word2vec 教程输入
TensorFlow word2vec tutorial input
在学习 TensorFlow word2vec tutorial 时,我很难理解教程关于将输入存储到 skip-gram 模型的占位符的解释。解释指出
The skip-gram model takes two inputs. One is a batch full of integers
representing the source context words, the other is for the target words... Now what we need to do is look up the vector for each of the source words in the batch... Now that we have the embeddings for each word, we'd like to try to predict the target word.
但是,既然我们使用的是 skip-gram 模型(而不是 CBOW),我们难道不应该改为查找每个目标词的词向量,然后根据给定的词预测上下文词吗?目标词?
此外,我假设下面的代码首先为目标词(输入)声明一个占位符,然后为源上下文词(我们的标签)声明一个占位符。
train_inputs = tf.placeholder(tf.int32, shape=[batch_size])
train_labels = tf.placeholder(tf.int32, shape=[batch_size, 1])
我是不是对教程有误解?
skip-gram 教程假设您的数据集是这样制作的:
(quick, the), (quick, brown), (brown, quick), (brown, fox), ...
它的目的是成对(输入,输出)=(center_word,context_word)。
事实上,如果您对多个(输入、输出)对进行平均,您将获得类似于在每个示例中预测每个上下文词的行为。
这个选择也是因为使用NCE作为损失函数,NCE试图在一些噪声词(随机选择)中区分单个目标词(上下文的词之一)。
您的输入和输出占位符应该具有相同的维度 (batch_size,1)
但输入只是 (batch_size)
因为嵌入层会自动扩展维度而损失函数(您提供标签的地方)需要一个矩阵作为输入。
因此,本教程并不是对 Mikolov 的 skip-gram 模型的精确实现,而是为了代码的简洁性和可读性做了一些近似。
在学习 TensorFlow word2vec tutorial 时,我很难理解教程关于将输入存储到 skip-gram 模型的占位符的解释。解释指出
The skip-gram model takes two inputs. One is a batch full of integers representing the source context words, the other is for the target words... Now what we need to do is look up the vector for each of the source words in the batch... Now that we have the embeddings for each word, we'd like to try to predict the target word.
但是,既然我们使用的是 skip-gram 模型(而不是 CBOW),我们难道不应该改为查找每个目标词的词向量,然后根据给定的词预测上下文词吗?目标词?
此外,我假设下面的代码首先为目标词(输入)声明一个占位符,然后为源上下文词(我们的标签)声明一个占位符。
train_inputs = tf.placeholder(tf.int32, shape=[batch_size])
train_labels = tf.placeholder(tf.int32, shape=[batch_size, 1])
我是不是对教程有误解?
skip-gram 教程假设您的数据集是这样制作的:
(quick, the), (quick, brown), (brown, quick), (brown, fox), ...
它的目的是成对(输入,输出)=(center_word,context_word)。
事实上,如果您对多个(输入、输出)对进行平均,您将获得类似于在每个示例中预测每个上下文词的行为。
这个选择也是因为使用NCE作为损失函数,NCE试图在一些噪声词(随机选择)中区分单个目标词(上下文的词之一)。
您的输入和输出占位符应该具有相同的维度 (batch_size,1)
但输入只是 (batch_size)
因为嵌入层会自动扩展维度而损失函数(您提供标签的地方)需要一个矩阵作为输入。
因此,本教程并不是对 Mikolov 的 skip-gram 模型的精确实现,而是为了代码的简洁性和可读性做了一些近似。