我是Python的新手并使用Tensorflow,但现在我只是尝试从here实现基本的Word2Vec教程。
它的代码如下:
with tf.device('/cpu:0'):
embeddings = tf.Variable(
tf.random_uniform([vocabulary_size, embedding_size], -1.0, 1.0))
embed = tf.nn.embedding_lookup(embeddings, train_inputs)
当我运行with tf.device
部分时,它会输出此错误:
File "<ipython-input-26-83a85a16701d>", line 1
with tf.device('/cpu:0'):
SyntaxError: unexpected EOF while parsing
当我运行整个块时,它会输出
Traceback (most recent call last):
File "<ipython-input-23-79908ea0756f>", line 5, in <module>
embed = tf.nn.embedding_lookup(embeddings, train_inputs)
File "...\Anaconda3\lib\site-packages\tensorflow\python\ops\embedding_ops.py", line 100, in embedding_lookup
with ops.name_scope(name, "embedding_lookup", params + [ids]) as name:
File "...\Anaconda3\lib\contextlib.py", line 59, in `__enter__`
return next(self.gen)
File "...\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 4055, in name_scope
g = _get_graph_from_inputs(values)
File "...\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 3804, in _get_graph_from_inputs
_assert_same_graph(original_graph_element, graph_element)
File "...\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 3743, in _assert_same_graph
"%s must be from the same graph as %s." % (item, original_item))
ValueError: Tensor("Placeholder_2:0", shape=(128,), dtype=int32) must be from the same graph as Tensor("Variable_6:0", shape=(50000, 128), dtype=float32_ref, device=/device:CPU:0).
以前谢谢!