2

I'm working through the code
https://www.tensorflow.org/tutorials/sequences/text_generation

When I arrive at the line the following error is produced.

 sampled_indices = tf.random.categorical(example_batch_predictions[0], num_samples=1)
 sampled_indices = tf.squeeze(sampled_indices,axis=-1).numpy()

Error

AttributeError
Traceback (most recent call last)

in

----> 1 sampled_indices = tf.random.categorical(example_batch_predictions[0], num_samples=1)
2 sampled_indices = tf.squeeze(sampled_indices,axis=-1).numpy()

AttributeError: module 'tensorflow._api.v1.random' has no attribute 'categorical'

System information - TensorFlow version: 1.12 Jupyter NoteBooks on Ubuntu

Any pointers for what could be missing? I'm wondering if there is an import missing?

1
  • 1
    You can now update to tf 2.0. This issue is fixed in 2.0. Commented Oct 1, 2019 at 11:24

1 Answer 1

4

tf.random.categorical probably has been changed to tf.random.multinomial, assuming example_batch_predictions are logits: https://www.tensorflow.org/api_docs/python/tf/random/multinomial

Sign up to request clarification or add additional context in comments.

1 Comment

Looks like tf.keras.losses.sparse_categorical_crossentropy can be replaced by tf.keras.losses.sparse_categorical_crossentropy. So return tf.nn.sparse_softmax_cross_entropy_with_logits(labels=labels, logits=logits).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.