#NEWLINE# def train( self , train_set , valid_set = None , test_set = None , train_size = None ) : #NEWLINE# #INDENT# 'We train over mini-batches and evaluate periodically.' #NEWLINE# iteration = 0 #NEWLINE# while True : #NEWLINE# #INDENT# if ( ( not ( iteration % self . config . test_frequency ) ) and test_set ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . test ( iteration , test_set ) #NEWLINE# #UNINDENT# except KeyboardInterrupt : #NEWLINE# #INDENT# logging . info ( 'interrupted!' ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if ( ( not ( iteration % self . validation_frequency ) ) and valid_set ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( not self . evaluate ( iteration , valid_set ) ) : #NEWLINE# #INDENT# logging . info ( 'patience elapsed, bailing out' ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# except KeyboardInterrupt : #NEWLINE# #INDENT# logging . info ( 'interrupted!' ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# train_message = '' #NEWLINE# try : #NEWLINE# #INDENT# train_message = self . train_func ( test_set ) #NEWLINE# #UNINDENT# except KeyboardInterrupt : #NEWLINE# #INDENT# logging . info ( 'interrupted!' ) #NEWLINE# break #NEWLINE# #UNINDENT# if ( not ( iteration % self . config . monitor_frequency ) ) : #NEWLINE# #INDENT# logging . info ( 'monitor (iter=%i) %s' , ( iteration + 1 ) , train_message ) #NEWLINE# #UNINDENT# iteration += 1 #NEWLINE# if hasattr ( self . network , 'iteration_callback' ) : #NEWLINE# #INDENT# self . network . iteration_callback ( ) #NEWLINE# #UNINDENT# ( yield train_message ) #NEWLINE# #UNINDENT# if valid_set : #NEWLINE# #INDENT# self . set_params ( self . best_params ) #NEWLINE# #UNINDENT# if test_set : #NEWLINE# #INDENT# self . test ( 0 , test_set )