TypeError: Unhashable type: 'numpy.ndarray' in keras
Question:
I have a code below
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)
And when i ran it, happened some wrong
answer = tokenizer.index_word[answer_seq]
issued error
TypeError: Unhashable type: 'numpy.ndarray'
I try to find the wrong, maybe answer_seq can’t hash, I don’t know.
Answers:
You should use tokenizer.sequences_to_texts([answer_seq]) instead.
I found the way to fix the code, just add something like below.
answer_seq_tuple = tuple(answer_seq)
answer = tokenizer.sequences_to_texts(answer_seq_tuple)
I have a code below
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)
And when i ran it, happened some wrong
answer = tokenizer.index_word[answer_seq]
issued error
TypeError: Unhashable type: 'numpy.ndarray'
I try to find the wrong, maybe answer_seq can’t hash, I don’t know.
You should use tokenizer.sequences_to_texts([answer_seq]) instead.
I found the way to fix the code, just add something like below.
answer_seq_tuple = tuple(answer_seq)
answer = tokenizer.sequences_to_texts(answer_seq_tuple)