Skip to content

Commit 43ef8bd

Browse files
committed
[ENHANCEMENT] Fixes issue #19 partly
1 parent 256d7fc commit 43ef8bd

File tree

1 file changed

+71
-13
lines changed

1 file changed

+71
-13
lines changed

Ch6/01_CNN_RNN_ATIS_intents.ipynb

+71-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Intent Detection Using CNN & RNN"
8+
]
9+
},
310
{
411
"cell_type": "markdown",
512
"metadata": {
613
"colab_type": "text",
714
"id": "Wz0jLNgTnMwF"
815
},
916
"source": [
10-
"In this notebook we will demonstrate various CNN and RNN models for the task of intent detection on the ATIS dataset. "
17+
"In this notebook we demonstrate various CNN and RNN architectures for the task of intent detection on the ATIS dataset. The ATIS dataset is a standard benchmark dataset for the tast of intent detection. ATIS Stands for Airline Travel Information System. The dataset can we found in the `Data2` folder under the `Data` folder."
18+
]
19+
},
20+
{
21+
"cell_type": "markdown",
22+
"metadata": {},
23+
"source": [
24+
"## Imports"
1125
]
1226
},
1327
{
@@ -33,11 +47,18 @@
3347
}
3448
],
3549
"source": [
36-
"\n",
37-
"#making the necessary imports\n",
50+
"#general imports\n",
3851
"import os\n",
3952
"import sys\n",
53+
"import random\n",
54+
"random.seed(0) #for reproducability of results\n",
55+
"\n",
56+
"#basic imports\n",
4057
"import numpy as np\n",
58+
"import pandas as pd\n",
59+
"\n",
60+
"\n",
61+
"#NN imports\n",
4162
"from keras.preprocessing.text import Tokenizer\n",
4263
"from keras.preprocessing.sequence import pad_sequences\n",
4364
"from keras.utils import to_categorical\n",
@@ -46,13 +67,10 @@
4667
"from keras.models import Model, Sequential\n",
4768
"from keras.initializers import Constant\n",
4869
"\n",
70+
"#encoder\n",
4971
"from sklearn.preprocessing import LabelEncoder\n",
5072
"\n",
51-
"import random\n",
52-
"random.seed(0)#for reproducability of results\n",
53-
"\n",
54-
"import pandas as pd\n",
55-
"import numpy as np"
73+
"\n"
5674
]
5775
},
5876
{
@@ -62,7 +80,9 @@
6280
"id": "LGFhMpnjo4L1"
6381
},
6482
"source": [
65-
"Loading the training data"
83+
"## Data Loading\n",
84+
"We load the data with the help of a few functions from `utils.py` which is included in this repository's Ch6 folder under folder name \"Data\". \n",
85+
"### Training Data\n"
6686
]
6787
},
6888
{
@@ -94,7 +114,6 @@
94114
}
95115
],
96116
"source": [
97-
"#utils is included in this repository'c Ch6 folder under folder name \"Data\"\n",
98117
"from Data.utils import fetch_data, read_method\n",
99118
"\n",
100119
"sents,labels,intents = fetch_data('Data/data2/atis.train.w-intent.iob')\n",
@@ -128,7 +147,7 @@
128147
"id": "qckNEPKRo8_V"
129148
},
130149
"source": [
131-
"Loading the test data"
150+
"### Testing Data"
132151
]
133152
},
134153
{
@@ -200,7 +219,7 @@
200219
"id": "nUZsI3ZmpBA2"
201220
},
202221
"source": [
203-
"Pre-Processing"
222+
"## Data Preprocessing"
204223
]
205224
},
206225
{
@@ -311,6 +330,15 @@
311330
"print('Splitting the train data into train and valid is done')"
312331
]
313332
},
333+
{
334+
"cell_type": "markdown",
335+
"metadata": {},
336+
"source": [
337+
"## Modeling\n",
338+
"### Embedding Matrix\n",
339+
"We need to prepare our embedding."
340+
]
341+
},
314342
{
315343
"cell_type": "code",
316344
"execution_count": 12,
@@ -377,6 +405,13 @@
377405
"print(\"Preparing of embedding matrix is done\")"
378406
]
379407
},
408+
{
409+
"cell_type": "markdown",
410+
"metadata": {},
411+
"source": [
412+
"### CNN with Pre-Trained Embeddings"
413+
]
414+
},
380415
{
381416
"cell_type": "code",
382417
"execution_count": 13,
@@ -457,6 +492,14 @@
457492
"print('Test accuracy with CNN:', acc)"
458493
]
459494
},
495+
{
496+
"cell_type": "markdown",
497+
"metadata": {},
498+
"source": [
499+
"### CNN-Embedding Layer\n",
500+
"Here, we train a CNN model with an embedding layer which is being trained on the fly instead of using the pre-trained embeddings."
501+
]
502+
},
460503
{
461504
"cell_type": "code",
462505
"execution_count": 14,
@@ -536,6 +579,14 @@
536579
"print('Test accuracy with CNN:', acc)\n"
537580
]
538581
},
582+
{
583+
"cell_type": "markdown",
584+
"metadata": {},
585+
"source": [
586+
"### RNN-Embedding Layer\n",
587+
"Here, we train a RNN model with an embedding layer which is being trained on the fly instead of using the pre-trained embeddings."
588+
]
589+
},
539590
{
540591
"cell_type": "code",
541592
"execution_count": 15,
@@ -601,6 +652,13 @@
601652
"print('Test accuracy with RNN:', acc)\n"
602653
]
603654
},
655+
{
656+
"cell_type": "markdown",
657+
"metadata": {},
658+
"source": [
659+
"### LSTM with Pre-Trained Embeddings"
660+
]
661+
},
604662
{
605663
"cell_type": "code",
606664
"execution_count": 16,
@@ -698,7 +756,7 @@
698756
"name": "python",
699757
"nbconvert_exporter": "python",
700758
"pygments_lexer": "ipython3",
701-
"version": "3.8.3"
759+
"version": "3.6.12"
702760
},
703761
"toc": {
704762
"base_numbering": 1,

0 commit comments

Comments
 (0)