前端输入导致的Keras形状错误

我正在尝试使用Keras和词袋模型构建一个聊天机器人。但是当我尝试从前端输入答案时,我遇到了以下错误:

ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 69 but received input with shape [None, 1]

这是我的代码:

model = tensorflow.keras.Sequential([        tensorflow.keras.layers.Dense(8,input_shape=(len(training[0]), )),        tensorflow.keras.layers.Dense(8),        tensorflow.keras.layers.Dense(len(output[0]), activation = "softmax")    ])    model.compile(optimizer="adam", loss="categorical_crossentropy", metrics="accuracy")    model.summary()try:        tensorflow.keras.models.load_model('heya')        print('Existing model loaded.')    except:        model.fit(training, output, epochs=1000, batch_size=8)        model.save('heya')

任何帮助都将不胜感激


回答:

你需要正确定义模型的输入和输出形状

输入维度是特征的数量(在你的例子中是69),而输出维度相当于类别的数量(在你的例子中是13)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注