Let's start with a quick end-to-end example of training a model. We'll train a sentiment classifier on a sample of the popular IMDb data, showing 4 steps:
from fastai.text import *
Contrary to images in Computer Vision, text can't directly be transformed into numbers to be fed into a model. The first thing we need to do is to preprocess our data so that we change the raw texts to lists of words, or tokens (a step that is called tokenization) then transform these tokens into numbers (a step that is called numericalization). These numbers are then passed to embedding layers that will convert them in arrays of floats before passing them through a model.
Steps:
To show examples, we have provided a small sample of the IMDB dataset which contains 1,000 reviews of movies with labels (positive or negative).
path = untar_data(URLs.IMDB_SAMPLE)
df = pd.read_csv(path/'texts.csv')
df.head()
| label | text | is_valid | |
|---|---|---|---|
| 0 | negative | Un-bleeping-believable! Meg Ryan doesn't even ... | False |
| 1 | positive | This is a extremely well-made film. The acting... | False |
| 2 | negative | Every once in a long while a movie will come a... | False |
| 3 | positive | Name just says it all. I watched this movie wi... | False |
| 4 | negative | This movie succeeds at being one of the most u... | False |
databunch object to use for a language model¶%%time
# throws `BrokenProcessPool` Error sometimes. Keep trying `till it works!
count = 0
error = True
while error:
try:
# The following line throws `AttributeError: backwards` on the learning step, below
# data_lm = TextDataBunch.from_csv(path, 'texts.csv')
# This Fastai Forum post shows the solution:
# https://forums.fast.ai/t/backwards-attributes-not-found-in-nlp-text-learner/51340?u=jcatanza
# We implement the solution on the following line:
data_lm = TextLMDataBunch.from_csv(path, 'texts.csv')
error = False
print(f'failure count is {count}\n')
except: # catch *all* exceptions
# accumulate failure count
count = count + 1
print(f'failure count is {count}')
failure count is 0 Wall time: 13 s
databunch object for use in a classifier model¶%%time
# throws `BrokenProcessPool` Error sometimes. Keep trying `till it works!
count = 0
error = True
while error:
try:
# Create the databunch for the classifier model
data_clas = TextClasDataBunch.from_csv(path, 'texts.csv', vocab=data_lm.train_ds.vocab, bs=32)
error = False
print(f'failure count is {count}\n')
except: # catch *all* exceptions
# accumulate failure count
count = count + 1
print(f'failure count is {count}')
failure count is 1 Wall time: 22.7 s
databunch objects for later use¶data_lm.save('data_lm_export.pkl')
data_clas.save('data_clas_export.pkl')
#bs=192
#bs=48
bs=32
data_lm = load_data(path, 'data_lm_export.pkl', bs=bs)
data_clas = load_data(path, 'data_clas_export.pkl', bs=bs)
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.
# torch.cuda.set_device(1)
torch.cuda.set_device(0)
wikitext-103¶learn = language_model_learner(data_lm, AWD_LSTM, drop_mult=0.5)
By default this step unfreezes and trains the weights for the last layer. Training updates the weights to values more applicable to the language of IMDb reviews.
learn.fit_one_cycle(1, 1e-2)
| epoch | train_loss | valid_loss | accuracy | time |
|---|---|---|---|---|
| 0 | 4.324914 | 3.921263 | 0.279464 | 00:09 |
language_model_learner??
learn.load_pretrained??
convert_weights??
You can use Visual Studio Code (vscode - open source editor that comes with recent versions of Anaconda, or can be installed separately), or most editors and IDEs, to browse code. vscode things to know:
Like a computer vision model, we can then unfreeze the model and fine-tune it. In this step we are allowing the model to update all the weights with values more suitable to the language of IMDb reviews. But we are mindful that the pretrained weights from wikitext-103 are likely already near their optimal values. For this we train the weights in the "earlier" layers with a much lower learning rate.
learn.unfreeze()
learn.fit_one_cycle(3, slice(1e-4,1e-2))
| epoch | train_loss | valid_loss | accuracy | time |
|---|---|---|---|---|
| 0 | 3.985726 | 3.922798 | 0.282494 | 00:12 |
| 1 | 3.683273 | 3.900530 | 0.281920 | 00:12 |
| 2 | 3.131985 | 3.939293 | 0.280150 | 00:12 |
To evaluate your language model, you can run the Learner.predict method and specify the number of words you want it to guess.
learn.predict("This is a review about", n_words=10)
'This is a review about India and is about bonanza ANY DEFEATED'
learn.predict("In the hierarchy of horror movies this has to be near the top.", n_words=10)
'In the hierarchy of horror movies this has to be near the top. This is much better , but there are more'
Sometimes the generated text doesn't make much sense because we have a tiny vocabulary and didn't train much. But note that the model respects basic grammar, which comes from the pretrained model.
Finally we save the encoder to be able to use it for classification in the next section.
learn.save('mini_imdb_language_model')
learn.save_encoder('mini_imdb_language_model_encoder')
We use mixed precision (.to_fp16())for greater speed, smaller memory footprint, and a regularizing effect.
learn = text_classifier_learner(data_clas, AWD_LSTM, drop_mult=0.5).to_fp16()
learn.load_encoder('mini_imdb_language_model_encoder')
RNNLearner(data=TextClasDataBunch;
Train: LabelList (799 items)
x: TextList
xxbos xxmaj in theory , films should be a form of entertainment . xxmaj while this xxunk documentaries and other experimental forms of film - making ; most movies , specially genre films , must not only tell it 's story or message , they must entertain their target audience in some way . xxmaj all this just to say that in my opinion a bad movie is not a movie with low production values or low - budget , a bad movie is one that is boring .
" xxmaj hellborn " or " xxmaj asylum of the xxmaj damned " as is known in the xxup u.s. , is a bad movie simply because it is just not involving , and xxunk boring and tiresome . xxmaj while it has a very good premise , it is just poorly developed and the mediocre acting does n't make things better . xxmaj on another hands the film probably could had been a fine or even classic b - movie , but here it is just a bad attempt at film - making .
xxmaj director xxmaj philip xxup j. xxmaj jones tells the tale of xxmaj james xxmaj bishop ( xxmaj matt xxmaj stasi ) , a young xxunk resident , who just got his dream job at xxmaj st. xxmaj andrew xxmaj mental xxmaj hospital ; but the old asylum seems to hide a secret . xxmaj after the mysterious death of some patients and the constant rumors of satanic xxunk , xxmaj james decides to find out what is going on ; only to find the xxunk of his boss , xxmaj dr. xxunk ( xxmaj bruce xxmaj payne ) , who believes that xxmaj bishop is going as insane as his patients .
xxmaj while the premise is quite interesting , the execution of the film leaves a lot to be desired . xxmaj in an attempt of making a supernatural psychological thriller , xxmaj jones goes for the easy way out and makes a movie filled with every cliché of the genre . xxmaj of course , there are lots of great movies that are also filled with clichés ; but in " xxmaj hellborn " every single one is wasted and turned into a cheap jump scare to keep things moving , resulting in a boring and predictable storyline .
xxmaj the acting is quite mediocre for the most part , with one big exception : xxmaj bruce xxmaj payne gives a top - notch performance that makes the movie look xxunk of such good acting . xxmaj matt xxmaj stasi is very weak as the lead character and the rest of the cast make forgettable performances .
xxmaj despite all this flaws , one thing has to be written about " xxmaj hellborn " ; it has a visual look very good for the budget and very similar to modern day big - budget xxmaj xxunk " horror " productions . xxmaj also , the make - up and prosthetics are done very nicely and the designs for the main antagonist are quite good . xxmaj sadly , the rest of the xxmaj special xxmaj effects are awful and outdated , making a huge contrast with the make - up & prosthetics .
" xxmaj hellborn " is a movie with a few good things xxunk by its serious flaws with terrible results . xxmaj hardcore horror or b - movie fans may be interested by its premise but it is a boring and tiresome experience . 3 / 10,xxbos xxmaj in order to hold the public 's attention for three hours , we were treated not so much to a family 's romp through four generations and xxunk years of xxmaj hungarian history , as to sexual xxunk with a sister , a sister - in - law and other xxunk . xxmaj oh yes , there was also a totally gratuitous rape . xxmaj having said all this , the first story of the relationship among the children of the patriarch was fresh and sensual - thanks to xxmaj jennifer xxmaj xxunk .,xxbos xxmaj in the many films i have seen xxmaj warren xxmaj oates , i have come to a definite conclusion , here is one talented individual . i first saw xxmaj mr. xxmaj oates back in the 1960 's television series called xxmaj xxunk xxmaj burke . xxmaj from then on , i followed his career closely and felt he was destined for great roles . xxmaj that happened in 1974 , when xxmaj sam xxmaj peckinpah gave him top billing in a film called ' xxmaj bring xxmaj me the xxmaj head of xxmaj xxunk xxmaj garcia . ' xxmaj of course , his biggest claim to fame was his magnificent role in ' xxmaj the xxmaj wild xxmaj bunch ' . i have always thought he was quite able to bring any character a certain magic , that is until i saw him in this flop . xxmaj the movie is called " xxmaj chandler " , a tribute to the iron fisted detectives of the 1950 's created by xxmaj raymond xxmaj chandler . xxmaj because , the synopsis said it was about a hard nose xxmaj private xxmaj eye , i was immediately interested . xxmaj however , i sat patiently through the entire film and found it to be a dull , xxunk - interesting , slow pace , twisted , confusing saga which if it had a theme or plot must have been left on some dark back room self . xxmaj xxunk and with some of xxmaj hollywood 's best supporting stars , such as xxmaj alex xxmaj xxunk , xxmaj mitch xxmaj ryan , xxmaj gordon xxmaj xxunk , xxmaj charles xxunk , xxmaj richard xxmaj xxunk and xxmaj scatman xxmaj crothers , this movie had enough power to reach xxmaj xxunk five , however , it xxunk on the xxunk and went no where . xxmaj as a result , one of my favorite actor 's got stuck in a poorly made vehicle which never got off the ground . * *,xxbos xxmaj halfway through xxmaj xxunk xxmaj xxunk 's " xxmaj evening , " a woman on her deathbed asks a figure appearing in her hallucination : " xxmaj can you tell me where my life went ? " xxmaj the line could be embarrassingly theatrical , but the woman speaking it is xxmaj vanessa xxmaj redgrave , xxunk it with utter simplicity , and the question tears your heart out .
xxmaj time and again , the film based on xxmaj susan xxmaj xxunk 's novel skirts xxunk and xxunk , it holds attention , offers admirable performances , and xxunk emotional involvement as few recent movies have . xxmaj with only six months of the year gone , there are now two memorable , meaningful , worthwhile films in theaters , the other , of course , being xxmaj xxunk xxmaj xxunk 's " xxmaj away from xxmaj her . " xxmaj hollywood might have turned " xxmaj evening " into a xxunk celebrity vehicle with its two xxunk of real - life xxunk and daughters - xxmaj vanessa xxmaj redgrave and xxmaj natasha xxmaj xxunk , and xxmaj meryl xxmaj streep and xxmaj xxunk xxmaj xxunk . xxmaj xxunk is xxmaj redgrave 's daughter in the film ( with a sister played by xxmaj tony xxmaj xxunk ) , and xxmaj xxunk plays xxmaj streep 's younger self , while xxmaj redgrave 's youthful incarnation is xxmaj claire xxmaj danes .
xxmaj add xxmaj glenn xxmaj close , xxmaj eileen xxmaj atkins , xxmaj hugh xxmaj dancy , xxmaj patrick xxmaj wilson , and a large cast - yes , it could have turned into a multiple star platform . xxmaj instead , xxmaj xxunk - the brilliant xxmaj hungarian cinematographer of " xxmaj xxunk , " and director of " xxmaj xxunk " - created a subtle ensemble work with a " xxmaj xxunk feel , " the story taking place in a high - society xxmaj newport environment , in the days leading up to a wedding that is xxunk with trouble .
xxmaj missed connections , wrong choices , and xxunk xxunk with social and family xxunk present quite a soap opera , but the quality of the writing , xxmaj xxunk 's direction , and xxunk acting raise " xxmaj evening " way above that level , into the the xxunk air of xxmaj english , xxmaj french ( and a few xxmaj american ) family xxunk from a century before its contemporary setting .
xxmaj complex relationships between xxunk and daughters , between friends and lovers , with the addition of a difficult xxunk all come across clearly , xxunk , xxunk . xxmaj individual tunes are woven into a xxunk .
xxmaj and yet , with the all the xxunk emphasis on ensemble and xxunk performances , the stars of " xxmaj evening " still shine through , xxmaj redgrave , xxmaj xxunk , xxmaj xxunk ( an exciting new discovery , looking vaguely like her mother , but a very different actress ) , xxmaj danes carrying most of the load - until xxmaj streep shows up in the final moments and , of course , steals the show . xxmaj dancy and xxmaj wilson are well worth the price of xxunk too .
xxmaj as with " xxmaj away from xxmaj her , " " xxmaj evening " stays with you at length , xxunk a re - thinking its story and characters , and re - experiencing the emotions it raises . xxmaj at two hours , the film runs a bit long , but the way it stays with you xxunk is welcome among the many movies that go cold long before your popcorn .,xxbos i think the biggest failing something can have is to be boring . xxmaj bad is actually better than boring . xxmaj this thing has no breath . xxmaj it does have the interesting fact of taking place in xxmaj cambodia . xxmaj how many xxmaj american made films of the 30 's take place in xxmaj cambodia . xxmaj nevertheless , the conflict there is a little hard to figure out . xxmaj even the xxunk movements are a little confusing . xxmaj what drags it to a resounding xxunk is the love story . xxmaj why those two guys are so totally transfixed on the xxunk blonde i do n't know . i thought he should continue to use his xxmaj zombies ( such as they are ) and forget all about her . xxmaj the movie just plods along . xxmaj the perfect xxunk is where one of the principle characters follows a xxmaj xxunk priest through the water to get to the secret place where the xxunk ( or whatever ) that explain how to turn people into zombies is kept . i thought they would never get there . xxmaj one guy takes two steps . xxmaj he stops . xxmaj he looks around . xxmaj the other guy hides behind some columns . xxmaj he takes two steps . xxmaj he stops . xxmaj he looks around . xxmaj the other guy hides behind some xxunk . xxmaj this is the movie in a nutshell . xxmaj then there is the bad acting and insipid dialogue . i actually have a lot of patience when it comes to b movies . xxmaj this one is insufferable . xxmaj by the way , a more xxunk title would be xxmaj revolt of the xxmaj hypnotized .
y: CategoryList
negative,negative,negative,positive,negative
Path: C:\Users\cross-entropy\.fastai\data\imdb_sample;
Valid: LabelList (201 items)
x: TextList
xxbos xxmaj it 's true that you always remember what you were doing at a point when disaster or tragedy strikes . xxmaj and none more so that xxmaj september 11 , 2001 , a date which changed the entire global landscape in its fight against terrorism .
xxmaj no , this documentary did n't set out to be dwelling on the events leading to 9 / 11 . xxmaj rather , the filmmakers , brothers xxmaj xxunk and xxmaj jules xxmaj xxunk , set out to do a documentary on the trials and xxunk of a rookie xxmaj new xxmaj york firefighter . xxmaj they had gone to the academy and done some shoots of training , and had xxunk their " xxunk " ( xxunk firefighter ) to join them in an xxup xxunk xxunk , home to xxmaj ladder 1 and xxmaj engine 7 . xxmaj but their production was to develop and contain at that time , believed to be the only shot of the first plane slamming into the xxmaj world xxmaj trace xxmaj center .
i was traveling back with a friend on the train from a night of xxup xxunk gaming , and received a call at about xxunk local time from my xxmaj dad , who informed me of the above . xxmaj few minutes later , he told me there was another , and that the xxup wtc was under attack . xxmaj by the time i arrived home , the upper floors of the twin xxunk were xxunk and in smoke , and to my horror , they collapsed , under an hour .
xxmaj the filmmakers had two cameras running that day , one who had followed a team out on a routine call , and which immediately xxunk to the xxup wtc upon hearing and seeing the plane crash into it . xxmaj we follow what is possible the only filmed sequence of events in the xxunk of xxup xxunk where the first xxunk of xxunk , xxunk , and police had to make sense of what happened , and to quickly develop a plan of action . xxmaj the other camera , held by the other brother , was making his way to xxup wtc to look for his xxunk , and along the journey , captured the many expressions of xxmaj new xxmaj yorkers , as well as the sense of chaos in and around xxmaj xxunk .
xxmaj xxunk throughout the documentary are numerous interviews with the men from xxmaj ladder 1 and xxmaj engine 7 , which miraculously , did not suffer any casualty . xxmaj but being survivors also brought about its own set of psychological turmoil , as they struggle to come to terms with the event . xxmaj through the events that unfold , we learn of the strong xxunk amongst these men who risk live and xxunk each day on their jobs , to save lives .
xxmaj we began with what the documentary was supposed to be , before events of the day totally xxunk in and became the focus , right up to the rescue phase where hopes of finding survivors under the rubble were kept alive by the men who work round the clock in making sense of the collapsed steel xxunk . xxmaj it 's not a film that is xxunk , and what you see here can not be recreated in any other documentary ( and xxunk , not sound stages for xxmaj hollywood xxunk ) . xxmaj it 's as close as you can get to that day , witnessing the event up close , from safety .
xxmaj code 1 xxup dvd contains a separate extra hour of 4 sets of interviews with the men of xxmaj ladder 1 and xxmaj engine 7 .,xxbos xxmaj sometimes you need to see a bad movie just to appreciate the good ones . xxmaj well , that 's my opinion anyway . xxmaj this one will always be in the bad movie category , simply because all but xxmaj shu xxmaj qi 's performance was terrible .
xxmaj martial xxmaj angel tells of xxmaj cat ( xxmaj shu xxmaj qi ) , a professional thief turned straight after leaving her lover , xxmaj chi xxmaj lam ( xxmaj xxunk xxmaj xxunk ) , two years before . xxmaj but her past returns to haunt her as xxmaj chi xxmaj lam is kidnapped for the ransom of security software belonging to the company xxmaj cat works for . xxmaj in order to rescue him , she calls on her old friends from her orphanage days , six other xxunk women , to save the day ...
i may have told the synopsis xxunk , but this is a cheesy story . xxmaj in fact , the whole script and direction lacked any quality at all . xxmaj much of the dialogue was meaningless and coupled with a plot that was as thin as rice - paper in water . xxmaj if i could sum it up , take a bad xxmaj jackie xxmaj chan movie , remove the comedy , remove the choreography , throw away the budget , and you have xxmaj martial xxmaj angels : a formulaic piece of work with no imagination at all .
xxmaj mind you , i do have to give credit where credit 's due , and xxmaj shu xxmaj qi was probably the only person to emerge unscathed from the terrible action , as it was her performance that xxunk through . xxmaj okay , you ca n't say she was excellent - after all she had absolutely nothing to work with - but she did manage to dig some character out from her role . xxmaj other than that , only xxmaj sandra xxmaj xxunk and xxmaj kelly xxmaj lin made any other impression - although these were mostly xxunk and very brief .
xxmaj elsewhere , the film just fell to pieces . xxmaj scenes and dialogue were completely unnatural and unbelievable , special effects were obviously done on the cheap with no attempt to clean up edges between persons and the mask of the blue screen , poor editing involving numerous xxunk in fight scenes , camera angles that were elementary and xxunk , and direction i 've seen better from a lost dog .
i guess this film was a too many xxunk affair . xxmaj most probably , the budget was blown away on the over - enthusiasm to have seven xxunk on the same silver screen . xxmaj that did n't leave much else .
xxmaj frankly , the way this film was made was like a cheap porn movie without the porn . xxmaj charlie 's xxmaj angels , it ai n't . xxmaj in fact , while sisters can do it for themselves , none of that was really that apparent here .
xxmaj definitely one to forget .,xxbos a xxunk - remembered melodrama thanks xxunk to xxmaj xxunk xxmaj xxunk 's fine xxmaj oscar - winning central performance about an xxunk - treated theme : the nature of acting and how it can xxunk one 's perception of reality . xxmaj in this case , we have a well - known xxunk tackling xxmaj shakespeare 's " xxmaj othello " , so that the film 's last third delves effectively into the thriller genre with press agent xxmaj edmond o'brien ( who happens to really be xxunk with xxmaj xxunk 's co - star and ex - wife xxmaj xxunk xxmaj xxunk ) ' xxunk ' the actor 's possible involvement in the xxmaj xxunk - like xxunk of a celebrity - seeking waitress ( a very slim xxmaj xxunk xxmaj winters ) . xxmaj the theatrical / xxmaj new xxmaj york atmosphere of the immediate post - war era is vividly captured by the husband - and - wife screen writing team of xxmaj xxunk xxmaj xxunk and xxmaj xxunk xxmaj gordon and legendary " actor 's director " xxmaj george xxmaj xxunk ( all of whom were recognized by the xxmaj academy with nominations ) ; incidentally , the film xxunk a second xxmaj oscar for xxmaj xxunk xxmaj xxunk 's xxunk score . xxmaj xxunk , forever the suave leading man blessed besides with a xxunk voice , does well enough by xxmaj shakespeare xxunk conviction the xxunk his character xxunk into obsessive jealousy , a murderous rage and , eventually , paranoia ; however , he is not let down by a supporting cast which also includes director xxmaj ray xxmaj collins , reporter xxmaj xxunk xxmaj mitchell , detective xxmaj joe xxmaj xxunk and xxunk xxmaj whit xxmaj xxunk . xxmaj though the mid - section is a bit xxunk , the film makes up for any xxunk with a remarkably - handled xxmaj xxunk xxunk .,xxbos xxmaj oh if only i could give this rubbish less than one star ! xxmaj there were two mildly amusing parts in the whole film and that is it ! one was where a line or two from the song xxmaj do n't xxmaj worry , xxmaj be xxmaj happy was xxunk by the slugs and the other was where xxmaj roddy fell of the toilet roll and landed with his feet and legs apart so that everything else he landed on on the way down hit him in the groin . xxmaj that is it there was nothing more amusing than that , at least not for me anyway ! xxmaj xxunk is not right in saying ' xxmaj fans of the completely terrible " xxmaj shrek " might enjoy , but " xxmaj wallace & xxmaj gromit " fans will probably turn away in xxunk . ' xxmaj as i loved xxmaj shrek 1 2 and 3 and i also love xxmaj wallace and xxmaj gromit . xxmaj you see what it boils down to is that if an animation is done extremely well then it is definitely worth watching , this however was about as far from done well as you can possibly get ! xxmaj the continuity mistakes were too big in number . xxmaj some were pointed out by the makers of this site others were not . i wo n't point out all of the others , but here are a few more to see : xxmaj when the young daughter leaves at the start of the film the catch to the cage door comes down and the hook part of it that is on the right clearly goes back around behind the round xxunk thus effectively making sure xxmaj roddy would not be able to get out and yet he does just by simply kicking at it . xxmaj at one point the ruby falls down xxmaj roddy 's back and gets pushed straight up into the the air by xxmaj rita all the while the ship is moving forwards . xxmaj in the next scene xxmaj roddy has caught it again . xxmaj this is impossible . xxmaj seeing as how the ship is moving forwards the only place when the ruby was xxunk out from under the back of xxmaj roddy 's shirt the only place it could have landed was in the water not in xxmaj roddy 's hand . xxmaj there was a third one i wanted to point out but for now i have forgotten it .
xxmaj too many , for want of a better word , ' jokes ' were repeated in one way or another , there was not enough time to establish any sort of connection with any of the characters , the characters were xxunk , shallow and empty , and the whole film left you wanting xxrep 4 . wanting to watch 85 minutes of anything else ! xxmaj paint xxunk or grass growing are two superb xxunk !,xxbos xxmaj one of the most appealing elements of a xxmaj gilliam film is that the well - xxunk visuals , the unsettling backdrops , and the manically frustrated characters are evidence of the creator 's involvement . xxmaj instead of most movies ( where the filmmaker is some director - for - hire that is paid to feature a star or two ) , you can feel xxmaj terry xxmaj gilliam 's presence through the experience . " 12 xxmaj monkeys " is evidence of xxmaj gilliam 's own vision and style , as opposed to making offbeat movies for their own sake . " 12 xxmaj monkeys " is a xxunk on similar themes of xxmaj gilliam 's xxunk : oppressive / recessive societies , the solitude of the protagonist , the frustration associated with disbelief , and parallel realms . xxmaj in this film xxmaj gilliam does a fine job of xxunk lines between the two realms , using xxunk to force the audience to believe rather than know . xxmaj this tendency for xxmaj gilliam to neglect to fill in certain gaps leads to xxunk of art - house pretentiousness . xxmaj the difference between xxmaj gilliam and artsy xxunk is that xxmaj gilliam 's choices clearly have a purpose and all of his images have meaning . xxmaj the two nearly identical xxunk scenes of xxmaj cole in the beginning are meant to draw comparisons which leave the audience xxunk . xxmaj his bald head is a mark of xxunk in the disease - ridden future world , yet makes him recognizable in the 1996 world . xxmaj the title itself is a mark of xxmaj gilliam 's creativity , as it requires the majority of the story to flesh out for its meaning to be fully understood . xxmaj all in all , xxmaj gilliam 's xxunk to making creative films that are interesting to watch yet also require thought and interpretation from the audience . xxmaj the film has immense re - watch value , since there are subtle details and hints that can be missed upon the first viewing . xxmaj definitely one of my favorites .
y: CategoryList
positive,negative,positive,negative,positive
Path: C:\Users\cross-entropy\.fastai\data\imdb_sample;
Test: None, model=SequentialRNN(
(0): MultiBatchEncoder(
(module): AWD_LSTM(
(encoder): Embedding(8992, 400, padding_idx=1)
(encoder_dp): EmbeddingDropout(
(emb): Embedding(8992, 400, padding_idx=1)
)
(rnns): ModuleList(
(0): WeightDropout(
(module): LSTM(400, 1152, batch_first=True)
)
(1): WeightDropout(
(module): LSTM(1152, 1152, batch_first=True)
)
(2): WeightDropout(
(module): LSTM(1152, 400, batch_first=True)
)
)
(input_dp): RNNDropout()
(hidden_dps): ModuleList(
(0): RNNDropout()
(1): RNNDropout()
(2): RNNDropout()
)
)
)
(1): PoolingLinearClassifier(
(layers): Sequential(
(0): BatchNorm1d(1200, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(1): Dropout(p=0.2, inplace=False)
(2): Linear(in_features=1200, out_features=50, bias=True)
(3): ReLU(inplace=True)
(4): BatchNorm1d(50, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): Dropout(p=0.1, inplace=False)
(6): Linear(in_features=50, out_features=2, bias=True)
)
)
), opt_func=functools.partial(<class 'torch.optim.adam.Adam'>, betas=(0.9, 0.99)), loss_func=FlattenedLoss of CrossEntropyLoss(), metrics=[<function accuracy at 0x000001E4A1319D08>], true_wd=True, bn_wd=True, wd=0.01, train_bn=True, path=WindowsPath('C:/Users/cross-entropy/.fastai/data/imdb_sample'), model_dir='models', callback_fns=[functools.partial(<class 'fastai.basic_train.Recorder'>, add_time=True, silent=False)], callbacks=[RNNTrainer
learn: ...
alpha: 2.0
beta: 1.0, MixedPrecision
learn: ...
loss_scale: 65536
max_noskip: 1000
dynamic: True
clip: None
flat_master: False
max_scale: 16777216
loss_fp32: True], layer_groups=[Sequential(
(0): Embedding(8992, 400, padding_idx=1)
(1): EmbeddingDropout(
(emb): Embedding(8992, 400, padding_idx=1)
)
), Sequential(
(0): WeightDropout(
(module): LSTM(400, 1152, batch_first=True)
)
(1): RNNDropout()
), Sequential(
(0): WeightDropout(
(module): LSTM(1152, 1152, batch_first=True)
)
(1): RNNDropout()
), Sequential(
(0): WeightDropout(
(module): LSTM(1152, 400, batch_first=True)
)
(1): RNNDropout()
), Sequential(
(0): PoolingLinearClassifier(
(layers): Sequential(
(0): BatchNorm1d(1200, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(1): Dropout(p=0.2, inplace=False)
(2): Linear(in_features=1200, out_features=50, bias=True)
(3): ReLU(inplace=True)
(4): BatchNorm1d(50, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): Dropout(p=0.1, inplace=False)
(6): Linear(in_features=50, out_features=2, bias=True)
)
)
)], add_time=True, silent=False)
data_clas.show_batch()
| text | target |
|---|---|
| xxbos xxmaj raising xxmaj victor xxmaj vargas : a xxmaj review \n \n xxmaj you know , xxmaj raising xxmaj victor xxmaj vargas is like sticking your hands into a big , steaming bowl of xxunk . xxmaj it 's warm and gooey , but you 're not sure if it feels right . xxmaj try as i might , no matter how warm and gooey xxmaj raising xxmaj | negative |
| xxbos xxmaj this film sat on my xxmaj tivo for weeks before i watched it . i dreaded a self - indulgent xxunk flick about relationships gone bad . i was wrong ; this was an xxunk xxunk into the screwed - up xxunk of xxmaj new xxmaj yorkers . \n \n xxmaj the format is the same as xxmaj max xxmaj xxunk ' " xxmaj la xxmaj ronde | positive |
| xxbos xxmaj many neglect that this is n't just a classic due to the fact that it 's the first xxup 3d game , or even the first xxunk - up . xxmaj it 's also one of the first stealth games , one of the xxunk definitely the first ) truly claustrophobic games , and just a pretty well - rounded gaming experience in general . xxmaj with graphics | positive |
| xxbos \n \n i 'm sure things did n't exactly go the same way in the real life of xxmaj xxunk xxmaj xxunk as they did in the film adaptation of his book , xxmaj xxunk xxmaj boys , but the movie " xxmaj october xxmaj sky " ( an xxunk of the book 's title ) is good enough to stand alone . i have not read xxmaj | positive |
| xxbos xxmaj to review this movie , i without any doubt would have to quote that memorable scene in xxmaj tarantino 's " xxmaj pulp xxmaj fiction " ( xxunk ) when xxmaj jules and xxmaj vincent are talking about xxmaj mia xxmaj wallace and what she does for a living . xxmaj jules tells xxmaj vincent that the " xxmaj only thing she did worthwhile was pilot " . | negative |
learn.fit_one_cycle(1, 1e-2)
learn.unfreeze()
learn.fit_one_cycle(3, slice(1e-4, 1e-2))
| epoch | train_loss | valid_loss | accuracy | time |
|---|---|---|---|---|
| 0 | 0.592132 | 0.516068 | 0.771144 | 01:01 |
| 1 | 0.454031 | 0.321474 | 0.870647 | 01:01 |
| 2 | 0.338722 | 0.323645 | 0.850746 | 01:01 |
We can use our model to predict on a few example of movie review-like raw text by using the Learner.predict method.
Our model is 70% sure that this is a positive review.
learn.predict('Although there was lots of blood and violence, I did not think this film was scary enough.')
C:\Users\cross-entropy\Anaconda3\envs\fastai\lib\site-packages\fastai\torch_core.py:83: UserWarning: Tensor is int32: upgrading to int64; for better performance use int64 input
warn('Tensor is int32: upgrading to int64; for better performance use int64 input')
(Category positive, tensor(1), tensor([0.3028, 0.6972]))
Our model is 83% sure that this is a positive review:
learn.predict('Not so good World War II epic film')
C:\Users\cross-entropy\Anaconda3\envs\fastai\lib\site-packages\fastai\torch_core.py:83: UserWarning: Tensor is int32: upgrading to int64; for better performance use int64 input
warn('Tensor is int32: upgrading to int64; for better performance use int64 input')
(Category positive, tensor(1), tensor([0.1734, 0.8266]))
Bottom line: the model did not do a good job, misclassifying both reviews (with high confidence, to boot!)
learn.unfreeze()
learn.fit_one_cycle(3, slice(1e-4, 1e-2))
| epoch | train_loss | valid_loss | accuracy | time |
|---|---|---|---|---|
| 0 | 0.263950 | 0.500555 | 0.825871 | 01:05 |
| 1 | 0.226157 | 0.297020 | 0.860696 | 01:05 |
| 2 | 0.163577 | 0.298125 | 0.855721 | 01:04 |
learn.predict('Although there was lots of blood and violence, I did not think this film was scary enough.')
C:\Users\cross-entropy\Anaconda3\envs\fastai\lib\site-packages\fastai\torch_core.py:83: UserWarning: Tensor is int32: upgrading to int64; for better performance use int64 input
warn('Tensor is int32: upgrading to int64; for better performance use int64 input')
(Category negative, tensor(0), tensor([0.9879, 0.0121]))
learn.predict('Not so good World War II epic film')
C:\Users\cross-entropy\Anaconda3\envs\fastai\lib\site-packages\fastai\torch_core.py:83: UserWarning: Tensor is int32: upgrading to int64; for better performance use int64 input
warn('Tensor is int32: upgrading to int64; for better performance use int64 input')
(Category negative, tensor(0), tensor([0.7353, 0.2647]))
The model seems to have benefitted from the extra training, since it now correctly classifies both reviews as negative, with high confidence.