Skip to content

Instantly share code, notes, and snippets.

@jcausey-astate
Created May 8, 2020 17:35
Show Gist options
  • Save jcausey-astate/ef7312380915d795f736f7c35aa6a1cb to your computer and use it in GitHub Desktop.
Save jcausey-astate/ef7312380915d795f736f7c35aa6a1cb to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# IMDB Sentiment Analysis using FastAI\n",
"\n",
"This example is a condensed version of the one shown at (https://docs.fast.ai/text.html#Quick-Start:-Training-an-IMDb-sentiment-model-with-ULMFiT). \n",
"\n",
"It uses the ULMFiT model (https://arxiv.org/abs/1801.06146).\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import sys, os\n",
"from pathlib import Path\n",
"import pandas as pd\n",
"from fastai.text import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"> \\[...\\] The library is structured around three steps:\n",
"> 1. Get your data preprocessed and ready to use in a minimum amount of code,\n",
"> 2. Create a language model with pretrained weights that you can fine-tune to your dataset,\n",
"> 3. Create other models such as classifiers on top of the encoder of the language model.\n",
"\n",
"In our case, we are using data from (https://www.kaggle.com/lakshmi25npathi/imdb-dataset-of-50k-movie-reviews), so we will use that version of the dataset. We assume the dataset is named \"IMDB Dataset.csv\" and saved in a directory named `data` that is in the same directory as this notebook. If that isn't the case when you are working through this on your own, just change the path below to match your own setup."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"data_filename = 'IMDB Dataset.csv'\n",
"data_dir = Path('data')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's read the dataset and print the first five lines to be sure it loaded properly. We'll use Pandas for that."
]
},
{
"cell_type": "code",
"execution_count": 3,
"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>review</th>\n",
" <th>sentiment</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>One of the other reviewers has mentioned that ...</td>\n",
" <td>positive</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>A wonderful little production. &lt;br /&gt;&lt;br /&gt;The...</td>\n",
" <td>positive</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>I thought this was a wonderful way to spend ti...</td>\n",
" <td>positive</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Basically there's a family where a little boy ...</td>\n",
" <td>negative</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Petter Mattei's \"Love in the Time of Money\" is...</td>\n",
" <td>positive</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" review sentiment\n",
"0 One of the other reviewers has mentioned that ... positive\n",
"1 A wonderful little production. <br /><br />The... positive\n",
"2 I thought this was a wonderful way to spend ti... positive\n",
"3 Basically there's a family where a little boy ... negative\n",
"4 Petter Mattei's \"Love in the Time of Money\" is... positive"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_csv(data_dir/data_filename)\n",
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Our dataset is a little different from the one in the FastAI example in a couple of ways that we need to be clear about:\n",
"\n",
"1. Their `label` column corresponds to our `sentiment` column, and it is our second column (it is their first).\n",
"2. Their `text` column corresponds to our `review` column (and this is our first column).\n",
"3. We do not have a column corresponding to thier `is_valid` column."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"> **Getting your data ready for modeling**<br>\n",
"> To get a DataBunch quickly, there are also several factory methods depending on how our data is structured. They are all detailed in text.data, here we'll use the method from_csv of the TextLMDataBunch (to get the data ready for a language model) and TextClasDataBunch (to get the data ready for a text classifier) classes.\n",
"\n",
"Notice that we need to set our `text_cols` and `label_cols` since the first column in our data is text (not label)."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"data_lm = TextLMDataBunch.from_csv(data_dir, data_filename, text_cols=0, label_cols=1)\n",
"# Classifier model data\n",
"data_clas = TextClasDataBunch.from_csv(data_dir, \n",
" data_filename, \n",
" vocab=data_lm.train_ds.vocab, \n",
" bs=32, \n",
" text_cols=0,\n",
" label_cols=1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"> This does all the necessary preprocessing behind the scene. For the classifier, we also pass the vocabulary (mapping from ids to words) that we want to use: this is to ensure that data_clas will use the same dictionary as data_lm.\n",
"\n",
"> Since this step can be a bit time-consuming, it's best to save the result with:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"data_lm.save('data_lm_export.pkl')\n",
"data_clas.save('data_clas_export.pkl')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"These files are saved in the \"data\" directory.\n",
"\n",
"You could re-load them with:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"data_lm = load_data(data_dir, 'data_lm_export.pkl')\n",
"data_clas = load_data(data_dir, 'data_clas_export.pkl', bs=16)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"> **Fine-tuning a language model**\n",
"\n",
"> We can use the `data_lm` object we created earlier to fine-tune a pretrained language model. fast.ai has an English model with an AWD-LSTM architecture available that we can download. We can create a learner object that will directly create a model, download the pretrained weights and be ready for fine-tuning."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>epoch</th>\n",
" <th>train_loss</th>\n",
" <th>valid_loss</th>\n",
" <th>accuracy</th>\n",
" <th>time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>4.241047</td>\n",
" <td>4.015764</td>\n",
" <td>0.294410</td>\n",
" <td>06:18</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learn = language_model_learner(data_lm, AWD_LSTM, drop_mult=0.5)\n",
"learn.fit_one_cycle(1, 1e-2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"> Like a computer vision model, we can then unfreeze the model and fine-tune it.\n",
"\n",
"This refers to *transfer learning*. When we unfreeze the model, the weights are allowed to change by training, so that the model begins to work better for our specific dataset."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>epoch</th>\n",
" <th>train_loss</th>\n",
" <th>valid_loss</th>\n",
" <th>accuracy</th>\n",
" <th>time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>3.889444</td>\n",
" <td>3.804476</td>\n",
" <td>0.318669</td>\n",
" <td>07:09</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learn.unfreeze()\n",
"learn.fit_one_cycle(1, 1e-3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"> To evaluate your language model, you can run the Learner.predict method and specify the number of words you want it to guess."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'This is a review about this movie i would puzzle against cagney and finance the'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"learn.predict(\"This is a review about\", n_words=10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Well, that is a start I suppose. For it to improve, you would need to train more epochs. Save the model so we could re-load it later and continue training if we want."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"learn.save_encoder('ft_enc')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Build a classifier\n",
"\n",
"> We now use the `data_clas` object we created earlier to build a classifier with our fine-tuned encoder. The learner object can be done in a single line."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"RNNLearner(data=TextClasDataBunch;\n",
"\n",
"Train: LabelList (39999 items)\n",
"x: TextList\n",
"xxbos xxmaj slayer starts in the xxmaj south xxmaj american rain forest where xxmaj captain xxmaj hawk ( xxmaj casper xxmaj van xxmaj dien ) & his men are attacked by a bunch of xxmaj vampires , they barely manage to escape with their lives . xxmaj jump forward six months later & xxmaj hawk is called to see xxmaj colonel xxmaj weaver ( xxmaj lynda xxmaj carter ) who informs him there has been other reported sightings of xxmaj vampires & that his ex - wife & her xxmaj xxunk xxmaj dr. xxmaj laurie xxmaj williams ( xxmaj jennifer o'dell ) has gone out there on an expedition to study beetles , worried she ask 's xxmaj hawk to take a squad of soldiers back to xxmaj south xxmaj america & officially provide back up to xxmaj captain xxmaj grieves ( xxmaj kevin xxmaj xxunk ) & his men while at the same time unofficially look for xxmaj laurie & not get killed by the xxmaj vampires who have decided to venture out of the caves & into the civilised xxmaj world ... \n",
" \n",
" xxmaj edited , written & directed by xxmaj kevin vanhook this is yet another poorly made xxmaj sci - xxmaj fi xxmaj channel original which just is n't very good in any respect . xxmaj the humourless script has nothing going for it as far as i could see , it 's one of those modern xxmaj vampire films which decides to pick & choose the ' traditional ' xxmaj vampire film lore rules it wants to use like these xxmaj vampires can be killed with stakes through the heart & have fangs but at the same time can freely walk around in sunlight & they do n't sleep in coffins . xxmaj the film moves along at a reasonable pace but it 's all very dull , bland & lifeless . xxmaj the story is poor & just rather stupid , the character 's are terrible , the dialogue is forgettable & there 's very little here to recommend . xxmaj slayer also tries to have some sort of ecological message as the head xxmaj vampire claims they are only starting to kill human beings because of their systematic destruction of the rain forest where they have lived in secret for centuries , unfortunately there 's no conviction there & is more like a throwaway line to fill the time than a serious statement . xxmaj there is n't enough exploitation content & is a rather unsatisfying way to spend 90 minutes of your time . xxmaj the makers do n't even do anything with the jungle setting , hell i did n't expect xxmaj predator ( 1987 ) but i hoped for a bit more than this . \n",
" \n",
" xxmaj director vanhook has made several horror films all of which i have seen have been equally poor , i 'm sorry but he does nothing here & turns in a throughly forgettable looking & feeling film . xxmaj there 's no atmosphere or tension & as for genuine scares forget about it . xxmaj the gore is restrained , there are some bitten necks & a bit of spraying blood but it 's nothing we have n't seen before or has much impact . xxmaj there 's also a huge xxmaj vampire monster creature at the end but it does n't look that impressive & it gets itself killed far too easily . \n",
" \n",
" xxmaj with a supposed budget of about $ xxunk this actually had a decent sized amount of money spent on it but it 's still a rubbish film , it 's reasonably well made but nothing special or memorable . xxmaj the acting sucks , i 'm sorry but that 's the way i saw it . \n",
" \n",
" xxmaj slayer is yet another poor , stupid & boring made - for - xxup tv xxmaj sci - xxmaj fi xxmaj channel rubbish that i simply ca n't recommend . xxmaj not to be confused with the rather fine one time xxmaj british ' xxmaj video xxmaj nasty ' gore film xxmaj the xxmaj slayer ( 1982 ) which is 100 times better than this so track that down & watch that instead .,xxbos xxmaj jackass xxmaj number xxmaj two is easily the most hilarious film of 2006 , beating the also hilarious xxmaj clerks xxup ii . xxmaj it is one of the best sequels in recent memory , beating xxmaj jackass xxmaj the xxmaj movie in every way . xxmaj now , this film may be the funniest , but it is also the most offensive , appalling , and utterly disgusting . xxmaj you will find yourself feeling sick several times throughout the film . i 'm completely serious when i say do n't eat anything before watching or during this film , because chances are that it will literally come back to haunt you . xxmaj keep the drinking to a minimum as well . xxmaj you 've been warned , because , just like the tagline says , it will make you beg for mercy . \n",
" \n",
" xxmaj jackass xxmaj number xxmaj two follows the crazy men from the hit show xxmaj jackass , xxmaj johnny xxmaj knoxville , xxmaj bam xxmaj margera , xxmaj ryan xxmaj dunn , xxmaj steve - o , xxmaj chris ' xxmaj party xxmaj boy ' xxmaj pontius , xxmaj preston xxmaj lacy , xxmaj ehren mcghehey , xxmaj dave xxmaj england , xxmaj brandon dicamillo , and xxmaj jason ' xxmaj wee xxmaj man ' xxmaj xxunk ( xxmaj chris ' xxmaj raab xxmaj himself ' xxmaj raab is absent ) as they perform the most outrageous , life - threatening , and revolting stunts imaginable . i 'm not going to tell what the stunts are , but i will warn you that any scene with an animal will be sickening or psychologically frightening , and that one cast member ( once again , not telling ) will flirt with death several times in the film . \n",
" \n",
" xxmaj what makes xxmaj jackass xxmaj number xxmaj two so entertaining is not the stunts themselves , but how the cast reacts to them and to doing them . xxmaj to put it simple , if they loved doing it and had a blast , you will too ( this goes for 99 % of the stunts ) . xxmaj all the stunts are very original , and 90 % of them are never - before - seen . xxmaj you will witness a few recycled ones , but they 're amped up . xxmaj you would n't think directing really factors into a movie like this , but it does ; xxmaj jeff xxmaj tremaine 's direction makes the movie so much funnier , because he provides guidance for the gang in their comedic timing , which is simply brilliant on his part . xxmaj he could have just sat back and slept throughout filming ( actually , you 'll see in the film that he did sleep through some filming ) , but he went out there and helped these crazy guys make the stunts as funny as he could . i give xxmaj mr. xxmaj tremaine two thumbs up for that . xxmaj another great thing about xxmaj jackass is its bonanza of celebrity cameos , and this time they include xxup bmx legend xxmaj mat xxmaj hoffman , skateboard god xxmaj tony xxmaj hawk , director / actor xxmaj jay xxmaj chandrasekhar ( xxmaj super xxmaj troopers & xxmaj beerfest ) , actor xxmaj luke xxmaj wilson , xxmaj miami xxmaj dolphins star xxmaj jason xxmaj taylor , and director / actor xxmaj mike xxmaj judge ( xxmaj office xxmaj space ) . xxmaj the scenes with xxmaj hoffman , xxmaj taylor , and xxmaj chandrasekhar are among the funniest in the film , as it 's even funnier to see these men as a part of the film . \n",
" \n",
" xxmaj jackass xxmaj number xxmaj two is one of the most politically incorrect , morally degrading , and just plain wrong movies of all time , if not the most . xxmaj despite this , it is so original and so hilarious that you wo n't care about that . xxmaj you 'll be gasping for air , laughing so hard you 'll be crying , and jumping out of your seat laughing throughout the entire film . xxmaj due to the explicit and potentially disturbing graphic content of this film , no one under 18 should watch this film . xxmaj you 've been warned . i hope you enjoy xxmaj jackass xxmaj number xxmaj two as much as i did . \n",
" \n",
" 10 / 10 --spy,xxbos a heist film with xxmaj jean xxmaj reno , xxmaj matt xxmaj damon and xxmaj laurence xxmaj fishburne ... sounds great on paper ? i suspect it must have done when someone green lighted the production of this movie but the end product is terrible ! \n",
" \n",
" xxmaj the story is dull , the action boring , and , for a film that is only 88 minutes it seems to just drag on . i could feel my life slipping away and was sure there was something better i should have been doing ... any paint to watch dry somewhere perhaps ? \n",
" \n",
" xxmaj sigh . i 'm a huge fan of xxmaj jean xxmaj reno , but what on earth was he thinking when he signed up to this ? xxmaj there are so many other great action movies around ... go watch one of those and let this movie be best forgotten .,xxbos xxmaj this is a weak film with a troubled history of cuts and re - naming . xxmaj it does n't work at all . xxmaj firstly the dramaturgy is all wrong . xxmaj it 's very slow moving at first and then hastily and unsatisfactorily moves to an end . xxmaj but there is also ( and that may have to do with the cuts ) an uneasy moving between genres . xxmaj it starts off with being a thriller to be taken at face value and then degenerates into a farce rather than satire . the ending may be funny but it 's also so blunt that i almost felt it insulted my intelligence ( what little there is ) . xxmaj so the film tries to be everything but does not really succeed on any level at all . xxmaj you can also see that in the very unsteady character development . xxmaj you almost get the impression xxmaj connery plays three roles rather than one .,xxbos xxmaj saw this film when it was an entry in xxmaj santa xxmaj fe xxmaj film xxmaj festival . xxmaj heavy film ! xxmaj depiction of a completely dysfunctional family taken to another level of the extreme , might have left me depressed to the extreme , had it not been for very funny sight gags and dialogue along the way which lightened the film 's overall tone . xxmaj the relatively \" uplifting \" ending gave hope for those affected by the initial tragedy . xxmaj still , i did not walk out of the theatre ready to go to a fun party . xxmaj the film stayed with me for several days . \n",
" \n",
" xxmaj brought back memories of \" xxmaj ordinary xxmaj people \" , but with humor mixed in with the tragedy . i thought the acting was excellent , especially by xxmaj sigourney xxmaj weaver and xxmaj emile xxmaj hirsh . xxmaj how each character dealt with the tragedy was at times sad , self - defeating , but also at times hilarious . xxmaj clever dialogue , and situations .\n",
"y: CategoryList\n",
"negative,positive,negative,negative,positive\n",
"Path: data;\n",
"\n",
"Valid: LabelList (10001 items)\n",
"x: TextList\n",
"xxbos xxmaj it 's amazing what you can do with little money . xxup dead xxup silent being a low budget movie delivers its promises . \n",
" \n",
" xxmaj too bad we do n't see xxmaj rob xxmaj lowe more often on the silver screen . xxmaj lowe is at its best in this riveting thriller . xxmaj no wonder he went from xxup dead xxup silent straight to the xxup tv mega hit xxmaj the xxmaj west xxmaj wing . \n",
" \n",
" xxup dead xxup silent 8 out of 10 \n",
" \n",
" xxmaj xxunk xxmaj toronto .,xxbos xxmaj this is the only film i 've seen that is made by xxmaj uwe xxmaj boll , i knew that he is probably the worst director ever who always makes films based on video games also that \" xxmaj house of the xxmaj dead \" is one of imdb bottom 100 . xxmaj but i still wanted to watch it because i 'm a huge fan of the game and i wanted to see what doe 's the film have that makes it so bad . xxmaj after watching it i do agree that it is crap , the movie had no story . xxmaj in the first 15 - 20 minutes there was nothing but topless teenage girls with no brains running about ( for a moment there i was wondering are the zombies brain - dead ? or the girls are ? ) then at night time the zombies popped out of nowhere & started attacking people later a woman started shooting them i mean it takes you one place then the other every 5 minutes . xxmaj is it supposed to be a comedy ? , or horror ? or both ? xxmaj before i knew it i fell asleep at the second half & woke up during the end credits so i did not manage to watch all of it , which is a good thing ! xxmaj the film is a true insult to the classic game , xxmaj uwe xxmaj boll please do not make any more films . xxmaj thank you !,xxbos xxmaj the first in the series was brilliant , easily one of the best xxmaj horror films of all time . xxmaj this is the crappiest . xxmaj when i sat down to watch this , i was actually thinking that how bad the fourth and fifth ones were , this would have to be good after the previous terrible ones . xxmaj boy was i wrong . xxmaj incredibly wrong . \n",
" \n",
" xxmaj when i watched the first ten minutes of it , i was actually really tempted to turn it off , but i thought no , maybe it 'll improve . xxmaj it did n't . \n",
" \n",
" xxmaj not only is this just a dire film by itself , it did n't need another sequel , because the last two ( fourth and fifth ) had already been terrible enough ! xxmaj also , how many times can you bring xxmaj freddy back ! ? xxmaj the acting in it was xxup terrible , the story - line was predictable and crap and it also had flaws in it as well . xxmaj the way they made xxmaj springwood was just totally wrong . xxmaj pays no respect to the first one at - all . xxmaj to add to this , the whole thing seemed really over - the - top . \n",
" \n",
" xxmaj some people are saying that this film was \" funny \" . xxmaj this film is not \" funny \" at all . xxmaj since when is xxmaj freddy xxmaj krueger supposed to be \" funny \" ? i would call it funnily crap . xxmaj this film is supposed to be a xxmaj horror film , not a comedy . xxmaj if xxmaj freddy had a daughter , would n't that information have surfaced like in the first one ! ? xxmaj the ending was also just plain stupid and cheesy , exactly like the rest of it . xxmaj this one completely destroys the essence and uniqueness of the first one . xxmaj just shows itself up . \n",
" \n",
" xxmaj such a shame that xxmaj wes xxmaj craven created something so good in the beginning , yet it has to be dragged down because of this trash that belongs in the bin . xxmaj they should n't have even bothered making this film . xxmaj nor any of the other sequels , except the third one . xxmaj the third one 's the only decent one out of all the sequels . \n",
" \n",
" xxmaj if this was a xxup dvd by itself and not part of the xxmaj nightmare xxmaj on xxmaj elm xxmaj street xxup dvd set that i got , i would have chucked it out when i got it . \n",
" \n",
" xxmaj summary : a pathetic and poor attempt at a sequel . \n",
" \n",
" - a complete xxup mockery of the first film \n",
" \n",
" xxmaj so please , do n't waste your time on this worthless junk .,xxbos i am from xxmaj sweden and i have just seen this movie and the thing is that i thought it was okay . i have seen many bad comments about it but you must remember that a lot of people that watch this two parts miniseries are located all over the world and not just in xxup usa . xxmaj also remember that not everyone has ever heard of the film made in the 60 : s and maybe not in the xxunk ) . xxmaj and even more ... that it can be hard to find the original movie and if so there always be people around that does n't like black / white films . xxmaj this one feels fresh and in color and will find its public . xxmaj its 12 years old now but i just saw it for the first time . i will try to find the first one if i can to compare them but i have n't seen it anywhere in xxmaj sweden . xxmaj ofcorse there is internet but not for anyone in the world . xxmaj the thing here is that this is mostly part of an xxmaj american crime - history and was big in the 50 - 60 : s in just xxup usa but in rest of the world it just past by i guess . xxmaj well it was told about for some time but 40 years later it will fade away in for example xxmaj europa cause time goes by . xxmaj we had our own problems and crimes so if someone will do a remake of the film and put it back in some light again its not a bad idea at all . a new generation can take part of this horrible story and even the film about xxmaj capote that was released just a few years ago witch was a pretty good film too i think . xxmaj it will boost interest to the events that took place some 50 years ago and maybe stop it to fall in sleep . xxmaj it started me up and now i am looking for the xxmaj robert xxmaj blake - version so it was n't that bad ... huh ? xxmaj this are my opinions . xxmaj some people will of course disagree but hey ... its okay . xxmaj sometimes there will be okay with remakes on old films . xxmaj its not every time the old ones are that good . xxmaj the film - making techniques has developed a lot and scenes can be made more realistic if they want today . xxmaj its always a question of money of course . xxmaj there has been so many movies that were made in the \" good old days \" but there were also money missing , bad directors etc , and they remakes them today ( 50 years later ) and suddenly they are okay to watch . xxmaj my friend got this box of old classic horror - movies and s / f and i ca nt say i was impressed of the so called good old days . xxmaj most of them you cold put in the trashcan directly . xxmaj they were so bad that we just sat there like zombies ... could not move ... like brain - dead . i ca nt recommend them to anyone . xxmaj some of them i have seen remakes of and i remember liking them ... but not the originals . xxmaj they were just painful awful . xxmaj this is like the old story of who was the best xxmaj bond ... xxmaj moore or xxmaj connery ... i think if you see xxmaj roger xxmaj moore first you maybe find him the one to trust or like ... xxmaj thanks for me and i am sorry for my xxmaj english , that s not so good . / xxmaj lars from xxmaj sweden,xxbos xxmaj was flipping around the xxup tv and xxup hbo was showing a double whammy of unbelievably horrendous medical conditions , so i turned to my twin sister and said , \" xxmaj hey this looks like fun , \" - truly i love documentaries - so we started watching it . xxmaj at first i thought xxmaj jonni xxmaj kennedy was a young man , but then it was explained that due to his condition , he never went through puberty , thus the high voice and smaller body . xxmaj he was on a crusade to raise money for his cause . xxmaj he had the most wonderful sense of humor combined with a beautiful sense of spirituality ... i cried , watched some more , laughed , got up to get another xxmaj kleenex , then cried some more . xxmaj once xxmaj jonni xxmaj kennedy 's \" time was up \" he flew to heaven to be with the angels . xxmaj he was more than ready ; he had learned his lessons from this life and he was free . i highly recommend this . xxmaj if you do not fall in love with this guy , you have no heart .\n",
"y: CategoryList\n",
"positive,negative,negative,positive,positive\n",
"Path: data;\n",
"\n",
"Test: None, model=SequentialRNN(\n",
" (0): MultiBatchEncoder(\n",
" (module): AWD_LSTM(\n",
" (encoder): Embedding(59576, 400, padding_idx=1)\n",
" (encoder_dp): EmbeddingDropout(\n",
" (emb): Embedding(59576, 400, padding_idx=1)\n",
" )\n",
" (rnns): ModuleList(\n",
" (0): WeightDropout(\n",
" (module): LSTM(400, 1152, batch_first=True)\n",
" )\n",
" (1): WeightDropout(\n",
" (module): LSTM(1152, 1152, batch_first=True)\n",
" )\n",
" (2): WeightDropout(\n",
" (module): LSTM(1152, 400, batch_first=True)\n",
" )\n",
" )\n",
" (input_dp): RNNDropout()\n",
" (hidden_dps): ModuleList(\n",
" (0): RNNDropout()\n",
" (1): RNNDropout()\n",
" (2): RNNDropout()\n",
" )\n",
" )\n",
" )\n",
" (1): PoolingLinearClassifier(\n",
" (layers): Sequential(\n",
" (0): BatchNorm1d(1200, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (1): Dropout(p=0.2, inplace=False)\n",
" (2): Linear(in_features=1200, out_features=50, bias=True)\n",
" (3): ReLU(inplace=True)\n",
" (4): BatchNorm1d(50, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (5): Dropout(p=0.1, inplace=False)\n",
" (6): Linear(in_features=50, out_features=2, bias=True)\n",
" )\n",
" )\n",
"), opt_func=functools.partial(<class 'torch.optim.adam.Adam'>, betas=(0.9, 0.99)), loss_func=FlattenedLoss of CrossEntropyLoss(), metrics=[<function accuracy at 0x7f89f743e440>], true_wd=True, bn_wd=True, wd=0.01, train_bn=True, path=PosixPath('data'), model_dir='models', callback_fns=[functools.partial(<class 'fastai.basic_train.Recorder'>, add_time=True, silent=False)], callbacks=[RNNTrainer\n",
"learn: ...\n",
"alpha: 2.0\n",
"beta: 1.0], layer_groups=[Sequential(\n",
" (0): Embedding(59576, 400, padding_idx=1)\n",
" (1): EmbeddingDropout(\n",
" (emb): Embedding(59576, 400, padding_idx=1)\n",
" )\n",
"), Sequential(\n",
" (0): WeightDropout(\n",
" (module): LSTM(400, 1152, batch_first=True)\n",
" )\n",
" (1): RNNDropout()\n",
"), Sequential(\n",
" (0): WeightDropout(\n",
" (module): LSTM(1152, 1152, batch_first=True)\n",
" )\n",
" (1): RNNDropout()\n",
"), Sequential(\n",
" (0): WeightDropout(\n",
" (module): LSTM(1152, 400, batch_first=True)\n",
" )\n",
" (1): RNNDropout()\n",
"), Sequential(\n",
" (0): PoolingLinearClassifier(\n",
" (layers): Sequential(\n",
" (0): BatchNorm1d(1200, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (1): Dropout(p=0.2, inplace=False)\n",
" (2): Linear(in_features=1200, out_features=50, bias=True)\n",
" (3): ReLU(inplace=True)\n",
" (4): BatchNorm1d(50, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
" (5): Dropout(p=0.1, inplace=False)\n",
" (6): Linear(in_features=50, out_features=2, bias=True)\n",
" )\n",
" )\n",
")], add_time=True, silent=False)"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"learn = text_classifier_learner(data_clas, AWD_LSTM, drop_mult=0.5)\n",
"learn.load_encoder('ft_enc')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th>text</th>\n",
" <th>target</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>xxbos xxmaj match 1 : xxmaj tag xxmaj team xxmaj table xxmaj match xxmaj bubba xxmaj ray and xxmaj spike xxmaj dudley vs xxmaj eddie xxmaj guerrero and xxmaj chris xxmaj benoit xxmaj bubba xxmaj ray and xxmaj spike xxmaj dudley started things off with a xxmaj tag xxmaj team xxmaj table xxmaj match against xxmaj eddie xxmaj guerrero and xxmaj chris xxmaj benoit . xxmaj according to the rules</td>\n",
" <td>positive</td>\n",
" </tr>\n",
" <tr>\n",
" <td>xxbos 1904 . xxmaj the xxmaj north xxmaj african nation of xxmaj morocco is hanging onto a tenuous xxmaj independence , as the various xxmaj european powers - xxmaj france , xxmaj germany , xxmaj britain , xxmaj russia , xxmaj spain , and now the xxmaj united xxmaj states - are vying for influence in the region . xxmaj the xxmaj sultan ( xxmaj marc xxmaj zuber ) is</td>\n",
" <td>positive</td>\n",
" </tr>\n",
" <tr>\n",
" <td>xxbos i was xxunk most of the xxunk not born in the 80 's . i was born on may 14th 1994 . xxmaj despite this , my life was very much in the style of the 80 's . xxmaj when other kids had xxunk , i was playing xxmaj zelda on my xxup nes etc . xxmaj now , this movie holds a special place in my heart</td>\n",
" <td>positive</td>\n",
" </tr>\n",
" <tr>\n",
" <td>xxbos xxmaj no , this is n't a sequel to the fabulous xxup ova series , but rather a remake of the events that occurred after the death of xxmaj xxunk ( and the disappearance of xxmaj woodchuck ) . xxmaj it is also more accurate to the novels that inspired this wonderful series , which is why characters ( namely xxmaj orson and xxmaj shiris ) are xxunk ,</td>\n",
" <td>positive</td>\n",
" </tr>\n",
" <tr>\n",
" <td>xxbos xxmaj the 1973 musical version of xxup lost xxup horizon is the most wonderful endearing and campy musical films of xxup all xxup time . xxmaj the 1973 musical remake of the xxmaj james xxmaj hilton novel about mythical xxup shangri - xxup la ! is a real special gem . xxmaj music by xxup burt xxup bacharach and lyrics by xxup hal xxmaj david . a strange mixture</td>\n",
" <td>positive</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"data_clas.show_batch()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can start fitting..."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>epoch</th>\n",
" <th>train_loss</th>\n",
" <th>valid_loss</th>\n",
" <th>accuracy</th>\n",
" <th>time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>0.334770</td>\n",
" <td>0.264535</td>\n",
" <td>0.896810</td>\n",
" <td>04:04</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learn.fit_one_cycle(1, 1e-2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then we will unfreeze the classifier layers and fine-tune it."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>epoch</th>\n",
" <th>train_loss</th>\n",
" <th>valid_loss</th>\n",
" <th>accuracy</th>\n",
" <th>time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>0.256341</td>\n",
" <td>0.198529</td>\n",
" <td>0.925008</td>\n",
" <td>04:34</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learn.freeze_to(-2)\n",
"learn.fit_one_cycle(1, slice(5e-3/2., 5e-3))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And unfreeze completely to train all layers"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>epoch</th>\n",
" <th>train_loss</th>\n",
" <th>valid_loss</th>\n",
" <th>accuracy</th>\n",
" <th>time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>0.214457</td>\n",
" <td>0.175501</td>\n",
" <td>0.935806</td>\n",
" <td>08:41</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learn.unfreeze()\n",
"learn.fit_one_cycle(1, slice(2e-3/100, 2e-3))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can predict the **sentiment** from the *text* by using the `predict()` method. This is what we've been working toward! Let's try:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(Category tensor(1), tensor(1), tensor([0.0033, 0.9967]))"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"learn.predict(\"This was a great movie!\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(Category tensor(0), tensor(0), tensor([0.9983, 0.0017]))"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"learn.predict(\"I've never seen a bigger waste of my time.\")"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(Category tensor(1), tensor(1), tensor([0.0748, 0.9252]))"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"learn.predict(\"This was a fantastic end to the trilogy.\")"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(Category tensor(0), tensor(0), tensor([0.7387, 0.2613]))"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"learn.predict('Just when we thought they couldn\\'t possibly make a worse TV movie than Sharknado? Syfy says, \"Hold my beer!\"')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.7.5 64-bit ('.venv': venv)",
"language": "python",
"name": "python37564bitvenvvenv3b4582745950484dbc0fc388368b0403"
},
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment