我正在尝试使用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)