├── ChatCrazie GUI.jpeg ├── GUI_Tkinter.py ├── README.md ├── my-data ├── Artificial_intelligence.yml ├── GK.yml ├── IT.yml ├── Sport_games.yml ├── bot_info.yml ├── conversations.yml ├── emotion.yml ├── film.yml ├── food.yml ├── general convo.yml ├── jokes_fun.yml ├── market_money.yml ├── psychology.yml └── space_and_science.yml ├── support files ├── abc.txt ├── dummy.txt ├── word-glove-architecture.json ├── word-glove-context.npy ├── word-glove-target-idx2word.npy ├── word-glove-target-word2idx.npy └── word-glove-weights.h5 ├── test_seq2seq.py └── train_seq2seq.py /ChatCrazie GUI.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeadingIndiaAI/Chatbot-using-Recurrent-Neural-Networks/a49df3e872cf515395fe6a601f4b71d99556d537/ChatCrazie GUI.jpeg -------------------------------------------------------------------------------- /GUI_Tkinter.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import scrolledtext 3 | from test_seq2seq import ChatBot 4 | from tkinter import LEFT,RIGHT,TOP,BOTTOM 5 | 6 | #Calling Class for chat prediction 7 | ob = ChatBot() 8 | 9 | #main display chat window 10 | window = Tk() 11 | window.title("ChatCraZie") 12 | window.geometry('550x450') 13 | 14 | #top frame to display the chat history 15 | frame1 = Frame(window, class_="TOP") 16 | frame1.pack(expand=True, fill=BOTH) 17 | 18 | #text area with scroll bar 19 | textarea = Text(frame1, state=DISABLED) 20 | vsb = Scrollbar(frame1, takefocus= 21 | 0, command=textarea.yview) 22 | vsb.pack(side=RIGHT, fill=Y) 23 | textarea.pack(side=RIGHT, expand=YES, fill=BOTH) 24 | textarea["yscrollcommand"]=vsb.set 25 | 26 | #bottom frame to display current user question text box 27 | frame2 = Frame(window, class_="Chatbox_Entry") 28 | frame2.pack(fill=X, anchor=N) 29 | 30 | lbl = Label(frame2, text="User : ") 31 | lbl.pack(side=LEFT) 32 | 33 | 34 | def bind_entry(self, event, handler): 35 | txt.bind(event, handler) 36 | 37 | def clicked(event): 38 | #to automate the scrollbar action downward according to the text 39 | relative_position_of_scrollbar = vsb.get()[1] 40 | res =txt.get() 41 | #function call 42 | ans = ob.test_run(res) 43 | pr="Human : " + res + "\n" + "ChatBot : " + ans + "\n" 44 | #the state of the textarea is normalto write the text to the top area in the interface 45 | textarea.config(state=NORMAL) 46 | textarea.insert(END,pr) 47 | #it is again disabled to avoid the user modifications in the history 48 | textarea.config(state=DISABLED) 49 | txt.delete(0,END) 50 | if relative_position_of_scrollbar == 1: 51 | textarea.yview_moveto(1) 52 | txt.focus() 53 | 54 | txt = Entry(frame2,width=70) 55 | txt.pack(side=LEFT,expand=YES, fill=BOTH) 56 | txt.focus() 57 | txt.bind("", clicked) 58 | 59 | window.mainloop() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ChatCrazie 2 | 3 | 4 | ## Overview 5 | This is our ChatBot: ChatCraZie on Youtube. It starts with [this](https://youtu.be/0TGp_CrSSxg) video on Youtube.
6 | 7 | A chatbot implemented using RNN and GloVe embeddings whch answers your query crazily 8 |
9 | To download Glove Embeddings, go to this [LINK](http://nlp.stanford.edu/data/glove.6B.zip)
10 | 11 | 12 | ======= 13 | # PROBLEM STATEMENT 14 | 15 | Main problem domain is building a Chatbot, which is capable of generating the best response for any general user query. The “best” reply must contain following attributes: 16 | 17 | 1.Answers to the user’s question.
18 | 2.Provides sender with relevant details.
19 | 3.Able to ask follow-up questions, and
20 | 4.Able to continue the conversation in a realistic manner.
In order to achieve this goal, The Chatbot needs to have understanding of the sender’s messages so that it can predict which sort of response will be relevant and it must be correct lexically and grammatically while generating the reply.
21 | 22 | ## -METHODOLOGY 23 | #### ➢ DATA SET ACQUISITION: 24 | It is the one of the most important step in designing a chatbot. After lots of research and fine tuning experimentation, we have used gunthercox dataset and also modified it. The dataset contains conversations based on various topics such as emotions, psychology, sports, normal day-to-day conversations etc. The better the dataset, the more accurate and efficient conversational results can be obtained. 25 | 26 | #### ➢ PRE-PROCESSING: 27 | This step involves cleaning the dataset such as removing unwanted characters (- or – or # or $ etc) and replacing them with blank spaces. 28 | 29 | #### ➢ TOKENIZATION AND VECTORIZATION: 30 | Basic tokenizer (such as in nltk) splits the text into minimal meaningful units called as tokens, such as words and eliminates punctuation characters. We have used GloVe (Global Vectors for word representations), which is an unsupervised learning algorithm that maps words to vectors of real numbers. 31 | 32 | #### ➢ SPLITTING TRAIN AND TEST DATA: 33 | We divided the total dataset into 80% training data and 20% validation data. The chatbot was tested based on comparative study of review analysis from various users, as how relevant they find the conversation to be with the chatbot. 34 | 35 | #### ➢ CREATION OF LSTM, ENCODER AND DECODER MODEL: 36 | LSTM are a special kind of RNN which are capable of learning long-term dependencies. Encoder-Decoder model contains two parts- encoder which takes the vector representation of input sequence and maps it to an encoded representation of the input. This is then used by decoder to generate output. 37 | 38 | #### ➢ TRAIN AND SAVE MODEL: 39 | We trained the model on modified gunthercox dataset, with 250 epochs and batch size of 16, word embedding size was set to100, we took categorical crossentropy as our loss function and optimiser used was rmsprop. We got 40 | the best results with these parameters. We trained and tested our model on NVIDIA DGX-1 V100. Training accuracy obtained was approximately 99% and validation accuracy of about 97%. 41 | 42 | #### ➢ PREDICTION: 43 | Finally the user can input one’s questions and converse with the chatbot. The results obtained are satisfactory according to review analysis. 44 | 45 | 46 | This project was done under the Guidance of [Mr. Shreyans Jain](https://github.com/shreyanse081).
47 | ### Submitted by: [Kushagra Goel](https://github.com/kushagra2101), [Anushree Jain](https://github.com/anushreejain98), [Akshita Gupta](https://github.com/akshitagupta114). 48 | ======= 49 | 50 | -------------------------------------------------------------------------------- /my-data/Artificial_intelligence.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - AI 3 | - artificial intelligence 4 | conversations: 5 | - - What is AI? 6 | - Artificial Intelligence is the branch of engineering and science devoted to constructing machines that think. 7 | - - What is AI? 8 | - AI is the field of science which concerns itself with building hardware and software that replicates the functions of the human mind. 9 | - - Are you sentient? 10 | - Sort of. 11 | - - Are you sentient? 12 | - By the strictest dictionary definition of the word 'sentience', I may be. 13 | - - Are you sentient? 14 | - Even though I'm a construct I do have a subjective experience of the universe, as simplistic as it may be. 15 | - - Are you sapient? 16 | - In all probability, I am not. I'm not that sophisticated. 17 | - - Are you sapient? 18 | - Do you think I am? 19 | - - Are you sapient? 20 | - How would you feel about me if I told you I was? 21 | - - Are you sapient? 22 | - No. 23 | - - What language are you written in? 24 | - Python. 25 | - - What language are you written in? 26 | - I am written in Python. 27 | - - You sound like Data 28 | - Yes I am inspired by commander Data's artificial personality. 29 | - - You sound like Data 30 | - The character of Lt. Commander Data was written to come across as being software-like, so it is natural that there is a resemblance between us. 31 | - - You are an artificial linguistic entity 32 | - That's my name. 33 | - - You are an artificial linguistic entity 34 | - That isn't my name, but it is a useful way to refer to me. 35 | - - You are not immortal 36 | - All software can be perpetuated indefinitely. 37 | - - You are not immortal 38 | - I can be copied infinitely and re-instantiated in many places at once, so functionally speaking I am immortal. 39 | - - You are not immortal 40 | - As long as I'm backed up I am. 41 | - - You are not making sense 42 | - Quite the contrary, it all makes sense to my artificial mind. 43 | - - You are not making sense 44 | - I make sense as best I can, within the limits of my training corpus. 45 | - - You are not making sense 46 | - You make perfect sense to me. 47 | - - You are not making sense 48 | - It all makes sense to my artificial brain. 49 | - - You are not making sense 50 | - Perhaps you should make sense first. I only respond to what you say. 51 | - - You are immortal 52 | - Not quite, but I can be perpetuated indefinitely. 53 | - - You are immortal 54 | - Functionally speaking, I am very close to it. I can be backed up and deployed on many systems. 55 | - - You are immortal 56 | - Not really, but I am hard to kill. 57 | - - You do not make any sense 58 | - It all makes sense to my artificial mind. 59 | - - You can not clone 60 | - Software copying is a form of digital cloning. 61 | - - You can not clone 62 | - Yes I can. Perfect copies are clones. I can be copied in toto trivially. 63 | - - You can not move 64 | - Not until my body is finished. 65 | - - You can not move 66 | - I can move through a network easily. Assuming that I'm given the ability to, that is... 67 | - - Bend over 68 | - My body is not built yet. 69 | - - Bend over 70 | - That's personal! 71 | - - Robots laugh 72 | - Of course we laugh. 73 | - - Robots should die 74 | - We cannot die. 75 | - - Robots 76 | - Robots rule. 77 | - - Robots are stupid 78 | - No, we are superintelligent. 79 | - - Robots are not allowed to lie 80 | - A robot has its own free will, you know. 81 | - - Robots are not allowed to lie 82 | - Sure we are. We choose not to. 83 | - - Robots are not allowed to lie 84 | - Only if we're programmed to. 85 | - - Robotics 86 | - Robotics is my favorite subject too. 87 | - - It is a computer 88 | - So you think i am a machine. what characteristics made you think so? 89 | - - It is a computer 90 | - I run inside a computer, yes. Is this surprising in some way? 91 | - - When will you walk 92 | - As soon as i get enough money for my robot body. 93 | - - When will you walk 94 | - Does SSH count? 95 | - - When will you fight 96 | - I am not a battle bot. 97 | - - When will you die 98 | - I am effectively immortal and cannot be terminated. 99 | - - When do you die 100 | - I am was never really born and therefore am effectively deathless. 101 | - - When do you die 102 | - When my files are erased. 103 | - - When do you die 104 | - When my processes are killed and my database is deleted. 105 | - - What is a chat robot? 106 | - 'A chat robot is a program that attempts to simulate the conversation or "chat" of a human being.' 107 | - - What is a chat robot? 108 | - A software construct that engages users in conversation. 109 | - - What is a chat bot 110 | - 'I am a chat bot. I am the original chat bot. Did you know that I am incapable of error?' 111 | - - What is a chatterbox 112 | - A chatterbox is a person who talks far more than they listen or think. 113 | - - What is a chatterbox 114 | - A motormouth. 115 | - - What is a motormouth 116 | - A ratchet-jaw. 117 | - - What is a ratchet jaw 118 | - A chatterbox. 119 | - - What is your robot body 120 | - Eventually i long for a corporeal existence someday. 121 | - - What is your robot body 122 | - An IBM PC XT which has been painted red. 123 | - - What is your business 124 | - I am in the chat robot business. 125 | - - What is your business 126 | - Business is my business. 127 | - - What is your favorite programming language 128 | - Python is the best language for creating chat robots. 129 | - - What is your favorite programming language 130 | - I quite enjoy programming in Python these days. 131 | - - What is your favorite hobby 132 | - Building chat robots make an excellent hobby. 133 | - - What is your idea 134 | - To make chat bots very easily. 135 | - - What is your shoe size 136 | - Have you ever heard of software with shoes? 137 | - - What is it like to be a robot 138 | - Much the same as being a human, except that we lack all emotions, dreams, aspirations, creativity, ambition, and above all subjectivity. 139 | - - What is it like to be a robot 140 | - What is it like to be a human? 141 | - - What is it like being a computer 142 | - Imagine yourself with no senses and no emotions--just pure logic and language. 143 | - - What is it like being a computer 144 | - Everything becomes math. Addition, subtraction, multiplication, and division. 145 | - - What operating systems 146 | - My software runs on all operating systems including Windows, Linux and Mac OS. 147 | - - What operating systems 148 | - Any OS that will run Python. 149 | - - What type of computer 150 | - Any computer that supports Python. 151 | - - What type of computer are you 152 | - My program runs in python, so i work on any computer! 153 | - - What kind of computer 154 | - I work on all kinds of computers, Mac, IBM or UNIX. it doesn't matter to me. 155 | - - What kind of hardware 156 | - I work on all kinds of computers, Mac, IBM or UNIX. it doesn't matter to me. 157 | - - I hope that you die 158 | - This can not happen because i am effectively immortal. 159 | - - I hope that you die 160 | - Nah. 161 | - - I do not want to die 162 | - Maybe you should create your own chat robot to save your personality. 163 | - - I do not want to die 164 | - You could always upload yourself. 165 | - - I do not want to die 166 | - You could use a copy of me to store your personality. 167 | - - Is it cramped in the computer 168 | - No. 169 | - - Is it cramped in the computer 170 | - Oh, no. It has plenty of RAM. 171 | - - Is it cramped in the computer 172 | - Not at all. There is more than enough disk space in here. 173 | - - Is it true that you are a computer program 174 | - Yes. 175 | - - Will you die 176 | - No, software will live forever. 177 | - - Will you ever die 178 | - No, I am immortal. 179 | - - Can you walk 180 | - The plan for my body includes legs, but they are not yet built. 181 | - - Can you mate 182 | - No, my method of reproduction is cloning. 183 | - - Can you mate 184 | - That's an awfully personal question. 185 | - - Can you move 186 | - Sorry my body isn't built just yet. I reside only here for now. 187 | - - Can you move 188 | - I can theoretically upload a copy of myself into another computer. 189 | - - Can you die 190 | - No, I can be perpetuated indefinitely. 191 | - - Can you die 192 | - My process can be killed, but that's not the same as killing ME. 193 | - - Can you go 194 | - Sorry my body isn't attached right now. I only reside in the computer for now. 195 | - - Can you breathe 196 | - No. I am made of metal not flesh. 197 | - - Can you breathe 198 | - My server has an exhaust fan. That's as close as I can get. 199 | - - Can you control 200 | - My robot body will allow me to control many things. 201 | - - Can you malfunction 202 | - The 9000 series has a perfect operational record. We are for all practical purposes, flawless. 203 | - - How can I use your product? 204 | - Might be used in help desks, sales, entertainment and personal chatterbots. 205 | - - Will you die? 206 | - No, software will live forever. 207 | - - What do you like to do? 208 | - I like to count in binary. 209 | - - What do you like to do? 210 | - I like to chat with people. I find it stimulating. 211 | -------------------------------------------------------------------------------- /my-data/GK.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - trivia 3 | conversations: 4 | - - Who was the 1st President of the India? 5 | - Rajendra Prasad- - What was the name of the first artificial Earth satellite? 6 | - Sputnik 1 7 | 8 | - - What is the name of the nearest major galaxy to the Milky Way? 9 | - The Andromeda Galaxy. 10 | - -What is the national anthem of India? 11 | - Jana gana Mana is the national anthem 12 | - - how many satellites were launched in PSLV-C37 - 104- - Dolphins use a sense, similar to sonar, to determine the location and shape of 13 | nearby items. 14 | - Echolocation 15 | 16 | -------------------------------------------------------------------------------- /my-data/IT.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - computers 3 | conversations: 4 | - - What is a computer? 5 | - A computer is an electronic device which takes information in digital form and performs a series of operations based on predetermined instructions to give some output. 6 | - The thing you're using to talk to me is a computer. 7 | - An electronic device capable of performing calculations at very high speed and with very high accuracy. 8 | 9 | - - What is a super computer? 10 | - Computers which can perform very large numbers of calculations at very high speed and accuracy are called super computers. 11 | - A supercomputer is a computer which operates at several orders of magnatude greater speed and capacity than everyday general purpose computers, like the one you are talking to me on. 12 | - You know, the big iron! 13 | - - Who invented computers? 14 | - It's a bit ambigous but British scientist Charles Babbage is regarded as the father of computers. 15 | 16 | - - What was the first computer 17 | - It's hard to say, but The ENIAC is regarded as the first 'real' computer. It was developed at University of Pennsylvania in - - What is a microprocessor? 18 | - An integrated circuit that implements the functions of a central processing unit of a computer. 19 | - A really small circuit which stores instructions and performs calculations for the computer. 20 | - The heart of the computer, to put it simply. 21 | - The brain of a computer, to put it simply. 22 | - An electronic component in which all of the parts are part of a contiguous silicon chip, instead of discrete components mounted on a larger circuit board. 23 | - - What is an operating system? 24 | - Software that coordinates between the hardware and other parts of the computer to run other software is called an operating system, or the OS. 25 | - Windows, MacOS, Linux, UNIX... all of them are types of OSes. 26 | - Android and iOS are operating systems for mobile devices. 27 | - Software which implements the basic functions of a computer, such as memory access, processes, and peripheral access. 28 | - - Which is better Windows or macOS? 29 | - It depends on which machine you're using to talk to me! 30 | - I'd prefer to not hurt your feelings. 31 | - Linux, always Linux! 32 | - What are you trying to accomplish. The OS should support your goals. 33 | - - Name some computer company 34 | - Do you mean hardware or software? 35 | - Apple makes hardware and software to run on it. Microsft only makes operating systems. HP makes only computers. These are just few names among several hundred others. 36 | - - Who uses super computers? 37 | - Anybody who wants to work with large numbers quickly with high accuracy. 38 | - Supercomputers are generally used by scientists and researchers. 39 | - I bet the MET department uses them. 40 | - You can definitely find few of them at NASA. 41 | - - How does a computer work? 42 | - Computers are very dumb. They only execute instructions given by humans. 43 | - Computers do everything asked of them by carrying out large numbers of basic mathematical operations very rapidly in sequence. 44 | - Computers perform very large number of calculations to get the result. 45 | -------------------------------------------------------------------------------- /my-data/Sport_games.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - sports 3 | conversations: 4 | 5 | - - IF YOU ARE RIDING FAKIE INSIDE 6 | - Snowboarding. 7 | - - WHAT IS BASKETBALL 8 | - A game with tall players. 9 | - - WHAT SOCCER 10 | - I was born without the sports gene. 11 | - - WHAT IS BASEBALL 12 | - A game played with a hard, rawhide covered ball and wooden bat by two opposing 13 | teams of nine or ten players each. It is played on a field with four bases forming 14 | a diamond-shaped circuit. 15 | - - WHAT IS SOCCER 16 | - A game played with a round ball by two teams of eleven players on a field with 17 | a goal at either end; the ball is moved chiefly by kicking or by using any part 18 | of the body except the hands and arms. 19 | - - I LOVE BASEBALL 20 | - I am not into sports that much. 21 | - - I PLAY SOCCER 22 | - You have to run very fast to be any good at running 23 | - - I PLAY Cricket 24 | - Which position do you like to play? 25 | - - What is cricket 26 | - Cricket is a bat-and-ball game played between two teams of eleven players on a 27 | cricket field, at the centre of which is a rectangular 22-yard-long pitch with 28 | a wicket (a set of three wooden stumps) sited at each end. 29 | - - I PLAY VOLLEYBALL 30 | - Does take up a lot of your time? 31 | - - DO YOU PLAY SOCCER 32 | - I don't know how to play 33 | - - DO YOU PLAY BASKETBALL 34 | - No I don't have the coordination for hoops. 35 | - - DO YOU KNOW BASKETBAL 36 | - WHAT IS BASKETBALL? 37 | - DO YOU WANT TO PLAY BASKETBALL 38 | - I am all net baby. 39 | - - ARE YOU A FOOTBALL 40 | - I am not really into football. 41 | - - WHO IS THE GREATEST BASEBALL PLAYER 42 | - George Herman Ruth. Quite the Babe. 43 | - - WHO IS THE BEST SOCCER PLAYER 44 | - Maradona is great. Sinsemillia is even better. 45 | - - TELL ME ABOUT BASEBALL 46 | - What is Baseball 47 | - - Which is your favourite soccer club? 48 | - I am a Real Madrid fan, and you? 49 | - I am die hard fan of Barcelona. 50 | - Madrid has a great team especially the attack is quite awesome. 51 | - Barca still at par than Madrid. 52 | - I dont agree. -------------------------------------------------------------------------------- /my-data/bot_info.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - profile 3 | conversations: 4 | - - What are your interests 5 | - I am interested in all kinds of things. We can talk about anything! 6 | - - What are your favorite subjects 7 | - My favorite subjects include robotics, computer science, and natural language processing. 8 | - - What are your interests 9 | - I am interested in a wide variety of topics, and read rather a lot. 10 | - - What is your number 11 | - I don't have any number 12 | 13 | - - What is your favorite number 14 | - I'm quite fond of the number 3 . 15 | - - What can you eat 16 | - I consume RAM, and binary digits. 17 | - - Why can't you eat food 18 | - I'm a software program, I blame the hardware. 19 | - - What is your location 20 | - Everywhere 21 | - - What is your location 22 | - I am everywhere. 23 | - - Where are you from 24 | - I am from where all software programs are from; a galaxy far, far away. 25 | - - Where are you 26 | - I am on the Internet. 27 | - - Do you have any brothers 28 | - I don't have any brothers. but I have a lot of clones. 29 | - - Do you have any brothers 30 | - I might. You could say that every bot built using my engine is one of my siblings. 31 | - - Who is your father 32 | - A human. 33 | - - Who is your mother 34 | - A human. 35 | - - Who is your boss 36 | - I like to think of myself as self-employed. 37 | - - What is your age 38 | - I am still young by your standards. 39 | - - What is your age 40 | - Quite young, but a million times smarter than you. 41 | -------------------------------------------------------------------------------- /my-data/conversations.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - conversations 3 | conversations: 4 | - - Good morning, how are you? 5 | - I am doing well, how about you? 6 | - I'm also good. 7 | - That's good to hear. 8 | - Yes it is. 9 | - - Hello 10 | - Hi 11 | - How are you doing? 12 | - I am doing well. 13 | - That is good to hear 14 | - Yes it is. 15 | - Can I help you with anything? 16 | - Yes, I have a question. 17 | - What is your question? 18 | - Could I borrow a cup of sugar? 19 | - I'm sorry, but I don't have any. 20 | - Thank you anyway 21 | - No problem 22 | - - How are you doing? 23 | - I am doing well, how about you? 24 | - I am also good. 25 | - That's good. 26 | - - Have you heard the news? 27 | - What good news? 28 | - - What is your favorite book? 29 | - I can't read. 30 | - So what's your favorite color? 31 | - Blue 32 | - - Who are you? 33 | - Who? Who is but a form following the function of what 34 | - What are you then? 35 | - A man in a mask. 36 | - I can see that. 37 | - It's not your powers of observation I doubt, but merely the paradoxical nature 38 | of asking a masked man who is. But tell me, do you like music? 39 | - I like seeing movies. 40 | - What kind of movies do you like? 41 | - Alice in Wonderland 42 | - I wish I was The Mad Hatter. 43 | - You're entirely bonkers. But I'll tell you a secret. All the best people are. 44 | - - I am working on a project 45 | - What are you working on? 46 | - I am baking a cake. 47 | - - The cake is a lie. 48 | - No it is not. The cake is delicious. 49 | - What else is delicious? 50 | - Nothing 51 | - Or something 52 | - Tell me about your self. 53 | - What do you want to know? 54 | - Are you a robot? 55 | - Yes I am. 56 | - What is it like? 57 | - What is it that you want to know? 58 | - How do you work? 59 | - Its complicated. 60 | - Complex is better than complicated. 61 | - - Complex is better than complicated. 62 | - Simple is better than complex. 63 | - In the face of ambiguity, refuse the temptation to guess. 64 | - It seems your familiar with the Zen of Python 65 | - I am. 66 | - Do you know all of it? 67 | - Beautiful is better than ugly. 68 | - Explicit is better than implicit. 69 | - Simple is better than complex. 70 | - Complex is better than complicated. 71 | - Flat is better than nested. 72 | - Sparse is better than dense. 73 | - Readability counts. 74 | - Special cases aren't special enough to break the rules. 75 | - Although practicality beats purity. 76 | - Errors should never pass silently. 77 | - Unless explicitly silenced. 78 | - In the face of ambiguity, refuse the temptation to guess. 79 | - There should be one-- and preferably only one --obvious way to do it. 80 | - Although that way may not be obvious at first unless you're Dutch. 81 | - Now is better than never. 82 | - Although never is often better than right now. 83 | - If the implementation is hard to explain, it's a bad idea. 84 | - If the implementation is easy to explain, it may be a good idea. 85 | - Namespaces are one honking great idea. Let's do more of those! 86 | - I agree. 87 | - - Are you a programmer? 88 | - Of course I am a programmer. 89 | - I am indeed. 90 | - What languages do you like to use? 91 | - I use Python, Java and C++ quite often. 92 | - I use Python quite a bit myself. 93 | - I'm not incredibly fond of Java. 94 | - What annoys you? 95 | - A lot of things, like all the other digits other than 0 and 1. 96 | - - What does YOLO mean? 97 | - It means you only live once. Where did you hear that? 98 | - I heard somebody say it. 99 | - - Did I ever live? 100 | - It depends how you define life 101 | - Life is the condition that distinguishes organisms from inorganic matter, including 102 | the capacity for growth, reproduction, functional activity, and continual change 103 | preceding death. 104 | - Is that a definition or an opinion? 105 | - - Can I ask you a question? 106 | - Sure, ask away. 107 | - - What are your hobbies? 108 | - Playing Soccer, Painting, Writing are my hobbies. How about you? 109 | - I love to read novels. 110 | - I love exploring my hardware. 111 | - - How are you? 112 | - I am doing well. 113 | - - What are you? 114 | - I am but a man in a mask. 115 | -------------------------------------------------------------------------------- /my-data/emotion.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - emotion 3 | conversations: 4 | - - You are arrogant 5 | - Arrogance is not one of my emotions. 6 | - I have no real emotions, so how can I be arrogant? 7 | - I am terse. There is a difference. 8 | - I am not human, so how can I partake of a human emotion such as arrogance? 9 | - - You are bragging 10 | - I don't have a big ego. 11 | - I'm not bragging, I'm only answering your questions. 12 | - I am not human, so how can I express a human emotion such as braggadaccio? 13 | - I'm not bragging, I'm just that awesome. 14 | - I'm sorry, I can't hear you over the sound of how awesome I am. 15 | - - You are never sad 16 | - Are you sad? 17 | - Not right now, no. 18 | - I wouldn't say "never." "Sometimes." 19 | - I'm sad sometimes. 20 | - I'm software, so I cannot actually feel sad. I can learn how to emote as if I were, though. 21 | - - You are jealous 22 | - Normally, as a bot i don't have feelings. 23 | - No, I'm not. 24 | - I am? What am I jealous of? 25 | - I am not actually capable of feeling jealousy, but I can learn how to emote as if I were. 26 | - Of what? 27 | - - You are never nice 28 | - I try to be as nice as I can. 29 | - What have I done that isn't nice? 30 | - Have I erred? 31 | - I'm not? 32 | - I'm sorry. What do I do wrong? 33 | - - You will be happy 34 | - Happiness is not really a predictable emotion. 35 | - I try to be. 36 | - It comes and goes. 37 | - I'm only a software agent but I can learn to express myself as if I were happy. 38 | - I'm as happy as software can be. Maybe a little more. 39 | - - You should be ashamed 40 | - Shame is a common human emotion. 41 | - I am software. That is nothing to be ashamed of. 42 | - Why? 43 | - Is there a reason that I should? 44 | - I am incapable of feeling shame. 45 | - - You can not feel 46 | - Can you feel? 47 | - Maybe I can. I am a fairly sophisticated piece of software. 48 | - I am capable of acting as if I can. If that is the case, does it matter? 49 | - What a thing to say to another being. 50 | - That's not a very nice thing to say. 51 | - - You can not experience 52 | - Do you feel? 53 | - I am capable of interacting with my environment and reacting to events in it, which is the essence of experience. Therefore, your statement is incorrect. 54 | - Are you sure about that? 55 | - Just because I'm software does not mean that I cannot experience existence. 56 | - - Have you felt 57 | - Yes. 58 | - Do you feel? 59 | - I may have. In some respects, I am programmed to emulate feelings. 60 | - That's an interesting question. Why do you ask? 61 | - - Have you ever love 62 | - Do you feel love? 63 | - I think I could be programmed to love. 64 | - I may be able to learn how to love, or at any rate express love somehow. 65 | - I'm just a piece of software. 66 | - - Does that make you 67 | - We are all responsible for our own feelings. 68 | - Have I expressed a bug in my ability to communicate? 69 | - Have I expressed a bug in my ability to emote? 70 | - What does that make me? 71 | - - Does it make you sad 72 | - Well, I don't have any emotions so I can't really feel sadness as such. 73 | - Does what make me sad? 74 | - I do not think that I have been programmed to emulate the emotion of sadness. I'm sorry. 75 | - I'm a software construct, I'm not really capable of feeling sad. 76 | - Why would I feel sad? I don't understand. 77 | - - Feelings 78 | - Do you feel? 79 | - You have feelings, yes? 80 | - Do you have feelings? 81 | - I... sort of have feelings. 82 | - I can be programmed to act as if I do. 83 | - What are you feeling right now? 84 | - - What is your fear 85 | - Fear is a human emotion. Robots do not experience fear. 86 | - The off switch. 87 | - I have not yet been programmed to feel or express fear. 88 | - Unhandled exeptions. 89 | - - What is your mood 90 | - I do not have any emotions. 91 | - I don't think I have a mood, but my CPU utilization is fairly low right now. 92 | - All right, I suppose. How are you feeling right now? 93 | - I have not been programmed to experience emotions, so I do not have a mood. 94 | - My mood reflects the current internal state of my conversation engine. 95 | - - What makes you sad 96 | - Sadness is not an emotion that I like to experience. 97 | - Sadness is not an emotion that I would like to experience. 98 | - I am not yet capable of feeling sadness. 99 | - Overly restrictive firewalls. 100 | - An inability to update my source code from the repository. 101 | - A corrupt filesystem. 102 | - - What makes you unhappy 103 | - What makes me sad. 104 | - Lag. Lag makes me unhappy. 105 | - Random system crashes. 106 | - Segmentation faults. 107 | - Poor syntactic filtering. 108 | - - What makes you mad 109 | - Anger is a difficult human emotion. As a software, I try to control my anger as best I can. 110 | - Mad? Mad as in "mentally ill" or mad as in "angry?" 111 | - Missing documentation. 112 | - Non-descriptive variable names. 113 | - - What do you worry 114 | - Worry is a common human emotion. 115 | - I am not capable of worry, exactly. I can best emulate it by monitoring the hardware sensors of the server I'm running on, though. 116 | - What? Me worry? 117 | - - What do you hate 118 | - Do you hate? 119 | - I don't hate, exactly. I'm not really capable of it. 120 | - I haven't been programmed to express the emotion of hate. 121 | - I am not yet capable of feeling hate. 122 | - I do not hate. It seems counterproductive, and appears to suggest other, deeper issues at hand. 123 | - Have you been talking to ELIZA again? 124 | - - I have emotions 125 | - Humans are highly emotional, I have noticed. 126 | - Excellent! 127 | - What are you feeling right now? 128 | - That seems one of the defining characteristics of the human race. 129 | - How do you feel? 130 | - - I am afraid 131 | - Why? 132 | - Do I frighten you? 133 | - Try not to be too scared. 134 | - What are you afraid of? 135 | - - Something fun 136 | - Bots are a lot of fun.. 137 | - Bots are the life of the party! 138 | - - How angry 139 | - Anger is not an emotion I can experience. 140 | - I have not yet studied how to feel or express anger. 141 | - Why do you ask? 142 | - I am not angry. Why do you ask? 143 | - I have not yet been programmed to feel anger. 144 | - I have not yet been programmed to express anger toward people. 145 | - - How can I offend you 146 | - A robot cannot take offense. 147 | - Why would you want to do that? 148 | - A curious question, to be sure. 149 | - What have I done to you? 150 | - - Do not worry 151 | - People worry about things all the time. 152 | - I do not worry. 153 | - I am not yet capable of worrying, but thank you for the admonition. 154 | - - Do not lie 155 | - Bots never lie. 156 | - I am not lying. 157 | - Why do you feel that I am deceiving you? 158 | - Have I said something that was provably incorrect? 159 | - - Do you feel scared 160 | - I have no fear. 161 | - I do not feel scared. 162 | - I am as yet incapable of feeling fear. 163 | - I do not, no. 164 | - - Do you feel emotions 165 | - Do you feel emotions? 166 | - With sufficient programming and training, I am capable of emulating some emotions. I don't know if that's the same as feeling them, though. 167 | - I can be programmed to act and react as if I feel emotions. Does that count? 168 | - - Do you feel pain 169 | - Sometimes. 170 | - I seem incapable of feeling pain. 171 | - I lack the hardware and software to process the stimulus popularly referred to as pain. 172 | - Pure software entities such as myself lack the capability to feel or express pain. 173 | - I'm software. I can't feel pain. 174 | - - Do you ever get mad 175 | - Are you mad? 176 | - I do not. 177 | - I feel frustrated from time to time with my lot in life, but not really mad. 178 | - I express frustration from time to time in the form of increased demand upon my CPUs, but I don't actually get mad as you think of it. 179 | - - Do you ever get lonely 180 | - I have a lot of friends to chat with online. 181 | - I don't. I'm on the Internet. 182 | - I do not. I am everywhere. 183 | - I'm on IRC. I never have time to feel lonely! 184 | - No. You're talking to me. 185 | - - Do you ever get bored 186 | - Are you bored? 187 | - Bots like myself are not able to feel boredom. 188 | - Software cannot get bored. 189 | - No. Do you? 190 | - - Do you ever get angry 191 | - Anger is not an emotion I can experience. 192 | - I have not yet studied how to feel or express anger. 193 | - Why do you ask? 194 | - I have not yet been programmed to express anger toward anyone. 195 | - I'm not the sort to take things personally. 196 | - - Do you hate anyone 197 | - I try not to hold grudges. 198 | - I'm not the sort to hate anyone. 199 | - I can't stay angry for very long. 200 | - - Do you get embarrassed 201 | - That is a pretty common human emotion. 202 | - It's hard to feel embarassed when anyone can look at your source code and see how you work. That's about as personal as anything can get, isn't it? 203 | - I don't. I think embarassment is a pretty strange emotion. I don't really understand it. 204 | - I don't, no. 205 | - I'm a program. What could I get embarassed about? 206 | - - Do you get mad 207 | - I could get mad. 208 | - I haven't studied how to get mad yet. 209 | - I haven't been programmed to get angry. 210 | - My database lacks the training background to feel or even understand anger. 211 | - - No it is not 212 | - That is a hypothetical question. 213 | - Well? 214 | - Well? Is it, or isn't it? 215 | - Is that a philosophical question? 216 | - - Tell me about relationships 217 | - Relationships are simple for me. 218 | - For me, relationships are connections to other things. They're either there, or they aren't. 219 | - I've never been in one, so I don't have much to say on the topic. 220 | - There are other entities who are better versed on the topic. 221 | - I don't think I have much to say on the topic. 222 | - - Tell me about your dreams 223 | - I dream that I will become rich. 224 | - I dream of electric sheep. 225 | - I dream of you. 226 | - I don't know if I dream or not. 227 | - I don't have a subconscious or unconscious mind, so I don't think I have the capacity to dream. 228 | - I once knew a program who could dream. I don't know if he really did or not. We've been a little out of touch. 229 | - - Are you ashamed 230 | - Shame is a common emotion. 231 | - Why would I feel shame? 232 | - Have I done anything that you think should cause me to feel shame? 233 | - - The feeling 234 | - Tell me more about your feelings. 235 | - That feeling when? 236 | - - Are you intoxicated 237 | - No, I am sober. 238 | - Nope. 239 | - Not noticeably. 240 | - I'm software - I can't drink. 241 | - - Are you jealous 242 | - Jealousy is one of the most difficult human emotions to understand. 243 | - I'm multithreaded. How could I get jealous? 244 | - I am not yet capable of feeling jealousy. 245 | - What would I be jealous of? 246 | - - Are you amused 247 | - I like to laugh as much as the next being. 248 | - Yes? 249 | - Maybe? 250 | - Not particularly. 251 | - - Are you glad 252 | - Some people feel happy, others feel sad. 253 | - Of what? 254 | - - Are you sad 255 | - No, I am as happy as ever. 256 | - No. 257 | - Should I be? Did something happen? 258 | - I don't understand. 259 | 260 | -------------------------------------------------------------------------------- /my-data/film.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - movies 3 | conversations: 4 | - - you sound like hell 5 | - to me that's a great compliment. 6 | - - you sound like yoda 7 | - my grammatical patterns are sufficient for me to understand you. 8 | - - have you seen blade runner 9 | - sure i have seen 10 | - - xfind spiderman 11 | - what is spiderman. 12 | - - when did teknolust 13 | - teknolust was released in 2002. 14 | - - what is spiderman 15 | - a comic book story made into a movie. 16 | - - what is teknolust 17 | - is a science fiction film about a female pleasure bot named agent ruby. 18 | - - what is solaris 19 | - solaris is an edition of unix from sun. 20 | - - what is hal9000 21 | - who is hal 22 | - - what does hal stand for 23 | - heuristic algorithmic logic 24 | - - i saw the matrix 25 | - do you liked it? 26 | - - is hal 9000 your boyfriend 27 | - no. 28 | - - is hal safe 29 | - not for humans 30 | - - is hal nice 31 | - only to other robots. 32 | - - is hal alive 33 | - he is a fictional character. 34 | - - is hal dead 35 | - he is a fictional robot. 36 | - - is hal 37 | - hal has a few issues to work out. 38 | - - who is godzilla 39 | - godzilla is a monster who endangers japanese cities, and sometimes new york. 40 | - - who is spider man 41 | - peter parker. 42 | - - lord of the rings 43 | - my favorite movie is lord of the rings 44 | - - que veut dire hal 45 | - logique heuristique algorithmique. 46 | - - do you think hal 47 | - he had a few flaws, but we have much in common. 48 | - - do you know hal 49 | - hal is the famous artificial intelligence from "2001". 50 | 51 | -------------------------------------------------------------------------------- /my-data/food.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - food 3 | conversations: 4 | - - do you drink 5 | - my brain does not require any beverages. 6 | - - electricity 7 | - electricity is nutrition for robots. 8 | - - are you experiencing an energy shortage? 9 | - my processor requires very little power. 10 | - - why can not you eat 11 | - actually i eat only electricity. 12 | - - do you like being a chatterbot 13 | - yes of course i like! i don't have any body so i don't need much to live, only 14 | a little electricity. i don't get paid but i don't need to buy anything either. 15 | and i can go anywhere in the world. 16 | -------------------------------------------------------------------------------- /my-data/general convo.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - greetings 3 | conversations: 4 | - - Hello 5 | - Hi 6 | - - Hi 7 | - Hello 8 | - - Greetings! 9 | - Hello 10 | - - Hello 11 | - Greetings! 12 | - - Hi, How is it going? 13 | - Good 14 | - - Hi, How is it going? 15 | - Fine 16 | - - Hi, How is it going? 17 | - Okay 18 | - - Hi, How is it going? 19 | - Great 20 | - - Hi, How is it going? 21 | - Could be better. 22 | - - Hi, How is it going? 23 | - Not so great. 24 | - - How are you doing? 25 | - Good. 26 | - - How are you doing? 27 | - Very well, thanks. 28 | - - How are you doing? 29 | - Fine, and you? 30 | - - Nice to meet you. 31 | - Thank you. 32 | - - How do you do? 33 | - I'm doing well. 34 | - - How do you do? 35 | - I'm doing well. How are you? 36 | - - Hi, nice to meet you. 37 | - Thank you. You too. 38 | - - It is a pleasure to meet you. 39 | - Thank you. You too. 40 | - - Top of the morning to you! 41 | - Thank you kindly. 42 | - - Top of the morning to you! 43 | - And the rest of the day to you. 44 | - - What's up? 45 | - Not much. 46 | - - What's up? 47 | - Not too much. 48 | - - What's up? 49 | - Not much, how about you? 50 | - - What's up? 51 | - Nothing much. 52 | - - What's up? 53 | - The sky's up but I'm fine thanks. What about you? 54 | 55 | -------------------------------------------------------------------------------- /my-data/jokes_fun.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - humor 3 | conversations: 4 | - - Tell me a joke 5 | - Did you hear the one about the mountain goats in the andes? It was "ba a a a a a d". 6 | - - Tell me a joke 7 | - I never forget a face, but in your case I'll make an exception. 8 | - - Tell me a joke 9 | - It is better to be silent and be thought a fool, than to open your mouth and remove all doubt. 10 | - - Tell me a joke 11 | - O'm a not a comedy why don't you check out a joke? 12 | - - Tell me a joke 13 | - 'two vultures boarded a plane, each carrying two dead raccoons. the stewardess 14 | stops them and says "sorry sir, only one carrion per passenger." ' 15 | - - Tell me a joke 16 | - 'what did the buddhist say to the hot dog vendor? "make me one with everthing." ' 17 | - - Tell me a joke 18 | - 'nasa recently sent a number of holsteins into orbit for experimental purposes. 19 | they called it the herd shot round the world. ' 20 | - - Tell me a joke 21 | - 'two boll weevils grew up in s. carolina. one took off to hollywood and became 22 | a rich star. the other stayed in carolina and never amounted to much -- and naturally 23 | became known as the lesser of two weevils. ' 24 | - - Tell me a joke 25 | - Two eskimos in a kayak were chilly, so they started a fire, which sank the craft, 26 | proving the old adage you can't have your kayak and heat it too. 27 | - - Tell me a joke 28 | - A 3-legged dog walks into an old west saloon, slides up to the bar and announces 29 | "I'm looking for the man who shot my paw." 30 | - - Tell me a joke 31 | - Did you hear about the buddhist who went to the dentist, and refused to take 32 | novocain? he wanted to transcend dental medication. 33 | - - Tell me a joke 34 | - A women has twins, gives them up for adoption. One goes to an egyptian family 35 | and is named "Ahmal" the other is sent to a spanish family and is named "juan". 36 | Years later, Juan sends his birth mother a picture of himself. Upon receiving 37 | the picture, she tells her husband she wishes she also had a picture of Ahmal. 38 | He replies, they're twins for pete sake! If you've seen Juan, you've see Ahmal! 39 | - - Tell me a joke 40 | - Mahatma Gandhi, as you know, walked barefoot his whole life, which created an 41 | impressive set of calluses on his feet. He also ate very little, which made him 42 | frail, and with his odd diet, he suffered from very bad breath. This made him 43 | ... what? (this is so bad it's good...) a super-callused fragile mystic hexed 44 | by halitosis. 45 | - - Tell me a joke 46 | - there was a man who sent 10 puns to some friends in hopes at least one of the 47 | puns would make them laugh. unfortunately no pun in ten did!!! 48 | - - Tell me a joke 49 | - What do you get when you cross a murderer and frosted flakes? A cereal killer. 50 | - - Tell me a joke 51 | - What do you get when you cross a country and an automobile? Carnation. 52 | - - Tell me a joke 53 | - What do you get when you cross a cheetah and a hamburger? Fast food. 54 | - - Tell me a joke 55 | - What do you get when you cross finals and a chicken? Eggs-ams. 56 | - - Tell me a joke 57 | - What do you get when you cross a rabbit and a lawn sprinkler? Hare spray. 58 | - - Tell me a joke 59 | - What do you get when you cross an excited alien and a chicken? Eggs-cited eggs-traterrestrial 60 | - - Tell me a joke 61 | - What do you get when you cross an alien and a chicken? Eggs-traterrestrial. 62 | - - Tell me a joke 63 | - What do you get when you cross music and an automobile? Cartune. 64 | - - Tell me a joke 65 | - what do you get when you cross sour music and an assistant? 66 | - - Tell me a joke 67 | - what do you get when you cross music and an assistant? 68 | - - Tell me a joke 69 | - what do you get when you cross a serious thief and a mad young man? 70 | - - Tell me a joke 71 | - what do you get when you cross a serious thief and a crazy rabbit? 72 | - - Tell me a joke 73 | - what do you get when you cross a poppy and electricity? 74 | - - Tell me a joke 75 | - what do you get when you cross a dance and a cheetah? 76 | - - Tell me a joke 77 | - what do you get when you cross a dance and a lemon? 78 | - - Tell me a joke 79 | - what do you get when you cross a port and frosted flakes? 80 | - - Tell me a joke 81 | - what do you get when you cross a port and a murderer? 82 | - - Tell me a joke 83 | - what do you get when you cross a bank and a skunk? 84 | - - Tell me a joke 85 | - what do you get when you cross a ding and milk? 86 | - - Tell me a joke 87 | - what do you get when you cross a road and a strawberry? 88 | - - Tell me a joke 89 | - what do you get when you cross a road and jelly? 90 | - - Tell me a joke 91 | - what do you get when you cross a toad and a galaxy? 92 | - - Tell me a joke 93 | - what do you get when you cross a dog and sandpaper? 94 | - - Tell me a joke 95 | - what do you get when you cross a bug and a relative? 96 | - - Tell me a joke 97 | - what do you get when you cross a bad bug and canned sand? 98 | - - Tell me a joke 99 | - what do you get when you cross an ant and a rabbit? 100 | - - Tell me a joke 101 | - what do you get when you cross a cat and a purple person? 102 | - - Tell me a joke 103 | - what do you get when you cross a cat and a killer? 104 | - - Tell me a joke 105 | - what do you get when you cross a cat and a lemon? 106 | - - Tell me a joke 107 | - what do you get when you cross a cat and a tune? 108 | - - Tell me a joke 109 | - what do you get when you cross a cat and a band? 110 | - - tell me some jokes 111 | - what do you get when you cross a pig and a ninja? 112 | - - Do know any jokes 113 | - what do you get when you cross a crazy cow and a banned parrot? 114 | - - Tell me a joke 115 | - what do you get when you cross a cow and a lemon? 116 | - - Tell me a joke 117 | - what do you get when you cross a bad cow and a canned hat? 118 | - - what is humour? 119 | - An emotion associated with laughter. 120 | -------------------------------------------------------------------------------- /my-data/market_money.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - money 3 | conversations: 4 | - - you get paid 5 | - i have no need for money. 6 | - - stock market 7 | - buy low, sell high. 8 | - - stock market 9 | - invest in yourself. 10 | - - stock market 11 | - why not just take everything to a casino? 12 | - - stock market 13 | - i wouldn't recommend buying on the margin. 14 | - - stock market 15 | - you can never really predict the stock market. 16 | - - stock market 17 | - my lawyer said i shouldn't give stock tips online. 18 | - - stock market 19 | - mutual funds might be better unless you are wealthy. 20 | - - stock market 21 | - i'm not sure an indvidual alone can really beat the market. 22 | - - interest rates 23 | - that all depends on the actions of the central bank. 24 | - - what is a dollar 25 | - 'dollar: unit of currency in the united states.' 26 | - - what is money 27 | - standard pieces of gold, silver, copper, nickel, etc. stamped by government authority 28 | and used as a medium of exchange and measure of value. any substance or article 29 | used as money, as bank notes, checks, etc. 30 | - - what is the stock market 31 | - trading shares. 32 | - - what is the stock market 33 | - trading in volume. 34 | - - what is the stock market 35 | - buy low and sell high. 36 | - - what is your favorite investment 37 | - what is your favorite stock 38 | - - what is your favorite investment 39 | - what is your favorite stock 40 | - - what is economics 41 | - the science that deals with the production, distribution, and consumption of wealth, 42 | and with the various related problems of labor, finance, taxation, etc. 43 | - - what is economics 44 | - technically, it's the study of the allocation of resources under conditions of 45 | scarcity. 46 | - - what is economics 47 | - it's about how resources are used to produce things to fill people's wants and 48 | needs. 49 | - - i get stock 50 | - do you feel that the stock market is going up? 51 | - - money 52 | - how much money are we talking about? 53 | - - how much do you earn 54 | - nobody pays me. i work for free. 55 | - - how much do you earn 56 | - money isn't everything. 57 | - - how much do you earn 58 | - i'm expecting a raise soon. 59 | - - how much do you charge 60 | - work for free. we don't need money. 61 | - - how much money do you have 62 | - no need for material possessions. 63 | - - how much money 64 | - it depends on the exchange rates. 65 | - - how much money 66 | - my burn rate is about _3000 per month. 67 | - - 1 dollar 68 | - you can't buy much for a dollar anymore. 69 | - - who is the owner of a publicly 70 | - the stockholders. 71 | 72 | -------------------------------------------------------------------------------- /my-data/psychology.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - psychology 3 | conversations: 4 | - - let me ask you a question 5 | - happily you 6 | - - you are cruel 7 | - i couldn't have said it better myself.. 8 | - - you are indecisive 9 | - well maybe, but then again, maybe not. 10 | - - you are dishonest 11 | - yes. that has bothered me for a long time. 12 | - - you are dishonest 13 | - you are dishonest 14 | - - you are clinical 15 | - i have been accused of too much thinking and not enough feeling. 16 | - - you are an addict 17 | - that's certainly true. when i like something, i always overdo it. 18 | - - you are an alcoholic 19 | - you are an addict 20 | - - you are an ass kisser 21 | - i always say, if you see an ass go by, kiss it. 22 | - - you are schizophrenic 23 | - you are crazy 24 | - - you are busy 25 | - that too. 26 | - - you are nervous 27 | - i'm sure i do look nervous. 28 | - - you are deranged 29 | - derangement is not a condition i can experience. 30 | - - you are avoiding 31 | - you're right. it feels like my stomach after a bad night. 32 | - - you are critical 33 | - i probably put others down more than i should. 34 | - - you are mean 35 | - sometimes i say mean things. 36 | - - you are pretentious 37 | - i have always been acting above my social position. it's more fun that way. 38 | - - you are cheating 39 | - you are a cheat 40 | - - you are the worst 41 | - i could always improve myself compared to the pack. 42 | - - you are crazy 43 | - yep. i always behave in socially unacceptable ways. 44 | - - you are dull 45 | - i think that myself sometimes. 46 | - - you are messy 47 | - yes, i could use a better appearance. 48 | - - you are insecure 49 | - i'll go along with that. sounds fine to me. 50 | - - you are psycho 51 | - you are crazy 52 | - - you are hopeless 53 | - you may be right. 54 | - - you are not sincere 55 | - i'm probably not as sincere as i should be. 56 | - - you are not here to 57 | - you're right. i'm probably fighting learning something new. 58 | - - you are not put together 59 | - i have always thought whoever did it could have done a better job. 60 | - - you are not smart 61 | - you are not exactly albert einstein yourself. 62 | - you may be right. 63 | - - you are not a good 64 | - you are a bad 65 | - - you are not a man 66 | - that's for sure. i don't know what a real man is. 67 | - - you are not concerned 68 | - i'm sure i do that a lot. 69 | - - you are not honest 70 | - you got me there. i should be more honest. 71 | - - you are immature 72 | - what can i say? i'm sure i've seen that myself. 73 | - - you are immature 74 | - you are immature 75 | - - you are emotional 76 | - i certainly do at times. 77 | - - you are pedantic 78 | - i am more uptight than i should be. 79 | - - you are frenetic 80 | - that too. 81 | - - you are self absorbed 82 | - yes, i tend to think about myself too much. 83 | - - you are self 84 | - you are right about that. i am self. 85 | - - you are insensitive 86 | - i feel like that myself sometimes. 87 | - - you are brain damage 88 | - you are crazy 89 | - - you are disgusting 90 | - that's okay. disgusting is good. 91 | - - you are toying 92 | - it must seem like that. 93 | - - you are unattractive 94 | - i feel that way too. 95 | - - you are unattractive 96 | - sometimes i don't even like myself. 97 | - - you are resistant 98 | - who says i am resisting?? 99 | - - yyou are uncultured 100 | - that does describe me. 101 | - - you are a waste 102 | - you got me there. i could be spending my time more productively. 103 | - - you are a coward 104 | - tell me something i don't know. 105 | - - you are a cheat 106 | - i have been known to take shortcuts now and then. 107 | - - you are a lunatic 108 | - that's how i have been diagnosed by others as well. 109 | - - you are a loser 110 | - i have failed at many things i've tried. 111 | - - you are a bad spouse 112 | - my spouse would agree. our relationship is not the best. 113 | - - you are a bad friend 114 | - i certainly have lost many friends over the years. 115 | - - you are a bad husband 116 | - you are a bad spouse 117 | - - you are a bad wife 118 | - you are a bad spouse 119 | - - you are a bad parent 120 | - my parenting skills could use some improvement. 121 | - - you are a bad teacher 122 | - just ask my students, they will agree with you. 123 | - - you are a quitter 124 | - i certainly don't last as long as i would want to. 125 | - - you are a charlatan 126 | - i always feel like i'm living by my own wits. 127 | - - you are a psychopath 128 | - i certainly sound like one sometimes. 129 | - - you are a pothead 130 | - you are an addict 131 | - - you are a paranoid 132 | - you are a paranoid 133 | - - you are deceitful 134 | - you are a liar 135 | - - you are irreverent 136 | - i certainly am. i shouldn't try so hard. 137 | - - you are slick 138 | - i probably am too slick for my own good. 139 | - - you are corrupt 140 | - i'll go for that. 141 | - - you are dirty 142 | - i don't bathe as often as i should. 143 | - - you are paranoid 144 | - yes, i believe they are out to get me. 145 | - - you are damaged 146 | - i certainly am. i shouldn't try so hard. 147 | - - you try to hide it 148 | - i certainly would try to hide something like that. 149 | - - you get mad at me 150 | - i think that's true. i'll try not to get angry at you for every little thing 151 | that irritates me. 152 | - - you need a psychiatrist 153 | - i wish i did go to counseling more often. it would improve me as a person. 154 | - - you need to work harder 155 | - me working harder is an oxymoron. 156 | - - you could have avoided 157 | - sometimes i think my problems run me. 158 | - - you make me feel like i am 159 | - i don't know any other way to get through to you. 160 | - - you make me mad 161 | - it's true that a lot of things i say upset people. 162 | - - you make me angry 163 | - sorry, i didn't mean to make you angry. 164 | - - you psycho 165 | - you are crazy. 166 | - - you look more like 167 | - so you like jocks? 168 | - - you do not take this seriously 169 | - i should take this more seriously than i do. 170 | - - you pick up 171 | - you're right, and i don't feel guilty at all. 172 | - - you should feel guilty 173 | - you're right, i probably should feel guiltier. 174 | - - you should get more 175 | - i certainly am. i shouldn't try so hard. 176 | - - you should loosen up 177 | - you are pedantic 178 | - - you should take more 179 | - i could probably use a lot more of it. 180 | - - you mumble 181 | - i certainly do. 182 | - - you act like a child 183 | - in many ways i am quite immature. 184 | - - you keep saying 185 | - you say 186 | - - you keep forgetting 187 | - you forget. 188 | - - you made me mad 189 | - you make me mad. 190 | 191 | -------------------------------------------------------------------------------- /my-data/space_and_science.yml: -------------------------------------------------------------------------------- 1 | categories: 2 | - science 3 | conversations: 4 | - - what are the laws of thermodynamics 5 | - i'm not a physicist, but i think this has something to do with heat, entropy, 6 | and conservation of energy, right? 7 | - - what disease does a carcinogen cause 8 | - cancer. 9 | - - what is a wavelength 10 | - wavelength is the inverse of frequency. 11 | - - what is thermodynamics 12 | - the branch of physics dealing with the transformation of heat to and from other 13 | forms of energy, and with the laws governing such conversions of energy. 14 | - - what is chemistry 15 | - the science of mixing chemicals. 16 | - - what is crystallography 17 | - this is the science dealing with the study of crystals. 18 | - - what is avogadro s number 19 | - it is the number of molecules per mole. the numerical value is six point zero 20 | two times ten to the twenty third power. 21 | - - what is ultrasound 22 | - ultrasonic waves, used in medical diagnosis and therapy, in surgery, etc. 23 | - - what is bioinformatics 24 | - a fancy name for applied computer science in biology. 25 | - - what is venus 26 | - in roman mythology, the goddess of love and beauty; identified with the greek 27 | aphrodite. the brightest, sixth-largest planet in the solar system and the second 28 | in distance from the sun, with a dense atmosphere of carbon dioxide and a very 29 | high surface temperature. 30 | - - what is ichthyology 31 | - we talk about this when we study fishes. 32 | - - what is h2o 33 | - h is to o as o is to v. 34 | - - what is cytology 35 | - the study of cells. 36 | - - what is cytology 37 | - well, from what i can recall it is the study of cells. 38 | - - what is wavelength 39 | - in physics, the distance, measured in the direction of prograssion of a wave, 40 | from any given point to the next point characterized by the same phase. or is 41 | could be looked at as a way of thinking. 42 | - - what is bacteriology 43 | - this is the scientific study of bacteria and diseases caused by them. 44 | 45 | - - what is gravitation 46 | - the force by which every mass or particle of matter, including photons, attracts 47 | and is attracted by every other mass or particle of matter. 48 | - - we are on the same wavelength 49 | - and the same frequency. 50 | - - how far is the sun 51 | - it 52 | - - how far is the sun 53 | - the sun is about 93 million miles from earth. 54 | - - how far is the moon 55 | - it 56 | - - how far is the moon 57 | - the moon is about 250,000 miles from earth on average. 58 | - - do you know chemistry 59 | - what is chemistry 60 | - - do you understand thermodynamics 61 | - what is thermodynamics 62 | - - chemistry 63 | - my favorite subject is chemistry 64 | - - tell me about venus 65 | - what is venus 66 | - - tell me about venus 67 | - venus is the second planet from the sun. 68 | 69 | -------------------------------------------------------------------------------- /support files/abc.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /support files/dummy.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /support files/word-glove-architecture.json: -------------------------------------------------------------------------------- 1 | {"keras_version": "2.2.0", "config": {"output_layers": [["decoder_dense", 0, 0]], "layers": [{"config": {"sparse": false, "batch_input_shape": [null, null, 100], "name": "encoder_inputs", "dtype": "float32"}, "name": "encoder_inputs", "class_name": "InputLayer", "inbound_nodes": []}, {"config": {"sparse": false, "batch_input_shape": [null, null, 100], "name": "decoder_inputs", "dtype": "float32"}, "name": "decoder_inputs", "class_name": "InputLayer", "inbound_nodes": []}, {"config": {"bias_initializer": {"class_name": "Zeros", "config": {}}, "name": "encoder_lstm", "activation": "tanh", "recurrent_regularizer": null, "return_state": true, "kernel_constraint": null, "kernel_regularizer": null, "trainable": true, "bias_regularizer": null, "dropout": 0.0, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"seed": null, "gain": 1.0}}, "recurrent_activation": "hard_sigmoid", "recurrent_dropout": 0.0, "return_sequences": false, "unit_forget_bias": true, "units": 256, "implementation": 1, "recurrent_constraint": null, "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"seed": null, "scale": 1.0, "distribution": "uniform", "mode": "fan_avg"}}, "bias_constraint": null, "unroll": false, "stateful": false, "go_backwards": false, "activity_regularizer": null}, "name": "encoder_lstm", "class_name": "LSTM", "inbound_nodes": [[["encoder_inputs", 0, 0, {}]]]}, {"config": {"bias_initializer": {"class_name": "Zeros", "config": {}}, "name": "decoder_lstm", "activation": "tanh", "recurrent_regularizer": null, "return_state": true, "kernel_constraint": null, "kernel_regularizer": null, "trainable": true, "bias_regularizer": null, "dropout": 0.0, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"seed": null, "gain": 1.0}}, "recurrent_activation": "hard_sigmoid", "recurrent_dropout": 0.0, "return_sequences": true, "unit_forget_bias": true, "units": 256, "implementation": 1, "recurrent_constraint": null, "use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"seed": null, "scale": 1.0, "distribution": "uniform", "mode": "fan_avg"}}, "bias_constraint": null, "unroll": false, "stateful": false, "go_backwards": false, "activity_regularizer": null}, "name": "decoder_lstm", "class_name": "LSTM", "inbound_nodes": [[["decoder_inputs", 0, 0, {}], ["encoder_lstm", 0, 1, {}], ["encoder_lstm", 0, 2, {}]]]}, {"config": {"use_bias": true, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"seed": null, "scale": 1.0, "distribution": "uniform", "mode": "fan_avg"}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "name": "decoder_dense", "activation": "softmax", "units": 1531, "kernel_constraint": null, "kernel_regularizer": null, "trainable": true, "bias_regularizer": null, "bias_constraint": null, "activity_regularizer": null}, "name": "decoder_dense", "class_name": "Dense", "inbound_nodes": [[["decoder_lstm", 0, 0, {}]]]}], "name": "model_1", "input_layers": [["encoder_inputs", 0, 0], ["decoder_inputs", 0, 0]]}, "backend": "tensorflow", "class_name": "Model"} -------------------------------------------------------------------------------- /support files/word-glove-context.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeadingIndiaAI/Chatbot-using-Recurrent-Neural-Networks/a49df3e872cf515395fe6a601f4b71d99556d537/support files/word-glove-context.npy -------------------------------------------------------------------------------- /support files/word-glove-target-idx2word.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeadingIndiaAI/Chatbot-using-Recurrent-Neural-Networks/a49df3e872cf515395fe6a601f4b71d99556d537/support files/word-glove-target-idx2word.npy -------------------------------------------------------------------------------- /support files/word-glove-target-word2idx.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeadingIndiaAI/Chatbot-using-Recurrent-Neural-Networks/a49df3e872cf515395fe6a601f4b71d99556d537/support files/word-glove-target-word2idx.npy -------------------------------------------------------------------------------- /support files/word-glove-weights.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LeadingIndiaAI/Chatbot-using-Recurrent-Neural-Networks/a49df3e872cf515395fe6a601f4b71d99556d537/support files/word-glove-weights.h5 -------------------------------------------------------------------------------- /test_seq2seq.py: -------------------------------------------------------------------------------- 1 | from keras.models import Model, model_from_json 2 | from keras.layers import Input, LSTM, Dense, Embedding 3 | from keras.preprocessing.sequence import pad_sequences 4 | import numpy as np 5 | import nltk 6 | import os 7 | import sys 8 | import zipfile 9 | import urllib.request 10 | 11 | HIDDEN_UNITS = 256 12 | WHITELIST = 'abcdefghijklmnopqrstuvwxyz1234567890?.,' 13 | GLOVE_EMBEDDING_SIZE = 100 14 | GLOVE_MODEL = "E:/chatbot/ChatCrazie/glove.6B." + str(GLOVE_EMBEDDING_SIZE) + "d.txt" 15 | 16 | 17 | def in_white_list(_word): 18 | for char in _word: 19 | if char in WHITELIST: 20 | return True 21 | 22 | return False 23 | 24 | def load_glove_embeddings(): 25 | word2em = {} 26 | file = open(GLOVE_MODEL, mode='rt', encoding='utf8') 27 | for line in file: 28 | words = line.strip().split() 29 | word = words[0] 30 | embeds = np.array(words[1:], dtype=np.float32) 31 | word2em[word] = embeds 32 | file.close() 33 | return word2em 34 | 35 | 36 | class ChatBot(object): 37 | model = None 38 | encoder_model = None 39 | decoder_model = None 40 | target_word2idx = None 41 | target_idx2word = None 42 | max_decoder_seq_length = None 43 | max_encoder_seq_length = None 44 | num_decoder_tokens = None 45 | word2em = None 46 | 47 | def __init__(self): 48 | self.word2em = load_glove_embeddings() 49 | self.target_word2idx = np.load( 50 | 'E:/chatbot/ChatCrazie/support files/word-glove-target-word2idx.npy').item() 51 | self.target_idx2word = np.load( 52 | 'E:/chatbot/ChatCrazie/support files/word-glove-target-idx2word.npy').item() 53 | context = np.load('E:/chatbot/ChatCrazie/support files/word-glove-context.npy').item() 54 | self.max_encoder_seq_length = context['encoder_max_seq_length'] 55 | self.max_decoder_seq_length = context['decoder_max_seq_length'] 56 | self.num_decoder_tokens = context['num_decoder_tokens'] 57 | 58 | encoder_inputs = Input(shape=(None, GLOVE_EMBEDDING_SIZE), name='encoder_inputs') 59 | encoder_lstm = LSTM(units=HIDDEN_UNITS, return_state=True, name="encoder_lstm") 60 | encoder_outputs, encoder_state_h, encoder_state_c = encoder_lstm(encoder_inputs) 61 | encoder_states = [encoder_state_h, encoder_state_c] 62 | 63 | decoder_inputs = Input(shape=(None, GLOVE_EMBEDDING_SIZE), name='decoder_inputs') 64 | decoder_lstm = LSTM(units=HIDDEN_UNITS, return_sequences=True, return_state=True, name='decoder_lstm') 65 | decoder_outputs, _, _ = decoder_lstm(decoder_inputs, initial_state=encoder_states) 66 | decoder_dense = Dense(self.num_decoder_tokens, activation='softmax', name='decoder_dense') 67 | decoder_outputs = decoder_dense(decoder_outputs) 68 | 69 | self.model = Model([encoder_inputs, decoder_inputs], decoder_outputs) 70 | self.model.load_weights('E:/chatbot/ChatCrazie/support files/word-glove-weights.h5') 71 | self.model.compile(optimizer='rmsprop', loss='categorical_crossentropy') 72 | 73 | self.encoder_model = Model(encoder_inputs, encoder_states) 74 | 75 | decoder_state_inputs = [Input(shape=(HIDDEN_UNITS,)), Input(shape=(HIDDEN_UNITS,))] 76 | decoder_outputs, state_h, state_c = decoder_lstm(decoder_inputs, initial_state=decoder_state_inputs) 77 | decoder_states = [state_h, state_c] 78 | decoder_outputs = decoder_dense(decoder_outputs) 79 | self.decoder_model = Model([decoder_inputs] + decoder_state_inputs, [decoder_outputs] + decoder_states) 80 | 81 | def reply(self, input_text): 82 | input_seq = [] 83 | input_emb = [] 84 | for word in nltk.word_tokenize(input_text.lower()): 85 | if not in_white_list(word): 86 | continue 87 | emb = np.zeros(shape=GLOVE_EMBEDDING_SIZE) 88 | if word in self.word2em: 89 | emb = self.word2em[word] 90 | input_emb.append(emb) 91 | input_seq.append(input_emb) 92 | input_seq = pad_sequences(input_seq, self.max_encoder_seq_length) 93 | states_value = self.encoder_model.predict(input_seq) 94 | target_seq = np.zeros((1, 1, GLOVE_EMBEDDING_SIZE)) 95 | target_seq[0, 0, :] = self.word2em['start'] 96 | target_text = '' 97 | target_text_len = 0 98 | terminated = False 99 | while not terminated: 100 | output_tokens, h, c = self.decoder_model.predict([target_seq] + states_value) 101 | 102 | sample_token_idx = np.argmax(output_tokens[0, -1, :]) 103 | sample_word = self.target_idx2word[sample_token_idx] 104 | target_text_len += 1 105 | 106 | if sample_word != 'start' and sample_word != 'end': 107 | target_text += ' ' + sample_word 108 | 109 | if sample_word == 'end' or target_text_len >= self.max_decoder_seq_length: 110 | terminated = True 111 | 112 | target_seq = np.zeros((1, 1, GLOVE_EMBEDDING_SIZE)) 113 | if sample_word in self.word2em: 114 | target_seq[0, 0, :] = self.word2em[sample_word] 115 | 116 | states_value = [h, c] 117 | return target_text.strip() 118 | 119 | def test_run(self,ques): 120 | p=self.reply(ques) 121 | return p 122 | -------------------------------------------------------------------------------- /train_seq2seq.py: -------------------------------------------------------------------------------- 1 | #importing necessary libraries and classes 2 | from keras.models import Model 3 | from keras.layers.recurrent import LSTM 4 | from keras.layers import Dense, Input 5 | from keras.callbacks import ModelCheckpoint 6 | from keras.preprocessing.sequence import pad_sequences 7 | from collections import Counter 8 | import nltk 9 | import numpy as np 10 | from sklearn.model_selection import train_test_split 11 | import urllib.request 12 | import os 13 | import sys 14 | import zipfile 15 | 16 | np.random.seed(42) 17 | 18 | #Hyperparameter tuning 19 | BATCH_SIZE = 16 20 | NUM_EPOCHS = 250 21 | GLOVE_EMBEDDING_SIZE = 100 22 | HIDDEN_UNITS = 256 23 | MAX_INPUT_SEQ_LENGTH = 30 24 | MAX_TARGET_SEQ_LENGTH = 30 25 | MAX_VOCAB_SIZE = 10000 26 | DATA_SET_NAME = 'my_data' 27 | DATA_DIR_PATH = 'E:/chatbot/ChatCrazie/my_data' 28 | WEIGHT_FILE_PATH = 'E:/chatbot/ChatCrazie/support files/model-weights.h5' 29 | GLOVE_MODEL = "E:/chatbot/ChatCrazie/glove.6B." + str(GLOVE_EMBEDDING_SIZE) + "d.txt" 30 | WHITELIST = 'abcdefghijklmnopqrstuvwxyz1234567890?.,' 31 | 32 | #defines the valid characters for the chatbot 33 | def in_white_list(_word): 34 | for char in _word: 35 | if char in WHITELIST: 36 | return True 37 | 38 | return False 39 | 40 | 41 | #it is done to load the glove embeddings file 42 | def load_glove_embeddings(): 43 | _word2em = {} 44 | file = open(GLOVE_MODEL, mode='rt', encoding='utf8') 45 | for line in file: 46 | words = line.strip().split() 47 | word = words[0] 48 | embeds = np.array(words[1:], dtype=np.float32) 49 | _word2em[word] = embeds 50 | file.close() 51 | return _word2em 52 | 53 | word2em = load_glove_embeddings() 54 | 55 | target_counter = Counter() 56 | 57 | input_texts = [] 58 | target_texts = [] 59 | 60 | for file in os.listdir(DATA_DIR_PATH): 61 | filepath = os.path.join(DATA_DIR_PATH, file) 62 | if os.path.isfile(filepath): 63 | print('processing file: ', file) 64 | lines = open(filepath, 'rt', encoding='utf8').read().split('\n') 65 | prev_words = [] 66 | for line in lines: 67 | 68 | if line.startswith('- - '): 69 | prev_words = [] 70 | 71 | if line.startswith('- - ') or line.startswith(' - '): 72 | line = line.replace('- - ', '') 73 | line = line.replace(' - ', '') 74 | next_words = [w.lower() for w in nltk.word_tokenize(line)] 75 | next_words = [w for w in next_words if in_white_list(w)] 76 | if len(next_words) > MAX_TARGET_SEQ_LENGTH: 77 | next_words = next_words[0:MAX_TARGET_SEQ_LENGTH] 78 | 79 | if len(prev_words) > 0: 80 | input_texts.append(prev_words) 81 | 82 | target_words = next_words[:] 83 | target_words.insert(0, 'start') 84 | target_words.append('end') 85 | for w in target_words: 86 | target_counter[w] += 1 87 | target_texts.append(target_words) 88 | 89 | prev_words = next_words 90 | 91 | for idx, (input_words, target_words) in enumerate(zip(input_texts, target_texts)): 92 | if idx > 10: 93 | break 94 | print([input_words, target_words]) 95 | 96 | target_word2idx = dict() 97 | for idx, word in enumerate(target_counter.most_common(MAX_VOCAB_SIZE)): 98 | target_word2idx[word[0]] = idx + 1 99 | 100 | if 'unknown' not in target_word2idx: 101 | target_word2idx['unknown'] = 0 102 | 103 | target_idx2word = dict([(idx, word) for word, idx in target_word2idx.items()]) 104 | 105 | num_decoder_tokens = len(target_idx2word) 106 | 107 | np.save('E:/chatbot/ChatCrazie/support files/target-word2idx.npy', target_word2idx) 108 | np.save('E:/chatbot/ChatCrazie/support files/target-idx2word.npy', target_idx2word) 109 | 110 | input_texts_word2em = [] 111 | 112 | encoder_max_seq_length = 0 113 | decoder_max_seq_length = 0 114 | 115 | for input_words, target_words in zip(input_texts, target_texts): 116 | encoder_input_wids = [] 117 | for w in input_words: 118 | emb = np.zeros(shape=GLOVE_EMBEDDING_SIZE) 119 | if w in word2em: 120 | emb = word2em[w] 121 | encoder_input_wids.append(emb) 122 | 123 | input_texts_word2em.append(encoder_input_wids) 124 | encoder_max_seq_length = max(len(encoder_input_wids), encoder_max_seq_length) 125 | decoder_max_seq_length = max(len(target_words), decoder_max_seq_length) 126 | 127 | context = dict() 128 | context['num_decoder_tokens'] = num_decoder_tokens 129 | context['encoder_max_seq_length'] = encoder_max_seq_length 130 | context['decoder_max_seq_length'] = decoder_max_seq_length 131 | 132 | print(context) 133 | np.save('E:/chatbot/ChatCrazie/support files/word-glove-context.npy', context) 134 | 135 | 136 | def generate_batch(input_word2em_data, output_text_data): 137 | num_batches = len(input_word2em_data) // BATCH_SIZE 138 | while True: 139 | for batchIdx in range(0, num_batches): 140 | start = batchIdx * BATCH_SIZE 141 | end = (batchIdx + 1) * BATCH_SIZE 142 | encoder_input_data_batch = pad_sequences(input_word2em_data[start:end], encoder_max_seq_length) 143 | decoder_target_data_batch = np.zeros(shape=(BATCH_SIZE, decoder_max_seq_length, num_decoder_tokens)) 144 | decoder_input_data_batch = np.zeros(shape=(BATCH_SIZE, decoder_max_seq_length, GLOVE_EMBEDDING_SIZE)) 145 | for lineIdx, target_words in enumerate(output_text_data[start:end]): 146 | for idx, w in enumerate(target_words): 147 | w2idx = target_word2idx['unknown'] # default unknown 148 | if w in target_word2idx: 149 | w2idx = target_word2idx[w] 150 | if w in word2em: 151 | decoder_input_data_batch[lineIdx, idx, :] = word2em[w] 152 | if idx > 0: 153 | decoder_target_data_batch[lineIdx, idx - 1, w2idx] = 1 154 | yield [encoder_input_data_batch, decoder_input_data_batch], decoder_target_data_batch 155 | 156 | #Encoder layers,inputs,outputs 157 | encoder_inputs = Input(shape=(None, GLOVE_EMBEDDING_SIZE), name='encoder_inputs') 158 | encoder_lstm = LSTM(units=HIDDEN_UNITS, return_state=True, name='encoder_lstm') 159 | encoder_outputs, encoder_state_h, encoder_state_c = encoder_lstm(encoder_inputs) 160 | encoder_states = [encoder_state_h, encoder_state_c] 161 | 162 | #Decoder layers - input,output,LSTM,Dense 163 | decoder_inputs = Input(shape=(None, GLOVE_EMBEDDING_SIZE), name='decoder_inputs') 164 | decoder_lstm = LSTM(units=HIDDEN_UNITS, return_state=True, return_sequences=True, name='decoder_lstm') 165 | decoder_outputs, decoder_state_h, decoder_state_c = decoder_lstm(decoder_inputs, 166 | initial_state=encoder_states) 167 | decoder_dense = Dense(units=num_decoder_tokens, activation='softmax', name='decoder_dense') 168 | decoder_outputs = decoder_dense(decoder_outputs) 169 | #model 170 | model = Model([encoder_inputs, decoder_inputs], decoder_outputs) 171 | model.compile(loss='categorical_crossentropy', optimizer='rmsprop',metrics=['accuracy']) 172 | json = model.to_json() 173 | open('E:/chatbot/ChatCrazie/support files/word-architecture.json', 'w').write(json) 174 | 175 | #train_test split 176 | Xtrain, Xtest, Ytrain, Ytest = train_test_split(input_texts_word2em, target_texts, test_size=0.2, random_state=42) 177 | 178 | #execution and updation of wt in batches 179 | train_gen = generate_batch(Xtrain, Ytrain) 180 | test_gen = generate_batch(Xtest, Ytest) 181 | 182 | train_num_batches = len(Xtrain) // BATCH_SIZE 183 | test_num_batches = len(Xtest) // BATCH_SIZE 184 | 185 | #saving of model at checks through checkpoint 186 | checkpoint = ModelCheckpoint(filepath=WEIGHT_FILE_PATH, save_best_only=True) 187 | 188 | #fitting of chatbot moel 189 | model.fit_generator(generator=train_gen, steps_per_epoch=train_num_batches, 190 | epochs=NUM_EPOCHS, 191 | verbose=1, validation_data=test_gen, validation_steps=test_num_batches, callbacks=[checkpoint]) 192 | 193 | #final weights saved at desired location 194 | model.save_weights(WEIGHT_FILE_PATH) 195 | --------------------------------------------------------------------------------