Skip to content

Commit 921f74e

Browse files
author
ugik
committed
chat-bot cleanup
1 parent 232cfb3 commit 921f74e

File tree

3 files changed

+57
-80
lines changed

3 files changed

+57
-80
lines changed

Tensorflow chat-bot model.ipynb

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,8 @@
119119
" output_row = list(output_empty)\n",
120120
" output_row[classes.index(doc[1])] = 1\n",
121121
"\n",
122-
" training.append([bag, output_row])"
123-
]
124-
},
125-
{
126-
"cell_type": "code",
127-
"execution_count": 5,
128-
"metadata": {
129-
"collapsed": true
130-
},
131-
"outputs": [],
132-
"source": [
122+
" training.append([bag, output_row])\n",
123+
"\n",
133124
"# shuffle our features and turn into np.array\n",
134125
"random.shuffle(training)\n",
135126
"training = np.array(training)\n",
@@ -141,7 +132,7 @@
141132
},
142133
{
143134
"cell_type": "code",
144-
"execution_count": 6,
135+
"execution_count": 5,
145136
"metadata": {
146137
"collapsed": false,
147138
"scrolled": true
@@ -151,10 +142,10 @@
151142
"name": "stdout",
152143
"output_type": "stream",
153144
"text": [
154-
"Training Step: 3999 | total loss: \u001b[1m\u001b[32m0.18876\u001b[0m\u001b[0m | time: 0.008s\n",
155-
"| Adam | epoch: 1000 | loss: 0.18876 - acc: 0.9896 -- iter: 24/27\n",
156-
"Training Step: 4000 | total loss: \u001b[1m\u001b[32m0.17795\u001b[0m\u001b[0m | time: 0.010s\n",
157-
"| Adam | epoch: 1000 | loss: 0.17795 - acc: 0.9907 -- iter: 27/27\n",
145+
"Training Step: 3999 | total loss: \u001b[1m\u001b[32m0.79875\u001b[0m\u001b[0m | time: 0.009s\n",
146+
"| Adam | epoch: 1000 | loss: 0.79875 - acc: 0.9100 -- iter: 24/27\n",
147+
"Training Step: 4000 | total loss: \u001b[1m\u001b[32m0.72213\u001b[0m\u001b[0m | time: 0.012s\n",
148+
"| Adam | epoch: 1000 | loss: 0.72213 - acc: 0.9190 -- iter: 27/27\n",
158149
"--\n",
159150
"INFO:tensorflow:/home/gk/gensim/notebooks/model.tflearn is not in all_model_checkpoint_paths. Manually adding it.\n"
160151
]
@@ -179,7 +170,7 @@
179170
},
180171
{
181172
"cell_type": "code",
182-
"execution_count": 7,
173+
"execution_count": 6,
183174
"metadata": {
184175
"collapsed": true
185176
},
@@ -210,7 +201,7 @@
210201
},
211202
{
212203
"cell_type": "code",
213-
"execution_count": 8,
204+
"execution_count": 7,
214205
"metadata": {
215206
"collapsed": false
216207
},
@@ -233,7 +224,7 @@
233224
},
234225
{
235226
"cell_type": "code",
236-
"execution_count": 9,
227+
"execution_count": 8,
237228
"metadata": {
238229
"collapsed": false
239230
},
@@ -242,7 +233,7 @@
242233
"name": "stdout",
243234
"output_type": "stream",
244235
"text": [
245-
"[[0.00010235147055936977, 7.91284620049737e-08, 0.04525074362754822, 3.261959591327468e-07, 0.9264171123504639, 1.7087060655285313e-08, 0.00015298598736990243, 0.00015127936785575002, 0.02792503498494625]]\n"
236+
"[[0.0006383281433954835, 1.1489937890019064e-08, 0.005845240317285061, 2.1674446543329395e-05, 0.9596946239471436, 1.4315231666728323e-08, 0.0018385507864877582, 1.7271321439693565e-06, 0.031959764659404755]]\n"
246237
]
247238
}
248239
],
@@ -252,7 +243,7 @@
252243
},
253244
{
254245
"cell_type": "code",
255-
"execution_count": 10,
246+
"execution_count": 9,
256247
"metadata": {
257248
"collapsed": false
258249
},

Tensorflow chat-bot response.ipynb

Lines changed: 45 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,8 @@
4242
"words = data['words']\n",
4343
"classes = data['classes']\n",
4444
"train_x = data['train_x']\n",
45-
"train_y = data['train_y']"
46-
]
47-
},
48-
{
49-
"cell_type": "code",
50-
"execution_count": 3,
51-
"metadata": {
52-
"collapsed": false
53-
},
54-
"outputs": [],
55-
"source": [
45+
"train_y = data['train_y']\n",
46+
"\n",
5647
"# import our chat-bot intents file\n",
5748
"import json\n",
5849
"with open('intents.json') as json_data:\n",
@@ -61,7 +52,7 @@
6152
},
6253
{
6354
"cell_type": "code",
64-
"execution_count": 4,
55+
"execution_count": 3,
6556
"metadata": {
6657
"collapsed": false,
6758
"scrolled": true
@@ -81,7 +72,7 @@
8172
},
8273
{
8374
"cell_type": "code",
84-
"execution_count": 5,
75+
"execution_count": 4,
8576
"metadata": {
8677
"collapsed": true
8778
},
@@ -112,7 +103,7 @@
112103
},
113104
{
114105
"cell_type": "code",
115-
"execution_count": 6,
106+
"execution_count": 5,
116107
"metadata": {
117108
"collapsed": false
118109
},
@@ -135,7 +126,7 @@
135126
},
136127
{
137128
"cell_type": "code",
138-
"execution_count": 7,
129+
"execution_count": 6,
139130
"metadata": {
140131
"collapsed": false
141132
},
@@ -147,24 +138,15 @@
147138
},
148139
{
149140
"cell_type": "code",
150-
"execution_count": 8,
151-
"metadata": {
152-
"collapsed": true
153-
},
154-
"outputs": [],
155-
"source": [
156-
"# create a data structure to hold user context\n",
157-
"context = {}"
158-
]
159-
},
160-
{
161-
"cell_type": "code",
162-
"execution_count": 9,
141+
"execution_count": 7,
163142
"metadata": {
164143
"collapsed": false
165144
},
166145
"outputs": [],
167146
"source": [
147+
"# create a data structure to hold user context\n",
148+
"context = {}\n",
149+
"\n",
168150
"ERROR_THRESHOLD = 0.25\n",
169151
"def classify(sentence):\n",
170152
" # generate probabilities from the model\n",
@@ -205,18 +187,18 @@
205187
},
206188
{
207189
"cell_type": "code",
208-
"execution_count": 10,
190+
"execution_count": 8,
209191
"metadata": {
210192
"collapsed": false
211193
},
212194
"outputs": [
213195
{
214196
"data": {
215197
"text/plain": [
216-
"[('opentoday', 0.9264171123504639)]"
198+
"[('opentoday', 0.9596946239471436)]"
217199
]
218200
},
219-
"execution_count": 10,
201+
"execution_count": 8,
220202
"metadata": {},
221203
"output_type": "execute_result"
222204
}
@@ -227,7 +209,7 @@
227209
},
228210
{
229211
"cell_type": "code",
230-
"execution_count": 11,
212+
"execution_count": 9,
231213
"metadata": {
232214
"collapsed": false
233215
},
@@ -236,7 +218,7 @@
236218
"name": "stdout",
237219
"output_type": "stream",
238220
"text": [
239-
"Our hours are 9am-9pm every day\n"
221+
"We're open every day from 9am-9pm\n"
240222
]
241223
}
242224
],
@@ -246,7 +228,7 @@
246228
},
247229
{
248230
"cell_type": "code",
249-
"execution_count": 12,
231+
"execution_count": 10,
250232
"metadata": {
251233
"collapsed": false
252234
},
@@ -255,7 +237,7 @@
255237
"name": "stdout",
256238
"output_type": "stream",
257239
"text": [
258-
"We accept most major credit cards\n"
240+
"We accept VISA, Mastercard and AMEX\n"
259241
]
260242
}
261243
],
@@ -265,7 +247,7 @@
265247
},
266248
{
267249
"cell_type": "code",
268-
"execution_count": 13,
250+
"execution_count": 11,
269251
"metadata": {
270252
"collapsed": false
271253
},
@@ -284,7 +266,7 @@
284266
},
285267
{
286268
"cell_type": "code",
287-
"execution_count": 14,
269+
"execution_count": 12,
288270
"metadata": {
289271
"collapsed": false
290272
},
@@ -295,7 +277,7 @@
295277
"{}"
296278
]
297279
},
298-
"execution_count": 14,
280+
"execution_count": 12,
299281
"metadata": {},
300282
"output_type": "execute_result"
301283
}
@@ -306,7 +288,7 @@
306288
},
307289
{
308290
"cell_type": "code",
309-
"execution_count": 15,
291+
"execution_count": 20,
310292
"metadata": {
311293
"collapsed": false
312294
},
@@ -325,7 +307,7 @@
325307
},
326308
{
327309
"cell_type": "code",
328-
"execution_count": 16,
310+
"execution_count": 21,
329311
"metadata": {
330312
"collapsed": false
331313
},
@@ -336,7 +318,7 @@
336318
"{'123': 'rentalday'}"
337319
]
338320
},
339-
"execution_count": 16,
321+
"execution_count": 21,
340322
"metadata": {},
341323
"output_type": "execute_result"
342324
}
@@ -348,7 +330,7 @@
348330
},
349331
{
350332
"cell_type": "code",
351-
"execution_count": 17,
333+
"execution_count": 22,
352334
"metadata": {
353335
"collapsed": false
354336
},
@@ -357,29 +339,28 @@
357339
"name": "stdout",
358340
"output_type": "stream",
359341
"text": [
360-
"tag: today\n",
361342
"For rentals today please call 1-800-MYMOPED\n"
362343
]
363344
}
364345
],
365346
"source": [
366-
"response('today', show_details=True)"
347+
"response('today')"
367348
]
368349
},
369350
{
370351
"cell_type": "code",
371-
"execution_count": 18,
352+
"execution_count": 16,
372353
"metadata": {
373354
"collapsed": false
374355
},
375356
"outputs": [
376357
{
377358
"data": {
378359
"text/plain": [
379-
"[('today', 0.5322513580322266), ('opentoday', 0.2611265480518341)]"
360+
"[('today', 0.5943121910095215)]"
380361
]
381362
},
382-
"execution_count": 18,
363+
"execution_count": 16,
383364
"metadata": {},
384365
"output_type": "execute_result"
385366
}
@@ -390,7 +371,7 @@
390371
},
391372
{
392373
"cell_type": "code",
393-
"execution_count": 19,
374+
"execution_count": 23,
394375
"metadata": {
395376
"collapsed": false
396377
},
@@ -399,38 +380,43 @@
399380
"name": "stdout",
400381
"output_type": "stream",
401382
"text": [
402-
"Hello, thanks for visiting\n"
383+
"context: \n",
384+
"tag: greeting\n",
385+
"Hi there, how can I help?\n"
403386
]
404387
}
405388
],
406389
"source": [
407390
"# clear context\n",
408-
"response(\"Hi there!\")"
391+
"response(\"Hi there!\", show_details=True)"
409392
]
410393
},
411394
{
412395
"cell_type": "code",
413-
"execution_count": 20,
396+
"execution_count": 24,
414397
"metadata": {
415398
"collapsed": false
416399
},
417400
"outputs": [
418401
{
419-
"name": "stdout",
420-
"output_type": "stream",
421-
"text": [
422-
"tag: opentoday\n",
423-
"Our hours are 9am-9pm every day\n"
424-
]
402+
"data": {
403+
"text/plain": [
404+
"[('today', 0.5943121910095215)]"
405+
]
406+
},
407+
"execution_count": 24,
408+
"metadata": {},
409+
"output_type": "execute_result"
425410
}
426411
],
427412
"source": [
428-
"response('today', show_details=True)"
413+
"response('today')\n",
414+
"classify('today')"
429415
]
430416
},
431417
{
432418
"cell_type": "code",
433-
"execution_count": 21,
419+
"execution_count": 25,
434420
"metadata": {
435421
"collapsed": false
436422
},

training_data

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)