Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tensorflow文本生成_Python_Tensorflow - Fatal编程技术网

Python Tensorflow文本生成

Python Tensorflow文本生成,python,tensorflow,Python,Tensorflow,我正在处理代码 当我到达该行时,产生以下错误 sampled_indices = tf.random.categorical(example_batch_predictions[0], num_samples=1) sampled_indices = tf.squeeze(sampled_indices,axis=-1).numpy() 错误 在 系统信息 -TensorFlow版本:Ubuntu上的1.12 Jupyter笔记本电脑 有没有关于可能遗漏什么的指针?我想知道是否缺少导入?

我正在处理代码

当我到达该行时,产生以下错误

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

系统信息 -TensorFlow版本:Ubuntu上的1.12 Jupyter笔记本电脑


有没有关于可能遗漏什么的指针?我想知道是否缺少导入?

tf.random.category可能已更改为tf.random.multinomial,假设示例批处理预测为logits:

看起来像tf.keras.loss.sparse\u categorical\u crossentropy可以被tf.keras.loss.sparse\u categorical\u crossentropy替换。因此,返回tf.nn.sparse\u softmax\u cross\u entropy\u,并使用logitslabels=labels,logits=logits。您现在可以更新到tf2.0。此问题在2.0中已修复。
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'