tensorflow - TensorFlow:没有打印输出查找嵌入
问题描述
我一直在遵循https://ireneli.eu/2017/01/17/tensorflow-07-word-embeddings-2-loading-pre-trained-vectors/上的说明。
为什么我没有得到运行以下命令的输出(在最后一个包含 sess.run() 的单元格中):
from __future__ import absolute_import, division, print_function
import os
import matplotlib.pyplot as plt
import tensorflow as tf
[新单元格]
import numpy as np
filename = 'glove.6B.50d.txt'
def loadGloVe(filename):
[有关其余定义,请参见上面的链接]
[见上面的链接初始化嵌入]
[新单元格]
sent_toks = None
with open("documents.json") as f:
training = js.load(f)
all_parags = [compute this value]
sent_toks = nltk.sent_tokenize(all_parags)
[新单元格 - 见上面的链接]
import tensorflow.contrib.learn as le
# init vocab processor
[etc.]
x = np.array(list(vocab_processor.transform(sent_toks)))
[新单元格]
g = tf.Graph()
with g.as_default():
W = tf.Variable(tf.constant(0.0, shape=[vocab_size, embedding_dim]),
trainable=False, name="W")
embedding_placeholder = tf.placeholder(tf.float32, [vocab_size, embedding_dim])
embedding_init = W.assign(embedding_placeholder)
foo = tf.nn.embedding_lookup(W, x[0])
init_op = tf.initialize_all_variables()
print_output = tf.Print(foo, [foo])
with tf.Session(graph = g) as sess:
sess.run(init_op)
sess.run(print_output)
顺便一提,
print(x[0])
给
[ 0 2827 5 6097 19 0 0 18 13 1427 1 59126
4135 111 1 7770 43737 2 622 0 2 6 19517 31152
1245 44144 5 6 20308 10 2891 509 707 6385 4 1
6307 3649 2 41 970 19123 2656 0 0 0 0 0
0 0]
解决方案
推荐阅读
- java - 错误:无法弄清楚如何将此字段保存到我的模型类中的数据库中
- dart - 异步运行同步库函数
- javascript - 将一个项目插入另一个处于反应状态的列表中
- spring-boot - OAuth2 使用社交帐户进行身份验证并将 jwt 令牌存储在数据库中
- python - 如何使用神经网络同时预测期望值和方差?
- html - 将长文本分成多行
- html - 打开具有相同 URL 的新选项卡,每个选项卡中使用不同的命令
- c++ - C++ 重载 () 运算符、左值和右值
- m4 - 如何正确检测 m4 中的定义/变量是否为空,而它可以包含逗号?
- java - 数组返回值问题中的Java递归线性搜索