{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"2022-01-06-sarcasm-tf.ipynb","provenance":[{"file_id":"https://github.com/recohut/nbs/blob/main/raw/DAF0AC92369C4F74A4AAA2AE089DFDB2.ipynb","timestamp":1644441239012}],"collapsed_sections":[],"toc_visible":true,"mount_file_id":"1JNj0t5pB0ZrfzkQziWwNsgsSNvdlk5q2","authorship_tag":"ABX9TyOZveElLkATPIa8VbAr4Z4n"},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"markdown","source":["# Sarcasm Detection in Tensorflow"],"metadata":{"id":"HBF2okXCVjmw"}},{"cell_type":"code","metadata":{"id":"kuk7dT6r_vWc"},"source":["path = '/content/drive/My Drive/Playground/DAF0AC92369C4F74A4AAA2AE089DFDB2'"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"q3o9tg-NAZSU"},"source":["!unzip '/content/drive/My Drive/Playground/DAF0AC92369C4F74A4AAA2AE089DFDB2/Sarcasm_Headlines_Dataset_v2.zip'"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"N47CVoQTAgdg"},"source":["import os\n","import re\n","import math\n","import numpy as np\n","import pandas as pd\n","from tqdm import tqdm\n","import seaborn as sns\n","import matplotlib.pyplot as plt\n","\n","import nltk\n","nltk.download('stopwords')\n","nltk.download('wordnet')\n","from nltk.corpus import stopwords\n","from nltk.stem.porter import PorterStemmer \n","from nltk.stem.snowball import SnowballStemmer\n","from nltk.stem.wordnet import WordNetLemmatizer\n","\n","from gensim.models import KeyedVectors\n","\n","import warnings\n","warnings.filterwarnings(\"ignore\")\n","\n","tqdm.pandas()\n","%reload_ext autoreload\n","%autoreload 2\n","%reload_ext google.colab.data_table\n","%config InlineBackend.figure_format = 'retina'\n","\n","plt.style.use('fivethirtyeight')\n","plt.style.use('seaborn-notebook')"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"bcCadMJZYp24"},"source":["import tensorflow as tf\n","import tensorflow.keras as keras \n","from keras.models import Sequential, Model \n","from keras import layers\n","from keras.layers import Dense, Dropout, Conv1D, GlobalMaxPooling1D"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"MHXMcep9BN8D","colab":{"base_uri":"https://localhost:8080/","height":274},"executionInfo":{"status":"ok","timestamp":1596285517595,"user_tz":-330,"elapsed":1036,"user":{"displayName":"Sparsh Agarwal","photoUrl":"","userId":"13037694610922482904"}},"outputId":"52791d7c-e721-4e69-b3e2-00b5ccb580d0"},"source":["def parse_data(file):\n"," for l in open(file,'r'):\n"," yield json.loads(l)\n","\n","data = list(parse_data('Sarcasm_Headlines_Dataset_v2.json'))\n","df = pd.DataFrame(data)\n","df.head()"],"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"application/vnd.google.colaboratory.module+javascript":"\n import \"https://ssl.gstatic.com/colaboratory/data_table/a6224c040fa35dcf/data_table.js\";\n\n window.createDataTable({\n data: [[{\n 'v': 0,\n 'f': \"0\",\n },\n{\n 'v': 1,\n 'f': \"1\",\n },\n\"thirtysomething scientists unveil doomsday clock of hair loss\",\n\"https://www.theonion.com/thirtysomething-scientists-unveil-doomsday-clock-of-hai-1819586205\"],\n [{\n 'v': 1,\n 'f': \"1\",\n },\n{\n 'v': 0,\n 'f': \"0\",\n },\n\"dem rep. totally nails why congress is falling short on gender, racial equality\",\n\"https://www.huffingtonpost.com/entry/donna-edwards-inequality_us_57455f7fe4b055bb1170b207\"],\n [{\n 'v': 2,\n 'f': \"2\",\n },\n{\n 'v': 0,\n 'f': \"0\",\n },\n\"eat your veggies: 9 deliciously different recipes\",\n\"https://www.huffingtonpost.com/entry/eat-your-veggies-9-delici_b_8899742.html\"],\n [{\n 'v': 3,\n 'f': \"3\",\n },\n{\n 'v': 1,\n 'f': \"1\",\n },\n\"inclement weather prevents liar from getting to work\",\n\"https://local.theonion.com/inclement-weather-prevents-liar-from-getting-to-work-1819576031\"],\n [{\n 'v': 4,\n 'f': \"4\",\n },\n{\n 'v': 1,\n 'f': \"1\",\n },\n\"mother comes pretty close to using word 'streaming' correctly\",\n\"https://www.theonion.com/mother-comes-pretty-close-to-using-word-streaming-cor-1819575546\"]],\n columns: [[\"number\", \"index\"], [\"number\", \"is_sarcastic\"], [\"string\", \"headline\"], [\"string\", \"article_link\"]],\n columnOptions: [{\"width\": \"1px\", \"className\": \"index_column\"}],\n rowsPerPage: 25,\n helpUrl: \"https://colab.research.google.com/notebooks/data_table.ipynb\",\n suppressOutputScrolling: true,\n minimumWidth: undefined,\n });\n ","text/html":["
\n"," | is_sarcastic | \n","headline | \n","article_link | \n","
---|---|---|---|
0 | \n","1 | \n","thirtysomething scientists unveil doomsday clo... | \n","https://www.theonion.com/thirtysomething-scien... | \n","
1 | \n","0 | \n","dem rep. totally nails why congress is falling... | \n","https://www.huffingtonpost.com/entry/donna-edw... | \n","
2 | \n","0 | \n","eat your veggies: 9 deliciously different recipes | \n","https://www.huffingtonpost.com/entry/eat-your-... | \n","
3 | \n","1 | \n","inclement weather prevents liar from getting t... | \n","https://local.theonion.com/inclement-weather-p... | \n","
4 | \n","1 | \n","mother comes pretty close to using word 'strea... | \n","https://www.theonion.com/mother-comes-pretty-c... | \n","