class_docstr: Wrapper to provide a common interfaces among different classifier modules
      
class_docstr_tok: ["Wrapper","to","provide","a","common","interfaces","among","different","classifier","modules"]
docstr: Calculate and store as model attributes:
  Average classification accuracy using rationales (self.avg_accuracy),
  Average classification accuracy rationale complements
      (self.anti_accuracy)
  Average sparsity of rationales (self.avg_sparsity)
  
  :param df_test: dataframe containing test data labels, tokens, masks,
      and counts
  :type df_test: pandas dataframe
  :param verbosity: {0, 1, 2}, default 2
      If 0, does not log any output
      If 1, logs accuracy, anti-rationale accuracy, sparsity, and
      continuity scores
      If 2, displays a random test example with rationale and
      classification
  :type verbosity: int, optional
docstr_tok: ["Calculate","and","store","as","model","attributes",":","Average","classification","accuracy","using","rationales","(","self.avg_accuracy",")",",","Average","classification","accuracy","rationale","complements","(","self.anti_accuracy",")","Average","sparsity","of","rationales","(","self.avg_sparsity",")",":","param","df_test",":","dataframe","containing","test","data","labels",",","tokens",",","masks",",","and","counts",":","type","df_test",":","pandas","dataframe",":","param","verbosity",":","{","0",",","1",",","2","}",",","default","2","If","0",",","does","not","log","any","output","If","1",",","logs","accuracy",",","anti-rationale","accuracy",",","sparsity",",","and","continuity","scores","If","2",",","displays","a","random","test","example","with","rationale","and","classification",":","type","verbosity",":","int",",","optional"]
code: def test(self, df_test, verbosity=2):
      """Calculate and store as model attributes:
      Average classification accuracy using rationales (self.avg_accuracy),
      Average classification accuracy rationale complements
          (self.anti_accuracy)
      Average sparsity of rationales (self.avg_sparsity)
  
      :param df_test: dataframe containing test data labels, tokens, masks,
          and counts
      :type df_test: pandas dataframe
      :param verbosity: {0, 1, 2}, default 2
          If 0, does not log any output
          If 1, logs accuracy, anti-rationale accuracy, sparsity, and
          continuity scores
          If 2, displays a random test example with rationale and
          classification
      :type verbosity: int, optional
      """
      self.model.eval()
      accuracy = 0
      for i in range(len(df_test) // self.args.test_batch_size):
          test_batch = df_test.iloc[
              i
              * self.args.test_batch_size : (i + 1)
              * self.args.test_batch_size
          ]
          batch_dict = generate_data(test_batch, self.args.cuda)
          batch_x_ = batch_dict["x"]
          batch_m_ = batch_dict["m"]
          batch_y_ = batch_dict["y"]
          predict, _, _ = self.model(batch_x_, batch_m_)
  
          # do a softmax on the predicted class probabilities
          _, y_pred = torch.max(predict, dim=1)
  
          accuracy += (y_pred == batch_y_).sum().item()
  
      self.avg_accuracy = accuracy / len(df_test)
      self.test_accs.append(self.avg_accuracy)
  
      if verbosity > 0:
          logging.info(
              "train acc: %.4f, test acc: %.4f"
              % (self.train_accs[-1], self.avg_accuracy)
          )
  
      if self.args.save_best_model:
          if self.avg_accuracy > self.best_test_acc:
              logging.info(
                  "saving best classifier model and model stats"
              )
              # save model
              torch.save(
                  self.model.state_dict(),
                  os.path.join(
                      self.args.model_folder_path,
                      self.args.model_prefix + "gen_classifier.pth",
                  ),
              )
  
      if self.avg_accuracy > self.best_test_acc:
          self.best_test_acc = self.avg_accuracy
          self.epochs_since_improv = 0
      else:
          self.epochs_since_improv += 1
  
imports: import os
  import logging
  import numpy
  import torch
  import torch.nn
  from torch.autograd import Variable
  from tqdm import tqdm
  from interpret_text.experimental.common.utils_introspective_rationale import generate_data
label_desc: Use image node_id 3 for calling the ClassifierWrapper obj's underlying member method code with example usage: obj.test(df_test, verbosity) without return types