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","."]
code: def __init__(
      self,
      name: str = "bert-base-uncased",
      max_tokens: int = 256,
      pad_to_max: bool = True,
      use_sub_sentence_represent: bool = False,
      special_tokens_list: list = None,
      add_pooling_layer: bool = False,
      num_layers_of_embedded: int = 1,
      use_checkpoint: bool = False,
      **kwargs,
  ) -> None:
      super().__init__(**kwargs)
      self.max_tokens = max_tokens
      self.pad_to_max = pad_to_max
  
      if AutoTokenizer is None:
          raise RuntimeError(
              "transformers is not installed, please install it by: "
              "pip install transformers."
          )
  
      self.tokenizer = AutoTokenizer.from_pretrained(name)
      self.language_backbone = nn.Sequential(
          OrderedDict(
              [
                  (
                      "body",
                      BertEncoder(
                          name,
                          add_pooling_layer=add_pooling_layer,
                          num_layers_of_embedded=num_layers_of_embedded,
                          use_checkpoint=use_checkpoint,
                      ),
                  )
              ]
          )
      )
  
      self.use_sub_sentence_represent = use_sub_sentence_represent
      if self.use_sub_sentence_represent:
          assert (
              special_tokens_list is not None
          ), "special_tokens should not be None \
                      if use_sub_sentence_represent is True"
  
          self.special_tokens = self.tokenizer.convert_tokens_to_ids(
              special_tokens_list
          )
  
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 1 to create a new BertModel object from inherited base classes: BaseModel with example: obj = BertModel(name, max_tokens, pad_to_max, use_sub_sentence_represent, special_tokens_list, add_pooling_layer, num_layers_of_embedded, use_checkpoint)