|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Basic Chatbot using ChatterBot" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": null, |
| 13 | + "metadata": {}, |
| 14 | + "outputs": [], |
| 15 | + "source": [ |
| 16 | + "import chatterbot\n", |
| 17 | + "from chatterbot import ChatBot\n", |
| 18 | + "from chatterbot.trainers import ListTrainer" |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "code", |
| 23 | + "execution_count": 22, |
| 24 | + "metadata": {}, |
| 25 | + "outputs": [ |
| 26 | + { |
| 27 | + "name": "stdout", |
| 28 | + "output_type": "stream", |
| 29 | + "text": [ |
| 30 | + "List Trainer: [####################] 100%\n" |
| 31 | + ] |
| 32 | + } |
| 33 | + ], |
| 34 | + "source": [ |
| 35 | + "#Let's give a name to your chat bot\n", |
| 36 | + "chatbot = ChatBot('Veronica')\n", |
| 37 | + "\n", |
| 38 | + "#Train the bot\n", |
| 39 | + "chatbot.set_trainer(ListTrainer)\n", |
| 40 | + "chatbot.train(['What is your name?', 'My name is Veronica'])" |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "code", |
| 45 | + "execution_count": 23, |
| 46 | + "metadata": {}, |
| 47 | + "outputs": [ |
| 48 | + { |
| 49 | + "data": { |
| 50 | + "text/plain": [ |
| 51 | + "<Statement text:My name is Veronica>" |
| 52 | + ] |
| 53 | + }, |
| 54 | + "execution_count": 23, |
| 55 | + "metadata": {}, |
| 56 | + "output_type": "execute_result" |
| 57 | + } |
| 58 | + ], |
| 59 | + "source": [ |
| 60 | + "#let's test the bot\n", |
| 61 | + "chatbot.get_response('What is your name?')" |
| 62 | + ] |
| 63 | + }, |
| 64 | + { |
| 65 | + "cell_type": "code", |
| 66 | + "execution_count": 24, |
| 67 | + "metadata": {}, |
| 68 | + "outputs": [ |
| 69 | + { |
| 70 | + "name": "stdout", |
| 71 | + "output_type": "stream", |
| 72 | + "text": [ |
| 73 | + "List Trainer: [####################] 100%\n" |
| 74 | + ] |
| 75 | + } |
| 76 | + ], |
| 77 | + "source": [ |
| 78 | + "#Let's train the bot with more data\n", |
| 79 | + "conversations = [\n", |
| 80 | + " 'Are you an artist?', 'No, are you mad? I am a bot',\n", |
| 81 | + " 'Do you like big bang theory?', 'Bazinga!',\n", |
| 82 | + " 'What is my name?', 'Natasha',\n", |
| 83 | + " 'What color is the sky?', 'Blue, stop asking me stupid questions'\n", |
| 84 | + "]\n", |
| 85 | + "\n", |
| 86 | + "chatbot.train(conversations)" |
| 87 | + ] |
| 88 | + }, |
| 89 | + { |
| 90 | + "cell_type": "code", |
| 91 | + "execution_count": 25, |
| 92 | + "metadata": {}, |
| 93 | + "outputs": [ |
| 94 | + { |
| 95 | + "data": { |
| 96 | + "text/plain": [ |
| 97 | + "<Statement text:Bazinga!>" |
| 98 | + ] |
| 99 | + }, |
| 100 | + "execution_count": 25, |
| 101 | + "metadata": {}, |
| 102 | + "output_type": "execute_result" |
| 103 | + } |
| 104 | + ], |
| 105 | + "source": [ |
| 106 | + "chatbot.get_response('Do you like big bang theory?')" |
| 107 | + ] |
| 108 | + }, |
| 109 | + { |
| 110 | + "cell_type": "code", |
| 111 | + "execution_count": 27, |
| 112 | + "metadata": {}, |
| 113 | + "outputs": [ |
| 114 | + { |
| 115 | + "name": "stdout", |
| 116 | + "output_type": "stream", |
| 117 | + "text": [ |
| 118 | + "ai.yml Training: [####################] 100%\n", |
| 119 | + "botprofile.yml Training: [####################] 100%\n", |
| 120 | + "computers.yml Training: [####################] 100%\n", |
| 121 | + "conversations.yml Training: [####################] 100%\n", |
| 122 | + "emotion.yml Training: [####################] 100%\n", |
| 123 | + "food.yml Training: [####################] 100%\n", |
| 124 | + "gossip.yml Training: [####################] 100%\n", |
| 125 | + "greetings.yml Training: [####################] 100%\n", |
| 126 | + "history.yml Training: [####################] 100%\n", |
| 127 | + "humor.yml Training: [####################] 100%\n", |
| 128 | + "literature.yml Training: [####################] 100%\n", |
| 129 | + "money.yml Training: [####################] 100%\n", |
| 130 | + "movies.yml Training: [####################] 100%\n", |
| 131 | + "politics.yml Training: [####################] 100%\n", |
| 132 | + "psychology.yml Training: [####################] 100%\n", |
| 133 | + "science.yml Training: [####################] 100%\n", |
| 134 | + "sports.yml Training: [####################] 100%\n", |
| 135 | + "trivia.yml Training: [####################] 100%\n" |
| 136 | + ] |
| 137 | + } |
| 138 | + ], |
| 139 | + "source": [ |
| 140 | + "#Let's use chatterbot corpus to train the bot\n", |
| 141 | + "from chatterbot.trainers import ChatterBotCorpusTrainer\n", |
| 142 | + "chatbot.set_trainer(ChatterBotCorpusTrainer)\n", |
| 143 | + "chatbot.train(\"chatterbot.corpus.english\")" |
| 144 | + ] |
| 145 | + }, |
| 146 | + { |
| 147 | + "cell_type": "code", |
| 148 | + "execution_count": 28, |
| 149 | + "metadata": {}, |
| 150 | + "outputs": [ |
| 151 | + { |
| 152 | + "data": { |
| 153 | + "text/plain": [ |
| 154 | + "<Statement text:Richard Nixon>" |
| 155 | + ] |
| 156 | + }, |
| 157 | + "execution_count": 28, |
| 158 | + "metadata": {}, |
| 159 | + "output_type": "execute_result" |
| 160 | + } |
| 161 | + ], |
| 162 | + "source": [ |
| 163 | + "chatbot.get_response('Who is the President of America?')" |
| 164 | + ] |
| 165 | + }, |
| 166 | + { |
| 167 | + "cell_type": "code", |
| 168 | + "execution_count": 29, |
| 169 | + "metadata": {}, |
| 170 | + "outputs": [ |
| 171 | + { |
| 172 | + "data": { |
| 173 | + "text/plain": [ |
| 174 | + "<Statement text:Python.>" |
| 175 | + ] |
| 176 | + }, |
| 177 | + "execution_count": 29, |
| 178 | + "metadata": {}, |
| 179 | + "output_type": "execute_result" |
| 180 | + } |
| 181 | + ], |
| 182 | + "source": [ |
| 183 | + "chatbot.get_response('What language do you speak?')" |
| 184 | + ] |
| 185 | + }, |
| 186 | + { |
| 187 | + "cell_type": "code", |
| 188 | + "execution_count": 33, |
| 189 | + "metadata": {}, |
| 190 | + "outputs": [ |
| 191 | + { |
| 192 | + "data": { |
| 193 | + "text/plain": [ |
| 194 | + "<Statement text:How are you doing?>" |
| 195 | + ] |
| 196 | + }, |
| 197 | + "execution_count": 33, |
| 198 | + "metadata": {}, |
| 199 | + "output_type": "execute_result" |
| 200 | + } |
| 201 | + ], |
| 202 | + "source": [ |
| 203 | + "chatbot.get_response('Hi')" |
| 204 | + ] |
| 205 | + }, |
| 206 | + { |
| 207 | + "cell_type": "markdown", |
| 208 | + "metadata": {}, |
| 209 | + "source": [ |
| 210 | + "The bot needs some intelligence. " |
| 211 | + ] |
| 212 | + } |
| 213 | + ], |
| 214 | + "metadata": { |
| 215 | + "kernelspec": { |
| 216 | + "display_name": "Python 3", |
| 217 | + "language": "python", |
| 218 | + "name": "python3" |
| 219 | + }, |
| 220 | + "language_info": { |
| 221 | + "codemirror_mode": { |
| 222 | + "name": "ipython", |
| 223 | + "version": 3 |
| 224 | + }, |
| 225 | + "file_extension": ".py", |
| 226 | + "mimetype": "text/x-python", |
| 227 | + "name": "python", |
| 228 | + "nbconvert_exporter": "python", |
| 229 | + "pygments_lexer": "ipython3", |
| 230 | + "version": "3.6.4" |
| 231 | + } |
| 232 | + }, |
| 233 | + "nbformat": 4, |
| 234 | + "nbformat_minor": 2 |
| 235 | +} |
0 commit comments