(self)
return self.response_df
Retrain a spacy model for NER using training data.
Retrain a spacy model for NER using training data.
Retrain a spacy model for NER using training data .
def retrain(self):
        """
        Retrain a spacy model for NER using training data.
        """

        # The request provides training data texts, entities, entity types together with the model name and any other arguments
        row_template = ['strData', 'strData', 'strData', 'strData', 'strData']
        col_headers = ['text', 'entity', 'entity_type', 'model_name', 'kwargs']
        
        # Create a Pandas DataFrame for the request data
        self.request_df = utils.request_df(self.request, row_template, col_headers)

        # Get the argument strings from the request dataframe
        kwargs = self.request_df.loc[0, 'kwargs']
        # Set the relevant parameters using the argument strings
        self._set_params(kwargs)

        # Check that a model name has been set
        if self.model in ["en_core_web_sm"]:
            err = "Incorrect usage: A name for the custom model needs to be specified."
            raise Exception(err)
        
        # Transform the training data to spaCy's training data format
        # This call populates the self.train and self.validation (if a test set is specified in the request arguments) objects
        self._prep_data()

        # Retrain the model and calculate evaluation metrics
        # This call saves the retrained model to disk and pepares the self.metrics dataframe for the response
        self._retrain_model()

        # Prepare the response, which will be the evaluation metrics prepared during retraining
        self.response_df = self.metrics

        # Debug information is printed to the terminal and logs if the paramater debug = true
        if self.debug:
            self._print_log(11)
        
        # Send the reponse table description to Qlik
        self._send_table_description("metrics")
        
        # Finally send the response
        return self.response_df
def retrain ( self ) : # The request provides training data texts, entities, entity types together with the model name and any other arguments row_template = [ 'strData' , 'strData' , 'strData' , 'strData' , 'strData' ] col_headers = [ 'text' , 'entity' , 'entity_type' , 'model_name' , 'kwargs' ] # Create a Pandas DataFrame for the request data self . request_df = utils . request_df ( self . request , row_template , col_headers ) # Get the argument strings from the request dataframe kwargs = self . request_df . loc [ 0 , 'kwargs' ] # Set the relevant parameters using the argument strings self . _set_params ( kwargs ) # Check that a model name has been set if self . model in [ "en_core_web_sm" ] : err = "Incorrect usage: A name for the custom model needs to be specified." raise Exception ( err ) # Transform the training data to spaCy's training data format # This call populates the self.train and self.validation (if a test set is specified in the request arguments) objects self . _prep_data ( ) # Retrain the model and calculate evaluation metrics # This call saves the retrained model to disk and pepares the self.metrics dataframe for the response self . _retrain_model ( ) # Prepare the response, which will be the evaluation metrics prepared during retraining self . response_df = self . metrics # Debug information is printed to the terminal and logs if the paramater debug = true if self . debug : self . _print_log ( 11 ) # Send the reponse table description to Qlik self . _send_table_description ( "metrics" ) # Finally send the response return self . response_df