{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "disaster_identification_using_tweeter_colab.ipynb",
      "provenance": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/mrm8488/shared_colab_notebooks/blob/master/disaster_identification_using_tweeter_colab.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "hgnclTMx5EcE",
        "colab_type": "text"
      },
      "source": [
        "# Identifying and categorizing the disaster-related tweets\n",
        "Semantic, temporal and spatial context , using natural language processing ,Deep Learning and spatial analysis.\n",
        "\n",
        "> code based on https://github.com/khordoo/disaster-watch-classifier\n",
        ">> Colab creator [mrm8488](https://twitter.com/mrm8488)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "F7FwnTtm5Ku2",
        "colab_type": "text"
      },
      "source": [
        "## 0. Getting the dataset"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "JbUIcERc4fh9",
        "colab_type": "code",
        "outputId": "510dc6dc-c434-4fc9-f14a-553ced1d99ed",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 217
        }
      },
      "source": [
        "!wget https://raw.githubusercontent.com/khordoo/disaster-watch-classifier/master/datasets/combined.csv"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "--2020-01-09 21:19:30--  https://raw.githubusercontent.com/khordoo/disaster-watch-classifier/master/datasets/combined.csv\n",
            "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...\n",
            "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.\n",
            "HTTP request sent, awaiting response... 200 OK\n",
            "Length: 9998295 (9.5M) [text/plain]\n",
            "Saving to: ‘combined.csv.1’\n",
            "\n",
            "\rcombined.csv.1        0%[                    ]       0  --.-KB/s               \rcombined.csv.1       18%[==>                 ]   1.75M  8.75MB/s               \rcombined.csv.1       59%[==========>         ]   5.69M  14.2MB/s               \rcombined.csv.1      100%[===================>]   9.53M  18.5MB/s    in 0.5s    \n",
            "\n",
            "2020-01-09 21:19:30 (18.5 MB/s) - ‘combined.csv.1’ saved [9998295/9998295]\n",
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qplIKFZE5l6e",
        "colab_type": "text"
      },
      "source": [
        "## 1. Setup and Imports"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2I-cCMRv5Das",
        "colab_type": "code",
        "outputId": "ebf7e0d3-e7cb-48f2-fc50-500bf19d16cf",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 54
        }
      },
      "source": [
        "try:\n",
        "  # %tensorflow_version only exists in Colab.\n",
        "  %tensorflow_version 2.x\n",
        "except Exception:\n",
        "  pass\n",
        "\n",
        "# Load the TensorBoard notebook extension\n",
        "%load_ext tensorboard"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "The tensorboard extension is already loaded. To reload it, use:\n",
            "  %reload_ext tensorboard\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "tqI3LUFQ6mQC",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "%matplotlib inline\n",
        "\n",
        "import os\n",
        "import numpy as np\n",
        "import pandas as pd\n",
        "import spacy\n",
        "import matplotlib.pyplot as plt\n",
        "import tensorflow as tf\n",
        "from sklearn.base import TransformerMixin ,BaseEstimator\n",
        "from sklearn.pipeline import Pipeline\n",
        "from sklearn.preprocessing import LabelEncoder\n",
        "from sklearn.model_selection import train_test_split\n",
        "from tensorflow.keras.utils import to_categorical\n",
        "from tensorflow.keras.models import Sequential ,model_from_json\n",
        "from tensorflow.keras.layers import Embedding,Dense,Dropout ,GlobalMaxPool1D, GRU\n",
        "from IPython.display import clear_output\n",
        "from google.colab import  files\n",
        "from tensorflow.keras.wrappers.scikit_learn import KerasClassifier\n",
        "from sklearn.model_selection import RandomizedSearchCV"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2w0u3Vfb8I_w",
        "colab_type": "text"
      },
      "source": [
        "## 2. Visualize data"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wWCjc27e7DvB",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "df = pd.read_csv(\"combined.csv\")"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wcsyXgb67lfi",
        "colab_type": "code",
        "outputId": "d64445ef-4e6c-48a1-d594-171dedceb90d",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 348
        }
      },
      "source": [
        "df.head(10)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Unnamed: 0</th>\n",
              "      <th>tweet id</th>\n",
              "      <th>tweet</th>\n",
              "      <th>label</th>\n",
              "      <th>category</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>0</td>\n",
              "      <td>'348351442404376578'</td>\n",
              "      <td>@Jay1972Jay Nope. Mid 80's. It's off Metallica...</td>\n",
              "      <td>off-topic</td>\n",
              "      <td>floods</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>1</td>\n",
              "      <td>'348167215536803841'</td>\n",
              "      <td>Nothing like a :16 second downpour to give us ...</td>\n",
              "      <td>off-topic</td>\n",
              "      <td>floods</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>2</td>\n",
              "      <td>'348644655786778624'</td>\n",
              "      <td>@NelsonTagoona so glad that you missed the flo...</td>\n",
              "      <td>on-topic</td>\n",
              "      <td>floods</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>3</td>\n",
              "      <td>'350519668815036416'</td>\n",
              "      <td>Party hard , suns down , still warm , lovin li...</td>\n",
              "      <td>off-topic</td>\n",
              "      <td>floods</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>4</td>\n",
              "      <td>'351446519733432320'</td>\n",
              "      <td>@Exclusionzone if you compare yourself to wate...</td>\n",
              "      <td>off-topic</td>\n",
              "      <td>floods</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>5</th>\n",
              "      <td>5</td>\n",
              "      <td>'349528038817546241'</td>\n",
              "      <td>and is usually viewed in a #heroic light, rece...</td>\n",
              "      <td>off-topic</td>\n",
              "      <td>floods</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>6</td>\n",
              "      <td>'351467497318387713'</td>\n",
              "      <td>You thought there was more to us but you knew ...</td>\n",
              "      <td>off-topic</td>\n",
              "      <td>floods</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>7</td>\n",
              "      <td>'349946283395530752'</td>\n",
              "      <td>'Canada' appeared on Tuesday 25 at the 18th pl...</td>\n",
              "      <td>off-topic</td>\n",
              "      <td>floods</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>8</td>\n",
              "      <td>'350124639705497601'</td>\n",
              "      <td>I #can't tell you how many times I had this re...</td>\n",
              "      <td>off-topic</td>\n",
              "      <td>floods</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>9</th>\n",
              "      <td>9</td>\n",
              "      <td>'351785290446299136'</td>\n",
              "      <td>I'm at Land &amp;amp; Sea (Calgary, Alberta) http:...</td>\n",
              "      <td>off-topic</td>\n",
              "      <td>floods</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "   Unnamed: 0              tweet id  ...      label category\n",
              "0           0  '348351442404376578'  ...  off-topic   floods\n",
              "1           1  '348167215536803841'  ...  off-topic   floods\n",
              "2           2  '348644655786778624'  ...   on-topic   floods\n",
              "3           3  '350519668815036416'  ...  off-topic   floods\n",
              "4           4  '351446519733432320'  ...  off-topic   floods\n",
              "5           5  '349528038817546241'  ...  off-topic   floods\n",
              "6           6  '351467497318387713'  ...  off-topic   floods\n",
              "7           7  '349946283395530752'  ...  off-topic   floods\n",
              "8           8  '350124639705497601'  ...  off-topic   floods\n",
              "9           9  '351785290446299136'  ...  off-topic   floods\n",
              "\n",
              "[10 rows x 5 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 11
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Bg8gEE-z7tKL",
        "colab_type": "code",
        "outputId": "fb374221-f99f-473c-cc9d-598f678b53bb",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 199
        }
      },
      "source": [
        "df.info()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "<class 'pandas.core.frame.DataFrame'>\n",
            "RangeIndex: 69139 entries, 0 to 69138\n",
            "Data columns (total 5 columns):\n",
            "Unnamed: 0    69139 non-null int64\n",
            "tweet id      69139 non-null object\n",
            " tweet        69139 non-null object\n",
            " label        69139 non-null object\n",
            "category      69139 non-null object\n",
            "dtypes: int64(1), object(4)\n",
            "memory usage: 2.6+ MB\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ixrxSAg771XG",
        "colab_type": "code",
        "outputId": "21edaef3-ddc1-471c-fa43-61f6e277273a",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 288
        }
      },
      "source": [
        "df.describe()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Unnamed: 0</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>count</th>\n",
              "      <td>69139.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>mean</th>\n",
              "      <td>34569.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>std</th>\n",
              "      <td>19958.854468</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>min</th>\n",
              "      <td>0.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>25%</th>\n",
              "      <td>17284.500000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>50%</th>\n",
              "      <td>34569.000000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>75%</th>\n",
              "      <td>51853.500000</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>max</th>\n",
              "      <td>69138.000000</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "         Unnamed: 0\n",
              "count  69139.000000\n",
              "mean   34569.000000\n",
              "std    19958.854468\n",
              "min        0.000000\n",
              "25%    17284.500000\n",
              "50%    34569.000000\n",
              "75%    51853.500000\n",
              "max    69138.000000"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 13
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "VrEMnn2b8UjT",
        "colab_type": "text"
      },
      "source": [
        "## 3. Data Loading"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wAjskJ8A8WnM",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "class DatasetExtractor(BaseEstimator,TransformerMixin):\n",
        "    \"\"\"Extractor class that loads multiple Tweeter files in csv format.\"\"\"\n",
        "    \n",
        "    COMBINDED_DATASET='combined.csv'\n",
        "    \n",
        "    def transform(self,X,y=None):\n",
        "        return self.hot_load()\n",
        "    \n",
        "    def hot_load(self):\n",
        "        \"\"\"Loads the pre-combined file if exists otherwise load all the files\"\"\"\n",
        "        combined_file_path='combined.csv'\n",
        "        if os.path.isfile(combined_file_path):\n",
        "            print('File Exists.Reloaded.')\n",
        "            return pd.read_csv(combined_file_path, index_col=0)\n",
        "        print('Loading Files..')\n",
        "        combined_dataset=load_data()\n",
        "        combined_dataset.to_csv(combined_file_path)\n",
        "        return combined_dataset\n",
        "    \n",
        "    def load_data(self):\n",
        "        \"\"\"Loads multiple disaster related tweet file and returns a Single Pandas data frame\"\"\"    \n",
        "        combined_dataset=pd.DataFrame()\n",
        "        for file_name in os.listdir(path=DATA_DIRECTORY):\n",
        "            category=extract_category_name(file_name)\n",
        "            df=pd.read_csv(f'{file_name}')\n",
        "            df['category']= category    \n",
        "            combined_dataset=combined_dataset.append(df,ignore_index = True)\n",
        "        return  combined_dataset  \n",
        "    \n",
        "    def extract_category_name(self,file_name):\n",
        "        \"\"\"Helper method that extracts the Disaster Category from the file name\"\"\"\n",
        "        category=file_name.split('.')[0]\n",
        "        if '_' in category:\n",
        "            category=category.split('_')[0]\n",
        "        return category "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "kYAnmSMU8vKz",
        "colab_type": "text"
      },
      "source": [
        "## 4. Data Cleaning"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8_-1souy8yT_",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "class DatasetCleaner(BaseEstimator,TransformerMixin):\n",
        "    \"\"\"Removes Redundent features and rows with missing values\"\"\"\n",
        "    def transform(self,X,y=None):\n",
        "        columns=X.columns.tolist()\n",
        "        X.columns=[column.strip() for column in columns]\n",
        "        X=X.drop('tweet id',axis=1)\n",
        "        X=X.dropna()\n",
        "        X['tweet']=X['tweet'].str.replace('@', '')\n",
        "        X['tweet']=X['tweet'].str.replace('#', '')\n",
        "        X['tweet']=X['tweet'].str.replace('http\\S+', '',regex=True)\n",
        "        X['tweet']=X['tweet'].str.strip()\n",
        "        X['tweet']=X['tweet'].str.lower()        \n",
        "        return X"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "a0Vge6AS9Zfa",
        "colab_type": "text"
      },
      "source": [
        "## 5. Data Distribution"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "sUjMzVUb9daE",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "class DistributionValidSampler(BaseEstimator,TransformerMixin):\n",
        "    \"\"\"Samples the (related and random ) tweets with equal proportion\"\"\"\n",
        "    def __init__(self,unrelated_size=None ,ignore_unrelated_proportion=True):\n",
        "        self._unrelated_size=unrelated_size\n",
        "        self._ignore_unrelated_proportion=ignore_unrelated_proportion\n",
        "\n",
        "        \n",
        "    def transform(self,X,y=None):\n",
        "        #Shuffle tweets\n",
        "        X_=X.sample(frac=1).reset_index(drop=True)\n",
        "        \n",
        "        X_=self._label_categories(X_)  \n",
        "        related,unrelated =self._equal_split(X_)\n",
        "        X_=self._merge(related,unrelated)\n",
        "        X_=X_.drop('category',axis=1)       \n",
        "        return X_\n",
        "    \n",
        "    def _label_categories(self,X):\n",
        "        \"\"\"Assings the category name to on-topic tweets and unrelated to off-topic tweets in \n",
        "         each category\n",
        "        \"\"\"\n",
        "        \n",
        "        if self._ignore_unrelated_proportion:\n",
        "            X['label']=X.apply(lambda row: row['category'] if 'on-topic' in row['label'] else 'unrelated',axis=1 ) \n",
        "        else:\n",
        "            X['label']=X.apply(lambda row: row['category'] if 'on-topic' in row['label'] else 'unrelated_'+row['category'],axis=1 )  \n",
        "        return X\n",
        "    \n",
        "    def _equal_split(self,X):\n",
        "        \"\"\"Splits the dataset into related and unrelated tweets.\n",
        "          This ensures that the number of unrelated tweets are not too high and \n",
        "          is in reasonable range.\n",
        "        \"\"\"\n",
        "        related=X[X['label'].str.contains('unrelated')==False]\n",
        "        unrelated=X[X['label'].str.contains('unrelated')]\n",
        "        ave_tweets=self._average_tweet_per_category(X)\n",
        "        unrelated=self._slice(unrelated,size=self._unrelated_size ,ave_size=ave_tweets)\n",
        "        return related,unrelated\n",
        "    \n",
        "    def _merge(self,X1,X2):\n",
        "        \"\"\"Merges the dataframes toghether\"\"\"\n",
        "        X=pd.DataFrame()\n",
        "        X=X.append(X1)\n",
        "        X=X.append(X2)\n",
        "        return X\n",
        "    \n",
        "    def _slice(self,X, size ,ave_size):\n",
        "        \"\"\"Extracts a subset of rows from a dataframe\"\"\"\n",
        "        if size is None:\n",
        "            size =ave_size\n",
        "        if size < X.shape[0]:\n",
        "            return X[:size]\n",
        "        return X    \n",
        "    \n",
        "    def _average_tweet_per_category(self,X):\n",
        "        \"\"\"Calculate the average number of tweets across all tweet categories\"\"\"\n",
        "        category_values=pd.DataFrame(X['label'].value_counts())\n",
        "        category_values=category_values.drop('unrelated',axis=0)\n",
        "        return int(category_values['label'].mean())"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "m0OJaf7w-sHF",
        "colab_type": "text"
      },
      "source": [
        "## 6. Data Transformation"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MK5Ti8Ft-x1d",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "class TextTokenizer(BaseEstimator,TransformerMixin):\n",
        "    \n",
        "    def __init__(self,pad_sequences,num_words=10000,max_length=100,max_pad_length=100 ):\n",
        "        self._num_words=num_words\n",
        "        self.max_length=max_length\n",
        "        self._tokenizer=None\n",
        "        self._pad_sequences=pad_sequences\n",
        "        self._max_pad_length=max_pad_length\n",
        "        self.vocab_size=None\n",
        "        self.tokenizer=None\n",
        "        \n",
        "    def transform(self,X,y=None):\n",
        "        self.tokenizer,self.vocab_size=self._get_tokenizer(X['tweet'])\n",
        "        X['tweet_encoded']=self.tokenizer.texts_to_sequences(X['tweet'])\n",
        "        X['tweet_encoded']= X['tweet_encoded'].apply(lambda x: self._pad_sequences([x],maxlen=self._max_pad_length ,padding='post')[0])\n",
        "        \n",
        "        return X\n",
        "    def _get_tokenizer(self,X):\n",
        "        tokenizer=tf.keras.preprocessing.text.Tokenizer(num_words=self._num_words)\n",
        "        tokenizer.fit_on_texts(X)\n",
        "        vocab_size=len(tokenizer.word_index)+1\n",
        "        return tokenizer,vocab_size"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "PtBFcIDK_O_f",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "class LabelOneHotEncoder(BaseEstimator,TransformerMixin):\n",
        "    def __init__(self):\n",
        "        self.label_encoder=None\n",
        "        self.one_hot_encoder=None\n",
        "        \n",
        "    def transform(self,X,y=None):\n",
        "        self.label_encoder=LabelEncoder().fit(X['label'])\n",
        "        self.one_hot_encoder=to_categorical\n",
        "        num_classes=len(set(X['label']))\n",
        "        X['label_encoded']= self.label_encoder.transform(X['label'].values)\n",
        "        X['label_one_hot']= X['label_encoded'].apply(lambda x: self.one_hot_encoder([x],num_classes=num_classes)[0])   \n",
        "        \n",
        "        return X"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "trB1X5sG_keL",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "class PassThroughTransformer(BaseEstimator,TransformerMixin):\n",
        "    \"\"\"Pass Through Trasformer to by pass the sklean pipleline limitation \"\"\"\n",
        "    def transform(self,X,y=None):\n",
        "        return X\n",
        "    def fit(self,X,y=None):\n",
        "        return X"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "t9q2SKKU_tbc",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "pipeline =Pipeline(steps=[\n",
        "    ('extractor',DatasetExtractor()),\n",
        "    ('cleaner',DatasetCleaner()),\n",
        "    ('distribution-validator',DistributionValidSampler(unrelated_size=None ,ignore_unrelated_proportion=True)),\n",
        "    ('tokenizer',TextTokenizer(tf.keras.preprocessing.sequence.pad_sequences)),\n",
        "    ('one-hot-encoder',LabelOneHotEncoder()),\n",
        "    ('pass-through',PassThroughTransformer()),\n",
        "    \n",
        "])"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qjkSWlOLOAKp",
        "colab_type": "code",
        "outputId": "38b2157b-4026-4cf5-eb3b-7bd4c97679ac",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "cleaned=pipeline.transform(None)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "File Exists.Reloaded.\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "27XnF51cOEH3",
        "colab_type": "code",
        "outputId": "79e2dbc6-425c-471f-972c-59a60f36b00b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 348
        }
      },
      "source": [
        "cleaned.head(10)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>tweet</th>\n",
              "      <th>label</th>\n",
              "      <th>tweet_encoded</th>\n",
              "      <th>label_encoded</th>\n",
              "      <th>label_one_hot</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>6</th>\n",
              "      <td>rt brooksmatic: on scanner: first suspect had ...</td>\n",
              "      <td>bombing</td>\n",
              "      <td>[2, 15, 1767, 179, 125, 236, 2347, 3366, 15, 4...</td>\n",
              "      <td>0</td>\n",
              "      <td>[1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>7</th>\n",
              "      <td>australia we should be so proud of the hero's ...</td>\n",
              "      <td>floods</td>\n",
              "      <td>[43, 41, 230, 32, 42, 779, 5, 1, 3, 1, 9, 908,...</td>\n",
              "      <td>3</td>\n",
              "      <td>[0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>8</th>\n",
              "      <td>i don't care about the tornado ripping up the ...</td>\n",
              "      <td>tornado</td>\n",
              "      <td>[11, 123, 602, 62, 1, 34, 9172, 50, 1, 106, 18...</td>\n",
              "      <td>5</td>\n",
              "      <td>[0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>14</th>\n",
              "      <td>pray for chile  prayforchile earthquakechile e...</td>\n",
              "      <td>earthquake</td>\n",
              "      <td>[151, 8, 111, 326, 6768, 25, 0, 0, 0, 0, 0, 0,...</td>\n",
              "      <td>1</td>\n",
              "      <td>[0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>15</th>\n",
              "      <td>rt corymonteith: heartbreaking news coming out...</td>\n",
              "      <td>tornado</td>\n",
              "      <td>[2, 9173, 1064, 56, 311, 35, 5, 24, 41, 74, 27...</td>\n",
              "      <td>5</td>\n",
              "      <td>[0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>17</th>\n",
              "      <td>all quiet on the chelsea front. hurricanesandy...</td>\n",
              "      <td>hurricane</td>\n",
              "      <td>[27, 2124, 15, 1, 4129, 1040, 874, 7778, 5, 0,...</td>\n",
              "      <td>4</td>\n",
              "      <td>[0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>18</th>\n",
              "      <td>rt guardian: new south wales braces for river ...</td>\n",
              "      <td>floods</td>\n",
              "      <td>[2, 830, 76, 206, 327, 290, 8, 153, 387, 33, 3...</td>\n",
              "      <td>3</td>\n",
              "      <td>[0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>19</th>\n",
              "      <td>prayforchile prayforindonesia save us god.. sa...</td>\n",
              "      <td>earthquake</td>\n",
              "      <td>[326, 2978, 962, 106, 157, 962, 7, 717, 0, 0, ...</td>\n",
              "      <td>1</td>\n",
              "      <td>[0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>20</th>\n",
              "      <td>at least 200 people injured in west, texas, pl...</td>\n",
              "      <td>explosion</td>\n",
              "      <td>[18, 198, 483, 31, 133, 3, 46, 19, 38, 14, 824...</td>\n",
              "      <td>2</td>\n",
              "      <td>[0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0]</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>23</th>\n",
              "      <td>'the amazing spider-man 2' crawls into the 201...</td>\n",
              "      <td>earthquake</td>\n",
              "      <td>[2979, 182, 5062, 208, 9174, 9175, 296, 1, 117...</td>\n",
              "      <td>1</td>\n",
              "      <td>[0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0]</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ],
            "text/plain": [
              "                                                tweet  ...                        label_one_hot\n",
              "6   rt brooksmatic: on scanner: first suspect had ...  ...  [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n",
              "7   australia we should be so proud of the hero's ...  ...  [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]\n",
              "8   i don't care about the tornado ripping up the ...  ...  [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0]\n",
              "14  pray for chile  prayforchile earthquakechile e...  ...  [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n",
              "15  rt corymonteith: heartbreaking news coming out...  ...  [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0]\n",
              "17  all quiet on the chelsea front. hurricanesandy...  ...  [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0]\n",
              "18  rt guardian: new south wales braces for river ...  ...  [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]\n",
              "19  prayforchile prayforindonesia save us god.. sa...  ...  [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n",
              "20  at least 200 people injured in west, texas, pl...  ...  [0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0]\n",
              "23  'the amazing spider-man 2' crawls into the 201...  ...  [0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n",
              "\n",
              "[10 rows x 5 columns]"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 23
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "pB3h7ZNRMdii",
        "colab_type": "code",
        "outputId": "11128e02-aa01-41c2-b385-b41c948912f8",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "cleaned.tweet[0]"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'trirawrr fuck! i was just being generous :( but still can you buy me them?? pretty please hansamu!'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 27
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "aRFkGiazOubA",
        "colab_type": "text"
      },
      "source": [
        "## 7. Train Validation set"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "8vjWcJ9FOMp_",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "test_size = 0.3\n",
        "X_train,X_test,y_train,y_test =train_test_split(cleaned['tweet_encoded'],cleaned['label_one_hot'],test_size=test_size,stratify=cleaned['label_encoded'])"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "OlOdjrgtPLZM",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "X_train=np.array(X_train.values.tolist())\n",
        "X_test=np.array(X_test.values.tolist())\n",
        "y_train=np.array(y_train.values.tolist())\n",
        "y_test=np.array(y_test.values.tolist())"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LgPi5vEtPMwZ",
        "colab_type": "code",
        "outputId": "7ae02e32-c50c-4f01-8786-ad832356ba9f",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 181
        }
      },
      "source": [
        "print(X_train[0])\n",
        "print(X_train.shape)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[   2  202   21    1   76  612    2 1080  116   76  161 1075    5   13\n",
            "   52  125  161  105    0    0    0    0    0    0    0    0    0    0\n",
            "    0    0    0    0    0    0    0    0    0    0    0    0    0    0\n",
            "    0    0    0    0    0    0    0    0    0    0    0    0    0    0\n",
            "    0    0    0    0    0    0    0    0    0    0    0    0    0    0\n",
            "    0    0    0    0    0    0    0    0    0    0    0    0    0    0\n",
            "    0    0    0    0    0    0    0    0    0    0    0    0    0    0\n",
            "    0    0]\n",
            "(30250, 100)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rtjvKxkMPRFG",
        "colab_type": "code",
        "outputId": "1aacc34f-860e-4134-9b51-e86914094bc5",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 54
        }
      },
      "source": [
        "print(y_train[0])\n",
        "print(y_train.shape)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[1. 0. 0. 0. 0. 0. 0.]\n",
            "(30250, 7)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ZyPNT37kPvO6",
        "colab_type": "text"
      },
      "source": [
        "## 8. Modeling"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rS4pV6rgPyMg",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "class PlotLosses(tf.keras.callbacks.Callback):\n",
        "    def on_train_begin(self, logs={}):\n",
        "        self.i = 0\n",
        "        self.x = []\n",
        "        self.losses = []\n",
        "        self.val_losses = []\n",
        "        \n",
        "        self.fig = plt.figure()\n",
        "        \n",
        "        self.logs = []\n",
        "\n",
        "    def on_epoch_end(self, epoch, logs={}):\n",
        "        \n",
        "        self.logs.append(logs)\n",
        "        self.x.append(self.i)\n",
        "        self.losses.append(logs.get('loss'))\n",
        "        self.val_losses.append(logs.get('val_loss'))\n",
        "        self.i += 1\n",
        "        \n",
        "        clear_output(wait=True)\n",
        "        plt.plot(self.x, self.losses, label=\"loss\")\n",
        "        plt.plot(self.x, self.val_losses, label=\"val_loss\")\n",
        "        plt.legend()\n",
        "        plt.show();"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "WwxNoLZ_QF32",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "embeding_dim=50\n",
        "tokenizer=pipeline.named_steps['tokenizer']\n",
        "max_length=tokenizer.max_length\n",
        "vocab_size=tokenizer.vocab_size"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BfD0JCoqQW8r",
        "colab_type": "code",
        "outputId": "849104f0-fad6-484e-f7d3-db7a31fc5205",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "num_classes=y_train[0].shape[0]\n",
        "num_classes"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "7"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 37
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ReAE_iDeQiqY",
        "colab_type": "text"
      },
      "source": [
        "## 8.1 Creating the model"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "he9Td13lQnW_",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "model=Sequential()\n",
        "model.add(Embedding(input_dim=vocab_size,output_dim=embeding_dim,input_length=max_length))\n",
        "model.add(GlobalMaxPool1D())\n",
        "model.add(Dropout(0.2))\n",
        "model.add(Dense(10,activation='relu'))\n",
        "model.add(Dropout(0.2))\n",
        "model.add(Dense(num_classes,activation='softmax'))"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "7m4nKFc2Q-sY",
        "colab_type": "code",
        "outputId": "fa480289-dd25-4e78-c4ff-bb7ed82a17e0",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 381
        }
      },
      "source": [
        "model.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy'] )\n",
        "model.summary()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Model: \"sequential\"\n",
            "_________________________________________________________________\n",
            "Layer (type)                 Output Shape              Param #   \n",
            "=================================================================\n",
            "embedding (Embedding)        (None, 100, 50)           2297700   \n",
            "_________________________________________________________________\n",
            "global_max_pooling1d (Global (None, 50)                0         \n",
            "_________________________________________________________________\n",
            "dropout (Dropout)            (None, 50)                0         \n",
            "_________________________________________________________________\n",
            "dense (Dense)                (None, 10)                510       \n",
            "_________________________________________________________________\n",
            "dropout_1 (Dropout)          (None, 10)                0         \n",
            "_________________________________________________________________\n",
            "dense_1 (Dense)              (None, 7)                 77        \n",
            "=================================================================\n",
            "Total params: 2,298,287\n",
            "Trainable params: 2,298,287\n",
            "Non-trainable params: 0\n",
            "_________________________________________________________________\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "s2SAxFTQSSik",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "import datetime"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "47vViR-1SgRA",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "log_dir=\"logs/train/\" + datetime.datetime.now().strftime(\"%Y%m%d-%H%M%S\")\n",
        "tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "E7jc-jr7S1KS",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "epochs = 4\n",
        "batch_size = 12\n",
        "verbose = 0\n",
        "validation_split = 0.2\n",
        "plot_losses = PlotLosses() #We wont use this callback"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "inmW6LEWStuV",
        "colab_type": "code",
        "outputId": "2c4b6e09-0aaf-4c40-8e7d-96f2e050817c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 199
        }
      },
      "source": [
        "model.fit(X_train,y_train,epochs=epochs,batch_size=batch_size,verbose=1,validation_split=validation_split,callbacks=[tensorboard_callback])"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Train on 24200 samples, validate on 6050 samples\n",
            "Epoch 1/4\n",
            "24200/24200 [==============================] - 44s 2ms/sample - loss: 0.7542 - accuracy: 0.7605 - val_loss: 0.3088 - val_accuracy: 0.9160\n",
            "Epoch 2/4\n",
            "24200/24200 [==============================] - 43s 2ms/sample - loss: 0.3640 - accuracy: 0.8905 - val_loss: 0.2567 - val_accuracy: 0.9263\n",
            "Epoch 3/4\n",
            "24200/24200 [==============================] - 43s 2ms/sample - loss: 0.2958 - accuracy: 0.9086 - val_loss: 0.2402 - val_accuracy: 0.9274\n",
            "Epoch 4/4\n",
            "24200/24200 [==============================] - 42s 2ms/sample - loss: 0.2539 - accuracy: 0.9247 - val_loss: 0.2374 - val_accuracy: 0.9283\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "<tensorflow.python.keras.callbacks.History at 0x7f37e6676128>"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 43
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "PjqPc1s2UDBO",
        "colab_type": "code",
        "outputId": "0a77b45d-02dd-4a34-d8a1-b19944f64040",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 821
        }
      },
      "source": [
        "%tensorboard --logdir logs/train"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mLFYJq_wZd_I",
        "colab_type": "text"
      },
      "source": [
        "## 8.2 Save and load model"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "zTl2Dvu1X4Zt",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "model.save(\"model_disaster_class.h5\")"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mw_aqEV-ZXuF",
        "colab_type": "text"
      },
      "source": [
        ""
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "EdUnIUbLZDB2",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "new_model = tf.keras.models.load_model(\"model_disaster_class.h5\")"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "XI0VxxDNYJtg",
        "colab_type": "text"
      },
      "source": [
        "## 9. Model evaluation"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0vM4L32bX_S6",
        "colab_type": "code",
        "outputId": "81653bf1-4c1e-4f7d-c8e3-3244f1979186",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "loss, acc = new_model.evaluate(X_test,  y_test, verbose=2)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "12965/12965 - 1s - loss: 0.2371 - accuracy: 0.9320\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "tSt_FZ50ZlLc",
        "colab_type": "text"
      },
      "source": [
        "## 10. Predictions"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CF_fmIZ1PLY6",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "vocab_size=pipeline.named_steps['tokenizer'].vocab_size\n",
        "max_length=pipeline.named_steps['tokenizer'].max_length\n",
        "label_encoder=pipeline.named_steps['one-hot-encoder'].label_encoder\n",
        "tokenizer=pipeline.named_steps['tokenizer'].tokenizer"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "PQ356CBMOXB8",
        "colab_type": "code",
        "outputId": "a98d06b7-bec1-45bc-f466-cfe4215b8318",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "#@title Text to predict (write what you want)\n",
        "\n",
        "text = 'large explosion at a texas fertilizer plant...multiple injuries reported...local hospital told to expect up to 100 patients: via ap' #@param {type:\"string\"}\n",
        "print(text)\n",
        "texts = []\n",
        "texts.append(text)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "large explosion at a texas fertilizer plant...multiple injuries reported...local hospital told to expect up to 100 patients: via ap\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "qaXXAFuoZCAF",
        "colab_type": "code",
        "outputId": "77d915dd-0da9-44ff-e034-fc51ac4f5d33",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 72
        }
      },
      "source": [
        "x_seq=tokenizer.texts_to_sequences(texts)[0]\n",
        "x_pad=tf.keras.preprocessing.sequence.pad_sequences([x_seq],maxlen=max_length ,padding='post')[0]\n",
        "x_pad=np.array(x_pad)\n",
        "x_pad=x_pad.reshape(1,100)\n",
        "x_pad.shape\n",
        "predict=new_model.predict_classes(x_pad)\n",
        "score=max(new_model.predict(x_pad)[0])\n",
        "print(predict)\n",
        "print('Predicted: '+ label_encoder.inverse_transform(predict)[0].upper())\n",
        "print('score',score)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "[2]\n",
            "Predicted: EXPLOSION\n",
            "score 0.99796414\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "jjHUHHd8aAGn",
        "colab_type": "text"
      },
      "source": [
        "## 11. Hyperparameters Optimization"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Ws9_8BtST-3q",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!pip install -U keras-tuner"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ObvV3LuPUuEV",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "from kerastuner.tuners import RandomSearch"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "5Ap2aLYzaDo9",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "vocab_size=pipeline.named_steps['tokenizer'].vocab_size\n",
        "max_length=pipeline.named_steps['tokenizer'].max_length\n",
        "\n",
        "def build_model(hp):\n",
        "    model=Sequential()\n",
        "    model.add(Embedding(input_dim=vocab_size,output_dim=50,input_length=max_length))\n",
        "    model.add(GlobalMaxPool1D())\n",
        "    model.add(Dropout(rate= hp.Float('dropout_1',0.1, 0.4, step=0.1, default=0.2)))\n",
        "    model.add(Dense(units = hp.Int('hidden_dense_units', 8, 32, step=8, default=10), activation='relu'))\n",
        "    model.add(Dropout(rate = hp.Float('dropout_2', 0.1, 0.4, step=0.1, default=0.2)))\n",
        "    model.add(Dense(num_classes,activation='softmax'))\n",
        "    model.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy'])\n",
        "    return model"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wVpaChzVUnLi",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "tuner = RandomSearch(\n",
        "    build_model,\n",
        "    objective='val_accuracy',\n",
        "    max_trials=5,\n",
        "    executions_per_trial=2,\n",
        "    directory='hp_finetuning',\n",
        "    project_name='disaster_class')"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "04zz-sHSaCq3",
        "colab_type": "code",
        "outputId": "9b6d4822-5def-4ca5-c92b-b6e98aeba0c9",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 440
        }
      },
      "source": [
        "tuner.search_space_summary()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Search space summary</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Default search space size: 3</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#7E57C2\"><h2 style=\"font-size:16px\">dropout_1 (Float)</h2></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-default: 0.2</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-max_value: 0.4</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-min_value: 0.1</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-sampling: None</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-step: 0.1</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#7E57C2\"><h2 style=\"font-size:16px\">hidden_dense_units (Int)</h2></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-default: 10</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-max_value: 32</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-min_value: 8</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-sampling: None</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-step: 8</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#7E57C2\"><h2 style=\"font-size:16px\">dropout_2 (Float)</h2></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-default: 0.2</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-max_value: 0.4</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-min_value: 0.1</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-sampling: None</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-step: 0.1</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "0_gUBQD5aGbl",
        "colab_type": "code",
        "outputId": "e7fb383b-9d15-4ee2-fd5a-0076ebda273b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        }
      },
      "source": [
        "tuner.search(X_train, y_train, epochs=5, validation_split=0.2)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Train on 24200 samples, validate on 6050 samples\n",
            "Epoch 1/5\n",
            "24200/24200 [==============================] - 19s 788us/sample - loss: 1.0704 - accuracy: 0.6596 - val_loss: 0.3886 - val_accuracy: 0.9121\n",
            "Epoch 2/5\n",
            "24200/24200 [==============================] - 18s 735us/sample - loss: 0.4229 - accuracy: 0.8819 - val_loss: 0.2931 - val_accuracy: 0.9202\n",
            "Epoch 3/5\n",
            "24200/24200 [==============================] - 18s 731us/sample - loss: 0.3449 - accuracy: 0.9024 - val_loss: 0.2671 - val_accuracy: 0.9256\n",
            "Epoch 4/5\n",
            "24200/24200 [==============================] - 18s 733us/sample - loss: 0.2866 - accuracy: 0.9200 - val_loss: 0.2560 - val_accuracy: 0.9276\n",
            "Epoch 5/5\n",
            "24200/24200 [==============================] - 18s 733us/sample - loss: 0.2526 - accuracy: 0.9290 - val_loss: 0.2534 - val_accuracy: 0.9286\n",
            "Train on 24200 samples, validate on 6050 samples\n",
            "Epoch 1/5\n",
            "24200/24200 [==============================] - 18s 760us/sample - loss: 1.1308 - accuracy: 0.5990 - val_loss: 0.4184 - val_accuracy: 0.9126\n",
            "Epoch 2/5\n",
            "24200/24200 [==============================] - 18s 734us/sample - loss: 0.4342 - accuracy: 0.8727 - val_loss: 0.2882 - val_accuracy: 0.9226\n",
            "Epoch 3/5\n",
            "24200/24200 [==============================] - 18s 735us/sample - loss: 0.3451 - accuracy: 0.8890 - val_loss: 0.2593 - val_accuracy: 0.9255\n",
            "Epoch 4/5\n",
            "24200/24200 [==============================] - 18s 741us/sample - loss: 0.3021 - accuracy: 0.8984 - val_loss: 0.2483 - val_accuracy: 0.9286\n",
            "Epoch 5/5\n",
            "24200/24200 [==============================] - 18s 736us/sample - loss: 0.2646 - accuracy: 0.9181 - val_loss: 0.2435 - val_accuracy: 0.9286\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial complete</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial summary</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Trial ID: e9502914d90be2441d86e8dc11b9b8ce</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Score: 0.9285950660705566</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Best step: 0</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#7E57C2\"><h2 style=\"font-size:16px\">Hyperparameters:</h2></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-dropout_1: 0.2</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-dropout_2: 0.1</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-hidden_dense_units: 8</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "Train on 24200 samples, validate on 6050 samples\n",
            "Epoch 1/5\n",
            "24200/24200 [==============================] - 19s 772us/sample - loss: 0.8911 - accuracy: 0.7129 - val_loss: 0.3062 - val_accuracy: 0.9112\n",
            "Epoch 2/5\n",
            "24200/24200 [==============================] - 18s 746us/sample - loss: 0.3165 - accuracy: 0.9096 - val_loss: 0.2544 - val_accuracy: 0.9235\n",
            "Epoch 3/5\n",
            "24200/24200 [==============================] - 18s 757us/sample - loss: 0.2488 - accuracy: 0.9276 - val_loss: 0.2387 - val_accuracy: 0.9266\n",
            "Epoch 4/5\n",
            "24200/24200 [==============================] - 18s 755us/sample - loss: 0.2044 - accuracy: 0.9390 - val_loss: 0.2354 - val_accuracy: 0.9283\n",
            "Epoch 5/5\n",
            "24200/24200 [==============================] - 18s 744us/sample - loss: 0.1687 - accuracy: 0.9503 - val_loss: 0.2364 - val_accuracy: 0.9283\n",
            "Train on 24200 samples, validate on 6050 samples\n",
            "Epoch 1/5\n",
            "24200/24200 [==============================] - 19s 800us/sample - loss: 0.9548 - accuracy: 0.6878 - val_loss: 0.3134 - val_accuracy: 0.9147\n",
            "Epoch 2/5\n",
            "24200/24200 [==============================] - 18s 738us/sample - loss: 0.3475 - accuracy: 0.9007 - val_loss: 0.2562 - val_accuracy: 0.9260\n",
            "Epoch 3/5\n",
            "24200/24200 [==============================] - 18s 758us/sample - loss: 0.2736 - accuracy: 0.9182 - val_loss: 0.2334 - val_accuracy: 0.9309\n",
            "Epoch 4/5\n",
            "24200/24200 [==============================] - 17s 714us/sample - loss: 0.2203 - accuracy: 0.9328 - val_loss: 0.2254 - val_accuracy: 0.9324\n",
            "Epoch 5/5\n",
            "24200/24200 [==============================] - 17s 705us/sample - loss: 0.1804 - accuracy: 0.9483 - val_loss: 0.2279 - val_accuracy: 0.9314\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial complete</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial summary</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Trial ID: f277528c2c2d567666f4722b1a8cb2b8</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Score: 0.9303305745124817</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Best step: 0</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#7E57C2\"><h2 style=\"font-size:16px\">Hyperparameters:</h2></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-dropout_1: 0.1</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-dropout_2: 0.2</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-hidden_dense_units: 16</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "Train on 24200 samples, validate on 6050 samples\n",
            "Epoch 1/5\n",
            "24200/24200 [==============================] - 18s 731us/sample - loss: 0.8595 - accuracy: 0.7273 - val_loss: 0.3044 - val_accuracy: 0.9132\n",
            "Epoch 2/5\n",
            "24200/24200 [==============================] - 17s 706us/sample - loss: 0.3135 - accuracy: 0.9110 - val_loss: 0.2507 - val_accuracy: 0.9246\n",
            "Epoch 3/5\n",
            "24200/24200 [==============================] - 17s 719us/sample - loss: 0.2444 - accuracy: 0.9280 - val_loss: 0.2321 - val_accuracy: 0.9279\n",
            "Epoch 4/5\n",
            "24200/24200 [==============================] - 17s 706us/sample - loss: 0.2011 - accuracy: 0.9414 - val_loss: 0.2275 - val_accuracy: 0.9314\n",
            "Epoch 5/5\n",
            "24200/24200 [==============================] - 17s 711us/sample - loss: 0.1689 - accuracy: 0.9500 - val_loss: 0.2261 - val_accuracy: 0.9312\n",
            "Train on 24200 samples, validate on 6050 samples\n",
            "Epoch 1/5\n",
            "24200/24200 [==============================] - 18s 725us/sample - loss: 0.8933 - accuracy: 0.7150 - val_loss: 0.3044 - val_accuracy: 0.9169\n",
            "Epoch 2/5\n",
            "24200/24200 [==============================] - 17s 702us/sample - loss: 0.3145 - accuracy: 0.9124 - val_loss: 0.2464 - val_accuracy: 0.9251\n",
            "Epoch 3/5\n",
            "24200/24200 [==============================] - 17s 713us/sample - loss: 0.2424 - accuracy: 0.9304 - val_loss: 0.2308 - val_accuracy: 0.9311\n",
            "Epoch 4/5\n",
            "24200/24200 [==============================] - 17s 709us/sample - loss: 0.1948 - accuracy: 0.9438 - val_loss: 0.2226 - val_accuracy: 0.9321\n",
            "Epoch 5/5\n",
            "24200/24200 [==============================] - 17s 718us/sample - loss: 0.1605 - accuracy: 0.9527 - val_loss: 0.2264 - val_accuracy: 0.9312\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial complete</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial summary</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Trial ID: dc12b385fc2369945d98883338facfa7</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Score: 0.9317355155944824</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Best step: 0</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#7E57C2\"><h2 style=\"font-size:16px\">Hyperparameters:</h2></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-dropout_1: 0.2</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-dropout_2: 0.30000000000000004</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-hidden_dense_units: 32</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "Train on 24200 samples, validate on 6050 samples\n",
            "Epoch 1/5\n",
            "24200/24200 [==============================] - 18s 732us/sample - loss: 1.0309 - accuracy: 0.6637 - val_loss: 0.3363 - val_accuracy: 0.9106\n",
            "Epoch 2/5\n",
            "24200/24200 [==============================] - 17s 723us/sample - loss: 0.3956 - accuracy: 0.8893 - val_loss: 0.2648 - val_accuracy: 0.9223\n",
            "Epoch 3/5\n",
            "24200/24200 [==============================] - 17s 720us/sample - loss: 0.3273 - accuracy: 0.9076 - val_loss: 0.2452 - val_accuracy: 0.9263\n",
            "Epoch 4/5\n",
            "24200/24200 [==============================] - 18s 723us/sample - loss: 0.2845 - accuracy: 0.9181 - val_loss: 0.2361 - val_accuracy: 0.9284\n",
            "Epoch 5/5\n",
            "24200/24200 [==============================] - 18s 723us/sample - loss: 0.2484 - accuracy: 0.9289 - val_loss: 0.2297 - val_accuracy: 0.9307\n",
            "Train on 24200 samples, validate on 6050 samples\n",
            "Epoch 1/5\n",
            "24200/24200 [==============================] - 18s 739us/sample - loss: 1.0473 - accuracy: 0.6541 - val_loss: 0.3510 - val_accuracy: 0.9117\n",
            "Epoch 2/5\n",
            "24200/24200 [==============================] - 18s 731us/sample - loss: 0.4180 - accuracy: 0.8867 - val_loss: 0.2712 - val_accuracy: 0.9231\n",
            "Epoch 3/5\n",
            "24200/24200 [==============================] - 17s 722us/sample - loss: 0.3337 - accuracy: 0.9067 - val_loss: 0.2512 - val_accuracy: 0.9261\n",
            "Epoch 4/5\n",
            "24200/24200 [==============================] - 17s 720us/sample - loss: 0.2903 - accuracy: 0.9185 - val_loss: 0.2396 - val_accuracy: 0.9279\n",
            "Epoch 5/5\n",
            "24200/24200 [==============================] - 17s 722us/sample - loss: 0.2577 - accuracy: 0.9264 - val_loss: 0.2327 - val_accuracy: 0.9291\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial complete</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial summary</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Trial ID: 9d2d851447fa43d4fd8a124fb3961eae</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Score: 0.9299173355102539</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Best step: 0</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#7E57C2\"><h2 style=\"font-size:16px\">Hyperparameters:</h2></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-dropout_1: 0.4</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-dropout_2: 0.30000000000000004</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-hidden_dense_units: 24</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "Train on 24200 samples, validate on 6050 samples\n",
            "Epoch 1/5\n",
            "24200/24200 [==============================] - 18s 743us/sample - loss: 0.8776 - accuracy: 0.7165 - val_loss: 0.3076 - val_accuracy: 0.9119\n",
            "Epoch 2/5\n",
            "24200/24200 [==============================] - 18s 730us/sample - loss: 0.3080 - accuracy: 0.9127 - val_loss: 0.2496 - val_accuracy: 0.9248\n",
            "Epoch 3/5\n",
            "24200/24200 [==============================] - 18s 730us/sample - loss: 0.2417 - accuracy: 0.9292 - val_loss: 0.2295 - val_accuracy: 0.9273\n",
            "Epoch 4/5\n",
            "24200/24200 [==============================] - 18s 734us/sample - loss: 0.1910 - accuracy: 0.9422 - val_loss: 0.2236 - val_accuracy: 0.9278\n",
            "Epoch 5/5\n",
            "24200/24200 [==============================] - 18s 740us/sample - loss: 0.1598 - accuracy: 0.9534 - val_loss: 0.2273 - val_accuracy: 0.9294\n",
            "Train on 24200 samples, validate on 6050 samples\n",
            "Epoch 1/5\n",
            "24200/24200 [==============================] - 18s 749us/sample - loss: 0.8563 - accuracy: 0.7265 - val_loss: 0.3031 - val_accuracy: 0.9145\n",
            "Epoch 2/5\n",
            "24200/24200 [==============================] - 18s 730us/sample - loss: 0.3087 - accuracy: 0.9116 - val_loss: 0.2504 - val_accuracy: 0.9258\n",
            "Epoch 3/5\n",
            "24200/24200 [==============================] - 18s 726us/sample - loss: 0.2434 - accuracy: 0.9271 - val_loss: 0.2317 - val_accuracy: 0.9283\n",
            "Epoch 4/5\n",
            "24200/24200 [==============================] - 18s 728us/sample - loss: 0.1992 - accuracy: 0.9411 - val_loss: 0.2236 - val_accuracy: 0.9311\n",
            "Epoch 5/5\n",
            "24200/24200 [==============================] - 18s 739us/sample - loss: 0.1656 - accuracy: 0.9514 - val_loss: 0.2224 - val_accuracy: 0.9319\n"
          ],
          "name": "stdout"
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial complete</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial summary</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Trial ID: 1fb2a6bb1cdc2acd9e845bc2ed8a0b5d</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Score: 0.930661141872406</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Best step: 0</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#7E57C2\"><h2 style=\"font-size:16px\">Hyperparameters:</h2></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-dropout_1: 0.2</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-dropout_2: 0.2</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-hidden_dense_units: 24</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "stream",
          "text": [
            "INFO:tensorflow:Oracle triggered exit\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZZKipRJFepzy",
        "colab_type": "code",
        "outputId": "ef8389aa-f3a5-4b56-9677-eb822c275d40",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 996
        }
      },
      "source": [
        "tuner.results_summary()"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Results summary</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Results in hp_finetuning/disaster_class</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Showing 10 best trials</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Objective(name='val_accuracy', direction='max')</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial summary</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Trial ID: dc12b385fc2369945d98883338facfa7</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Score: 0.9317355155944824</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Best step: 0</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#7E57C2\"><h2 style=\"font-size:16px\">Hyperparameters:</h2></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-dropout_1: 0.2</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-dropout_2: 0.30000000000000004</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-hidden_dense_units: 32</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial summary</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Trial ID: 1fb2a6bb1cdc2acd9e845bc2ed8a0b5d</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Score: 0.930661141872406</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Best step: 0</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#7E57C2\"><h2 style=\"font-size:16px\">Hyperparameters:</h2></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-dropout_1: 0.2</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-dropout_2: 0.2</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-hidden_dense_units: 24</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial summary</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Trial ID: f277528c2c2d567666f4722b1a8cb2b8</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Score: 0.9303305745124817</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Best step: 0</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#7E57C2\"><h2 style=\"font-size:16px\">Hyperparameters:</h2></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-dropout_1: 0.1</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-dropout_2: 0.2</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-hidden_dense_units: 16</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial summary</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Trial ID: 9d2d851447fa43d4fd8a124fb3961eae</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Score: 0.9299173355102539</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Best step: 0</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#7E57C2\"><h2 style=\"font-size:16px\">Hyperparameters:</h2></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-dropout_1: 0.4</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-dropout_2: 0.30000000000000004</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-hidden_dense_units: 24</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#4527A0\"><h1 style=\"font-size:18px\">Trial summary</h1></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Trial ID: e9502914d90be2441d86e8dc11b9b8ce</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Score: 0.9285950660705566</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-Best step: 0</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:#7E57C2\"><h2 style=\"font-size:16px\">Hyperparameters:</h2></span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-dropout_1: 0.2</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:blue\"> |-dropout_2: 0.1</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        },
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<span style=\"color:cyan\"> |-hidden_dense_units: 8</span>"
            ],
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ]
          },
          "metadata": {
            "tags": []
          }
        }
      ]
    }
  ]
}