Skip to content

Latest commit

 

History

History
88 lines (69 loc) · 3.04 KB

README.md

File metadata and controls

88 lines (69 loc) · 3.04 KB

Chat-Neuron

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.

Installation of Package

pip install ChatNeuron==1.1

Import the module

from ChatNeuron.ai import chatNeuron
from tensorflow.keras import preprocessing
import numpy as np

Train Custome NLP Model

Coloum name should be 'questions' and 'answers'. Example below,
image

Source Code

from ChatNeuron.ai import chatNeuron

tokenizer, encoder_model, decoder_model, maxlen_questions, maxlen_answers = chatNeuron.build_chatbot(csvFilePath, batch, epoch, savepath)

The parameters need to be passed are,

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,
image


Responce from Custome NLP Trained Model

We have tokenizer, encoder_model, decoder_model, maxlen_questions, maxlen_answers these variable from the trained model

Preprocessing Function

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')

Below script will get the responce from the bot need to pass the text

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.


Model for NLP

image

Deploy link :

https://chat-neuron.onrender.com/