class_docstr: Hugging Face Transformers PostEncoder.
class_docstr_tok: ["Hugging","Face","Transformers","PostEncoder","."]
docstr: Forward.
docstr_tok: ["Forward","."]
code: def forward(
      self, input: torch.Tensor, input_lengths: torch.Tensor
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      """Forward."""
      if input.size(1) < self.length_adaptor_ratio:
          raise TooShortUttError(
              f"has {input.size(1)} frames and is too short for subsampling "
              + f"(it needs at least {self.length_adaptor_ratio} frames), "
              + "return empty results",
              input.size(1),
              self.length_adaptor_ratio,
          )
  
      input = input.permute(0, 2, 1)
      input = self.length_adaptor(input)
      input = input.permute(0, 2, 1)
  
      input_lengths = (
          input_lengths.float()
          .div(self.length_adaptor_ratio)
          .floor()
          .long()
      )
  
      input = self.linear_in(input)
  
      if self.lang_token_embed is not None:
          lang_token_embed = (
              self.lang_token_embed.unsqueeze(0)
              .unsqueeze(0)
              .repeat(input.size(0), 1, 1)
          )
          input = torch.cat(
              [lang_token_embed.to(input.device), input], dim=1
          )
          input_lengths = input_lengths + 1
  
      args = {"return_dict": True}
  
      mask = (~make_pad_mask(input_lengths)).to(input.device).float()
  
      if self.extend_attention_mask:
          args["attention_mask"] = _extend_attention_mask(mask)
      else:
          args["attention_mask"] = mask
  
      if self.use_inputs_embeds:
          args["inputs_embeds"] = input
      else:
          args["hidden_states"] = input
  
      if self.transformer.config.model_type == "mpnet":
          args["head_mask"] = [None for _ in self.transformer.layer]
  
      output = self.transformer(**args).last_hidden_state
  
      return output, input_lengths
  
file_path: espnet/espnet2/asr/postencoder/hugging_face_transformers_postencoder.py
imports: import copy
  import logging
  from typing import Tuple
  import torch
  from typeguard import check_argument_types
  from espnet2.asr.postencoder.abs_postencoder import AbsPostEncoder
  from espnet.nets.pytorch_backend.nets_utils import make_pad_mask
  from espnet.nets.pytorch_backend.transformer.subsampling import TooShortUttError
label_desc: Use image node_id 2 for calling the HuggingFaceTransformersPostEncoder obj's underlying member method code with example usage: obj.forward(input, input_lengths) and returns: output,  input_lengths