(self, step)
Output useful information to stdout and the log file if debugging is required.
        :step: Print the corresponding step in the log
Output useful information to stdout and the log file if debugging is required.
        :step: Print the corresponding step in the log
Output useful information to stdout and the log file if debugging is required . : step : Print the corresponding step in the log
def _print_log(self, step):
        """
        Output useful information to stdout and the log file if debugging is required.
        :step: Print the corresponding step in the log
        """
        
        # Set mode to append to log file
        mode = 'a'

        if self.logfile is None:
            # Increment log counter for the class. Each instance of the class generates a new log.
            self.__class__.log_no += 1

            # Create a log file for the instance
            # Logs will be stored in ..\logs\SKLearn Log <n>.txt
            self.logfile = os.path.join(os.getcwd(), 'logs', 'SpaCy Log {}.txt'.format(self.log_no))
        
        if step == 1:
            # Output log header
            output = "\nSpaCyForQlik Log: {0} \n\n".format(time.ctime(time.time()))
            # Set mode to write new log file
            mode = 'w'
                                
        elif step == 2:
            # Output the model name and execution parameters to the terminal and log file
            output = "Model: {0}\n\n".format(self.model)
            output += "Execution parameters: {0}\n\n".format(self.kwargs) 
        
        elif step == 3:
            # Output the request data frame to the terminal and log file
            output = "REQUEST: {0} rows x cols\nSample Data:\n\n".format(self.request_df.shape)
            output += "{0}\n...\n{1}\n\n".format(self.request_df.head().to_string(), self.request_df.tail().to_string())
        
        elif step == 4:
            # Output the response data frame to the terminal and log file
            output = "RESPONSE: {0} rows x cols\nSample Data:\n\n".format(self.response_df.shape)
            output += "{0}\n...\n{1}\n\n".format(self.response_df.head().to_string(), self.response_df.tail().to_string())
        
        elif step == 5:
            # Output the table description if the call was made from the load script
            output = "\nTABLE DESCRIPTION SENT TO QLIK:\n\n{0} \n\n".format(self.table)
        
        elif step == 6:
            output = "Completed transformations.\nTop and bottom 3 samples for training:\n\n"
            
            # Output the top and bottom 3 results from training data
            for text, annotations in self.train[:3] + self.train[-3:]:
                output += '{0}\n\n {1}\n\n'.format(text, annotations)
            
            # Print the top and bottom 3 testing samples as well if the data has been split into subsets
            try:
                output += "Data split into {0} samples for training and {1} samples for testing.\n".format(len(self.train), len(self.validation))
                output += "Top and bottom 3 samples for testing:\n\n"

                # Output the top and bottom 3 results from the testing data
                for text, annotations in self.validation[:3] + self.validation[-3:]:
                    output += '{0}\n\n {1}\n\n'.format(text, annotations)
            except (TypeError, AttributeError) as e:
                pass
        
        elif step == 7:
            # Output after a model is successfully loaded for training
            output = "Loaded model {0}\n\n".format(self.base_model)

        elif step == 8:
            # Print loss at current epoch with training data
            output = "{0}, Losses with Training data: {1}\n".format(self.losses_train[-1][0], self.losses_train[-1][1])

        elif step == 9:
            # Print loss at current epoch with testing data
            output = "{0}, Losses with Testing data: {1}\n".format(self.losses_test[-1][0], self.losses_test[-1][1])

        elif step == 10:
            # Output after model is successfully saved to disk
            output = "\nModel successfully saved to disk at directory: {0}\n\n".format(self.path + self.model + '/')

        elif step == 11:
            # Output after evaluation metrics have been calculated
            output = "RESPONSE: {0} rows x cols\nSample Data:\n\n".format(self.response_df.shape)
            output += "{0}\n...\n{1}\n\n".format(self.response_df.head(10).to_string(), self.response_df.tail(5).to_string())

        sys.stdout.write(output)
        with open(self.logfile, mode, encoding='utf-8') as f:
            f.write(output)
def _print_log ( self , step ) : # Set mode to append to log file mode = 'a' if self . logfile is None : # Increment log counter for the class. Each instance of the class generates a new log. self . __class__ . log_no += 1 # Create a log file for the instance # Logs will be stored in ..\logs\SKLearn Log <n>.txt self . logfile = os . path . join ( os . getcwd ( ) , 'logs' , 'SpaCy Log {}.txt' . format ( self . log_no ) ) if step == 1 : # Output log header output = "\nSpaCyForQlik Log: {0} \n\n" . format ( time . ctime ( time . time ( ) ) ) # Set mode to write new log file mode = 'w' elif step == 2 : # Output the model name and execution parameters to the terminal and log file output = "Model: {0}\n\n" . format ( self . model ) output += "Execution parameters: {0}\n\n" . format ( self . kwargs ) elif step == 3 : # Output the request data frame to the terminal and log file output = "REQUEST: {0} rows x cols\nSample Data:\n\n" . format ( self . request_df . shape ) output += "{0}\n...\n{1}\n\n" . format ( self . request_df . head ( ) . to_string ( ) , self . request_df . tail ( ) . to_string ( ) ) elif step == 4 : # Output the response data frame to the terminal and log file output = "RESPONSE: {0} rows x cols\nSample Data:\n\n" . format ( self . response_df . shape ) output += "{0}\n...\n{1}\n\n" . format ( self . response_df . head ( ) . to_string ( ) , self . response_df . tail ( ) . to_string ( ) ) elif step == 5 : # Output the table description if the call was made from the load script output = "\nTABLE DESCRIPTION SENT TO QLIK:\n\n{0} \n\n" . format ( self . table ) elif step == 6 : output = "Completed transformations.\nTop and bottom 3 samples for training:\n\n" # Output the top and bottom 3 results from training data for text , annotations in self . train [ : 3 ] + self . train [ - 3 : ] : output += '{0}\n\n {1}\n\n' . format ( text , annotations ) # Print the top and bottom 3 testing samples as well if the data has been split into subsets try : output += "Data split into {0} samples for training and {1} samples for testing.\n" . format ( len ( self . train ) , len ( self . validation ) ) output += "Top and bottom 3 samples for testing:\n\n" # Output the top and bottom 3 results from the testing data for text , annotations in self . validation [ : 3 ] + self . validation [ - 3 : ] : output += '{0}\n\n {1}\n\n' . format ( text , annotations ) except ( TypeError , AttributeError ) as e : pass elif step == 7 : # Output after a model is successfully loaded for training output = "Loaded model {0}\n\n" . format ( self . base_model ) elif step == 8 : # Print loss at current epoch with training data output = "{0}, Losses with Training data: {1}\n" . format ( self . losses_train [ - 1 ] [ 0 ] , self . losses_train [ - 1 ] [ 1 ] ) elif step == 9 : # Print loss at current epoch with testing data output = "{0}, Losses with Testing data: {1}\n" . format ( self . losses_test [ - 1 ] [ 0 ] , self . losses_test [ - 1 ] [ 1 ] ) elif step == 10 : # Output after model is successfully saved to disk output = "\nModel successfully saved to disk at directory: {0}\n\n" . format ( self . path + self . model + '/' ) elif step == 11 : # Output after evaluation metrics have been calculated output = "RESPONSE: {0} rows x cols\nSample Data:\n\n" . format ( self . response_df . shape ) output += "{0}\n...\n{1}\n\n" . format ( self . response_df . head ( 10 ) . to_string ( ) , self . response_df . tail ( 5 ) . to_string ( ) ) sys . stdout . write ( output ) with open ( self . logfile , mode , encoding = 'utf-8' ) as f : f . write ( output )