class_docstr: BERT-based sequence classifier
docstr: Scores the given dataset and returns the predicted classes.
  
  Args:
      token_ids (list): List of training token lists.
      input_mask (list): List of input mask lists.
      token_type_ids (list, optional): List of lists. Each sublist
          contains segment ids indicating if the token belongs to
          the first sentence(0) or second sentence(1). Only needed
          for two-sentence tasks.
      num_gpus (int, optional): The number of gpus to use.
                                If None is specified, all available GPUs
                                will be used. Defaults to None.
      batch_size (int, optional): Scoring batch size. Defaults to 32.
      probabilities (bool, optional):
          If True, the predicted probability distribution
          is also returned. Defaults to False.
  Returns:
      1darray, namedtuple(1darray, ndarray): Predicted classes or
          (classes, probabilities) if probabilities is True.
docstr_tok: ["Scores","the","given","dataset","and","returns","the","predicted","classes",".","Args",":","token_ids","(","list",")",":","List","of","training","token","lists",".","input_mask","(","list",")",":","List","of","input","mask","lists",".","token_type_ids","(","list",",","optional",")",":","List","of","lists",".","Each","sublist","contains","segment","ids","indicating","if","the","token","belongs","to","the","first","sentence","(","0",")","or","second","sentence","(","1",")",".","Only","needed","for","two-sentence","tasks",".","num_gpus","(","int",",","optional",")",":","The","number","of","gpus","to","use",".","If","None","is","specified",",","all","available","GPUs","will","be","used",".","Defaults","to","None",".","batch_size","(","int",",","optional",")",":","Scoring","batch","size",".","Defaults","to","32.","probabilities","(","bool",",","optional",")",":","If","True",",","the","predicted","probability","distribution","is","also","returned",".","Defaults","to","False",".","Returns",":","1darray",",","namedtuple","(","1darray",",","ndarray",")",":","Predicted","classes","or","(","classes",",","probabilities",")","if","probabilities","is","True","."]
code: def predict(
      self,
      token_ids,
      input_mask,
      token_type_ids=None,
      num_gpus=None,
      batch_size=32,
      probabilities=False,
  ):
      """Scores the given dataset and returns the predicted classes.
  
      Args:
          token_ids (list): List of training token lists.
          input_mask (list): List of input mask lists.
          token_type_ids (list, optional): List of lists. Each sublist
              contains segment ids indicating if the token belongs to
              the first sentence(0) or second sentence(1). Only needed
              for two-sentence tasks.
          num_gpus (int, optional): The number of gpus to use.
                                    If None is specified, all available GPUs
                                    will be used. Defaults to None.
          batch_size (int, optional): Scoring batch size. Defaults to 32.
          probabilities (bool, optional):
              If True, the predicted probability distribution
              is also returned. Defaults to False.
      Returns:
          1darray, namedtuple(1darray, ndarray): Predicted classes or
              (classes, probabilities) if probabilities is True.
      """
      device, num_gpus = get_device(num_gpus)
      self.model = move_to_device(self.model, device, num_gpus)
  
      # score
      self.model.eval()
  
      token_ids_tensor = torch.tensor(token_ids, dtype=torch.long)
      input_mask_tensor = torch.tensor(input_mask, dtype=torch.long)
  
      if token_type_ids:
          token_type_ids_tensor = torch.tensor(
              token_type_ids, dtype=torch.long
          )
          test_dataset = TensorDataset(
              token_ids_tensor, input_mask_tensor, token_type_ids_tensor
          )
      else:
          test_dataset = TensorDataset(
              token_ids_tensor, input_mask_tensor
          )
  
      test_sampler = SequentialSampler(test_dataset)
      test_dataloader = DataLoader(
          test_dataset, sampler=test_sampler, batch_size=batch_size
      )
  
      preds = []
      for i, batch in enumerate(
          tqdm(test_dataloader, desc="Iteration")
      ):
          if token_type_ids:
              x_batch, mask_batch, token_type_ids_batch = tuple(
                  t.to(device) for t in batch
              )
          else:
              token_type_ids_batch = None
              x_batch, mask_batch = tuple(t.to(device) for t in batch)
  
          with torch.no_grad():
              p_batch = self.model(
                  input_ids=x_batch,
                  token_type_ids=token_type_ids_batch,
                  attention_mask=mask_batch,
                  labels=None,
              )
          preds.append(p_batch.cpu())
  
      preds = np.concatenate(preds)
  
      if probabilities:
          return namedtuple("Predictions", "classes probabilities")(
              preds.argmax(axis=1),
              nn.Softmax(dim=1)(torch.Tensor(preds)).numpy(),
          )
      else:
          return preds.argmax(axis=1)
  
imports: import logging
  import warnings
  from collections.abc import Iterable
  from enum import Enum
  import torch
  from pytorch_pretrained_bert.tokenization import BertTokenizer
  from tqdm import tqdm
  import numpy
  import torch.nn
  from torch.utils.data import DataLoader, RandomSampler, SequentialSampler, TensorDataset
  from pytorch_pretrained_bert.modeling import BertForSequenceClassification
  from pytorch_pretrained_bert.optimization import BertAdam
  from interpret_text.experimental.common.utils_pytorch import get_device, move_to_device
  from interpret_text.experimental.common.constants import BertTokens
  from collections import namedtuple
  from cached_property import cached_property
label_desc: Use image node_id 4 for calling the BERTSequenceClassifier obj's underlying member method code with example usage: obj.predict(token_ids, input_mask, token_type_ids, num_gpus, batch_size, probabilities) and returns: namedtuple, preds