NeuralNine / neuralintents

A simple interface for working with intents and chatbots.
MIT License
253 stars 137 forks source link

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

Open CalluMcGregor opened 1 year ago

CalluMcGregor commented 1 year ago

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 commented 6 months ago

hello did you fix this issue ? having the same one