You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have trained my model and all the files are where they should be (I think) but when i run my file (below) nothing happens. I get no errors, but i cant use my chatbot or anything.
import random
import json
import pickle
import numpy as np
import nltk
from nltk.stem import WordNetLemmatizer
from tensorflow import keras
from keras.models import load_model
lemmatizer = WordNetLemmatizer()
intents = json.loads(open('intents.json').read())
words = pickle.load(open('words.pkl', 'rb'))
classes = pickle.load(open('classes.pkl', 'rb'))
model = load_model('chatbot_model.h5')
def clean_sentence(sentence):
sentence_words = nltk.word_tokenize(sentence)
sentence_words = [lemmatizer.lemmatize(word) for word in sentence_words]
return(sentence_words)
def word_bag(sentence):
sentence_words = clean_sentence(sentence)
bag = [0] * len(words)
for w in sentence_words:
for i, word in enumerate(words):
if word == w:
bag[i] = 1
return np.array(bag)
def predict_class(sentence):
wb = word_bag(sentence)
result = model.predict(np.array([wb]))[0]
ERROR_THRESHOLD = 0.25
result = [[i, r] for i, r in enumerate(result) if r > ERROR_THRESHOLD]
result.sort(key=lambda x: x[1], reverse=True)
return_list = []
for r in result:
return_list.append({'intent': classes[r[0]], 'probability': str(r[1])})
return return_list
The text was updated successfully, but these errors were encountered:
I have trained my model and all the files are where they should be (I think) but when i run my file (below) nothing happens. I get no errors, but i cant use my chatbot or anything.
import random
import json
import pickle
import numpy as np
import nltk
from nltk.stem import WordNetLemmatizer
from tensorflow import keras
from keras.models import load_model
lemmatizer = WordNetLemmatizer()
intents = json.loads(open('intents.json').read())
words = pickle.load(open('words.pkl', 'rb'))
classes = pickle.load(open('classes.pkl', 'rb'))
model = load_model('chatbot_model.h5')
def clean_sentence(sentence):
sentence_words = nltk.word_tokenize(sentence)
sentence_words = [lemmatizer.lemmatize(word) for word in sentence_words]
return(sentence_words)
def word_bag(sentence):
sentence_words = clean_sentence(sentence)
bag = [0] * len(words)
for w in sentence_words:
for i, word in enumerate(words):
if word == w:
bag[i] = 1
return np.array(bag)
def predict_class(sentence):
wb = word_bag(sentence)
result = model.predict(np.array([wb]))[0]
ERROR_THRESHOLD = 0.25
result = [[i, r] for i, r in enumerate(result) if r > ERROR_THRESHOLD]
The text was updated successfully, but these errors were encountered: