docstr: Initializes model to use BERT model for GLUE tasks.
docstr_tok: ["Initializes","model","to","use","BERT","model","for","GLUE","tasks","."]
code: def __init__(self, cfg: DictConfig, trainer: Trainer = None):
      """
      Initializes model to use BERT model for GLUE tasks.
      """
  
      if cfg.task_name not in cfg.supported_tasks:
          raise ValueError(
              f"{cfg.task_name} not in supported task. Choose from {cfg.supported_tasks}"
          )
      self.task_name = cfg.task_name
  
      # needed to setup validation on multiple datasets
      # MNLI task has two separate dev sets: matched and mismatched
      if not self._is_model_being_restored():
          if self.task_name == "mnli":
              cfg.validation_ds.ds_item = [
                  os.path.join(cfg.dataset.data_dir, "dev_matched.tsv"),
                  os.path.join(
                      cfg.dataset.data_dir, "dev_mismatched.tsv"
                  ),
              ]
          else:
              cfg.validation_ds.ds_item = os.path.join(
                  cfg.dataset.data_dir, cfg.validation_ds.ds_item
              )
          cfg.train_ds.ds_item = os.path.join(
              cfg.dataset.data_dir, cfg.train_ds.ds_item
          )
          logging.info(
              f"Using {cfg.validation_ds.ds_item} for model evaluation."
          )
  
      super().__init__(cfg=cfg, trainer=trainer)
  
      num_labels = GLUE_TASKS_NUM_LABELS[self.task_name]
      # uses [CLS] token for classification (the first token)
      if self.task_name == "sts-b":
          self.pooler = SequenceRegression(
              hidden_size=self.bert_model.config.hidden_size
          )
          self.loss = MSELoss()
      else:
          self.pooler = SequenceClassifier(
              hidden_size=self.bert_model.config.hidden_size,
              num_classes=num_labels,
              log_softmax=False,
          )
          self.loss = CrossEntropyLoss()
  
imports: import os
  from typing import Dict, Optional, Union
  import numpy
  import torch
  from omegaconf import DictConfig
  from pytorch_lightning import Trainer
  from nemo.collections.common.losses import CrossEntropyLoss, MSELoss
  from nemo.collections.nlp.data.glue_benchmark.glue_benchmark_dataset import GLUE_TASKS_NUM_LABELS, GLUEDataset
  from nemo.collections.nlp.models.glue_benchmark.metrics_for_glue import compute_metrics
  from nemo.collections.nlp.models.nlp_model import NLPModel
  from nemo.collections.nlp.modules.common import SequenceClassifier, SequenceRegression
  from nemo.collections.nlp.parts.utils_funcs import list2str, tensor2list
  from nemo.core.classes import typecheck
  from nemo.core.neural_types import NeuralType
  from nemo.utils import logging
label_desc: Use image node_id 4 to create a new GLUEModel object from inherited base classes: NLPModel with example: obj = GLUEModel(cfg, trainer)