): #This loop from https://github.com/jaimezorno/Deep-Learning-for-NLP-Creating-a-Chatbot/blob/master/Deep%20Learning%20for%20NLP-%20Creating%20a%20chatbot.ipynb if val == val_max: k = key print(k) print(pred_res[0][val_max]) #Here is where a story and question is input line by line def input_story(): story = [] for i in range(3): story.append( input("Enter Story Sentence :") ) # note: Add a space after the final period, ie. 'apple . ' question = input("What is the question?:") return ''.join(word for word in story), question story, question = input_story() my_s = [(story.split(), question.split(), 'yes')] print(my_s) the_story, the_question, the_ans = vectorize_stories(my_s) pred_res = model.predict(([the_story, the_question])) val_max = np.argmax(pred_res[0]) for key, val in t.word_index.items( ): #This loop from https://github.com/jaimezorno/Deep-Learning-for-NLP-Creating-a-Chatbot/blob/master/Deep%20Learning%20for%20NLP-%20Creating%20a%20chatbot.ipynb if val == val_max: k = key print(k) print(pred_res[0][val_max])
import numpy as np import pandas as pd from keras.preprocessing.text import Tokenizer from collections import Counter from keras.layers import Embedding, Input, LSTM, Dense, Conv1D, Conv2D, MaxPool2D, MaxPooling1D, Dropout, Activation, Reshape, Concatenate, Flatten from keras.models import Sequential, model_from_json from keras.models import Model from keras.preprocessing.sequence import pad_sequences from keras.utils import np_utils # read the input f = open("LabelledData.txt", 'r') Input = f.read() Input = Input.split("\n") Input_len = len(Input) Input_data = {} # seperating label and data InputData = {} InputLabel = {} for j in range(0, Input_len - 2): b = Input[j].split(",,, ") Input_data[j] = b InputData[j] = Input_data[j][0] InputLabel[j] = Input_data[j][1] d = InputLabel.values() tokenizerlabel = Tokenizer(num_words=20000) tokenizerlabel.fit_on_texts(d) sequenceslabel = tokenizerlabel.texts_to_sequences(d) # As the data has imbalanced classifiers