下面有一个代码
while True:
question = input("你: ")
question_seq = tokenizer.texts_to_sequences([question])
question_seq_padded = keras.preprocessing.sequence.pad_sequences(question_seq, maxlen=max_len)
answer_seq = model.predict(question_seq_padded).argmax(axis=-1)[0]
answer = tokenizer.index_word[answer_seq]
print("機器人:", answer)
当我运行它时,发生了一些错误
answer = tokenizer.index_word[answer_seq]
发布错误
TypeError: Unhashable type: 'numpy.ndarray'
我试着找到错误的,也许answer_seq不能哈希,我不知道。
您应该使用tokenizer.sequences_to_texts([answer_seq])。
我找到了修复代码的方法,只需添加如下内容:
answer_seq_tuple = tuple(answer_seq)
answer = tokenizer.sequences_to_texts(answer_seq_tuple)