class_docstr: Support huggingface text backbones.
  Refer to https://github.com/huggingface/transformers
class_docstr_tok: ["Support","huggingface","text","backbones",".","Refer","to","https",":","\/\/github.com\/huggingface\/transformers"]
docstr: Parameters
  ----------
  text_token_ids : torch.Tensor
      Indices of input sequence tokens in the vocabulary.
  text_segment_ids : torch.Tensor
      Indices of input sequence segments.
  text_valid_length : torch.Tensor
      Valid length of the input text sequence.
  text_column_names : list of str, optional
      Names of the text columns.
  text_column_indices : list of torch.Tensor, optional
      Start and stop indices of the text columns.
  
  Returns
  -------
      A tuple that contains (pooled_features, logits, column_features, column_feature_masks)
docstr_tok: ["Parameters","--","--","--","--","--","text_token_ids",":","torch.Tensor","Indices","of","input","sequence","tokens","in","the","vocabulary",".","text_segment_ids",":","torch.Tensor","Indices","of","input","sequence","segments",".","text_valid_length",":","torch.Tensor","Valid","length","of","the","input","text","sequence",".","text_column_names",":","list","of","str",",","optional","Names","of","the","text","columns",".","text_column_indices",":","list","of","torch.Tensor",",","optional","Start","and","stop","indices","of","the","text","columns",".","Returns","--","--","--","-","A","tuple","that","contains","(","pooled_features",",","logits",",","column_features",",","column_feature_masks",")"]
code: def forward(
      self,
      text_token_ids: torch.Tensor,
      text_segment_ids: torch.Tensor,
      text_valid_length: torch.Tensor,
      text_column_names: Optional[List[str]] = None,
      text_column_indices: Optional[List[torch.Tensor]] = None,
  ):
      """
      Parameters
      ----------
      text_token_ids : torch.Tensor
          Indices of input sequence tokens in the vocabulary.
      text_segment_ids : torch.Tensor
          Indices of input sequence segments.
      text_valid_length : torch.Tensor
          Valid length of the input text sequence.
      text_column_names : list of str, optional
          Names of the text columns.
      text_column_indices : list of torch.Tensor, optional
          Start and stop indices of the text columns.
  
      Returns
      -------
          A tuple that contains (pooled_features, logits, column_features, column_feature_masks)
      """
      if self.disable_seg_ids:
          text_segment_ids = None
  
      steps = torch.arange(0, text_token_ids.shape[1]).type_as(
          text_valid_length
      )
      text_masks = (
          steps.reshape((1, -1)) < text_valid_length.reshape((-1, 1))
      ).type_as(text_token_ids)
  
      if self.is_t5:
          # For the T5 model, we will only use the encoder to encode the sentence. This is adopted in
          # "Sentence-T5 (ST5): Scalable Sentence Encoders from Pre-trained Text-to-Text Models"
          # (https://aclanthology.org/2022.findings-acl.146.pdf).
          inputs_embeds = self.model.encoder.embed_tokens(
              text_token_ids
          )
          if self.gradient_checkpointing:
              # FIXME(?) This is a hack! We added a DummyLayer to ensure that the
              #  gradient checkpointing will assign output layer as require_grad=True
              #  Reference: https://discuss.pytorch.org/t/checkpoint-with-no-grad-requiring-inputs-problem/19117/9
              inputs_embeds = self.dummy_layer(inputs_embeds)
          outputs = self.model.encoder(
              inputs_embeds=inputs_embeds,
              attention_mask=text_masks,
          )
      else:
          if "token_type_ids" in self.tokenizer.model_input_names:
              outputs = self.model(
                  input_ids=text_token_ids,
                  token_type_ids=text_segment_ids,
                  attention_mask=text_masks,
              )
          else:
              outputs = self.model(
                  input_ids=text_token_ids,
                  attention_mask=text_masks,
              )
      if self.pooling_mode == "cls":
          pooled_features = outputs.last_hidden_state[:, 0, :]
      elif self.pooling_mode == "mean":
          pooled_features = (
              outputs.last_hidden_state * text_masks.unsqueeze(-1)
          ).sum(1)
          sum_mask = text_masks.unsqueeze(-1).sum(1)
          sum_mask = torch.clamp(sum_mask, min=1e-9)
          pooled_features = pooled_features / sum_mask
      else:
          raise NotImplementedError(
              f"Pooling mode={self.pooling_mode} is not supported."
          )
  
      logits = self.head(pooled_features)
      last_hidden_state = outputs.last_hidden_state
  
      batch = {
          self.text_token_ids_key: text_token_ids,
          self.text_segment_ids_key: text_segment_ids,
          self.text_valid_length_key: text_valid_length,
      }
      if text_column_names:
          assert len(text_column_names) == len(
              text_column_indices
          ), "invalid text column inputs"
          for idx, name in enumerate(text_column_names):
              batch[name] = text_column_indices[idx]
      column_features, column_feature_masks = get_column_features(
          batch=batch,
          column_name_prefix=self.text_column_prefix,
          features=last_hidden_state,
          valid_lengths=text_valid_length,
          cls_feature=pooled_features,
      )
  
      if column_features == {} or column_feature_masks == {}:
          return pooled_features, logits
      else:
          return (
              pooled_features,
              logits,
              column_features,
              column_feature_masks,
          )
  
imports: import logging
  from typing import Dict, List, Optional, Tuple
  import torch
  from torch import nn
  from transformers import logging
  from transformers.models.t5 import T5PreTrainedModel
  from ..constants import AUTOMM, COLUMN, COLUMN_FEATURES, FEATURES, LABEL, LOGITS, MASKS, TEXT_SEGMENT_IDS, TEXT_TOKEN_IDS, TEXT_VALID_LENGTH
  from .utils import DummyLayer, assign_layer_ids, get_column_features, get_hf_config_and_model, get_pretrained_tokenizer, init_weights
label_desc: Use image node_id 9 for calling the HFAutoModelForTextPrediction obj's underlying member method code with example usage: obj.forward(text_token_ids, text_segment_ids, text_valid_length, text_column_names, text_column_indices) and returns: pooled_features,  logits, pooled_features,  logits,  column_features,  column_feature_masks