class_docstr: BERT model for language embedding only encoder.
  
  Args:
      name (str, optional): name of the pretrained BERT model from
          HuggingFace. Defaults to bert-base-uncased.
      max_tokens (int, optional): maximum number of tokens to be
          used for BERT. Defaults to 256.
      pad_to_max (bool, optional): whether to pad the tokens to max_tokens.
           Defaults to True.
      use_sub_sentence_represent (bool, optional): whether to use sub
          sentence represent introduced in `Grounding DINO
          <https://arxiv.org/abs/2303.05499>`. Defaults to False.
      special_tokens_list (list, optional): special tokens used to split
          subsentence. It cannot be None when `use_sub_sentence_represent`
          is True. Defaults to None.
      add_pooling_layer (bool, optional): whether to adding pooling
          layer in bert encoder. Defaults to False.
      num_layers_of_embedded (int, optional): number of layers of
          the embedded model. Defaults to 1.
      use_checkpoint (bool, optional): whether to use gradient checkpointing.
           Defaults to False.
class_docstr_tok: ["BERT","model","for","language","embedding","only","encoder",".","Args",":","name","(","str",",","optional",")",":","name","of","the","pretrained","BERT","model","from","HuggingFace",".","Defaults","to","bert-base-uncased",".","max_tokens","(","int",",","optional",")",":","maximum","number","of","tokens","to","be","used","for","BERT",".","Defaults","to","256.","pad_to_max","(","bool",",","optional",")",":","whether","to","pad","the","tokens","to","max_tokens",".","Defaults","to","True",".","use_sub_sentence_represent","(","bool",",","optional",")",":","whether","to","use","sub","sentence","represent","introduced","in","`","Grounding","DINO","<","https",":","\/\/arxiv.org\/abs\/2303.05499",">","`",".","Defaults","to","False",".","special_tokens_list","(","list",",","optional",")",":","special","tokens","used","to","split","subsentence",".","It","can","not","be","None","when","`","use_sub_sentence_represent","`","is","True",".","Defaults","to","None",".","add_pooling_layer","(","bool",",","optional",")",":","whether","to","adding","pooling","layer","in","bert","encoder",".","Defaults","to","False",".","num_layers_of_embedded","(","int",",","optional",")",":","number","of","layers","of","the","embedded","model",".","Defaults","to","1.","use_checkpoint","(","bool",",","optional",")",":","whether","to","use","gradient","checkpointing",".","Defaults","to","False","."]
docstr: Forward function.
docstr_tok: ["Forward","function","."]
code: def forward(self, captions: Sequence[str], **kwargs) -> dict:
      """Forward function."""
      device = next(self.language_backbone.parameters()).device
      tokenized = self.tokenizer.batch_encode_plus(
          captions,
          max_length=self.max_tokens,
          padding="max_length" if self.pad_to_max else "longest",
          return_special_tokens_mask=True,
          return_tensors="pt",
          truncation=True,
      ).to(device)
      input_ids = tokenized.input_ids
      if self.use_sub_sentence_represent:
          (
              attention_mask,
              position_ids,
          ) = generate_masks_with_special_tokens_and_transfer_map(
              tokenized, self.special_tokens
          )
          token_type_ids = tokenized["token_type_ids"]
  
      else:
          attention_mask = tokenized.attention_mask
          position_ids = None
          token_type_ids = None
  
      tokenizer_input = {
          "input_ids": input_ids,
          "attention_mask": attention_mask,
          "position_ids": position_ids,
          "token_type_ids": token_type_ids,
      }
      language_dict_features = self.language_backbone(tokenizer_input)
      if self.use_sub_sentence_represent:
          language_dict_features["position_ids"] = position_ids
          language_dict_features[
              "text_token_mask"
          ] = tokenized.attention_mask.bool()
      return language_dict_features
  
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 BertModel obj's underlying member method code with example usage: obj.forward(captions) and returns: language_dict_features