def predict(self, eval_dataset: Optional[Dataset]=None, prediction_loss_only: Optional[bool]=None, scoring_model: Optional[str]=None):
    logging.info('*** Test ***')
    datasets = (eval_dataset or self.test_datasets)
    for (task_name, test_dataset) in datasets.items():
        logger.info(task_name)
        test_dataloader = self.get_test_dataloader(test_dataset)
        test_result = self._prediction_loop(test_dataloader, description='Prediction', task_name=task_name, mode=test_dataset.mode)
        self._log(test_result.metrics)
        for (key, value) in test_result.metrics.items():
            logger.info('  %s = %s', key, value)
        softmax = torch.nn.Softmax(dim=1)
        probs = softmax(torch.Tensor(test_result.predictions)).numpy().astype('float64')
        logits = test_result.predictions.astype('float64')
        output_mode = task_output_modes[task_name]
        if (output_mode == 'classification'):
            predictions = np.argmax(logits, axis=1)
        self.run_name = wandb.run.name
        output_test_file = os.path.join(self.args.output_dir, f'{task_name}_test_iter_{self.run_name}.tsv')
        if (scoring_model is None):
            scoring_model = self.run_name
        if self.is_world_master():
            with open(output_test_file, 'w') as writer:
                logger.info('***** Test results {} *****'.format(task_name))
                logger.info('***** Writing as {} *****'.format(self.run_name))
                if (output_mode == 'regression'):
                    writer.write('index\tprediction\n')
                else:
                    writer.write('index\tscoring_model\tprediction\tprobability\tlogits\n')
                for (index, item) in enumerate(predictions):
                    if (output_mode == 'regression'):
                        writer.write(('%d\t%3.3f\n' % (index, item)))
                    else:
                        i_probs = probs[index, :]
                        i_logits = logits[index, :]
                        i_logits = json.dumps(dict(zip(test_dataset.get_labels(), i_logits)))
                        writer.write(('%d\t%s\t%s\t%3.6f\t%s\n' % (index, scoring_model, test_dataset.get_labels()[item], i_probs[item], i_logits)))
def predict(self, eval_dataset: Optional[Dataset]=None, prediction_loss_only: Optional[bool]=None, scoring_model: Optional[str]=None):
    logging.info('*** Test ***')
    datasets = (eval_dataset or self.test_datasets)
    for (task_name, test_dataset) in datasets.items():
        logger.info(task_name)
        test_dataloader = self.get_test_dataloader(test_dataset)
        test_result = self._prediction_loop(test_dataloader, description='Prediction', task_name=task_name, mode=test_dataset.mode)
        self._log(test_result.metrics)
        for (key, value) in test_result.metrics.items():
            logger.info('  %s = %s', key, value)
        softmax = torch.nn.Softmax(dim=1)
        probs = softmax(torch.Tensor(test_result.predictions)).numpy().astype('float64')
        logits = test_result.predictions.astype('float64')
        output_mode = task_output_modes[task_name]
        if (output_mode == 'classification'):
            predictions = np.argmax(logits, axis=1)
        self.run_name = wandb.run.name
        output_test_file = os.path.join(self.args.output_dir, f'{task_name}_test_iter_{self.run_name}.tsv')
        if (scoring_model is None):
            scoring_model = self.run_name
        if self.is_world_master():
            with open(output_test_file, 'w') as writer:
                logger.info('***** Test results {} *****'.format(task_name))
                logger.info('***** Writing as {} *****'.format(self.run_name))
                if (output_mode == 'regression'):
                    writer.write('index\tprediction\n')
                else:
                    writer.write('index\tscoring_model\tprediction\tprobability\tlogits\n')
                for (index, item) in enumerate(predictions):
                    if (output_mode == 'regression'):
                        writer.write(('%d\t%3.3f\n' % (index, item)))
                    else:
                        i_probs = probs[index, :]
                        i_logits = logits[index, :]
                        i_logits = json.dumps(dict(zip(test_dataset.get_labels(), i_logits)))
                        writer.write(('%d\t%s\t%s\t%3.6f\t%s\n' % (index, scoring_model, test_dataset.get_labels()[item], i_probs[item], i_logits)))