Python Word2Vec输入和输出向量

Python Word2Vec输入和输出向量,python,tensorflow,deep-learning,word2vec,Python,Tensorflow,Deep Learning,Word2vec,在阅读有关udacity的word2vec教程时,从文章中可以看出,输入字向量和输出字向量是分开的矩阵 例如,['the','cat','sat','on','mat']。 这里输入向量$w_i$,“the','cat','on','mat'将预测“sat'的输出向量$w_o$。它通过如下所示的采样softmax执行此操作,其中| context |是上下文单词的大小(本例中为4) 因此,一旦完成训练,可能会有两个向量用于sat作为输入向量,另一个用于输出向量问题是为什么没有一个矩阵。这将确保

在阅读有关udacity的word2vec教程时,从文章中可以看出,输入字向量和输出字向量是分开的矩阵

例如,
['the','cat','sat','on','mat']
。 这里输入向量$w_i$,
“the','cat','on','mat'
将预测
“sat'
的输出向量$w_o$。它通过如下所示的采样softmax执行此操作,其中
| context |
是上下文单词的大小(本例中为4)

因此,一旦完成训练,可能会有两个向量用于
sat
作为输入向量,另一个用于输出向量问题是为什么没有一个矩阵。这将确保相同单词的输入和输出向量对齐

如果有帮助,tensorflow代码附在下面(为什么不设置softmax_权重=嵌入和softmax_偏差=0)

# Variables.
embeddings = tf.Variable(tf.random_uniform([vocabulary_size, embedding_size], -1.0, 1.0))
softmax_weights = tf.Variable(tf.truncated_normal([vocabulary_size, embedding_size],
                         stddev=1.0 / math.sqrt(embedding_size)))
softmax_biases = tf.Variable(tf.zeros([vocabulary_size]))

# Model.
# Look up embeddings for inputs.
embed = tf.nn.embedding_lookup(embeddings, train_dataset)
# Compute the softmax loss, using a sample of the negative labels each time.
loss = tf.reduce_mean(tf.nn.sampled_softmax_loss(softmax_weights, softmax_biases, embed,
                               train_labels, num_sampled, vocabulary_size))
更新:
我在没有单独输出矩阵的情况下实现了它,结果仍然很好:我想现在的问题应该是,对于输出矩阵的不同,是否有数学上的原因。

尝试使用一个矩阵来实现它并报告您的发现。请参阅:尝试使用一个矩阵来实现它并报告您的发现。请参阅: