class_docstr: Adds a optional transformer layer and classification layers on top of BERT.
  Args:
      bert_model: pretrained BERT model
      output_dim: dimension of the output layer for defult 1 linear layer classifier. Either output_dim or classifier_layer must be specified
      add_transformer_layer: if additional transformer layer should be added on top of the pretrained model
      layer_pulled: which layer should be pulled from pretrained model
      aggregation: embeddings aggregation (pooling) strategy. Available options are:
          (default)"first" - [CLS] representation,
          "mean" - average of all embeddings except CLS,
          "max" - max of all embeddings except CLS
      classifier_layer: classification layers, can be a signle layer, or list of layers (for ex, torch.nn.Sequential)
code: def __init__(
      self,
      bert_model: BertModel,
      output_dim: int = -1,
      add_transformer_layer: bool = False,
      layer_pulled: int = -1,
      aggregation: str = "first",
      classifier_layer: torch.nn.Module = None,
  ):
      super(BertWrapper, self).__init__()
      self.layer_pulled = layer_pulled
      self.aggregation = aggregation
      self.add_transformer_layer = add_transformer_layer
      # deduce bert output dim from the size of embeddings
      bert_output_dim = (
          bert_model.embeddings.word_embeddings.weight.size(1)
      )
  
      if add_transformer_layer:
          config_for_one_layer = BertConfig(
              0,
              hidden_size=bert_output_dim,
              num_attention_heads=int(bert_output_dim / 64),
              intermediate_size=3072,
              hidden_act="gelu",
          )
          self.additional_transformer_layer = BertLayer(
              config_for_one_layer
          )
      if classifier_layer is None and output_dim == -1:
          raise Exception(
              "Either output dimention or classifier layers must be specified"
          )
      elif classifier_layer is None:
          self.additional_linear_layer = torch.nn.Linear(
              bert_output_dim, output_dim
          )
      else:
          self.additional_linear_layer = classifier_layer
          if output_dim != -1:
              print(
                  "Both classifier layer and output dimension are specified. Output dimension parameter is ignored."
              )
      self.bert_model = bert_model
  
file_path: ParlAI/parlai/agents/bert_ranker/helpers.py
imports: from parlai.core.torch_ranker_agent import TorchRankerAgent
  from parlai.utils.torch import neginf
  import torch
label_desc: Use image node_id 1 to create a new BertWrapper object from inherited base classes: torch.nn with example: obj = BertWrapper(bert_model, output_dim, add_transformer_layer, layer_pulled, aggregation, classifier_layer)