diff --git a/Ch6/01_CNN_RNN_ATIS_intents.ipynb b/Ch6/01_CNN_RNN_ATIS_intents.ipynb index b9913d6..f248d19 100644 --- a/Ch6/01_CNN_RNN_ATIS_intents.ipynb +++ b/Ch6/01_CNN_RNN_ATIS_intents.ipynb @@ -1,5 +1,12 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Intent Detection Using CNN & RNN" + ] + }, { "cell_type": "markdown", "metadata": { @@ -7,7 +14,14 @@ "id": "Wz0jLNgTnMwF" }, "source": [ - "In this notebook we will demonstrate various CNN and RNN models for the task of intent detection on the ATIS dataset. " + "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." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Imports" ] }, { @@ -33,11 +47,18 @@ } ], "source": [ - "\n", - "#making the necessary imports\n", + "#general imports\n", "import os\n", "import sys\n", + "import random\n", + "random.seed(0) #for reproducability of results\n", + "\n", + "#basic imports\n", "import numpy as np\n", + "import pandas as pd\n", + "\n", + "\n", + "#NN imports\n", "from keras.preprocessing.text import Tokenizer\n", "from keras.preprocessing.sequence import pad_sequences\n", "from keras.utils import to_categorical\n", @@ -46,13 +67,10 @@ "from keras.models import Model, Sequential\n", "from keras.initializers import Constant\n", "\n", + "#encoder\n", "from sklearn.preprocessing import LabelEncoder\n", "\n", - "import random\n", - "random.seed(0)#for reproducability of results\n", - "\n", - "import pandas as pd\n", - "import numpy as np" + "\n" ] }, { @@ -62,7 +80,9 @@ "id": "LGFhMpnjo4L1" }, "source": [ - "Loading the training data" + "## Data Loading\n", + "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", + "### Training Data\n" ] }, { @@ -94,7 +114,6 @@ } ], "source": [ - "#utils is included in this repository'c Ch6 folder under folder name \"Data\"\n", "from Data.utils import fetch_data, read_method\n", "\n", "sents,labels,intents = fetch_data('Data/data2/atis.train.w-intent.iob')\n", @@ -128,7 +147,7 @@ "id": "qckNEPKRo8_V" }, "source": [ - "Loading the test data" + "### Testing Data" ] }, { @@ -200,7 +219,7 @@ "id": "nUZsI3ZmpBA2" }, "source": [ - "Pre-Processing" + "## Data Preprocessing" ] }, { @@ -311,6 +330,15 @@ "print('Splitting the train data into train and valid is done')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Modeling\n", + "### Embedding Matrix\n", + "We need to prepare our embedding." + ] + }, { "cell_type": "code", "execution_count": 12, @@ -377,6 +405,13 @@ "print(\"Preparing of embedding matrix is done\")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### CNN with Pre-Trained Embeddings" + ] + }, { "cell_type": "code", "execution_count": 13, @@ -457,6 +492,14 @@ "print('Test accuracy with CNN:', acc)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### CNN-Embedding Layer\n", + "Here, we train a CNN model with an embedding layer which is being trained on the fly instead of using the pre-trained embeddings." + ] + }, { "cell_type": "code", "execution_count": 14, @@ -536,6 +579,14 @@ "print('Test accuracy with CNN:', acc)\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### RNN-Embedding Layer\n", + "Here, we train a RNN model with an embedding layer which is being trained on the fly instead of using the pre-trained embeddings." + ] + }, { "cell_type": "code", "execution_count": 15, @@ -601,6 +652,13 @@ "print('Test accuracy with RNN:', acc)\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### LSTM with Pre-Trained Embeddings" + ] + }, { "cell_type": "code", "execution_count": 16, @@ -698,7 +756,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.3" + "version": "3.6.12" }, "toc": { "base_numbering": 1,