An Application and an AI Library can able to train NLP Chatbot Model with own custome dataset. User or Developer can able to train the AI NLP chat bot Model by uploading their custome dataset.
pip install ChatNeuron==1.1
from ChatNeuron.ai import chatNeuron
from tensorflow.keras import preprocessing
import numpy as np
Coloum name should be 'questions' and 'answers'. Example below,
from ChatNeuron.ai import chatNeuron
tokenizer, encoder_model, decoder_model, maxlen_questions, maxlen_answers = chatNeuron.build_chatbot(csvFilePath, batch, epoch, savepath)
csvFilePath - CSV File that consist of the coloum questions and answers
batch - Number of batch the model will take during the training
epoch - Numebr of Iteration the model need to be trained
savepath - Path where the model will be saved
The model will train like below,
We have tokenizer, encoder_model, decoder_model, maxlen_questions, maxlen_answers
these variable from the trained model
def preprocess_input(input_sentence,tokenizer,maxlen_questions):
tokens = input_sentence.lower().split()
tokens_list = []
for word in tokens:
tokens_list.append(tokenizer.word_index[word])
return preprocessing.sequence.pad_sequences([tokens_list] , maxlen=maxlen_questions , padding='post')
states_values = encoderModel.predict(preprocess_input(question,tokenizer,int(maxlen_questions)), verbose=0)
empty_target_seq = np.zeros((1 , 1))
empty_target_seq[0, 0] = tokenizer.word_index['start']
stop_condition = False
decoded_translation = ''
while not stop_condition :
dec_outputs , h , c = decoderModel.predict([empty_target_seq] + states_values, verbose=0)
sampled_word_index = np.argmax(dec_outputs[0, -1, :])
sampled_word = None
for word , index in tokenizer.word_index.items() :
if sampled_word_index == index :
decoded_translation += f' {word}'
sampled_word = word
if sampled_word == 'end' or len(decoded_translation.split()) > int(maxlen_answers):
stop_condition = True
empty_target_seq = np.zeros((1 , 1))
empty_target_seq[0 , 0] = sampled_word_index
states_values = [h , c]
print(f'Human: {question}')
print()
decoded_translation = decoded_translation.split(' end')[0]
print(f'Bot: {decoded_translation}')
print('-'*25)
Insted of the question pass you own question.
https://chat-neuron.onrender.com/