Skip to content

Commit

Permalink
chat-bot cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ugik committed May 7, 2017
1 parent 232cfb3 commit 921f74e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 80 deletions.
33 changes: 12 additions & 21 deletions Tensorflow chat-bot model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,8 @@
" output_row = list(output_empty)\n",
" output_row[classes.index(doc[1])] = 1\n",
"\n",
" training.append([bag, output_row])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
" training.append([bag, output_row])\n",
"\n",
"# shuffle our features and turn into np.array\n",
"random.shuffle(training)\n",
"training = np.array(training)\n",
Expand All @@ -141,7 +132,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {
"collapsed": false,
"scrolled": true
Expand All @@ -151,10 +142,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Training Step: 3999 | total loss: \u001b[1m\u001b[32m0.18876\u001b[0m\u001b[0m | time: 0.008s\n",
"| Adam | epoch: 1000 | loss: 0.18876 - acc: 0.9896 -- iter: 24/27\n",
"Training Step: 4000 | total loss: \u001b[1m\u001b[32m0.17795\u001b[0m\u001b[0m | time: 0.010s\n",
"| Adam | epoch: 1000 | loss: 0.17795 - acc: 0.9907 -- iter: 27/27\n",
"Training Step: 3999 | total loss: \u001b[1m\u001b[32m0.79875\u001b[0m\u001b[0m | time: 0.009s\n",
"| Adam | epoch: 1000 | loss: 0.79875 - acc: 0.9100 -- iter: 24/27\n",
"Training Step: 4000 | total loss: \u001b[1m\u001b[32m0.72213\u001b[0m\u001b[0m | time: 0.012s\n",
"| Adam | epoch: 1000 | loss: 0.72213 - acc: 0.9190 -- iter: 27/27\n",
"--\n",
"INFO:tensorflow:/home/gk/gensim/notebooks/model.tflearn is not in all_model_checkpoint_paths. Manually adding it.\n"
]
Expand All @@ -179,7 +170,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {
"collapsed": true
},
Expand Down Expand Up @@ -210,7 +201,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {
"collapsed": false
},
Expand All @@ -233,7 +224,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {
"collapsed": false
},
Expand All @@ -242,7 +233,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[[0.00010235147055936977, 7.91284620049737e-08, 0.04525074362754822, 3.261959591327468e-07, 0.9264171123504639, 1.7087060655285313e-08, 0.00015298598736990243, 0.00015127936785575002, 0.02792503498494625]]\n"
"[[0.0006383281433954835, 1.1489937890019064e-08, 0.005845240317285061, 2.1674446543329395e-05, 0.9596946239471436, 1.4315231666728323e-08, 0.0018385507864877582, 1.7271321439693565e-06, 0.031959764659404755]]\n"
]
}
],
Expand All @@ -252,7 +243,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {
"collapsed": false
},
Expand Down
104 changes: 45 additions & 59 deletions Tensorflow chat-bot response.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,8 @@
"words = data['words']\n",
"classes = data['classes']\n",
"train_x = data['train_x']\n",
"train_y = data['train_y']"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"train_y = data['train_y']\n",
"\n",
"# import our chat-bot intents file\n",
"import json\n",
"with open('intents.json') as json_data:\n",
Expand All @@ -61,7 +52,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {
"collapsed": false,
"scrolled": true
Expand All @@ -81,7 +72,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {
"collapsed": true
},
Expand Down Expand Up @@ -112,7 +103,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {
"collapsed": false
},
Expand All @@ -135,7 +126,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {
"collapsed": false
},
Expand All @@ -147,24 +138,15 @@
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# create a data structure to hold user context\n",
"context = {}"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# create a data structure to hold user context\n",
"context = {}\n",
"\n",
"ERROR_THRESHOLD = 0.25\n",
"def classify(sentence):\n",
" # generate probabilities from the model\n",
Expand Down Expand Up @@ -205,18 +187,18 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[('opentoday', 0.9264171123504639)]"
"[('opentoday', 0.9596946239471436)]"
]
},
"execution_count": 10,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -227,7 +209,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 9,
"metadata": {
"collapsed": false
},
Expand All @@ -236,7 +218,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Our hours are 9am-9pm every day\n"
"We're open every day from 9am-9pm\n"
]
}
],
Expand All @@ -246,7 +228,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 10,
"metadata": {
"collapsed": false
},
Expand All @@ -255,7 +237,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"We accept most major credit cards\n"
"We accept VISA, Mastercard and AMEX\n"
]
}
],
Expand All @@ -265,7 +247,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 11,
"metadata": {
"collapsed": false
},
Expand All @@ -284,7 +266,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 12,
"metadata": {
"collapsed": false
},
Expand All @@ -295,7 +277,7 @@
"{}"
]
},
"execution_count": 14,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -306,7 +288,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 20,
"metadata": {
"collapsed": false
},
Expand All @@ -325,7 +307,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 21,
"metadata": {
"collapsed": false
},
Expand All @@ -336,7 +318,7 @@
"{'123': 'rentalday'}"
]
},
"execution_count": 16,
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -348,7 +330,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 22,
"metadata": {
"collapsed": false
},
Expand All @@ -357,29 +339,28 @@
"name": "stdout",
"output_type": "stream",
"text": [
"tag: today\n",
"For rentals today please call 1-800-MYMOPED\n"
]
}
],
"source": [
"response('today', show_details=True)"
"response('today')"
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[('today', 0.5322513580322266), ('opentoday', 0.2611265480518341)]"
"[('today', 0.5943121910095215)]"
]
},
"execution_count": 18,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -390,7 +371,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 23,
"metadata": {
"collapsed": false
},
Expand All @@ -399,38 +380,43 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Hello, thanks for visiting\n"
"context: \n",
"tag: greeting\n",
"Hi there, how can I help?\n"
]
}
],
"source": [
"# clear context\n",
"response(\"Hi there!\")"
"response(\"Hi there!\", show_details=True)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tag: opentoday\n",
"Our hours are 9am-9pm every day\n"
]
"data": {
"text/plain": [
"[('today', 0.5943121910095215)]"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"response('today', show_details=True)"
"response('today')\n",
"classify('today')"
]
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 25,
"metadata": {
"collapsed": false
},
Expand Down
Binary file modified training_data
Binary file not shown.

0 comments on commit 921f74e

Please sign in to comment.