繁体   English   中英

ValueError:检查输入时出错:预期 embedding_2_input 具有形状 (500,) 但得到形状为 (1,) 的数组

[英]ValueError: Error when checking input: expected embedding_2_input to have shape (500,) but got array with shape (1,)

我已经使用 keras 训练了模型,并在尝试使用 keras 情感分析使用原始文本数据预测值时从 SQL 服务器获取原始数据

这是我的代码

x_data = [clean_text]
x_data_series = pd.Series(x_data)
raw_text = tokenizer.texts_to_sequences(x_data_series)
raw_text = pad_sequences(raw_text, maxlen=1, dtype='int32', value=0)
for x_t in raw_text:
  sentiment = model.predict(x_t,batch_size=2)[0]
  y_classes = sentiment.argmax(axis=-1) 

在这条线上获取错误

sentiment = model.predict(x_t,batch_size=2)[0]

错误

ValueError:检查输入时出错:预期 embedding_2_input 具有形状 (500,) 但得到形状为 (1,) 的数组

model.predict()需要小批量数据,但您只传递一个样本。 您可以通过在x_t创建附加维度将您的样本转换为大小为 1 的小x_t

sentiment = model.predict(x_t[np.newaxis, :],batch_size=2)[0]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM