code: def main():
      args = parse_args()
      use_cuda = torch.cuda.is_available()
      torch.backends.cudnn.benchmark = True
      random.seed(1337)
      torch.manual_seed(1337)
      if not use_cuda:
          print(
              "warning, the experiments would take ages to run on cpu"
          )
  
      hyperparams = vars(args)
  
      heuristic = get_heuristic(
          hyperparams["heuristic"], hyperparams["shuffle_prop"]
      )
  
      model = BertForSequenceClassification.from_pretrained(
          pretrained_model_name_or_path=hyperparams["model"]
      )
      tokenizer = BertTokenizer.from_pretrained(
          pretrained_model_name_or_path=hyperparams["model"]
      )
  
      # In this example we use tokenizer once only in the beginning since it would
      # make the whole process faster. However, it is also possible to input tokenizer
      # in trainer.
      active_set, test_set = get_datasets(
          hyperparams["initial_pool"], tokenizer
      )
  
      # change dropout layer to MCDropout
      model = patch_module(model)
  
      if use_cuda:
          model.cuda()
  
      init_weights = deepcopy(model.state_dict())
  
      training_args = TrainingArguments(
          output_dir="/app/baal/results",  # output directory
          num_train_epochs=hyperparams[
              "learning_epoch"
          ],  # total # of training epochs
          per_device_train_batch_size=16,  # batch size per device during training
          per_device_eval_batch_size=64,  # batch size for evaluation
          weight_decay=0.01,  # strength of weight decay
          logging_dir="/app/baal/logs",  # directory for storing logs
      )
  
      # We wrap the huggingface Trainer to create an Active Learning Trainer
      model = BaalTransformersTrainer(
          model=model,
          args=training_args,
          train_dataset=active_set,
          eval_dataset=test_set,
          tokenizer=None,
      )
  
      logs = {}
      logs["epoch"] = 0
  
      # In this case, nlp data is fast to process and we do NoT need to use a smaller batch_size
      active_loop = ActiveLearningLoop(
          active_set,
          model.predict_on_dataset,
          heuristic,
          hyperparams.get("query_size", 1),
          iterations=hyperparams["iterations"],
      )
  
      for epoch in tqdm(range(args.epoch)):
          # we use the default setup of HuggingFace for training (ex: epoch=1).
          # The setup is adjustable when BaalHuggingFaceTrainer is defined.
          model.train()
  
          # Validation!
          eval_metrics = model.evaluate()
  
          # We reorder the unlabelled pool at the frequency of learning_epoch
          # This helps with speed while not changing the quality of uncertainty estimation.
          should_continue = active_loop.step()
  
          # We reset the model weights to relearn from the new trainset.
          model.load_state_dict(init_weights)
          model.lr_scheduler = None
          if not should_continue:
              break
          active_logs = {
              "epoch": epoch,
              "labeled_data": active_set.labelled_map,
              "Next Training set size": len(active_set),
          }
  
          logs = {**eval_metrics, **active_logs}
          print(logs)
  
file_path: baal/experiments/nlp_bert_mcdropout.py
imports: import argparse
  import random
  from copy import deepcopy
  import torch
  import torch.backends
  from tqdm import tqdm
  from datasets import load_dataset
  from transformers import BertTokenizer, TrainingArguments
  from transformers import BertForSequenceClassification
  from baal.active import get_heuristic
  from baal.active.active_loop import ActiveLearningLoop
  from baal.active.dataset.nlp_datasets import active_huggingface_dataset, HuggingFaceDatasets
  from baal.bayesian.dropout import patch_module
  from baal.transformers_trainer_wrapper import BaalTransformersTrainer
label_desc: Use image node_id 3 for calling a global function with example usage: main() without return types