In [2]:
import tarfile
import re
import urllib.request
import os
import random

class ImdbMovieReviews:
    DEFAULT_URL = \
        'http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz'
    TOKEN_REGEX = re.compile(r'[A-Za-z]+|[!?.:,()]')
    
    def __init__(self):
        self._cache_dir = './imdb'
        self._url = 'http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz'
        
        if not os.path.isfile(self._cache_dir):
            urllib.request.urlretrieve(self._url, self._cache_dir)
        self.filepath = self._cache_dir

    def __iter__(self):
        with tarfile.open(self.filepath) as archive:
            items = archive.getnames()
            for filename in archive.getnames():
                if filename.startswith('aclImdb/train/pos/'):
                    yield self._read(archive, filename), True
                elif filename.startswith('aclImdb/train/neg/'):
                    yield self._read(archive, filename), False
                    
    def _read(self, archive, filename):
        with archive.extractfile(filename) as file_:
            data = file_.read().decode('utf-8')
            data = type(self).TOKEN_REGEX.findall(data)
            data = [x.lower() for x in data]
            return data

In [3]:
import numpy as np
# Spacy is my favourite nlp framework, which havu builtin word embeddings trains on wikipesia
from spacy.en import English

class Embedding:
    
    def __init__(self, length):
#          spaCy makes using word vectors very easy. 
#             The Lexeme , Token , Span  and Doc  classes all have a .vector property,
#             which is a 1-dimensional numpy array of 32-bit floats:
        self.parser = English()
        self._length = length
        self.dimensions = 300
        
    def __call__(self, sequence):
        data = np.zeros((self._length, self.dimensions))
        # you can access known words from the parser's vocabulary
        embedded = [self.parser.vocab[w].vector for w in sequence]
        data[:len(sequence)] = embedded
        return data

In [18]:
from lazy import lazy

class SequenceClassificationModel:
    def __init__(self, data, params):
        self.params = params
        self.cpnt_path = 'att_checkpoints'
        self.attention_size = 500
        self._create_placeholders()
        self.prediction
        self.cost
        self.error
        self.optimize
        self.global_step = 0
        self._create_summaries()
        self.sess = tf.Session()
        self.sess.run(tf.global_variables_initializer())
    
    def _create_placeholders(self):
        with tf.name_scope("data"):
            self.data = tf.placeholder(tf.float32, [None, self.params.seq_length, self.params.embed_length])
            self.target = tf.placeholder(tf.float32, [None, 2])
  
    def _create_summaries(self):
        with tf.name_scope("summaries"):
            tf.summary.scalar('loss', self.cost)
            tf.summary.scalar('erroe', self.error)
            self.summary = tf.summary.merge_all()
            saver = tf.train.Saver()
            
    @lazy
    def length(self):
        with tf.name_scope("seq_length"):
            used = tf.sign(tf.reduce_max(tf.abs(self.data), reduction_indices=2))
            length = tf.reduce_sum(used, reduction_indices=1)
            length = tf.cast(length, tf.int32)
        return length
    
    @lazy
    def prediction(self):
        with tf.name_scope("recurrent_layer"):
            rnn_output, _ = tf.nn.dynamic_rnn(
                self.params.rnn_cell(self.params.rnn_hidden),
                self.data,
                dtype=tf.float32,
                sequence_length=self.length
            )
        
        with tf.name_scope("attention"):
            hidden_size = rnn_output.shape[2].value  # D value - hidden size of the RNN layer

            # Trainable parameters
            W_omega = tf.Variable(tf.random_normal([self.params.rnn_hidden, self.attention_size], stddev=0.1))
            b_omega = tf.Variable(tf.random_normal([self.attention_size], stddev=0.1))
            u_omega = tf.Variable(tf.random_normal([self.attention_size], stddev=0.1))

            # Applying fully connected layer with non-linear activation to each of the B*T timestamps;
            #  the shape of `v` is (B,T,D)*(D,A)=(B,T,A), where A=attention_size
            v = tf.tanh(tf.tensordot(rnn_output, W_omega, axes=1) + b_omega)
            # For each of the timestamps its vector of size A from `v` is reduced with `u` vector
            vu = tf.tensordot(v, u_omega, axes=1)   # (B,T) shape
            alphas = tf.nn.softmax(vu)              # (B,T) shape also

            # Output of (Bi-)RNN is reduced with attention vector; the result has (B,D) shape
#             output = tf.reduce_sum(rnn_output * tf.expand_dims(alphas, -1), 1)
            last = tf.reduce_sum(rnn_output * tf.expand_dims(alphas, -1), 1)

#         last = self._last_relevant(output, self.length)

        with tf.name_scope("softmax_layer"):
            num_classes = int(self.target.get_shape()[1])
            weight = tf.Variable(tf.truncated_normal(
                [self.params.rnn_hidden, num_classes], stddev=0.01))
            bias = tf.Variable(tf.constant(0.1, shape=[num_classes]))
            prediction = tf.nn.softmax(tf.matmul(last, weight) + bias)
        return prediction
    
    @lazy
    def cost(self):
        cross_entropy = -tf.reduce_sum(self.target * tf.log(self.prediction))
        return cross_entropy
    
    @lazy
    def error(self):
        self.mistakes = tf.not_equal(
            tf.argmax(self.target, 1), tf.argmax(self.prediction, 1))
        return tf.reduce_mean(tf.cast(self.mistakes, tf.float32))
    
    @lazy
    def optimize(self):
        with tf.name_scope("optimization"):
            gradient = self.params.optimizer.compute_gradients(self.cost)
            if self.params.gradient_clipping:
                limit = self.params.gradient_clipping
                gradient = [
                    (tf.clip_by_value(g, -limit, limit), v)
                    if g is not None else (None, v)
                    for g, v in gradient]
            optimize = self.params.optimizer.apply_gradients(gradient)
        return optimize
    
    def train(self, batches, save_prefix, save_every=10):
        saver = tf.train.Saver()
        if os.path.isdir(self.cpnt_path):
            saver.restore(self.sess, tf.train.latest_checkpoint(self.cpnt_path))
        else:
            os.makedirs(self.cpnt_path)
        summary_path = os.path.join('att_graphs', 'run{}'.format(self.global_step))
        summary_writer = tf.summary.FileWriter(summary_path, self.sess.graph)
        self.global_step += 1
        for index, batch in enumerate(batches):
            feed = {model.data: batch[0], model.target: batch[1]}
            error, _, summary_str = self.sess.run([model.error, model.optimize, model.summary], feed)
            print('{}: {:3.1f}%'.format(index + 1, 100 * error))
            if index % save_every == 0:
                summary_writer.add_summary(summary_str, index)
                summary_writer.flush()
            if index % save_every == 0:
                save_path = os.path.join(self.cpnt_path, save_prefix)
                print('saving...', save_path)
                saver.save(self.sess, save_path, global_step=index)
                
        saver.save(self.sess, os.path.join(self.cpnt_path, save_prefix + '_final'))

    def predict_proba(self, data):
        feed = {model.data: data, }
        prediction = self.sess.run([model.prediction], feed)        
        return prediction
        
    def close(self):
        tf.reset_default_graph()
        self.session.close()

In [5]:
def preprocess_batched(iterator, length, embedding, batch_size):
    iterator = iter(iterator)
    while True:
        data = np.zeros((batch_size, length, embedding.dimensions))
        target = np.zeros((batch_size, 2))
        for index in range(batch_size):
            text, label = next(iterator)
            data[index] = embedding(text)
            target[index] = [1, 0] if label else [0, 1]
        yield data, target

In [6]:
reviews = list(ImdbMovieReviews())

In [7]:
random.shuffle(reviews)

In [8]:
length = max(len(x[0]) for x in reviews)
embedding = Embedding(length)

In [9]:
from attrdict import AttrDict

params = AttrDict(
    rnn_cell=tf.contrib.rnn.GRUCell,
    rnn_hidden=300,
    optimizer=tf.train.RMSPropOptimizer(0.002),
    batch_size=20,
    gradient_clipping=100,
    seq_length=length,
    embed_length=embedding.dimensions
)

In [19]:
batches = preprocess_batched(reviews, length, embedding, params.batch_size)

In [20]:
tf.reset_default_graph()

model = SequenceClassificationModel(data, params)

In [21]:
model.train(batches, save_prefix='simple-rnn-attention')


