Skip to content

Instantly share code, notes, and snippets.

@robhawkins
Created November 26, 2017 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robhawkins/53127e0e1dbaf334b5a08667979052c3 to your computer and use it in GitHub Desktop.
Save robhawkins/53127e0e1dbaf334b5a08667979052c3 to your computer and use it in GitHub Desktop.
Happiness predictions out of order
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window.Plotly) {{require(['plotly'],function(plotly) {window.Plotly=plotly;});}}</script>"
],
"text/vnd.plotly.v1+html": [
"<script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window.Plotly) {{require(['plotly'],function(plotly) {window.Plotly=plotly;});}}</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Put these at the top of every notebook, to get automatic reloading and inline plotting\n",
"%reload_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline\n",
"\n",
"import os\n",
"os.environ['CUDA_VISIBLE_DEVICES'] = \"1\"\n",
"\n",
"from fastai.learner import *\n",
"\n",
"import torchtext\n",
"from torchtext import vocab, data\n",
"from torchtext.datasets import language_modeling\n",
"\n",
"from fastai.rnn_reg import *\n",
"from fastai.rnn_train import *\n",
"from fastai.nlp import *\n",
"from fastai.lm_rnn import *\n",
"\n",
"import dill as pickle\n",
"import pandas as pd\n",
"\n",
"import plotly.graph_objs as go\n",
"import plotly.offline as py\n",
"py.init_notebook_mode(connected=True)\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"## TODO: Make small df for language model validation & test"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"PATH='data/happiness/'\n",
"TRN_FILE = f'{PATH}/train.csv'\n",
"TST_FILE = f'{PATH}/train.csv'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"train_df = pd.read_csv(TRN_FILE)\n",
"train_df.Is_Response.replace(['not happy'], ['not_happy'], inplace=True)\n",
"\n",
"test_df = pd.read_csv(TST_FILE)\n",
"\n",
"msk = np.random.rand(len(train_df)) < 0.9\n",
"val_df = train_df[~msk].reset_index()\n",
"train_df = train_df[msk].reset_index()\n",
"tiny_df = train_df[0:1].reset_index()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"bs=55; bptt=70\n",
"em_sz = 200 # size of each embedding vector\n",
"nh = 500 # number of hidden activations per layer\n",
"nl = 3 # number of layers\n",
"\n",
"opt_fn = partial(optim.Adam, betas=(0.7, 0.99))\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": true
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>User_ID</th>\n",
" <th>Description</th>\n",
" <th>Browser_Used</th>\n",
" <th>Device_Used</th>\n",
" <th>Is_Response</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>id10326</td>\n",
" <td>The room was kind of clean but had a VERY stro...</td>\n",
" <td>Edge</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>id10327</td>\n",
" <td>I stayed at the Crown Plaza April -- - April -...</td>\n",
" <td>Internet Explorer</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>id10328</td>\n",
" <td>I booked this hotel through Hotwire at the low...</td>\n",
" <td>Mozilla</td>\n",
" <td>Tablet</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>id10329</td>\n",
" <td>Stayed here with husband and sons on the way t...</td>\n",
" <td>InternetExplorer</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>id10330</td>\n",
" <td>My girlfriends and I stayed here to celebrate ...</td>\n",
" <td>Edge</td>\n",
" <td>Tablet</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>id10331</td>\n",
" <td>We had - rooms. One was very nice and clearly ...</td>\n",
" <td>InternetExplorer</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>id10332</td>\n",
" <td>My husband and I have stayed in this hotel a f...</td>\n",
" <td>Firefox</td>\n",
" <td>Tablet</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>id10333</td>\n",
" <td>My wife &amp; I stayed in this glorious city a whi...</td>\n",
" <td>Google Chrome</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>id10334</td>\n",
" <td>My boyfriend and I stayed at the Fairmont on a...</td>\n",
" <td>Internet Explorer</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>id10335</td>\n",
" <td>Wonderful staff, great location, but it was de...</td>\n",
" <td>Chrome</td>\n",
" <td>Tablet</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>id10336</td>\n",
" <td>Steps off Times Square, nice rooms, stayed - n...</td>\n",
" <td>Internet Explorer</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>id10337</td>\n",
" <td>Me, the Wife and - kids stayed here on Valenti...</td>\n",
" <td>IE</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>id10338</td>\n",
" <td>We stay at the Jolly Madison over the Xmas per...</td>\n",
" <td>Edge</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>id10339</td>\n",
" <td>I highly recommend the Hawthorne Terrace as an...</td>\n",
" <td>Internet Explorer</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>id10340</td>\n",
" <td>I found the hotel clean and nicely located. Go...</td>\n",
" <td>Chrome</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>id10341</td>\n",
" <td>Stayed at the Elan from --th to --th October a...</td>\n",
" <td>Mozilla</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>id10342</td>\n",
" <td>Priceline sent us to this hotel after acceptin...</td>\n",
" <td>Mozilla</td>\n",
" <td>Tablet</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>id10343</td>\n",
" <td>Old and cheap furnitures,our chair was simply ...</td>\n",
" <td>Google Chrome</td>\n",
" <td>Desktop</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>id10344</td>\n",
" <td>We stayed here for - nights and were really ha...</td>\n",
" <td>Google Chrome</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>id10345</td>\n",
" <td>The service was fine, but the hotel itself fel...</td>\n",
" <td>Mozilla</td>\n",
" <td>Desktop</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>id10346</td>\n",
" <td>Having stayed at many Hilton properties, I exp...</td>\n",
" <td>Firefox</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>id10347</td>\n",
" <td>This is everything you could want from a hotel...</td>\n",
" <td>Firefox</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>id10348</td>\n",
" <td>I very much wanted to stay at a boutique hotel...</td>\n",
" <td>Edge</td>\n",
" <td>Tablet</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>id10349</td>\n",
" <td>I really liked this hotel. The staff were wond...</td>\n",
" <td>Chrome</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>id10350</td>\n",
" <td>My wife and spent - days there this month as a...</td>\n",
" <td>Chrome</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>id10351</td>\n",
" <td>We stayed at this hotel for two nights over th...</td>\n",
" <td>Opera</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>id10352</td>\n",
" <td>Took a girls trip to LA and had no idea where ...</td>\n",
" <td>InternetExplorer</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>id10353</td>\n",
" <td>Stayed with my girlfriend for a long weekend. ...</td>\n",
" <td>Mozilla Firefox</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>id10354</td>\n",
" <td>I have stayed here numerous times and never be...</td>\n",
" <td>Mozilla</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>id10355</td>\n",
" <td>The public areas are nice to look at. The staf...</td>\n",
" <td>Firefox</td>\n",
" <td>Tablet</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38902</th>\n",
" <td>id49228</td>\n",
" <td>After having stayed at the Waldorf many times,...</td>\n",
" <td>InternetExplorer</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38903</th>\n",
" <td>id49229</td>\n",
" <td>This hotel is a great choice for those staying...</td>\n",
" <td>Mozilla</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38904</th>\n",
" <td>id49230</td>\n",
" <td>Although New York is a large city, whenever I ...</td>\n",
" <td>Google Chrome</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38905</th>\n",
" <td>id49231</td>\n",
" <td>I used to live in Austin, so when I moved away...</td>\n",
" <td>IE</td>\n",
" <td>Desktop</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38906</th>\n",
" <td>id49232</td>\n",
" <td>I've stayed at the Hilton, Hyatt, Magnolia and...</td>\n",
" <td>InternetExplorer</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38907</th>\n",
" <td>id49233</td>\n",
" <td>Great Location,short walk from Amtrak station,...</td>\n",
" <td>Firefox</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38908</th>\n",
" <td>id49234</td>\n",
" <td>When we booked this was a Renaissance Hotel bu...</td>\n",
" <td>Mozilla</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38909</th>\n",
" <td>id49235</td>\n",
" <td>Hotel is an old style Red Roof and has not bee...</td>\n",
" <td>Mozilla</td>\n",
" <td>Desktop</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38910</th>\n",
" <td>id49236</td>\n",
" <td>I have to admit I tried rebooking since I was ...</td>\n",
" <td>Chrome</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38911</th>\n",
" <td>id49237</td>\n",
" <td>Room was nice, everything seemed pretty new. R...</td>\n",
" <td>Internet Explorer</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38912</th>\n",
" <td>id49238</td>\n",
" <td>then a great place to stay is this hotel. Not ...</td>\n",
" <td>Mozilla Firefox</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38913</th>\n",
" <td>id49239</td>\n",
" <td>I will never ever stay at this Hotel again. I ...</td>\n",
" <td>Firefox</td>\n",
" <td>Desktop</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38914</th>\n",
" <td>id49240</td>\n",
" <td>After being on a bus for -- hours and finally ...</td>\n",
" <td>Mozilla</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38915</th>\n",
" <td>id49241</td>\n",
" <td>pretty cool hotel. stayed for a few days in mi...</td>\n",
" <td>InternetExplorer</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38916</th>\n",
" <td>id49242</td>\n",
" <td>We stopped over in LAX on the way to Canada an...</td>\n",
" <td>Google Chrome</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38917</th>\n",
" <td>id49243</td>\n",
" <td>I love this hotel and will stay again for seve...</td>\n",
" <td>Chrome</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38918</th>\n",
" <td>id49244</td>\n",
" <td>We were excited about our stay at the Blu Aqua...</td>\n",
" <td>Edge</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38919</th>\n",
" <td>id49245</td>\n",
" <td>I didn't get to see much of Seattle but the ho...</td>\n",
" <td>Internet Explorer</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38920</th>\n",
" <td>id49246</td>\n",
" <td>My husband and I stayed one night at the Heart...</td>\n",
" <td>InternetExplorer</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38921</th>\n",
" <td>id49247</td>\n",
" <td>We staed at the Handlery Hotel to Visit San Di...</td>\n",
" <td>Edge</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38922</th>\n",
" <td>id49248</td>\n",
" <td>This hotel has a great location if you want to...</td>\n",
" <td>Edge</td>\n",
" <td>Desktop</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38923</th>\n",
" <td>id49249</td>\n",
" <td>I am pretty impartial to this hotel. I would d...</td>\n",
" <td>Edge</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38924</th>\n",
" <td>id49250</td>\n",
" <td>We booked a room with two single beds. Upon ar...</td>\n",
" <td>Internet Explorer</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38925</th>\n",
" <td>id49251</td>\n",
" <td>Arrived via taxi from La Guardia - driving int...</td>\n",
" <td>Mozilla</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38926</th>\n",
" <td>id49252</td>\n",
" <td>I tend to post reviews only when I’ve had an e...</td>\n",
" <td>Firefox</td>\n",
" <td>Desktop</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38927</th>\n",
" <td>id49253</td>\n",
" <td>We arrived late at night and walked in to a ch...</td>\n",
" <td>Edge</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38928</th>\n",
" <td>id49254</td>\n",
" <td>The only positive impression is location and p...</td>\n",
" <td>InternetExplorer</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38929</th>\n",
" <td>id49255</td>\n",
" <td>Traveling with friends for shopping and a show...</td>\n",
" <td>Firefox</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38930</th>\n",
" <td>id49256</td>\n",
" <td>The experience was just ok. We paid extra for ...</td>\n",
" <td>Chrome</td>\n",
" <td>Desktop</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38931</th>\n",
" <td>id49257</td>\n",
" <td>The Westin is a wonderfully restored grande da...</td>\n",
" <td>Mozilla</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>38932 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" User_ID Description \\\n",
"0 id10326 The room was kind of clean but had a VERY stro... \n",
"1 id10327 I stayed at the Crown Plaza April -- - April -... \n",
"2 id10328 I booked this hotel through Hotwire at the low... \n",
"3 id10329 Stayed here with husband and sons on the way t... \n",
"4 id10330 My girlfriends and I stayed here to celebrate ... \n",
"5 id10331 We had - rooms. One was very nice and clearly ... \n",
"6 id10332 My husband and I have stayed in this hotel a f... \n",
"7 id10333 My wife & I stayed in this glorious city a whi... \n",
"8 id10334 My boyfriend and I stayed at the Fairmont on a... \n",
"9 id10335 Wonderful staff, great location, but it was de... \n",
"10 id10336 Steps off Times Square, nice rooms, stayed - n... \n",
"11 id10337 Me, the Wife and - kids stayed here on Valenti... \n",
"12 id10338 We stay at the Jolly Madison over the Xmas per... \n",
"13 id10339 I highly recommend the Hawthorne Terrace as an... \n",
"14 id10340 I found the hotel clean and nicely located. Go... \n",
"15 id10341 Stayed at the Elan from --th to --th October a... \n",
"16 id10342 Priceline sent us to this hotel after acceptin... \n",
"17 id10343 Old and cheap furnitures,our chair was simply ... \n",
"18 id10344 We stayed here for - nights and were really ha... \n",
"19 id10345 The service was fine, but the hotel itself fel... \n",
"20 id10346 Having stayed at many Hilton properties, I exp... \n",
"21 id10347 This is everything you could want from a hotel... \n",
"22 id10348 I very much wanted to stay at a boutique hotel... \n",
"23 id10349 I really liked this hotel. The staff were wond... \n",
"24 id10350 My wife and spent - days there this month as a... \n",
"25 id10351 We stayed at this hotel for two nights over th... \n",
"26 id10352 Took a girls trip to LA and had no idea where ... \n",
"27 id10353 Stayed with my girlfriend for a long weekend. ... \n",
"28 id10354 I have stayed here numerous times and never be... \n",
"29 id10355 The public areas are nice to look at. The staf... \n",
"... ... ... \n",
"38902 id49228 After having stayed at the Waldorf many times,... \n",
"38903 id49229 This hotel is a great choice for those staying... \n",
"38904 id49230 Although New York is a large city, whenever I ... \n",
"38905 id49231 I used to live in Austin, so when I moved away... \n",
"38906 id49232 I've stayed at the Hilton, Hyatt, Magnolia and... \n",
"38907 id49233 Great Location,short walk from Amtrak station,... \n",
"38908 id49234 When we booked this was a Renaissance Hotel bu... \n",
"38909 id49235 Hotel is an old style Red Roof and has not bee... \n",
"38910 id49236 I have to admit I tried rebooking since I was ... \n",
"38911 id49237 Room was nice, everything seemed pretty new. R... \n",
"38912 id49238 then a great place to stay is this hotel. Not ... \n",
"38913 id49239 I will never ever stay at this Hotel again. I ... \n",
"38914 id49240 After being on a bus for -- hours and finally ... \n",
"38915 id49241 pretty cool hotel. stayed for a few days in mi... \n",
"38916 id49242 We stopped over in LAX on the way to Canada an... \n",
"38917 id49243 I love this hotel and will stay again for seve... \n",
"38918 id49244 We were excited about our stay at the Blu Aqua... \n",
"38919 id49245 I didn't get to see much of Seattle but the ho... \n",
"38920 id49246 My husband and I stayed one night at the Heart... \n",
"38921 id49247 We staed at the Handlery Hotel to Visit San Di... \n",
"38922 id49248 This hotel has a great location if you want to... \n",
"38923 id49249 I am pretty impartial to this hotel. I would d... \n",
"38924 id49250 We booked a room with two single beds. Upon ar... \n",
"38925 id49251 Arrived via taxi from La Guardia - driving int... \n",
"38926 id49252 I tend to post reviews only when I’ve had an e... \n",
"38927 id49253 We arrived late at night and walked in to a ch... \n",
"38928 id49254 The only positive impression is location and p... \n",
"38929 id49255 Traveling with friends for shopping and a show... \n",
"38930 id49256 The experience was just ok. We paid extra for ... \n",
"38931 id49257 The Westin is a wonderfully restored grande da... \n",
"\n",
" Browser_Used Device_Used Is_Response \n",
"0 Edge Mobile not_happy \n",
"1 Internet Explorer Mobile not_happy \n",
"2 Mozilla Tablet not_happy \n",
"3 InternetExplorer Desktop happy \n",
"4 Edge Tablet not_happy \n",
"5 InternetExplorer Desktop happy \n",
"6 Firefox Tablet not_happy \n",
"7 Google Chrome Mobile happy \n",
"8 Internet Explorer Desktop happy \n",
"9 Chrome Tablet not_happy \n",
"10 Internet Explorer Tablet happy \n",
"11 IE Mobile happy \n",
"12 Edge Mobile not_happy \n",
"13 Internet Explorer Desktop happy \n",
"14 Chrome Desktop happy \n",
"15 Mozilla Desktop happy \n",
"16 Mozilla Tablet not_happy \n",
"17 Google Chrome Desktop not_happy \n",
"18 Google Chrome Mobile happy \n",
"19 Mozilla Desktop not_happy \n",
"20 Firefox Mobile not_happy \n",
"21 Firefox Desktop happy \n",
"22 Edge Tablet not_happy \n",
"23 Chrome Desktop happy \n",
"24 Chrome Desktop happy \n",
"25 Opera Mobile not_happy \n",
"26 InternetExplorer Mobile happy \n",
"27 Mozilla Firefox Desktop happy \n",
"28 Mozilla Mobile happy \n",
"29 Firefox Tablet not_happy \n",
"... ... ... ... \n",
"38902 InternetExplorer Mobile happy \n",
"38903 Mozilla Mobile happy \n",
"38904 Google Chrome Tablet happy \n",
"38905 IE Desktop not_happy \n",
"38906 InternetExplorer Desktop happy \n",
"38907 Firefox Mobile happy \n",
"38908 Mozilla Desktop happy \n",
"38909 Mozilla Desktop not_happy \n",
"38910 Chrome Desktop happy \n",
"38911 Internet Explorer Mobile happy \n",
"38912 Mozilla Firefox Tablet happy \n",
"38913 Firefox Desktop not_happy \n",
"38914 Mozilla Mobile not_happy \n",
"38915 InternetExplorer Tablet happy \n",
"38916 Google Chrome Desktop happy \n",
"38917 Chrome Tablet happy \n",
"38918 Edge Mobile not_happy \n",
"38919 Internet Explorer Desktop happy \n",
"38920 InternetExplorer Tablet happy \n",
"38921 Edge Desktop happy \n",
"38922 Edge Desktop not_happy \n",
"38923 Edge Mobile not_happy \n",
"38924 Internet Explorer Desktop happy \n",
"38925 Mozilla Mobile happy \n",
"38926 Firefox Desktop not_happy \n",
"38927 Edge Desktop happy \n",
"38928 InternetExplorer Mobile not_happy \n",
"38929 Firefox Mobile not_happy \n",
"38930 Chrome Desktop not_happy \n",
"38931 Mozilla Desktop happy \n",
"\n",
"[38932 rows x 5 columns]"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"train_df"
]
},
{
"cell_type": "markdown",
"metadata": {
"heading_collapsed": true
},
"source": [
"### Inspecting data"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": true,
"hidden": true
},
"outputs": [],
"source": [
"train_df['device_happy'] = train_df['Device_Used']+'_'+train_df['Is_Response']\n",
"train_df['browser_happy'] = train_df['Browser_Used']+'_'+train_df['Is_Response']"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": true,
"hidden": true
},
"outputs": [],
"source": [
"def plot(var, df):\n",
" data = [go.Bar(\n",
" x = df[var].unique(),\n",
" y = df[var].value_counts().values,\n",
" marker= dict(colorscale='Jet',\n",
" color = df[var].value_counts().values\n",
" ),\n",
" text='Number of comments for this category'\n",
" )]\n",
" layout = go.Layout(\n",
" title='Target variable distribution',\n",
" xaxis = dict(categoryorder='category ascending')\n",
" )\n",
"\n",
" fig = go.Figure(data=data, layout=layout)\n",
"\n",
" py.iplot(fig, filename='basic-bar')\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": true,
"hidden": true
},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"data": [
{
"marker": {
"color": [
26521,
12411
],
"colorscale": "Jet"
},
"text": "Number of comments for this category",
"type": "bar",
"x": [
"not happy",
"happy"
],
"y": [
26521,
12411
]
}
],
"layout": {
"title": "Target variable distribution"
}
},
"text/html": [
"<div id=\"b57efbe4-da2e-4fee-a90a-085794400931\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"b57efbe4-da2e-4fee-a90a-085794400931\", [{\"type\": \"bar\", \"x\": [\"not happy\", \"happy\"], \"y\": [26521, 12411], \"marker\": {\"colorscale\": \"Jet\", \"color\": [26521, 12411]}, \"text\": \"Number of comments for this category\"}], {\"title\": \"Target variable distribution\"}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\"})});</script>"
],
"text/vnd.plotly.v1+html": [
"<div id=\"b57efbe4-da2e-4fee-a90a-085794400931\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"b57efbe4-da2e-4fee-a90a-085794400931\", [{\"type\": \"bar\", \"x\": [\"not happy\", \"happy\"], \"y\": [26521, 12411], \"marker\": {\"colorscale\": \"Jet\", \"color\": [26521, 12411]}, \"text\": \"Number of comments for this category\"}], {\"title\": \"Target variable distribution\"}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\"})});</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot('Is_Response', train_df)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": true,
"hidden": true
},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"data": [
{
"marker": {
"color": [
10602,
10595,
5324,
4431,
4374,
3606
],
"colorscale": "Jet"
},
"text": "Number of comments for this category",
"type": "bar",
"x": [
"Mobile_not happy",
"Tablet_not happy",
"Desktop_happy",
"Mobile_happy",
"Tablet_happy",
"Desktop_not happy"
],
"y": [
10602,
10595,
5324,
4431,
4374,
3606
]
}
],
"layout": {
"title": "Target variable distribution",
"xaxis": {
"categoryorder": "category ascending"
}
}
},
"text/html": [
"<div id=\"349e2da5-06d6-4a13-815a-c772f9f4735c\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"349e2da5-06d6-4a13-815a-c772f9f4735c\", [{\"type\": \"bar\", \"x\": [\"Mobile_not happy\", \"Tablet_not happy\", \"Desktop_happy\", \"Mobile_happy\", \"Tablet_happy\", \"Desktop_not happy\"], \"y\": [10602, 10595, 5324, 4431, 4374, 3606], \"marker\": {\"colorscale\": \"Jet\", \"color\": [10602, 10595, 5324, 4431, 4374, 3606]}, \"text\": \"Number of comments for this category\"}], {\"title\": \"Target variable distribution\", \"xaxis\": {\"categoryorder\": \"category ascending\"}}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\"})});</script>"
],
"text/vnd.plotly.v1+html": [
"<div id=\"349e2da5-06d6-4a13-815a-c772f9f4735c\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"349e2da5-06d6-4a13-815a-c772f9f4735c\", [{\"type\": \"bar\", \"x\": [\"Mobile_not happy\", \"Tablet_not happy\", \"Desktop_happy\", \"Mobile_happy\", \"Tablet_happy\", \"Desktop_not happy\"], \"y\": [10602, 10595, 5324, 4431, 4374, 3606], \"marker\": {\"colorscale\": \"Jet\", \"color\": [10602, 10595, 5324, 4431, 4374, 3606]}, \"text\": \"Number of comments for this category\"}], {\"title\": \"Target variable distribution\", \"xaxis\": {\"categoryorder\": \"category ascending\"}}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\"})});</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot('device_happy', train_df)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": true,
"hidden": true
},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"data": [
{
"marker": {
"color": [
15026,
14976,
8930
],
"colorscale": "Jet"
},
"text": "Number of comments for this category",
"type": "bar",
"x": [
"Mobile",
"Tablet",
"Desktop"
],
"y": [
15026,
14976,
8930
]
}
],
"layout": {
"title": "Target variable distribution",
"xaxis": {
"categoryorder": "category ascending"
}
}
},
"text/html": [
"<div id=\"adec066e-81a1-4008-afd8-ceda6217807b\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"adec066e-81a1-4008-afd8-ceda6217807b\", [{\"type\": \"bar\", \"x\": [\"Mobile\", \"Tablet\", \"Desktop\"], \"y\": [15026, 14976, 8930], \"marker\": {\"colorscale\": \"Jet\", \"color\": [15026, 14976, 8930]}, \"text\": \"Number of comments for this category\"}], {\"title\": \"Target variable distribution\", \"xaxis\": {\"categoryorder\": \"category ascending\"}}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\"})});</script>"
],
"text/vnd.plotly.v1+html": [
"<div id=\"adec066e-81a1-4008-afd8-ceda6217807b\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"adec066e-81a1-4008-afd8-ceda6217807b\", [{\"type\": \"bar\", \"x\": [\"Mobile\", \"Tablet\", \"Desktop\"], \"y\": [15026, 14976, 8930], \"marker\": {\"colorscale\": \"Jet\", \"color\": [15026, 14976, 8930]}, \"text\": \"Number of comments for this category\"}], {\"title\": \"Target variable distribution\", \"xaxis\": {\"categoryorder\": \"category ascending\"}}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\"})});</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot('Device_Used', train_df)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": true,
"hidden": true
},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"data": [
{
"marker": {
"color": [
7367,
7134,
4659,
4588,
4328,
3092,
2470,
2439,
2103,
390,
362
],
"colorscale": "Jet"
},
"text": "Number of comments for this category",
"type": "bar",
"x": [
"Edge",
"Internet Explorer",
"Mozilla",
"InternetExplorer",
"Firefox",
"Google Chrome",
"Chrome",
"IE",
"Opera",
"Mozilla Firefox",
"Safari"
],
"y": [
7367,
7134,
4659,
4588,
4328,
3092,
2470,
2439,
2103,
390,
362
]
}
],
"layout": {
"title": "Target variable distribution",
"xaxis": {
"categoryorder": "category ascending"
}
}
},
"text/html": [
"<div id=\"fc9b2974-eeb4-4d1a-9e23-9316acf49e50\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"fc9b2974-eeb4-4d1a-9e23-9316acf49e50\", [{\"type\": \"bar\", \"x\": [\"Edge\", \"Internet Explorer\", \"Mozilla\", \"InternetExplorer\", \"Firefox\", \"Google Chrome\", \"Chrome\", \"IE\", \"Opera\", \"Mozilla Firefox\", \"Safari\"], \"y\": [7367, 7134, 4659, 4588, 4328, 3092, 2470, 2439, 2103, 390, 362], \"marker\": {\"colorscale\": \"Jet\", \"color\": [7367, 7134, 4659, 4588, 4328, 3092, 2470, 2439, 2103, 390, 362]}, \"text\": \"Number of comments for this category\"}], {\"title\": \"Target variable distribution\", \"xaxis\": {\"categoryorder\": \"category ascending\"}}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\"})});</script>"
],
"text/vnd.plotly.v1+html": [
"<div id=\"fc9b2974-eeb4-4d1a-9e23-9316acf49e50\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"fc9b2974-eeb4-4d1a-9e23-9316acf49e50\", [{\"type\": \"bar\", \"x\": [\"Edge\", \"Internet Explorer\", \"Mozilla\", \"InternetExplorer\", \"Firefox\", \"Google Chrome\", \"Chrome\", \"IE\", \"Opera\", \"Mozilla Firefox\", \"Safari\"], \"y\": [7367, 7134, 4659, 4588, 4328, 3092, 2470, 2439, 2103, 390, 362], \"marker\": {\"colorscale\": \"Jet\", \"color\": [7367, 7134, 4659, 4588, 4328, 3092, 2470, 2439, 2103, 390, 362]}, \"text\": \"Number of comments for this category\"}], {\"title\": \"Target variable distribution\", \"xaxis\": {\"categoryorder\": \"category ascending\"}}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\"})});</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot('Browser_Used', train_df)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": true,
"hidden": true
},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"data": [
{
"marker": {
"color": [
4035,
3967,
3916,
3685,
3682,
3218,
3203,
2103,
2099,
1845,
1841,
1251,
1125,
624,
621,
367,
340,
284,
258,
241,
121,
106
],
"colorscale": "Jet"
},
"text": "Number of comments for this category",
"type": "bar",
"x": [
"Edge_not happy",
"Internet Explorer_not happy",
"Mozilla_not happy",
"InternetExplorer_happy",
"Firefox_not happy",
"Google Chrome_happy",
"Internet Explorer_happy",
"Chrome_not happy",
"IE_happy",
"Chrome_happy",
"Mozilla_happy",
"Google Chrome_not happy",
"Firefox_happy",
"Opera_not happy",
"Mozilla Firefox_happy",
"InternetExplorer_not happy",
"Edge_happy",
"IE_not happy",
"Safari_happy",
"Opera_happy",
"Safari_not happy",
"Mozilla Firefox_not happy"
],
"y": [
4035,
3967,
3916,
3685,
3682,
3218,
3203,
2103,
2099,
1845,
1841,
1251,
1125,
624,
621,
367,
340,
284,
258,
241,
121,
106
]
}
],
"layout": {
"title": "Target variable distribution",
"xaxis": {
"categoryorder": "category ascending"
}
}
},
"text/html": [
"<div id=\"84fb643d-1d66-4696-ab82-8ad431dc951f\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"84fb643d-1d66-4696-ab82-8ad431dc951f\", [{\"type\": \"bar\", \"x\": [\"Edge_not happy\", \"Internet Explorer_not happy\", \"Mozilla_not happy\", \"InternetExplorer_happy\", \"Firefox_not happy\", \"Google Chrome_happy\", \"Internet Explorer_happy\", \"Chrome_not happy\", \"IE_happy\", \"Chrome_happy\", \"Mozilla_happy\", \"Google Chrome_not happy\", \"Firefox_happy\", \"Opera_not happy\", \"Mozilla Firefox_happy\", \"InternetExplorer_not happy\", \"Edge_happy\", \"IE_not happy\", \"Safari_happy\", \"Opera_happy\", \"Safari_not happy\", \"Mozilla Firefox_not happy\"], \"y\": [4035, 3967, 3916, 3685, 3682, 3218, 3203, 2103, 2099, 1845, 1841, 1251, 1125, 624, 621, 367, 340, 284, 258, 241, 121, 106], \"marker\": {\"colorscale\": \"Jet\", \"color\": [4035, 3967, 3916, 3685, 3682, 3218, 3203, 2103, 2099, 1845, 1841, 1251, 1125, 624, 621, 367, 340, 284, 258, 241, 121, 106]}, \"text\": \"Number of comments for this category\"}], {\"title\": \"Target variable distribution\", \"xaxis\": {\"categoryorder\": \"category ascending\"}}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\"})});</script>"
],
"text/vnd.plotly.v1+html": [
"<div id=\"84fb643d-1d66-4696-ab82-8ad431dc951f\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"84fb643d-1d66-4696-ab82-8ad431dc951f\", [{\"type\": \"bar\", \"x\": [\"Edge_not happy\", \"Internet Explorer_not happy\", \"Mozilla_not happy\", \"InternetExplorer_happy\", \"Firefox_not happy\", \"Google Chrome_happy\", \"Internet Explorer_happy\", \"Chrome_not happy\", \"IE_happy\", \"Chrome_happy\", \"Mozilla_happy\", \"Google Chrome_not happy\", \"Firefox_happy\", \"Opera_not happy\", \"Mozilla Firefox_happy\", \"InternetExplorer_not happy\", \"Edge_happy\", \"IE_not happy\", \"Safari_happy\", \"Opera_happy\", \"Safari_not happy\", \"Mozilla Firefox_not happy\"], \"y\": [4035, 3967, 3916, 3685, 3682, 3218, 3203, 2103, 2099, 1845, 1841, 1251, 1125, 624, 621, 367, 340, 284, 258, 241, 121, 106], \"marker\": {\"colorscale\": \"Jet\", \"color\": [4035, 3967, 3916, 3685, 3682, 3218, 3203, 2103, 2099, 1845, 1841, 1251, 1125, 624, 621, 367, 340, 284, 258, 241, 121, 106]}, \"text\": \"Number of comments for this category\"}], {\"title\": \"Target variable distribution\", \"xaxis\": {\"categoryorder\": \"category ascending\"}}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\"})});</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot('browser_happy', train_df)"
]
},
{
"cell_type": "markdown",
"metadata": {
"heading_collapsed": true
},
"source": [
"### Build language model"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true,
"hidden": true
},
"outputs": [],
"source": [
"TEXT = torchtext.data.Field(lower=True, tokenize=spacy_tok)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true,
"hidden": true,
"scrolled": true
},
"outputs": [],
"source": [
"#md = LanguageModelData(TEXT, **FILES, bs=bs, bptt=bptt, min_freq=5)\n",
"\n",
"md = LanguageModelData.from_dataframes(PATH, TEXT, 'Description',\n",
" train_df, val_df, test_df, bs=bs, bptt=bptt)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true,
"hidden": true
},
"outputs": [],
"source": [
"pickle.dump(TEXT, open(f'{PATH}/models/TEXT.pkl','wb'))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true,
"hidden": true,
"scrolled": true
},
"outputs": [],
"source": [
"learner = md.get_model(opt_fn, em_sz, nh, nl,\n",
" dropouti=0.05, dropout=0.05, wdrop=0.1, dropoute=0.02, dropouth=0.05)\n",
"learner.reg_fn = partial(seq2seq_reg, alpha=2, beta=1)\n",
"learner.clip=0.3"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"hidden": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "fb6af18e2d9d483f8b2f3c1e263836a5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" 81%|████████▏ | 966/1187 [02:51<00:39, 5.63it/s, loss=nan] "
]
}
],
"source": [
"lrf=learner.lr_find()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"hidden": true,
"scrolled": true
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEOCAYAAACEiBAqAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xd8VFX+//HXJ70npAFJSAKE0HukqCAIlkUERexdv7Lq\n2nCb67o/1226q7trW11RV2zYQFzFgggiCFISinQIEEogjRDS+/n9MYObzRJIYGbulM/z8ZhHZu7c\nmfu+M5BPzj33niPGGJRSSvkuP6sDKKWUspYWAqWU8nFaCJRSysdpIVBKKR+nhUAppXycFgKllPJx\nWgiUUsrHaSFQSikfp4VAKaV8nBYCpZTycQFWB2iP+Ph4k56ebnUMpZTyKDk5OSXGmIRTree0QiAi\n/wImA0XGmAH2ZVcCvwX6AiOMMdntea/09HSys9u1qlJKKTsR2dee9Zx5aGg2cHGrZZuBacAyJ25X\nKaVUBzitRWCMWSYi6a2WbQMQEWdtVimlVAdpZ7FSSvk4ty0EIjJDRLJFJLu4uNjqOEop5bXcthAY\nY2YZY7KMMVkJCafs9FZKKXWa3LYQKKWUcg1nnj76DjAOiBeRg8CjQCnwHJAAfCoiG4wxFzkrw9ZD\n5RwqqyEwwI9AP7H99Pcj0F8I8rfdD/AXQgP9CQ8OIDjATzuylVI+x5lnDV3bxlPznbXN1uas2cdb\nq/a3e31/PyE8yFYUwoL8iQgOICwogPDgAMKDbcu7RIWQFhdG9/hw+nSJIihAG1VKKc/mEVcWn66f\njM/g6qxU6puaabDfGpvMfz2ub2ymtqGZyrpGqusbqaproqquker6ph+WHSqroaq+kcraRo5U1f/w\n/mFB/ozvk8jPL+xNeny4hXuqlFKnz6sLQdfoULpGh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19UF5AC4FyJgEeN8a8\n9F8LbZPETARGG2OqRWQptukzAWqNMU2t3qfO/rOJtv/N1rW4L22sczJVLe4/h20a04/tWX/bxmv8\ngFHGmNqTvG8N/9k3hzHG7BSRYcAk4A8ishiY38bqM4FCbFOV+gEnyivYWl4LT/BcCLb9UF5K+wiU\nMy0EbhORCAARSRaRRGx/bR61F4E+wCgnbX8FcIW9r6Azts7e9ojmP+O639xieQUQ2eLxl9hm/gLA\n/hd3a9uAjDa2sxLb0MFgOwa/3H5/FbZDP7R4/r+ISBJQbYx5C3gSGAbsALqKyFn2dSLtnd/R2FoK\nzcCN2Ob2bW0hcJeIBNpfm2lvSYCtBXHSs4uUZ9NCoJzGGPMltkMb34nIJmAutl+kXwABIrIN2zy6\nq5wUYR626fu2Am8B64Bj7Xjdb4EPRCQHKGmx/BPg8uOdxcB9QJa9c3UrJ5gFyxizHdv0kJGtn8NW\nRG4Vke+x/YK+3778AeBB+/KMNjIPBNaIyAbgUeAPxph64GrgOXtn+yJsf82/ANxsX9aH/279HPcK\nts9pnf2U0pf4T+trPPDpCV6jvIQOQ6282vFj9mKbt3YNcI4xpsDFGWYCFcaYV9q5fhhQY4wxInIN\nto7jqU4NefI8y7BNDn/UqgzKubSPQHm7BSISg63T9/euLgJ2LwJXdmD94dg6dwUow3ZGkSVEJAFb\nf4kWAS+mLQKllPJx2keglFI+TguBUkr5OC0ESinl47QQKKWUj9NCoJRSPk4LgVJK+bj/DzMfWbHI\nPoaTAAAAAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x7fdaa52c6748>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learner.sched.plot()"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"hidden": true,
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bde76f1d2b3a421badb03f2185800124",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 0. 6.12176 6.07478] \n",
"\n"
]
}
],
"source": [
"learner.fit(1e-2, 1)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"hidden": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d7e121323b5a4e1cb8600c89996ca34b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 0. 4.31361 4.26048] \n",
"[ 1. 3.83279 3.76361] \n",
"[ 2. 3.65958 3.63309] \n",
"[ 3. 3.76728 3.70998] \n",
"[ 4. 3.66437 3.60313] \n",
"[ 5. 3.55213 3.52256] \n",
"[ 6. 3.48179 3.49506] \n",
"[ 7. 3.72117 3.65075] \n",
"[ 8. 3.68247 3.61816] \n",
"[ 9. 3.63464 3.57345] \n",
"[ 10. 3.58028 3.52536] \n",
"[ 11. 3.50675 3.47718] \n",
"[ 12. 3.44388 3.44178] \n",
"[ 13. 3.39997 3.41916] \n",
"[ 14. 3.36362 3.41361] \n",
"\n"
]
}
],
"source": [
"learner.fit(1e-2, 4, wds=1e-6, cycle_len=1, cycle_mult=2, cycle_save_name='adam1_cycle_')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"hidden": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5e56a4894cd54ebd81f7f3937c30bbbb",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 0. 3.6878 3.62219] \n",
"[ 1. 3.82222 3.74911] \n",
"[ 2. 3.66374 3.6021 ] \n",
"[ 3. 3.87951 3.80899] \n",
"[ 4. 3.79115 3.71117] \n",
"[ 5. 3.68332 3.61516] \n",
"[ 6. 3.59533 3.56605] \n",
"[ 7. 3.87646 3.81644] \n",
"[ 8. 3.86822 3.79612] \n",
"[ 9. 3.82485 3.75954] \n",
"[ 10. 3.7683 3.69983] \n",
"[ 11. 3.70777 3.6439 ] \n",
"[ 12. 3.64578 3.59399] \n",
"[ 13. 3.5963 3.55151] \n",
"[ 14. 3.55934 3.54348] \n",
"\n"
]
}
],
"source": [
"learner.fit(1e-2, 4, wds=1e-5, cycle_len=1, cycle_mult=2, cycle_save_name='adam1_cycle2_')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": true,
"hidden": true
},
"outputs": [],
"source": [
"learner.save_encoder('adam1_enc')\n",
"learner.save('adam1')"
]
},
{
"cell_type": "markdown",
"metadata": {
"heading_collapsed": true
},
"source": [
"### Checking the language model"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"hidden": true
},
"outputs": [
{
"data": {
"text/plain": [
"'. the staff was not very friendly , and I'"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m=learner.model\n",
"ss=\". the staff was not very friendly, and I \"\n",
"s = [spacy_tok(ss)]\n",
"t=TEXT.numericalize(s)\n",
"' '.join(s[0])"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true,
"hidden": true
},
"outputs": [],
"source": [
"# Set batch size to 1\n",
"m[0].bs=1\n",
"# Turn off dropout\n",
"m.eval()\n",
"# Reset hidden state\n",
"m.reset()\n",
"# Get predictions from model\n",
"res,*_ = m(t)\n",
"# Put the batch size back to what it was\n",
"m[0].bs=bs"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"hidden": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
". the staff was not very friendly, and I \n",
"\n",
". the room was clean and the bed was comfortable . the bathroom was small but clean . the bathroom was very clean and the shower was great . the room was clean and the bed was comfortable . the bathroom was very clean and the shower was great . the only thing i would say is that the room was a bit small , but it was clean and ...\n"
]
}
],
"source": [
"print(ss,\"\\n\")\n",
"for i in range(70):\n",
" n=res[-1].topk(2)[1]\n",
" n = n[1] if n.data[0]==0 else n[0]\n",
" print(TEXT.vocab.itos[n.data[0]], end=' ')\n",
" res,*_ = m(n[0].unsqueeze(0))\n",
"print('...')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Classification model"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"class PredictHappinessDataset(torchtext.data.Dataset):\n",
" def __init__(self, path, text_field, label_field, dfs, **kwargs):\n",
" fields = [(\"text\", text_field), (\"label\", label_field)]\n",
" examples = []\n",
" for i in range(dfs[path].values[:,1].shape[0]):\n",
" text = dfs[path].Description[i]\n",
" label = dfs[path].Is_Response[i]\n",
" examples.append(data.Example.fromlist([text, label], fields))\n",
" super().__init__(examples, fields, **kwargs)\n",
"\n",
" @staticmethod\n",
" def sort_key(ex): return len(ex.text)\n",
" \n",
" @classmethod\n",
" def splits(cls, text_field, label_field, path,\n",
" train, val, test, dfs, **kwargs):\n",
" return super().splits(path,\n",
" text_field=text_field, label_field=label_field,\n",
" train=train, validation=val, test=test, dfs=dfs, **kwargs)\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"df = {'train': train_df, 'val': val_df, 'test': test_df}\n",
"#TEXT = pickle.load(open(f'{PATH}models/TEXT.pkl','rb'))\n",
"TEXT = pickle.load(open(f'{PATH}models/h2TEXT.pkl','rb'))\n",
"LABEL = data.Field(sequential=False)\n",
"splits = PredictHappinessDataset.splits(TEXT, LABEL, '',\n",
" train='train',\n",
" val='val', test='test', dfs=df)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"md2 = TextData.from_splits(PATH, splits, 1)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"dropouti, dropout, wdrop, dropoute, dropouth = np.array([0.05,0.05,0.1,0.02,0.05])*6\n",
"m3 = md2.get_model(opt_fn, 1500, bptt, emb_sz=em_sz, n_hid=nh, n_layers=nl, \n",
" dropouti=dropouti, dropout=dropout, wdrop=wdrop,\n",
" dropoute=dropoute, dropouth=dropouth)\n",
"m3.reg_fn = partial(seq2seq_reg, alpha=2, beta=1)\n",
"m3.load_encoder(f'h2_adam1_enc')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"m3.load_cycle('h1',3)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"m3.clip=25.\n",
"lrs=np.array([1e-4,1e-3,1e-2])"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Widget Javascript not detected. It may not be installed or enabled properly.\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "19ae939afbe242e0b2f0471560309e8a"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 0. 0.36368 0.29015 0.87844] \n",
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Widget Javascript not detected. It may not be installed or enabled properly.\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "63e754a8a4d34865b2fa5ca823a17a9b"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 0. 0.27269 0.24616 0.90416] \n",
"\n"
]
}
],
"source": [
"m3.freeze_to(-1)\n",
"m3.fit(lrs/2, 1, metrics=[accuracy])\n",
"m3.unfreeze()\n",
"m3.fit(lrs, 1, metrics=[accuracy], cycle_len=1)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Widget Javascript not detected. It may not be installed or enabled properly.\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d1ba3bc244cd470dabe7b719cb7feed7"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 0. 0.29082 0.24119 0.90234] \n",
"[ 1. 0.24561 0.23406 0.90675] \n",
"[ 2. 0.25842 0.23033 0.91013] \n",
"[ 3. 0.2491 0.22947 0.90961] \n",
"[ 4. 0.24476 0.23164 0.91013] \n",
"[ 5. 0.22587 0.22839 0.90779] \n",
"[ 6. 0.23329 0.23076 0.90831] \n",
"[ 7. 0.22022 0.22785 0.90727] \n",
" 64%|██████▎ | 405/637 [01:07<00:38, 6.03it/s, loss=0.237]"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-11-3698c4e9330f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mm3\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlrs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m30\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmetrics\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0maccuracy\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcycle_len\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcycle_save_name\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'h1'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m~/fastai-pytorch/courses/dl1/fastai/learner.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, lrs, n_cycle, wds, **kwargs)\u001b[0m\n\u001b[1;32m 97\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msched\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 98\u001b[0m \u001b[0mlayer_opt\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_layer_opt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlrs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 99\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit_gen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlayer_opt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mn_cycle\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 100\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 101\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mlr_find\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstart_lr\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1e-5\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mend_lr\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwds\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/fastai-pytorch/courses/dl1/fastai/learner.py\u001b[0m in \u001b[0;36mfit_gen\u001b[0;34m(self, model, data, layer_opt, n_cycle, cycle_len, cycle_mult, cycle_save_name, metrics, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m 87\u001b[0m \u001b[0mn_epoch\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msum_geom\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcycle_len\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcycle_len\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcycle_mult\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mn_cycle\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 88\u001b[0m fit(model, data, n_epoch, layer_opt.opt, self.crit,\n\u001b[0;32m---> 89\u001b[0;31m metrics=metrics, callbacks=callbacks, reg_fn=self.reg_fn, clip=self.clip, **kwargs)\n\u001b[0m\u001b[1;32m 90\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 91\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mget_layer_groups\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodels\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_layer_groups\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/fastai-pytorch/courses/dl1/fastai/model.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(model, data, epochs, opt, crit, metrics, callbacks, **kwargs)\u001b[0m\n\u001b[1;32m 82\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[0mbatch_num\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 84\u001b[0;31m \u001b[0mloss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstepper\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mV\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mV\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my\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 85\u001b[0m \u001b[0mavg_loss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mavg_loss\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mavg_mom\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mloss\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mavg_mom\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 86\u001b[0m \u001b[0mdebias_loss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mavg_loss\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mavg_mom\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mbatch_num\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/fastai-pytorch/courses/dl1/fastai/model.py\u001b[0m in \u001b[0;36mstep\u001b[0;34m(self, xs, y)\u001b[0m\n\u001b[1;32m 43\u001b[0m \u001b[0mloss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mraw_loss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcrit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 44\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreg_fn\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mloss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreg_fn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mxtra\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mraw_loss\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 45\u001b[0;31m \u001b[0mloss\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbackward\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 46\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclip\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# Gradient clipping\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 47\u001b[0m \u001b[0mnn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mutils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclip_grad_norm\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrainable_params_\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mm\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclip\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/autograd/variable.py\u001b[0m in \u001b[0;36mbackward\u001b[0;34m(self, gradient, retain_graph, create_graph, retain_variables)\u001b[0m\n\u001b[1;32m 154\u001b[0m \u001b[0mVariable\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 155\u001b[0m \"\"\"\n\u001b[0;32m--> 156\u001b[0;31m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mautograd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbackward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgradient\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mretain_graph\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcreate_graph\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mretain_variables\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 157\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 158\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mregister_hook\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhook\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/autograd/__init__.py\u001b[0m in \u001b[0;36mbackward\u001b[0;34m(variables, grad_variables, retain_graph, create_graph, retain_variables)\u001b[0m\n\u001b[1;32m 96\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 97\u001b[0m Variable._execution_engine.run_backward(\n\u001b[0;32m---> 98\u001b[0;31m variables, grad_variables, retain_graph)\n\u001b[0m\u001b[1;32m 99\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 100\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"source": [
"m3.fit(lrs, 30, metrics=[accuracy], cycle_len=2, cycle_save_name='h1')"
]
},
{
"cell_type": "code",
"execution_count": 85,
"metadata": {},
"outputs": [],
"source": [
"log_preds, y = m3.predict_with_targs(is_test=True)"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"m3."
]
},
{
"cell_type": "code",
"execution_count": 89,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"38932"
]
},
"execution_count": 89,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(test_df)"
]
},
{
"cell_type": "code",
"execution_count": 86,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"38885"
]
},
"execution_count": 86,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(log_preds)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"47"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(test_df)-len(log_preds)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"47"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(test_df)%bs"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"\n",
"val_preds,y = m3.predict_with_targs()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 1, 1, 1, 2, 1, 1, 1, 1, 1])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = np.argmax(val_preds,axis=1)\n",
"\n",
"res[:10]"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 1, 1, 1, 2, 1, 1, 1, 1, 1])"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y[:10]"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>index</th>\n",
" <th>User_ID</th>\n",
" <th>Description</th>\n",
" <th>Browser_Used</th>\n",
" <th>Device_Used</th>\n",
" <th>Is_Response</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>5</td>\n",
" <td>id10331</td>\n",
" <td>We had - rooms. One was very nice and clearly ...</td>\n",
" <td>InternetExplorer</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>8</td>\n",
" <td>id10334</td>\n",
" <td>My boyfriend and I stayed at the Fairmont on a...</td>\n",
" <td>Internet Explorer</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>9</td>\n",
" <td>id10335</td>\n",
" <td>Wonderful staff, great location, but it was de...</td>\n",
" <td>Chrome</td>\n",
" <td>Tablet</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>16</td>\n",
" <td>id10342</td>\n",
" <td>Priceline sent us to this hotel after acceptin...</td>\n",
" <td>Mozilla</td>\n",
" <td>Tablet</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>35</td>\n",
" <td>id10361</td>\n",
" <td>Booked - rooms, at check-in they upgraded all ...</td>\n",
" <td>Firefox</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>45</td>\n",
" <td>id10371</td>\n",
" <td>Got a awesome rate here - $-- a night for a Ra...</td>\n",
" <td>InternetExplorer</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>46</td>\n",
" <td>id10372</td>\n",
" <td>We booked this hotel based on the fairly good ...</td>\n",
" <td>Edge</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>47</td>\n",
" <td>id10373</td>\n",
" <td>We spent - nights at the Sofitel Washington fr...</td>\n",
" <td>Chrome</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>81</td>\n",
" <td>id10407</td>\n",
" <td>My wife and I recently stayed at the Henderson...</td>\n",
" <td>Firefox</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>90</td>\n",
" <td>id10416</td>\n",
" <td>Just back from five nights in the Belvedere an...</td>\n",
" <td>Edge</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" index User_ID Description \\\n",
"0 5 id10331 We had - rooms. One was very nice and clearly ... \n",
"1 8 id10334 My boyfriend and I stayed at the Fairmont on a... \n",
"2 9 id10335 Wonderful staff, great location, but it was de... \n",
"3 16 id10342 Priceline sent us to this hotel after acceptin... \n",
"4 35 id10361 Booked - rooms, at check-in they upgraded all ... \n",
"5 45 id10371 Got a awesome rate here - $-- a night for a Ra... \n",
"6 46 id10372 We booked this hotel based on the fairly good ... \n",
"7 47 id10373 We spent - nights at the Sofitel Washington fr... \n",
"8 81 id10407 My wife and I recently stayed at the Henderson... \n",
"9 90 id10416 Just back from five nights in the Belvedere an... \n",
"\n",
" Browser_Used Device_Used Is_Response \n",
"0 InternetExplorer Desktop happy \n",
"1 Internet Explorer Desktop happy \n",
"2 Chrome Tablet not_happy \n",
"3 Mozilla Tablet not_happy \n",
"4 Firefox Tablet happy \n",
"5 InternetExplorer Desktop happy \n",
"6 Edge Mobile not_happy \n",
"7 Chrome Mobile happy \n",
"8 Firefox Tablet happy \n",
"9 Edge Mobile happy "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"val_df[:10]"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [
{
"ename": "KeyError",
"evalue": "<class 'numpy.ndarray'>",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-62-e79ab44dcbcf>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mfin_preds\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mF\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msoftmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mval_preds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/nn/functional.py\u001b[0m in \u001b[0;36msoftmax\u001b[0;34m(input)\u001b[0m\n\u001b[1;32m 527\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 528\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0msoftmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 529\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0m_functions\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mthnn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mauto\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mSoftmax\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 530\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 531\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/nn/_functions/thnn/auto.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(ctx, input, *params)\u001b[0m\n\u001b[1;32m 124\u001b[0m \u001b[0;34m@\u001b[0m\u001b[0mstaticmethod\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 125\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mctx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 126\u001b[0;31m \u001b[0mctx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_backend\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtype2backend\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput\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 127\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 128\u001b[0m \u001b[0mctx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madditional_args\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~/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/_thnn/__init__.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__getitem__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbackends\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload\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 16\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mKeyError\u001b[0m: <class 'numpy.ndarray'>"
]
}
],
"source": [
"fin_preds = F.softmax(val_preds, bs=1)"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2659"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len([z for z in x if z == 1])"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1191"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len([z for z in x if z == 2])"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"si=50\n",
"sj=si+25"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 1, 2, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1])"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y[si:sj]"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 1, 2, 1, 2, 2, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1])"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x[si:sj]"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>index</th>\n",
" <th>User_ID</th>\n",
" <th>Description</th>\n",
" <th>Browser_Used</th>\n",
" <th>Device_Used</th>\n",
" <th>Is_Response</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>483</td>\n",
" <td>id10809</td>\n",
" <td>I'm on business, and I travel from city to cit...</td>\n",
" <td>Firefox</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>51</th>\n",
" <td>507</td>\n",
" <td>id10833</td>\n",
" <td>Good location for exploring NY, helpful staff,...</td>\n",
" <td>IE</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>52</th>\n",
" <td>510</td>\n",
" <td>id10836</td>\n",
" <td>We stayed for three days and then another stay...</td>\n",
" <td>Edge</td>\n",
" <td>Desktop</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>53</th>\n",
" <td>530</td>\n",
" <td>id10856</td>\n",
" <td>So many disheartening problems with this hotel...</td>\n",
" <td>Firefox</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>54</th>\n",
" <td>534</td>\n",
" <td>id10860</td>\n",
" <td>This was my second stay, so I feel I can justi...</td>\n",
" <td>Mozilla Firefox</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>55</th>\n",
" <td>546</td>\n",
" <td>id10872</td>\n",
" <td>We stayed at the Radisson for - nights on reco...</td>\n",
" <td>Firefox</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>56</th>\n",
" <td>566</td>\n",
" <td>id10892</td>\n",
" <td>I stayed there for - days in July. The hotel i...</td>\n",
" <td>InternetExplorer</td>\n",
" <td>Desktop</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>57</th>\n",
" <td>569</td>\n",
" <td>id10895</td>\n",
" <td>Great hotel. I stayed at Hotel George for a br...</td>\n",
" <td>Firefox</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>58</th>\n",
" <td>570</td>\n",
" <td>id10896</td>\n",
" <td>My brother and I stayed here last month for - ...</td>\n",
" <td>Chrome</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>59</th>\n",
" <td>588</td>\n",
" <td>id10914</td>\n",
" <td>Party weekend? couples get away? this is a fan...</td>\n",
" <td>Internet Explorer</td>\n",
" <td>Desktop</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>60</th>\n",
" <td>592</td>\n",
" <td>id10918</td>\n",
" <td>Very nice hotel at reasonable rates. Rooms are...</td>\n",
" <td>Google Chrome</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>61</th>\n",
" <td>598</td>\n",
" <td>id10924</td>\n",
" <td>My husband I stayed here one night in April of...</td>\n",
" <td>Firefox</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>62</th>\n",
" <td>612</td>\n",
" <td>id10938</td>\n",
" <td>We always love staying at Residence Inn! This ...</td>\n",
" <td>Firefox</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>63</th>\n",
" <td>646</td>\n",
" <td>id10972</td>\n",
" <td>found it on Expedia with a nice package rate. ...</td>\n",
" <td>Mozilla Firefox</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>64</th>\n",
" <td>654</td>\n",
" <td>id10980</td>\n",
" <td>I Loved the fact that the hotel had an outdoor...</td>\n",
" <td>Mozilla Firefox</td>\n",
" <td>Desktop</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>65</th>\n",
" <td>663</td>\n",
" <td>id10989</td>\n",
" <td>-------\\nThis hotel is a nightmare! The weeken...</td>\n",
" <td>IE</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>66</th>\n",
" <td>682</td>\n",
" <td>id11008</td>\n",
" <td>We just returned from a - night stay (Oct. ---...</td>\n",
" <td>Internet Explorer</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>67</th>\n",
" <td>687</td>\n",
" <td>id11013</td>\n",
" <td>My husband &amp; I had a pleasant stay at this Sta...</td>\n",
" <td>Firefox</td>\n",
" <td>Desktop</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>68</th>\n",
" <td>693</td>\n",
" <td>id11019</td>\n",
" <td>We traveled to baltimore for a family occasion...</td>\n",
" <td>Google Chrome</td>\n",
" <td>Mobile</td>\n",
" <td>not_happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>69</th>\n",
" <td>694</td>\n",
" <td>id11020</td>\n",
" <td>We enjoyed our stay at the Belvedere. The loca...</td>\n",
" <td>Internet Explorer</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>70</th>\n",
" <td>695</td>\n",
" <td>id11021</td>\n",
" <td>We thoroughly enjoyed our stay at the Magnolia...</td>\n",
" <td>Internet Explorer</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>71</th>\n",
" <td>701</td>\n",
" <td>id11027</td>\n",
" <td>Unique boutique hotel, Rouge = red. Truly Red ...</td>\n",
" <td>Google Chrome</td>\n",
" <td>Tablet</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>72</th>\n",
" <td>708</td>\n",
" <td>id11034</td>\n",
" <td>The Kimberly Suites Hotel was a great experien...</td>\n",
" <td>Chrome</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>73</th>\n",
" <td>709</td>\n",
" <td>id11035</td>\n",
" <td>Spent a few days here while my partner attende...</td>\n",
" <td>InternetExplorer</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>74</th>\n",
" <td>716</td>\n",
" <td>id11042</td>\n",
" <td>The lobby looked wonderful, and a pretty sitti...</td>\n",
" <td>Firefox</td>\n",
" <td>Mobile</td>\n",
" <td>happy</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" index User_ID Description \\\n",
"50 483 id10809 I'm on business, and I travel from city to cit... \n",
"51 507 id10833 Good location for exploring NY, helpful staff,... \n",
"52 510 id10836 We stayed for three days and then another stay... \n",
"53 530 id10856 So many disheartening problems with this hotel... \n",
"54 534 id10860 This was my second stay, so I feel I can justi... \n",
"55 546 id10872 We stayed at the Radisson for - nights on reco... \n",
"56 566 id10892 I stayed there for - days in July. The hotel i... \n",
"57 569 id10895 Great hotel. I stayed at Hotel George for a br... \n",
"58 570 id10896 My brother and I stayed here last month for - ... \n",
"59 588 id10914 Party weekend? couples get away? this is a fan... \n",
"60 592 id10918 Very nice hotel at reasonable rates. Rooms are... \n",
"61 598 id10924 My husband I stayed here one night in April of... \n",
"62 612 id10938 We always love staying at Residence Inn! This ... \n",
"63 646 id10972 found it on Expedia with a nice package rate. ... \n",
"64 654 id10980 I Loved the fact that the hotel had an outdoor... \n",
"65 663 id10989 -------\\nThis hotel is a nightmare! The weeken... \n",
"66 682 id11008 We just returned from a - night stay (Oct. ---... \n",
"67 687 id11013 My husband & I had a pleasant stay at this Sta... \n",
"68 693 id11019 We traveled to baltimore for a family occasion... \n",
"69 694 id11020 We enjoyed our stay at the Belvedere. The loca... \n",
"70 695 id11021 We thoroughly enjoyed our stay at the Magnolia... \n",
"71 701 id11027 Unique boutique hotel, Rouge = red. Truly Red ... \n",
"72 708 id11034 The Kimberly Suites Hotel was a great experien... \n",
"73 709 id11035 Spent a few days here while my partner attende... \n",
"74 716 id11042 The lobby looked wonderful, and a pretty sitti... \n",
"\n",
" Browser_Used Device_Used Is_Response \n",
"50 Firefox Mobile not_happy \n",
"51 IE Tablet happy \n",
"52 Edge Desktop not_happy \n",
"53 Firefox Mobile not_happy \n",
"54 Mozilla Firefox Mobile happy \n",
"55 Firefox Tablet happy \n",
"56 InternetExplorer Desktop not_happy \n",
"57 Firefox Desktop happy \n",
"58 Chrome Tablet happy \n",
"59 Internet Explorer Desktop happy \n",
"60 Google Chrome Mobile happy \n",
"61 Firefox Mobile happy \n",
"62 Firefox Tablet happy \n",
"63 Mozilla Firefox Mobile happy \n",
"64 Mozilla Firefox Desktop not_happy \n",
"65 IE Mobile not_happy \n",
"66 Internet Explorer Mobile happy \n",
"67 Firefox Desktop not_happy \n",
"68 Google Chrome Mobile not_happy \n",
"69 Internet Explorer Mobile happy \n",
"70 Internet Explorer Tablet happy \n",
"71 Google Chrome Tablet happy \n",
"72 Chrome Mobile happy \n",
"73 InternetExplorer Mobile happy \n",
"74 Firefox Mobile happy "
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"val_df[si:sj]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[-14.85583, 2.40349, -2.00159],\n",
" [-19.95844, 4.35516, -3.72412],\n",
" [-16.24511, 2.68365, -2.23638],\n",
" [-17.58333, 2.84794, -2.38252],\n",
" [-13.6572 , 2.52569, -2.17866],\n",
" [-19.11308, 3.61321, -3.13233],\n",
" [-17.74234, 2.28132, -1.75192],\n",
" [-23.44251, 4.14215, -3.47599],\n",
" [-19.18306, 4.32479, -3.83419],\n",
" [-18.64775, 3.99196, -3.45184]], dtype=float32)"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"val_preds[:10]"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": true
},
"outputs": [
{
"ename": "TypeError",
"evalue": "'RNN_Learner' object is not callable",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-21-d3e057eeeffe>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mTEXT\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnumericalize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m' '\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mres\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0m_\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mm3\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m: 'RNN_Learner' object is not callable"
]
}
],
"source": [
"ss=\". the staff was not very friendly \"\n",
"s = [spacy_tok(ss)]\n",
"t=TEXT.numericalize(s)\n",
"' '.join(s[0])\n",
"res, *_ = m3(t)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment