我试图理解word2vec示例是如何工作的,并不真正理解传递给nse_loss函数的权重和偏差的目的是什么.函数有两个变量输入:权重(加偏差)和嵌入.
# Look up embeddings for inputs.
embeddings = tf.Variable(
tf.random_uniform([vocabulary_size, embedding_size], -1.0, 1.0))
embed = tf.nn.embedding_lookup(embeddings, train_inputs)
# Construct the variables for the NCE loss
nce_weights = tf.Variable(
tf.truncated_normal([vocabulary_size, embedding_size],
stddev=1.0 / math.sqrt(embedding_size)))
nce_biases = tf.Variable(tf.zeros([vocabulary_size]))
Run Code Online (Sandbox Code Playgroud)
两者都是随机初始化的(据我所知)两者都在学习期间受到更新.
# Compute the average NCE loss for the batch.
loss = tf.reduce_mean(
tf.nn.nce_loss(nce_weights, nce_biases, embed, train_labels,
num_sampled, vocabulary_size))
Run Code Online (Sandbox Code Playgroud)
我想他们两个都应该代表训练有素的模型.然而,重量和偏差以后从未用于相似性计算.相反,只使用一个组件:
# Compute the cosine similarity between minibatch examples and all embeddings.
norm = tf.sqrt(tf.reduce_sum(tf.square(embeddings), 1, keep_dims=True))
normalized_embeddings = embeddings / norm …Run Code Online (Sandbox Code Playgroud) 有没有notify()可能造成僵局的情况,但是notifyAll()- 从来没有?
例如,在多个锁的情况下.notify()通知只运行一个线程,它检查对某个对象的锁定并再次等待,但另一个线程可以解锁该对象.在使用的情况下,notifyAll()将通知所有线程运行,其中一个轮流将确保解锁该对象.