我正在尝试使用Keras和python训练一个简单的模型。文本经过了完美的预处理。但是当我尝试适应它时,出现以下错误:
df <- data.frame(x = 1:10, y = 1:10)
library(ggplot2)
ggplot(df, aes(x, y)) +
geom_point() +
# Y position adjusted manually
geom_text(aes(5, 2.9, label = "-"), color = "blue", size = 1000) +
# Y position adjusted manually
geom_text(aes(5, 21.2, label = "-"), color = "blue", size = 1000) +
# Plot outside plot area
coord_cartesian(ylim = c(0, 10), clip = "off")
但是File "main.py", line 47, in <module>
model.fit(x_train, y_train, batch_size=32, epochs=3)
File "/home/shamildacoder/.local/lib/python3.6/site-packages/keras/engine/training.py", line 952, in fit
batch_size=batch_size)
File "/home/shamildacoder/.local/lib/python3.6/site-packages/keras/engine/training.py", line 789, in _standardize_user_data
exception_prefix='target')
File "/home/shamildacoder/.local/lib/python3.6/site-packages/keras/engine/training_utils.py", line 138, in standardize_input_data
str(data_shape))
ValueError: Error when checking target: expected dense_2 to have shape (121885,) but got array with shape (1000,)
和print(x_train.shape)
都返回print(y_train.shape)
。我没看到任何原因。
代码:https://pastebin.com/afnzBf6B
(121885, 1000)
答案 0 :(得分:1)
在预处理阶段,您使用texts_to_matrix()
方法(具有默认参数)将给定序列作为单行编码格式的矩阵行返回。现在,如果您只想使用密集层将一个热编码序列转换为另一个热编码序列,则需要将最后一层中的单位数设置为词汇表大小(即,矩阵),并使用@unique
作为最后一层的激活函数:
sigmoid