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

问题描述 投票:0回答:1

[我已经使用keras训练了模型,当尝试使用keras情绪分析来预测带有原始文本数据的值时从SQL Server获取原始数据

这是我的代码

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,)

python tensorflow keras sentiment-analysis
1个回答
0
投票

model.predict()需要小批数据,但是您只传递了一个样本。您可以通过在x_t:]中创建其他尺寸,将样本转换为大小为1的小批量。

sentiment = model.predict(x_t[np.newaxis, :],batch_size=2)[0]
© www.soinside.com 2019 - 2024. All rights reserved.