simpletransformers/seq2seq/seq2seq_model.py
def evaluate(self, eval_dataset, output_dir, verbose=True, silent=False, **kwargs):
        """
        Evaluates the model on eval_dataset.

        Utility function to be used by the eval_model() method. Not intended to be used directly.
        """

        model = self.model
        args = self.args
        eval_output_dir = output_dir

        results = {}

        eval_sampler = SequentialSampler(eval_dataset)
        eval_dataloader = DataLoader(eval_dataset, sampler=eval_sampler, batch_size=args.eval_batch_size)

        if args.n_gpu > 1:
            model = torch.nn.DataParallel(model)

        eval_loss = 0.0
        nb_eval_steps = 0
        model.eval()

        if args.n_gpu > 1:
            model = torch.nn.DataParallel(model)

        if self.args.fp16:
            from torch.cuda import amp

        for batch in tqdm(eval_dataloader, disable=args.silent or silent, desc="Running Evaluation"):
            # batch = tuple(t.to(device) for t in batch)

            inputs = self._get_inputs_dict(batch)
            with torch.no_grad():
                if self.args.fp16:
                    with amp.autocast():
                        outputs = model(**inputs)
                        loss = outputs[0]
                else:
                    outputs = model(**inputs)
                    loss = outputs[0]
                eval_loss += loss.mean().item()
            nb_eval_steps += 1

        eval_loss = eval_loss / nb_eval_steps

        results["eval_loss"] = eval_loss

        output_eval_file = os.path.join(eval_output_dir, "eval_results.txt")
        with open(output_eval_file, "w") as writer:
            for key in sorted(results.keys()):
                writer.write("{} = {}\n".format(key, str(results[key])))

        return results

        Evaluates the model on eval_dataset.

        Utility function to be used by the eval_model() method. Not intended to be used directly.
        
Evaluates the model on eval_dataset.
Utility function to be used by the eval_model() method. Not intended to be used directly.
Evaluates the model on eval_dataset . Utility function to be used by the eval_model () method . Not intended to be used directly .
def evaluate(self, eval_dataset, output_dir, verbose=True, silent=False, **kwargs):
        model = self.model
        args = self.args
        eval_output_dir = output_dir
        results = {}
        eval_sampler = SequentialSampler(eval_dataset)
        eval_dataloader = DataLoader(eval_dataset, sampler=eval_sampler, batch_size=args.eval_batch_size)
        if args.n_gpu > 1:
            model = torch.nn.DataParallel(model)
        eval_loss = 0.0
        nb_eval_steps = 0
        model.eval()
        if args.n_gpu > 1:
            model = torch.nn.DataParallel(model)
        if self.args.fp16:
            from torch.cuda import amp
        for batch in tqdm(eval_dataloader, disable=args.silent or silent, desc="Running Evaluation"):
            inputs = self._get_inputs_dict(batch)
            with torch.no_grad():
                if self.args.fp16:
                    with amp.autocast():
                        outputs = model(**inputs)
                        loss = outputs[0]
                else:
                    outputs = model(**inputs)
                    loss = outputs[0]
                eval_loss += loss.mean().item()
            nb_eval_steps += 1
        eval_loss = eval_loss / nb_eval_steps
        results["eval_loss"] = eval_loss
        output_eval_file = os.path.join(eval_output_dir, "eval_results.txt")
        with open(output_eval_file, "w") as writer:
            for key in sorted(results.keys()):
                writer.write("{} = {}\n".format(key, str(results[key])))
        return results
def evaluate ( self , eval_dataset , output_dir , verbose = True , silent = False , ** kwargs ) : model = self . model args = self . args eval_output_dir = output_dir results = { } eval_sampler = SequentialSampler ( eval_dataset ) eval_dataloader = DataLoader ( eval_dataset , sampler = eval_sampler , batch_size = args . eval_batch_size ) if args . n_gpu > 1 : model = torch . nn . DataParallel ( model ) eval_loss = 0.0 nb_eval_steps = 0 model . eval ( ) if args . n_gpu > 1 : model = torch . nn . DataParallel ( model ) if self . args . fp16 : from torch . cuda import amp for batch in tqdm ( eval_dataloader , disable = args . silent or silent , desc = "Running Evaluation" ) : inputs = self . _get_inputs_dict ( batch ) with torch . no_grad ( ) : if self . args . fp16 : with amp . autocast ( ) : outputs = model ( ** inputs ) loss = outputs [ 0 ] else : outputs = model ( ** inputs ) loss = outputs [ 0 ] eval_loss += loss . mean ( ) . item ( ) nb_eval_steps += 1 eval_loss = eval_loss / nb_eval_steps results [ "eval_loss" ] = eval_loss output_eval_file = os . path . join ( eval_output_dir , "eval_results.txt" ) with open ( output_eval_file , "w" ) as writer : for key in sorted ( results . keys ( ) ) : writer . write ( "{} = {}\n" . format ( key , str ( results [ key ] ) ) ) return results
Evaluates the model on eval_dataset.
Evaluates the model on eval_dataset .
"""
        Evaluates the model on eval_dataset.

        Utility function to be used by the eval_model() method. Not intended to be used directly.
        """ # batch = tuple(t.to(device) for t in batch)
self
eval_dataset
output_dir
verbose
silent