simpletransformers/seq2seq/seq2seq_model.py
def train_model(
        self, train_data, output_dir=None, show_running_loss=True, args=None, eval_data=None, test_data=None, verbose=True, **kwargs,
    ):
        """
        Trains the model using 'train_data'

        Args:
            train_data: Pandas DataFrame containing the 2 columns - `input_text`, `target_text`.
                        - `input_text`: The input text sequence.
                        - `target_text`: The target text sequence
            output_dir: The directory where model files will be saved. If not given, self.args.output_dir will be used.
            show_running_loss (optional): Set to False to prevent running loss from being printed to console. Defaults to True.
            args (optional): Optional changes to the args dict of the model. Any changes made will persist for the model.
            eval_data (optional): A DataFrame against which evaluation will be performed when evaluate_during_training is enabled. Is required if evaluate_during_training is enabled.
            test_data (optional): Test data which prediction will be performed when predict_during_training is enabled. Is required if prediction_during_training is enabled.
            **kwargs: Additional metrics that should be used. Pass in the metrics as keyword arguments (name of metric: function to use).
                        A metric function should take in two parameters. The first parameter will be the true labels, and the second parameter will be the predictions. Both inputs
                        will be lists of strings. Note that this will slow down training significantly as the predicted sequences need to be generated.

        Returns:
            None
        """  # noqa: ignore flake8"

        if args:
            self.args.update_from_dict(args)

        # if self.args.silent:
        #     show_running_loss = False

        if self.args.evaluate_during_training and eval_data is None:
            raise ValueError(
                "evaluate_during_training is enabled but eval_data is not specified."
                " Pass eval_data to model.train_model() if using evaluate_during_training."
            )

        if self.args.predict_during_training and test_data is None:
            raise ValueError(
                "predict_during_training is enabled but test_data is not specified."
                " Pass test_data to model.train_model() if using predict_during_training."
            )

        if not output_dir:
            output_dir = self.args.output_dir

        if os.path.exists(output_dir) and os.listdir(output_dir) and not self.args.overwrite_output_dir:
            raise ValueError(
                "Output directory ({}) already exists and is not empty."
                " Set args.overwrite_output_dir = True to overcome.".format(output_dir)
            )

        self._move_model_to_device()

        train_dataset = self.load_and_cache_examples(train_data, verbose=verbose)

        os.makedirs(output_dir, exist_ok=True)

        global_step, tr_loss = self.train(
            train_dataset,
            output_dir,
            show_running_loss=show_running_loss,
            eval_data=eval_data,
            test_data=test_data,
            verbose=verbose,
            **kwargs,
        )

        self.save_model(self.args.output_dir, model=self.model)

        # model_to_save = self.model.module if hasattr(self.model, "module") else self.model
        # model_to_save.save_pretrained(output_dir)
        # self.encoder_tokenizer.save_pretrained(output_dir)
        # self.decoder_tokenizer.save_pretrained(output_dir)
        # torch.save(self.args, os.path.join(output_dir, "training_args.bin"))

        if verbose:
            logger.info(" Training of {} model complete. Saved to {}.".format(self.args.model_name, output_dir))

        Trains the model using 'train_data'

        Args:
            train_data: Pandas DataFrame containing the 2 columns - `input_text`, `target_text`.
                        - `input_text`: The input text sequence.
                        - `target_text`: The target text sequence
            output_dir: The directory where model files will be saved. If not given, self.args.output_dir will be used.
            show_running_loss (optional): Set to False to prevent running loss from being printed to console. Defaults to True.
            args (optional): Optional changes to the args dict of the model. Any changes made will persist for the model.
            eval_data (optional): A DataFrame against which evaluation will be performed when evaluate_during_training is enabled. Is required if evaluate_during_training is enabled.
            test_data (optional): Test data which prediction will be performed when predict_during_training is enabled. Is required if prediction_during_training is enabled.
            **kwargs: Additional metrics that should be used. Pass in the metrics as keyword arguments (name of metric: function to use).
                        A metric function should take in two parameters. The first parameter will be the true labels, and the second parameter will be the predictions. Both inputs
                        will be lists of strings. Note that this will slow down training significantly as the predicted sequences need to be generated.

        Returns:
            None
        
Trains the model using 'train_data'
Trains the model using ' train_data '
def train_model(
        self, train_data, output_dir=None, show_running_loss=True, args=None, eval_data=None, test_data=None, verbose=True, **kwargs,
    ):
        if args:
            self.args.update_from_dict(args)
        if self.args.evaluate_during_training and eval_data is None:
            raise ValueError(
                "evaluate_during_training is enabled but eval_data is not specified."
                " Pass eval_data to model.train_model() if using evaluate_during_training."
            )
        if self.args.predict_during_training and test_data is None:
            raise ValueError(
                "predict_during_training is enabled but test_data is not specified."
                " Pass test_data to model.train_model() if using predict_during_training."
            )
        if not output_dir:
            output_dir = self.args.output_dir
        if os.path.exists(output_dir) and os.listdir(output_dir) and not self.args.overwrite_output_dir:
            raise ValueError(
                "Output directory ({}) already exists and is not empty."
                " Set args.overwrite_output_dir = True to overcome.".format(output_dir)
            )
        self._move_model_to_device()
        train_dataset = self.load_and_cache_examples(train_data, verbose=verbose)
        os.makedirs(output_dir, exist_ok=True)
        global_step, tr_loss = self.train(
            train_dataset,
            output_dir,
            show_running_loss=show_running_loss,
            eval_data=eval_data,
            test_data=test_data,
            verbose=verbose,
            **kwargs,
        )
        self.save_model(self.args.output_dir, model=self.model)
        if verbose:
            logger.info(" Training of {} model complete. Saved to {}.".format(self.args.model_name, output_dir))
