python - tensorflow 层 basic_lstm_cell_1 的 LSTM 输入 0

标签 python tensorflow

当我运行代码时,我正在使用 tensorflow 处理 lstm,它向我显示错误。代码运行正常,但是当我运行函数时 tf.nn.dynamic_rnn(lstmCell, data, dtype=tf.float64) 它显示值错误

import tensorflow as tf

wordsList = np.load('urduwords.npy')
wordVectors = np.load('urduwordsMatrix.npy')

batchSize = 24
lstmUnits = 64
numClasses = 2
iterations = 10000

tf.reset_default_graph()


labels = tf.placeholder(tf.float32, [batchSize, numClasses])
input_data = tf.placeholder(tf.int32, [batchSize, maxSeqLength])

print(labels)

data = tf.Variable(tf.zeros([batchSize, maxSeqLength, numDimensions]),dtype=tf.float32)
print(data)


data = tf.nn.embedding_lookup(wordVectors,input_data)
print(data)


lstmCell = tf.contrib.rnn.BasicLSTMCell(lstmUnits)
lstmCell = tf.contrib.rnn.DropoutWrapper(cell=lstmCell, output_keep_prob=0.1)

value, _ = tf.nn.dynamic_rnn(lstmCell, data, dtype=tf.float64)

如何使用 tensorflow 解决此错误。

ValueError: Input 0 of layer basic_lstm_cell_1 is incompatible with the layer: expected ndim=2, found ndim=3. Full shape received: [24, 1, 2]

input_data 的形状是

(24, 30, 1, 2)

wordVector 的形状是

(24053, 1, 2)

最佳答案

标签形状是 4 维的,因为你向 tf 提供了错误类型的数据,

请尝试使用 NumberPy 数组或 List

关于python - tensorflow 层 basic_lstm_cell_1 的 LSTM 输入 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52801571/

相关文章:

python - 如何禁用pygame中的窗口关闭按钮?

python - 在 Django 中更改 url

python - 从张量列表创建参差不齐的张量

machine-learning - 什么代表 Keras 中训练结果的损失或准确性

tensorflow - TensorFlow 计划支持 OpenCL 吗?

python - 如何使用 FastAPI + uvicorn 在工作人员之间共享数据库连接?

python - 在 Python 中将 unicode 文本规范化为文件名等

python - 查找包含给定文件的文件系统的大小和可用空间

python - 将 InputLayer 添加到现有 Keras 模型以与 Android Tensor Flow Library 一起使用

python - tensorflow -运行时错误 : Cannot get value inside Tensorflow graph function