code: def __init__(
      self, opts, projection_dim: int, *args, **kwargs
  ) -> None:
      model_dim = getattr(opts, "model.text.transformer.model_dim", 512)
      no_scale_embedding = getattr(
          opts, "model.text.transformer.no_scale_embedding", False
      )
      no_pos_embedding = getattr(
          opts, "model.text.transformer.no_pos_embedding", False
      )
      embed_dropout = getattr(
          opts, "model.text.transformer.embed_dropout", 0.0
      )
      dropout = getattr(opts, "model.text.transformer.dropout", 0.0)
      attn_dropout = getattr(
          opts, "model.text.transformer.attn_dropout", 0.0
      )
      ffn_dropout = getattr(
          opts, "model.text.transformer.ffn_dropout", 0.0
      )
      norm_layer = getattr(
          opts, "model.text.transformer.norm_layer", None
      )
  
      gradient_ckpt = getattr(
          opts, "model.text.transformer.gradient_checkpoint", False
      )
  
      if norm_layer is None:
          logger.error(
              "Normalization layer can not be None in {}".format(
                  self.__class__.__name__
              )
          )
  
      super().__init__(
          opts=opts, projection_dim=projection_dim, *args, **kwargs
      )
  
      # token embedding layer
      padding_index = getattr(opts, "dataset.padding_index", None)
      self.embedding_layer = Embedding(
          opts=opts,
          embedding_dim=model_dim,
          padding_idx=padding_index,
          num_embeddings=self.vocab_size,
      )
      self.embed_scale = (
          1.0 if no_scale_embedding else model_dim**-0.5
      )
  
      context_length = getattr(opts, "dataset.text_context_length")
  
      if getattr(opts, "common.debug_mode", False):
          context_length = 77
  
      assert context_length is not None, (
          "Context length can't be None. Please set dataset.text_context_length "
          "argument in your dataset class"
      )
  
      self.positional_embedding = (
          None
          if no_pos_embedding
          else PositionalEmbedding(
              opts=opts,
              num_embeddings=context_length,
              embedding_dim=model_dim,
              padding_idx=getattr(opts, "dataset.padding_index", None),
              is_learnable=not getattr(
                  opts,
                  "model.text.transformer.sinusoidal_pos_emb",
                  False,
              ),
          )
      )
  
      self.embedding_dropout = Dropout(p=embed_dropout)
  
      # Transformer layer
  
      n_transformer_layers = getattr(
          opts, "model.text.transformer.n_transformer_layers", 6
      )
      # FFN multipliers for transformer layer
      ffn_multipliers = getattr(
          opts, "model.text.transformer.ffn_multiplier_per_layer", 4.0
      )
      if isinstance(ffn_multipliers, (float, int)):
          ffn_multipliers = [ffn_multipliers] * n_transformer_layers
  
      if not isinstance(ffn_multipliers, Sequence):
          logger.error(
              "{} expects FFN multipliers as a list, whose length is the same as number of "
              "transformer layers. Got: {}".format(
                  self.__class__.__name__, type(ffn_multipliers)
              )
          )
      elif (
          isinstance(ffn_multipliers, Sequence)
          and len(ffn_multipliers) != n_transformer_layers
      ):
          logger.error(
              "We need FFN multiplier for each transformer layer. Got {} ffn multipliers while number of "
              "transformer layers = {}".format(
                  len(ffn_multipliers), n_transformer_layers
              )
          )
      ffn_dims = [
          int(math.ceil(model_dim * ffn_mult / 16.0) * 16.0)
          for ffn_mult in ffn_multipliers
      ]
  
      # Heads for transformer layers
      mha_heads = getattr(
          opts, "model.text.transformer.n_heads_per_layer", 8
      )
      if isinstance(mha_heads, int):
          mha_heads = [mha_heads] * n_transformer_layers
  
      if not isinstance(mha_heads, Sequence):
          logger.error(
              "{} expects MHA heads as a list, whose length is the same as number of "
              "transformer layers. Got: {}".format(
                  self.__class__.__name__, type(mha_heads)
              )
          )
      elif (
          isinstance(mha_heads, Sequence)
          and len(mha_heads) != n_transformer_layers
      ):
          logger.error(
              "{} needs MHA heads for each transformer layer. Got {} mha heads while number of "
              "transformer layers = {}".format(
                  self.__class__.__name__,
                  len(mha_heads),
                  n_transformer_layers,
              )
          )
  
      self.transformer = nn.ModuleList(
          [
              TransformerEncoder(
                  opts=opts,
                  embed_dim=model_dim,
                  num_heads=mha_heads[layer_idx],
                  ffn_latent_dim=ffn_dims[layer_idx],
                  attn_dropout=attn_dropout,
                  ffn_dropout=ffn_dropout,
                  dropout=dropout,
                  transformer_norm_layer=norm_layer,
              )
              for layer_idx in range(n_transformer_layers)
          ]
      )
      self.final_layer_norm = get_normalization_layer(
          opts, num_features=model_dim, norm_type=norm_layer
      )
  
      self.projection_layer = nn.Parameter(
          torch.empty(model_dim, self.projection_dim)
      )
      self.model_dim = model_dim
      self.reset_parameters_clip_style()
      self.gradient_ckpt = gradient_ckpt
      self.use_pytorch_mha = False
      self.causal_masking = getattr(
          opts, "model.text.transformer.causal_masking", False
      )
      self.classes_per_split_zero_shot = max(
          1,
          int(
              getattr(
                  opts,
                  "model.text.transformer.classes_per_split_zero_shot",
                  1,
              )
          ),
      )
  
imports: import argparse
  import math
  from typing import Optional, Sequence
  import torch
  from torch import Tensor, nn
  from torch.nn import functional
  from torch.utils.checkpoint import checkpoint
  from cvnets.layers import Dropout, Embedding, PositionalEmbedding, get_normalization_layer
  from cvnets.modules import TransformerEncoder
  from cvnets.text_encoders import TEXT_ENCODER_REGISTRY, BaseTextEncoder
  from utils import logger
label_desc: Use image node_id 1 to create a new TextTransformer object from inherited base classes: BaseTextEncoder with example: obj = TextTransformer(opts, projection_dim)