class_docstr: Transformer-based Speech-to-Text Decoder from OpenAI's Whisper Model:
  
  URL: https://github.com/openai/whisper
class_docstr_tok: ["Transformer-based","Speech-to-Text","Decoder","from","OpenAI","'s","Whisper","Model",":","URL",":","https",":","\/\/github.com\/openai\/whisper"]
code: def __init__(
      self,
      vocab_size: int,
      encoder_output_size: int,
      dropout_rate: float = 0.0,
      whisper_model: str = "small",
      download_dir: str = None,
      load_origin_token_embedding=False,
  ):
      try:
          import whisper
      except Exception as e:
          print("Error: whisper is not properly installed.")
          print(
              "Please install whisper with: cd ${MAIN_ROOT}/tools && "
              "./installers/install_whisper.sh"
          )
          raise e
  
      assert check_argument_types()
      super().__init__()
  
      assert whisper_model in whisper.available_models()
      _model = whisper.load_model(
          whisper_model, download_root=download_dir, device="cpu"
      )
      self.decoders = copy.deepcopy(_model.decoder)
      attention_dim = self.decoders.token_embedding.embedding_dim
  
      # note that originally Whisper doesn't use dropouts
      self.dropout = torch.nn.Dropout(dropout_rate)
  
      # load the original token_embeddings, if the vocabulary is expanded
      self.load_origin_token_embedding = load_origin_token_embedding
  
      # vocab size mismatch -> reinitialize embedding
      # orig vocab size (multilingual): 51865
      # orig vocab size (english): 51864
      if vocab_size != self.decoders.token_embedding.num_embeddings:
          if self.load_origin_token_embedding:
              assert (
                  vocab_size
                  > self.decoders.token_embedding.num_embeddings
              ), "expanded vocab_size should be larged than the origin"
              self.decoders.token_embedding = ExpandedTokenEmbedding(
                  self.decoders.token_embedding,
                  vocab_size
                  - self.decoders.token_embedding.num_embeddings,
              )
          else:
              orig_emb_std, orig_emb_mean = torch.std_mean(
                  self.decoders.token_embedding.weight
              )
              self.decoders.token_embedding = torch.nn.Embedding(
                  vocab_size, attention_dim
              )
              torch.nn.init.normal_(
                  self.decoders.token_embedding.weight,
                  orig_emb_mean.item(),
                  orig_emb_std.item(),
              )
  
      self.decoders.train()
      del _model
  
file_path: espnet/espnet2/asr/decoder/whisper_decoder.py
imports: import copy
  from typing import Any, List, Tuple
  import torch
  from typeguard import check_argument_types
  from espnet2.asr.decoder.abs_decoder import AbsDecoder
  from espnet.nets.scorer_interface import BatchScorerInterface
label_desc: Use image node_id 1 to create a new OpenAIWhisperDecoder object from inherited base classes: AbsDecoder, BatchScorerInterface with example: obj = OpenAIWhisperDecoder(vocab_size, encoder_output_size, dropout_rate, whisper_model, download_dir, load_origin_token_embedding)