class_docstr: BERT encoder for language embedding.
  
  Args:
      name (str): name of the pretrained BERT model from HuggingFace.
              Defaults to bert-base-uncased.
      add_pooling_layer (bool): whether to add a pooling layer.
      num_layers_of_embedded (int): number of layers of the embedded model.
              Defaults to 1.
      use_checkpoint (bool): whether to use gradient checkpointing.
              Defaults to False.
class_docstr_tok: ["BERT","encoder","for","language","embedding",".","Args",":","name","(","str",")",":","name","of","the","pretrained","BERT","model","from","HuggingFace",".","Defaults","to","bert-base-uncased",".","add_pooling_layer","(","bool",")",":","whether","to","add","a","pooling","layer",".","num_layers_of_embedded","(","int",")",":","number","of","layers","of","the","embedded","model",".","Defaults","to","1.","use_checkpoint","(","bool",")",":","whether","to","use","gradient","checkpointing",".","Defaults","to","False","."]
code: def forward(self, x) -> dict:
      mask = x["attention_mask"]
  
      outputs = self.model(
          input_ids=x["input_ids"],
          attention_mask=mask,
          position_ids=x["position_ids"],
          token_type_ids=x["token_type_ids"],
          output_hidden_states=True,
      )
  
      # outputs has 13 layers, 1 input layer and 12 hidden layers
      encoded_layers = outputs.hidden_states[1:]
      features = torch.stack(
          encoded_layers[-self.num_layers_of_embedded :], 1
      ).mean(1)
      # language embedding has shape [len(phrase), seq_len, language_dim]
      features = features / self.num_layers_of_embedded
      if mask.dim() == 2:
          embedded = features * mask.unsqueeze(-1).float()
      else:
          embedded = features
  
      results = {
          "embedded": embedded,
          "masks": mask,
          "hidden": encoded_layers[-1],
      }
      return results
  
file_path: mmdetection/mmdet/models/language_models/bert.py
imports: from collections import OrderedDict
  from typing import Sequence
  import torch
  from mmengine.model import BaseModel
  from torch import nn
  from mmdet.registry import MODELS
label_desc: Use image node_id 2 for calling the BertEncoder obj's underlying member method code with example usage: obj.forward(x) and returns: results