Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I run my code, nothing happens? Plz help #43

Open
CalluMcGregor opened this issue Jun 9, 2023 · 1 comment
Open

When I run my code, nothing happens? Plz help #43

CalluMcGregor opened this issue Jun 9, 2023 · 1 comment

Comments

@CalluMcGregor
Copy link

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
@NajibNakhla
Copy link

hello did you fix this issue ? having the same one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants