<s> from __future__ import division , print_function <EOL> import logging <EOL> import os <EOL> FORMAT = '<STR_LIT>' <EOL> DATEFMT = "<STR_LIT>" <EOL> logging . basicConfig ( format = FORMAT , datefmt = DATEFMT , level = logging . INFO ) <EOL> import sys <EOL> import theano <EOL> debug = sys . gettrace ( ) is not None <EOL> if debug : <EOL> print ( "<STR_LIT>" ) <EOL> theano . config . optimizer = '<STR_LIT>' <EOL> theano . config . exception_verbosity = '<STR_LIT>' <EOL> theano . config . compute_test_value = '<STR_LIT>' <EOL> else : <EOL> theano . config . compute_test_value = '<STR_LIT>' <EOL> import theano . tensor as T <EOL> import numpy as np <EOL> import fuel <EOL> from argparse import ArgumentParser <EOL> from fuel . streams import DataStream <EOL> from fuel . schemes import SequentialScheme , ShuffledScheme <EOL> from blocks . algorithms import GradientDescent , CompositeRule , StepClipping <EOL> from blocks . algorithms import Adam , RMSProp , AdaGrad , Scale , AdaDelta <EOL> from blocks . initialization import Constant <EOL> from blocks . graph import ComputationGraph , apply_dropout <EOL> from blocks . extensions import FinishAfter , Timing , Printing , ProgressBar <EOL> from blocks . extensions . saveload import SimpleExtension <EOL> from blocks . bricks import Random , Initializable <EOL> from blocks . bricks . base import application <EOL> from blocks . extensions . monitoring import DataStreamMonitoring <EOL> from blocks . extensions . monitoring import TrainingDataMonitoring <EOL> from blocks . main_loop import MainLoop <EOL> from blocks . model import Model <EOL> from blocks . bricks . recurrent import LSTM , GatedRecurrent <EOL> from blocks . bricks . recurrent import RecurrentStack <EOL> from blocks . bricks . sequence_generators import SequenceGenerator , Readout <EOL> from fuel . datasets import H5PYDataset <EOL> from blocks . filter import VariableFilter <EOL> from blocks . extensions . saveload import Checkpoint , Load <EOL> import cPickle as pickle <EOL> from blocks_extras import OrthogonalGlorot <EOL> from blocks . initialization import Uniform <EOL> floatX = theano . config . floatX <EOL> fuel . config . floatX = floatX <EOL> from fuel . transformers import Mapping <EOL> from blocks . utils import named_copy <EOL> logger = logging . getLogger ( __name__ ) <EOL> import pprint <EOL> import math <EOL> def _is_nan ( log ) : <EOL> return any ( v != v for v in log . current_row . itervalues ( ) ) <EOL> def _transpose ( data ) : <EOL> return tuple ( np . swapaxes ( array , <NUM_LIT:0> , <NUM_LIT:1> ) for array in data ) <EOL> import matplotlib <EOL> matplotlib . use ( '<STR_LIT>' ) <EOL> from matplotlib import pylab as pl <EOL> from pylab import cm <EOL> def drawpoints ( points , xmin = None , ymin = None , xmax = None , ymax = None ) : <EOL> skips = np . hstack ( ( np . array ( [ <NUM_LIT:0> ] ) , points [ : , <NUM_LIT:2> ] ) ) <EOL> xys = np . vstack ( ( np . zeros ( ( <NUM_LIT:1> , <NUM_LIT:2> ) ) , np . cumsum ( points [ : , : <NUM_LIT:2> ] , axis = <NUM_LIT:0> ) ) ) <EOL> xys [ : , : <NUM_LIT:2> ] -= xys [ : , : <NUM_LIT:2> ] . mean ( axis = <NUM_LIT:0> ) <EOL> xs = [ ] <EOL> ys = [ ] <EOL> x = [ ] <EOL> y = [ ] <EOL> for xy , s in zip ( xys , skips ) : <EOL> if s : <EOL> if len ( x ) > <NUM_LIT:1> : <EOL> xs . append ( x ) <EOL> ys . append ( y ) <EOL> x = [ ] <EOL> y = [ ] <EOL> else : <EOL> x . append ( xy [ <NUM_LIT:0> ] ) <EOL> y . append ( xy [ <NUM_LIT:1> ] ) <EOL> for x , y in zip ( xs , ys ) : <EOL> pl . plot ( x , y , '<STR_LIT>' ) <EOL> if xmin is None : <EOL> xmin , ymin = xys . min ( axis = <NUM_LIT:0> ) <EOL> xmax , ymax = xys . max ( axis = <NUM_LIT:0> ) <EOL> ax = pl . gca ( ) <EOL> ax . set_xlim ( xmin , xmax ) <EOL> ax . set_ylim ( ymin , ymax ) <EOL> ax . invert_yaxis ( ) <EOL> ax . set_xticks ( [ ] ) <EOL> ax . set_yticks ( [ ] ) <EOL> class Sample ( SimpleExtension ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , generator , N = <NUM_LIT:8> , steps = <NUM_LIT> , path = '<STR_LIT>' , ** kwargs ) : <EOL> self . N = N <EOL> self . path = path <EOL> super ( Sample , self ) . __init__ ( ** kwargs ) <EOL> batch_size = self . N * self . N <EOL> self . sample = ComputationGraph ( generator . generate ( <EOL> n_steps = steps , batch_size = batch_size , iterate = True ) <EOL> ) . get_theano_function ( ) <EOL> def do ( self , callback_name , * args ) : <EOL> batch_size = self . N * self . N <EOL> epochstr = "<STR_LIT>" <EOL> if self . main_loop : <EOL> epochstr = "<STR_LIT>" . format ( self . main_loop . log . status [ '<STR_LIT>' ] ) <EOL> res = self . sample ( ) <EOL> outputs = res [ - <NUM_LIT:2> ] <EOL> mins = [ ] <EOL> maxs = [ ] <EOL> for i in range ( batch_size ) : <EOL> points = outputs [ : , i , : ] <EOL> xys = np . vstack ( ( np . zeros ( ( <NUM_LIT:1> , <NUM_LIT:2> ) ) , np . cumsum ( points [ : , : <NUM_LIT:2> ] , axis = <NUM_LIT:0> ) ) ) <EOL> xys [ : , : <NUM_LIT:2> ] -= xys [ : , : <NUM_LIT:2> ] . mean ( axis = <NUM_LIT:0> ) <EOL> mins . append ( xys . min ( axis = <NUM_LIT:0> ) ) <EOL> maxs . append ( xys . max ( axis = <NUM_LIT:0> ) ) <EOL> xmin , ymin = np . array ( mins ) . min ( axis = <NUM_LIT:0> ) <EOL> xmax , ymax = np . array ( maxs ) . max ( axis = <NUM_LIT:0> ) <EOL> r = ( ymax - ymin ) / ( xmax - xmin ) <EOL> reverse = r > <NUM_LIT:1.> <EOL> if reverse : r = <NUM_LIT:1.> / r <EOL> bestapprox = <NUM_LIT:10> <EOL> for f in range ( <NUM_LIT:1> , self . N ) : <EOL> if self . N % f != <NUM_LIT:0> : <EOL> continue <EOL> rapprox = <NUM_LIT:1.> / float ( f * f ) <EOL> if abs ( r - rapprox ) < abs ( r - bestapprox ) : <EOL> bestapprox = rapprox <EOL> bestf = f <EOL> if reverse : <EOL> h , w = self . N // bestf , self . N * bestf <EOL> r = <NUM_LIT:1.> / r <EOL> bestapprox = <NUM_LIT:1.> / bestapprox <EOL> else : <EOL> h , w = self . N * bestf , self . N // bestf <EOL> if bestapprox > r : <EOL> newydelta = ( ymax - ymin ) * bestapprox / r <EOL> ymax += newydelta / <NUM_LIT> <EOL> ymin -= newydelta / <NUM_LIT> <EOL> else : <EOL> newxdelta = ( xmax - xmin ) * r / bestapprox <EOL> xmax += newxdelta / <NUM_LIT> <EOL> xmin -= newxdelta / <NUM_LIT> <EOL> pl . close ( '<STR_LIT:all>' ) <EOL> fig = pl . figure ( '<STR_LIT>' ) <EOL> fig . set_size_inches ( <NUM_LIT> , <NUM_LIT> ) <EOL> for i in range ( batch_size ) : <EOL> pl . subplot ( h , w , i + <NUM_LIT:1> ) <EOL> drawpoints ( outputs [ : , i , : ] , xmin , ymin , xmax , ymax ) <EOL> fname = os . path . join ( self . path , '<STR_LIT>' . format ( epochstr ) ) <EOL> print ( '<STR_LIT>' % fname ) <EOL> pl . subplots_adjust ( left = <NUM_LIT> , right = <NUM_LIT> , bottom = <NUM_LIT> , top = <NUM_LIT> , <EOL> wspace = <NUM_LIT> , hspace = <NUM_LIT> ) <EOL> pl . savefig ( fname ) <EOL> fig = pl . figure ( '<STR_LIT>' ) <EOL> fig . set_size_inches ( <NUM_LIT> , <NUM_LIT> ) <EOL> img = <NUM_LIT:1> - outputs [ : , : , <NUM_LIT:2> ] <EOL> pl . imshow ( img , cmap = cm . gray ) <EOL> pl . gca ( ) . set_xticks ( [ ] ) <EOL> pl . gca ( ) . set_yticks ( [ ] ) <EOL> pl . xlabel ( '<STR_LIT>' ) <EOL> pl . ylabel ( '<STR_LIT>' ) <EOL> pl . title ( '<STR_LIT>' ) <EOL> if not os . path . exists ( self . path ) : <EOL> os . mkdir ( self . path ) <EOL> fname = os . path . join ( self . path , '<STR_LIT>' . format ( epochstr ) ) <EOL> print ( '<STR_LIT>' % fname ) <EOL> pl . savefig ( fname ) <EOL> from blocks . bricks . sequence_generators import AbstractEmitter <EOL> class SketchEmitter ( AbstractEmitter , Initializable , Random ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , mix_dim = <NUM_LIT:20> , epsilon = <NUM_LIT> , ** kwargs ) : <EOL> self . mix_dim = mix_dim <EOL> self . epsilon = epsilon <EOL> super ( SketchEmitter , self ) . __init__ ( ** kwargs ) <EOL> def components ( self , readouts ) : <EOL> """<STR_LIT>""" <EOL> mix_dim = self . mix_dim <EOL> output_norm = <NUM_LIT:2> * mix_dim <EOL> readouts = readouts . reshape ( ( - <NUM_LIT:1> , self . get_dim ( '<STR_LIT>' ) ) ) <EOL> mean = readouts [ : , <NUM_LIT:0> : output_norm ] . reshape ( ( - <NUM_LIT:1> , mix_dim , <NUM_LIT:2> ) ) <EOL> sigma = T . exp ( readouts [ : , output_norm : <NUM_LIT:2> * output_norm ] <EOL> . reshape ( ( - <NUM_LIT:1> , mix_dim , <NUM_LIT:2> ) ) ) <EOL> corr = T . tanh ( readouts [ : , <NUM_LIT:2> * output_norm : <NUM_LIT:2> * output_norm + mix_dim ] ) <EOL> weight = T . nnet . softmax ( <EOL> readouts [ : , <NUM_LIT:2> * output_norm + mix_dim : <NUM_LIT:2> * output_norm + <NUM_LIT:2> * mix_dim ] ) <EOL> penup = T . nnet . sigmoid ( readouts [ : , <NUM_LIT:2> * output_norm + <NUM_LIT:2> * mix_dim : ] ) <EOL> return mean , sigma , corr , weight , penup <EOL> @ application <EOL> def emit ( self , readouts ) : <EOL> """<STR_LIT>""" <EOL> mean , sigma , corr , weight , penup = self . components ( readouts ) <EOL> mix_dim = self . mix_dim <EOL> batch_size = readouts . shape [ <NUM_LIT:0> ] <EOL> nr = self . theano_rng . normal ( <EOL> size = ( batch_size , mix_dim , <NUM_LIT:2> ) , <EOL> avg = <NUM_LIT:0.> , std = <NUM_LIT:1.> ) <EOL> c = ( <NUM_LIT:1> - T . sqrt ( <NUM_LIT:1> - corr ** <NUM_LIT:2> ) ) / ( corr + self . epsilon ) <EOL> c = c . dimshuffle ( ( <NUM_LIT:0> , <NUM_LIT:1> , '<STR_LIT:x>' ) ) <EOL> nr = nr + nr [ : , : , : : - <NUM_LIT:1> ] * c <EOL> nr = nr / T . sqrt ( <NUM_LIT:1> + c ** <NUM_LIT:2> ) <EOL> nr = nr * sigma <EOL> nr = nr + mean <EOL> weight = self . theano_rng . multinomial ( pvals = weight , dtype = floatX ) <EOL> xy = nr * weight [ : , : , None ] <EOL> xy = xy . sum ( axis = <NUM_LIT:1> ) <EOL> un = self . theano_rng . uniform ( size = ( batch_size , <NUM_LIT:1> ) ) <EOL> penup = T . cast ( un < penup , floatX ) <EOL> res = T . concatenate ( [ xy , penup ] , axis = <NUM_LIT:1> ) <EOL> return res <EOL> def cost ( self , readouts , outputs ) : <EOL> """<STR_LIT>""" <EOL> nll_ndim = readouts . ndim - <NUM_LIT:1> <EOL> nll_shape = readouts . shape [ : - <NUM_LIT:1> ] <EOL> outputs = outputs . reshape ( ( - <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> mean , sigma , corr , weight , penup = self . components ( readouts ) <EOL> d = outputs [ : , : <NUM_LIT:2> ] . dimshuffle ( ( <NUM_LIT:0> , '<STR_LIT:x>' , <NUM_LIT:1> ) ) - mean <EOL> sigma2 = sigma [ : , : , <NUM_LIT:0> ] * sigma [ : , : , <NUM_LIT:1> ] + self . epsilon <EOL> z = d ** <NUM_LIT:2> / sigma ** <NUM_LIT:2> <EOL> z = z . sum ( axis = - <NUM_LIT:1> ) - <NUM_LIT:2> * corr * ( d [ : , : , <NUM_LIT:0> ] * d [ : , : , <NUM_LIT:1> ] ) / sigma2 <EOL> corr1 = <NUM_LIT:1> - corr ** <NUM_LIT:2> + self . epsilon <EOL> n = - z / ( <NUM_LIT:2> * corr1 ) <EOL> nmax = n . max ( axis = - <NUM_LIT:1> , keepdims = True ) <EOL> n = n - nmax <EOL> n = T . exp ( n ) / ( <NUM_LIT:2> * np . pi * sigma2 * T . sqrt ( corr1 ) ) <EOL> nll = - T . log ( ( n * weight ) . sum ( axis = - <NUM_LIT:1> , keepdims = True ) + self . epsilon ) <EOL> nll -= nmax <EOL> nll += T . nnet . binary_crossentropy ( penup , outputs [ : , <NUM_LIT:2> : ] ) <EOL> return nll . reshape ( nll_shape , ndim = nll_ndim ) <EOL> @ application <EOL> def initial_outputs ( self , batch_size ) : <EOL> return T . zeros ( ( batch_size , <NUM_LIT:3> ) ) <EOL> def get_dim ( self , name ) : <EOL> if name == '<STR_LIT>' : <EOL> return <NUM_LIT:2> * ( <NUM_LIT:2> * self . mix_dim ) + <NUM_LIT:2> * self . mix_dim + <NUM_LIT:1> <EOL> if name == '<STR_LIT>' : <EOL> return <NUM_LIT:3> <EOL> return super ( SketchEmitter , self ) . get_dim ( name ) <EOL> def main ( name , epochs , batch_size , learning_rate , <EOL> dim , mix_dim , old_model_name , max_length , bokeh , GRU , dropout , <EOL> depth , max_grad , step_method , epsilon , sample , skip , uniform , top ) : <EOL> datasource = name <EOL> def shnum ( x ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:0>' if x <= <NUM_LIT:0> else '<STR_LIT>' % ( ( "<STR_LIT>" % x ) [ <NUM_LIT:0> ] , - np . floor ( np . log10 ( x ) ) ) <EOL> jobname = "<STR_LIT>" % ( datasource , depth , dim , mix_dim , <EOL> int ( dropout * <NUM_LIT:10> ) , <EOL> shnum ( learning_rate ) , batch_size , <EOL> shnum ( epsilon ) ) <EOL> if max_length != <NUM_LIT> : <EOL> jobname += '<STR_LIT>' % max_length <EOL> if GRU : <EOL> jobname += '<STR_LIT:g>' <EOL> if max_grad != <NUM_LIT> : <EOL> jobname += '<STR_LIT>' % max_grad <EOL> if step_method != '<STR_LIT>' : <EOL> jobname += step_method <EOL> if skip : <EOL> jobname += '<STR_LIT:D>' <EOL> assert depth > <NUM_LIT:1> <EOL> if top : <EOL> jobname += '<STR_LIT:T>' <EOL> assert depth > <NUM_LIT:1> <EOL> if uniform > <NUM_LIT:0.> : <EOL> jobname += '<STR_LIT>' % int ( uniform * <NUM_LIT:100> ) <EOL> if debug : <EOL> jobname += "<STR_LIT>" <EOL> if sample : <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" % jobname ) <EOL> if old_model_name : <EOL> print ( "<STR_LIT>" % old_model_name ) <EOL> transitions = [ GatedRecurrent ( dim = dim ) if GRU else LSTM ( dim = dim ) <EOL> for _ in range ( depth ) ] <EOL> if depth > <NUM_LIT:1> : <EOL> transition = RecurrentStack ( transitions , name = "<STR_LIT>" , <EOL> skip_connections = skip or top ) <EOL> if skip : <EOL> source_names = [ RecurrentStack . suffix ( '<STR_LIT>' , d ) for d in range ( depth ) ] <EOL> else : <EOL> source_names = [ RecurrentStack . suffix ( '<STR_LIT>' , depth - <NUM_LIT:1> ) ] <EOL> else : <EOL> transition = transitions [ <NUM_LIT:0> ] <EOL> transition . name = "<STR_LIT>" <EOL> source_names = [ '<STR_LIT>' ] <EOL> emitter = SketchEmitter ( mix_dim = mix_dim , <EOL> epsilon = epsilon , <EOL> name = "<STR_LIT>" ) <EOL> readout = Readout ( <EOL> readout_dim = emitter . get_dim ( '<STR_LIT>' ) , <EOL> source_names = source_names , <EOL> emitter = emitter , <EOL> name = "<STR_LIT>" ) <EOL> generator = SequenceGenerator ( readout = readout , transition = transition ) <EOL> if uniform > <NUM_LIT:0.> : <EOL> generator . weights_init = Uniform ( width = uniform * <NUM_LIT> ) <EOL> else : <EOL> generator . weights_init = OrthogonalGlorot ( ) <EOL> generator . biases_init = Constant ( <NUM_LIT:0> ) <EOL> x = T . tensor3 ( '<STR_LIT>' , dtype = floatX ) <EOL> if debug : <EOL> x . tag . test_value = np . ones ( ( max_length , batch_size , <NUM_LIT:3> ) ) . astype ( floatX ) <EOL> x = x [ : max_length , : , : ] <EOL> cost = generator . cost ( x ) <EOL> cost . name = "<STR_LIT>" <EOL> model = Model ( cost ) <EOL> params = model . get_parameter_dict ( ) <EOL> logger . info ( "<STR_LIT>" + <EOL> pprint . pformat ( <EOL> [ ( key , value . get_value ( ) . shape ) for key , value <EOL> in params . items ( ) ] , <EOL> width = <NUM_LIT> ) ) <EOL> model_size = <NUM_LIT:0> <EOL> for v in params . itervalues ( ) : <EOL> s = v . get_value ( ) . shape <EOL> model_size += s [ <NUM_LIT:0> ] * ( s [ <NUM_LIT:1> ] if len ( s ) > <NUM_LIT:1> else <NUM_LIT:1> ) <EOL> logger . info ( "<STR_LIT>" % model_size ) <EOL> extensions = [ ] <EOL> if old_model_name : <EOL> if old_model_name == '<STR_LIT>' : <EOL> old_model_name = jobname <EOL> with open ( old_model_name + '<STR_LIT>' , "<STR_LIT:rb>" ) as f : <EOL> old_model = pickle . load ( f ) <EOL> model . set_parameter_values ( old_model . get_parameter_values ( ) ) <EOL> del old_model <EOL> else : <EOL> for brick in model . get_top_bricks ( ) : <EOL> brick . initialize ( ) <EOL> if sample : <EOL> assert old_model_name and old_model_name != '<STR_LIT>' <EOL> Sample ( generator , steps = max_length , path = old_model_name ) . do ( None ) <EOL> exit ( <NUM_LIT:0> ) <EOL> cg = ComputationGraph ( cost ) <EOL> if dropout > <NUM_LIT:0.> : <EOL> from blocks . roles import INPUT , OUTPUT <EOL> dropout_target = VariableFilter ( roles = [ OUTPUT ] , <EOL> bricks = transitions , <EOL> name_regex = '<STR_LIT>' ) ( cg . variables ) <EOL> print ( '<STR_LIT>' % len ( dropout_target ) ) <EOL> cg = apply_dropout ( cg , dropout_target , dropout ) <EOL> opt_cost = cg . outputs [ <NUM_LIT:0> ] <EOL> else : <EOL> opt_cost = cost <EOL> if step_method == '<STR_LIT>' : <EOL> step_rule = Adam ( learning_rate ) <EOL> elif step_method == '<STR_LIT>' : <EOL> step_rule = RMSProp ( learning_rate , decay_rate = <NUM_LIT> ) <EOL> elif step_method == '<STR_LIT>' : <EOL> step_rule = AdaGrad ( learning_rate ) <EOL> elif step_method == '<STR_LIT>' : <EOL> step_rule = AdaDelta ( ) <EOL> elif step_method == '<STR_LIT>' : <EOL> step_rule = Scale ( learning_rate ) <EOL> else : <EOL> raise Exception ( '<STR_LIT>' % step_method ) <EOL> step_rule = CompositeRule ( [ StepClipping ( max_grad ) , step_rule ] ) <EOL> algorithm = GradientDescent ( <EOL> cost = opt_cost , parameters = cg . parameters , <EOL> step_rule = step_rule ) <EOL> observables = [ cost ] <EOL> ( energies , ) = VariableFilter ( <EOL> applications = [ generator . readout . readout ] , <EOL> name_regex = "<STR_LIT>" ) ( cg . variables ) <EOL> min_energy = named_copy ( energies . min ( ) , "<STR_LIT>" ) <EOL> max_energy = named_copy ( energies . max ( ) , "<STR_LIT>" ) <EOL> observables += [ min_energy , max_energy ] <EOL> observables += [ algorithm . total_step_norm , algorithm . total_gradient_norm ] <EOL> for name , param in params . items ( ) : <EOL> observables . append ( named_copy ( <EOL> param . norm ( <NUM_LIT:2> ) , name + "<STR_LIT>" ) ) <EOL> observables . append ( named_copy ( <EOL> algorithm . gradients [ param ] . norm ( <NUM_LIT:2> ) , name + "<STR_LIT>" ) ) <EOL> datasource_fname = os . path . join ( fuel . config . data_path , datasource , <EOL> datasource + '<STR_LIT>' ) <EOL> train_ds = H5PYDataset ( datasource_fname , <EOL> which_sets = [ '<STR_LIT:train>' ] , sources = ( '<STR_LIT>' , ) , <EOL> load_in_memory = True ) <EOL> train_stream = DataStream ( train_ds , <EOL> iteration_scheme = ShuffledScheme ( <EOL> train_ds . num_examples , batch_size ) ) <EOL> test_ds = H5PYDataset ( datasource_fname , <EOL> which_sets = [ '<STR_LIT:test>' ] , sources = ( '<STR_LIT>' , ) , <EOL> load_in_memory = True ) <EOL> test_stream = DataStream ( test_ds , <EOL> iteration_scheme = SequentialScheme ( <EOL> test_ds . num_examples , batch_size ) ) <EOL> train_stream = Mapping ( train_stream , _transpose ) <EOL> test_stream = Mapping ( test_stream , _transpose ) <EOL> def stream_stats ( ds , label ) : <EOL> itr = ds . get_epoch_iterator ( as_dict = True ) <EOL> batch_count = <NUM_LIT:0> <EOL> examples_count = <NUM_LIT:0> <EOL> for batch in itr : <EOL> batch_count += <NUM_LIT:1> <EOL> examples_count += batch [ '<STR_LIT>' ] . shape [ <NUM_LIT:1> ] <EOL> print ( '<STR_LIT>' % <EOL> ( label , batch_count , examples_count ) ) <EOL> stream_stats ( train_stream , '<STR_LIT:train>' ) <EOL> stream_stats ( test_stream , '<STR_LIT:test>' ) <EOL> extensions += [ Timing ( every_n_batches = <NUM_LIT:10> ) , <EOL> TrainingDataMonitoring ( <EOL> observables , prefix = "<STR_LIT:train>" , <EOL> every_n_batches = <NUM_LIT:10> ) , <EOL> DataStreamMonitoring ( <EOL> [ cost ] , <EOL> test_stream , <EOL> prefix = "<STR_LIT:test>" , <EOL> on_resumption = True , <EOL> after_epoch = False , <EOL> every_n_batches = <NUM_LIT:100> ) , <EOL> Printing ( every_n_batches = <NUM_LIT:10> ) , <EOL> Checkpoint ( jobname , <EOL> before_training = False , after_epoch = True , <EOL> save_separately = [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> Sample ( generator , steps = max_length , <EOL> path = jobname + '<STR_LIT>' , <EOL> every_n_batches = <NUM_LIT:100> ) , <EOL> ProgressBar ( ) , <EOL> FinishAfter ( after_n_epochs = epochs ) <EOL> . add_condition ( [ "<STR_LIT>" ] , _is_nan ) , <EOL> ] <EOL> if bokeh : <EOL> from blocks . extras . extensions . plot import Plot <EOL> extensions . append ( Plot ( <EOL> '<STR_LIT>' , <EOL> channels = [ [ '<STR_LIT>' ] ] , every_n_batches = <NUM_LIT:10> ) ) <EOL> main_loop = MainLoop ( <EOL> model = model , <EOL> data_stream = train_stream , <EOL> algorithm = algorithm , <EOL> extensions = extensions <EOL> ) <EOL> main_loop . run ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> parser = ArgumentParser ( ) <EOL> parser . add_argument ( "<STR_LIT>" , type = str , <EOL> default = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , type = int , <EOL> default = <NUM_LIT> , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , type = int , dest = "<STR_LIT>" , <EOL> default = <NUM_LIT> , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , type = float , <EOL> dest = "<STR_LIT>" , default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , type = int , <EOL> default = <NUM_LIT> , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , type = int , <EOL> default = <NUM_LIT:20> , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , type = str , dest = "<STR_LIT>" , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , type = int , default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store_true>' , default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store_true>' , default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , type = float , default = <NUM_LIT:0> , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , type = int , <EOL> default = <NUM_LIT:3> , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , type = float , <EOL> default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , type = str , default = "<STR_LIT>" , <EOL> choices = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , type = float , default = <NUM_LIT> , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store_true>' , default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store_true>' , default = False , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , action = '<STR_LIT:store_true>' , default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , type = float , default = <NUM_LIT:0> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> args = parser . parse_args ( ) <EOL> main ( ** vars ( args ) ) </s>
