Open vladimircape opened 7 years ago
I guess that you used an old version of TensorFlow. The order of the parameters of the function nce_loss() in TensorFlow 1.0 have changed. For this error, you just need to exchange the position of train_labels and embed.
D:\Programms\Python35>python 08_word2vec.py I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfully opened CUDA libr ary cublas64_80.dll locally I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfully opened CUDA libr ary cudnn64_5.dll locally I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfully opened CUDA libr ary cufft64_80.dll locally I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfully opened CUDA libr ary nvcuda.dll locally I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfully opened CUDA libr ary curand64_80.dll locally Word count [('cats', 10), ('dogs', 6), ('and', 5), ('are', 4), ('love', 3)] Sample data [7, 12, 24, 11, 13, 19, 7, 15, 17, 27] ['the', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy', 'dog', 'I'] Context pairs [[[7, 24], 12], [[12, 11], 24], [[24, 13], 11], [[11, 19], 13], [[13, 7], 19], [[19, 15], 7], [[7, 17], 15], [[15, 27], 17], [ [17, 4], 27], [[27, 0], 4]] skip-gram pairs [[12, 7], [12, 24], [24, 12], [24, 11], [11, 24]] Batches (x, y) ([17, 20, 0], [[15], [14], [25]]) Traceback (most recent call last): File "D:\Programms\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 490, in apply_op preferred_dtype=default_dtype) File "D:\Programms\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 669, in convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "D:\Programms\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 583, in _TensorTensorConversionFunction % (dtype.name, t.dtype.name, str(t))) ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("nce_loss/Reshape_1:0", shape=(?, 1, ?), dtype=fl oat32)'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "08_word2vec.py", line 92, in
loss = tf.reduce_mean(tf.nn.nce_loss(nce_weights, nce_biases, train_labels, embed, num_sampled, voc_size))
File "D:\Programms\Python35\lib\site-packages\tensorflow\python\ops\nn.py", line 1336, in nce_loss
name=name)
File "D:\Programms\Python35\lib\site-packages\tensorflow\python\ops\nn.py", line 1198, in _compute_sampled_logits
array_ops.reshape(true_w, new_true_w_shape))
File "D:\Programms\Python35\lib\site-packages\tensorflow\python\ops\gen_math_ops.py", line 1613, in mul
result = _op_def_lib.apply_op("Mul", x=x, y=y, name=name)
File "D:\Programms\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 521, in apply_op
inferred_from[input_arg.type_attr]))
TypeError: Input 'y' of 'Mul' Op has type float32 that does not match type int32 of argument 'x'.