1: 50.0%
saving... att_checkpoints/simple-rnn-attention
2: 60.0%
3: 50.0%
4: 50.0%
5: 50.0%
6: 50.0%
7: 60.0%
8: 55.0%
9: 55.0%
10: 35.0%
11: 65.0%
saving... att_checkpoints/simple-rnn-attention
12: 55.0%
13: 35.0%
14: 25.0%
15: 55.0%
16: 45.0%
17: 55.0%
18: 35.0%
19: 60.0%
20: 40.0%
21: 40.0%
saving... att_checkpoints/simple-rnn-attention
22: 60.0%
23: 50.0%
24: 40.0%
25: 70.0%
26: 40.0%
27: 45.0%
28: 55.0%
29: 55.0%
30: 50.0%
31: 50.0%
saving... att_checkpoints/simple-rnn-attention
32: 45.0%
33: 50.0%
34: 40.0%
35: 55.0%
36: 45.0%
37: 45.0%
38: 60.0%
39: 35.0%
40: 55.0%
41: 50.0%
saving... att_checkpoints/simple-rnn-attention
42: 30.0%
43: 50.0%
44: 50.0%
45: 50.0%
46: 35.0%
47: 60.0%
48: 55.0%
49: 55.0%
50: 65.0%
51: 35.0%
saving... att_checkpoints/simple-rnn-attention
52: 50.0%
53: 40.0%
54: 50.0%
55: 60.0%
56: 60.0%
57: 50.0%
58: 55.0%
59: 50.0%
60: 65.0%
61: 65.0%
saving... att_checkpoints/simple-rnn-attention
62: 65.0%
63: 60.0%
64: 55.0%
65: 55.0%
66: 40.0%
67: 60.0%
68: 60.0%
69: 60.0%
70: 45.0%
71: 65.0%
saving... att_checkpoints/simple-rnn-attention
72: 65.0%
73: 40.0%
74: 55.0%
75: 70.0%
76: 55.0%
77: 55.0%
78: 60.0%
79: 55.0%
80: 65.0%
81: 40.0%
saving... att_checkpoints/simple-rnn-attention
82: 40.0%
83: 25.0%
84: 40.0%
85: 65.0%
86: 50.0%
87: 50.0%
88: 45.0%
89: 40.0%
90: 45.0%
91: 65.0%
saving... att_checkpoints/simple-rnn-attention
92: 40.0%
93: 60.0%
94: 65.0%
95: 30.0%
96: 50.0%
97: 55.0%
98: 60.0%
99: 60.0%
100: 55.0%
101: 55.0%
saving... att_checkpoints/simple-rnn-attention
102: 60.0%
103: 40.0%
104: 35.0%
105: 65.0%
106: 45.0%
107: 45.0%
108: 65.0%
109: 65.0%
110: 45.0%
111: 55.0%
saving... att_checkpoints/simple-rnn-attention
112: 50.0%
113: 50.0%
114: 35.0%
115: 75.0%
116: 55.0%
117: 50.0%
118: 40.0%
119: 30.0%
120: 50.0%
121: 45.0%
saving... att_checkpoints/simple-rnn-attention
122: 50.0%
123: 45.0%
124: 40.0%
125: 30.0%
126: 50.0%
127: 45.0%
128: 55.0%
129: 60.0%
130: 50.0%
131: 60.0%
saving... att_checkpoints/simple-rnn-attention
132: 55.0%
133: 50.0%
134: 60.0%
135: 40.0%
136: 55.0%
137: 50.0%
138: 55.0%
139: 45.0%
140: 65.0%
141: 50.0%
saving... att_checkpoints/simple-rnn-attention
142: 45.0%
143: 40.0%
144: 70.0%
145: 40.0%
146: 40.0%
147: 40.0%
148: 75.0%
149: 60.0%
150: 60.0%
151: 75.0%
saving... att_checkpoints/simple-rnn-attention
152: 35.0%
153: 50.0%
154: 50.0%
155: 55.0%
156: 45.0%
157: 55.0%
158: 60.0%
159: 45.0%
160: 65.0%
161: 50.0%
saving... att_checkpoints/simple-rnn-attention
162: 70.0%
163: 50.0%
164: 50.0%
165: 45.0%
166: 30.0%
167: 65.0%
168: 40.0%
169: 50.0%
170: 45.0%
171: 50.0%
saving... att_checkpoints/simple-rnn-attention
172: 45.0%
173: 65.0%
174: 50.0%
175: 45.0%
176: 35.0%
177: 40.0%
178: 55.0%
179: 60.0%
180: 60.0%
181: 50.0%
saving... att_checkpoints/simple-rnn-attention
182: 40.0%
183: 40.0%
184: 55.0%
185: 55.0%
186: 45.0%
187: 40.0%
188: 65.0%
189: 50.0%
190: 55.0%
191: 45.0%
saving... att_checkpoints/simple-rnn-attention
192: 60.0%
193: 65.0%
194: 55.0%
195: 30.0%
196: 60.0%
197: 70.0%
198: 50.0%
199: 50.0%
200: 45.0%
201: 50.0%
saving... att_checkpoints/simple-rnn-attention
202: 45.0%
203: 45.0%
204: 70.0%
205: 65.0%
206: 45.0%
207: 60.0%
208: 45.0%
209: 45.0%
210: 45.0%
211: 60.0%
saving... att_checkpoints/simple-rnn-attention
212: 55.0%
213: 50.0%
214: 50.0%
215: 60.0%
216: 25.0%
217: 55.0%
218: 70.0%
219: 50.0%
220: 40.0%
221: 40.0%
saving... att_checkpoints/simple-rnn-attention
222: 65.0%
223: 45.0%
224: 45.0%
225: 50.0%
226: 25.0%
227: 60.0%
228: 35.0%
229: 55.0%
230: 50.0%
231: 65.0%
saving... att_checkpoints/simple-rnn-attention
232: 35.0%
233: 45.0%
234: 35.0%
235: 45.0%
236: 50.0%
237: 55.0%
238: 30.0%
239: 55.0%
240: 50.0%
241: 35.0%
saving... att_checkpoints/simple-rnn-attention
242: 55.0%
243: 75.0%
244: 75.0%
245: 35.0%
246: 40.0%
247: 45.0%
248: 45.0%
249: 45.0%
250: 50.0%
251: 25.0%
saving... att_checkpoints/simple-rnn-attention
252: 40.0%
253: 50.0%
254: 45.0%
255: 70.0%
256: 45.0%
257: 75.0%
258: 35.0%
259: 50.0%
260: 55.0%
261: 60.0%
saving... att_checkpoints/simple-rnn-attention
262: 40.0%
263: 55.0%
264: 50.0%
265: 35.0%
266: 45.0%
267: 70.0%
268: 30.0%
269: 55.0%
270: 45.0%
271: 45.0%
saving... att_checkpoints/simple-rnn-attention
272: 40.0%
273: 55.0%
274: 50.0%
275: 60.0%
276: 30.0%
277: 60.0%
278: 40.0%
279: 70.0%
280: 40.0%
281: 30.0%
saving... att_checkpoints/simple-rnn-attention
282: 70.0%
283: 55.0%
284: 60.0%
285: 50.0%
286: 65.0%
287: 55.0%
288: 60.0%
289: 40.0%
290: 55.0%
291: 40.0%
saving... att_checkpoints/simple-rnn-attention
292: 65.0%
293: 55.0%
294: 50.0%
295: 55.0%
296: 40.0%
297: 50.0%
298: 55.0%
299: 45.0%
300: 40.0%
301: 45.0%
saving... att_checkpoints/simple-rnn-attention
302: 45.0%
303: 65.0%
304: 40.0%
305: 65.0%
306: 50.0%
307: 35.0%
308: 50.0%
309: 45.0%
310: 50.0%
311: 60.0%
saving... att_checkpoints/simple-rnn-attention
312: 25.0%
313: 50.0%
314: 50.0%
315: 50.0%
316: 55.0%
317: 35.0%
318: 55.0%
319: 75.0%
320: 35.0%
321: 35.0%
saving... att_checkpoints/simple-rnn-attention
322: 65.0%
323: 50.0%
324: 60.0%
325: 50.0%
326: 75.0%
327: 50.0%
328: 45.0%
329: 55.0%
330: 60.0%
331: 60.0%
saving... att_checkpoints/simple-rnn-attention
332: 25.0%
333: 50.0%
334: 55.0%
335: 45.0%
336: 50.0%
337: 60.0%
338: 50.0%
339: 60.0%
340: 60.0%
341: 60.0%
saving... att_checkpoints/simple-rnn-attention
342: 55.0%
343: 60.0%
344: 40.0%
345: 60.0%
346: 35.0%
347: 30.0%
348: 50.0%
349: 40.0%
350: 45.0%
351: 60.0%
saving... att_checkpoints/simple-rnn-attention
352: 50.0%
353: 30.0%
354: 60.0%
355: 35.0%
356: 40.0%
357: 50.0%
358: 35.0%
359: 55.0%
360: 45.0%
361: 55.0%
saving... att_checkpoints/simple-rnn-attention
362: 35.0%
363: 55.0%
364: 40.0%
365: 45.0%
366: 50.0%
367: 40.0%
368: 45.0%
369: 50.0%
370: 50.0%
371: 65.0%
saving... att_checkpoints/simple-rnn-attention
372: 40.0%
373: 65.0%
374: 65.0%
375: 30.0%
376: 60.0%
377: 40.0%
378: 45.0%
379: 20.0%
380: 70.0%
381: 65.0%
saving... att_checkpoints/simple-rnn-attention
382: 65.0%
383: 40.0%
384: 80.0%
385: 45.0%
386: 60.0%
387: 50.0%
388: 65.0%
389: 45.0%
390: 40.0%
391: 80.0%
saving... att_checkpoints/simple-rnn-attention
392: 50.0%
393: 55.0%
394: 55.0%
395: 55.0%
396: 60.0%
397: 35.0%
398: 65.0%
399: 40.0%
400: 40.0%
401: 65.0%
saving... att_checkpoints/simple-rnn-attention
402: 40.0%
403: 60.0%
404: 45.0%
405: 50.0%
406: 50.0%
407: 40.0%
408: 40.0%
409: 55.0%
410: 20.0%
411: 70.0%
saving... att_checkpoints/simple-rnn-attention
412: 50.0%
413: 50.0%
414: 45.0%
415: 35.0%
416: 75.0%
417: 65.0%
418: 50.0%
419: 70.0%
420: 75.0%
421: 50.0%
saving... att_checkpoints/simple-rnn-attention
422: 50.0%
423: 40.0%
424: 60.0%
425: 45.0%
426: 40.0%
427: 40.0%
428: 60.0%
429: 40.0%
430: 40.0%
431: 40.0%
saving... att_checkpoints/simple-rnn-attention
432: 45.0%
433: 55.0%
434: 60.0%
435: 80.0%
436: 30.0%
437: 40.0%
438: 50.0%
439: 30.0%
440: 45.0%
441: 65.0%
saving... att_checkpoints/simple-rnn-attention
442: 50.0%
443: 45.0%
444: 40.0%
445: 50.0%
446: 35.0%
447: 45.0%
448: 45.0%
449: 40.0%
450: 45.0%
451: 50.0%
saving... att_checkpoints/simple-rnn-attention
452: 55.0%
453: 55.0%
454: 55.0%
455: 60.0%
456: 40.0%
457: 55.0%
458: 40.0%
459: 35.0%
460: 45.0%
461: 35.0%
saving... att_checkpoints/simple-rnn-attention
462: 25.0%
463: 45.0%
464: 50.0%
465: 50.0%
466: 60.0%
467: 45.0%
468: 40.0%
469: 30.0%
470: 45.0%
471: 45.0%
saving... att_checkpoints/simple-rnn-attention
472: 35.0%
473: 40.0%
474: 65.0%
475: 35.0%
476: 40.0%
477: 50.0%
478: 40.0%
479: 35.0%
480: 50.0%
481: 50.0%
saving... att_checkpoints/simple-rnn-attention
482: 50.0%
483: 35.0%
484: 35.0%
485: 45.0%
486: 40.0%
487: 45.0%
488: 55.0%
489: 50.0%
490: 60.0%
491: 45.0%
saving... att_checkpoints/simple-rnn-attention
492: 25.0%
493: 55.0%
494: 35.0%
495: 65.0%
496: 35.0%
497: 55.0%
498: 45.0%
499: 40.0%
500: 55.0%
501: 40.0%
saving... att_checkpoints/simple-rnn-attention
502: 40.0%
503: 45.0%
504: 40.0%
505: 55.0%
506: 65.0%
507: 55.0%
508: 40.0%
509: 35.0%
510: 50.0%
511: 70.0%
saving... att_checkpoints/simple-rnn-attention
512: 40.0%
513: 45.0%
514: 60.0%
515: 50.0%
516: 30.0%
517: 30.0%
518: 60.0%
519: 40.0%
520: 35.0%
521: 25.0%
saving... att_checkpoints/simple-rnn-attention
522: 55.0%
523: 60.0%
524: 60.0%
525: 55.0%
526: 75.0%
527: 35.0%
528: 40.0%
529: 25.0%
530: 60.0%
531: 40.0%
saving... att_checkpoints/simple-rnn-attention
532: 30.0%
533: 35.0%
534: 55.0%
535: 25.0%
536: 50.0%
537: 50.0%
538: 25.0%
539: 45.0%
540: 45.0%
541: 25.0%
saving... att_checkpoints/simple-rnn-attention
542: 15.0%
543: 55.0%
544: 50.0%
545: 55.0%
546: 20.0%
547: 35.0%
548: 35.0%
549: 45.0%
550: 50.0%
551: 25.0%
saving... att_checkpoints/simple-rnn-attention
552: 40.0%
553: 30.0%
554: 10.0%
555: 25.0%
556: 40.0%
557: 35.0%
558: 20.0%
559: 30.0%
560: 55.0%
561: 25.0%
saving... att_checkpoints/simple-rnn-attention
562: 35.0%
563: 40.0%
564: 20.0%
565: 35.0%
566: 35.0%
567: 55.0%
568: 50.0%
569: 45.0%
570: 40.0%
571: 40.0%
saving... att_checkpoints/simple-rnn-attention
572: 50.0%
573: 25.0%
574: 25.0%
575: 15.0%
576: 45.0%
577: 50.0%
578: 20.0%
579: 35.0%
580: 40.0%
581: 30.0%
saving... att_checkpoints/simple-rnn-attention
582: 45.0%
583: 55.0%
584: 15.0%
585: 35.0%
586: 30.0%
587: 30.0%
588: 45.0%
589: 60.0%
590: 35.0%
591: 15.0%
saving... att_checkpoints/simple-rnn-attention
592: 30.0%
593: 45.0%
594: 50.0%
595: 35.0%
596: 35.0%
597: 40.0%
598: 40.0%
599: 40.0%
600: 25.0%
601: 25.0%
saving... att_checkpoints/simple-rnn-attention
602: 20.0%
603: 20.0%
604: 20.0%
605: 45.0%
606: 30.0%
607: 50.0%
608: 35.0%
609: 30.0%
610: 35.0%
611: 30.0%
saving... att_checkpoints/simple-rnn-attention
612: 10.0%
613: 25.0%
614: 35.0%
615: 45.0%
616: 30.0%
617: 25.0%
618: 35.0%
619: 20.0%
620: 15.0%
621: 15.0%
saving... att_checkpoints/simple-rnn-attention
622: 35.0%
623: 45.0%
624: 35.0%
625: 45.0%
626: 30.0%
627: 25.0%
628: 20.0%
629: 25.0%
630: 35.0%
631: 30.0%
saving... att_checkpoints/simple-rnn-attention
632: 40.0%
633: 10.0%
634: 45.0%
635: 20.0%
636: 15.0%
637: 40.0%
638: 30.0%
639: 25.0%
640: 20.0%
641: 20.0%
saving... att_checkpoints/simple-rnn-attention
642: 20.0%
643: 10.0%
644: 25.0%
645: 30.0%
646: 20.0%
647: 40.0%
648: 15.0%
649: 15.0%
650: 20.0%
651: 20.0%
saving... att_checkpoints/simple-rnn-attention
652: 35.0%
653: 30.0%
654: 50.0%
655: 30.0%
656: 30.0%
657: 40.0%
658: 20.0%
659: 20.0%
660: 15.0%
661: 15.0%
saving... att_checkpoints/simple-rnn-attention
662: 15.0%
663: 20.0%
664: 35.0%
665: 25.0%
666: 15.0%
667: 25.0%
668: 30.0%
669: 45.0%
670: 35.0%
671: 15.0%
saving... att_checkpoints/simple-rnn-attention
672: 35.0%
673: 15.0%
674: 30.0%
675: 20.0%
676: 15.0%
677: 20.0%
678: 20.0%
679: 30.0%
680: 30.0%
681: 20.0%
saving... att_checkpoints/simple-rnn-attention
682: 25.0%
683: 15.0%
684: 20.0%
685: 15.0%
686: 20.0%
687: 20.0%
688: 15.0%
689: 20.0%
690: 25.0%
691: 20.0%
saving... att_checkpoints/simple-rnn-attention
692: 15.0%
693: 30.0%
694: 20.0%
695: 25.0%
696: 25.0%
697: 30.0%
698: 20.0%
699: 15.0%
700: 25.0%
701: 10.0%
saving... att_checkpoints/simple-rnn-attention
702: 10.0%
703: 30.0%
704: 15.0%
705: 25.0%
706: 25.0%
707: 20.0%
708: 10.0%
709: 25.0%
710: 15.0%
711: 15.0%
saving... att_checkpoints/simple-rnn-attention
712: 15.0%
713: 30.0%
714: 20.0%
715: 15.0%
716: 30.0%
717: 15.0%
718: 15.0%
719: 15.0%
720: 25.0%
721: 20.0%
saving... att_checkpoints/simple-rnn-attention
722: 10.0%
723: 15.0%
724: 10.0%
725: 45.0%
726: 10.0%
727: 35.0%
728: 30.0%
729: 20.0%
730: 15.0%
731: 15.0%
saving... att_checkpoints/simple-rnn-attention
732: 30.0%
733: 20.0%
734: 10.0%
735: 20.0%
736: 15.0%
737: 20.0%
738: 20.0%
739: 20.0%
740: 35.0%
741: 15.0%
saving... att_checkpoints/simple-rnn-attention
742: 20.0%
743: 25.0%
744: 10.0%
745: 25.0%
746: 20.0%
747: 15.0%
748: 35.0%
749: 25.0%
750: 20.0%
751: 15.0%
saving... att_checkpoints/simple-rnn-attention
752: 25.0%
753: 5.0%
754: 35.0%
755: 20.0%
756: 20.0%
757: 15.0%
758: 20.0%
759: 20.0%
760: 10.0%
761: 10.0%
saving... att_checkpoints/simple-rnn-attention
762: 0.0%
763: 20.0%
764: 15.0%
765: 25.0%
766: 5.0%
767: 10.0%
768: 10.0%
769: 15.0%
770: 20.0%
771: 15.0%
saving... att_checkpoints/simple-rnn-attention
772: 30.0%
773: 15.0%
774: 25.0%
775: 15.0%
776: 10.0%
777: 30.0%
778: 5.0%
779: 25.0%
780: 15.0%
781: 35.0%
saving... att_checkpoints/simple-rnn-attention
782: 5.0%
783: 10.0%
784: 10.0%
785: 5.0%
786: 30.0%
787: 35.0%
788: 30.0%
789: 20.0%
790: 25.0%
791: 10.0%
saving... att_checkpoints/simple-rnn-attention
792: 20.0%
793: 30.0%
794: 20.0%
795: 25.0%
796: 30.0%
797: 10.0%
798: 10.0%
799: 20.0%
800: 15.0%
801: 15.0%
saving... att_checkpoints/simple-rnn-attention
802: 25.0%
803: 15.0%
804: 15.0%
805: 25.0%
806: 30.0%
807: 20.0%
808: 30.0%
809: 20.0%
810: 15.0%
811: 40.0%
saving... att_checkpoints/simple-rnn-attention
812: 20.0%
813: 5.0%
814: 10.0%
815: 10.0%
816: 15.0%
817: 15.0%
818: 15.0%
819: 15.0%
820: 40.0%
821: 35.0%
saving... att_checkpoints/simple-rnn-attention
822: 5.0%
823: 15.0%
824: 15.0%
825: 20.0%
826: 15.0%
827: 5.0%
828: 10.0%
829: 10.0%
830: 15.0%
831: 10.0%
saving... att_checkpoints/simple-rnn-attention
832: 5.0%
833: 15.0%
834: 25.0%
835: 20.0%
836: 20.0%
837: 25.0%
838: 30.0%
839: 30.0%
840: 0.0%
841: 20.0%
saving... att_checkpoints/simple-rnn-attention
842: 20.0%
843: 15.0%
844: 10.0%
845: 10.0%
846: 25.0%
847: 25.0%
848: 5.0%
849: 10.0%
850: 25.0%
851: 15.0%
saving... att_checkpoints/simple-rnn-attention
852: 30.0%
853: 20.0%
854: 10.0%
855: 10.0%
856: 20.0%
857: 20.0%
858: 15.0%
859: 20.0%
860: 15.0%
861: 35.0%
saving... att_checkpoints/simple-rnn-attention
862: 15.0%
863: 10.0%
864: 20.0%
865: 15.0%
866: 30.0%
867: 20.0%
868: 10.0%
869: 35.0%
870: 5.0%
871: 15.0%
saving... att_checkpoints/simple-rnn-attention
872: 20.0%
873: 15.0%
874: 25.0%
875: 15.0%
876: 5.0%
877: 55.0%
878: 15.0%
879: 5.0%
880: 20.0%
881: 0.0%
saving... att_checkpoints/simple-rnn-attention
882: 15.0%
883: 10.0%
884: 15.0%
885: 10.0%
886: 20.0%
887: 20.0%
888: 30.0%
889: 10.0%
890: 20.0%
891: 20.0%
saving... att_checkpoints/simple-rnn-attention
892: 10.0%
893: 15.0%
894: 20.0%
895: 30.0%
896: 30.0%
897: 15.0%
898: 20.0%
899: 5.0%
900: 5.0%
901: 10.0%
saving... att_checkpoints/simple-rnn-attention
902: 10.0%
903: 5.0%
904: 20.0%
905: 15.0%
906: 20.0%
907: 25.0%
908: 10.0%
909: 20.0%
910: 0.0%
911: 20.0%
saving... att_checkpoints/simple-rnn-attention
912: 15.0%
913: 15.0%
914: 20.0%
915: 10.0%
916: 25.0%
917: 10.0%
918: 25.0%
919: 0.0%
920: 30.0%
921: 5.0%
saving... att_checkpoints/simple-rnn-attention
922: 10.0%
923: 5.0%
924: 25.0%
925: 5.0%
926: 25.0%
927: 5.0%
928: 10.0%
929: 10.0%
930: 10.0%
931: 15.0%
saving... att_checkpoints/simple-rnn-attention
932: 10.0%
933: 25.0%
934: 35.0%
935: 10.0%
936: 15.0%
937: 10.0%
938: 5.0%
939: 20.0%
940: 15.0%
941: 5.0%
saving... att_checkpoints/simple-rnn-attention
942: 5.0%
943: 15.0%
944: 10.0%
945: 10.0%
946: 25.0%
947: 35.0%
948: 10.0%
949: 10.0%
950: 35.0%
951: 10.0%
saving... att_checkpoints/simple-rnn-attention
952: 20.0%
953: 20.0%
954: 15.0%
955: 20.0%
956: 15.0%
957: 25.0%
958: 5.0%
959: 20.0%
960: 20.0%
961: 30.0%
saving... att_checkpoints/simple-rnn-attention
962: 30.0%
963: 5.0%
964: 10.0%
965: 35.0%
966: 0.0%
967: 20.0%
968: 20.0%
969: 45.0%
970: 15.0%
971: 0.0%
saving... att_checkpoints/simple-rnn-attention
972: 30.0%
973: 30.0%
974: 20.0%
975: 25.0%
976: 5.0%
977: 15.0%
978: 25.0%
979: 15.0%
980: 25.0%
981: 20.0%
saving... att_checkpoints/simple-rnn-attention
982: 20.0%
983: 5.0%
984: 10.0%
985: 15.0%
986: 20.0%
987: 5.0%
988: 25.0%
989: 25.0%
990: 10.0%
991: 10.0%
saving... att_checkpoints/simple-rnn-attention
992: 20.0%
993: 25.0%
994: 25.0%
995: 10.0%
996: 0.0%
997: 0.0%
998: 20.0%
999: 20.0%
1000: 20.0%
1001: 35.0%
saving... att_checkpoints/simple-rnn-attention
1002: 20.0%
1003: 20.0%
1004: 0.0%
1005: 5.0%
1006: 10.0%
1007: 30.0%
1008: 20.0%
1009: 20.0%
1010: 15.0%
1011: 15.0%
saving... att_checkpoints/simple-rnn-attention
1012: 20.0%
1013: 15.0%
1014: 20.0%
1015: 15.0%
1016: 15.0%
1017: 10.0%
1018: 15.0%
1019: 15.0%
1020: 15.0%
1021: 20.0%
saving... att_checkpoints/simple-rnn-attention
1022: 5.0%
1023: 15.0%
1024: 30.0%
1025: 5.0%
1026: 10.0%
1027: 20.0%
1028: 15.0%
1029: 5.0%
1030: 20.0%
1031: 30.0%
saving... att_checkpoints/simple-rnn-attention
1032: 20.0%
1033: 10.0%
1034: 0.0%
1035: 15.0%
1036: 25.0%
1037: 5.0%
1038: 25.0%
1039: 20.0%
1040: 20.0%
1041: 20.0%
saving... att_checkpoints/simple-rnn-attention
1042: 5.0%
1043: 25.0%
1044: 0.0%
1045: 20.0%
1046: 35.0%
1047: 15.0%
1048: 10.0%
1049: 25.0%
1050: 10.0%
1051: 20.0%
saving... att_checkpoints/simple-rnn-attention
1052: 20.0%
1053: 15.0%
1054: 5.0%
1055: 5.0%
1056: 25.0%
1057: 10.0%
1058: 15.0%
1059: 15.0%
1060: 30.0%
1061: 10.0%
saving... att_checkpoints/simple-rnn-attention
1062: 15.0%
1063: 30.0%
1064: 35.0%
1065: 20.0%
1066: 20.0%
1067: 5.0%
1068: 10.0%
1069: 10.0%
1070: 15.0%
1071: 5.0%
saving... att_checkpoints/simple-rnn-attention
1072: 20.0%
1073: 15.0%
1074: 20.0%
1075: 20.0%
1076: 30.0%
1077: 20.0%
1078: 30.0%
1079: 30.0%
1080: 15.0%
1081: 5.0%
saving... att_checkpoints/simple-rnn-attention
1082: 15.0%
1083: 20.0%
1084: 15.0%
1085: 15.0%
1086: 15.0%
1087: 0.0%
1088: 10.0%
1089: 5.0%
1090: 25.0%
1091: 15.0%
saving... att_checkpoints/simple-rnn-attention
1092: 15.0%
1093: 15.0%
1094: 5.0%
1095: 5.0%
1096: 10.0%
1097: 25.0%
1098: 25.0%
1099: 10.0%
1100: 20.0%
1101: 20.0%
saving... att_checkpoints/simple-rnn-attention
1102: 20.0%
1103: 35.0%
1104: 10.0%
1105: 10.0%
1106: 15.0%
1107: 10.0%
1108: 15.0%
1109: 25.0%
1110: 10.0%
1111: 10.0%
saving... att_checkpoints/simple-rnn-attention
1112: 10.0%
1113: 15.0%
1114: 5.0%
1115: 20.0%
1116: 30.0%
1117: 5.0%
1118: 15.0%
1119: 10.0%
1120: 25.0%
1121: 20.0%
saving... att_checkpoints/simple-rnn-attention
1122: 30.0%
1123: 15.0%
1124: 25.0%
1125: 10.0%
1126: 15.0%
1127: 5.0%
1128: 0.0%
1129: 30.0%
1130: 10.0%
1131: 15.0%
saving... att_checkpoints/simple-rnn-attention
1132: 35.0%
1133: 35.0%
1134: 5.0%
1135: 20.0%
1136: 5.0%
1137: 35.0%
1138: 5.0%
1139: 15.0%
1140: 15.0%
1141: 20.0%
saving... att_checkpoints/simple-rnn-attention
1142: 35.0%
1143: 5.0%
1144: 15.0%
1145: 25.0%
1146: 15.0%
1147: 25.0%
1148: 10.0%
1149: 15.0%
1150: 20.0%
1151: 15.0%
saving... att_checkpoints/simple-rnn-attention
1152: 15.0%
1153: 10.0%
1154: 15.0%
1155: 15.0%
1156: 5.0%
1157: 20.0%
1158: 5.0%
1159: 5.0%
1160: 15.0%
1161: 15.0%
saving... att_checkpoints/simple-rnn-attention
1162: 5.0%
1163: 15.0%
1164: 10.0%
1165: 20.0%
1166: 25.0%
1167: 10.0%
1168: 20.0%
1169: 5.0%
1170: 10.0%
1171: 0.0%
saving... att_checkpoints/simple-rnn-attention
1172: 20.0%
1173: 30.0%
1174: 25.0%
1175: 5.0%
1176: 10.0%
1177: 15.0%
1178: 15.0%
1179: 0.0%
1180: 15.0%
1181: 35.0%
saving... att_checkpoints/simple-rnn-attention
1182: 10.0%
1183: 15.0%
1184: 5.0%
1185: 10.0%
1186: 10.0%
1187: 15.0%
1188: 40.0%
1189: 15.0%
1190: 5.0%
1191: 15.0%
saving... att_checkpoints/simple-rnn-attention
1192: 15.0%
1193: 20.0%
1194: 15.0%
1195: 20.0%
1196: 5.0%
1197: 15.0%
1198: 5.0%
1199: 20.0%
1200: 15.0%
1201: 0.0%
saving... att_checkpoints/simple-rnn-attention
1202: 10.0%
1203: 10.0%
1204: 15.0%
1205: 20.0%
1206: 25.0%
1207: 15.0%
1208: 25.0%
1209: 15.0%
1210: 20.0%
1211: 20.0%
saving... att_checkpoints/simple-rnn-attention
1212: 10.0%
1213: 15.0%
1214: 15.0%
1215: 25.0%
1216: 25.0%
1217: 15.0%
1218: 10.0%
1219: 0.0%
1220: 10.0%
1221: 10.0%
saving... att_checkpoints/simple-rnn-attention
1222: 30.0%
1223: 20.0%
1224: 10.0%
1225: 15.0%
1226: 15.0%
1227: 5.0%
1228: 10.0%
1229: 10.0%
1230: 5.0%
1231: 20.0%
saving... att_checkpoints/simple-rnn-attention
1232: 5.0%
1233: 20.0%
1234: 10.0%
1235: 10.0%
1236: 15.0%
1237: 25.0%
1238: 25.0%
1239: 0.0%
1240: 20.0%
1241: 30.0%
saving... att_checkpoints/simple-rnn-attention
1242: 10.0%
1243: 15.0%
1244: 10.0%
1245: 0.0%
1246: 5.0%
1247: 10.0%
1248: 25.0%
1249: 5.0%
1250: 10.0%
/home/kurbanov/Soft/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:143: DeprecationWarning: generator 'preprocess_batched' raised StopIteration