class_docstr: Named entity recognition with huggingface backbones. Inherit from HFAutoModelForTextPrediction.
class_docstr_tok: ["Named","entity","recognition","with","huggingface","backbones",".","Inherit","from","HFAutoModelForTextPrediction","."]
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.
  token_word_mapping : torch.Tensor
      Mapping the named entities to task specific labels.
  word_offsets : torch.Tensor
      Locations of the named entities.
  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 (sequence_output, logits, logits_label, token_word_mapping, word_offsets, 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",".","token_word_mapping",":","torch.Tensor","Mapping","the","named","entities","to","task","specific","labels",".","word_offsets",":","torch.Tensor","Locations","of","the","named","entities",".","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","(","sequence_output",",","logits",",","logits_label",",","token_word_mapping",",","word_offsets",",","column_features",",","column_feature_masks",")"]
code: def forward(
      self,
      text_token_ids: torch.Tensor,
      text_segment_ids: torch.Tensor,
      text_valid_length: torch.Tensor,
      token_word_mapping: torch.Tensor,
      word_offsets: 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.
      token_word_mapping : torch.Tensor
          Mapping the named entities to task specific labels.
      word_offsets : torch.Tensor
          Locations of the named entities.
      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 (sequence_output, logits, logits_label, token_word_mapping, word_offsets, 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
          )
          outputs = self.model.encoder(
              inputs_embeds=inputs_embeds,
              attention_mask=text_masks,
          )
      else:
          outputs = self.model(
              input_ids=text_token_ids,
              token_type_ids=text_segment_ids,
              attention_mask=text_masks,
          )
  
      sequence_output = outputs.last_hidden_state
      batch_size, max_len, feat_dim = sequence_output.shape
      valid_output = torch.zeros(
          batch_size, max_len, feat_dim, dtype=torch.float32
      )
  
      pooled_features = outputs.last_hidden_state[:, 0, :]
  
      logits = self.head(sequence_output)
  
      logits_label = torch.argmax(F.log_softmax(logits, dim=-1), dim=-1)
  
      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"
          batch.update(
              **dict(zip(text_column_names, text_column_indices))
          )
      column_features, column_feature_masks = get_column_features(
          batch=batch,
          column_name_prefix=self.text_column_prefix,
          features=outputs.last_hidden_state,
          valid_lengths=text_valid_length,
          cls_feature=pooled_features,
      )
  
      if column_features == {} or column_feature_masks == {}:
          return (
              sequence_output,
              logits,
              logits_label,
              token_word_mapping,
              word_offsets,
          )
      else:
          return (
              sequence_output,
              logits,
              logits_label,
              token_word_mapping,
              word_offsets,
              column_features,
              column_feature_masks,
          )
  
file_path: autogluon/multimodal/src/autogluon/multimodal/models/ner_text.py
imports: import logging
  from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn.functional
  from torch import nn
  from transformers import logging
  from ..constants import AUTOMM, COLUMN, COLUMN_FEATURES, FEATURES, LABEL, LOGITS, MASKS, NER_ANNOTATION, TEXT_SEGMENT_IDS, TEXT_TOKEN_IDS, TEXT_VALID_LENGTH, TOKEN_WORD_MAPPING, WORD_OFFSETS
  from .huggingface_text import HFAutoModelForTextPrediction
  from .utils import assign_layer_ids, get_column_features, get_pretrained_tokenizer
label_desc: Use image node_id 5 for calling the HFAutoModelForNER obj's underlying member method code with example usage: obj.forward(text_token_ids, text_segment_ids, text_valid_length, token_word_mapping, word_offsets, text_column_names, text_column_indices) and returns: sequence_output,  logits,  logits_label,  token_word_mapping,  word_offsets, sequence_output,  logits,  logits_label,  token_word_mapping,  word_offsets,  column_features,  column_feature_masks