Skip to content

Instantly share code, notes, and snippets.

@danielpcox
Created December 7, 2019 21: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 danielpcox/7030902243dc951d5ea500082003a399 to your computer and use it in GitHub Desktop.
Save danielpcox/7030902243dc951d5ea500082003a399 to your computer and use it in GitHub Desktop.
FastAITextSandbox.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "FastAITextSandbox.ipynb",
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/danielpcox/7030902243dc951d5ea500082003a399/fastaitextsandbox.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "D5hu8SVuPIT2",
"colab_type": "code",
"colab": {}
},
"source": [
"from fastai.text import * "
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "Q6XWfvvmPN50",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 51
},
"outputId": "40a1c6e0-b573-4b78-8dd4-ac66d503ae1f"
},
"source": [
"path = untar_data(URLs.IMDB_SAMPLE)\n",
"path"
],
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": [
"Downloading http://files.fast.ai/data/examples/imdb_sample\n"
],
"name": "stdout"
},
{
"output_type": "display_data",
"data": {
"text/html": [
""
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"PosixPath('/root/.fastai/data/imdb_sample')"
]
},
"metadata": {
"tags": []
},
"execution_count": 2
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "PM2ZBkqsPktL",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 204
},
"outputId": "f6c1dce9-cfe9-4214-b8f2-932ed71fd8ac"
},
"source": [
"df = pd.read_csv(path/'texts.csv')\n",
"df.head()"
],
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"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>label</th>\n",
" <th>text</th>\n",
" <th>is_valid</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>negative</td>\n",
" <td>Un-bleeping-believable! Meg Ryan doesn't even ...</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>positive</td>\n",
" <td>This is a extremely well-made film. The acting...</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>negative</td>\n",
" <td>Every once in a long while a movie will come a...</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>positive</td>\n",
" <td>Name just says it all. I watched this movie wi...</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>negative</td>\n",
" <td>This movie succeeds at being one of the most u...</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" label text is_valid\n",
"0 negative Un-bleeping-believable! Meg Ryan doesn't even ... False\n",
"1 positive This is a extremely well-made film. The acting... False\n",
"2 negative Every once in a long while a movie will come a... False\n",
"3 positive Name just says it all. I watched this movie wi... False\n",
"4 negative This movie succeeds at being one of the most u... False"
]
},
"metadata": {
"tags": []
},
"execution_count": 3
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "gUEqYVIkPpvR",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 17
},
"outputId": "791305fa-3111-4b4c-80d6-b2a5ba4a735e"
},
"source": [
"# Language model data\n",
"data_lm = TextLMDataBunch.from_csv(path, 'texts.csv')\n",
"# Classifier model data\n",
"data_clas = TextClasDataBunch.from_csv(path, 'texts.csv', vocab=data_lm.train_ds.vocab, bs=32)"
],
"execution_count": 4,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/html": [
""
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
},
{
"output_type": "display_data",
"data": {
"text/html": [
""
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
},
{
"output_type": "display_data",
"data": {
"text/html": [
""
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
},
{
"output_type": "display_data",
"data": {
"text/html": [
""
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "cAM_nEoVP3l2",
"colab_type": "code",
"colab": {}
},
"source": [
"data_lm.save('data_lm_export.pkl')\n",
"data_clas.save('data_clas_export.pkl')"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "JZCCEXoCQARX",
"colab_type": "code",
"colab": {}
},
"source": [
"data_lm = load_data(path, 'data_lm_export.pkl')\n",
"data_clas = load_data(path, 'data_clas_export.pkl', bs=16)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "02R3ThiNQEIW",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 97
},
"outputId": "0f8198ae-c006-44b7-9db7-349170019185"
},
"source": [
"learn = language_model_learner(data_lm, AWD_LSTM, drop_mult=0.5)\n",
"learn.fit_one_cycle(1, 1e-2)"
],
"execution_count": 7,
"outputs": [
{
"output_type": "stream",
"text": [
"Downloading https://s3.amazonaws.com/fast-ai-modelzoo/wt103-fwd\n"
],
"name": "stdout"
},
{
"output_type": "display_data",
"data": {
"text/html": [
""
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
},
{
"output_type": "display_data",
"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.302381</td>\n",
" <td>3.961235</td>\n",
" <td>0.277981</td>\n",
" <td>00:06</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "GlQw0a2WQNEj",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 80
},
"outputId": "f591a26e-82a0-4b8d-ceff-fde6062d433e"
},
"source": [
"learn.unfreeze()\n",
"learn.fit_one_cycle(1, 1e-3)"
],
"execution_count": 8,
"outputs": [
{
"output_type": "display_data",
"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.937546</td>\n",
" <td>3.885066</td>\n",
" <td>0.288233</td>\n",
" <td>00:08</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "GEMI7W-0QUjX",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "8a8fe8f3-7117-4962-fad5-7dec6d766340"
},
"source": [
"learn.predict(\"This is a review about\", n_words=10)"
],
"execution_count": 9,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"'This is a review about our new standards of entertainment started in your working class'"
]
},
"metadata": {
"tags": []
},
"execution_count": 9
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "q8obytCVQcIJ",
"colab_type": "code",
"colab": {}
},
"source": [
"learn.save_encoder('ft_enc')"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "NPiHL1LzQhOn",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"outputId": "338a94ad-d299-44b0-a508-83e28fcb7325"
},
"source": [
"learn = text_classifier_learner(data_clas, AWD_LSTM, drop_mult=0.5)\n",
"learn.load_encoder('ft_enc')"
],
"execution_count": 11,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"RNNLearner(data=TextClasDataBunch;\n",
"\n",
"Train: LabelList (799 items)\n",
"x: TextList\n",
"xxbos xxmaj this is one of the worst films ever . i like cheesy movies but this is simply awful . xxmaj where are the images in the film that are on the box ? i think more money was spent on the xxup dvd box xxunk than on the entire film . \n",
" \n",
" xxmaj why would a company release a xxup dvd that the cover is so misleading ? i feel like such an idiot for renting this movie based strictly on the box . xxmaj as much as i explore imdb i should have done a little research and made a list prior to visiting my local video rental store . i have no one to blame except myself . i want my money and time back . \n",
" \n",
" xxup do xxup not xxup watch xxup this xxup movie . \n",
" \n",
" xxmaj even if curiosity is xxunk you , stick xxunk xxunk in your eyes instead . xxmaj it will be much more enjoyable . xxmaj you have been warned !,xxbos xxmaj do n't bother . a little xxunk could go a long way , but all we get is pure ham , particularly from xxmaj xxunk . xxmaj the plot is one of those xxunk car episodes ... the vehicle xxunk into another and everything changes direction again , until we are merely xxunk our heads wondering if there were ever a plot . xxmaj gina xxmaj phillips is actually good , but it 's hard playing across from a xxunk xxmaj xxunk playing xxmaj lady xxmaj xxunk lost in the xxmaj xxunk 's xxmaj brother 's xxmaj xxunk xxmaj xxunk . xxmaj ah , the xxmaj raven ... now there 's an actor . xxmaj and there is the relative who just lies and bed and looks xxunk . xxmaj or xxmaj dr. xxmaj xxunk who 's filled with lots of xxunk and no working xxunk . i 'm one of those xxunk who just has to see a movie to the end . xxmaj xxunk the xxmaj raven , \" xxmaj xxunk . \",xxbos xxmaj in this movie , xxmaj chávez supporters ( either venezuelan and not - venezuelan ) just lie about a dramatic situation in our country . \n",
" \n",
" xxmaj they did not say that the conflict started because of xxmaj chávez announcement firing a lot of xxup xxunk best workers just for political issues . \n",
" \n",
" xxmaj they did not say anything about more than 96 xxup tv xxunk xxunk by xxmaj chávez during only 3 days in \" xxup xxunk xxup xxunk \" ( a kind of xxunk o private xxup tv xxunk ) . xxmaj each one with about 20 minutes of duration . \n",
" \n",
" xxmaj they did not tell us anything about xxmaj the xxunk announcement made by xxmaj general xxunk xxmaj xxunk xxmaj lucas xxmaj xxunk xxmaj romero , xxmaj inspector xxmaj general of the army forces , who is a traditional supporter of xxmaj chávez . xxmaj even now , in despite of his announcement , he is the xxmaj ministro de xxmaj xxunk y xxmaj xxunk . xxmaj after xxmaj chávez return he xxunk the xxmaj charge of xxmaj ministro del xxmaj xxunk ( equals to xxmaj defense xxmaj secretary in xxup us ) . \n",
" \n",
" xxmaj they did not say anything about xxmaj chávez orders about shooting against a xxunk people concentration who was claiming for elections . \n",
" \n",
" xxmaj they did not say anything about the people in this concentration that were killed by xxmaj chávez xxmaj supporters ( either civilians and xxmaj military official forces ) . \n",
" \n",
" xxmaj they present some facts in a wrong order , in order to lie . \n",
" \n",
" xxmaj they did not say anything about venezuelan civilian society that s are even now claiming for an elections in order to solve the crisis and xxmaj chávez actions in order to avoid the elections . \n",
" \n",
" xxmaj that 's why i tell you xxrep 4 . xxmaj this movie is just a lot of lies or a big lie .,xxbos xxmaj the fact that most of the budget for this presumably went on the heavy - duty cast list should n't have xxunk if it had been staged with flair and imagination and some sympathy for the original 's satirical intent . xxmaj instead we get xxunk bad song and dance sequences featuring xxunk xxunk and xxunk , and the final alienation is accomplished by pulling back to reveal the action has taken place on a music - hall stage , appropriately enough for a production that 's more xxmaj xxunk ' xxmaj oliver ' xxmaj blair than xxmaj xxunk . xxmaj the acting talent is shamefully xxunk : xxmaj migenes and xxmaj xxunk are good but do n't have to try very hard : xxmaj migenes at least has a great voice and some feel for the material . xxmaj julia looks perfect as xxmaj xxunk , but struggles with the character , xxunk by a fake xxunk accent . xxmaj harris 's xxmaj xxunk is embarrassingly mannered and xxmaj xxunk is atrocious . xxmaj the adaptations of lyrics , script and music are often awkward : it was a bad move to base the film on xxmaj marc xxmaj xxunk 's xxunk xxmaj broadway version , but at least his words were xxunk , unlike most of what 's been xxunk in gestures of xxunk . xxmaj and the attempt at xxunk the low budget by filming at claustrophobic angles on xxunk - xxunk sets lit in garish blues and xxunk as if by some bargain - basement xxmaj xxunk xxmaj xxunk fails utterly -- the film just looks cheap , shoddy and xxunk made . xxmaj disgraceful .,xxbos xxmaj god , i was bored out of my head as i watched this pilot . i had been expecting a lot from it , as i 'm a huge fan of xxmaj james xxmaj cameron ( and not just since \" xxmaj titanic \" , i might add ) , and his name in the credits i thought would be a guarantee of quality ( xxmaj then again , he also wrote the leaden xxmaj strange xxmaj days .. ) . xxmaj but the thing failed miserably at grabbing my attention at any point of its almost two hours of duration . xxmaj in all that time , it barely went beyond its two line synopsis , and i would be very hard pressed to try to figure out any kind of coherent plot out of all the mess of xxunk that went nowhere . xxmaj on top of that , i do n't think the xxunk xxunk even those of any regular \" a - xxmaj team \" episode . xxmaj as for xxmaj xxunk , yes , she is gorgeous , of course , but the fact that she only displays one single facial expression the entire movie ( xxunk and surly ) , makes me also get bored of her \" gal xxunk an attitude \" schtick pretty soon . xxmaj you can count me out of this one , xxmaj mr. xxmaj cameron !\n",
"y: CategoryList\n",
"negative,negative,negative,negative,negative\n",
"Path: /root/.fastai/data/imdb_sample;\n",
"\n",
"Valid: LabelList (201 items)\n",
"x: TextList\n",
"xxbos xxmaj the spoiler warning is for those people who want to see for themselves what animals and landscapes pass before their eyes , although i do n't mention it in great detail . \n",
" \n",
" \" xxmaj earth \" is an xxunk . 90 minute cinema version based on \" xxmaj planet earth \" which i watched all on xxup bbc xxunk xxup tv version was narrated by xxmaj david xxmaj attenborough , a captivating commentator , who i had wished had also done it for \" xxmaj earth \" but it is xxmaj patrick xxmaj stewart , xxmaj star xxmaj trek 's xxmaj captain xxmaj xxunk . xxmaj there are xxunk shots of the xxmaj earth from space so that 's may be appropriate . xxmaj in any case he has a nice enough and calm voice for it . xxmaj there are 12 xxunk in which we follow animal life on earth from xxmaj north xxmaj pole to xxmaj xxunk . 3 animal families , polar bear , elephant and whale , appear in more than one of these parts . xxmaj each \" chapter \" starts with an indication how far from north pole or xxunk it is . xxmaj we see something of each kind of animal , but only xxunk and birds , and some fish , and some beautiful shots of xxunk , mountains , waterfalls , xxunk and jungle , a near perfect presentation of the variety of life and landscapes and xxunk on earth . xxmaj you get the impression that our planet is only inhabited by animals : people or villages or cities are n't in the film , so it 's a typical nature documentary , but breathtakingly shot and accompanied by delightful music . xxmaj when the film opened i already knew it would end far too soon for me . xxmaj it is a family film , so no brutal killings of any animals . xxmaj when one is caught by his hunter the shot ends and in other cases where we see the prey being caught it 's shot in slow - motion which makes it less violent and watchable for young children ( age limit 6 in xxmaj the xxmaj netherlands ) . xxmaj no blood is shed . xxmaj some scenes ( xxunk born animals ) are really cute and will be adored by kids . xxmaj it looks like an ordinary nature film but when you know how many shooting days it took ( xxunk ) and how much money it has cost it becomes an even more astonishing piece of beauty . xxmaj it had it 's xxmaj dutch premiere yesterday , a month before the actual release , in a cinema of 500 seats , of which 15 were taken . xxmaj true beauty is rarely interesting for cinema goers , it seems . xxmaj as i knew the xxup tv - series i was of course very curious if my favourite scenes would make it into this movie . xxmaj some did n't , but the most impressive shots ( big waterfalls ) did , luckily . xxmaj it was the first time i ever cried in a nature film .,xxbos xxmaj evidently when you offer a actor enough money they will do anything . i am not sure how much xxmaj john xxmaj xxunk - xxmaj xxunk got , but most of the money he made should go to his fans as an apology for even being associated with such a xxup rotten movie . xxmaj the special effects were worse then effects from the 1950 's b movies and the acting of the rest of the cast was even worse . xxmaj as to how bad the acting was a child gave the second best performance in my opinion . xxmaj the xxmaj english was terribly accented and i think no one could really even speak xxmaj english they just xxunk how the words should sound instead of xxunk the script and trying to make their character both \" life - like \" and real .,xxbos xxmaj the first hour or so of the movie was mostly boring to say the least . xxmaj however it improved afterwards as the xxmaj valentine xxmaj party xxunk . xxmaj apart from the twist as to the identity of the killer in the very end , the hot bath murder scene was one of the few relatively memorable aspects of this movie . xxmaj the scene at the garden with xxmaj kate was well shot and so was the very last scene ( the ' twist ' ) . xxmaj in those scenes , there was some genuine suspense and thrills and the hot bath murder scene had a nasty ( the way slashers should be ) edge to it . xxmaj the earlier murders are xxunk devoid of gore .,xxbos xxmaj this was a great movie that had a lot of under lying issues . xxmaj it dealt with issues of xxunk and class . xxmaj but , it also had a message of knowing yourself and taking responsibility for yourself . xxmaj this movie was very deep it gave the message of that you and only you can control your destiny . xxmaj it also showed that knowing yourself and being comfortable with who you are is the only way you will ever fit into society . xxmaj what others think of you is not important . i believe this movie did a wonderful job of showing it . xxmaj the actors i think were able to convey each character wonderfully . i just thought it was amazing how deep this movie really was . xxmaj at a just xxunk look you would n't see how deep the movie is , but on further look you see the xxunk meaning of the movie .,xxbos i must say that i had wanted to see this film for a long time , and i was not disappointed . xxmaj the acting of xxmaj xxunk xxmaj xxunk is simply fantastic . xxmaj as a part xxunk myself , i can relate with how the story develops . i have never experienced anything of the sort but some xxunk moments xxunk the sleeping and it can be scary . xxmaj it was a great film , worth every xxunk . i hope that one day i can work with xxmaj xxunk myself , it would be an honor and beyond . i can recommend it for everybody . xxmaj maybe not small children as they may get scared . xxmaj but if you are an xxunk like me , you 'll understand the world , the xxunk and the fear . xxmaj you 'll love it . \n",
" \n",
" xxup xxunk\n",
"y: CategoryList\n",
"positive,negative,positive,positive,positive\n",
"Path: /root/.fastai/data/imdb_sample;\n",
"\n",
"Test: None, model=SequentialRNN(\n",
" (0): MultiBatchEncoder(\n",
" (module): AWD_LSTM(\n",
" (encoder): Embedding(8952, 400, padding_idx=1)\n",
" (encoder_dp): EmbeddingDropout(\n",
" (emb): Embedding(8952, 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 0x7f2b71479378>], true_wd=True, bn_wd=True, wd=0.01, train_bn=True, path=PosixPath('/root/.fastai/data/imdb_sample'), model_dir='models', callback_fns=[functools.partial(<class 'fastai.basic_train.Recorder'>, add_time=True, silent=False)], callbacks=[RNNTrainer\n",
"learn: RNNLearner(data=TextClasDataBunch;\n",
"\n",
"Train: LabelList (799 items)\n",
"x: TextList\n",
"xxbos xxmaj this is one of the worst films ever . i like cheesy movies but this is simply awful . xxmaj where are the images in the film that are on the box ? i think more money was spent on the xxup dvd box xxunk than on the entire film . \n",
" \n",
" xxmaj why would a company release a xxup dvd that the cover is so misleading ? i feel like such an idiot for renting this movie based strictly on the box . xxmaj as much as i explore imdb i should have done a little research and made a list prior to visiting my local video rental store . i have no one to blame except myself . i want my money and time back . \n",
" \n",
" xxup do xxup not xxup watch xxup this xxup movie . \n",
" \n",
" xxmaj even if curiosity is xxunk you , stick xxunk xxunk in your eyes instead . xxmaj it will be much more enjoyable . xxmaj you have been warned !,xxbos xxmaj do n't bother . a little xxunk could go a long way , but all we get is pure ham , particularly from xxmaj xxunk . xxmaj the plot is one of those xxunk car episodes ... the vehicle xxunk into another and everything changes direction again , until we are merely xxunk our heads wondering if there were ever a plot . xxmaj gina xxmaj phillips is actually good , but it 's hard playing across from a xxunk xxmaj xxunk playing xxmaj lady xxmaj xxunk lost in the xxmaj xxunk 's xxmaj brother 's xxmaj xxunk xxmaj xxunk . xxmaj ah , the xxmaj raven ... now there 's an actor . xxmaj and there is the relative who just lies and bed and looks xxunk . xxmaj or xxmaj dr. xxmaj xxunk who 's filled with lots of xxunk and no working xxunk . i 'm one of those xxunk who just has to see a movie to the end . xxmaj xxunk the xxmaj raven , \" xxmaj xxunk . \",xxbos xxmaj in this movie , xxmaj chávez supporters ( either venezuelan and not - venezuelan ) just lie about a dramatic situation in our country . \n",
" \n",
" xxmaj they did not say that the conflict started because of xxmaj chávez announcement firing a lot of xxup xxunk best workers just for political issues . \n",
" \n",
" xxmaj they did not say anything about more than 96 xxup tv xxunk xxunk by xxmaj chávez during only 3 days in \" xxup xxunk xxup xxunk \" ( a kind of xxunk o private xxup tv xxunk ) . xxmaj each one with about 20 minutes of duration . \n",
" \n",
" xxmaj they did not tell us anything about xxmaj the xxunk announcement made by xxmaj general xxunk xxmaj xxunk xxmaj lucas xxmaj xxunk xxmaj romero , xxmaj inspector xxmaj general of the army forces , who is a traditional supporter of xxmaj chávez . xxmaj even now , in despite of his announcement , he is the xxmaj ministro de xxmaj xxunk y xxmaj xxunk . xxmaj after xxmaj chávez return he xxunk the xxmaj charge of xxmaj ministro del xxmaj xxunk ( equals to xxmaj defense xxmaj secretary in xxup us ) . \n",
" \n",
" xxmaj they did not say anything about xxmaj chávez orders about shooting against a xxunk people concentration who was claiming for elections . \n",
" \n",
" xxmaj they did not say anything about the people in this concentration that were killed by xxmaj chávez xxmaj supporters ( either civilians and xxmaj military official forces ) . \n",
" \n",
" xxmaj they present some facts in a wrong order , in order to lie . \n",
" \n",
" xxmaj they did not say anything about venezuelan civilian society that s are even now claiming for an elections in order to solve the crisis and xxmaj chávez actions in order to avoid the elections . \n",
" \n",
" xxmaj that 's why i tell you xxrep 4 . xxmaj this movie is just a lot of lies or a big lie .,xxbos xxmaj the fact that most of the budget for this presumably went on the heavy - duty cast list should n't have xxunk if it had been staged with flair and imagination and some sympathy for the original 's satirical intent . xxmaj instead we get xxunk bad song and dance sequences featuring xxunk xxunk and xxunk , and the final alienation is accomplished by pulling back to reveal the action has taken place on a music - hall stage , appropriately enough for a production that 's more xxmaj xxunk ' xxmaj oliver ' xxmaj blair than xxmaj xxunk . xxmaj the acting talent is shamefully xxunk : xxmaj migenes and xxmaj xxunk are good but do n't have to try very hard : xxmaj migenes at least has a great voice and some feel for the material . xxmaj julia looks perfect as xxmaj xxunk , but struggles with the character , xxunk by a fake xxunk accent . xxmaj harris 's xxmaj xxunk is embarrassingly mannered and xxmaj xxunk is atrocious . xxmaj the adaptations of lyrics , script and music are often awkward : it was a bad move to base the film on xxmaj marc xxmaj xxunk 's xxunk xxmaj broadway version , but at least his words were xxunk , unlike most of what 's been xxunk in gestures of xxunk . xxmaj and the attempt at xxunk the low budget by filming at claustrophobic angles on xxunk - xxunk sets lit in garish blues and xxunk as if by some bargain - basement xxmaj xxunk xxmaj xxunk fails utterly -- the film just looks cheap , shoddy and xxunk made . xxmaj disgraceful .,xxbos xxmaj god , i was bored out of my head as i watched this pilot . i had been expecting a lot from it , as i 'm a huge fan of xxmaj james xxmaj cameron ( and not just since \" xxmaj titanic \" , i might add ) , and his name in the credits i thought would be a guarantee of quality ( xxmaj then again , he also wrote the leaden xxmaj strange xxmaj days .. ) . xxmaj but the thing failed miserably at grabbing my attention at any point of its almost two hours of duration . xxmaj in all that time , it barely went beyond its two line synopsis , and i would be very hard pressed to try to figure out any kind of coherent plot out of all the mess of xxunk that went nowhere . xxmaj on top of that , i do n't think the xxunk xxunk even those of any regular \" a - xxmaj team \" episode . xxmaj as for xxmaj xxunk , yes , she is gorgeous , of course , but the fact that she only displays one single facial expression the entire movie ( xxunk and surly ) , makes me also get bored of her \" gal xxunk an attitude \" schtick pretty soon . xxmaj you can count me out of this one , xxmaj mr. xxmaj cameron !\n",
"y: CategoryList\n",
"negative,negative,negative,negative,negative\n",
"Path: /root/.fastai/data/imdb_sample;\n",
"\n",
"Valid: LabelList (201 items)\n",
"x: TextList\n",
"xxbos xxmaj the spoiler warning is for those people who want to see for themselves what animals and landscapes pass before their eyes , although i do n't mention it in great detail . \n",
" \n",
" \" xxmaj earth \" is an xxunk . 90 minute cinema version based on \" xxmaj planet earth \" which i watched all on xxup bbc xxunk xxup tv version was narrated by xxmaj david xxmaj attenborough , a captivating commentator , who i had wished had also done it for \" xxmaj earth \" but it is xxmaj patrick xxmaj stewart , xxmaj star xxmaj trek 's xxmaj captain xxmaj xxunk . xxmaj there are xxunk shots of the xxmaj earth from space so that 's may be appropriate . xxmaj in any case he has a nice enough and calm voice for it . xxmaj there are 12 xxunk in which we follow animal life on earth from xxmaj north xxmaj pole to xxmaj xxunk . 3 animal families , polar bear , elephant and whale , appear in more than one of these parts . xxmaj each \" chapter \" starts with an indication how far from north pole or xxunk it is . xxmaj we see something of each kind of animal , but only xxunk and birds , and some fish , and some beautiful shots of xxunk , mountains , waterfalls , xxunk and jungle , a near perfect presentation of the variety of life and landscapes and xxunk on earth . xxmaj you get the impression that our planet is only inhabited by animals : people or villages or cities are n't in the film , so it 's a typical nature documentary , but breathtakingly shot and accompanied by delightful music . xxmaj when the film opened i already knew it would end far too soon for me . xxmaj it is a family film , so no brutal killings of any animals . xxmaj when one is caught by his hunter the shot ends and in other cases where we see the prey being caught it 's shot in slow - motion which makes it less violent and watchable for young children ( age limit 6 in xxmaj the xxmaj netherlands ) . xxmaj no blood is shed . xxmaj some scenes ( xxunk born animals ) are really cute and will be adored by kids . xxmaj it looks like an ordinary nature film but when you know how many shooting days it took ( xxunk ) and how much money it has cost it becomes an even more astonishing piece of beauty . xxmaj it had it 's xxmaj dutch premiere yesterday , a month before the actual release , in a cinema of 500 seats , of which 15 were taken . xxmaj true beauty is rarely interesting for cinema goers , it seems . xxmaj as i knew the xxup tv - series i was of course very curious if my favourite scenes would make it into this movie . xxmaj some did n't , but the most impressive shots ( big waterfalls ) did , luckily . xxmaj it was the first time i ever cried in a nature film .,xxbos xxmaj evidently when you offer a actor enough money they will do anything . i am not sure how much xxmaj john xxmaj xxunk - xxmaj xxunk got , but most of the money he made should go to his fans as an apology for even being associated with such a xxup rotten movie . xxmaj the special effects were worse then effects from the 1950 's b movies and the acting of the rest of the cast was even worse . xxmaj as to how bad the acting was a child gave the second best performance in my opinion . xxmaj the xxmaj english was terribly accented and i think no one could really even speak xxmaj english they just xxunk how the words should sound instead of xxunk the script and trying to make their character both \" life - like \" and real .,xxbos xxmaj the first hour or so of the movie was mostly boring to say the least . xxmaj however it improved afterwards as the xxmaj valentine xxmaj party xxunk . xxmaj apart from the twist as to the identity of the killer in the very end , the hot bath murder scene was one of the few relatively memorable aspects of this movie . xxmaj the scene at the garden with xxmaj kate was well shot and so was the very last scene ( the ' twist ' ) . xxmaj in those scenes , there was some genuine suspense and thrills and the hot bath murder scene had a nasty ( the way slashers should be ) edge to it . xxmaj the earlier murders are xxunk devoid of gore .,xxbos xxmaj this was a great movie that had a lot of under lying issues . xxmaj it dealt with issues of xxunk and class . xxmaj but , it also had a message of knowing yourself and taking responsibility for yourself . xxmaj this movie was very deep it gave the message of that you and only you can control your destiny . xxmaj it also showed that knowing yourself and being comfortable with who you are is the only way you will ever fit into society . xxmaj what others think of you is not important . i believe this movie did a wonderful job of showing it . xxmaj the actors i think were able to convey each character wonderfully . i just thought it was amazing how deep this movie really was . xxmaj at a just xxunk look you would n't see how deep the movie is , but on further look you see the xxunk meaning of the movie .,xxbos i must say that i had wanted to see this film for a long time , and i was not disappointed . xxmaj the acting of xxmaj xxunk xxmaj xxunk is simply fantastic . xxmaj as a part xxunk myself , i can relate with how the story develops . i have never experienced anything of the sort but some xxunk moments xxunk the sleeping and it can be scary . xxmaj it was a great film , worth every xxunk . i hope that one day i can work with xxmaj xxunk myself , it would be an honor and beyond . i can recommend it for everybody . xxmaj maybe not small children as they may get scared . xxmaj but if you are an xxunk like me , you 'll understand the world , the xxunk and the fear . xxmaj you 'll love it . \n",
" \n",
" xxup xxunk\n",
"y: CategoryList\n",
"positive,negative,positive,positive,positive\n",
"Path: /root/.fastai/data/imdb_sample;\n",
"\n",
"Test: None, model=SequentialRNN(\n",
" (0): MultiBatchEncoder(\n",
" (module): AWD_LSTM(\n",
" (encoder): Embedding(8952, 400, padding_idx=1)\n",
" (encoder_dp): EmbeddingDropout(\n",
" (emb): Embedding(8952, 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 0x7f2b71479378>], true_wd=True, bn_wd=True, wd=0.01, train_bn=True, path=PosixPath('/root/.fastai/data/imdb_sample'), model_dir='models', callback_fns=[functools.partial(<class 'fastai.basic_train.Recorder'>, add_time=True, silent=False)], callbacks=[...], layer_groups=[Sequential(\n",
" (0): Embedding(8952, 400, padding_idx=1)\n",
" (1): EmbeddingDropout(\n",
" (emb): Embedding(8952, 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)\n",
"alpha: 2.0\n",
"beta: 1.0], layer_groups=[Sequential(\n",
" (0): Embedding(8952, 400, padding_idx=1)\n",
" (1): EmbeddingDropout(\n",
" (emb): Embedding(8952, 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)"
]
},
"metadata": {
"tags": []
},
"execution_count": 11
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "S9mg7jbFQlfx",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 289
},
"outputId": "822f5ac4-9277-4685-b3e5-ee7a51008aed"
},
"source": [
"data_clas.show_batch()"
],
"execution_count": 12,
"outputs": [
{
"output_type": "display_data",
"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 now that xxmaj che(2008 ) has finished its relatively short xxmaj australian cinema run ( extremely limited xxunk screen in xxmaj xxunk , after xxunk ) , i can xxunk join both xxunk of \" xxmaj at xxmaj the xxmaj movies \" in taking xxmaj steven xxmaj soderbergh to task . \\n \\n xxmaj it 's usually satisfying to watch a film director change his style /</td>\n",
" <td>negative</td>\n",
" </tr>\n",
" <tr>\n",
" <td>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</td>\n",
" <td>positive</td>\n",
" </tr>\n",
" <tr>\n",
" <td>xxbos i really wanted to love this show . i truly , honestly did . \\n \\n xxmaj for the first time , gay viewers get their own version of the \" xxmaj the xxmaj xxunk \" . xxmaj with the help of his obligatory \" hag \" xxmaj xxunk , xxmaj james , a good looking , well - to - do thirty - something has the chance</td>\n",
" <td>negative</td>\n",
" </tr>\n",
" <tr>\n",
" <td>xxbos \\n \\n i 'm sure things did n't exactly go the same way in the real life of xxmaj homer xxmaj hickam as they did in the film adaptation of his book , xxmaj rocket 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</td>\n",
" <td>positive</td>\n",
" </tr>\n",
" <tr>\n",
" <td>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 \" .</td>\n",
" <td>negative</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "_dTVeKznQnrf",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 80
},
"outputId": "a83e74af-8d70-4ca4-ceab-1f2df98e8f14"
},
"source": [
"learn.fit_one_cycle(1, 1e-2)"
],
"execution_count": 13,
"outputs": [
{
"output_type": "display_data",
"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.600434</td>\n",
" <td>0.558093</td>\n",
" <td>0.726368</td>\n",
" <td>00:12</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "yp4GJOwGQtqh",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 80
},
"outputId": "ecd7f022-4847-49ab-b5f9-cb3bfbf88c4f"
},
"source": [
"learn.freeze_to(-2)\n",
"learn.fit_one_cycle(1, slice(5e-3/2., 5e-3))"
],
"execution_count": 14,
"outputs": [
{
"output_type": "display_data",
"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.532677</td>\n",
" <td>0.436928</td>\n",
" <td>0.820895</td>\n",
" <td>00:11</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "06Qle6fgQzv6",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 80
},
"outputId": "13db6432-3bb4-405d-8f30-beeb371c81af"
},
"source": [
"learn.unfreeze()\n",
"learn.fit_one_cycle(1, slice(2e-3/100, 2e-3))"
],
"execution_count": 15,
"outputs": [
{
"output_type": "display_data",
"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.418552</td>\n",
" <td>0.390670</td>\n",
" <td>0.830846</td>\n",
" <td>00:18</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "KTg1MqtnQ7iC",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "922ea183-048e-4d8d-ee6c-f9ac81829db4"
},
"source": [
"learn.predict(\"This was a great movie!\")"
],
"execution_count": 16,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(Category positive, tensor(1), tensor([0.0121, 0.9879]))"
]
},
"metadata": {
"tags": []
},
"execution_count": 16
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "-QsQ-_h1RA0i",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": 0,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment