code: def forward_zero_shot(
      self,
      text_tokens: Tensor,
      key_padding_mask: Optional[Tensor] = None,
      *args,
      **kwargs,
  ) -> Tensor:
      # In case of zero-shot evaluation, text tokens is of shape [Batch, num_classes, num_captions, context_length]
      # For example, in the ImageNet dataset, we have 1000 classes, and for each class we generate certain number of
      # captions (each caption with context_length tokens)
  
      if self.training:
          raise NotImplementedError(
              "Zero-shot evaluation is only supported with eval mode"
          )
  
      if text_tokens.ndim != 4:
          logger.error(
              "For zero-shot evaluation, expected size of text is [Batch, Num_classes, num_captions, context_len]"
          )
  
      (
          batch_size,
          num_classes,
          num_captions,
          context_len,
      ) = text_tokens.shape
  
      # for zero-shot evaluation, text templates are the same across all images in the batch
      # Therefore, batch size should be 1.
      if batch_size > 1:
          text_tokens = text_tokens[0:1]
          batch_size = 1
          logger.warning(
              "For zero-shot evaluation, text templates are the same across all images in the batch."
              "Got: {}. Please consider adjusting collate function.".format(
                  batch_size
              )
          )
  
      text_features = []
  
      for start_idx in range(
          0, num_classes, self.classes_per_split_zero_shot
      ):
          end_idx = min(
              start_idx + self.classes_per_split_zero_shot, num_classes
          )
  
          text_tokens_split = text_tokens[0, start_idx:end_idx, ...]
          num_classes_split = text_tokens_split.shape[0]
          text_tokens_split = text_tokens_split.reshape(
              num_classes_split * num_captions, context_len
          )
  
          key_padding_mask_split = None
          if key_padding_mask is not None:
              key_padding_mask_split = key_padding_mask[
                  0, start_idx:end_idx, ...
              ]
              key_padding_mask_split = key_padding_mask_split.reshape(
                  num_classes_split * num_captions, context_len
              )
  
          # [num_classes_per_split * num_cations, context_len] --> [num_classes_per_split * num_cations, latent_dim]
          class_embedding_split = self.encode_text(
              text_tokens=text_tokens_split,
              key_padding_mask=key_padding_mask_split,
          )
  
          # [num_classes_per_split * num_cations, latent_dim] --> [num_classes_per_split, num_cations, latent_dim]
          class_embedding_split = class_embedding_split.reshape(
              num_classes_split,
              num_captions,
              class_embedding_split.shape[-1],
          )
  
          # Compute mean of all classes
          # [num_classes_per_split, num_cations, latent_dim] --> [num_classes_per_split, latent_dim]
          mean_class_embedding_split = class_embedding_split.mean(dim=1)
  
          # Normalize the embeddings
          mean_class_embedding_split = F.normalize(
              mean_class_embedding_split, dim=-1
          )
  
          text_features.append(mean_class_embedding_split)
  
      # [num_classes_per_split, latent_dim] * num_splits --> [num_classes, Latent_dim]
      text_features = torch.cat(text_features, dim=0)
      # [num_classes, Latent_dim] --> [Latent_dim, num_classes]
      text_features = text_features.transpose(0, 1)
      return text_features.contiguous()
  
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 7 for calling the TextTransformer obj's underlying member method code with example usage: obj.forward_zero_shot(text_tokens, key_padding_mask) and returns: text_features