|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": null, |
6 |
| - "id": "economic-canadian", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "worth-knock", |
7 | 7 | "metadata": {},
|
8 |
| - "outputs": [], |
| 8 | + "outputs": [ |
| 9 | + { |
| 10 | + "name": "stderr", |
| 11 | + "output_type": "stream", |
| 12 | + "text": [ |
| 13 | + "WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.\n", |
| 14 | + "WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.\n", |
| 15 | + "WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.\n", |
| 16 | + "WARNING:root:Limited tf.summary API due to missing TensorBoard installation.\n", |
| 17 | + "WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.\n", |
| 18 | + "WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.\n", |
| 19 | + "WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation.\n" |
| 20 | + ] |
| 21 | + }, |
| 22 | + { |
| 23 | + "name": "stdout", |
| 24 | + "output_type": "stream", |
| 25 | + "text": [ |
| 26 | + "WARNING:tensorflow:From C:\\Users\\Ankesh Kumar\\anaconda3\\envs\\tfbase\\lib\\site-packages\\tensorflow\\python\\compat\\v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.\n", |
| 27 | + "Instructions for updating:\n", |
| 28 | + "non-resource variables are not supported in the long term\n" |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "name": "stderr", |
| 33 | + "output_type": "stream", |
| 34 | + "text": [ |
| 35 | + "WARNING:tensorflow:From C:\\Users\\Ankesh Kumar\\anaconda3\\envs\\tfbase\\lib\\site-packages\\tensorflow\\python\\compat\\v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version.\n", |
| 36 | + "Instructions for updating:\n", |
| 37 | + "non-resource variables are not supported in the long term\n" |
| 38 | + ] |
| 39 | + }, |
| 40 | + { |
| 41 | + "name": "stdout", |
| 42 | + "output_type": "stream", |
| 43 | + "text": [ |
| 44 | + "curses is not supported on this machine (please install/reinstall curses for an optimal experience)\n" |
| 45 | + ] |
| 46 | + } |
| 47 | + ], |
9 | 48 | "source": [
|
10 | 49 | "import nltk\n",
|
11 | 50 | "from nltk.stem.lancaster import LancasterStemmer\n",
|
|
21 | 60 | {
|
22 | 61 | "cell_type": "code",
|
23 | 62 | "execution_count": 2,
|
24 |
| - "id": "broadband-country", |
| 63 | + "id": "greater-keeping", |
25 | 64 | "metadata": {},
|
26 | 65 | "outputs": [],
|
27 | 66 | "source": [
|
|
41 | 80 | },
|
42 | 81 | {
|
43 | 82 | "cell_type": "code",
|
44 |
| - "execution_count": null, |
45 |
| - "id": "ruled-seating", |
| 83 | + "execution_count": 3, |
| 84 | + "id": "liberal-valve", |
46 | 85 | "metadata": {},
|
47 |
| - "outputs": [], |
| 86 | + "outputs": [ |
| 87 | + { |
| 88 | + "name": "stdout", |
| 89 | + "output_type": "stream", |
| 90 | + "text": [ |
| 91 | + "WARNING:tensorflow:From C:\\Users\\Ankesh Kumar\\anaconda3\\envs\\tfbase\\lib\\site-packages\\tflearn\\initializations.py:164: calling TruncatedNormal.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.\n", |
| 92 | + "Instructions for updating:\n", |
| 93 | + "Call initializer instance with the dtype argument instead of passing it to the constructor\n" |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "name": "stderr", |
| 98 | + "output_type": "stream", |
| 99 | + "text": [ |
| 100 | + "WARNING:tensorflow:From C:\\Users\\Ankesh Kumar\\anaconda3\\envs\\tfbase\\lib\\site-packages\\tflearn\\initializations.py:164: calling TruncatedNormal.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.\n", |
| 101 | + "Instructions for updating:\n", |
| 102 | + "Call initializer instance with the dtype argument instead of passing it to the constructor\n" |
| 103 | + ] |
| 104 | + } |
| 105 | + ], |
48 | 106 | "source": [
|
49 | 107 | "# Build neural network\n",
|
50 | 108 | "net = tflearn.input_data(shape=[None, len(train_x[0])])\n",
|
|
60 | 118 | {
|
61 | 119 | "cell_type": "code",
|
62 | 120 | "execution_count": 4,
|
63 |
| - "id": "empirical-palace", |
| 121 | + "id": "fabulous-herald", |
64 | 122 | "metadata": {},
|
65 | 123 | "outputs": [],
|
66 | 124 | "source": [
|
|
89 | 147 | },
|
90 | 148 | {
|
91 | 149 | "cell_type": "code",
|
92 |
| - "execution_count": 7, |
93 |
| - "id": "naval-criticism", |
| 150 | + "execution_count": 5, |
| 151 | + "id": "typical-rental", |
94 | 152 | "metadata": {},
|
95 | 153 | "outputs": [
|
96 | 154 | {
|
|
111 | 169 | },
|
112 | 170 | {
|
113 | 171 | "cell_type": "code",
|
114 |
| - "execution_count": null, |
115 |
| - "id": "practical-internet", |
| 172 | + "execution_count": 6, |
| 173 | + "id": "headed-marks", |
116 | 174 | "metadata": {},
|
117 |
| - "outputs": [], |
| 175 | + "outputs": [ |
| 176 | + { |
| 177 | + "name": "stdout", |
| 178 | + "output_type": "stream", |
| 179 | + "text": [ |
| 180 | + "INFO:tensorflow:Restoring parameters from C:\\Users\\Ankesh Kumar\\UtilProject\\model.tflearn\n" |
| 181 | + ] |
| 182 | + }, |
| 183 | + { |
| 184 | + "name": "stderr", |
| 185 | + "output_type": "stream", |
| 186 | + "text": [ |
| 187 | + "INFO:tensorflow:Restoring parameters from C:\\Users\\Ankesh Kumar\\UtilProject\\model.tflearn\n" |
| 188 | + ] |
| 189 | + } |
| 190 | + ], |
118 | 191 | "source": [
|
119 | 192 | "model.load('./model.tflearn')"
|
120 | 193 | ]
|
121 | 194 | },
|
122 | 195 | {
|
123 | 196 | "cell_type": "code",
|
124 |
| - "execution_count": 9, |
125 |
| - "id": "close-mortality", |
| 197 | + "execution_count": 7, |
| 198 | + "id": "suitable-fitness", |
126 | 199 | "metadata": {},
|
127 | 200 | "outputs": [],
|
128 | 201 | "source": [
|
|
168 | 241 | },
|
169 | 242 | {
|
170 | 243 | "cell_type": "code",
|
171 |
| - "execution_count": 10, |
172 |
| - "id": "original-fifth", |
| 244 | + "execution_count": 8, |
| 245 | + "id": "innovative-auction", |
173 | 246 | "metadata": {},
|
174 | 247 | "outputs": [
|
175 | 248 | {
|
176 | 249 | "data": {
|
177 | 250 | "text/plain": [
|
178 |
| - "[('opentoday', 0.9936719)]" |
| 251 | + "[('opentoday', 0.7488097), ('today', 0.25112572)]" |
179 | 252 | ]
|
180 | 253 | },
|
181 |
| - "execution_count": 10, |
| 254 | + "execution_count": 8, |
182 | 255 | "metadata": {},
|
183 | 256 | "output_type": "execute_result"
|
184 | 257 | }
|
|
189 | 262 | },
|
190 | 263 | {
|
191 | 264 | "cell_type": "code",
|
192 |
| - "execution_count": 11, |
193 |
| - "id": "binary-richards", |
| 265 | + "execution_count": 9, |
| 266 | + "id": "boring-cooper", |
194 | 267 | "metadata": {},
|
195 | 268 | "outputs": [
|
196 | 269 | {
|
|
207 | 280 | },
|
208 | 281 | {
|
209 | 282 | "cell_type": "code",
|
210 |
| - "execution_count": 12, |
211 |
| - "id": "focal-publisher", |
| 283 | + "execution_count": 10, |
| 284 | + "id": "pursuant-hamilton", |
212 | 285 | "metadata": {},
|
213 | 286 | "outputs": [
|
214 | 287 | {
|
215 | 288 | "name": "stdout",
|
216 | 289 | "output_type": "stream",
|
217 | 290 | "text": [
|
218 |
| - "See you later, thanks for visiting\n" |
| 291 | + "Bye! Come back again soon.\n" |
219 | 292 | ]
|
220 | 293 | }
|
221 | 294 | ],
|
|
225 | 298 | },
|
226 | 299 | {
|
227 | 300 | "cell_type": "code",
|
228 |
| - "execution_count": 13, |
229 |
| - "id": "serial-seeker", |
| 301 | + "execution_count": 11, |
| 302 | + "id": "exempt-proxy", |
230 | 303 | "metadata": {},
|
231 | 304 | "outputs": [
|
232 | 305 | {
|
|
235 | 308 | "{}"
|
236 | 309 | ]
|
237 | 310 | },
|
238 |
| - "execution_count": 13, |
| 311 | + "execution_count": 11, |
239 | 312 | "metadata": {},
|
240 | 313 | "output_type": "execute_result"
|
241 | 314 | }
|
|
246 | 319 | },
|
247 | 320 | {
|
248 | 321 | "cell_type": "code",
|
249 |
| - "execution_count": 14, |
250 |
| - "id": "activated-ridge", |
| 322 | + "execution_count": 12, |
| 323 | + "id": "whole-politics", |
251 | 324 | "metadata": {},
|
252 | 325 | "outputs": [
|
253 | 326 | {
|
|
264 | 337 | },
|
265 | 338 | {
|
266 | 339 | "cell_type": "code",
|
267 |
| - "execution_count": 20, |
268 |
| - "id": "appropriate-atlantic", |
| 340 | + "execution_count": 13, |
| 341 | + "id": "collectible-occasions", |
269 | 342 | "metadata": {},
|
270 | 343 | "outputs": [
|
271 | 344 | {
|
272 | 345 | "name": "stdout",
|
273 | 346 | "output_type": "stream",
|
274 | 347 | "text": [
|
275 |
| - "My pleasure\n" |
| 348 | + "Any time!\n" |
276 | 349 | ]
|
277 | 350 | }
|
278 | 351 | ],
|
279 | 352 | "source": [
|
280 | 353 | "response(\"thanks, your great\")"
|
281 | 354 | ]
|
| 355 | + }, |
| 356 | + { |
| 357 | + "cell_type": "code", |
| 358 | + "execution_count": null, |
| 359 | + "id": "molecular-queen", |
| 360 | + "metadata": {}, |
| 361 | + "outputs": [ |
| 362 | + { |
| 363 | + "name": "stdout", |
| 364 | + "output_type": "stream", |
| 365 | + "text": [ |
| 366 | + " * Serving Flask app \"__main__\" (lazy loading)\n", |
| 367 | + " * Environment: production\n", |
| 368 | + " WARNING: This is a development server. Do not use it in a production deployment.\n", |
| 369 | + " Use a production WSGI server instead.\n", |
| 370 | + " * Debug mode: off\n" |
| 371 | + ] |
| 372 | + }, |
| 373 | + { |
| 374 | + "name": "stderr", |
| 375 | + "output_type": "stream", |
| 376 | + "text": [ |
| 377 | + "INFO:werkzeug: * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)\n" |
| 378 | + ] |
| 379 | + } |
| 380 | + ], |
| 381 | + "source": [ |
| 382 | + "from flask import Flask, jsonify\n", |
| 383 | + "from flask import request \n", |
| 384 | + "from flask_cors import CORS, cross_origin\n", |
| 385 | + "\n", |
| 386 | + "app = Flask(__name__)\n", |
| 387 | + "\n", |
| 388 | + "CORS(app)\n", |
| 389 | + "\n", |
| 390 | + "@app.route(\"/api\", methods=['GET'])\n", |
| 391 | + "def classifydone():\n", |
| 392 | + " ERROR_THRESHOLD = 0.25\n", |
| 393 | + " \n", |
| 394 | + " #sentence = request.json['sentence']\n", |
| 395 | + " sentence = 'is your shop open today?'\n", |
| 396 | + " userID='123'\n", |
| 397 | + " show_details=False\n", |
| 398 | + " # generate probabilities from the model\n", |
| 399 | + " results = classify(sentence)\n", |
| 400 | + " # if we have a classification then find the matching intent tag\n", |
| 401 | + " if results:\n", |
| 402 | + " # loop as long as there are matches to process\n", |
| 403 | + " while results:\n", |
| 404 | + " for i in intents['intents']:\n", |
| 405 | + " # find a tag matching the first result\n", |
| 406 | + " if i['tag'] == results[0][0]:\n", |
| 407 | + " # set context for this intent if necessary\n", |
| 408 | + " if 'context_set' in i:\n", |
| 409 | + " if show_details: print ('context:', i['context_set'])\n", |
| 410 | + " context[userID] = i['context_set']\n", |
| 411 | + "\n", |
| 412 | + " # check if this intent is contextual and applies to this user's conversation\n", |
| 413 | + " if not 'context_filter' in i or \\\n", |
| 414 | + " (userID in context and 'context_filter' in i and i['context_filter'] == context[userID]):\n", |
| 415 | + " if show_details: print ('tag:', i['tag'])\n", |
| 416 | + " # a random response from the intent\n", |
| 417 | + " return jsonify({'task': random.choice(i['responses'])})\n", |
| 418 | + "\n", |
| 419 | + " \n", |
| 420 | + "\n", |
| 421 | + "# def classify_local(sentence):\n", |
| 422 | + "# ERROR_THRESHOLD = 0.25\n", |
| 423 | + " \n", |
| 424 | + "# # generate probabilities from the model\n", |
| 425 | + "# results = model.predict([bow(sentence, words)])[0]\n", |
| 426 | + "# # filter out predictions below a threshold, and provide intent index\n", |
| 427 | + "# results = [[i,r] for i,r in enumerate(results) if r>ERROR_THRESHOLD]\n", |
| 428 | + "# # sort by strength of probability\n", |
| 429 | + "# results.sort(key=lambda x: x[1], reverse=True)\n", |
| 430 | + "# return_list = []\n", |
| 431 | + "# for r in results:\n", |
| 432 | + "# return_list.append((classes[r[0]], str(r[1])))\n", |
| 433 | + "# # return tuple of intent and probability\n", |
| 434 | + " \n", |
| 435 | + "# return return_list\n", |
| 436 | + "\n", |
| 437 | + "# running REST interface\n", |
| 438 | + "if __name__ == \"__main__\":\n", |
| 439 | + " app.run(host='0.0.0.0')" |
| 440 | + ] |
| 441 | + }, |
| 442 | + { |
| 443 | + "cell_type": "code", |
| 444 | + "execution_count": null, |
| 445 | + "id": "french-scheme", |
| 446 | + "metadata": {}, |
| 447 | + "outputs": [], |
| 448 | + "source": [] |
282 | 449 | }
|
283 | 450 | ],
|
284 | 451 | "metadata": {
|
|
0 commit comments