def train_model ( self , train_data , output_dir = None , show_running_loss = True , args = None , eval_data = None , test_data = None , verbose = True , ** kwargs , ) : if args : self . args . update_from_dict ( args ) if self . args . evaluate_during_training and eval_data is None : raise ValueError ( "evaluate_during_training is enabled but eval_data is not specified." " Pass eval_data to model.train_model() if using evaluate_during_training." ) if self . args . predict_during_training and test_data is None : raise ValueError ( "predict_during_training is enabled but test_data is not specified." " Pass test_data to model.train_model() if using predict_during_training." ) if not output_dir : output_dir = self . args . output_dir if os . path . exists ( output_dir ) and os . listdir ( output_dir ) and not self . args . overwrite_output_dir : raise ValueError ( "Output directory ({}) already exists and is not empty." " Set args.overwrite_output_dir = True to overcome." . format ( output_dir ) ) self . _move_model_to_device ( ) train_dataset = self . load_and_cache_examples ( train_data , verbose = verbose ) os . makedirs ( output_dir , exist_ok = True ) global_step , tr_loss = self . train ( train_dataset , output_dir , show_running_loss = show_running_loss , eval_data = eval_data , test_data = test_data , verbose = verbose , ** kwargs , ) self . save_model ( self . args . output_dir , model = self . model ) if verbose : logger . info ( " Training of {} model complete. Saved to {}." . format ( self . args . model_name , output_dir ) )
Trains the model using 'train_data'
Trains the model using ' train_data '
"""
        Trains the model using 'train_data'

        Args:
            train_data: Pandas DataFrame containing the 2 columns - `input_text`, `target_text`.
                        - `input_text`: The input text sequence.
                        - `target_text`: The target text sequence
            output_dir: The directory where model files will be saved. If not given, self.args.output_dir will be used.
            show_running_loss (optional): Set to False to prevent running loss from being printed to console. Defaults to True.
            args (optional): Optional changes to the args dict of the model. Any changes made will persist for the model.
            eval_data (optional): A DataFrame against which evaluation will be performed when evaluate_during_training is enabled. Is required if evaluate_during_training is enabled.
            test_data (optional): Test data which prediction will be performed when predict_during_training is enabled. Is required if prediction_during_training is enabled.
            **kwargs: Additional metrics that should be used. Pass in the metrics as keyword arguments (name of metric: function to use).
                        A metric function should take in two parameters. The first parameter will be the true labels, and the second parameter will be the predictions. Both inputs
                        will be lists of strings. Note that this will slow down training significantly as the predicted sequences need to be generated.

        Returns:
            None
        """ # noqa: ignore flake8" # if self.args.silent: #     show_running_loss = False # model_to_save = self.model.module if hasattr(self.model, "module") else self.model # model_to_save.save_pretrained(output_dir) # self.encoder_tokenizer.save_pretrained(output_dir) # self.decoder_tokenizer.save_pretrained(output_dir) # torch.save(self.args, os.path.join(output_dir, "training_args.bin"))
None
self
train_data
Pandas DataFrame containing the 2 columns - `input_text`, `target_text`.
`input_text`: The input text sequence.
`target_text`: The target text sequence
Pandas DataFrame containing the 2 columns - ` input_text ` ` target_text ` . ` input_text ` : The input text sequence . ` target_text ` : The target text sequence
output_dir
The directory where model files will be saved. If not given, self.args.output_dir will be used.
The directory where model files will be saved . If not given self . args . output_dir will be used .
show_running_loss
Set to False to prevent running loss from being printed to console. Defaults to True.
Set to False to prevent running loss from being printed to console . Defaults to True .
True
args
Optional changes to the args dict of the model. Any changes made will persist for the model.
Optional changes to the args dict of the model . Any changes made will persist for the model .
eval_data
A DataFrame against which evaluation will be performed when evaluate_during_training is enabled. Is required if evaluate_during_training is enabled.
A DataFrame against which evaluation will be performed when evaluate_during_training is enabled . Is required if evaluate_during_training is enabled .
test_data
Test data which prediction will be performed when predict_during_training is enabled. Is required if prediction_during_training is enabled.
Test data which prediction will be performed when predict_during_training is enabled . Is required if prediction_during_training is enabled .
verbose
**kwargs
Additional metrics that should be used. Pass in the metrics as keyword arguments (name of metric: function to use).
A metric function should take in two parameters. The first parameter will be the true labels, and the second parameter will be the predictions. Both inputs
will be lists of strings. Note that this will slow down training significantly as the predicted sequences need to be generated.
Additional metrics that should be used . Pass in the metrics as keyword arguments ( name of metric : function to use ) . A metric function should take in two parameters . The first parameter will be the true labels and the second parameter will be the predictions . Both inputs will be lists of strings . Note that this will slow down training significantly as the predicted sequences need to be generated .