class_docstr: BERT language model pretraining.
class_docstr_tok: ["BERT","language","model","pretraining","."]
code: def __init__(self, cfg: DictConfig, trainer: Trainer = None):
      vocab_file = None
      config_dict = None
      config_file = None
  
      if cfg.tokenizer is not None:
          if cfg.tokenizer.get("tokenizer_name") and cfg.tokenizer.get(
              "tokenizer_model"
          ):
              self._setup_tokenizer(cfg.tokenizer)
          if cfg.get("tokenizer.vocab_file"):
              vocab_file = self.register_artifact(
                  "tokenizer.vocab_file", cfg.tokenizer.vocab_file
              )
      else:
          self.tokenizer = None
  
      super().__init__(cfg=cfg, trainer=trainer)
  
      if cfg.get("language_model.config"):
          config_dict = OmegaConf.to_container(
              cfg.language_model.config
          )
      if cfg.get("language_model.config_file"):
          config_file = self.register_artifact(
              "language_model.config_file",
              cfg.language_model.config_file,
          )
  
      self.bert_model = get_lm_model(
          config_file=config_file,
          config_dict=config_dict,
          vocab_file=vocab_file,
          trainer=trainer,
          cfg=cfg,
      )
  
      self.hidden_size = self.bert_model.config.hidden_size
      self.vocab_size = self.bert_model.config.vocab_size
      self.only_mlm_loss = cfg.only_mlm_loss
  
      self.mlm_classifier = BertPretrainingTokenClassifier(
          hidden_size=self.hidden_size,
          num_classes=self.vocab_size,
          num_layers=cfg.num_tok_classification_layers,
          activation="gelu",
          log_softmax=True,
          use_transformer_init=True,
      )
  
      self.mlm_loss = SmoothedCrossEntropyLoss()
  
      if not self.only_mlm_loss:
          self.nsp_classifier = SequenceClassifier(
              hidden_size=self.hidden_size,
              num_classes=2,
              num_layers=cfg.num_seq_classification_layers,
              log_softmax=False,
              activation="tanh",
              use_transformer_init=True,
          )
  
          self.nsp_loss = CrossEntropyLoss()
          self.agg_loss = AggregatorLoss(num_inputs=2)
  
      # # tie weights of MLM softmax layer and embedding layer of the encoder
      if (
          self.mlm_classifier.mlp.last_linear_layer.weight.shape
          != self.bert_model.embeddings.word_embeddings.weight.shape
      ):
          raise ValueError(
              "Final classification layer does not match embedding layer."
          )
      self.mlm_classifier.mlp.last_linear_layer.weight = (
          self.bert_model.embeddings.word_embeddings.weight
      )
      # create extra bias
  
      # setup to track metrics
      self.validation_perplexity = Perplexity()
  
      self.setup_optimization(cfg.optim)
  
imports: import os
  from typing import Dict, Optional
  import torch
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Trainer
  from torch.utils.data import DataLoader
  from nemo.collections.common.losses import AggregatorLoss, CrossEntropyLoss, SmoothedCrossEntropyLoss
  from nemo.collections.common.metrics import Perplexity
  from nemo.collections.nlp.data.language_modeling.lm_bert_dataset import BertPretrainingDataset, BertPretrainingPreprocessedDataloader
  from nemo.collections.nlp.modules.common import BertPretrainingTokenClassifier, SequenceClassifier
  from nemo.collections.nlp.modules.common.lm_utils import get_lm_model
  from nemo.collections.nlp.modules.common.tokenizer_utils import get_tokenizer
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.classes.modelPT import ModelPT
  from nemo.core.neural_types import NeuralType
  from nemo.utils import logging
label_desc: Use image node_id 3 to create a new BERTLMModel object from inherited base classes: ModelPT with example: obj = BERTLMModel(cfg, trainer)