class_docstr: Speech Representation Using Encoder Outputs from OpenAI's Whisper Model:
  
  URL: https://github.com/openai/whisper
class_docstr_tok: ["Speech","Representation","Using","Encoder","Outputs","from","OpenAI","'s","Whisper","Model",":","URL",":","https",":","\/\/github.com\/openai\/whisper"]
code: def whisper_encode(
      self,
      input: torch.Tensor,
      ilens: torch.Tensor = None,
  ) -> torch.Tensor:
      whisper_encoder = self.whisper.encoder
  
      x = F.gelu(whisper_encoder.conv1(input))
      x = F.gelu(whisper_encoder.conv2(x))
      x = x.permute(0, 2, 1)
  
      n_frames = x.size(1)
      max_pos = whisper_encoder.positional_embedding.size(0)
      if n_frames <= max_pos:
          x = (
              x + whisper_encoder.positional_embedding[: x.size(1), :]
          ).to(x.dtype)
      else:
          x = x[:, :max_pos, :] + whisper_encoder.positional_embedding
  
      for block in whisper_encoder.blocks:
          x = block(x)
  
      x = whisper_encoder.ln_post(x)
  
      if ilens is not None:
          olens = (
              1
              + (
                  ilens
                  - whisper_encoder.conv2.kernel_size[0]
                  + 2 * whisper_encoder.conv2.padding[0]
              )
              // whisper_encoder.conv2.stride[0]
          )
          olens = torch.clamp(olens, max=max_pos)
      else:
          olens = None
  
      return x, olens
  
file_path: espnet/espnet2/asr/frontend/whisper.py
imports: import contextlib
  from typing import Tuple
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.asr.frontend.abs_frontend import AbsFrontend
label_desc: Use image node_id 4 for calling the WhisperFrontend obj's underlying member method code with example usage: obj.whisper_encode(input, ilens) and returns: x,  olens