python - tensorflow 文本生成

标签 python tensorflow

我正在研究代码
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/

相关文章:

python - 如果 Python 进程在特定时间内未完成,则终止它?

python - TensorFlow AttributeError : 'NoneType' object has no attribute 'TF_DeleteStatus'

python - 一些 Python 对象未绑定(bind)到检查点值

python - 从相对路径导入模块

python - 对同等大小的图像进行逐像素比较,找到每个像素最常见的颜色

python - 比较字典值并排序一些

python - 搜索字典以获取每个键的完整路径

tensorflow - tf.multinomial 如何工作?

tensorflow - 如何在不使用估计器 API 运行训练/评估的情况下可视化 TensorFlow 图?

python-3.x - 如何为模型准备测试集形状。使用 keras 和 tensorflow 进行评估?