class_docstr: Implementation of T-Few (https://arxiv.org/pdf/2205.05638.pdf).
  Refer to https://github.com/r-three/t-few
class_docstr_tok: ["Implementation","of","T-Few","(","https",":","\/\/arxiv.org\/pdf\/2205.05638.pdf",")",".","Refer","to","https",":","\/\/github.com\/r-three\/t-few"]
docstr: Load a pretrained T5-based text transformer backbone.
  
  Parameters
  ----------
  prefix
      The model prefix.
  checkpoint_name
      Name of the checkpoint. We support loading T5ForConditionalGeneration checkpoints from
      Huggingface Models list: https://huggingface.co/models.
      We recommend using T0 backbones. For example, you may use
          - 'bigscience/T0_3B'
          - 'bigscience/T0p'
          - 'bigscience/T0pp'
  num_classes
      The number of classes. 1 for a regression task.
  length_norm
       Normalizes length to adjust for length bias in target template
  unlikely_loss
      Adds loss term that lowers probability of incorrect outputs
  mc_loss
      Adds multiple choice cross entropy loss
  gradient_checkpointing
      Whether to enable gradient checkpointing
  low_cpu_mem_usage
      Whether to turn on the optimization of reducing the peak CPU memory usage when loading the pretrained model.
  pretrained
      Whether using the pretrained weights. If pretrained=True, download the pretrained model.
  tokenizer_name
      Name of the huggingface tokenizer type.
docstr_tok: ["Load","a","pretrained","T5-based","text","transformer","backbone",".","Parameters","--","--","--","--","--","prefix","The","model","prefix",".","checkpoint_name","Name","of","the","checkpoint",".","We","support","loading","T5ForConditionalGeneration","checkpoints","from","Huggingface","Models","list",":","https",":","\/\/huggingface.co\/models",".","We","recommend","using","T0","backbones",".","For","example",",","you","may","use","-","'bigscience\/T0_3B'","-","'bigscience\/T0p'","-","'bigscience\/T0pp'","num_classes","The","number","of","classes",".","1","for","a","regression","task",".","length_norm","Normalizes","length","to","adjust","for","length","bias","in","target","template","unlikely_loss","Adds","loss","term","that","lowers","probability","of","incorrect","outputs","mc_loss","Adds","multiple","choice","cross","entropy","loss","gradient_checkpointing","Whether","to","enable","gradient","checkpointing","low_cpu_mem_usage","Whether","to","turn","on","the","optimization","of","reducing","the","peak","CPU","memory","usage","when","loading","the","pretrained","model",".","pretrained","Whether","using","the","pretrained","weights",".","If","pretrained=True",",","download","the","pretrained","model",".","tokenizer_name","Name","of","the","huggingface","tokenizer","type","."]
code: def __init__(
      self,
      prefix: str,
      checkpoint_name: str = "bigscience/T0_3B",
      num_classes: Optional[int] = 0,
      length_norm: float = 1.0,  # Normalizes length to adjust for length bias in target template
      unlikely_loss: float = 1.0,  # Adds loss term that lowers probability of incorrect outputs
      mc_loss: float = 1.0,  # Adds multiple choice cross entropy loss
      gradient_checkpointing: Optional[bool] = False,
      low_cpu_mem_usage: Optional[bool] = False,
      pretrained: Optional[bool] = True,
      tokenizer_name: Optional[str] = "hf_auto",
  ):
      """
      Load a pretrained T5-based text transformer backbone.
  
      Parameters
      ----------
      prefix
          The model prefix.
      checkpoint_name
          Name of the checkpoint. We support loading T5ForConditionalGeneration checkpoints from
          Huggingface Models list: https://huggingface.co/models.
          We recommend using T0 backbones. For example, you may use
              - 'bigscience/T0_3B'
              - 'bigscience/T0p'
              - 'bigscience/T0pp'
      num_classes
          The number of classes. 1 for a regression task.
      length_norm
           Normalizes length to adjust for length bias in target template
      unlikely_loss
          Adds loss term that lowers probability of incorrect outputs
      mc_loss
          Adds multiple choice cross entropy loss
      gradient_checkpointing
          Whether to enable gradient checkpointing
      low_cpu_mem_usage
          Whether to turn on the optimization of reducing the peak CPU memory usage when loading the pretrained model.
      pretrained
          Whether using the pretrained weights. If pretrained=True, download the pretrained model.
      tokenizer_name
          Name of the huggingface tokenizer type.
      """
      super().__init__()
      logger.debug(f"initializing {checkpoint_name}")
  
      self.checkpoint_name = checkpoint_name
      self.num_classes = num_classes
  
      self.config = AutoConfig.from_pretrained(checkpoint_name)
  
      if pretrained:
          self.model = AutoModelForSeq2SeqLM.from_pretrained(
              checkpoint_name, low_cpu_mem_usage=low_cpu_mem_usage
          )
      else:
          self.model = AutoModelForSeq2SeqLM.from_config(self.config)
  
      self.tokenizer_name = tokenizer_name
      self.tokenizer = get_pretrained_tokenizer(
          tokenizer_name=self.tokenizer_name,
          checkpoint_name=self.checkpoint_name,
      )
      self.eos_token = self.tokenizer.eos_token
      self.out_features = (
          self.model.config.hidden_size
      )  # required attribute for some features, e.g. data augmentation
  
      self.gradient_checkpointing = gradient_checkpointing
      if gradient_checkpointing:
          self.model.gradient_checkpointing_enable()
          self.dummy_layer = DummyLayer()
  
      self.prefix = prefix
  
      self.mc_loss = mc_loss
      self.unlikely_loss = unlikely_loss
      self.length_norm = length_norm
  
      self.name_to_id = self.get_layer_ids()
      self.head_layer_names = [
          n for n, layer_id in self.name_to_id.items() if layer_id == 0
      ]
  
imports: import collections
  import logging
  import os
  import random
  from functools import lru_cache
  from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn.functional
  from torch import nn
  from transformers import AutoConfig, AutoModelForSeq2SeqLM
  from transformers import logging
  from ..constants import AUTOMM, CHOICES_IDS, COLUMN, COLUMN_FEATURES, FEATURES, LABEL, LM_TARGET, LOGITS, MASKS, TEMPLATE_LOGITS, TEXT_SEGMENT_IDS, TEXT_TOKEN_IDS, TEXT_VALID_LENGTH
  from .utils import DummyLayer, assign_layer_ids, get_column_features, get_pretrained_tokenizer
label_desc: Use image node_id 1 to create a new TFewModel object from inherited base classes: nn with example: obj = TFewModel(prefix, checkpoint_name, num_classes, length_norm, unlikely_loss, mc_loss, gradient_checkpointing, low_cpu_mem_usage, pretrained, tokenizer_name)