Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running 08_word2vec.ipynb #76

Closed
w268wang opened this issue Feb 4, 2017 · 4 comments
Closed

Error when running 08_word2vec.ipynb #76

w268wang opened this issue Feb 4, 2017 · 4 comments

Comments

@w268wang
Copy link

w268wang commented Feb 4, 2017

I tried to run the ipynb file on my Mac and got this error

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/anaconda/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py in apply_op(self, op_type_name, name, **keywords)
    489                 as_ref=input_arg.is_ref,
--> 490                 preferred_dtype=default_dtype)
    491           except ValueError:

~/anaconda/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in convert_to_tensor(value, dtype, name, as_ref, preferred_dtype)
    656         if ret is None:
--> 657           ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
    658 

~/anaconda/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in _TensorTensorConversionFunction(t, dtype, name, as_ref)
    570         "Tensor conversion requested dtype %s for Tensor with dtype %s: %r"
--> 571         % (dtype.name, t.dtype.name, str(t)))
    572   return t

ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("nce_loss/Reshape_1:0", shape=(?, 1, ?), dtype=float32)'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-3-9796681a13df> in <module>()
     19 #   tf.nn.nce_loss(weights, biases, inputs, labels, num_sampled, num_classes ...)
     20 # It automatically draws negative samples when we evaluate the loss.
---> 21 loss = tf.reduce_mean(tf.nn.nce_loss(nce_weights, nce_biases, train_labels, embed, num_sampled, voc_size))
     22 # Use the adam optimizer
     23 train_op = tf.train.AdamOptimizer(1e-1).minimize(loss)

~/anaconda/lib/python3.5/site-packages/tensorflow/python/ops/nn.py in nce_loss(weights, biases, inputs, labels, num_sampled, num_classes, num_true, sampled_values, remove_accidental_hits, partition_strategy, name)
   1189       remove_accidental_hits=remove_accidental_hits,
   1190       partition_strategy=partition_strategy,
-> 1191       name=name)
   1192   sampled_losses = sigmoid_cross_entropy_with_logits(
   1193       logits, labels, name="sampled_losses")

~/anaconda/lib/python3.5/site-packages/tensorflow/python/ops/nn.py in _compute_sampled_logits(weights, biases, inputs, labels, num_sampled, num_classes, num_true, sampled_values, subtract_log_q, remove_accidental_hits, partition_strategy, name)
   1049     row_wise_dots = math_ops.mul(
   1050         array_ops.expand_dims(inputs, 1),
-> 1051         array_ops.reshape(true_w, new_true_w_shape))
   1052     # We want the row-wise dot plus biases which yields a
   1053     # [batch_size, num_true] tensor of true_logits.

~/anaconda/lib/python3.5/site-packages/tensorflow/python/ops/gen_math_ops.py in mul(x, y, name)
   1517     A `Tensor`. Has the same type as `x`.
   1518   """
-> 1519   result = _op_def_lib.apply_op("Mul", x=x, y=y, name=name)
   1520   return result
   1521 

~/anaconda/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py in apply_op(self, op_type_name, name, **keywords)
    510                   "%s type %s of argument '%s'." %
    511                   (prefix, dtypes.as_dtype(attrs[input_arg.type_attr]).name,
--> 512                    inferred_from[input_arg.type_attr]))
    513 
    514           types = [values.dtype]

TypeError: Input 'y' of 'Mul' Op has type float32 that does not match type int32 of argument 'x'.

when trying to execute the second last line of the second last block
loss = tf.reduce_mean(tf.nn.nce_loss(nce_weights, nce_biases, train_labels, embed, num_sampled, voc_size))
I double checked the document, but still cannot fix the issue. Is there any idea what is going wrong?
Python: 3.5
tensorflow: 0.11.0
OS: Sierra 10.12.2

Many thanks

@ruzrobert
Copy link
Contributor

Hello, @w268wang !
You need to use TensorFlow r1.0-rc0, to make Tutorials work.
0.11 is very (if we can say like that) old version.

@w268wang
Copy link
Author

w268wang commented Feb 4, 2017

Hi, @ruzrobert thank you for your reply!
I did a pip install tensorflow --upgrade and it update my tensorflow to 0.12.1 (and I got the same error :( ) and the version of documents on the tensorflow website is r0.12.
Is r1.0 released and how can I get it?
Many thanks

@ruzrobert
Copy link
Contributor

ruzrobert commented Feb 4, 2017

There is even r1.0-rc1 released 21 hours ago, but I am on rc0 right now.
You can get links for downloads here:
tensorflow/tensorflow@0174cb2
Specifically, for you, Mac OS X:
#Mac OS X, CPU only, Python 3.4 or 3.5:
(tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.0.0rc0-py3-none-any.whl
I don't see a GPU version for Python 3 there.

Also, you can found GPU version of rc1 here:
https://www.tensorflow.org/versions/r1.0/get_started/os_setup
# Mac OS X, GPU enabled, Python 3.4 or 3.5:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.0.0rc1-py3-none-any.whl
# Python 3
$ sudo pip3 install --upgrade $TF_BINARY_URL

Try that :)

@w268wang
Copy link
Author

w268wang commented Feb 4, 2017

Thanks a lot @ruzrobert !
That was embarrassing though... I will go checking the branches next time

@w268wang w268wang closed this as completed Feb 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants