This is my code for a chatbot I’m creating. I keep getting a “TypeError: int() argument must be a string, a bytes-like object or a real number, not ‘NoneType'” error when running it however.
def pre_process_data(data):
tokens = nltk.word_tokenize(data)
tokens = [word.lower() for word in tokens]
stop_words = set(stopwords.words('english'))
tokens = [
word for word in tokens if word not in stop_words and word not in string.punctuation]
lemmatizer = WordNetLemmatizer()
tokens = [lemmatizer.lemmatize(word) for word in tokens]
return tokens
def predict_answer(model, tokenizer, question):
question = pre_process_data(question)
sequence = tokenizer.texts_to_sequences([question])
padded_sequence = pad_sequences(
sequence, maxlen=sequence_length, padding='post', truncating='post')
prediction = model.predict(padded_sequence)[0]
index = numpy.argmax(prediction)
answer = tokenizer.index_word[index]
return answer
while True:
question = input('You: ')
answer = predict_answer(model, tokenizer, question)
print('Chatbot:', answer)
I’m not too sure what I’ve done wrong here ):
The full error code is:
Traceback (most recent call last):
File "D:Chatbotmain.py", line 119, in <module>
answer = predict_answer(model, tokenizer, question)
File "D:Chatbotmain.py", line 109, in predict_answer
padded_sequence = pad_sequences(
File "D:Chatbot.venvlibsite-packageskerassrcutilssequence_utils.py", line 125, in pad_sequences
trunc = np.asarray(trunc, dtype=dtype)
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'