class_docstr: The TextAttack model benchmarking module:
  
  A command line parser to evaluatate a model from user
  specifications.
class_docstr_tok: ["The","TextAttack","model","benchmarking","module",":","A","command","line","parser","to","evaluatate","a","model","from","user","specifications","."]
code: def test_model_on_dataset(self, args):
      model = ModelArgs._create_model_from_args(args)
      dataset = DatasetArgs._create_dataset_from_args(args)
      if args.num_examples == -1:
          args.num_examples = len(dataset)
  
      preds = []
      ground_truth_outputs = []
      i = 0
      while i < min(args.num_examples, len(dataset)):
          dataset_batch = dataset[
              i : min(args.num_examples, i + args.batch_size)
          ]
          batch_inputs = []
          for text_input, ground_truth_output in dataset_batch:
              attacked_text = textattack.shared.AttackedText(text_input)
              batch_inputs.append(attacked_text.tokenizer_input)
              ground_truth_outputs.append(ground_truth_output)
          batch_preds = model(batch_inputs)
  
          if not isinstance(batch_preds, torch.Tensor):
              batch_preds = torch.Tensor(batch_preds)
  
          preds.extend(batch_preds)
          i += args.batch_size
  
      preds = torch.stack(preds).squeeze().cpu()
      ground_truth_outputs = torch.tensor(ground_truth_outputs).cpu()
  
      logger.info(f"Got {len(preds)} predictions.")
  
      if preds.ndim == 1:
          # if preds is just a list of numbers, assume regression for now
          # TODO integrate with `textattack.metrics` package
          pearson_correlation, _ = scipy.stats.pearsonr(
              ground_truth_outputs, preds
          )
          spearman_correlation, _ = scipy.stats.spearmanr(
              ground_truth_outputs, preds
          )
  
          logger.info(
              f"Pearson correlation = {_cb(pearson_correlation)}"
          )
          logger.info(
              f"Spearman correlation = {_cb(spearman_correlation)}"
          )
      else:
          guess_labels = preds.argmax(dim=1)
          successes = (
              (guess_labels == ground_truth_outputs).sum().item()
          )
          perc_accuracy = successes / len(preds) * 100.0
          perc_accuracy = "{:.2f}%".format(perc_accuracy)
          logger.info(
              f"Correct {successes}/{len(preds)} ({_cb(perc_accuracy)})"
          )
  
file_path: TextAttack/textattack/commands/eval_model_command.py
imports: from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
  from dataclasses import dataclass
  import scipy
  import torch
  import textattack
  from textattack import DatasetArgs, ModelArgs
  from textattack.commands import TextAttackCommand
  from textattack.model_args import HUGGINGFACE_MODELS, TEXTATTACK_MODELS
label_desc: Use image node_id 2 for calling the EvalModelCommand obj's underlying member method code with example usage: obj.test_model_on_dataset(args) without return types