【发布时间】:2021-10-17 10:49:14
【问题描述】:
我一直在尝试用 python 制作一个简单的聊天机器人,但输入形状有问题 我的神经网络如下:
from keras import models
from keras import layers
model = models.Sequential()
model.add(layers.Dense(8,activation='relu', input_shape=(46,)))
model.add(layers.Dense(8,activation='relu'))
model.add(layers.Dense(len(output[0]), activation = 'softmax'))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
model.fit(training,output,epochs = 200, batch_size=8)
我的数据的输入形状是(26, 46),是一袋词的形式 当我尝试与模型聊天时,会显示此错误
Error when checking input: expected dense_141_input to have shape (46,) but got array with shape (1,)
还有我的聊天方式
def chat():
print("Chat with the bot type quit to end ")
while True:
inp = input("You: ")
if inp.lower() == "quit":
break
results = model.predict([bag_of_words(inp, words)])
results_index = numpy.argmax(results)
tag = labels[results_index]
for tg in data["intents"]:
if tg['tag'] == tag:
responses = tg['responses']
print(random.choice(responses))
【问题讨论】:
标签: keras neural-network chatbot