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Toxicity.ipynb",
|
| 7 |
+
"provenance": [],
|
| 8 |
+
"collapsed_sections": []
|
| 9 |
+
},
|
| 10 |
+
"kernelspec": {
|
| 11 |
+
"name": "python3",
|
| 12 |
+
"display_name": "Python 3"
|
| 13 |
+
},
|
| 14 |
+
"language_info": {
|
| 15 |
+
"name": "python"
|
| 16 |
+
},
|
| 17 |
+
"accelerator": "GPU",
|
| 18 |
+
"gpuClass": "standard"
|
| 19 |
+
},
|
| 20 |
+
"cells": [
|
| 21 |
+
{
|
| 22 |
+
"cell_type": "code",
|
| 23 |
+
"execution_count": 1,
|
| 24 |
+
"metadata": {
|
| 25 |
+
"colab": {
|
| 26 |
+
"base_uri": "https://localhost:8080/"
|
| 27 |
+
},
|
| 28 |
+
"id": "S99TDbfWWq0u",
|
| 29 |
+
"outputId": "27146bb5-1f2c-42ce-9d75-f2e46418494e"
|
| 30 |
+
},
|
| 31 |
+
"outputs": [
|
| 32 |
+
{
|
| 33 |
+
"output_type": "stream",
|
| 34 |
+
"name": "stdout",
|
| 35 |
+
"text": [
|
| 36 |
+
"Mounted at /content/drive\n"
|
| 37 |
+
]
|
| 38 |
+
}
|
| 39 |
+
],
|
| 40 |
+
"source": [
|
| 41 |
+
"from google.colab import drive\n",
|
| 42 |
+
"drive.mount('/content/drive')"
|
| 43 |
+
]
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"cell_type": "code",
|
| 47 |
+
"source": [
|
| 48 |
+
"ls drive/MyDrive/jigsaw-toxic-comment-classification-challenge/"
|
| 49 |
+
],
|
| 50 |
+
"metadata": {
|
| 51 |
+
"colab": {
|
| 52 |
+
"base_uri": "https://localhost:8080/"
|
| 53 |
+
},
|
| 54 |
+
"id": "6MtlVgwufR8M",
|
| 55 |
+
"outputId": "acbed960-207b-4f6a-f5da-077cfba36c1d"
|
| 56 |
+
},
|
| 57 |
+
"execution_count": 2,
|
| 58 |
+
"outputs": [
|
| 59 |
+
{
|
| 60 |
+
"output_type": "stream",
|
| 61 |
+
"name": "stdout",
|
| 62 |
+
"text": [
|
| 63 |
+
"\u001b[0m\u001b[01;34msample_submission.csv\u001b[0m/ test.csv.zip train.csv.zip\n",
|
| 64 |
+
"sample_submission.csv.zip \u001b[01;34mtest_labels.csv\u001b[0m/ X_test.pickle\n",
|
| 65 |
+
"simple_model.h5 test_labels.csv.zip X_train.pickle\n",
|
| 66 |
+
"\u001b[01;34mtest.csv\u001b[0m/ \u001b[01;34mtrain.csv\u001b[0m/\n"
|
| 67 |
+
]
|
| 68 |
+
}
|
| 69 |
+
]
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
"cell_type": "code",
|
| 73 |
+
"source": [
|
| 74 |
+
"%cd drive/MyDrive/jigsaw-toxic-comment-classification-challenge/"
|
| 75 |
+
],
|
| 76 |
+
"metadata": {
|
| 77 |
+
"colab": {
|
| 78 |
+
"base_uri": "https://localhost:8080/"
|
| 79 |
+
},
|
| 80 |
+
"id": "la5teYvGfcZ2",
|
| 81 |
+
"outputId": "60f69844-0a0e-4b3f-9882-d1291ee433b4"
|
| 82 |
+
},
|
| 83 |
+
"execution_count": 3,
|
| 84 |
+
"outputs": [
|
| 85 |
+
{
|
| 86 |
+
"output_type": "stream",
|
| 87 |
+
"name": "stdout",
|
| 88 |
+
"text": [
|
| 89 |
+
"/content/drive/MyDrive/jigsaw-toxic-comment-classification-challenge\n"
|
| 90 |
+
]
|
| 91 |
+
}
|
| 92 |
+
]
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"cell_type": "code",
|
| 96 |
+
"source": [
|
| 97 |
+
"import pandas as pd\n",
|
| 98 |
+
"import numpy as np\n",
|
| 99 |
+
"import tensorflow as tf\n",
|
| 100 |
+
"import matplotlib.pyplot as plt\n",
|
| 101 |
+
"from tensorflow import keras\n",
|
| 102 |
+
"from keras.preprocessing.text import Tokenizer\n",
|
| 103 |
+
"from keras.preprocessing.sequence import pad_sequences\n",
|
| 104 |
+
"import nltk\n",
|
| 105 |
+
"from nltk.corpus import stopwords\n",
|
| 106 |
+
"nltk.download('stopwords')\n",
|
| 107 |
+
"nltk.download('punkt')\n",
|
| 108 |
+
"from nltk.tokenize import word_tokenize\n",
|
| 109 |
+
"import re\n",
|
| 110 |
+
"from sklearn.model_selection import train_test_split"
|
| 111 |
+
],
|
| 112 |
+
"metadata": {
|
| 113 |
+
"colab": {
|
| 114 |
+
"base_uri": "https://localhost:8080/"
|
| 115 |
+
},
|
| 116 |
+
"id": "0iHYnJ53foct",
|
| 117 |
+
"outputId": "d9c9717b-5368-474b-b3e8-dcd85f4f4ce5"
|
| 118 |
+
},
|
| 119 |
+
"execution_count": 4,
|
| 120 |
+
"outputs": [
|
| 121 |
+
{
|
| 122 |
+
"output_type": "stream",
|
| 123 |
+
"name": "stderr",
|
| 124 |
+
"text": [
|
| 125 |
+
"[nltk_data] Downloading package stopwords to /root/nltk_data...\n",
|
| 126 |
+
"[nltk_data] Unzipping corpora/stopwords.zip.\n",
|
| 127 |
+
"[nltk_data] Downloading package punkt to /root/nltk_data...\n",
|
| 128 |
+
"[nltk_data] Unzipping tokenizers/punkt.zip.\n"
|
| 129 |
+
]
|
| 130 |
+
}
|
| 131 |
+
]
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
"cell_type": "code",
|
| 135 |
+
"source": [
|
| 136 |
+
"train = pd.read_csv('train.csv/train.csv')\n"
|
| 137 |
+
],
|
| 138 |
+
"metadata": {
|
| 139 |
+
"id": "GBGHqE1Wfeb9"
|
| 140 |
+
},
|
| 141 |
+
"execution_count": 5,
|
| 142 |
+
"outputs": []
|
| 143 |
+
},
|
| 144 |
+
{
|
| 145 |
+
"cell_type": "code",
|
| 146 |
+
"source": [
|
| 147 |
+
"test = pd.read_csv('test.csv/test.csv')"
|
| 148 |
+
],
|
| 149 |
+
"metadata": {
|
| 150 |
+
"id": "-wGlqD9GZrkC"
|
| 151 |
+
},
|
| 152 |
+
"execution_count": 6,
|
| 153 |
+
"outputs": []
|
| 154 |
+
},
|
| 155 |
+
{
|
| 156 |
+
"cell_type": "code",
|
| 157 |
+
"source": [
|
| 158 |
+
"test_labels = pd.read_csv('test_labels.csv/test_labels.csv')"
|
| 159 |
+
],
|
| 160 |
+
"metadata": {
|
| 161 |
+
"id": "haDqTJbRZwy3"
|
| 162 |
+
},
|
| 163 |
+
"execution_count": 7,
|
| 164 |
+
"outputs": []
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"cell_type": "code",
|
| 168 |
+
"source": [
|
| 169 |
+
"train.shape"
|
| 170 |
+
],
|
| 171 |
+
"metadata": {
|
| 172 |
+
"colab": {
|
| 173 |
+
"base_uri": "https://localhost:8080/"
|
| 174 |
+
},
|
| 175 |
+
"id": "mllErgckfvOa",
|
| 176 |
+
"outputId": "fc720f9b-d80d-48af-fed8-b472d554c22f"
|
| 177 |
+
},
|
| 178 |
+
"execution_count": 8,
|
| 179 |
+
"outputs": [
|
| 180 |
+
{
|
| 181 |
+
"output_type": "execute_result",
|
| 182 |
+
"data": {
|
| 183 |
+
"text/plain": [
|
| 184 |
+
"(159571, 8)"
|
| 185 |
+
]
|
| 186 |
+
},
|
| 187 |
+
"metadata": {},
|
| 188 |
+
"execution_count": 8
|
| 189 |
+
}
|
| 190 |
+
]
|
| 191 |
+
},
|
| 192 |
+
{
|
| 193 |
+
"cell_type": "code",
|
| 194 |
+
"source": [
|
| 195 |
+
"train.head()"
|
| 196 |
+
],
|
| 197 |
+
"metadata": {
|
| 198 |
+
"colab": {
|
| 199 |
+
"base_uri": "https://localhost:8080/",
|
| 200 |
+
"height": 461
|
| 201 |
+
},
|
| 202 |
+
"id": "v5JPdmYTf36i",
|
| 203 |
+
"outputId": "83d2d1ca-af74-4a91-8ac5-594f7ea28055"
|
| 204 |
+
},
|
| 205 |
+
"execution_count": 9,
|
| 206 |
+
"outputs": [
|
| 207 |
+
{
|
| 208 |
+
"output_type": "execute_result",
|
| 209 |
+
"data": {
|
| 210 |
+
"text/plain": [
|
| 211 |
+
" id comment_text toxic \\\n",
|
| 212 |
+
"0 0000997932d777bf Explanation\\nWhy the edits made under my usern... 0 \n",
|
| 213 |
+
"1 000103f0d9cfb60f D'aww! He matches this background colour I'm s... 0 \n",
|
| 214 |
+
"2 000113f07ec002fd Hey man, I'm really not trying to edit war. It... 0 \n",
|
| 215 |
+
"3 0001b41b1c6bb37e \"\\nMore\\nI can't make any real suggestions on ... 0 \n",
|
| 216 |
+
"4 0001d958c54c6e35 You, sir, are my hero. Any chance you remember... 0 \n",
|
| 217 |
+
"\n",
|
| 218 |
+
" severe_toxic obscene threat insult identity_hate \n",
|
| 219 |
+
"0 0 0 0 0 0 \n",
|
| 220 |
+
"1 0 0 0 0 0 \n",
|
| 221 |
+
"2 0 0 0 0 0 \n",
|
| 222 |
+
"3 0 0 0 0 0 \n",
|
| 223 |
+
"4 0 0 0 0 0 "
|
| 224 |
+
],
|
| 225 |
+
"text/html": [
|
| 226 |
+
"\n",
|
| 227 |
+
" <div id=\"df-8f71142f-150c-41dd-bf4f-57aa47dad455\">\n",
|
| 228 |
+
" <div class=\"colab-df-container\">\n",
|
| 229 |
+
" <div>\n",
|
| 230 |
+
"<style scoped>\n",
|
| 231 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 232 |
+
" vertical-align: middle;\n",
|
| 233 |
+
" }\n",
|
| 234 |
+
"\n",
|
| 235 |
+
" .dataframe tbody tr th {\n",
|
| 236 |
+
" vertical-align: top;\n",
|
| 237 |
+
" }\n",
|
| 238 |
+
"\n",
|
| 239 |
+
" .dataframe thead th {\n",
|
| 240 |
+
" text-align: right;\n",
|
| 241 |
+
" }\n",
|
| 242 |
+
"</style>\n",
|
| 243 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 244 |
+
" <thead>\n",
|
| 245 |
+
" <tr style=\"text-align: right;\">\n",
|
| 246 |
+
" <th></th>\n",
|
| 247 |
+
" <th>id</th>\n",
|
| 248 |
+
" <th>comment_text</th>\n",
|
| 249 |
+
" <th>toxic</th>\n",
|
| 250 |
+
" <th>severe_toxic</th>\n",
|
| 251 |
+
" <th>obscene</th>\n",
|
| 252 |
+
" <th>threat</th>\n",
|
| 253 |
+
" <th>insult</th>\n",
|
| 254 |
+
" <th>identity_hate</th>\n",
|
| 255 |
+
" </tr>\n",
|
| 256 |
+
" </thead>\n",
|
| 257 |
+
" <tbody>\n",
|
| 258 |
+
" <tr>\n",
|
| 259 |
+
" <th>0</th>\n",
|
| 260 |
+
" <td>0000997932d777bf</td>\n",
|
| 261 |
+
" <td>Explanation\\nWhy the edits made under my usern...</td>\n",
|
| 262 |
+
" <td>0</td>\n",
|
| 263 |
+
" <td>0</td>\n",
|
| 264 |
+
" <td>0</td>\n",
|
| 265 |
+
" <td>0</td>\n",
|
| 266 |
+
" <td>0</td>\n",
|
| 267 |
+
" <td>0</td>\n",
|
| 268 |
+
" </tr>\n",
|
| 269 |
+
" <tr>\n",
|
| 270 |
+
" <th>1</th>\n",
|
| 271 |
+
" <td>000103f0d9cfb60f</td>\n",
|
| 272 |
+
" <td>D'aww! He matches this background colour I'm s...</td>\n",
|
| 273 |
+
" <td>0</td>\n",
|
| 274 |
+
" <td>0</td>\n",
|
| 275 |
+
" <td>0</td>\n",
|
| 276 |
+
" <td>0</td>\n",
|
| 277 |
+
" <td>0</td>\n",
|
| 278 |
+
" <td>0</td>\n",
|
| 279 |
+
" </tr>\n",
|
| 280 |
+
" <tr>\n",
|
| 281 |
+
" <th>2</th>\n",
|
| 282 |
+
" <td>000113f07ec002fd</td>\n",
|
| 283 |
+
" <td>Hey man, I'm really not trying to edit war. It...</td>\n",
|
| 284 |
+
" <td>0</td>\n",
|
| 285 |
+
" <td>0</td>\n",
|
| 286 |
+
" <td>0</td>\n",
|
| 287 |
+
" <td>0</td>\n",
|
| 288 |
+
" <td>0</td>\n",
|
| 289 |
+
" <td>0</td>\n",
|
| 290 |
+
" </tr>\n",
|
| 291 |
+
" <tr>\n",
|
| 292 |
+
" <th>3</th>\n",
|
| 293 |
+
" <td>0001b41b1c6bb37e</td>\n",
|
| 294 |
+
" <td>\"\\nMore\\nI can't make any real suggestions on ...</td>\n",
|
| 295 |
+
" <td>0</td>\n",
|
| 296 |
+
" <td>0</td>\n",
|
| 297 |
+
" <td>0</td>\n",
|
| 298 |
+
" <td>0</td>\n",
|
| 299 |
+
" <td>0</td>\n",
|
| 300 |
+
" <td>0</td>\n",
|
| 301 |
+
" </tr>\n",
|
| 302 |
+
" <tr>\n",
|
| 303 |
+
" <th>4</th>\n",
|
| 304 |
+
" <td>0001d958c54c6e35</td>\n",
|
| 305 |
+
" <td>You, sir, are my hero. Any chance you remember...</td>\n",
|
| 306 |
+
" <td>0</td>\n",
|
| 307 |
+
" <td>0</td>\n",
|
| 308 |
+
" <td>0</td>\n",
|
| 309 |
+
" <td>0</td>\n",
|
| 310 |
+
" <td>0</td>\n",
|
| 311 |
+
" <td>0</td>\n",
|
| 312 |
+
" </tr>\n",
|
| 313 |
+
" </tbody>\n",
|
| 314 |
+
"</table>\n",
|
| 315 |
+
"</div>\n",
|
| 316 |
+
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-8f71142f-150c-41dd-bf4f-57aa47dad455')\"\n",
|
| 317 |
+
" title=\"Convert this dataframe to an interactive table.\"\n",
|
| 318 |
+
" style=\"display:none;\">\n",
|
| 319 |
+
" \n",
|
| 320 |
+
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
|
| 321 |
+
" width=\"24px\">\n",
|
| 322 |
+
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
|
| 323 |
+
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
|
| 324 |
+
" </svg>\n",
|
| 325 |
+
" </button>\n",
|
| 326 |
+
" \n",
|
| 327 |
+
" <style>\n",
|
| 328 |
+
" .colab-df-container {\n",
|
| 329 |
+
" display:flex;\n",
|
| 330 |
+
" flex-wrap:wrap;\n",
|
| 331 |
+
" gap: 12px;\n",
|
| 332 |
+
" }\n",
|
| 333 |
+
"\n",
|
| 334 |
+
" .colab-df-convert {\n",
|
| 335 |
+
" background-color: #E8F0FE;\n",
|
| 336 |
+
" border: none;\n",
|
| 337 |
+
" border-radius: 50%;\n",
|
| 338 |
+
" cursor: pointer;\n",
|
| 339 |
+
" display: none;\n",
|
| 340 |
+
" fill: #1967D2;\n",
|
| 341 |
+
" height: 32px;\n",
|
| 342 |
+
" padding: 0 0 0 0;\n",
|
| 343 |
+
" width: 32px;\n",
|
| 344 |
+
" }\n",
|
| 345 |
+
"\n",
|
| 346 |
+
" .colab-df-convert:hover {\n",
|
| 347 |
+
" background-color: #E2EBFA;\n",
|
| 348 |
+
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
|
| 349 |
+
" fill: #174EA6;\n",
|
| 350 |
+
" }\n",
|
| 351 |
+
"\n",
|
| 352 |
+
" [theme=dark] .colab-df-convert {\n",
|
| 353 |
+
" background-color: #3B4455;\n",
|
| 354 |
+
" fill: #D2E3FC;\n",
|
| 355 |
+
" }\n",
|
| 356 |
+
"\n",
|
| 357 |
+
" [theme=dark] .colab-df-convert:hover {\n",
|
| 358 |
+
" background-color: #434B5C;\n",
|
| 359 |
+
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
|
| 360 |
+
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
|
| 361 |
+
" fill: #FFFFFF;\n",
|
| 362 |
+
" }\n",
|
| 363 |
+
" </style>\n",
|
| 364 |
+
"\n",
|
| 365 |
+
" <script>\n",
|
| 366 |
+
" const buttonEl =\n",
|
| 367 |
+
" document.querySelector('#df-8f71142f-150c-41dd-bf4f-57aa47dad455 button.colab-df-convert');\n",
|
| 368 |
+
" buttonEl.style.display =\n",
|
| 369 |
+
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
|
| 370 |
+
"\n",
|
| 371 |
+
" async function convertToInteractive(key) {\n",
|
| 372 |
+
" const element = document.querySelector('#df-8f71142f-150c-41dd-bf4f-57aa47dad455');\n",
|
| 373 |
+
" const dataTable =\n",
|
| 374 |
+
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
|
| 375 |
+
" [key], {});\n",
|
| 376 |
+
" if (!dataTable) return;\n",
|
| 377 |
+
"\n",
|
| 378 |
+
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
|
| 379 |
+
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
|
| 380 |
+
" + ' to learn more about interactive tables.';\n",
|
| 381 |
+
" element.innerHTML = '';\n",
|
| 382 |
+
" dataTable['output_type'] = 'display_data';\n",
|
| 383 |
+
" await google.colab.output.renderOutput(dataTable, element);\n",
|
| 384 |
+
" const docLink = document.createElement('div');\n",
|
| 385 |
+
" docLink.innerHTML = docLinkHtml;\n",
|
| 386 |
+
" element.appendChild(docLink);\n",
|
| 387 |
+
" }\n",
|
| 388 |
+
" </script>\n",
|
| 389 |
+
" </div>\n",
|
| 390 |
+
" </div>\n",
|
| 391 |
+
" "
|
| 392 |
+
]
|
| 393 |
+
},
|
| 394 |
+
"metadata": {},
|
| 395 |
+
"execution_count": 9
|
| 396 |
+
}
|
| 397 |
+
]
|
| 398 |
+
},
|
| 399 |
+
{
|
| 400 |
+
"cell_type": "markdown",
|
| 401 |
+
"source": [
|
| 402 |
+
"Check for Missing values - no missing values found"
|
| 403 |
+
],
|
| 404 |
+
"metadata": {
|
| 405 |
+
"id": "aGx06xC0hj4z"
|
| 406 |
+
}
|
| 407 |
+
},
|
| 408 |
+
{
|
| 409 |
+
"cell_type": "code",
|
| 410 |
+
"source": [
|
| 411 |
+
"train.isnull().sum()"
|
| 412 |
+
],
|
| 413 |
+
"metadata": {
|
| 414 |
+
"colab": {
|
| 415 |
+
"base_uri": "https://localhost:8080/"
|
| 416 |
+
},
|
| 417 |
+
"id": "2YH3nZJbhgWP",
|
| 418 |
+
"outputId": "f9ccab2f-bb8e-4d97-d171-a50208ce66c1"
|
| 419 |
+
},
|
| 420 |
+
"execution_count": 10,
|
| 421 |
+
"outputs": [
|
| 422 |
+
{
|
| 423 |
+
"output_type": "execute_result",
|
| 424 |
+
"data": {
|
| 425 |
+
"text/plain": [
|
| 426 |
+
"id 0\n",
|
| 427 |
+
"comment_text 0\n",
|
| 428 |
+
"toxic 0\n",
|
| 429 |
+
"severe_toxic 0\n",
|
| 430 |
+
"obscene 0\n",
|
| 431 |
+
"threat 0\n",
|
| 432 |
+
"insult 0\n",
|
| 433 |
+
"identity_hate 0\n",
|
| 434 |
+
"dtype: int64"
|
| 435 |
+
]
|
| 436 |
+
},
|
| 437 |
+
"metadata": {},
|
| 438 |
+
"execution_count": 10
|
| 439 |
+
}
|
| 440 |
+
]
|
| 441 |
+
},
|
| 442 |
+
{
|
| 443 |
+
"cell_type": "code",
|
| 444 |
+
"source": [
|
| 445 |
+
"X_train = train.iloc[:,1]\n",
|
| 446 |
+
"Y_train = train.iloc[:,2:]"
|
| 447 |
+
],
|
| 448 |
+
"metadata": {
|
| 449 |
+
"id": "j8CQE7Ylf5Eh"
|
| 450 |
+
},
|
| 451 |
+
"execution_count": 11,
|
| 452 |
+
"outputs": []
|
| 453 |
+
},
|
| 454 |
+
{
|
| 455 |
+
"cell_type": "code",
|
| 456 |
+
"source": [
|
| 457 |
+
"X_test = test.iloc[:,1]\n",
|
| 458 |
+
"Y_test = test_labels.iloc[:,1:]"
|
| 459 |
+
],
|
| 460 |
+
"metadata": {
|
| 461 |
+
"id": "DqOgLlX3ErqC"
|
| 462 |
+
},
|
| 463 |
+
"execution_count": 12,
|
| 464 |
+
"outputs": []
|
| 465 |
+
},
|
| 466 |
+
{
|
| 467 |
+
"cell_type": "code",
|
| 468 |
+
"source": [
|
| 469 |
+
"sentences = np.asarray(X_train)"
|
| 470 |
+
],
|
| 471 |
+
"metadata": {
|
| 472 |
+
"id": "fAyLcRFEgNEs"
|
| 473 |
+
},
|
| 474 |
+
"execution_count": 13,
|
| 475 |
+
"outputs": []
|
| 476 |
+
},
|
| 477 |
+
{
|
| 478 |
+
"cell_type": "markdown",
|
| 479 |
+
"source": [
|
| 480 |
+
"**STEP 1: REMOVING CONTRACTIONS**"
|
| 481 |
+
],
|
| 482 |
+
"metadata": {
|
| 483 |
+
"id": "NhKFgZPeo8Vw"
|
| 484 |
+
}
|
| 485 |
+
},
|
| 486 |
+
{
|
| 487 |
+
"cell_type": "code",
|
| 488 |
+
"source": [
|
| 489 |
+
"CONTRACTION_MAP = {\n",
|
| 490 |
+
"\"ain't\": \"is not\",\n",
|
| 491 |
+
"\"aren't\": \"are not\",\n",
|
| 492 |
+
"\"can't\": \"cannot\",\n",
|
| 493 |
+
"\"can't've\": \"cannot have\",\n",
|
| 494 |
+
"\"'cause\": \"because\",\n",
|
| 495 |
+
"\"could've\": \"could have\",\n",
|
| 496 |
+
"\"couldn't\": \"could not\",\n",
|
| 497 |
+
"\"couldn't've\": \"could not have\",\n",
|
| 498 |
+
"\"didn't\": \"did not\",\n",
|
| 499 |
+
"\"doesn't\": \"does not\",\n",
|
| 500 |
+
"\"don't\": \"do not\",\n",
|
| 501 |
+
"\"hadn't\": \"had not\",\n",
|
| 502 |
+
"\"hadn't've\": \"had not have\",\n",
|
| 503 |
+
"\"hasn't\": \"has not\",\n",
|
| 504 |
+
"\"haven't\": \"have not\",\n",
|
| 505 |
+
"\"he'd\": \"he would\",\n",
|
| 506 |
+
"\"he'd've\": \"he would have\",\n",
|
| 507 |
+
"\"he'll\": \"he will\",\n",
|
| 508 |
+
"\"he'll've\": \"he he will have\",\n",
|
| 509 |
+
"\"he's\": \"he is\",\n",
|
| 510 |
+
"\"how'd\": \"how did\",\n",
|
| 511 |
+
"\"how'd'y\": \"how do you\",\n",
|
| 512 |
+
"\"how'll\": \"how will\",\n",
|
| 513 |
+
"\"how's\": \"how is\",\n",
|
| 514 |
+
"\"i'd\": \"i would\",\n",
|
| 515 |
+
"\"i'd've\": \"i would have\",\n",
|
| 516 |
+
"\"i'll\": \"i will\",\n",
|
| 517 |
+
"\"i'll've\": \"i will have\",\n",
|
| 518 |
+
"\"i'm\": \"i am\",\n",
|
| 519 |
+
"\"i've\": \"i have\",\n",
|
| 520 |
+
"\"isn't\": \"is not\",\n",
|
| 521 |
+
"\"it'd\": \"it would\",\n",
|
| 522 |
+
"\"it'd've\": \"it would have\",\n",
|
| 523 |
+
"\"it'll\": \"it will\",\n",
|
| 524 |
+
"\"it'll've\": \"it will have\",\n",
|
| 525 |
+
"\"it's\": \"it is\",\n",
|
| 526 |
+
"\"let's\": \"let us\",\n",
|
| 527 |
+
"\"ma'am\": \"madam\",\n",
|
| 528 |
+
"\"mayn't\": \"may not\",\n",
|
| 529 |
+
"\"might've\": \"might have\",\n",
|
| 530 |
+
"\"mightn't\": \"might not\",\n",
|
| 531 |
+
"\"mightn't've\": \"might not have\",\n",
|
| 532 |
+
"\"must've\": \"must have\",\n",
|
| 533 |
+
"\"mustn't\": \"must not\",\n",
|
| 534 |
+
"\"mustn't've\": \"must not have\",\n",
|
| 535 |
+
"\"needn't\": \"need not\",\n",
|
| 536 |
+
"\"needn't've\": \"need not have\",\n",
|
| 537 |
+
"\"o'clock\": \"of the clock\",\n",
|
| 538 |
+
"\"oughtn't\": \"ought not\",\n",
|
| 539 |
+
"\"oughtn't've\": \"ought not have\",\n",
|
| 540 |
+
"\"shan't\": \"shall not\",\n",
|
| 541 |
+
"\"sha'n't\": \"shall not\",\n",
|
| 542 |
+
"\"shan't've\": \"shall not have\",\n",
|
| 543 |
+
"\"she'd\": \"she would\",\n",
|
| 544 |
+
"\"she'd've\": \"she would have\",\n",
|
| 545 |
+
"\"she'll\": \"she will\",\n",
|
| 546 |
+
"\"she'll've\": \"she will have\",\n",
|
| 547 |
+
"\"she's\": \"she is\",\n",
|
| 548 |
+
"\"should've\": \"should have\",\n",
|
| 549 |
+
"\"shouldn't\": \"should not\",\n",
|
| 550 |
+
"\"shouldn't've\": \"should not have\",\n",
|
| 551 |
+
"\"so've\": \"so have\",\n",
|
| 552 |
+
"\"so's\": \"so as\",\n",
|
| 553 |
+
"\"that'd\": \"that would\",\n",
|
| 554 |
+
"\"that'd've\": \"that would have\",\n",
|
| 555 |
+
"\"that's\": \"that is\",\n",
|
| 556 |
+
"\"there'd\": \"there would\",\n",
|
| 557 |
+
"\"there'd've\": \"there would have\",\n",
|
| 558 |
+
"\"there's\": \"there is\",\n",
|
| 559 |
+
"\"they'd\": \"they would\",\n",
|
| 560 |
+
"\"they'd've\": \"they would have\",\n",
|
| 561 |
+
"\"they'll\": \"they will\",\n",
|
| 562 |
+
"\"they'll've\": \"they will have\",\n",
|
| 563 |
+
"\"they're\": \"they are\",\n",
|
| 564 |
+
"\"they've\": \"they have\",\n",
|
| 565 |
+
"\"to've\": \"to have\",\n",
|
| 566 |
+
"\"wasn't\": \"was not\",\n",
|
| 567 |
+
"\"we'd\": \"we would\",\n",
|
| 568 |
+
"\"we'd've\": \"we would have\",\n",
|
| 569 |
+
"\"we'll\": \"we will\",\n",
|
| 570 |
+
"\"we'll've\": \"we will have\",\n",
|
| 571 |
+
"\"we're\": \"we are\",\n",
|
| 572 |
+
"\"we've\": \"we have\",\n",
|
| 573 |
+
"\"weren't\": \"were not\",\n",
|
| 574 |
+
"\"what'll\": \"what will\",\n",
|
| 575 |
+
"\"what'll've\": \"what will have\",\n",
|
| 576 |
+
"\"what're\": \"what are\",\n",
|
| 577 |
+
"\"what's\": \"what is\",\n",
|
| 578 |
+
"\"what've\": \"what have\",\n",
|
| 579 |
+
"\"when's\": \"when is\",\n",
|
| 580 |
+
"\"when've\": \"when have\",\n",
|
| 581 |
+
"\"where'd\": \"where did\",\n",
|
| 582 |
+
"\"where's\": \"where is\",\n",
|
| 583 |
+
"\"where've\": \"where have\",\n",
|
| 584 |
+
"\"who'll\": \"who will\",\n",
|
| 585 |
+
"\"who'll've\": \"who will have\",\n",
|
| 586 |
+
"\"who's\": \"who is\",\n",
|
| 587 |
+
"\"who've\": \"who have\",\n",
|
| 588 |
+
"\"why's\": \"why is\",\n",
|
| 589 |
+
"\"why've\": \"why have\",\n",
|
| 590 |
+
"\"will've\": \"will have\",\n",
|
| 591 |
+
"\"won't\": \"will not\",\n",
|
| 592 |
+
"\"won't've\": \"will not have\",\n",
|
| 593 |
+
"\"would've\": \"would have\",\n",
|
| 594 |
+
"\"wouldn't\": \"would not\",\n",
|
| 595 |
+
"\"wouldn't've\": \"would not have\",\n",
|
| 596 |
+
"\"y'all\": \"you all\",\n",
|
| 597 |
+
"\"y'all'd\": \"you all would\",\n",
|
| 598 |
+
"\"y'all'd've\": \"you all would have\",\n",
|
| 599 |
+
"\"y'all're\": \"you all are\",\n",
|
| 600 |
+
"\"y'all've\": \"you all have\",\n",
|
| 601 |
+
"\"you'd\": \"you would\",\n",
|
| 602 |
+
"\"you'd've\": \"you would have\",\n",
|
| 603 |
+
"\"you'll\": \"you will\",\n",
|
| 604 |
+
"\"you'll've\": \"you will have\",\n",
|
| 605 |
+
"\"you're\": \"you are\",\n",
|
| 606 |
+
"\"you've\": \"you have\",\n",
|
| 607 |
+
"}"
|
| 608 |
+
],
|
| 609 |
+
"metadata": {
|
| 610 |
+
"id": "SwbHKYS5laGN"
|
| 611 |
+
},
|
| 612 |
+
"execution_count": 14,
|
| 613 |
+
"outputs": []
|
| 614 |
+
},
|
| 615 |
+
{
|
| 616 |
+
"cell_type": "code",
|
| 617 |
+
"source": [
|
| 618 |
+
"def expand_contractions(sentences):\n",
|
| 619 |
+
" contractions_re = re.compile('(%s)'%'|'.join(CONTRACTION_MAP.keys()))\n",
|
| 620 |
+
" def exp_cont(s, contractions_dict=CONTRACTION_MAP):\n",
|
| 621 |
+
" def replace(match):\n",
|
| 622 |
+
" return contractions_dict[match.group(0)]\n",
|
| 623 |
+
" return contractions_re.sub(replace, s)\n",
|
| 624 |
+
" for i in range(len(sentences)):\n",
|
| 625 |
+
" sentences[i] = exp_cont(sentences[i])\n"
|
| 626 |
+
],
|
| 627 |
+
"metadata": {
|
| 628 |
+
"id": "SmK41aqlmDXq"
|
| 629 |
+
},
|
| 630 |
+
"execution_count": 15,
|
| 631 |
+
"outputs": []
|
| 632 |
+
},
|
| 633 |
+
{
|
| 634 |
+
"cell_type": "code",
|
| 635 |
+
"source": [
|
| 636 |
+
"sentences"
|
| 637 |
+
],
|
| 638 |
+
"metadata": {
|
| 639 |
+
"colab": {
|
| 640 |
+
"base_uri": "https://localhost:8080/"
|
| 641 |
+
},
|
| 642 |
+
"id": "XKMkBnBu6aC5",
|
| 643 |
+
"outputId": "ded977d1-dcff-49fc-d7c3-46f7df8e0e74"
|
| 644 |
+
},
|
| 645 |
+
"execution_count": 16,
|
| 646 |
+
"outputs": [
|
| 647 |
+
{
|
| 648 |
+
"output_type": "execute_result",
|
| 649 |
+
"data": {
|
| 650 |
+
"text/plain": [
|
| 651 |
+
"array([\"Explanation\\nWhy the edits made under my username Hardcore Metallica Fan were reverted? They weren't vandalisms, just closure on some GAs after I voted at New York Dolls FAC. And please don't remove the template from the talk page since I'm retired now.89.205.38.27\",\n",
|
| 652 |
+
" \"D'aww! He matches this background colour I'm seemingly stuck with. Thanks. (talk) 21:51, January 11, 2016 (UTC)\",\n",
|
| 653 |
+
" \"Hey man, I'm really not trying to edit war. It's just that this guy is constantly removing relevant information and talking to me through edits instead of my talk page. He seems to care more about the formatting than the actual info.\",\n",
|
| 654 |
+
" ...,\n",
|
| 655 |
+
" 'Spitzer \\n\\nUmm, theres no actual article for prostitution ring. - Crunch Captain.',\n",
|
| 656 |
+
" 'And it looks like it was actually you who put on the speedy to have the first version deleted now that I look at it.',\n",
|
| 657 |
+
" '\"\\nAnd ... I really don\\'t think you understand. I came here and my idea was bad right away. What kind of community goes \"\"you have bad ideas\"\" go away, instead of helping rewrite them. \"'],\n",
|
| 658 |
+
" dtype=object)"
|
| 659 |
+
]
|
| 660 |
+
},
|
| 661 |
+
"metadata": {},
|
| 662 |
+
"execution_count": 16
|
| 663 |
+
}
|
| 664 |
+
]
|
| 665 |
+
},
|
| 666 |
+
{
|
| 667 |
+
"cell_type": "code",
|
| 668 |
+
"source": [
|
| 669 |
+
"# expand_contractions(sentences)"
|
| 670 |
+
],
|
| 671 |
+
"metadata": {
|
| 672 |
+
"id": "4tAHKGfSmwL4"
|
| 673 |
+
},
|
| 674 |
+
"execution_count": 17,
|
| 675 |
+
"outputs": []
|
| 676 |
+
},
|
| 677 |
+
{
|
| 678 |
+
"cell_type": "code",
|
| 679 |
+
"source": [
|
| 680 |
+
"from nltk.tokenize import word_tokenize\n",
|
| 681 |
+
"nltk.download('punkt')\n",
|
| 682 |
+
"word_tokenize(sentences[0])"
|
| 683 |
+
],
|
| 684 |
+
"metadata": {
|
| 685 |
+
"id": "Ic1c0ajxm2Dw",
|
| 686 |
+
"colab": {
|
| 687 |
+
"base_uri": "https://localhost:8080/"
|
| 688 |
+
},
|
| 689 |
+
"outputId": "ada4bd35-7985-4b9f-d3fe-db07bfd85188"
|
| 690 |
+
},
|
| 691 |
+
"execution_count": 18,
|
| 692 |
+
"outputs": [
|
| 693 |
+
{
|
| 694 |
+
"output_type": "stream",
|
| 695 |
+
"name": "stderr",
|
| 696 |
+
"text": [
|
| 697 |
+
"[nltk_data] Downloading package punkt to /root/nltk_data...\n",
|
| 698 |
+
"[nltk_data] Package punkt is already up-to-date!\n"
|
| 699 |
+
]
|
| 700 |
+
},
|
| 701 |
+
{
|
| 702 |
+
"output_type": "execute_result",
|
| 703 |
+
"data": {
|
| 704 |
+
"text/plain": [
|
| 705 |
+
"['Explanation',\n",
|
| 706 |
+
" 'Why',\n",
|
| 707 |
+
" 'the',\n",
|
| 708 |
+
" 'edits',\n",
|
| 709 |
+
" 'made',\n",
|
| 710 |
+
" 'under',\n",
|
| 711 |
+
" 'my',\n",
|
| 712 |
+
" 'username',\n",
|
| 713 |
+
" 'Hardcore',\n",
|
| 714 |
+
" 'Metallica',\n",
|
| 715 |
+
" 'Fan',\n",
|
| 716 |
+
" 'were',\n",
|
| 717 |
+
" 'reverted',\n",
|
| 718 |
+
" '?',\n",
|
| 719 |
+
" 'They',\n",
|
| 720 |
+
" 'were',\n",
|
| 721 |
+
" \"n't\",\n",
|
| 722 |
+
" 'vandalisms',\n",
|
| 723 |
+
" ',',\n",
|
| 724 |
+
" 'just',\n",
|
| 725 |
+
" 'closure',\n",
|
| 726 |
+
" 'on',\n",
|
| 727 |
+
" 'some',\n",
|
| 728 |
+
" 'GAs',\n",
|
| 729 |
+
" 'after',\n",
|
| 730 |
+
" 'I',\n",
|
| 731 |
+
" 'voted',\n",
|
| 732 |
+
" 'at',\n",
|
| 733 |
+
" 'New',\n",
|
| 734 |
+
" 'York',\n",
|
| 735 |
+
" 'Dolls',\n",
|
| 736 |
+
" 'FAC',\n",
|
| 737 |
+
" '.',\n",
|
| 738 |
+
" 'And',\n",
|
| 739 |
+
" 'please',\n",
|
| 740 |
+
" 'do',\n",
|
| 741 |
+
" \"n't\",\n",
|
| 742 |
+
" 'remove',\n",
|
| 743 |
+
" 'the',\n",
|
| 744 |
+
" 'template',\n",
|
| 745 |
+
" 'from',\n",
|
| 746 |
+
" 'the',\n",
|
| 747 |
+
" 'talk',\n",
|
| 748 |
+
" 'page',\n",
|
| 749 |
+
" 'since',\n",
|
| 750 |
+
" 'I',\n",
|
| 751 |
+
" \"'m\",\n",
|
| 752 |
+
" 'retired',\n",
|
| 753 |
+
" 'now.89.205.38.27']"
|
| 754 |
+
]
|
| 755 |
+
},
|
| 756 |
+
"metadata": {},
|
| 757 |
+
"execution_count": 18
|
| 758 |
+
}
|
| 759 |
+
]
|
| 760 |
+
},
|
| 761 |
+
{
|
| 762 |
+
"cell_type": "markdown",
|
| 763 |
+
"source": [
|
| 764 |
+
"**STEP 2 : REMOVE NEWLINES AND TABS**"
|
| 765 |
+
],
|
| 766 |
+
"metadata": {
|
| 767 |
+
"id": "24RwZS7jqpRu"
|
| 768 |
+
}
|
| 769 |
+
},
|
| 770 |
+
{
|
| 771 |
+
"cell_type": "code",
|
| 772 |
+
"source": [
|
| 773 |
+
"def remove_newlines_and_tabs(sentences):\n",
|
| 774 |
+
" \n",
|
| 775 |
+
" for i in range(len(sentences)):\n",
|
| 776 |
+
" sentences[i] = sentences[i].replace('\\n',' ').replace('\\t',' ').replace('\\\\', ' ')"
|
| 777 |
+
],
|
| 778 |
+
"metadata": {
|
| 779 |
+
"id": "hAE_XZhNo6Sg"
|
| 780 |
+
},
|
| 781 |
+
"execution_count": 19,
|
| 782 |
+
"outputs": []
|
| 783 |
+
},
|
| 784 |
+
{
|
| 785 |
+
"cell_type": "code",
|
| 786 |
+
"source": [
|
| 787 |
+
"remove_newlines_and_tabs(sentences)"
|
| 788 |
+
],
|
| 789 |
+
"metadata": {
|
| 790 |
+
"id": "ES2lNuosrlD7"
|
| 791 |
+
},
|
| 792 |
+
"execution_count": 20,
|
| 793 |
+
"outputs": []
|
| 794 |
+
},
|
| 795 |
+
{
|
| 796 |
+
"cell_type": "code",
|
| 797 |
+
"source": [
|
| 798 |
+
"sentences[0]"
|
| 799 |
+
],
|
| 800 |
+
"metadata": {
|
| 801 |
+
"colab": {
|
| 802 |
+
"base_uri": "https://localhost:8080/",
|
| 803 |
+
"height": 70
|
| 804 |
+
},
|
| 805 |
+
"id": "EiYPVRCeroDa",
|
| 806 |
+
"outputId": "40ecf610-3451-4cc4-8cf9-caaab929eed1"
|
| 807 |
+
},
|
| 808 |
+
"execution_count": 21,
|
| 809 |
+
"outputs": [
|
| 810 |
+
{
|
| 811 |
+
"output_type": "execute_result",
|
| 812 |
+
"data": {
|
| 813 |
+
"text/plain": [
|
| 814 |
+
"\"Explanation Why the edits made under my username Hardcore Metallica Fan were reverted? They weren't vandalisms, just closure on some GAs after I voted at New York Dolls FAC. And please don't remove the template from the talk page since I'm retired now.89.205.38.27\""
|
| 815 |
+
],
|
| 816 |
+
"application/vnd.google.colaboratory.intrinsic+json": {
|
| 817 |
+
"type": "string"
|
| 818 |
+
}
|
| 819 |
+
},
|
| 820 |
+
"metadata": {},
|
| 821 |
+
"execution_count": 21
|
| 822 |
+
}
|
| 823 |
+
]
|
| 824 |
+
},
|
| 825 |
+
{
|
| 826 |
+
"cell_type": "markdown",
|
| 827 |
+
"source": [
|
| 828 |
+
"**STEP 3: REMOVE ALL STOPWORDS**"
|
| 829 |
+
],
|
| 830 |
+
"metadata": {
|
| 831 |
+
"id": "Hq8pJmkctVCe"
|
| 832 |
+
}
|
| 833 |
+
},
|
| 834 |
+
{
|
| 835 |
+
"cell_type": "code",
|
| 836 |
+
"source": [
|
| 837 |
+
"stoplist = set(stopwords.words('english'))"
|
| 838 |
+
],
|
| 839 |
+
"metadata": {
|
| 840 |
+
"id": "AkRl7hzAvcfL"
|
| 841 |
+
},
|
| 842 |
+
"execution_count": 22,
|
| 843 |
+
"outputs": []
|
| 844 |
+
},
|
| 845 |
+
{
|
| 846 |
+
"cell_type": "code",
|
| 847 |
+
"source": [
|
| 848 |
+
"stoplist"
|
| 849 |
+
],
|
| 850 |
+
"metadata": {
|
| 851 |
+
"id": "mO2GkSx8v-5y",
|
| 852 |
+
"colab": {
|
| 853 |
+
"base_uri": "https://localhost:8080/"
|
| 854 |
+
},
|
| 855 |
+
"outputId": "afe4c26b-6dad-41db-ca84-56b6e448bf33"
|
| 856 |
+
},
|
| 857 |
+
"execution_count": 23,
|
| 858 |
+
"outputs": [
|
| 859 |
+
{
|
| 860 |
+
"output_type": "execute_result",
|
| 861 |
+
"data": {
|
| 862 |
+
"text/plain": [
|
| 863 |
+
"{'a',\n",
|
| 864 |
+
" 'about',\n",
|
| 865 |
+
" 'above',\n",
|
| 866 |
+
" 'after',\n",
|
| 867 |
+
" 'again',\n",
|
| 868 |
+
" 'against',\n",
|
| 869 |
+
" 'ain',\n",
|
| 870 |
+
" 'all',\n",
|
| 871 |
+
" 'am',\n",
|
| 872 |
+
" 'an',\n",
|
| 873 |
+
" 'and',\n",
|
| 874 |
+
" 'any',\n",
|
| 875 |
+
" 'are',\n",
|
| 876 |
+
" 'aren',\n",
|
| 877 |
+
" \"aren't\",\n",
|
| 878 |
+
" 'as',\n",
|
| 879 |
+
" 'at',\n",
|
| 880 |
+
" 'be',\n",
|
| 881 |
+
" 'because',\n",
|
| 882 |
+
" 'been',\n",
|
| 883 |
+
" 'before',\n",
|
| 884 |
+
" 'being',\n",
|
| 885 |
+
" 'below',\n",
|
| 886 |
+
" 'between',\n",
|
| 887 |
+
" 'both',\n",
|
| 888 |
+
" 'but',\n",
|
| 889 |
+
" 'by',\n",
|
| 890 |
+
" 'can',\n",
|
| 891 |
+
" 'couldn',\n",
|
| 892 |
+
" \"couldn't\",\n",
|
| 893 |
+
" 'd',\n",
|
| 894 |
+
" 'did',\n",
|
| 895 |
+
" 'didn',\n",
|
| 896 |
+
" \"didn't\",\n",
|
| 897 |
+
" 'do',\n",
|
| 898 |
+
" 'does',\n",
|
| 899 |
+
" 'doesn',\n",
|
| 900 |
+
" \"doesn't\",\n",
|
| 901 |
+
" 'doing',\n",
|
| 902 |
+
" 'don',\n",
|
| 903 |
+
" \"don't\",\n",
|
| 904 |
+
" 'down',\n",
|
| 905 |
+
" 'during',\n",
|
| 906 |
+
" 'each',\n",
|
| 907 |
+
" 'few',\n",
|
| 908 |
+
" 'for',\n",
|
| 909 |
+
" 'from',\n",
|
| 910 |
+
" 'further',\n",
|
| 911 |
+
" 'had',\n",
|
| 912 |
+
" 'hadn',\n",
|
| 913 |
+
" \"hadn't\",\n",
|
| 914 |
+
" 'has',\n",
|
| 915 |
+
" 'hasn',\n",
|
| 916 |
+
" \"hasn't\",\n",
|
| 917 |
+
" 'have',\n",
|
| 918 |
+
" 'haven',\n",
|
| 919 |
+
" \"haven't\",\n",
|
| 920 |
+
" 'having',\n",
|
| 921 |
+
" 'he',\n",
|
| 922 |
+
" 'her',\n",
|
| 923 |
+
" 'here',\n",
|
| 924 |
+
" 'hers',\n",
|
| 925 |
+
" 'herself',\n",
|
| 926 |
+
" 'him',\n",
|
| 927 |
+
" 'himself',\n",
|
| 928 |
+
" 'his',\n",
|
| 929 |
+
" 'how',\n",
|
| 930 |
+
" 'i',\n",
|
| 931 |
+
" 'if',\n",
|
| 932 |
+
" 'in',\n",
|
| 933 |
+
" 'into',\n",
|
| 934 |
+
" 'is',\n",
|
| 935 |
+
" 'isn',\n",
|
| 936 |
+
" \"isn't\",\n",
|
| 937 |
+
" 'it',\n",
|
| 938 |
+
" \"it's\",\n",
|
| 939 |
+
" 'its',\n",
|
| 940 |
+
" 'itself',\n",
|
| 941 |
+
" 'just',\n",
|
| 942 |
+
" 'll',\n",
|
| 943 |
+
" 'm',\n",
|
| 944 |
+
" 'ma',\n",
|
| 945 |
+
" 'me',\n",
|
| 946 |
+
" 'mightn',\n",
|
| 947 |
+
" \"mightn't\",\n",
|
| 948 |
+
" 'more',\n",
|
| 949 |
+
" 'most',\n",
|
| 950 |
+
" 'mustn',\n",
|
| 951 |
+
" \"mustn't\",\n",
|
| 952 |
+
" 'my',\n",
|
| 953 |
+
" 'myself',\n",
|
| 954 |
+
" 'needn',\n",
|
| 955 |
+
" \"needn't\",\n",
|
| 956 |
+
" 'no',\n",
|
| 957 |
+
" 'nor',\n",
|
| 958 |
+
" 'not',\n",
|
| 959 |
+
" 'now',\n",
|
| 960 |
+
" 'o',\n",
|
| 961 |
+
" 'of',\n",
|
| 962 |
+
" 'off',\n",
|
| 963 |
+
" 'on',\n",
|
| 964 |
+
" 'once',\n",
|
| 965 |
+
" 'only',\n",
|
| 966 |
+
" 'or',\n",
|
| 967 |
+
" 'other',\n",
|
| 968 |
+
" 'our',\n",
|
| 969 |
+
" 'ours',\n",
|
| 970 |
+
" 'ourselves',\n",
|
| 971 |
+
" 'out',\n",
|
| 972 |
+
" 'over',\n",
|
| 973 |
+
" 'own',\n",
|
| 974 |
+
" 're',\n",
|
| 975 |
+
" 's',\n",
|
| 976 |
+
" 'same',\n",
|
| 977 |
+
" 'shan',\n",
|
| 978 |
+
" \"shan't\",\n",
|
| 979 |
+
" 'she',\n",
|
| 980 |
+
" \"she's\",\n",
|
| 981 |
+
" 'should',\n",
|
| 982 |
+
" \"should've\",\n",
|
| 983 |
+
" 'shouldn',\n",
|
| 984 |
+
" \"shouldn't\",\n",
|
| 985 |
+
" 'so',\n",
|
| 986 |
+
" 'some',\n",
|
| 987 |
+
" 'such',\n",
|
| 988 |
+
" 't',\n",
|
| 989 |
+
" 'than',\n",
|
| 990 |
+
" 'that',\n",
|
| 991 |
+
" \"that'll\",\n",
|
| 992 |
+
" 'the',\n",
|
| 993 |
+
" 'their',\n",
|
| 994 |
+
" 'theirs',\n",
|
| 995 |
+
" 'them',\n",
|
| 996 |
+
" 'themselves',\n",
|
| 997 |
+
" 'then',\n",
|
| 998 |
+
" 'there',\n",
|
| 999 |
+
" 'these',\n",
|
| 1000 |
+
" 'they',\n",
|
| 1001 |
+
" 'this',\n",
|
| 1002 |
+
" 'those',\n",
|
| 1003 |
+
" 'through',\n",
|
| 1004 |
+
" 'to',\n",
|
| 1005 |
+
" 'too',\n",
|
| 1006 |
+
" 'under',\n",
|
| 1007 |
+
" 'until',\n",
|
| 1008 |
+
" 'up',\n",
|
| 1009 |
+
" 've',\n",
|
| 1010 |
+
" 'very',\n",
|
| 1011 |
+
" 'was',\n",
|
| 1012 |
+
" 'wasn',\n",
|
| 1013 |
+
" \"wasn't\",\n",
|
| 1014 |
+
" 'we',\n",
|
| 1015 |
+
" 'were',\n",
|
| 1016 |
+
" 'weren',\n",
|
| 1017 |
+
" \"weren't\",\n",
|
| 1018 |
+
" 'what',\n",
|
| 1019 |
+
" 'when',\n",
|
| 1020 |
+
" 'where',\n",
|
| 1021 |
+
" 'which',\n",
|
| 1022 |
+
" 'while',\n",
|
| 1023 |
+
" 'who',\n",
|
| 1024 |
+
" 'whom',\n",
|
| 1025 |
+
" 'why',\n",
|
| 1026 |
+
" 'will',\n",
|
| 1027 |
+
" 'with',\n",
|
| 1028 |
+
" 'won',\n",
|
| 1029 |
+
" \"won't\",\n",
|
| 1030 |
+
" 'wouldn',\n",
|
| 1031 |
+
" \"wouldn't\",\n",
|
| 1032 |
+
" 'y',\n",
|
| 1033 |
+
" 'you',\n",
|
| 1034 |
+
" \"you'd\",\n",
|
| 1035 |
+
" \"you'll\",\n",
|
| 1036 |
+
" \"you're\",\n",
|
| 1037 |
+
" \"you've\",\n",
|
| 1038 |
+
" 'your',\n",
|
| 1039 |
+
" 'yours',\n",
|
| 1040 |
+
" 'yourself',\n",
|
| 1041 |
+
" 'yourselves'}"
|
| 1042 |
+
]
|
| 1043 |
+
},
|
| 1044 |
+
"metadata": {},
|
| 1045 |
+
"execution_count": 23
|
| 1046 |
+
}
|
| 1047 |
+
]
|
| 1048 |
+
},
|
| 1049 |
+
{
|
| 1050 |
+
"cell_type": "code",
|
| 1051 |
+
"source": [
|
| 1052 |
+
"def remove_stopwords(sentences):\n",
|
| 1053 |
+
" for i in range(len(sentences)):\n",
|
| 1054 |
+
" tokens = word_tokenize(sentences[i])\n",
|
| 1055 |
+
" \n",
|
| 1056 |
+
" filtered_tokens = [token for token in tokens if token.lower() not in stoplist]\n",
|
| 1057 |
+
" sentences[i] = \" \".join(filtered_tokens)"
|
| 1058 |
+
],
|
| 1059 |
+
"metadata": {
|
| 1060 |
+
"id": "eFM8kzLywViL"
|
| 1061 |
+
},
|
| 1062 |
+
"execution_count": 24,
|
| 1063 |
+
"outputs": []
|
| 1064 |
+
},
|
| 1065 |
+
{
|
| 1066 |
+
"cell_type": "code",
|
| 1067 |
+
"source": [
|
| 1068 |
+
"# remove_stopwords(sentences)"
|
| 1069 |
+
],
|
| 1070 |
+
"metadata": {
|
| 1071 |
+
"id": "DxM1LXQ-xOsx"
|
| 1072 |
+
},
|
| 1073 |
+
"execution_count": 25,
|
| 1074 |
+
"outputs": []
|
| 1075 |
+
},
|
| 1076 |
+
{
|
| 1077 |
+
"cell_type": "code",
|
| 1078 |
+
"source": [
|
| 1079 |
+
"sentences[0]"
|
| 1080 |
+
],
|
| 1081 |
+
"metadata": {
|
| 1082 |
+
"colab": {
|
| 1083 |
+
"base_uri": "https://localhost:8080/",
|
| 1084 |
+
"height": 70
|
| 1085 |
+
},
|
| 1086 |
+
"id": "zBKsllEvxYqp",
|
| 1087 |
+
"outputId": "a1e0cd93-e4d8-4af4-d81a-c2fc787e8220"
|
| 1088 |
+
},
|
| 1089 |
+
"execution_count": 26,
|
| 1090 |
+
"outputs": [
|
| 1091 |
+
{
|
| 1092 |
+
"output_type": "execute_result",
|
| 1093 |
+
"data": {
|
| 1094 |
+
"text/plain": [
|
| 1095 |
+
"\"Explanation Why the edits made under my username Hardcore Metallica Fan were reverted? They weren't vandalisms, just closure on some GAs after I voted at New York Dolls FAC. And please don't remove the template from the talk page since I'm retired now.89.205.38.27\""
|
| 1096 |
+
],
|
| 1097 |
+
"application/vnd.google.colaboratory.intrinsic+json": {
|
| 1098 |
+
"type": "string"
|
| 1099 |
+
}
|
| 1100 |
+
},
|
| 1101 |
+
"metadata": {},
|
| 1102 |
+
"execution_count": 26
|
| 1103 |
+
}
|
| 1104 |
+
]
|
| 1105 |
+
},
|
| 1106 |
+
{
|
| 1107 |
+
"cell_type": "code",
|
| 1108 |
+
"source": [
|
| 1109 |
+
"X_train[0]"
|
| 1110 |
+
],
|
| 1111 |
+
"metadata": {
|
| 1112 |
+
"colab": {
|
| 1113 |
+
"base_uri": "https://localhost:8080/",
|
| 1114 |
+
"height": 70
|
| 1115 |
+
},
|
| 1116 |
+
"id": "SFBlPvME445_",
|
| 1117 |
+
"outputId": "9da0c4d0-2ccd-4552-de9c-b6195c8cc6f2"
|
| 1118 |
+
},
|
| 1119 |
+
"execution_count": 27,
|
| 1120 |
+
"outputs": [
|
| 1121 |
+
{
|
| 1122 |
+
"output_type": "execute_result",
|
| 1123 |
+
"data": {
|
| 1124 |
+
"text/plain": [
|
| 1125 |
+
"\"Explanation Why the edits made under my username Hardcore Metallica Fan were reverted? They weren't vandalisms, just closure on some GAs after I voted at New York Dolls FAC. And please don't remove the template from the talk page since I'm retired now.89.205.38.27\""
|
| 1126 |
+
],
|
| 1127 |
+
"application/vnd.google.colaboratory.intrinsic+json": {
|
| 1128 |
+
"type": "string"
|
| 1129 |
+
}
|
| 1130 |
+
},
|
| 1131 |
+
"metadata": {},
|
| 1132 |
+
"execution_count": 27
|
| 1133 |
+
}
|
| 1134 |
+
]
|
| 1135 |
+
},
|
| 1136 |
+
{
|
| 1137 |
+
"cell_type": "markdown",
|
| 1138 |
+
"source": [
|
| 1139 |
+
"**STEP 4: LEMMETIZATION**"
|
| 1140 |
+
],
|
| 1141 |
+
"metadata": {
|
| 1142 |
+
"id": "xFJzNYvb5HgE"
|
| 1143 |
+
}
|
| 1144 |
+
},
|
| 1145 |
+
{
|
| 1146 |
+
"cell_type": "code",
|
| 1147 |
+
"source": [
|
| 1148 |
+
"nltk.download('wordnet')\n",
|
| 1149 |
+
"nltk.download('omw-1.4')"
|
| 1150 |
+
],
|
| 1151 |
+
"metadata": {
|
| 1152 |
+
"colab": {
|
| 1153 |
+
"base_uri": "https://localhost:8080/"
|
| 1154 |
+
},
|
| 1155 |
+
"id": "nidlSbOF54Eg",
|
| 1156 |
+
"outputId": "940afaf6-7680-4ee5-d136-2ee178658285"
|
| 1157 |
+
},
|
| 1158 |
+
"execution_count": 28,
|
| 1159 |
+
"outputs": [
|
| 1160 |
+
{
|
| 1161 |
+
"output_type": "stream",
|
| 1162 |
+
"name": "stderr",
|
| 1163 |
+
"text": [
|
| 1164 |
+
"[nltk_data] Downloading package wordnet to /root/nltk_data...\n",
|
| 1165 |
+
"[nltk_data] Unzipping corpora/wordnet.zip.\n",
|
| 1166 |
+
"[nltk_data] Downloading package omw-1.4 to /root/nltk_data...\n",
|
| 1167 |
+
"[nltk_data] Unzipping corpora/omw-1.4.zip.\n"
|
| 1168 |
+
]
|
| 1169 |
+
},
|
| 1170 |
+
{
|
| 1171 |
+
"output_type": "execute_result",
|
| 1172 |
+
"data": {
|
| 1173 |
+
"text/plain": [
|
| 1174 |
+
"True"
|
| 1175 |
+
]
|
| 1176 |
+
},
|
| 1177 |
+
"metadata": {},
|
| 1178 |
+
"execution_count": 28
|
| 1179 |
+
}
|
| 1180 |
+
]
|
| 1181 |
+
},
|
| 1182 |
+
{
|
| 1183 |
+
"cell_type": "code",
|
| 1184 |
+
"source": [
|
| 1185 |
+
"w_tokenizer = nltk.tokenize.WhitespaceTokenizer()\n",
|
| 1186 |
+
"lemmatizer = nltk.stem.WordNetLemmatizer()"
|
| 1187 |
+
],
|
| 1188 |
+
"metadata": {
|
| 1189 |
+
"id": "AR4oMkl84_0S"
|
| 1190 |
+
},
|
| 1191 |
+
"execution_count": 29,
|
| 1192 |
+
"outputs": []
|
| 1193 |
+
},
|
| 1194 |
+
{
|
| 1195 |
+
"cell_type": "code",
|
| 1196 |
+
"source": [
|
| 1197 |
+
"def lemmetization(sentences):\n",
|
| 1198 |
+
" for i in range(len(sentences)):\n",
|
| 1199 |
+
" lemma = [lemmatizer.lemmatize(w,'v') for w in w_tokenizer.tokenize(sentences[i])]\n",
|
| 1200 |
+
"\n",
|
| 1201 |
+
" sentences[i] = \" \".join(lemma)"
|
| 1202 |
+
],
|
| 1203 |
+
"metadata": {
|
| 1204 |
+
"id": "ecvmGMq_5jFV"
|
| 1205 |
+
},
|
| 1206 |
+
"execution_count": 30,
|
| 1207 |
+
"outputs": []
|
| 1208 |
+
},
|
| 1209 |
+
{
|
| 1210 |
+
"cell_type": "code",
|
| 1211 |
+
"source": [
|
| 1212 |
+
"# lemmetization(sentences)"
|
| 1213 |
+
],
|
| 1214 |
+
"metadata": {
|
| 1215 |
+
"id": "i7WGctMU5zc3"
|
| 1216 |
+
},
|
| 1217 |
+
"execution_count": 31,
|
| 1218 |
+
"outputs": []
|
| 1219 |
+
},
|
| 1220 |
+
{
|
| 1221 |
+
"cell_type": "code",
|
| 1222 |
+
"source": [
|
| 1223 |
+
"sentences[0]"
|
| 1224 |
+
],
|
| 1225 |
+
"metadata": {
|
| 1226 |
+
"colab": {
|
| 1227 |
+
"base_uri": "https://localhost:8080/",
|
| 1228 |
+
"height": 70
|
| 1229 |
+
},
|
| 1230 |
+
"id": "hOBeoBDx5-Lb",
|
| 1231 |
+
"outputId": "b4cac999-d23b-451d-85ed-983dc80bcf65"
|
| 1232 |
+
},
|
| 1233 |
+
"execution_count": 32,
|
| 1234 |
+
"outputs": [
|
| 1235 |
+
{
|
| 1236 |
+
"output_type": "execute_result",
|
| 1237 |
+
"data": {
|
| 1238 |
+
"text/plain": [
|
| 1239 |
+
"\"Explanation Why the edits made under my username Hardcore Metallica Fan were reverted? They weren't vandalisms, just closure on some GAs after I voted at New York Dolls FAC. And please don't remove the template from the talk page since I'm retired now.89.205.38.27\""
|
| 1240 |
+
],
|
| 1241 |
+
"application/vnd.google.colaboratory.intrinsic+json": {
|
| 1242 |
+
"type": "string"
|
| 1243 |
+
}
|
| 1244 |
+
},
|
| 1245 |
+
"metadata": {},
|
| 1246 |
+
"execution_count": 32
|
| 1247 |
+
}
|
| 1248 |
+
]
|
| 1249 |
+
},
|
| 1250 |
+
{
|
| 1251 |
+
"cell_type": "markdown",
|
| 1252 |
+
"source": [
|
| 1253 |
+
"**COMPLETE PREPROCESSING**"
|
| 1254 |
+
],
|
| 1255 |
+
"metadata": {
|
| 1256 |
+
"id": "FsxyOMoIfGX7"
|
| 1257 |
+
}
|
| 1258 |
+
},
|
| 1259 |
+
{
|
| 1260 |
+
"cell_type": "code",
|
| 1261 |
+
"source": [
|
| 1262 |
+
"def preprocess(sentences):\n",
|
| 1263 |
+
" expand_contractions(sentences)\n",
|
| 1264 |
+
" remove_newlines_and_tabs(sentences)\n",
|
| 1265 |
+
" remove_stopwords(sentences)\n",
|
| 1266 |
+
" lemmetization(sentences)\n"
|
| 1267 |
+
],
|
| 1268 |
+
"metadata": {
|
| 1269 |
+
"id": "x6lG8QmcfM3I"
|
| 1270 |
+
},
|
| 1271 |
+
"execution_count": 33,
|
| 1272 |
+
"outputs": []
|
| 1273 |
+
},
|
| 1274 |
+
{
|
| 1275 |
+
"cell_type": "code",
|
| 1276 |
+
"source": [
|
| 1277 |
+
"X_train = np.asarray(X_train)\n"
|
| 1278 |
+
],
|
| 1279 |
+
"metadata": {
|
| 1280 |
+
"id": "MOqqqCaTiSxP"
|
| 1281 |
+
},
|
| 1282 |
+
"execution_count": 34,
|
| 1283 |
+
"outputs": []
|
| 1284 |
+
},
|
| 1285 |
+
{
|
| 1286 |
+
"cell_type": "code",
|
| 1287 |
+
"source": [
|
| 1288 |
+
"X_test = np.asarray(X_test)"
|
| 1289 |
+
],
|
| 1290 |
+
"metadata": {
|
| 1291 |
+
"id": "Fe2ae8plibLg"
|
| 1292 |
+
},
|
| 1293 |
+
"execution_count": 35,
|
| 1294 |
+
"outputs": []
|
| 1295 |
+
},
|
| 1296 |
+
{
|
| 1297 |
+
"cell_type": "code",
|
| 1298 |
+
"source": [
|
| 1299 |
+
"# try:\n",
|
| 1300 |
+
"# file = open('X_train.pickle')\n",
|
| 1301 |
+
"# X_train = pickle.load(file)\n",
|
| 1302 |
+
"# except:\n",
|
| 1303 |
+
"# preprocess(X_train)"
|
| 1304 |
+
],
|
| 1305 |
+
"metadata": {
|
| 1306 |
+
"id": "LLMhKjStfgUI"
|
| 1307 |
+
},
|
| 1308 |
+
"execution_count": 36,
|
| 1309 |
+
"outputs": []
|
| 1310 |
+
},
|
| 1311 |
+
{
|
| 1312 |
+
"cell_type": "code",
|
| 1313 |
+
"source": [
|
| 1314 |
+
"# try:\n",
|
| 1315 |
+
"# file = open('X_test.pickle')\n",
|
| 1316 |
+
"# X_test = pickle.load(file)\n",
|
| 1317 |
+
"# except:\n",
|
| 1318 |
+
"# preprocess(X_test)"
|
| 1319 |
+
],
|
| 1320 |
+
"metadata": {
|
| 1321 |
+
"id": "ra6ArxduicgO"
|
| 1322 |
+
},
|
| 1323 |
+
"execution_count": 37,
|
| 1324 |
+
"outputs": []
|
| 1325 |
+
},
|
| 1326 |
+
{
|
| 1327 |
+
"cell_type": "code",
|
| 1328 |
+
"source": [
|
| 1329 |
+
"preprocess(X_train)\n"
|
| 1330 |
+
],
|
| 1331 |
+
"metadata": {
|
| 1332 |
+
"id": "p6hpfOgYUM2s"
|
| 1333 |
+
},
|
| 1334 |
+
"execution_count": 38,
|
| 1335 |
+
"outputs": []
|
| 1336 |
+
},
|
| 1337 |
+
{
|
| 1338 |
+
"cell_type": "code",
|
| 1339 |
+
"source": [
|
| 1340 |
+
"preprocess(X_test)"
|
| 1341 |
+
],
|
| 1342 |
+
"metadata": {
|
| 1343 |
+
"id": "60Cxbqm6a6-x",
|
| 1344 |
+
"colab": {
|
| 1345 |
+
"base_uri": "https://localhost:8080/",
|
| 1346 |
+
"height": 311
|
| 1347 |
+
},
|
| 1348 |
+
"outputId": "c2901f80-a873-4d9a-afda-ee542d7fd391"
|
| 1349 |
+
},
|
| 1350 |
+
"execution_count": 39,
|
| 1351 |
+
"outputs": [
|
| 1352 |
+
{
|
| 1353 |
+
"output_type": "error",
|
| 1354 |
+
"ename": "KeyboardInterrupt",
|
| 1355 |
+
"evalue": "ignored",
|
| 1356 |
+
"traceback": [
|
| 1357 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
| 1358 |
+
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
| 1359 |
+
"\u001b[0;32m<ipython-input-39-e1adff6a4102>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mpreprocess\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX_test\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
| 1360 |
+
"\u001b[0;32m<ipython-input-33-5bcef99561d9>\u001b[0m in \u001b[0;36mpreprocess\u001b[0;34m(sentences)\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mexpand_contractions\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msentences\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mremove_newlines_and_tabs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msentences\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mremove_stopwords\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msentences\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0mlemmetization\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msentences\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
| 1361 |
+
"\u001b[0;32m<ipython-input-24-b8fe72b23e7b>\u001b[0m in \u001b[0;36mremove_stopwords\u001b[0;34m(sentences)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mremove_stopwords\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msentences\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msentences\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mtokens\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mword_tokenize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msentences\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mfiltered_tokens\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mtoken\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mtoken\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mtokens\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtoken\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlower\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mstoplist\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
| 1362 |
+
"\u001b[0;32m/usr/local/lib/python3.7/dist-packages/nltk/tokenize/__init__.py\u001b[0m in \u001b[0;36mword_tokenize\u001b[0;34m(text, language, preserve_line)\u001b[0m\n\u001b[1;32m 129\u001b[0m \u001b[0msentences\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mpreserve_line\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0msent_tokenize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlanguage\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 130\u001b[0m return [\n\u001b[0;32m--> 131\u001b[0;31m \u001b[0mtoken\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0msent\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msentences\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mtoken\u001b[0m \u001b[0;32min\u001b[0m \u001b[0m_treebank_word_tokenizer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtokenize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msent\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 132\u001b[0m ]\n",
|
| 1363 |
+
"\u001b[0;32m/usr/local/lib/python3.7/dist-packages/nltk/tokenize/__init__.py\u001b[0m in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 129\u001b[0m \u001b[0msentences\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mpreserve_line\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0msent_tokenize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlanguage\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 130\u001b[0m return [\n\u001b[0;32m--> 131\u001b[0;31m \u001b[0mtoken\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0msent\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msentences\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mtoken\u001b[0m \u001b[0;32min\u001b[0m \u001b[0m_treebank_word_tokenizer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtokenize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msent\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 132\u001b[0m ]\n",
|
| 1364 |
+
"\u001b[0;32m/usr/local/lib/python3.7/dist-packages/nltk/tokenize/destructive.py\u001b[0m in \u001b[0;36mtokenize\u001b[0;34m(self, text, convert_parentheses, return_str)\u001b[0m\n\u001b[1;32m 177\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 178\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mregexp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msubstitution\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mENDING_QUOTES\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 179\u001b[0;31m \u001b[0mtext\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mregexp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msub\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msubstitution\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 180\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 181\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mregexp\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mCONTRACTIONS2\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
| 1365 |
+
"\u001b[0;32m/usr/lib/python3.7/re.py\u001b[0m in \u001b[0;36m_subx\u001b[0;34m(pattern, template)\u001b[0m\n\u001b[1;32m 307\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0msre_parse\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexpand_template\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtemplate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmatch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 308\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 309\u001b[0;31m \u001b[0;32mdef\u001b[0m \u001b[0m_subx\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpattern\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtemplate\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 310\u001b[0m \u001b[0;31m# internal: Pattern.sub/subn implementation helper\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 311\u001b[0m \u001b[0mtemplate\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_compile_repl\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtemplate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpattern\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
| 1366 |
+
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
|
| 1367 |
+
]
|
| 1368 |
+
}
|
| 1369 |
+
]
|
| 1370 |
+
},
|
| 1371 |
+
{
|
| 1372 |
+
"cell_type": "code",
|
| 1373 |
+
"source": [
|
| 1374 |
+
"len(X_train)"
|
| 1375 |
+
],
|
| 1376 |
+
"metadata": {
|
| 1377 |
+
"id": "f64s33hMWHAR"
|
| 1378 |
+
},
|
| 1379 |
+
"execution_count": null,
|
| 1380 |
+
"outputs": []
|
| 1381 |
+
},
|
| 1382 |
+
{
|
| 1383 |
+
"cell_type": "code",
|
| 1384 |
+
"source": [
|
| 1385 |
+
"len(Y_train)"
|
| 1386 |
+
],
|
| 1387 |
+
"metadata": {
|
| 1388 |
+
"id": "Y1CJHBIoWIfX"
|
| 1389 |
+
},
|
| 1390 |
+
"execution_count": null,
|
| 1391 |
+
"outputs": []
|
| 1392 |
+
},
|
| 1393 |
+
{
|
| 1394 |
+
"cell_type": "code",
|
| 1395 |
+
"source": [
|
| 1396 |
+
"X_train[:10]"
|
| 1397 |
+
],
|
| 1398 |
+
"metadata": {
|
| 1399 |
+
"id": "Zhj2NzjVRivv"
|
| 1400 |
+
},
|
| 1401 |
+
"execution_count": null,
|
| 1402 |
+
"outputs": []
|
| 1403 |
+
},
|
| 1404 |
+
{
|
| 1405 |
+
"cell_type": "code",
|
| 1406 |
+
"source": [
|
| 1407 |
+
"X_train[:10]"
|
| 1408 |
+
],
|
| 1409 |
+
"metadata": {
|
| 1410 |
+
"id": "hghd8rlsgiNt"
|
| 1411 |
+
},
|
| 1412 |
+
"execution_count": null,
|
| 1413 |
+
"outputs": []
|
| 1414 |
+
},
|
| 1415 |
+
{
|
| 1416 |
+
"cell_type": "markdown",
|
| 1417 |
+
"source": [
|
| 1418 |
+
""
|
| 1419 |
+
],
|
| 1420 |
+
"metadata": {
|
| 1421 |
+
"id": "E8pMmNvHfPXC"
|
| 1422 |
+
}
|
| 1423 |
+
},
|
| 1424 |
+
{
|
| 1425 |
+
"cell_type": "code",
|
| 1426 |
+
"source": [
|
| 1427 |
+
"import pickle\n",
|
| 1428 |
+
"\n",
|
| 1429 |
+
"# Store data (serialize)\n",
|
| 1430 |
+
"with open('X_train.pickle', 'wb') as handle:\n",
|
| 1431 |
+
" pickle.dump(X_train, handle, protocol=pickle.HIGHEST_PROTOCOL)"
|
| 1432 |
+
],
|
| 1433 |
+
"metadata": {
|
| 1434 |
+
"id": "hZOaW4aEk4xe"
|
| 1435 |
+
},
|
| 1436 |
+
"execution_count": null,
|
| 1437 |
+
"outputs": []
|
| 1438 |
+
},
|
| 1439 |
+
{
|
| 1440 |
+
"cell_type": "code",
|
| 1441 |
+
"source": [
|
| 1442 |
+
"import pickle\n",
|
| 1443 |
+
"\n",
|
| 1444 |
+
"# Store data (serialize)\n",
|
| 1445 |
+
"with open('X_test.pickle', 'wb') as handle:\n",
|
| 1446 |
+
" pickle.dump(X_test, handle, protocol=pickle.HIGHEST_PROTOCOL)"
|
| 1447 |
+
],
|
| 1448 |
+
"metadata": {
|
| 1449 |
+
"id": "klbZTEsak9XA"
|
| 1450 |
+
},
|
| 1451 |
+
"execution_count": null,
|
| 1452 |
+
"outputs": []
|
| 1453 |
+
},
|
| 1454 |
+
{
|
| 1455 |
+
"cell_type": "markdown",
|
| 1456 |
+
"source": [
|
| 1457 |
+
"**STEP 5: TOKENIZATION**"
|
| 1458 |
+
],
|
| 1459 |
+
"metadata": {
|
| 1460 |
+
"id": "8Z_YNy2pjkm2"
|
| 1461 |
+
}
|
| 1462 |
+
},
|
| 1463 |
+
{
|
| 1464 |
+
"cell_type": "code",
|
| 1465 |
+
"source": [
|
| 1466 |
+
"tokenizer = Tokenizer()"
|
| 1467 |
+
],
|
| 1468 |
+
"metadata": {
|
| 1469 |
+
"id": "xXv3o79Djkm9"
|
| 1470 |
+
},
|
| 1471 |
+
"execution_count": 61,
|
| 1472 |
+
"outputs": []
|
| 1473 |
+
},
|
| 1474 |
+
{
|
| 1475 |
+
"cell_type": "code",
|
| 1476 |
+
"source": [
|
| 1477 |
+
"tokenizer.fit_on_texts(X_train)"
|
| 1478 |
+
],
|
| 1479 |
+
"metadata": {
|
| 1480 |
+
"id": "WgbvrxJBjkm-"
|
| 1481 |
+
},
|
| 1482 |
+
"execution_count": 62,
|
| 1483 |
+
"outputs": []
|
| 1484 |
+
},
|
| 1485 |
+
{
|
| 1486 |
+
"cell_type": "code",
|
| 1487 |
+
"source": [
|
| 1488 |
+
"X_train"
|
| 1489 |
+
],
|
| 1490 |
+
"metadata": {
|
| 1491 |
+
"id": "OH9-l_l2j7Bv",
|
| 1492 |
+
"colab": {
|
| 1493 |
+
"base_uri": "https://localhost:8080/"
|
| 1494 |
+
},
|
| 1495 |
+
"outputId": "d9ef3853-977e-4340-9923-b3576cd2d19e"
|
| 1496 |
+
},
|
| 1497 |
+
"execution_count": 63,
|
| 1498 |
+
"outputs": [
|
| 1499 |
+
{
|
| 1500 |
+
"output_type": "execute_result",
|
| 1501 |
+
"data": {
|
| 1502 |
+
"text/plain": [
|
| 1503 |
+
"array([\"Explanation edit make username Hardcore Metallica Fan revert ? vandalisms , closure GAs vote New York Dolls FAC . please remove template talk page since 'm retire now.89.205.38.27\",\n",
|
| 1504 |
+
" \"D'aww ! match background colour 'm seemingly stick . Thanks . ( talk ) 21:51 , January 11 , 2016 ( UTC )\",\n",
|
| 1505 |
+
" \"Hey man , 'm really try edit war . 's guy constantly remove relevant information talk edit instead talk page . seem care format actual info .\",\n",
|
| 1506 |
+
" ...,\n",
|
| 1507 |
+
" 'Spitzer Umm , theres actual article prostitution ring . - Crunch Captain .',\n",
|
| 1508 |
+
" 'look like actually put speedy first version delete look .',\n",
|
| 1509 |
+
" \"`` ... really think understand . come idea bad right away . kind community go `` '' bad ideas '' '' go away , instead help rewrite them. ``\"],\n",
|
| 1510 |
+
" dtype=object)"
|
| 1511 |
+
]
|
| 1512 |
+
},
|
| 1513 |
+
"metadata": {},
|
| 1514 |
+
"execution_count": 63
|
| 1515 |
+
}
|
| 1516 |
+
]
|
| 1517 |
+
},
|
| 1518 |
+
{
|
| 1519 |
+
"cell_type": "code",
|
| 1520 |
+
"source": [
|
| 1521 |
+
"X_train_tokenized = tokenizer.texts_to_sequences(X_train)"
|
| 1522 |
+
],
|
| 1523 |
+
"metadata": {
|
| 1524 |
+
"id": "_HMHOBXgjkm-"
|
| 1525 |
+
},
|
| 1526 |
+
"execution_count": 64,
|
| 1527 |
+
"outputs": []
|
| 1528 |
+
},
|
| 1529 |
+
{
|
| 1530 |
+
"cell_type": "code",
|
| 1531 |
+
"source": [
|
| 1532 |
+
"X_train_tokenized"
|
| 1533 |
+
],
|
| 1534 |
+
"metadata": {
|
| 1535 |
+
"id": "by_5XhtTjkm-"
|
| 1536 |
+
},
|
| 1537 |
+
"execution_count": null,
|
| 1538 |
+
"outputs": []
|
| 1539 |
+
},
|
| 1540 |
+
{
|
| 1541 |
+
"cell_type": "code",
|
| 1542 |
+
"source": [
|
| 1543 |
+
""
|
| 1544 |
+
],
|
| 1545 |
+
"metadata": {
|
| 1546 |
+
"id": "Sr3MNvqvjqrb"
|
| 1547 |
+
},
|
| 1548 |
+
"execution_count": null,
|
| 1549 |
+
"outputs": []
|
| 1550 |
+
},
|
| 1551 |
+
{
|
| 1552 |
+
"cell_type": "markdown",
|
| 1553 |
+
"source": [
|
| 1554 |
+
"**STEP 6: FIND MAX LENGTH OF SENTENCES**"
|
| 1555 |
+
],
|
| 1556 |
+
"metadata": {
|
| 1557 |
+
"id": "5IBFsrGXsu3F"
|
| 1558 |
+
}
|
| 1559 |
+
},
|
| 1560 |
+
{
|
| 1561 |
+
"cell_type": "code",
|
| 1562 |
+
"source": [
|
| 1563 |
+
"max_len = 0\n",
|
| 1564 |
+
"test = \"\"\n",
|
| 1565 |
+
"j=0\n",
|
| 1566 |
+
"for i,sentence in enumerate(X_train_tokenized):\n",
|
| 1567 |
+
" length = len(sentence)\n",
|
| 1568 |
+
" if length>max_len:\n",
|
| 1569 |
+
" j=i\n",
|
| 1570 |
+
" max_len = length\n",
|
| 1571 |
+
" test = sentence"
|
| 1572 |
+
],
|
| 1573 |
+
"metadata": {
|
| 1574 |
+
"id": "EcFlSbPgstPo"
|
| 1575 |
+
},
|
| 1576 |
+
"execution_count": 45,
|
| 1577 |
+
"outputs": []
|
| 1578 |
+
},
|
| 1579 |
+
{
|
| 1580 |
+
"cell_type": "code",
|
| 1581 |
+
"source": [
|
| 1582 |
+
"max_len"
|
| 1583 |
+
],
|
| 1584 |
+
"metadata": {
|
| 1585 |
+
"colab": {
|
| 1586 |
+
"base_uri": "https://localhost:8080/"
|
| 1587 |
+
},
|
| 1588 |
+
"id": "2U5-2NbqtJMK",
|
| 1589 |
+
"outputId": "4968498b-afeb-4032-811b-98e258564d56"
|
| 1590 |
+
},
|
| 1591 |
+
"execution_count": 46,
|
| 1592 |
+
"outputs": [
|
| 1593 |
+
{
|
| 1594 |
+
"output_type": "execute_result",
|
| 1595 |
+
"data": {
|
| 1596 |
+
"text/plain": [
|
| 1597 |
+
"1348"
|
| 1598 |
+
]
|
| 1599 |
+
},
|
| 1600 |
+
"metadata": {},
|
| 1601 |
+
"execution_count": 46
|
| 1602 |
+
}
|
| 1603 |
+
]
|
| 1604 |
+
},
|
| 1605 |
+
{
|
| 1606 |
+
"cell_type": "markdown",
|
| 1607 |
+
"source": [
|
| 1608 |
+
"**STEP 7 : PAD SEQUENCES**"
|
| 1609 |
+
],
|
| 1610 |
+
"metadata": {
|
| 1611 |
+
"id": "NsRq1qlXv-bk"
|
| 1612 |
+
}
|
| 1613 |
+
},
|
| 1614 |
+
{
|
| 1615 |
+
"cell_type": "code",
|
| 1616 |
+
"source": [
|
| 1617 |
+
"X_train_processed = pad_sequences(X_train_tokenized,maxlen=max_len,padding = 'post')"
|
| 1618 |
+
],
|
| 1619 |
+
"metadata": {
|
| 1620 |
+
"id": "TlUpXXnPvZRm"
|
| 1621 |
+
},
|
| 1622 |
+
"execution_count": 47,
|
| 1623 |
+
"outputs": []
|
| 1624 |
+
},
|
| 1625 |
+
{
|
| 1626 |
+
"cell_type": "code",
|
| 1627 |
+
"source": [
|
| 1628 |
+
"X_train_processed"
|
| 1629 |
+
],
|
| 1630 |
+
"metadata": {
|
| 1631 |
+
"colab": {
|
| 1632 |
+
"base_uri": "https://localhost:8080/"
|
| 1633 |
+
},
|
| 1634 |
+
"id": "Xe6caWuBwNKh",
|
| 1635 |
+
"outputId": "60dae5f9-e24e-4d38-e578-097a64cb179e"
|
| 1636 |
+
},
|
| 1637 |
+
"execution_count": 48,
|
| 1638 |
+
"outputs": [
|
| 1639 |
+
{
|
| 1640 |
+
"output_type": "execute_result",
|
| 1641 |
+
"data": {
|
| 1642 |
+
"text/plain": [
|
| 1643 |
+
"array([[ 562, 7, 10, ..., 0, 0, 0],\n",
|
| 1644 |
+
" [86373, 934, 431, ..., 0, 0, 0],\n",
|
| 1645 |
+
" [ 305, 312, 25, ..., 0, 0, 0],\n",
|
| 1646 |
+
" ...,\n",
|
| 1647 |
+
" [27845, 6291, 4403, ..., 0, 0, 0],\n",
|
| 1648 |
+
" [ 41, 13, 139, ..., 0, 0, 0],\n",
|
| 1649 |
+
" [ 74, 14, 124, ..., 0, 0, 0]], dtype=int32)"
|
| 1650 |
+
]
|
| 1651 |
+
},
|
| 1652 |
+
"metadata": {},
|
| 1653 |
+
"execution_count": 48
|
| 1654 |
+
}
|
| 1655 |
+
]
|
| 1656 |
+
},
|
| 1657 |
+
{
|
| 1658 |
+
"cell_type": "markdown",
|
| 1659 |
+
"source": [
|
| 1660 |
+
"**SIMPLE NN MODEL**"
|
| 1661 |
+
],
|
| 1662 |
+
"metadata": {
|
| 1663 |
+
"id": "32Qp_ks2wse0"
|
| 1664 |
+
}
|
| 1665 |
+
},
|
| 1666 |
+
{
|
| 1667 |
+
"cell_type": "markdown",
|
| 1668 |
+
"source": [
|
| 1669 |
+
"Test"
|
| 1670 |
+
],
|
| 1671 |
+
"metadata": {
|
| 1672 |
+
"id": "5P0hiAqj-bAM"
|
| 1673 |
+
}
|
| 1674 |
+
},
|
| 1675 |
+
{
|
| 1676 |
+
"cell_type": "code",
|
| 1677 |
+
"source": [
|
| 1678 |
+
"max_features=100000\n",
|
| 1679 |
+
"tokenizer = Tokenizer(num_words=max_features)\n",
|
| 1680 |
+
"tokenizer.fit_on_texts(list(X_train))\n",
|
| 1681 |
+
"list_tokenized_train = tokenizer.texts_to_sequences(X_train)\n"
|
| 1682 |
+
],
|
| 1683 |
+
"metadata": {
|
| 1684 |
+
"id": "qCoNNFx3-aWv"
|
| 1685 |
+
},
|
| 1686 |
+
"execution_count": 53,
|
| 1687 |
+
"outputs": []
|
| 1688 |
+
},
|
| 1689 |
+
{
|
| 1690 |
+
"cell_type": "code",
|
| 1691 |
+
"source": [
|
| 1692 |
+
"maxpadlen = 200\n",
|
| 1693 |
+
"X_t=pad_sequences(list_tokenized_train, maxlen=maxpadlen, padding = 'post')\n"
|
| 1694 |
+
],
|
| 1695 |
+
"metadata": {
|
| 1696 |
+
"id": "_f3D936I-lct"
|
| 1697 |
+
},
|
| 1698 |
+
"execution_count": 54,
|
| 1699 |
+
"outputs": []
|
| 1700 |
+
},
|
| 1701 |
+
{
|
| 1702 |
+
"cell_type": "code",
|
| 1703 |
+
"source": [
|
| 1704 |
+
"X_t"
|
| 1705 |
+
],
|
| 1706 |
+
"metadata": {
|
| 1707 |
+
"colab": {
|
| 1708 |
+
"base_uri": "https://localhost:8080/"
|
| 1709 |
+
},
|
| 1710 |
+
"id": "G0-f0_J8-srQ",
|
| 1711 |
+
"outputId": "4c6f4468-772f-4c74-b1a6-e4d8114be98f"
|
| 1712 |
+
},
|
| 1713 |
+
"execution_count": 55,
|
| 1714 |
+
"outputs": [
|
| 1715 |
+
{
|
| 1716 |
+
"output_type": "execute_result",
|
| 1717 |
+
"data": {
|
| 1718 |
+
"text/plain": [
|
| 1719 |
+
"array([[ 562, 7, 10, ..., 0, 0, 0],\n",
|
| 1720 |
+
" [86373, 934, 431, ..., 0, 0, 0],\n",
|
| 1721 |
+
" [ 305, 312, 25, ..., 0, 0, 0],\n",
|
| 1722 |
+
" ...,\n",
|
| 1723 |
+
" [27845, 6291, 4403, ..., 0, 0, 0],\n",
|
| 1724 |
+
" [ 41, 13, 139, ..., 0, 0, 0],\n",
|
| 1725 |
+
" [ 74, 14, 124, ..., 0, 0, 0]], dtype=int32)"
|
| 1726 |
+
]
|
| 1727 |
+
},
|
| 1728 |
+
"metadata": {},
|
| 1729 |
+
"execution_count": 55
|
| 1730 |
+
}
|
| 1731 |
+
]
|
| 1732 |
+
},
|
| 1733 |
+
{
|
| 1734 |
+
"cell_type": "code",
|
| 1735 |
+
"source": [
|
| 1736 |
+
""
|
| 1737 |
+
],
|
| 1738 |
+
"metadata": {
|
| 1739 |
+
"id": "NhVw8fNyezD3"
|
| 1740 |
+
},
|
| 1741 |
+
"execution_count": null,
|
| 1742 |
+
"outputs": []
|
| 1743 |
+
},
|
| 1744 |
+
{
|
| 1745 |
+
"cell_type": "code",
|
| 1746 |
+
"source": [
|
| 1747 |
+
"\n",
|
| 1748 |
+
"from sklearn.model_selection import train_test_split\n",
|
| 1749 |
+
"# x_train, x_val, y_train, y_val = train_test_split(X_train_processed, Y_train, test_size=0.2)\n",
|
| 1750 |
+
"lstm_model = keras.Sequential([\n",
|
| 1751 |
+
" keras.layers.Embedding(max_features+1,32) , \n",
|
| 1752 |
+
" keras.layers.Bidirectional(keras.layers.LSTM(32, activation='tanh')) , \n",
|
| 1753 |
+
" keras.layers.Dense(128, activation=\"relu\"),\n",
|
| 1754 |
+
" keras.layers.Dense(256, activation=\"relu\"),\n",
|
| 1755 |
+
" keras.layers.Dense(128, activation=\"relu\"),\n",
|
| 1756 |
+
" keras.layers.Dense(6, activation=\"sigmoid\")\n",
|
| 1757 |
+
"])\n",
|
| 1758 |
+
"lstm_model.compile(loss=\"BinaryCrossentropy\", optimizer=\"Adam\", metrics=[\"accuracy\"])\n",
|
| 1759 |
+
"model_history = lstm_model.fit(X_t, Y_train, epochs=1)"
|
| 1760 |
+
],
|
| 1761 |
+
"metadata": {
|
| 1762 |
+
"colab": {
|
| 1763 |
+
"base_uri": "https://localhost:8080/"
|
| 1764 |
+
},
|
| 1765 |
+
"id": "XUa6X8eA-2yS",
|
| 1766 |
+
"outputId": "4c734a3a-2dc1-4c31-954a-fd64c8904bb1"
|
| 1767 |
+
},
|
| 1768 |
+
"execution_count": 56,
|
| 1769 |
+
"outputs": [
|
| 1770 |
+
{
|
| 1771 |
+
"output_type": "stream",
|
| 1772 |
+
"name": "stdout",
|
| 1773 |
+
"text": [
|
| 1774 |
+
"4987/4987 [==============================] - 101s 19ms/step - loss: 0.0619 - accuracy: 0.9897\n"
|
| 1775 |
+
]
|
| 1776 |
+
}
|
| 1777 |
+
]
|
| 1778 |
+
},
|
| 1779 |
+
{
|
| 1780 |
+
"cell_type": "code",
|
| 1781 |
+
"source": [
|
| 1782 |
+
"res = lstm_model.predict(np.expand_dims(X_t[15],axis=0))\n",
|
| 1783 |
+
"\n",
|
| 1784 |
+
"(res > 0.5).astype(int)"
|
| 1785 |
+
],
|
| 1786 |
+
"metadata": {
|
| 1787 |
+
"colab": {
|
| 1788 |
+
"base_uri": "https://localhost:8080/"
|
| 1789 |
+
},
|
| 1790 |
+
"id": "4grayjEH_5Pu",
|
| 1791 |
+
"outputId": "f780c913-97b0-488b-8c44-9544df9b202d"
|
| 1792 |
+
},
|
| 1793 |
+
"execution_count": 145,
|
| 1794 |
+
"outputs": [
|
| 1795 |
+
{
|
| 1796 |
+
"output_type": "execute_result",
|
| 1797 |
+
"data": {
|
| 1798 |
+
"text/plain": [
|
| 1799 |
+
"array([[0, 0, 0, 0, 0, 0]])"
|
| 1800 |
+
]
|
| 1801 |
+
},
|
| 1802 |
+
"metadata": {},
|
| 1803 |
+
"execution_count": 145
|
| 1804 |
+
}
|
| 1805 |
+
]
|
| 1806 |
+
},
|
| 1807 |
+
{
|
| 1808 |
+
"cell_type": "code",
|
| 1809 |
+
"source": [
|
| 1810 |
+
"Y_train.iloc[12]"
|
| 1811 |
+
],
|
| 1812 |
+
"metadata": {
|
| 1813 |
+
"colab": {
|
| 1814 |
+
"base_uri": "https://localhost:8080/"
|
| 1815 |
+
},
|
| 1816 |
+
"id": "iTTVDTG-AGo4",
|
| 1817 |
+
"outputId": "82856c35-7903-45d1-e50a-32c32d8bd5b7"
|
| 1818 |
+
},
|
| 1819 |
+
"execution_count": 142,
|
| 1820 |
+
"outputs": [
|
| 1821 |
+
{
|
| 1822 |
+
"output_type": "execute_result",
|
| 1823 |
+
"data": {
|
| 1824 |
+
"text/plain": [
|
| 1825 |
+
"toxic 1\n",
|
| 1826 |
+
"severe_toxic 0\n",
|
| 1827 |
+
"obscene 0\n",
|
| 1828 |
+
"threat 0\n",
|
| 1829 |
+
"insult 0\n",
|
| 1830 |
+
"identity_hate 0\n",
|
| 1831 |
+
"Name: 12, dtype: int64"
|
| 1832 |
+
]
|
| 1833 |
+
},
|
| 1834 |
+
"metadata": {},
|
| 1835 |
+
"execution_count": 142
|
| 1836 |
+
}
|
| 1837 |
+
]
|
| 1838 |
+
},
|
| 1839 |
+
{
|
| 1840 |
+
"cell_type": "code",
|
| 1841 |
+
"source": [
|
| 1842 |
+
"input_text = 'COCKSUCKER BEFORE YOU PISS AROUND ON MY WORK'"
|
| 1843 |
+
],
|
| 1844 |
+
"metadata": {
|
| 1845 |
+
"id": "R0zjKTuVAX8u"
|
| 1846 |
+
},
|
| 1847 |
+
"execution_count": 160,
|
| 1848 |
+
"outputs": []
|
| 1849 |
+
},
|
| 1850 |
+
{
|
| 1851 |
+
"cell_type": "code",
|
| 1852 |
+
"source": [
|
| 1853 |
+
"def predict_using_simple_model(text):\n",
|
| 1854 |
+
" sentences =[text]\n",
|
| 1855 |
+
" expand_contractions(sentences)\n",
|
| 1856 |
+
" remove_newlines_and_tabs(sentences)\n",
|
| 1857 |
+
" remove_stopwords(sentences)\n",
|
| 1858 |
+
" lemmetization(sentences)\n",
|
| 1859 |
+
" print(sentences)\n",
|
| 1860 |
+
" tokenized_text = tokenizer.texts_to_sequences(sentences)\n",
|
| 1861 |
+
" padded_text = pad_sequences(tokenized_text,maxlen=maxpadlen,padding = 'post')\n",
|
| 1862 |
+
" print(lstm_model.predict(padded_text))\n",
|
| 1863 |
+
" return lstm_model.predict(padded_text)"
|
| 1864 |
+
],
|
| 1865 |
+
"metadata": {
|
| 1866 |
+
"id": "mN_eJSP1AZ-d"
|
| 1867 |
+
},
|
| 1868 |
+
"execution_count": 158,
|
| 1869 |
+
"outputs": []
|
| 1870 |
+
},
|
| 1871 |
+
{
|
| 1872 |
+
"cell_type": "code",
|
| 1873 |
+
"source": [
|
| 1874 |
+
"res = predict_using_simple_model(input_text)\n",
|
| 1875 |
+
"(res > 0.5).astype(int)"
|
| 1876 |
+
],
|
| 1877 |
+
"metadata": {
|
| 1878 |
+
"colab": {
|
| 1879 |
+
"base_uri": "https://localhost:8080/"
|
| 1880 |
+
},
|
| 1881 |
+
"id": "9Mb2krODAadW",
|
| 1882 |
+
"outputId": "3733a10c-e889-4d38-dc22-f77745e55aae"
|
| 1883 |
+
},
|
| 1884 |
+
"execution_count": 159,
|
| 1885 |
+
"outputs": [
|
| 1886 |
+
{
|
| 1887 |
+
"output_type": "stream",
|
| 1888 |
+
"name": "stdout",
|
| 1889 |
+
"text": [
|
| 1890 |
+
"['HATE BLACK']\n",
|
| 1891 |
+
"[[0.8108128 0.04237914 0.459502 0.02853931 0.3863017 0.10296743]]\n"
|
| 1892 |
+
]
|
| 1893 |
+
},
|
| 1894 |
+
{
|
| 1895 |
+
"output_type": "execute_result",
|
| 1896 |
+
"data": {
|
| 1897 |
+
"text/plain": [
|
| 1898 |
+
"array([[1, 0, 0, 0, 0, 0]])"
|
| 1899 |
+
]
|
| 1900 |
+
},
|
| 1901 |
+
"metadata": {},
|
| 1902 |
+
"execution_count": 159
|
| 1903 |
+
}
|
| 1904 |
+
]
|
| 1905 |
+
},
|
| 1906 |
+
{
|
| 1907 |
+
"cell_type": "markdown",
|
| 1908 |
+
"source": [
|
| 1909 |
+
"**Test 2**"
|
| 1910 |
+
],
|
| 1911 |
+
"metadata": {
|
| 1912 |
+
"id": "I0zU8ZbPgHLf"
|
| 1913 |
+
}
|
| 1914 |
+
},
|
| 1915 |
+
{
|
| 1916 |
+
"cell_type": "code",
|
| 1917 |
+
"source": [
|
| 1918 |
+
"from sklearn.model_selection import train_test_split\n",
|
| 1919 |
+
"# x_train, x_val, y_train, y_val = train_test_split(X_train_processed, Y_train, test_size=0.2)\n",
|
| 1920 |
+
"lstm_model_2 = keras.Sequential([\n",
|
| 1921 |
+
" keras.layers.Embedding(max_features+1,32) , \n",
|
| 1922 |
+
" keras.layers.Bidirectional(keras.layers.LSTM(32, activation='tanh')) , \n",
|
| 1923 |
+
" keras.layers.Dense(128, activation=\"relu\"),\n",
|
| 1924 |
+
" keras.layers.Dense(256, activation=\"relu\"),\n",
|
| 1925 |
+
" keras.layers.Dense(128, activation=\"relu\"),\n",
|
| 1926 |
+
" keras.layers.Dense(6, activation=\"sigmoid\")\n",
|
| 1927 |
+
"])\n",
|
| 1928 |
+
"lstm_model_2.compile(loss=\"BinaryCrossentropy\", optimizer=\"Adam\", metrics=[\"accuracy\"])\n",
|
| 1929 |
+
"model_history = lstm_model_2.fit(X_train_processed, Y_train, epochs=1)"
|
| 1930 |
+
],
|
| 1931 |
+
"metadata": {
|
| 1932 |
+
"colab": {
|
| 1933 |
+
"base_uri": "https://localhost:8080/"
|
| 1934 |
+
},
|
| 1935 |
+
"id": "4GTMdGgfgGxm",
|
| 1936 |
+
"outputId": "6b526957-1217-4ca1-d19f-f1744fb4a751"
|
| 1937 |
+
},
|
| 1938 |
+
"execution_count": 59,
|
| 1939 |
+
"outputs": [
|
| 1940 |
+
{
|
| 1941 |
+
"output_type": "stream",
|
| 1942 |
+
"name": "stdout",
|
| 1943 |
+
"text": [
|
| 1944 |
+
"4987/4987 [==============================] - 458s 91ms/step - loss: 0.0589 - accuracy: 0.9895\n"
|
| 1945 |
+
]
|
| 1946 |
+
}
|
| 1947 |
+
]
|
| 1948 |
+
},
|
| 1949 |
+
{
|
| 1950 |
+
"cell_type": "code",
|
| 1951 |
+
"source": [
|
| 1952 |
+
"res = lstm_model_2.predict(np.expand_dims(X_train_processed[6],axis=0))\n",
|
| 1953 |
+
"\n",
|
| 1954 |
+
"(res > 0.5).astype(int)"
|
| 1955 |
+
],
|
| 1956 |
+
"metadata": {
|
| 1957 |
+
"colab": {
|
| 1958 |
+
"base_uri": "https://localhost:8080/"
|
| 1959 |
+
},
|
| 1960 |
+
"id": "UWS_61LOgWwI",
|
| 1961 |
+
"outputId": "4e5a42e4-8904-4ee4-c797-31c56c02a0f8"
|
| 1962 |
+
},
|
| 1963 |
+
"execution_count": 60,
|
| 1964 |
+
"outputs": [
|
| 1965 |
+
{
|
| 1966 |
+
"output_type": "execute_result",
|
| 1967 |
+
"data": {
|
| 1968 |
+
"text/plain": [
|
| 1969 |
+
"array([[1, 0, 1, 0, 1, 0]])"
|
| 1970 |
+
]
|
| 1971 |
+
},
|
| 1972 |
+
"metadata": {},
|
| 1973 |
+
"execution_count": 60
|
| 1974 |
+
}
|
| 1975 |
+
]
|
| 1976 |
+
},
|
| 1977 |
+
{
|
| 1978 |
+
"cell_type": "code",
|
| 1979 |
+
"source": [
|
| 1980 |
+
"text = 'Stupid peace of shit stop deleting my stuff asshole go die and fall in a hole go to hell!'"
|
| 1981 |
+
],
|
| 1982 |
+
"metadata": {
|
| 1983 |
+
"id": "_LYBbAIhnHt6"
|
| 1984 |
+
},
|
| 1985 |
+
"execution_count": 68,
|
| 1986 |
+
"outputs": []
|
| 1987 |
+
},
|
| 1988 |
+
{
|
| 1989 |
+
"cell_type": "code",
|
| 1990 |
+
"source": [
|
| 1991 |
+
"def predict_using_text(text):\n",
|
| 1992 |
+
" sentences = [text]\n",
|
| 1993 |
+
" expand_contractions(sentences)\n",
|
| 1994 |
+
" remove_newlines_and_tabs(sentences)\n",
|
| 1995 |
+
" remove_stopwords(sentences)\n",
|
| 1996 |
+
" lemmetization(sentences)\n",
|
| 1997 |
+
" tokenized = tokenizer.texts_to_sequences(sentences)\n",
|
| 1998 |
+
" padded = pad_sequences(tokenized,maxlen=max_len,padding = 'post')\n",
|
| 1999 |
+
" res = lstm_model_2.predict(padded)\n",
|
| 2000 |
+
" print((res > 0.5).astype(int))"
|
| 2001 |
+
],
|
| 2002 |
+
"metadata": {
|
| 2003 |
+
"id": "10wbT70anQDk"
|
| 2004 |
+
},
|
| 2005 |
+
"execution_count": 72,
|
| 2006 |
+
"outputs": []
|
| 2007 |
+
},
|
| 2008 |
+
{
|
| 2009 |
+
"cell_type": "code",
|
| 2010 |
+
"source": [
|
| 2011 |
+
"predict_using_text(text)"
|
| 2012 |
+
],
|
| 2013 |
+
"metadata": {
|
| 2014 |
+
"colab": {
|
| 2015 |
+
"base_uri": "https://localhost:8080/"
|
| 2016 |
+
},
|
| 2017 |
+
"id": "XmyBnnebocWu",
|
| 2018 |
+
"outputId": "7de8aa84-531d-44a2-986f-c9954a87674b"
|
| 2019 |
+
},
|
| 2020 |
+
"execution_count": 73,
|
| 2021 |
+
"outputs": [
|
| 2022 |
+
{
|
| 2023 |
+
"output_type": "stream",
|
| 2024 |
+
"name": "stdout",
|
| 2025 |
+
"text": [
|
| 2026 |
+
"[[1 0 1 0 1 0]]\n"
|
| 2027 |
+
]
|
| 2028 |
+
}
|
| 2029 |
+
]
|
| 2030 |
+
},
|
| 2031 |
+
{
|
| 2032 |
+
"cell_type": "code",
|
| 2033 |
+
"source": [
|
| 2034 |
+
"lstm_model_2.save('comment_toxicity_model.h5')"
|
| 2035 |
+
],
|
| 2036 |
+
"metadata": {
|
| 2037 |
+
"id": "QTpNX9bIzGsk"
|
| 2038 |
+
},
|
| 2039 |
+
"execution_count": 76,
|
| 2040 |
+
"outputs": []
|
| 2041 |
+
},
|
| 2042 |
+
{
|
| 2043 |
+
"cell_type": "markdown",
|
| 2044 |
+
"source": [
|
| 2045 |
+
"**Gradio**"
|
| 2046 |
+
],
|
| 2047 |
+
"metadata": {
|
| 2048 |
+
"id": "Pe8m1Efby9-y"
|
| 2049 |
+
}
|
| 2050 |
+
},
|
| 2051 |
+
{
|
| 2052 |
+
"cell_type": "code",
|
| 2053 |
+
"source": [
|
| 2054 |
+
"\n",
|
| 2055 |
+
"!pip install gradio jinja2"
|
| 2056 |
+
],
|
| 2057 |
+
"metadata": {
|
| 2058 |
+
"colab": {
|
| 2059 |
+
"base_uri": "https://localhost:8080/"
|
| 2060 |
+
},
|
| 2061 |
+
"id": "QcJ11A7eyzuL",
|
| 2062 |
+
"outputId": "60ef21b2-02fb-4fd2-fe0b-f907d22d3fb5"
|
| 2063 |
+
},
|
| 2064 |
+
"execution_count": 74,
|
| 2065 |
+
"outputs": [
|
| 2066 |
+
{
|
| 2067 |
+
"output_type": "stream",
|
| 2068 |
+
"name": "stdout",
|
| 2069 |
+
"text": [
|
| 2070 |
+
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
|
| 2071 |
+
"Collecting gradio\n",
|
| 2072 |
+
" Downloading gradio-3.0.20-py3-none-any.whl (5.1 MB)\n",
|
| 2073 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 5.1 MB 4.1 MB/s \n",
|
| 2074 |
+
"\u001b[?25hRequirement already satisfied: jinja2 in /usr/local/lib/python3.7/dist-packages (2.11.3)\n",
|
| 2075 |
+
"Collecting analytics-python\n",
|
| 2076 |
+
" Downloading analytics_python-1.4.0-py2.py3-none-any.whl (15 kB)\n",
|
| 2077 |
+
"Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from gradio) (1.3.5)\n",
|
| 2078 |
+
"Collecting paramiko\n",
|
| 2079 |
+
" Downloading paramiko-2.11.0-py2.py3-none-any.whl (212 kB)\n",
|
| 2080 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 212 kB 53.9 MB/s \n",
|
| 2081 |
+
"\u001b[?25hCollecting python-multipart\n",
|
| 2082 |
+
" Downloading python-multipart-0.0.5.tar.gz (32 kB)\n",
|
| 2083 |
+
"Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from gradio) (1.21.6)\n",
|
| 2084 |
+
"Requirement already satisfied: pillow in /usr/local/lib/python3.7/dist-packages (from gradio) (7.1.2)\n",
|
| 2085 |
+
"Collecting fastapi\n",
|
| 2086 |
+
" Downloading fastapi-0.78.0-py3-none-any.whl (54 kB)\n",
|
| 2087 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 54 kB 3.1 MB/s \n",
|
| 2088 |
+
"\u001b[?25hCollecting ffmpy\n",
|
| 2089 |
+
" Downloading ffmpy-0.3.0.tar.gz (4.8 kB)\n",
|
| 2090 |
+
"Collecting aiohttp\n",
|
| 2091 |
+
" Downloading aiohttp-3.8.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.1 MB)\n",
|
| 2092 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 1.1 MB 49.7 MB/s \n",
|
| 2093 |
+
"\u001b[?25hRequirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from gradio) (2.23.0)\n",
|
| 2094 |
+
"Collecting uvicorn\n",
|
| 2095 |
+
" Downloading uvicorn-0.18.1-py3-none-any.whl (57 kB)\n",
|
| 2096 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 57 kB 2.7 MB/s \n",
|
| 2097 |
+
"\u001b[?25hCollecting fsspec\n",
|
| 2098 |
+
" Downloading fsspec-2022.5.0-py3-none-any.whl (140 kB)\n",
|
| 2099 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 140 kB 30.4 MB/s \n",
|
| 2100 |
+
"\u001b[?25hCollecting pydub\n",
|
| 2101 |
+
" Downloading pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n",
|
| 2102 |
+
"Collecting pycryptodome\n",
|
| 2103 |
+
" Downloading pycryptodome-3.15.0-cp35-abi3-manylinux2010_x86_64.whl (2.3 MB)\n",
|
| 2104 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 2.3 MB 35.0 MB/s \n",
|
| 2105 |
+
"\u001b[?25hRequirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from gradio) (3.2.2)\n",
|
| 2106 |
+
"Collecting markdown-it-py[linkify,plugins]\n",
|
| 2107 |
+
" Downloading markdown_it_py-2.1.0-py3-none-any.whl (84 kB)\n",
|
| 2108 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 84 kB 2.8 MB/s \n",
|
| 2109 |
+
"\u001b[?25hCollecting orjson\n",
|
| 2110 |
+
" Downloading orjson-3.7.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (256 kB)\n",
|
| 2111 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 256 kB 42.8 MB/s \n",
|
| 2112 |
+
"\u001b[?25hRequirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.7/dist-packages (from jinja2) (2.0.1)\n",
|
| 2113 |
+
"Collecting asynctest==0.13.0\n",
|
| 2114 |
+
" Downloading asynctest-0.13.0-py3-none-any.whl (26 kB)\n",
|
| 2115 |
+
"Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.7/dist-packages (from aiohttp->gradio) (21.4.0)\n",
|
| 2116 |
+
"Requirement already satisfied: charset-normalizer<3.0,>=2.0 in /usr/local/lib/python3.7/dist-packages (from aiohttp->gradio) (2.0.12)\n",
|
| 2117 |
+
"Collecting aiosignal>=1.1.2\n",
|
| 2118 |
+
" Downloading aiosignal-1.2.0-py3-none-any.whl (8.2 kB)\n",
|
| 2119 |
+
"Collecting async-timeout<5.0,>=4.0.0a3\n",
|
| 2120 |
+
" Downloading async_timeout-4.0.2-py3-none-any.whl (5.8 kB)\n",
|
| 2121 |
+
"Requirement already satisfied: typing-extensions>=3.7.4 in /usr/local/lib/python3.7/dist-packages (from aiohttp->gradio) (4.1.1)\n",
|
| 2122 |
+
"Collecting multidict<7.0,>=4.5\n",
|
| 2123 |
+
" Downloading multidict-6.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (94 kB)\n",
|
| 2124 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 94 kB 3.0 MB/s \n",
|
| 2125 |
+
"\u001b[?25hCollecting yarl<2.0,>=1.0\n",
|
| 2126 |
+
" Downloading yarl-1.7.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (271 kB)\n",
|
| 2127 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 271 kB 39.8 MB/s \n",
|
| 2128 |
+
"\u001b[?25hCollecting frozenlist>=1.1.1\n",
|
| 2129 |
+
" Downloading frozenlist-1.3.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (144 kB)\n",
|
| 2130 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 144 kB 42.3 MB/s \n",
|
| 2131 |
+
"\u001b[?25hRequirement already satisfied: idna>=2.0 in /usr/local/lib/python3.7/dist-packages (from yarl<2.0,>=1.0->aiohttp->gradio) (2.10)\n",
|
| 2132 |
+
"Requirement already satisfied: python-dateutil>2.1 in /usr/local/lib/python3.7/dist-packages (from analytics-python->gradio) (2.8.2)\n",
|
| 2133 |
+
"Collecting backoff==1.10.0\n",
|
| 2134 |
+
" Downloading backoff-1.10.0-py2.py3-none-any.whl (31 kB)\n",
|
| 2135 |
+
"Collecting monotonic>=1.5\n",
|
| 2136 |
+
" Downloading monotonic-1.6-py2.py3-none-any.whl (8.2 kB)\n",
|
| 2137 |
+
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from analytics-python->gradio) (1.15.0)\n",
|
| 2138 |
+
"Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->gradio) (1.24.3)\n",
|
| 2139 |
+
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->gradio) (2022.6.15)\n",
|
| 2140 |
+
"Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->gradio) (3.0.4)\n",
|
| 2141 |
+
"Requirement already satisfied: pydantic!=1.7,!=1.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,<2.0.0,>=1.6.2 in /usr/local/lib/python3.7/dist-packages (from fastapi->gradio) (1.8.2)\n",
|
| 2142 |
+
"Collecting starlette==0.19.1\n",
|
| 2143 |
+
" Downloading starlette-0.19.1-py3-none-any.whl (63 kB)\n",
|
| 2144 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 63 kB 1.8 MB/s \n",
|
| 2145 |
+
"\u001b[?25hCollecting anyio<5,>=3.4.0\n",
|
| 2146 |
+
" Downloading anyio-3.6.1-py3-none-any.whl (80 kB)\n",
|
| 2147 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 80 kB 9.2 MB/s \n",
|
| 2148 |
+
"\u001b[?25hCollecting sniffio>=1.1\n",
|
| 2149 |
+
" Downloading sniffio-1.2.0-py3-none-any.whl (10 kB)\n",
|
| 2150 |
+
"Collecting mdurl~=0.1\n",
|
| 2151 |
+
" Downloading mdurl-0.1.1-py3-none-any.whl (10 kB)\n",
|
| 2152 |
+
"Collecting mdit-py-plugins\n",
|
| 2153 |
+
" Downloading mdit_py_plugins-0.3.0-py3-none-any.whl (43 kB)\n",
|
| 2154 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 43 kB 2.1 MB/s \n",
|
| 2155 |
+
"\u001b[?25hCollecting linkify-it-py~=1.0\n",
|
| 2156 |
+
" Downloading linkify_it_py-1.0.3-py3-none-any.whl (19 kB)\n",
|
| 2157 |
+
"Collecting uc-micro-py\n",
|
| 2158 |
+
" Downloading uc_micro_py-1.0.1-py3-none-any.whl (6.2 kB)\n",
|
| 2159 |
+
"Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->gradio) (3.0.9)\n",
|
| 2160 |
+
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->gradio) (1.4.3)\n",
|
| 2161 |
+
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->gradio) (0.11.0)\n",
|
| 2162 |
+
"Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas->gradio) (2022.1)\n",
|
| 2163 |
+
"Collecting cryptography>=2.5\n",
|
| 2164 |
+
" Downloading cryptography-37.0.2-cp36-abi3-manylinux_2_24_x86_64.whl (4.0 MB)\n",
|
| 2165 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 4.0 MB 24.4 MB/s \n",
|
| 2166 |
+
"\u001b[?25hCollecting bcrypt>=3.1.3\n",
|
| 2167 |
+
" Downloading bcrypt-3.2.2-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (62 kB)\n",
|
| 2168 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 62 kB 732 kB/s \n",
|
| 2169 |
+
"\u001b[?25hCollecting pynacl>=1.0.1\n",
|
| 2170 |
+
" Downloading PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (856 kB)\n",
|
| 2171 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 856 kB 36.7 MB/s \n",
|
| 2172 |
+
"\u001b[?25hRequirement already satisfied: cffi>=1.1 in /usr/local/lib/python3.7/dist-packages (from bcrypt>=3.1.3->paramiko->gradio) (1.15.0)\n",
|
| 2173 |
+
"Requirement already satisfied: pycparser in /usr/local/lib/python3.7/dist-packages (from cffi>=1.1->bcrypt>=3.1.3->paramiko->gradio) (2.21)\n",
|
| 2174 |
+
"Collecting h11>=0.8\n",
|
| 2175 |
+
" Downloading h11-0.13.0-py3-none-any.whl (58 kB)\n",
|
| 2176 |
+
"\u001b[K |ββββββββββββββββββββββββββββββββ| 58 kB 4.6 MB/s \n",
|
| 2177 |
+
"\u001b[?25hRequirement already satisfied: click>=7.0 in /usr/local/lib/python3.7/dist-packages (from uvicorn->gradio) (7.1.2)\n",
|
| 2178 |
+
"Building wheels for collected packages: ffmpy, python-multipart\n",
|
| 2179 |
+
" Building wheel for ffmpy (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
|
| 2180 |
+
" Created wheel for ffmpy: filename=ffmpy-0.3.0-py3-none-any.whl size=4712 sha256=c83267f00c3d705a61d99547a2b2b531230130bc5c0710fa4e5c5aec60fd9053\n",
|
| 2181 |
+
" Stored in directory: /root/.cache/pip/wheels/13/e4/6c/e8059816e86796a597c6e6b0d4c880630f51a1fcfa0befd5e6\n",
|
| 2182 |
+
" Building wheel for python-multipart (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
|
| 2183 |
+
" Created wheel for python-multipart: filename=python_multipart-0.0.5-py3-none-any.whl size=31678 sha256=9402f9afbc2e02540246432e83f77f34bbec24d28b37a1bfe8b85b740b5e843b\n",
|
| 2184 |
+
" Stored in directory: /root/.cache/pip/wheels/2c/41/7c/bfd1c180534ffdcc0972f78c5758f89881602175d48a8bcd2c\n",
|
| 2185 |
+
"Successfully built ffmpy python-multipart\n",
|
| 2186 |
+
"Installing collected packages: sniffio, mdurl, uc-micro-py, multidict, markdown-it-py, frozenlist, anyio, yarl, starlette, pynacl, monotonic, mdit-py-plugins, linkify-it-py, h11, cryptography, bcrypt, backoff, asynctest, async-timeout, aiosignal, uvicorn, python-multipart, pydub, pycryptodome, paramiko, orjson, fsspec, ffmpy, fastapi, analytics-python, aiohttp, gradio\n",
|
| 2187 |
+
"Successfully installed aiohttp-3.8.1 aiosignal-1.2.0 analytics-python-1.4.0 anyio-3.6.1 async-timeout-4.0.2 asynctest-0.13.0 backoff-1.10.0 bcrypt-3.2.2 cryptography-37.0.2 fastapi-0.78.0 ffmpy-0.3.0 frozenlist-1.3.0 fsspec-2022.5.0 gradio-3.0.20 h11-0.13.0 linkify-it-py-1.0.3 markdown-it-py-2.1.0 mdit-py-plugins-0.3.0 mdurl-0.1.1 monotonic-1.6 multidict-6.0.2 orjson-3.7.3 paramiko-2.11.0 pycryptodome-3.15.0 pydub-0.25.1 pynacl-1.5.0 python-multipart-0.0.5 sniffio-1.2.0 starlette-0.19.1 uc-micro-py-1.0.1 uvicorn-0.18.1 yarl-1.7.2\n"
|
| 2188 |
+
]
|
| 2189 |
+
}
|
| 2190 |
+
]
|
| 2191 |
+
},
|
| 2192 |
+
{
|
| 2193 |
+
"cell_type": "code",
|
| 2194 |
+
"source": [
|
| 2195 |
+
"import tensorflow as tf\n",
|
| 2196 |
+
"import gradio as gr"
|
| 2197 |
+
],
|
| 2198 |
+
"metadata": {
|
| 2199 |
+
"id": "SioQk70yzCmg"
|
| 2200 |
+
},
|
| 2201 |
+
"execution_count": 75,
|
| 2202 |
+
"outputs": []
|
| 2203 |
+
},
|
| 2204 |
+
{
|
| 2205 |
+
"cell_type": "code",
|
| 2206 |
+
"source": [
|
| 2207 |
+
"def score_comment(comment):\n",
|
| 2208 |
+
" sentences = [comment]\n",
|
| 2209 |
+
" expand_contractions(sentences)\n",
|
| 2210 |
+
" remove_newlines_and_tabs(sentences)\n",
|
| 2211 |
+
" remove_stopwords(sentences)\n",
|
| 2212 |
+
" lemmetization(sentences)\n",
|
| 2213 |
+
" tokenized = tokenizer.texts_to_sequences(sentences)\n",
|
| 2214 |
+
" padded = pad_sequences(tokenized,maxlen=max_len,padding = 'post')\n",
|
| 2215 |
+
" results = lstm_model_2.predict(padded)\n",
|
| 2216 |
+
" \n",
|
| 2217 |
+
" text = ''\n",
|
| 2218 |
+
" for idx, col in enumerate(train.columns[2:]):\n",
|
| 2219 |
+
" text += '{}: {}\\n'.format(col, results[0][idx]>0.5)\n",
|
| 2220 |
+
" print(text)\n",
|
| 2221 |
+
" return text"
|
| 2222 |
+
],
|
| 2223 |
+
"metadata": {
|
| 2224 |
+
"id": "8NXDXUiOzE8P"
|
| 2225 |
+
},
|
| 2226 |
+
"execution_count": 81,
|
| 2227 |
+
"outputs": []
|
| 2228 |
+
},
|
| 2229 |
+
{
|
| 2230 |
+
"cell_type": "code",
|
| 2231 |
+
"source": [
|
| 2232 |
+
"score_comment(text)"
|
| 2233 |
+
],
|
| 2234 |
+
"metadata": {
|
| 2235 |
+
"colab": {
|
| 2236 |
+
"base_uri": "https://localhost:8080/",
|
| 2237 |
+
"height": 174
|
| 2238 |
+
},
|
| 2239 |
+
"id": "JMNVJ0AqzoaL",
|
| 2240 |
+
"outputId": "c3150373-d8f1-44d6-a84c-59aa9a4fa76e"
|
| 2241 |
+
},
|
| 2242 |
+
"execution_count": 82,
|
| 2243 |
+
"outputs": [
|
| 2244 |
+
{
|
| 2245 |
+
"output_type": "stream",
|
| 2246 |
+
"name": "stdout",
|
| 2247 |
+
"text": [
|
| 2248 |
+
"toxic: True\n",
|
| 2249 |
+
"severe_toxic: False\n",
|
| 2250 |
+
"obscene: True\n",
|
| 2251 |
+
"threat: False\n",
|
| 2252 |
+
"insult: True\n",
|
| 2253 |
+
"identity_hate: False\n",
|
| 2254 |
+
"\n"
|
| 2255 |
+
]
|
| 2256 |
+
},
|
| 2257 |
+
{
|
| 2258 |
+
"output_type": "execute_result",
|
| 2259 |
+
"data": {
|
| 2260 |
+
"text/plain": [
|
| 2261 |
+
"'toxic: True\\nsevere_toxic: False\\nobscene: True\\nthreat: False\\ninsult: True\\nidentity_hate: False\\n'"
|
| 2262 |
+
],
|
| 2263 |
+
"application/vnd.google.colaboratory.intrinsic+json": {
|
| 2264 |
+
"type": "string"
|
| 2265 |
+
}
|
| 2266 |
+
},
|
| 2267 |
+
"metadata": {},
|
| 2268 |
+
"execution_count": 82
|
| 2269 |
+
}
|
| 2270 |
+
]
|
| 2271 |
+
},
|
| 2272 |
+
{
|
| 2273 |
+
"cell_type": "code",
|
| 2274 |
+
"source": [
|
| 2275 |
+
"interface = gr.Interface(fn=score_comment, \n",
|
| 2276 |
+
" inputs=gr.inputs.Textbox(lines=2, placeholder='Comment to score'),\n",
|
| 2277 |
+
" outputs='text')"
|
| 2278 |
+
],
|
| 2279 |
+
"metadata": {
|
| 2280 |
+
"colab": {
|
| 2281 |
+
"base_uri": "https://localhost:8080/"
|
| 2282 |
+
},
|
| 2283 |
+
"id": "vxOtY1hAz6Pa",
|
| 2284 |
+
"outputId": "6b6c7060-fc54-4c22-eb4f-a8b57ffb377f"
|
| 2285 |
+
},
|
| 2286 |
+
"execution_count": 83,
|
| 2287 |
+
"outputs": [
|
| 2288 |
+
{
|
| 2289 |
+
"output_type": "stream",
|
| 2290 |
+
"name": "stderr",
|
| 2291 |
+
"text": [
|
| 2292 |
+
"/usr/local/lib/python3.7/dist-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
|
| 2293 |
+
" warnings.warn(value)\n",
|
| 2294 |
+
"/usr/local/lib/python3.7/dist-packages/gradio/deprecation.py:40: UserWarning: `numeric` parameter is deprecated, and it has no effect\n",
|
| 2295 |
+
" warnings.warn(value)\n",
|
| 2296 |
+
"/usr/local/lib/python3.7/dist-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
|
| 2297 |
+
" warnings.warn(value)\n"
|
| 2298 |
+
]
|
| 2299 |
+
}
|
| 2300 |
+
]
|
| 2301 |
+
},
|
| 2302 |
+
{
|
| 2303 |
+
"cell_type": "code",
|
| 2304 |
+
"source": [
|
| 2305 |
+
"interface.launch(share=True)"
|
| 2306 |
+
],
|
| 2307 |
+
"metadata": {
|
| 2308 |
+
"colab": {
|
| 2309 |
+
"base_uri": "https://localhost:8080/",
|
| 2310 |
+
"height": 663
|
| 2311 |
+
},
|
| 2312 |
+
"id": "vxx6NnCUz_O-",
|
| 2313 |
+
"outputId": "aa6057b4-7dbd-457a-a296-f648d5b83926"
|
| 2314 |
+
},
|
| 2315 |
+
"execution_count": 84,
|
| 2316 |
+
"outputs": [
|
| 2317 |
+
{
|
| 2318 |
+
"output_type": "stream",
|
| 2319 |
+
"name": "stdout",
|
| 2320 |
+
"text": [
|
| 2321 |
+
"Colab notebook detected. To show errors in colab notebook, set `debug=True` in `launch()`\n",
|
| 2322 |
+
"Running on public URL: https://53293.gradio.app\n",
|
| 2323 |
+
"\n",
|
| 2324 |
+
"This share link expires in 72 hours. For free permanent hosting, check out Spaces (https://huggingface.co/spaces)\n"
|
| 2325 |
+
]
|
| 2326 |
+
},
|
| 2327 |
+
{
|
| 2328 |
+
"output_type": "display_data",
|
| 2329 |
+
"data": {
|
| 2330 |
+
"text/plain": [
|
| 2331 |
+
"<IPython.core.display.HTML object>"
|
| 2332 |
+
],
|
| 2333 |
+
"text/html": [
|
| 2334 |
+
"<div><iframe src=\"https://53293.gradio.app\" width=\"900\" height=\"500\" allow=\"autoplay; camera; microphone;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 2335 |
+
]
|
| 2336 |
+
},
|
| 2337 |
+
"metadata": {}
|
| 2338 |
+
},
|
| 2339 |
+
{
|
| 2340 |
+
"output_type": "execute_result",
|
| 2341 |
+
"data": {
|
| 2342 |
+
"text/plain": [
|
| 2343 |
+
"(<gradio.routes.App at 0x7fe3a02b58d0>,\n",
|
| 2344 |
+
" 'http://127.0.0.1:7860/',\n",
|
| 2345 |
+
" 'https://53293.gradio.app')"
|
| 2346 |
+
]
|
| 2347 |
+
},
|
| 2348 |
+
"metadata": {},
|
| 2349 |
+
"execution_count": 84
|
| 2350 |
+
}
|
| 2351 |
+
]
|
| 2352 |
+
}
|
| 2353 |
+
]
|
| 2354 |
+
}
|