Skip to content

Instantly share code, notes, and snippets.

@sujitpal
Created May 12, 2016 15:21
Show Gist options
  • Save sujitpal/a57a10e3dafa22e02af117e5b82cc607 to your computer and use it in GitHub Desktop.
Save sujitpal/a57a10e3dafa22e02af117e5b82cc607 to your computer and use it in GitHub Desktop.
LSTM for Sequence to Sequence Generation - Deep Learning Learners Meetup Presentation May-12-2016
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## RNN For Sequence to Sequence Translation"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using Theano backend.\n"
]
}
],
"source": [
"from __future__ import print_function\n",
"from keras.layers.core import Activation, Dense, RepeatVector\n",
"from keras.layers.recurrent import LSTM\n",
"from keras.layers.wrappers import TimeDistributed\n",
"from keras.models import Sequential\n",
"from sklearn.cross_validation import train_test_split\n",
"import nltk\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Extract text to list of words"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"words = []\n",
"fin = open(\"data/alice_in_wonderland.txt\", 'rb')\n",
"for line in fin:\n",
" line = line.strip()\n",
" if len(line) == 0:\n",
" continue\n",
" for sentence in nltk.sent_tokenize(line):\n",
" for word in nltk.word_tokenize(sentence):\n",
" words.append(word.lower())\n",
"fin.close()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create vocabulary and lookup tables"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"char_vocab = set([c for c in \" \".join(words)])\n",
"nb_chars = len(char_vocab)\n",
"char2index = {c:i for i, c in enumerate(sorted(char_vocab))}\n",
"index2char = {i:c for i, c in enumerate(sorted(char_vocab))}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create input and output texts"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['nwod', 'eht', 'tibbar', 'eloh']\n"
]
}
],
"source": [
"def reverse_words(words):\n",
" reversed_words = []\n",
" for word in words:\n",
" reversed_words.append(word[::-1])\n",
" return reversed_words\n",
"\n",
"test_words = [\"down\", \"the\", \"rabbit\", \"hole\"]\n",
"print(reverse_words(test_words))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"maxlen = 36\n"
]
}
],
"source": [
"SEQLEN = 4\n",
"STEP = 1\n",
"\n",
"input_texts = []\n",
"output_texts = []\n",
"for i in range(len(words) - SEQLEN):\n",
" input_words = words[i:i + SEQLEN]\n",
" input_texts.append(\" \".join(input_words))\n",
" output_texts.append(\" \".join(reverse_words(input_words)))\n",
"\n",
"maxlen = max([len(x) for x in input_texts])\n",
"print(\"maxlen =\", maxlen)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Vectorize input and output texts"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"X = np.zeros((len(input_texts), maxlen, nb_chars), dtype=np.bool)\n",
"y = np.zeros((len(output_texts), maxlen, nb_chars), dtype=np.bool)\n",
"for i, input_text in enumerate(input_texts):\n",
" input_text = input_text.ljust(maxlen)\n",
" for j, ch in enumerate([c for c in input_text]):\n",
" X[i, j, char2index[ch]] = 1\n",
"for i, output_text in enumerate(output_texts):\n",
" output_text = output_text.ljust(maxlen)\n",
" for j, ch in enumerate([c for c in output_text]):\n",
" y[i, j, char2index[ch]] = 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Split Data into training and validation"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"Xtrain, Xval, ytrain, yval = train_test_split(X, y, test_size=0.1,\n",
" random_state=42)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Build model\n",
"\n",
"Our model is built as two LSTMs, an encoder and a decoder. The encoder writes a single vector per sequence to a context vector, which is then repeated into a sequence of size maxlen, which is fed into the decoder. The decoder returns a vector for each character in the sequence, each of which is sent to a Dense (fully connected) layer with Softmax activation."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"model = Sequential()\n",
"model.add(LSTM(512, input_shape=(maxlen, nb_chars), return_sequences=False))\n",
"model.add(RepeatVector(maxlen))\n",
"model.add(LSTM(512, return_sequences=True))\n",
"model.add(TimeDistributed(Dense(nb_chars)))\n",
"model.add(Activation(\"softmax\"))\n",
"\n",
"model.compile(loss=\"categorical_crossentropy\", optimizer=\"adam\",\n",
" metrics=[\"accuracy\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Test Model"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"==================================================\n",
"Iteration-#: 0\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 433s - loss: 1.4564 - acc: 0.6134 - val_loss: 1.3376 - val_acc: 0.6199\n",
"input: [you , wo n't], expected: [uoy , ow t'n], got: []\n",
"input: [a pleasant temper ,], expected: [a tnasaelp repmet ,], got: [eea eeeaa]\n",
"input: [the place where it], expected: [eht ecalp erehw ti], got: [eeeeeeee eeee]\n",
"input: [how far we go], expected: [woh raf ew og], got: [e]\n",
"input: [politely as she could], expected: [yletilop sa ehs dluoc], got: [eellll ee]\n",
"input: [if he were trying], expected: [fi eh erew gniyrt], got: [ee ee]\n",
"input: [? ' said alice], expected: [? ' dias ecila], got: [ii]\n",
"input: [will prosecute you. --], expected: [lliw etucesorp .uoy --], got: [eelll eooo]\n",
"input: [and opened their eyes], expected: [dna denepo rieht seye], got: [eee eeeee]\n",
"input: [hardly hear the words], expected: [yldrah raeh eht sdrow], got: [eeeeeee eeea]\n",
"==================================================\n",
"Iteration-#: 1\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 440s - loss: 1.2020 - acc: 0.6382 - val_loss: 1.0665 - val_acc: 0.6594\n",
"input: [then the other ,], expected: [neht eht rehto ,], got: [ent ettttthhh]\n",
"input: [room ! ' said], expected: [moor ! ' dias], got: [roo aaa]\n",
"input: [sort of circle ,], expected: [tros fo elcric ,], got: [fo f cccccc ,]\n",
"input: [sage , as he], expected: [egas , sa eh], got: [eaa hh]\n",
"input: [, she kept fanning], expected: [, ehs tpek gninnaf], got: [, enn nnnnnnnnnn]\n",
"input: [so proud as all], expected: [os duorp sa lla], got: [ooooooo aaa aaa]\n",
"input: [but do cats eat], expected: [tub od stac tae], got: [tuuuu aaa]\n",
"input: [nothing else to say], expected: [gnihton esle ot yas], got: [nnnnnnntttt a]\n",
"input: [underneath her chin :], expected: [htaenrednu reh nihc :], got: [dnnnnnneee hhhhhhhhh]\n",
"input: [the mock turtle .], expected: [eht kcom eltrut .], got: [eht eettttcccc]\n",
"==================================================\n",
"Iteration-#: 2\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 439s - loss: 0.9643 - acc: 0.6905 - val_loss: 0.8505 - val_acc: 0.7275\n",
"input: [, i 'd hardly], expected: [, i d' yldrah], got: [, i di ddrad]\n",
"input: [a great interest in], expected: [a taerg tseretni ni], got: [a ett gniiiit t]\n",
"input: [, just at present], expected: [, tsuj ta tneserp], got: [, tuus sut eeeee]\n",
"input: [alice began in a], expected: [ecila nageb ni a], got: [ecil eaaa a]\n",
"input: [none of my own], expected: [enon fo ym nwo], got: [nnnn fo o oo]\n",
"input: [to the mock turtle], expected: [ot eht kcom eltrut], got: [tt eht eett ttttt]\n",
"input: [. 'i can see], expected: [. i' nac ees], got: [. ii eaa eea]\n",
"input: [jumped up , and], expected: [depmuj pu , dna], got: [eeuppp u dna]\n",
"input: [, ( she had], expected: [, ( ehs dah], got: [, ( hhh dhh]\n",
"input: [of things at all], expected: [fo sgniht ta lla], got: [oo ghitt aa laa]\n",
"==================================================\n",
"Iteration-#: 3\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 439s - loss: 0.7840 - acc: 0.7452 - val_loss: 0.7246 - val_acc: 0.7634\n",
"input: [arms , took the], expected: [smra , koot eht], got: [ssam , tnott tt]\n",
"input: [ought to be a], expected: [thguo ot eb a], got: [tooot tt ea]\n",
"input: [flamingo and brought it], expected: [ognimalf dna thguorb ti], got: [gnillabf foo gooob ti]\n",
"input: [animals with their fur], expected: [slamina htiw rieht ruf], got: [glilaaw tiht tii rrff]\n",
"input: [does n't begin .], expected: [seod t'n nigeb .], got: [deood nn nnieb .]\n",
"input: [replied : 'what 's], expected: [deilper : tahw' s'], got: [eleerrr . tiww ']\n",
"input: [' 'what did they], expected: [' tahw' did yeht], got: [' daa'' di' ee]\n",
"input: [, i 'll look], expected: [, i ll' kool], got: [, i llll koo]\n",
"input: [us dry would be], expected: [su yrd dluow eb], got: [uu duy deuu ii]\n",
"input: [life . indeed ,], expected: [efil . deedni ,], got: [elil , deeddd ,]\n",
"==================================================\n",
"Iteration-#: 4\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 448s - loss: 0.6556 - acc: 0.7853 - val_loss: 0.6616 - val_acc: 0.7828\n",
"input: [just been picked up], expected: [tsuj neeb dekcip pu], got: [eeuj eeis dkippp]\n",
"input: [that was lying under], expected: [taht saw gniyl rednu], got: [taht saw dninn ener]\n",
"input: [! the antipathies ,], expected: [! eht seihtapitna ,], got: [. eht nnitiiiii ,]\n",
"input: [friend of mine --], expected: [dneirf fo enim --], got: [deifff f nnimm --]\n",
"input: [it , and fortunately], expected: [ti , dna yletanutrof], got: [ti a dnn nntttttton]\n",
"input: [nurse it a bit], expected: [esrun ti a tib], got: [serrw ti a tii]\n",
"input: [finished the first verse], expected: [dehsinif eht tsrif esrev], got: [deiiiif fih seiii eerre]\n",
"input: ['d rather not .], expected: [d' rehtar ton .], got: [d' reerr oo ..]\n",
"input: [a knife , it], expected: [a efink , ti], got: [, enilf , ti]\n",
"input: [, 'that they 'd], expected: [, taht' yeht d'], got: [, tahtt eeht y]\n",
"==================================================\n",
"Iteration-#: 5\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 447s - loss: 0.5882 - acc: 0.8069 - val_loss: 0.6302 - val_acc: 0.7946\n",
"input: [march hare . 'it], expected: [hcram erah . ti'], got: [rcaaa rrhh . ti']\n",
"input: [elbow . ' on], expected: [woble . ' no], got: [wooow ! ' on]\n",
"input: [not , would not], expected: [ton , dluow ton], got: [non , dloow oo]\n",
"input: [at having found out], expected: [ta gnivah dnuof tuo], got: [aa gnihaa duuo tot]\n",
"input: [choked and had to], expected: [dekohc dna dah ot], got: [deooo dna dno t]\n",
"input: [head impatiently , and], expected: [daeh yltneitapmi , dna], got: [daah yeltttiiiii , ddaa]\n",
"input: ['ll have you executed], expected: [ll' evah uoy detucexe], got: [laa eva' uuy eeeeuuu]\n",
"input: [the last word with], expected: [eht tsal drow htiw], got: [eht saaw doow thhw]\n",
"input: [way through the neighbouring], expected: [yaw hguorht eht gniruobhgien], got: [tuh hhuuh eht ggioooorrrr]\n",
"input: [again -- '' before], expected: [niaga -- '' erofeb], got: [niaaa ---'' eeeef]\n",
"==================================================\n",
"Iteration-#: 6\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 442s - loss: 0.5288 - acc: 0.8259 - val_loss: 0.5334 - val_acc: 0.8248\n",
"input: [i did n't !], expected: [i did t'n !], got: [i did t' !]\n",
"input: [stupid ) , whether], expected: [diputs ) , rehtehw], got: [deipus , i rrhhhhw]\n",
"input: [and cried . 'come], expected: [dna deirc . emoc'], got: [dna ecira . ecoo']\n",
"input: [room ! ' said], expected: [moor ! ' dias], got: [rooo ! ' dias]\n",
"input: [as she had made], expected: [sa ehs dah edam], got: [sa ehs ehs daam]\n",
"input: [might find another key], expected: [thgim dnif rehtona yek], got: [tiiii dnof deennn ee]\n",
"input: [that she was in], expected: [taht ehs saw ni], got: [taht ehs si si]\n",
"input: [i can guess that], expected: [i nac sseug taht], got: [i scc ssaub ttht]\n",
"input: [join the dance ?], expected: [nioj eht ecnad ?], got: [nnnb eht dcaab !]\n",
"input: [for repeating his remark], expected: [rof gnitaeper sih kramer], got: [rrr ggiitrrrr ta eemaaa]\n",
"==================================================\n",
"Iteration-#: 7\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 448s - loss: 0.4789 - acc: 0.8424 - val_loss: 0.5748 - val_acc: 0.8209\n",
"input: [and swam slowly back], expected: [dna maws ylwols kcab], got: [sna saaw yluomw ylaw]\n",
"input: [with me ! there], expected: [htiw em ! ereht], got: [hiit mm e eeeht]\n",
"input: [no use speaking to], expected: [on esu gnikaeps ot], got: [oo eee gnikkaps ot]\n",
"input: [the hatter grumbled :], expected: [eht rettah delbmurg :], got: [eht eettah eldrrrrb -]\n",
"input: [a pity ! ''], expected: [a ytip ! ''], got: [a tiip ! '']\n",
"input: ['sit down , both], expected: [tis' nwod , htob], got: [sii' tood , tobb]\n",
"input: [it ? ' alice], expected: [ti ? ' ecila], got: [ti ? ' ecila]\n",
"input: [. ' 'once upon], expected: [. ' ecno' nopu], got: [. ' ecoo' nuoo]\n",
"input: [she was beginning to], expected: [ehs saw gninnigeb ot], got: [ehs saw gninneee ot]\n",
"input: [yet , please your], expected: [tey , esaelp ruoy], got: [yee , elaeee uoy]\n",
"==================================================\n",
"Iteration-#: 8\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 449s - loss: 0.4389 - acc: 0.8557 - val_loss: 0.4820 - val_acc: 0.8407\n",
"input: [alice could see ,], expected: [ecila dluoc ees ,], got: [ecila dluoc ees ,]\n",
"input: [' said alice ;], expected: [' dias ecila ;], got: [' dias ecila ;]\n",
"input: [' exclaimed alice .], expected: [' demialcxe ecila .], got: [' eeiiaeeeeeeeci]\n",
"input: [queen to-day ? '], expected: [neeuq yad-ot ? '], got: [eeeuq ylbbbb ? ']\n",
"input: [it , and fortunately], expected: [ti , dna yletanutrof], got: [, t nnn ylltttttnoa]\n",
"input: [must be , '], expected: [tsum eb , '], got: [tsum eb , ']\n",
"input: [this they slipped the], expected: [siht yeht deppils eht], got: [tiht ylht deepppp eht]\n",
"input: [again , dear !], expected: [niaga , raed !], got: [tigga , rree !]\n",
"input: [own ears for having], expected: [nwo srae rof gnivah], got: [wow rraa raa gniras]\n",
"input: ['i keep them to], expected: [i' peek meht ot], got: [i' eeek hht .]\n",
"==================================================\n",
"Iteration-#: 9\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 442s - loss: 0.4336 - acc: 0.8589 - val_loss: 0.3787 - val_acc: 0.8757\n",
"input: [tell you more than], expected: [llet uoy erom naht], got: [llet uoy rrom naht]\n",
"input: [for , you see], expected: [rof , uoy ees], got: [rof , uoy ees]\n",
"input: [might appear to others], expected: [thgim raeppa ot srehto], got: [tagmm eaaaap ot rsrrot]\n",
"input: [is may it wo], expected: [si yam ti ow], got: [si yas ti ot]\n",
"input: [executed , as sure], expected: [detucexe , sa erus], got: [detneeeb , s eruuc]\n",
"input: [for this time the], expected: [rof siht emit eht], got: [fof hiht emit eht]\n",
"input: [of present ! '], expected: [fo tneserp ! '], got: [fo tteeeee ! ']\n",
"input: [finished it off .], expected: [dehsinif ti ffo .], got: [deiiiiif oi foo .]\n",
"input: [and book-shelves ; here], expected: [dna sevlehs-koob ; ereh], got: [dna eeeo---ooooc : eeeh]\n",
"input: [. 'cheshire puss ,], expected: [. erihsehc' ssup ,], got: [. ecihhhh' ssus ,]\n",
"==================================================\n",
"Iteration-#: 10\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 441s - loss: 0.4010 - acc: 0.8691 - val_loss: 0.4724 - val_acc: 0.8440\n",
"input: [, they seemed to], expected: [, yeht demees ot], got: [, yeht deeees ot]\n",
"input: [just been picked up], expected: [tsuj neeb dekcip pu], got: [tsuj neeb dekiip pu]\n",
"input: [kept all my limbs], expected: [tpek lla ym sbmil], got: [tae llll a mmmmm]\n",
"input: [of her age knew], expected: [fo reh ega wenk], got: [fo reh eae nnik]\n",
"input: [i 've been changed], expected: [i ev' neeb degnahc], got: [' ev' eeeb dennneb]\n",
"input: [exclaimed . 'you know], expected: [demialcxe . uoy' wonk], got: [dlliaeeea . uoy wnok]\n",
"input: [are you getting on], expected: [era uoy gnitteg no], got: [rra uo ggntteg no]\n",
"input: [; but , on], expected: [; tub , no], got: [; tub , nn]\n",
"input: [as prizes . there], expected: [sa sezirp . ereht], got: [sa siiprr . eeeht]\n",
"input: [a natural way again], expected: [a larutan yaw niaga], got: [a duuutaa yaa nniwa]\n",
"==================================================\n",
"Iteration-#: 11\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 441s - loss: 0.3479 - acc: 0.8865 - val_loss: 0.3868 - val_acc: 0.8742\n",
"input: [deep sigh , 'i], expected: [peed hgis , i'], got: [deep sses , ii]\n",
"input: [being that person ,], expected: [gnieb taht nosrep ,], got: [gnieb taht nopprr ,]\n",
"input: [alice . 'you did], expected: [ecila . uoy' did], got: [ecila . uoy' did]\n",
"input: [white kid gloves in], expected: [etihw dik sevolg ni], got: [etihw dda sevvvv si]\n",
"input: [always hated cats :], expected: [syawla detah stac :], got: [yaalla eeaaa taaa !]\n",
"input: [. ' on which], expected: [. ' no hcihw], got: [. ' oo hcihw]\n",
"input: [' chapter xii .], expected: [' retpahc iix .], got: [' retpahc eip .]\n",
"input: [very difficult question .], expected: [yrev tluciffid noitseuq .], got: [yrev yutsiiiiid ttiuqq]\n",
"input: [crossed over to the], expected: [dessorc revo ot eht], got: [ssroroa rroo ot eht]\n",
"input: [lady tells us a], expected: [ydal sllet su a], got: [ylal sllet sa a]\n",
"==================================================\n",
"Iteration-#: 12\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 442s - loss: 0.3246 - acc: 0.8943 - val_loss: 0.4106 - val_acc: 0.8701\n",
"input: [the picture . )], expected: [eht erutcip . )], got: [eht eetttuc . )]\n",
"input: [sleep , 'that ``], expected: [peels , taht' ``], got: [eeees , taht' ``]\n",
"input: [continued as follows the], expected: [deunitnoc sa swollof eht], got: [denniuuoc lla swolloa eht]\n",
"input: [to draw , you], expected: [ot ward , uoy], got: [ot rard , uoy]\n",
"input: [looked anxiously at the], expected: [dekool ylsuoixna ta eht], got: [denool ylaiilnnn aaehht]\n",
"input: [she thought . 'but], expected: [ehs thguoht . tub'], got: [ehs thguoht . tub']\n",
"input: [to go ! let], expected: [ot og ! tel], got: [ot og a tee]\n",
"input: [small again . '], expected: [llams niaga . '], got: [llams niala . '']\n",
"input: [was his first speech], expected: [saw sih tsrif hceeps], got: [siw sih sssif eeehs]\n",
"input: ['jury-men ' would have], expected: [nem-yruj' ' dluow evah], got: [ynnejeus lluo' eaah]\n",
"==================================================\n",
"Iteration-#: 13\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 443s - loss: 0.3212 - acc: 0.8955 - val_loss: 0.3481 - val_acc: 0.8875\n",
"input: [pet : 'dinah 's], expected: [tep : hanid' s'], got: [ttp : hini'' s']\n",
"input: [comfort , one way], expected: [trofmoc , eno yaw], got: [tootooc , wn aaw]\n",
"input: [sides at once .], expected: [sedis ta ecno .], got: [sddis ta ecna .]\n",
"input: [e -- e --], expected: [e -- e --], got: [e -- ----]\n",
"input: [: -- 'you may], expected: [: -- uoy' yam], got: [: -- uoy' yam]\n",
"input: [hare said -- '], expected: [erah dias -- '], got: [erah dias -- ']\n",
"input: ['you might just as], expected: [uoy' thgim tsuj sa], got: [uoy' hhgi' tsu s]\n",
"input: [everything 's curious today], expected: [gnihtyreve s' suoiruc yadot], got: [gnihteree si suooiu dauu]\n",
"input: [room ! ' said], expected: [moor ! ' dias], got: [room ! ' dias]\n",
"input: [' said alice .], expected: [' dias ecila .], got: [' dias ecila .]\n",
"==================================================\n",
"Iteration-#: 14\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 444s - loss: 0.2849 - acc: 0.9076 - val_loss: 0.3204 - val_acc: 0.8981\n",
"input: [the two sides of], expected: [eht owt sedis fo], got: [eht oht sddsw fo]\n",
"input: [there seemed to be], expected: [ereht demees ot eb], got: [ereht demees ot eb]\n",
"input: [and near the king], expected: [dna raen eht gnik], got: [dna reen eht gnik]\n",
"input: [i wonder ? '], expected: [i rednow ? '], got: [i rednow ? ']\n",
"input: [room ! ' said], expected: [moor ! ' dias], got: [roor ! ' dias]\n",
"input: [so bill 's got], expected: [os llib s' tog], got: [ob llis s' oot]\n",
"input: ['d hardly finished the], expected: [d' yldrah dehsinif eht], got: [y' ylddhh dehsiif eht]\n",
"input: [glad to find her], expected: [dalg ot dnif reh], got: [dgag ot dnif reh]\n",
"input: [a little now and], expected: [a elttil won dna], got: [a elttil wwo dna]\n",
"input: [it how far we], expected: [ti woh raf ew], got: [ti woh rww eh]\n",
"==================================================\n",
"Iteration-#: 15\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 443s - loss: 0.2592 - acc: 0.9159 - val_loss: 0.2356 - val_acc: 0.9235\n",
"input: [' interrupted alice .], expected: [' detpurretni ecila .], got: [' detrerreto ecila]\n",
"input: [, and looked at], expected: [, dna dekool ta], got: [, dna dekool ta]\n",
"input: [mercia and northumbria ,], expected: [aicrem dna airbmuhtron ,], got: [riiric dna ribmuttuuom ,]\n",
"input: [triumphantly , pointing to], expected: [yltnahpmuirt , gnitniop ot], got: [ylttattpptmm , gniniipp ot]\n",
"input: [thought alice ; 'i], expected: [thguoht ecila ; i'], got: [thguoht ecila ; i']\n",
"input: [cheerfully he seems to], expected: [yllufreehc eh smees ot], got: [yllfuureec yb seees ot]\n",
"input: [, 'and the moral], expected: [, dna' eht larom], got: [, dna' eht llrom]\n",
"input: [friend of mine --], expected: [dneirf fo enim --], got: [deirff fo eniu --]\n",
"input: [began again : 'ou], expected: [nageb niaga : uo'], got: [nageb niaga : uo']\n",
"input: [a well ? '], expected: [a llew ? '], got: [a llew ? ']\n",
"==================================================\n",
"Iteration-#: 16\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 444s - loss: 0.2731 - acc: 0.9132 - val_loss: 0.2830 - val_acc: 0.9082\n",
"input: [, very carefully ,], expected: [, yrev ylluferac ,], got: [, yrev yllaarrrc ,]\n",
"input: [herself , ( not], expected: [flesreh , ( ton], got: [flesreh , ' too]\n",
"input: [! ' chorus .], expected: [! ' surohc .], got: [! ' sroocc .]\n",
"input: [axes , ' said], expected: [sexa , ' dias], got: [enae , ' dias]\n",
"input: [pleaded poor alice .], expected: [dedaelp roop ecila .], got: [dedaepp roop ecila .]\n",
"input: [thought alice , 'or], expected: [thguoht ecila , ro'], got: [thguoht ecila , ro']\n",
"input: [, very carefully ,], expected: [, yrev ylluferac ,], got: [, yrev yllaarrrc ,]\n",
"input: [and i 've tried], expected: [dna i ev' deirt], got: [dna i ev' deirt]\n",
"input: [i know . silence], expected: [i wonk . ecnelis], got: [. wonk . eciils]\n",
"input: [came upon a little], expected: [emac nopu a elttil], got: [emac noop a elttil]\n",
"==================================================\n",
"Iteration-#: 17\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 445s - loss: 0.2338 - acc: 0.9251 - val_loss: 0.2304 - val_acc: 0.9256\n",
"input: [the cat , as], expected: [eht tac , sa], got: [eht tac , sa]\n",
"input: [one , they gave], expected: [eno , yeht evag], got: [eno , yeht evag]\n",
"input: [. as there seemed], expected: [. sa ereht demees], got: [. sa ereht demees]\n",
"input: [said the pigeon in], expected: [dias eht noegip ni], got: [dias eht nnegip ni]\n",
"input: [! wow ! wow], expected: [! wow ! wow], got: [! woh ! wow]\n",
"input: [, and was delighted], expected: [, dna saw dethgiled], got: [, dna saw dehgggled]\n",
"input: [not open any of], expected: [ton nepo yna fo], got: [oon nnep yna fo]\n",
"input: [stupid ) , whether], expected: [diputs ) , rehtehw], got: [dippus , ' reetehw]\n",
"input: [for a baby :], expected: [rof a ybab :], got: [rof a ybbb :]\n",
"input: [! the antipathies ,], expected: [! eht seihtapitna ,], got: [! eht atitttaaa ,]\n",
"==================================================\n",
"Iteration-#: 18\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 445s - loss: 0.2104 - acc: 0.9329 - val_loss: 0.3086 - val_acc: 0.9074\n",
"input: [the dormouse . 'do], expected: [eht esuomrod . od'], got: [eht esuomrod . on']\n",
"input: [but it all came], expected: [tub ti lla emac], got: [tub ti lla emac]\n",
"input: [to change them --], expected: [ot egnahc meht --], got: [ot eggaah meht --]\n",
"input: [eagerly , and he], expected: [ylregae , dna eh], got: [ylreea , dna eh]\n",
"input: [may not have lived], expected: [yam ton evah devil], got: [yam ton evah eevil]\n",
"input: [to begin with .], expected: [ot nigeb htiw .], got: [ot nigeb htiw .]\n",
"input: [, ' said the], expected: [, ' dias eht], got: [, ' dias eht]\n",
"input: [a puzzled expression that], expected: [a delzzup noisserpxe taht], got: [a dezzeec nnsseeeep naht]\n",
"input: [a large plate came], expected: [a egral etalp emac], got: [a egral etaal emac]\n",
"input: [little fishes in with], expected: [elttil sehsif ni htiw], got: [elttil seesif ni htiw]\n",
"==================================================\n",
"Iteration-#: 19\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 445s - loss: 0.2228 - acc: 0.9301 - val_loss: 0.3177 - val_acc: 0.8990\n",
"input: ['fury said to a], expected: [yruf' dias ot a], got: [yruu' diasoot a]\n",
"input: [, and looking at], expected: [, dna gnikool ta], got: [, dna gnikool ta]\n",
"input: [tone . 'pray do], expected: [enot . yarp' od], got: [enot . ydaa' od]\n",
"input: [just time to begin], expected: [tsuj emit ot nigeb], got: [tsuj emit ot nieeb]\n",
"input: [was looking about for], expected: [saw gnikool tuoba rof], got: [sww gnikool tuoba rof]\n",
"input: [see , as they], expected: [ees , sa yeht], got: [ees , sa yeh]\n",
"input: [fly up into a], expected: [ylf pu otni a], got: [yle pu tnna a]\n",
"input: [only a child !], expected: [ylno a dlihc !], got: [ylno ! dlihc !]\n",
"input: [your flamingo . shall], expected: [ruoy ognimalf . llahs], got: [yuoy gnilban lllas]\n",
"input: [latin grammar , 'a], expected: [nital rammarg , a'], got: [gnila yaammmm , aa]\n",
"==================================================\n",
"Iteration-#: 20\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 448s - loss: 0.2363 - acc: 0.9260 - val_loss: 0.1985 - val_acc: 0.9370\n",
"input: [went on , turning], expected: [tnew no , gninrut], got: [tnew no , gninrut]\n",
"input: [it in the air], expected: [ti ni eht ria], got: [ti ni eht ria]\n",
"input: [, in a rather], expected: [, ni a rehtar], got: [, ni a rehtar]\n",
"input: [was , ' the], expected: [saw , ' eht], got: [saw , ' eht]\n",
"input: [it might happen any], expected: [ti thgim neppah yna], got: [ti thgim neppah nnp]\n",
"input: [two , and the], expected: [owt , dna eht], got: [owt , dna eht]\n",
"input: [came up to the], expected: [emac pu ot eht], got: [emac pu ot eht]\n",
"input: [upon their faces .], expected: [nopu rieht secaf .], got: [nopu rihht sccaf .]\n",
"input: [it was quite out], expected: [ti saw etiuq tuo], got: [ti saw etiuq tuo]\n",
"input: [-- i hope i], expected: [-- i epoh i], got: [-- i esih i]\n",
"==================================================\n",
"Iteration-#: 21\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 451s - loss: 0.1837 - acc: 0.9422 - val_loss: 0.3163 - val_acc: 0.9022\n",
"input: [her great delight it], expected: [reh taerg thgiled ti], got: [reh taerg thgiged ti]\n",
"input: [? ' the mouse], expected: [? ' eht esuom], got: [? ' eht esuom]\n",
"input: [next the ten courtiers], expected: [txen eht net sreitruoc], got: [txen eet eeh rriitruc]\n",
"input: [it trot away quietly], expected: [ti tort yawa ylteiuq], got: [ti toom yaww ylttiut]\n",
"input: [be sure , this], expected: [eb erus , siht], got: [eb eros , siht]\n",
"input: [this , that she], expected: [siht , taht ehs], got: [siht , saht ehs]\n",
"input: [hare said -- '], expected: [erah dias -- '], got: [erah dias -- ']\n",
"input: [, and a scroll], expected: [, dna a llorcs], got: [, dna a llrohs]\n",
"input: [by mistake ; and], expected: [yb ekatsim ; dna], got: [yb ekttiim ; dna]\n",
"input: [take care of themselves], expected: [ekat erac fo sevlesmeht], got: [ekat erah fo semmmemeht]\n",
"==================================================\n",
"Iteration-#: 22\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 467s - loss: 0.1925 - acc: 0.9391 - val_loss: 0.2015 - val_acc: 0.9358\n",
"input: [show you ! a], expected: [wohs uoy ! a], got: [woss uoy ! a]\n",
"input: [. lastly , she], expected: [. yltsal , ehs], got: [. ylttaa , ehs]\n",
"input: [stingy about it ,], expected: [ygnits tuoba ti ,], got: [ynitts tuoba ti ,]\n",
"input: [he seems to grin], expected: [eh smees ot nirg], got: [eh smees ot nirg]\n",
"input: [one , but it], expected: [eno , tub ti], got: [eno , tub ti]\n",
"input: [sleepy voice behind her], expected: [ypeels eciov dniheb reh], got: [ylevee ciob diiheb reh]\n",
"input: [hurry , muttering to], expected: [yrruh , gnirettum ot], got: [yruu , gnirrtrum ot]\n",
"input: [more questions about it], expected: [erom snoitseuq tuoba ti], got: [eroo snittssuus tuoba ti]\n",
"input: [' would have done], expected: [' dluow evah enod], got: [' dluow evah edod]\n",
"input: [, very carefully ,], expected: [, yrev ylluferac ,], got: [, yrev ylfufcaec ,]\n",
"==================================================\n",
"Iteration-#: 23\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 467s - loss: 0.1774 - acc: 0.9444 - val_loss: 0.1976 - val_acc: 0.9368\n",
"input: [, in her haste], expected: [, ni reh etsah], got: [, ni reh etaat]\n",
"input: [-- will the roof], expected: [-- lliw eht foor], got: [-- lliw eht roof]\n",
"input: [only say , 'i], expected: [ylno yas , i'], got: [ylno yas , i']\n",
"input: [, in her haste], expected: [, ni reh etsah], got: [, ni reh etaat]\n",
"input: [, after thinking a], expected: [, retfa gnikniht a], got: [, retfa gnikniht a]\n",
"input: [hurriedly went on ,], expected: [yldeirruh tnew no ,], got: [yllrdrrhs tnww no ,]\n",
"input: [waistcoat-pocket , and looked], expected: [tekcop-taoctsiaw , dna dekool], got: [yattattpttttccc ddkooo]\n",
"input: ['off with his head], expected: [ffo' htiw sih daeh], got: [ffo' hthw sih daeh]\n",
"input: [rest , between yourself], expected: [tser , neewteb flesruoy], got: [tsee , eeeeeew flesreof]\n",
"input: [( she was obliged], expected: [( ehs saw degilbo], got: [( ehs saw degglbb]\n",
"==================================================\n",
"Iteration-#: 24\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 467s - loss: 0.1797 - acc: 0.9444 - val_loss: 0.3241 - val_acc: 0.8967\n",
"input: [the schoolroom , and], expected: [eht moorloohcs , dna], got: [eht moooooooocc , nn]\n",
"input: [said the queen ,], expected: [dias eht neeuq ,], got: [dias eht neeuq ,]\n",
"input: [was quite surprised to], expected: [saw etiuq desirprus ot], got: [daw etiuq deiiprrus ot]\n",
"input: [, ( she had], expected: [, ( ehs dah], got: [, ( ehs dah]\n",
"input: [it does . '], expected: [ti seod . '], got: [ti seod . ']\n",
"input: [well to say 'drink], expected: [llew ot yas knird'], got: [lleb ot laa gniyr']\n",
"input: [if i was ,], expected: [fi i saw ,], got: [fi i ssw ,]\n",
"input: [a great hurry .], expected: [a taerg yrruh .], got: [a taerg yrruh .]\n",
"input: [tone . 'pray do], expected: [enot . yarp' od], got: [ekot . yrau' od]\n",
"input: [at poor alice ,], expected: [ta roop ecila ,], got: [ta roop ecilp ,]\n",
"==================================================\n",
"Iteration-#: 25\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 465s - loss: 0.1487 - acc: 0.9532 - val_loss: 0.2007 - val_acc: 0.9357\n",
"input: [a great hurry ;], expected: [a taerg yrruh ;], got: [a taerg yrrut ;]\n",
"input: [said alice , as], expected: [dias ecila , sa], got: [dias ecila , sa]\n",
"input: ['what are they doing], expected: [tahw' era yeht gniod], got: [tahw' yey yeht gniog]\n",
"input: [, dear ! ''], expected: [, raed ! ''], got: [, raed ! '']\n",
"input: [said , with a], expected: [dias , htiw a], got: [dias , htiw a]\n",
"input: [glad to find her], expected: [dalg ot dnif reh], got: [dalg ot dnif reh]\n",
"input: [that makes them sour], expected: [taht sekam meht ruos], got: [taht ssnam eeht ruos]\n",
"input: [in spite of all], expected: [ni etips fo lla], got: [ni etips fo lla]\n",
"input: ['oh , do n't], expected: [ho' , od t'n], got: [ho' , od t'n]\n",
"input: [table and the little], expected: [elbat dna eht elttil], got: [elbaa dna eht elttil]\n",
"==================================================\n",
"Iteration-#: 26\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 463s - loss: 0.1549 - acc: 0.9523 - val_loss: 0.2007 - val_acc: 0.9393\n",
"input: [with me ! there], expected: [htiw em ! ereht], got: [htiw em ! ereht]\n",
"input: [no larger : still], expected: [on regral : llits], got: [oo eegall : llits]\n",
"input: [salmon , and so], expected: [nomlas , dna os], got: [nomlas , dna os]\n",
"input: [to the seaside once], expected: [ot eht edisaes ecno], got: [ot eht edneses ecno]\n",
"input: [left to make one], expected: [tfel ot ekam eno], got: [tfef ot emam eno]\n",
"input: [the course , here], expected: [eht esruoc , ereh], got: [eht esruoc , reh]\n",
"input: [i wonder what i], expected: [i rednow tahw i], got: [i rednow taww i]\n",
"input: [she succeeded in getting], expected: [ehs dedeeccus ni gnitteg], got: [ehs dedeeccuc ti gnitteg]\n",
"input: ['she boxed the queen], expected: [ehs' dexob eht neeuq], got: [ehs' dedob eht neeuq]\n",
"input: [the law , and], expected: [eht wal , dna], got: [eht wal , dna]\n",
"==================================================\n",
"Iteration-#: 27\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 467s - loss: 0.1289 - acc: 0.9598 - val_loss: 0.1345 - val_acc: 0.9572\n",
"input: [to ask . 'suppose], expected: [ot ksa . esoppus'], got: [ot kka . espppps']\n",
"input: [' exclaimed alice .], expected: [' demialcxe ecila .], got: [' deiiaccxe ecila .]\n",
"input: [took up the little], expected: [koot pu eht elttil], got: [koot pu eht elttil]\n",
"input: [their mouths ; and], expected: [rieht shtuom ; dna], got: [rieht ssuuom ; dna]\n",
"input: [story 'you ca n't], expected: [yrots uoy' ac t'n], got: [yrots uoo' ac tan]\n",
"input: [to begin again ,], expected: [ot nigeb niaga ,], got: [ot nigeb niaga ,]\n",
"input: [the cupboards as she], expected: [eht sdraobpuc sa ehs], got: [eht srruoropp sa ehs]\n",
"input: [* chapter ii .], expected: [* retpahc ii .], got: [* retpahc ii .]\n",
"input: [last came a rumbling], expected: [tsal emac a gnilbmur], got: [tsal emac a gnilbmur]\n",
"input: [his note-book hastily .], expected: [sih koob-eton ylitsah .], got: [ei' koobooono ylstsah .]\n",
"==================================================\n",
"Iteration-#: 28\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 459s - loss: 0.1745 - acc: 0.9474 - val_loss: 0.1597 - val_acc: 0.9498\n",
"input: [as yet . '], expected: [sa tey . '], got: [sa tey . ']\n",
"input: [of having nothing to], expected: [fo gnivah gnihton ot], got: [fo gnivah gnihton ot]\n",
"input: [: 'it 's generally], expected: [: ti' s' yllareneg], got: [: ti' e' yllaerneg]\n",
"input: [, and you 'll], expected: [, dna uoy ll'], got: [, dna uoy ll']\n",
"input: [see what was the], expected: [ees tahw saw eht], got: [ees tahw saw eht]\n",
"input: [not otherwise than what], expected: [ton esiwrehto naht tahw], got: [ton esohrthht taht tahw]\n",
"input: [she felt that it], expected: [ehs tlef taht ti], got: [ehs tlef taht ti]\n",
"input: [, ' said the], expected: [, ' dias eht], got: [, ' dias eht]\n",
"input: [hot tureen ! who], expected: [toh neerut ! ohw], got: [tot neerut ! ohw]\n",
"input: ['yes , that 's], expected: [sey' , taht s'], got: [sey' , taht s']\n",
"==================================================\n",
"Iteration-#: 29\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 448s - loss: 0.1499 - acc: 0.9540 - val_loss: 0.1595 - val_acc: 0.9502\n",
"input: [it out into the], expected: [ti tuo otni eht], got: [ti tuo otni eht]\n",
"input: [does n't seem to], expected: [seod t'n mees ot], got: [seod t'n mees ot]\n",
"input: [time , as it], expected: [emit , sa ti], got: [emit , sa ti]\n",
"input: [at all . soup], expected: [ta lla . puos], got: [ta lla . puos]\n",
"input: [the direction in which], expected: [eht noitcerid ni hcihw], got: [eht noittcrid ni hcihw]\n",
"input: [. 'fifteenth , '], expected: [. htneetfif' , '], got: [. htnhttein' , ']\n",
"input: [done such a thing], expected: [enod hcus a gniht], got: [eeod hcus a gniht]\n",
"input: [by the time she], expected: [yb eht emit ehs], got: [yb eht emit ehs]\n",
"input: [any more -- as], expected: [yna erom -- sa], got: [yna erom -- sa]\n",
"input: [right way of speaking], expected: [thgir yaw fo gnikaeps], got: [thgir yaw po gnikeeps]\n",
"==================================================\n",
"Iteration-#: 30\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 448s - loss: 0.1382 - acc: 0.9579 - val_loss: 0.1671 - val_acc: 0.9479\n",
"input: [the gryphon lifted up], expected: [eht nohpyrg detfil pu], got: [eht nohpyrg detnip f]\n",
"input: [, 'in this way], expected: [, ni' siht yaw], got: [, nn' shw yaw]\n",
"input: [white kid gloves in], expected: [etihw dik sevolg ni], got: [etihw dik sevolg ni]\n",
"input: [trees , a little], expected: [seert , a elttil], got: [seert , ' elttil]\n",
"input: [my tail when i], expected: [ym liat nehw i], got: [ym llat nehw i]\n",
"input: [n't think that proved], expected: [t'n kniht taht devorp], got: [t'n kniht taht dekoop]\n",
"input: [to have got into], expected: [ot evah tog otni], got: [ot evah tog otni]\n",
"input: [a wink of sleep], expected: [a kniw fo peels], got: [a kniw oo peel]\n",
"input: [making quite a conversation], expected: [gnikam etiuq a noitasrevnoc], got: [dnikam etiuq a noitasrevnu]\n",
"input: [the order of the], expected: [eht redro fo eht], got: [eht redro fo eht]\n",
"==================================================\n",
"Iteration-#: 31\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 447s - loss: 0.1055 - acc: 0.9678 - val_loss: 0.1262 - val_acc: 0.9603\n",
"input: [was so full of], expected: [saw os lluf fo], got: [saw os lluo fo]\n",
"input: [watch out of his], expected: [hctaw tuo fo sih], got: [hctaw tuo fo sih]\n",
"input: [the kitchen . 'when], expected: [eht nehctik . nehw'], got: [eht nehccik . nehw']\n",
"input: ['they 'd have been], expected: [yeht' d' evah neeb], got: [yeht' d' evah neeb]\n",
"input: [and no more of], expected: [dna on erom fo], got: [dna on erom fo]\n",
"input: [talk , ' said], expected: [klat , ' dias], got: [klat , ' dias]\n",
"input: [no pictures or conversations], expected: [on serutcip ro snoitasrevnoc], got: [oi rrrutccc ro oottsrrrvnnoc]\n",
"input: [table . 'nothing can], expected: [elbat . gnihton' nac], got: [elbat . gnihton' nac]\n",
"input: [mind now ! '], expected: [dnim won ! '], got: [dnim won ! ']\n",
"input: [written up somewhere .], expected: [nettirw pu erehwemos .], got: [nettirr no eroheemot .]\n",
"==================================================\n",
"Iteration-#: 32\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 447s - loss: 0.1163 - acc: 0.9643 - val_loss: 0.1957 - val_acc: 0.9405\n",
"input: [her , ' said], expected: [reh , ' dias], got: [reh , ' dias]\n",
"input: [' said the dormouse], expected: [' dias eht esuomrod], got: [' dias eht esuomrod]\n",
"input: [queen , who were], expected: [neeuq , ohw erew], got: [neeuq , ohw erew]\n",
"input: [m -- ' 'why], expected: [m -- ' yhw'], got: [m -- ' yhw']\n",
"input: [? ' quite a], expected: [? ' etiuq a], got: [? ' egiuq a]\n",
"input: [much right , '], expected: [hcum thgir , '], got: [hcum thgir , ']\n",
"input: [the week before .], expected: [eht keew erofeb .], got: [eht keew eroreb .]\n",
"input: [of finding morals in], expected: [fo gnidnif slarom ni], got: [fo gnidnff sammm i]\n",
"input: [never was so ordered], expected: [reven saw os deredro], got: [reven siw os dererup]\n",
"input: [was for bringing the], expected: [saw rof gnignirb eht], got: [saw rof gnignirg eht]\n",
"==================================================\n",
"Iteration-#: 33\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 448s - loss: 0.1682 - acc: 0.9500 - val_loss: 0.1894 - val_acc: 0.9402\n",
"input: [, 'or i 'll], expected: [, ro' i ll'], got: [, ro' i ll']\n",
"input: [just been picked up], expected: [tsuj neeb dekcip pu], got: [tsuj neeb dekiip pu]\n",
"input: [peeped into the book], expected: [depeep otni eht koob], got: [depeep htni ehs koob]\n",
"input: [emphasis , looking hard], expected: [sisahpme , gnikool drah], got: [ssiipeep , gnikool drah]\n",
"input: [he said , turning], expected: [eh dias , gninrut], got: [eh dias , gninrut]\n",
"input: [you , wo n't], expected: [uoy , ow t'n], got: [uoy , ow t'n]\n",
"input: [flamingo was gone across], expected: [ognimalf saw enog ssorca], got: [ggiiiiff swaw noo sssooc]\n",
"input: [' 'would n't it], expected: [' dluow' t'n ti], got: [' dluow' t'n ti]\n",
"input: [the day and night], expected: [eht yad dna thgin], got: [eht yad dna thgid]\n",
"input: [some more tea ,], expected: [emos erom aet ,], got: [emos eros eet ,]\n",
"==================================================\n",
"Iteration-#: 34\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 448s - loss: 0.1185 - acc: 0.9638 - val_loss: 0.1479 - val_acc: 0.9552\n",
"input: [last came a rumbling], expected: [tsal emac a gnilbmur], got: [tcal emac a gnilbmur]\n",
"input: [she turned away .], expected: [ehs denrut yawa .], got: [ehs denrus yawa .]\n",
"input: [to remain where she], expected: [ot niamer erehw ehs], got: [ot niamer erehw ehs]\n",
"input: [gryphon , the squeaking], expected: [nohpyrg , eht gnikaeuqs], got: [nohpyrg , eht gnnkkauts]\n",
"input: [she went on all], expected: [ehs tnew no lla], got: [ehs tnew no lla]\n",
"input: [be wasting our breath], expected: [eb gnitsaw ruo htaerb], got: [eb gnitsaw ruo ttgrrb]\n",
"input: [to say it out], expected: [ot yas ti tuo], got: [ot yas ti tuo]\n",
"input: [him when he sneezes], expected: [mih nehw eh sezeens], got: [mih nehw eh sezeees]\n",
"input: [' and he added], expected: [' dna eh dedda], got: [' dna eh dedda]\n",
"input: [i do it again], expected: [i od ti niaga], got: [i od ti niaga]\n",
"==================================================\n",
"Iteration-#: 35\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 449s - loss: 0.0932 - acc: 0.9717 - val_loss: 0.1323 - val_acc: 0.9592\n",
"input: [a capital one for], expected: [a latipac eno rof], got: [a latipac eno rof]\n",
"input: ['re wrong about the], expected: [er' gnorw tuoba eht], got: [er' gnoow tuoba eht]\n",
"input: [thing ! ' said], expected: [gniht ! ' dias], got: [gniht ! ' dias]\n",
"input: [an egg ! '], expected: [na gge ! '], got: [na gge ! ']\n",
"input: [( in which the], expected: [( ni hcihw eht], got: [( ni hcihw eht]\n",
"input: [to go ! let], expected: [ot og ! tel], got: [ot og p tel]\n",
"input: [such a hurry that], expected: [hcus a yrruh taht], got: [hcus a yrruh taht]\n",
"input: [: -- 'fury said], expected: [: -- yruf' dias], got: [: -- yruo' dias]\n",
"input: [sigh , 'i was], expected: [hgis , i' saw], got: [hgis , i' saw]\n",
"input: [of singers . 'you], expected: [fo sregnis . uoy'], got: [fo srednis . uoy']\n",
"==================================================\n",
"Iteration-#: 36\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 448s - loss: 0.0969 - acc: 0.9708 - val_loss: 0.1986 - val_acc: 0.9377\n",
"input: [a little startled by], expected: [a elttil deltrats yb], got: [a elttil dettaat bb]\n",
"input: [went on again :], expected: [tnew no niaga :], got: [tnew no niata :]\n",
"input: [the little door ,], expected: [eht elttil rood ,], got: [eht elttil rood ,]\n",
"input: [said 'no , never], expected: [dias on' , reven], got: [dias oon , reven]\n",
"input: [sisters -- they were], expected: [sretsis -- yeht erew], got: [sressiw -- teht erew]\n",
"input: [looked anxiously at the], expected: [dekool ylsuoixna ta eht], got: [dekoll ylsuoiona aa eh]\n",
"input: [finishing the game .], expected: [gnihsinif eht emag .], got: [gnihsgnif eht emag .]\n",
"input: [sounded best . some], expected: [dednuos tseb . emos], got: [deduuus tseu a emoc]\n",
"input: [to work , and], expected: [ot krow , dna], got: [ot krow , dna]\n",
"input: ['re thinking about something], expected: [er' gnikniht tuoba gnihtemos], got: [eht gnikniht tsoba gnihteeor]\n",
"==================================================\n",
"Iteration-#: 37\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 449s - loss: 0.0886 - acc: 0.9732 - val_loss: 0.1160 - val_acc: 0.9643\n",
"input: [that ; nor did], expected: [taht ; ron did], got: [taht ; ron did]\n",
"input: [left to make one], expected: [tfel ot ekam eno], got: [tfel ot ekam eno]\n",
"input: [our house i should], expected: [ruo esuoh i dluohs], got: [roo esuoh i dluohs]\n",
"input: [she thought , and], expected: [ehs thguoht , dna], got: [ehs thguoht , dna]\n",
"input: [outside , ' the], expected: [edistuo , ' eht], got: [edistuo , ' eht]\n",
"input: [the duchess , 'and], expected: [eht ssehcud , dna'], got: [eht ssehcud , dna']\n",
"input: [dare say you never], expected: [erad yas uoy reven], got: [erad yas uoy reven]\n",
"input: [little pattering of feet], expected: [elttil gnirettap fo teef], got: [elttil gniretraf fo teef]\n",
"input: [the cook threw a], expected: [eht kooc werht a], got: [eht kooc rehwt a]\n",
"input: ['re a kind of], expected: [er' a dnik fo], got: [er' a dnik fo]\n",
"==================================================\n",
"Iteration-#: 38\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 449s - loss: 0.0759 - acc: 0.9774 - val_loss: 0.2531 - val_acc: 0.9287\n",
"input: ['but i 'm not], expected: [tub' i m' ton], got: [tub' i m' ton]\n",
"input: [me hear the name], expected: [em raeh eht eman], got: [em raeh eht eman]\n",
"input: [from him to you], expected: [morf mih ot uoy], got: [moof mih ot uoyy]\n",
"input: [if you 'd rather], expected: [fi uoy d' rehtar], got: [fi uoy '' rehtar]\n",
"input: [not remember the simple], expected: [ton rebmemer eht elpmis], got: [t'n rebmemer met elbmis]\n",
"input: [' said the mock], expected: [' dias eht kcom], got: [' dias eht kcom]\n",
"input: [on ! ' 'i], expected: [no ! ' i'], got: [no ! ' ']\n",
"input: [, as she could], expected: [, sa ehs dluoc], got: [, sa ehs dluoc]\n",
"input: [' said the cat], expected: [' dias eht tac], got: [' dias eht tac]\n",
"input: [bat ? ' when], expected: [tab ? ' nehw], got: [tab ? ' nehw]\n",
"==================================================\n",
"Iteration-#: 39\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 448s - loss: 0.1173 - acc: 0.9645 - val_loss: 0.2899 - val_acc: 0.9212\n",
"input: [a conversation of it], expected: [a noitasrevnoc fo ti], got: [a toitasrevncc to ti]\n",
"input: [or two , which], expected: [ro owt , hcihw], got: [ro owt , hcihw]\n",
"input: [that she was in], expected: [taht ehs saw ni], got: [taht ehs saw ni]\n",
"input: [his cheeks , he], expected: [sih skeehc , eh], got: [sih skeehs , eh]\n",
"input: [i almost think i], expected: [i tsomla kniht i], got: [i tsomla kkiht i]\n",
"input: [ever to get out], expected: [reve ot teg tuo], got: [reve ot teg tuo]\n",
"input: [( she was obliged], expected: [( ehs saw degilbo], got: [: ehs saw deggilo]\n",
"input: [his head ! ''], expected: [sih daeh ! ''], got: [sih daeh ! '']\n",
"input: [, a little timidly], expected: [, a elttil yldimit], got: [, a elttil yldimitt]\n",
"input: [the hatter . 'you], expected: [eht rettah . uoy'], got: [eht rettah . uoy']\n",
"==================================================\n",
"Iteration-#: 40\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 449s - loss: 0.1319 - acc: 0.9610 - val_loss: 0.1199 - val_acc: 0.9631\n",
"input: ['s conduct at first], expected: [s' tcudnoc ta tsrif], got: [s' tccuona ta tsrif]\n",
"input: [her great delight it], expected: [reh taerg thgiled ti], got: [reh taerg thgiled ti]\n",
"input: [advisable -- '' '], expected: [elbasivda -- '' '], got: [elaa-svaa -- '' ']\n",
"input: [hedges , ' the], expected: [segdeh , ' eht], got: [seggeh , ' eht]\n",
"input: [gryphon answered , very], expected: [nohpyrg derewsna , yrev], got: [nohpyrg derswwap , yrev]\n",
"input: ['s rather curious ,], expected: [s' rehtar suoiruc ,], got: [s' rehtar suoiruc ,]\n",
"input: [very decided tone :], expected: [yrev dediced enot :], got: [yrev dedddre enot :]\n",
"input: [. 'well , i], expected: [. llew' , i], got: [. llew' , i]\n",
"input: [' said alice :], expected: [' dias ecila :], got: [' dias ecila :]\n",
"input: [if you could only], expected: [fi uoy dluoc ylno], got: [fi uoy dluoc ylno]\n",
"==================================================\n",
"Iteration-#: 41\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 450s - loss: 0.0779 - acc: 0.9766 - val_loss: 0.1006 - val_acc: 0.9691\n",
"input: [trees , a little], expected: [seert , a elttil], got: [serrt , a elttil]\n",
"input: [she would manage it], expected: [ehs dluow eganam ti], got: [ehs dluow eganam ti]\n",
"input: [' 'if any one], expected: [' fi' yna eno], got: [' fi' yna eno]\n",
"input: [to the porpoise ,], expected: [ot eht esioprop ,], got: [ot eht esioppop ,]\n",
"input: [out laughing : and], expected: [tuo gnihgual : dna], got: [tuo gnigguag : dna]\n",
"input: [read : -- 'they], expected: [daer : -- yeht'], got: [daer : -- yeht']\n",
"input: [finished the first verse], expected: [dehsinif eht tsrif esrev], got: [dehinnif eht tsrif esree]\n",
"input: [. alice caught the], expected: [. ecila thguac eht], got: [. ecila thguac eht]\n",
"input: [' said the lory], expected: [' dias eht yrol], got: [' dias eht yrol]\n",
"input: [footman 's head :], expected: [namtoof s' daeh :], got: [namtoof sa daeh !]\n",
"==================================================\n",
"Iteration-#: 42\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 449s - loss: 0.1156 - acc: 0.9663 - val_loss: 0.1540 - val_acc: 0.9525\n",
"input: [. alice crouched down], expected: [. ecila dehcuorc nwod], got: [. ecila deccoorc nwod]\n",
"input: [! ' said the], expected: [! ' dias eht], got: [! ' dias eht]\n",
"input: [looking at the house], expected: [gnikool ta eht esuoh], got: [gnikool ta eht esuoh]\n",
"input: [there seemed to be], expected: [ereht demees ot eb], got: [ereht demees ot eb]\n",
"input: [grow to my right], expected: [worg ot ym thgir], got: [worg os ym thgir]\n",
"input: [change the subject of], expected: [egnahc eht tcejbus fo], got: [egnahc eht tceejus fu]\n",
"input: [drawling-master was an old], expected: [retsam-gnilward saw na dlo], got: [rattarrdiibarr sa na new]\n",
"input: [' thought alice ,], expected: [' thguoht ecila ,], got: [' thguoht ecila ,]\n",
"input: [dormouse denied nothing ,], expected: [esuomrod deined gnihton ,], got: [esuomrod dnidnih gnihtih ,]\n",
"input: [was mystery , '], expected: [saw yretsym , '], got: [saw yretssmm, ']\n",
"==================================================\n",
"Iteration-#: 43\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 450s - loss: 0.0808 - acc: 0.9764 - val_loss: 0.1047 - val_acc: 0.9679\n",
"input: [to say 'i once], expected: [ot yas i' ecno], got: [ot yas s' ecno]\n",
"input: [n't like changing so], expected: [t'n ekil gnignahc os], got: [t'n ekil gnignahc os]\n",
"input: [sharply . 'do you], expected: [ylprahs . od' uoy], got: [ylarers . od' uoy]\n",
"input: [in a low voice], expected: [ni a wol eciov], got: [ni a wol eciov]\n",
"input: [so much surprised ,], expected: [os hcum desirprus ,], got: [os hcum desirprus ,]\n",
"input: [, in a rather], expected: [, ni a rehtar], got: [, ni a rehtar]\n",
"input: [in a low voice], expected: [ni a wol eciov], got: [ni a wol eciov]\n",
"input: [to the mock turtle], expected: [ot eht kcom eltrut], got: [ot eht kcom eltrut]\n",
"input: [. ' -- as], expected: [. ' -- sa], got: [. ' -- sa]\n",
"input: [way off , and], expected: [yaw ffo , dna], got: [yaw ffo , dna]\n",
"==================================================\n",
"Iteration-#: 44\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 449s - loss: 0.0640 - acc: 0.9814 - val_loss: 0.1749 - val_acc: 0.9474\n",
"input: [it sat for a], expected: [ti tas rof a], got: [ti tat rof a]\n",
"input: [from him to you], expected: [morf mih ot uoy], got: [morf mih ot uoy]\n",
"input: [glad to do so], expected: [dalg ot od os], got: [dald ot od os]\n",
"input: [as she spoke .], expected: [sa ehs ekops .], got: [sa ehs ekops .]\n",
"input: [the pepper when he], expected: [eht reppep nehw eh], got: [eht reppep nehw eh]\n",
"input: [am ! but i], expected: [ma ! tub i], got: [ma ! tub i]\n",
"input: [' 'you ! '], expected: [' uoy' ! '], got: [' hoy' ! ']\n",
"input: ['s it , '], expected: [s' ti , '], got: [s' ti , ']\n",
"input: [to get us dry], expected: [ot teg su yrd], got: [ot teg ss yrd]\n",
"input: [alice , who had], expected: [ecila , ohw dah], got: [ecila , ohw dah]\n",
"==================================================\n",
"Iteration-#: 45\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 450s - loss: 0.0875 - acc: 0.9742 - val_loss: 0.3754 - val_acc: 0.9009\n",
"input: [rabbit read : --], expected: [tibbar daer : --], got: [tibber naae : --]\n",
"input: [they looked so good], expected: [yeht dekool os doog], got: [yeht dekoos os doog]\n",
"input: [dear dinah ! i], expected: [raed hanid ! i], got: [raed hanid ! i]\n",
"input: [they have their tails], expected: [yeht evah rieht sliat], got: [yeht evah rieht sliat]\n",
"input: [by his face only], expected: [yb sih ecaf ylno], got: [yb sth ecaf ylno]\n",
"input: [she thought , 'and], expected: [ehs thguoht , dna'], got: [ehs thguoht , dna']\n",
"input: ['ll see me there], expected: [ll' ees em ereht], got: [ll' ee' em ereht]\n",
"input: [front of the house], expected: [tnorf fo eht esuoh], got: [tnof fo eht esuoh]\n",
"input: [up into a tree], expected: [pu otni a eert], got: [pu otn oa errt]\n",
"input: [up his head --], expected: [pu sih daeh --], got: [pu sih aaeh --]\n",
"==================================================\n",
"Iteration-#: 46\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 449s - loss: 0.0897 - acc: 0.9728 - val_loss: 0.1238 - val_acc: 0.9615\n",
"input: [to herself , 'it], expected: [ot flesreh , ti'], got: [ot flesreh , ti']\n",
"input: [enormous puppy was looking], expected: [suomrone yppup saw gnikool], got: [suorrrnn ypuop tah gnikolp]\n",
"input: [to herself , (], expected: [ot flesreh , (], got: [ot flesreh , (]\n",
"input: [the month is it], expected: [eht htnom si ti], got: [eht hcnom ti ti]\n",
"input: [as to size ,], expected: [sa ot ezis ,], got: [sa ot ezis ,]\n",
"input: [his ear . alice], expected: [sih rae . ecila], got: [sih rae . ecila]\n",
"input: [eggs , i know], expected: [sgge , i wonk], got: [sgge , i wonk]\n",
"input: [do , why then], expected: [od , yhw neht], got: [od , yow neht]\n",
"input: [anxiously round , to], expected: [ylsuoixna dnuor , ot], got: [ylouoisna dduor ,o ot]\n",
"input: [were writing down 'stupid], expected: [erew gnitirw nwod diputs'], got: [erew gnidirw nwod dipssus]\n",
"==================================================\n",
"Iteration-#: 47\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 449s - loss: 0.0699 - acc: 0.9796 - val_loss: 0.1002 - val_acc: 0.9701\n",
"input: [went on , 'you], expected: [tnew no , uoy'], got: [tnew no , uoy']\n",
"input: [again ! ' which], expected: [niaga ! ' hcihw], got: [niaga ! ' hcihw]\n",
"input: [, and everybody laughed], expected: [, dna ydobyreve dehgual], got: [, dna ydgbyreve dehgaaa]\n",
"input: [see how he can], expected: [ees woh eh nac], got: [ees woh eh nac]\n",
"input: [, ' the hatter], expected: [, ' eht rettah], got: [, ' eht rettah]\n",
"input: [, but hurriedly went], expected: [, tub yldeirruh tnew], got: [, tub yldeiruuh tnew]\n",
"input: [. ' 'you are], expected: [. ' uoy' era], got: [. ' uoy' era]\n",
"input: [, 'i kept all], expected: [, i' tpek lla], got: [, i' tpek lla]\n",
"input: [, stretching , and], expected: [, gnihcterts , dna], got: [, gnihciertt , dna]\n",
"input: [that perhaps it was], expected: [taht spahrep ti saw], got: [taht spahrep si saw]\n",
"==================================================\n",
"Iteration-#: 48\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 450s - loss: 0.0761 - acc: 0.9782 - val_loss: 0.1843 - val_acc: 0.9431\n",
"input: [in managing her flamingo], expected: [ni gniganam reh ognimalf], got: [ni gnignaa rrh oonimaal]\n",
"input: [, resting their elbows], expected: [, gnitser rieht swoble], got: [, gniteel sieht swolle]\n",
"input: [left to make one], expected: [tfel ot ekam eno], got: [tfel ot ekam eno]\n",
"input: [me on messages next], expected: [em no segassem txen], got: [em nn semaesem teem]\n",
"input: [close behind her ,], expected: [esolc dniheb reh ,], got: [esolc deiihb reh ,]\n",
"input: [. ' so she], expected: [. ' os ehs], got: [. ' os ehs]\n",
"input: [, ' said the], expected: [, ' dias eht], got: [, ' dias eht]\n",
"input: [neither of the others], expected: [rehtien fo eht srehto], got: [rehtiiv fo eht srehoo]\n",
"input: [the hatter went on], expected: [eht rettah tnew no], got: [eht rettah tnew no]\n",
"input: [way , was the], expected: [yaw , saw eht], got: [yaw , saw eht]\n",
"==================================================\n",
"Iteration-#: 49\n",
"Train on 30009 samples, validate on 3335 samples\n",
"Epoch 1/1\n",
"30009/30009 [==============================] - 449s - loss: 0.0799 - acc: 0.9758 - val_loss: 0.0958 - val_acc: 0.9706\n",
"input: [herself , rather sharply], expected: [flesreh , rehtar ylprahs], got: [flesreh , rehtah ylprahs]\n",
"input: [the king eagerly ,], expected: [eht gnik ylregae ,], got: [eht gnik ylregae ,]\n",
"input: [down and make out], expected: [nwod dna ekam tuo], got: [nwod dna ekam tuo]\n",
"input: ['they 'd have been], expected: [yeht' d' evah neeb], got: [yeht' '' evah neeb]\n",
"input: [as he spoke ,], expected: [sa eh ekops ,], got: [sa eh ekops ,]\n",
"input: [one , but it], expected: [eno , tub ti], got: [eno , tub ti]\n",
"input: [that she was in], expected: [taht ehs saw ni], got: [taht ehs saw ni]\n",
"input: [, and then said], expected: [, dna neht dias], got: [, dna neht dias]\n",
"input: [there 's half my], expected: [ereht s' flah ym], got: [ereht s' llah ym]\n",
"input: [) to the confused], expected: [) ot eht desufnoc], got: [) ot eht desufnoc]\n"
]
}
],
"source": [
"def decode_text(y):\n",
" text_seq = []\n",
" for i in range(y.shape[0]):\n",
" idx = np.argmax(y[i])\n",
" text_seq.append(index2char[idx])\n",
" return \"\".join(text_seq).strip()\n",
"\n",
"for iteration in range(50):\n",
" print(\"=\" * 50)\n",
" print(\"Iteration-#: %d\" % (iteration))\n",
" model.fit(Xtrain, ytrain, batch_size=128, nb_epoch=1,\n",
" validation_data=(Xval, yval))\n",
" # select 10 samples from validation data\n",
" for i in range(10):\n",
" test_idx = np.random.randint(Xval.shape[0])\n",
" Xtest = np.array([Xval[test_idx, :, :]])\n",
" ytest = np.array([yval[test_idx, :, :]])\n",
" ypred = model.predict([Xtest], verbose=0)\n",
" xtest_text = decode_text(Xtest[0])\n",
" ytest_text = decode_text(ytest[0])\n",
" ypred_text = decode_text(ypred[0])\n",
" print(\"input: [%s], expected: [%s], got: [%s]\" % (\n",
" xtest_text, ytest_text, ypred_text))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment