Skip to content

Commit

Permalink
[ENHANCEMENT] Fixes issue #19 partly
Browse files Browse the repository at this point in the history
  • Loading branch information
varunp2k committed Jan 9, 2021
1 parent 256d7fc commit 43ef8bd
Showing 1 changed file with 71 additions and 13 deletions.
84 changes: 71 additions & 13 deletions Ch6/01_CNN_RNN_ATIS_intents.ipynb
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Intent Detection Using CNN & RNN"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"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"
]
},
{
Expand All @@ -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",
Expand All @@ -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"
]
},
{
Expand All @@ -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"
]
},
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -128,7 +147,7 @@
"id": "qckNEPKRo8_V"
},
"source": [
"Loading the test data"
"### Testing Data"
]
},
{
Expand Down Expand Up @@ -200,7 +219,7 @@
"id": "nUZsI3ZmpBA2"
},
"source": [
"Pre-Processing"
"## Data Preprocessing"
]
},
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -698,7 +756,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.6.12"
},
"toc": {
"base_numbering": 1,
Expand Down

0 comments on commit 43ef8bd

Please sign in to comment.