gpt4 book ai didi

python - tensorflow word2vec 教程如何更新嵌入?

转载 作者:太空宇宙 更新时间:2023-11-04 02:47:33 24 4
gpt4 key购买 nike

此线程接近:What is the purpose of weights and biases in tensorflow word2vec example?

但我对此的解释仍然遗漏了一些东西:https://github.com/tensorflow/tensorflow/blob/r1.2/tensorflow/examples/tutorials/word2vec/word2vec_basic.py

据我了解,您将词典中的目标词和上下文词的索引提供给网络。

_, loss_val = session.run([optimizer, loss], feed_dict=feed_dict)
average_loss += loss_val

然后查找批量输入以返回开始时随机生成的向量

    embeddings = tf.Variable(
tf.random_uniform([vocabulary_size, embedding_size], -1.0, 1.0))
# Look up embeddings for inputs.
embed = tf.nn.embedding_lookup(embeddings, train_inputs)

然后优化器调整权重和偏差以最好地预测标签而不是 num_sampled 随机选择

 loss = tf.reduce_mean(
tf.nn.nce_loss(weights=nce_weights,
biases=nce_biases,
labels=train_labels,
inputs=embed,
num_sampled=num_sampled,
num_classes=vocabulary_size))

# Construct the SGD optimizer using a learning rate of 1.0.
optimizer = tf.train.GradientDescentOptimizer(1.0).minimize(loss)

我的问题如下:

  1. 嵌入变量在哪里更新?。在我看来,我可以通过神经网络运行单词索引或仅获取 final_embeddings 向量并使用它来获得最终结果。但我不明白 embeddings 的随机初始化在哪里发生了变化。

  2. 如果我要绘制这个计算图,它会是什么样子(或者更好的是,实际这样做的最佳方法是什么)?

  3. 这是一次运行批处理中的所有上下文/目标对吗?还是一个一个的?

最佳答案

嵌入嵌入是一个变量。每次你做反向传播时它都会更新(同时运行有损失的优化器)

Grpah:您是否尝试保存图形并将其显示在 tensorboard 中?这是您要找的吗?

批处理:至少在您链接的示例中,他正在使用第 96 行的函数进行批处理。https://github.com/tensorflow/tensorflow/blob/r1.2/tensorflow/examples/tutorials/word2vec/word2vec_basic.py#L96

如果我误解了你的问题,请纠正我。

关于python - tensorflow word2vec 教程如何更新嵌入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44704751/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com