我正在研究代码
https://www.tensorflow.org/tutorials/sequences/text_generation
当我到达该行时,会产生以下错误。
sampled_indices = tf.random.categorical(example_batch_predictions[0], num_samples=1)
sampled_indices = tf.squeeze(sampled_indices,axis=-1).numpy()
错误
AttributeError
Traceback (most recent call last)
中
----> 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'
系统信息 - TensorFlow 版本:Ubuntu 上的 1.12 Jupyter NoteBooks
有什么可能遗漏的地方吗?我想知道是否缺少导入?
最佳答案
tf.random.categorical 可能已更改为 tf.random.multinomial,假设 example_batch_predictions 是 logits: https://www.tensorflow.org/api_docs/python/tf/random/multinomial
关于python - tensorflow 文本生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54210128/