class_docstr: Base class for encoder decoder RNNT-based models with subword tokenization.
class_docstr_tok: ["Base","class","for","encoder","decoder","RNNT-based","models","with","subword","tokenization","."]
docstr: Changes vocabulary used during RNNT decoding process. Use this method when fine-tuning on from pre-trained model.
  This method changes only decoder and leaves encoder and pre-processing modules unchanged. For example, you would
  use it if you want to use pretrained encoder when fine-tuning on data in another language, or when you'd need
  model to learn capitalization, punctuation and/or special characters.
  
  Args:
      new_tokenizer_dir: Directory path to tokenizer or a config for a new tokenizer (if the tokenizer type is `agg`)
      new_tokenizer_type: Type of tokenizer. Can be either `agg`, `bpe` or `wpe`.
      decoding_cfg: A config for the decoder, which is optional. If the decoding type
          needs to be changed (from say Greedy to Beam decoding etc), the config can be passed here.
  
  Returns: None
docstr_tok: ["Changes","vocabulary","used","during","RNNT","decoding","process",".","Use","this","method","when","fine-tuning","on","from","pre-trained","model",".","This","method","changes","only","decoder","and","leaves","encoder","and","pre-processing","modules","unchanged",".","For","example",",","you","would","use","it","if","you","want","to","use","pretrained","encoder","when","fine-tuning","on","data","in","another","language",",","or","when","you","'d","need","model","to","learn","capitalization",",","punctuation","and\/or","special","characters",".","Args",":","new_tokenizer_dir",":","Directory","path","to","tokenizer","or","a","config","for","a","new","tokenizer","(","if","the","tokenizer","type","is","`","agg","`",")","new_tokenizer_type",":","Type","of","tokenizer",".","Can","be","either","`","agg","`",",","`","bpe","`","or","`","wpe","`",".","decoding_cfg",":","A","config","for","the","decoder",",","which","is","optional",".","If","the","decoding","type","needs","to","be","changed","(","from","say","Greedy","to","Beam","decoding","etc",")",",","the","config","can","be","passed","here",".","Returns",":","None"]
code: def change_vocabulary(
      self,
      new_tokenizer_dir: Union[str, DictConfig],
      new_tokenizer_type: str,
      decoding_cfg: Optional[DictConfig] = None,
  ):
      """
      Changes vocabulary used during RNNT decoding process. Use this method when fine-tuning on from pre-trained model.
      This method changes only decoder and leaves encoder and pre-processing modules unchanged. For example, you would
      use it if you want to use pretrained encoder when fine-tuning on data in another language, or when you'd need
      model to learn capitalization, punctuation and/or special characters.
  
      Args:
          new_tokenizer_dir: Directory path to tokenizer or a config for a new tokenizer (if the tokenizer type is `agg`)
          new_tokenizer_type: Type of tokenizer. Can be either `agg`, `bpe` or `wpe`.
          decoding_cfg: A config for the decoder, which is optional. If the decoding type
              needs to be changed (from say Greedy to Beam decoding etc), the config can be passed here.
  
      Returns: None
  
      """
      if isinstance(new_tokenizer_dir, DictConfig):
          if new_tokenizer_type == "agg":
              new_tokenizer_cfg = new_tokenizer_dir
          else:
              raise ValueError(
                  f"New tokenizer dir should be a string unless the tokenizer is `agg`, but this tokenizer type is: {new_tokenizer_type}"
              )
      else:
          new_tokenizer_cfg = None
  
      if new_tokenizer_cfg is not None:
          tokenizer_cfg = new_tokenizer_cfg
      else:
          if not os.path.isdir(new_tokenizer_dir):
              raise NotADirectoryError(
                  f"New tokenizer dir must be non-empty path to a directory. But I got: {new_tokenizer_dir}"
              )
  
          if new_tokenizer_type.lower() not in ("bpe", "wpe"):
              raise ValueError(
                  f"New tokenizer type must be either `bpe` or `wpe`"
              )
  
          tokenizer_cfg = OmegaConf.create(
              {"dir": new_tokenizer_dir, "type": new_tokenizer_type}
          )
  
      # Setup the tokenizer
      self._setup_tokenizer(tokenizer_cfg)
  
      # Initialize a dummy vocabulary
      vocabulary = self.tokenizer.tokenizer.get_vocab()
  
      joint_config = self.joint.to_config_dict()
      new_joint_config = copy.deepcopy(joint_config)
      if self.tokenizer_type == "agg":
          new_joint_config["vocabulary"] = ListConfig(vocabulary)
      else:
          new_joint_config["vocabulary"] = ListConfig(
              list(vocabulary.keys())
          )
  
      new_joint_config["num_classes"] = len(vocabulary)
      del self.joint
      self.joint = EncDecRNNTBPEModel.from_config_dict(new_joint_config)
  
      decoder_config = self.decoder.to_config_dict()
      new_decoder_config = copy.deepcopy(decoder_config)
      new_decoder_config.vocab_size = len(vocabulary)
      del self.decoder
      self.decoder = EncDecRNNTBPEModel.from_config_dict(
          new_decoder_config
      )
  
      del self.loss
      self.loss = RNNTLoss(
          num_classes=self.joint.num_classes_with_blank - 1
      )
  
      if decoding_cfg is None:
          # Assume same decoding config as before
          decoding_cfg = self.cfg.decoding
  
      # Assert the decoding config with all hyper parameters
      decoding_cls = OmegaConf.structured(RNNTBPEDecodingConfig)
      decoding_cls = OmegaConf.create(
          OmegaConf.to_container(decoding_cls)
      )
      decoding_cfg = OmegaConf.merge(decoding_cls, decoding_cfg)
  
      self.decoding = RNNTBPEDecoding(
          decoding_cfg=decoding_cfg,
          decoder=self.decoder,
          joint=self.joint,
          tokenizer=self.tokenizer,
      )
  
      self.wer = WER(
          decoding=self.decoding,
          batch_dim_index=self.wer.batch_dim_index,
          use_cer=self.wer.use_cer,
          log_prediction=self.wer.log_prediction,
          dist_sync_on_step=True,
      )
  
      # Setup fused Joint step
      if self.joint.fuse_loss_wer or (
          self.decoding.joint_fused_batch_size is not None
          and self.decoding.joint_fused_batch_size > 0
      ):
          self.joint.set_loss(self.loss)
          self.joint.set_wer(self.wer)
  
      # Update config
      with open_dict(self.cfg.joint):
          self.cfg.joint = new_joint_config
  
      with open_dict(self.cfg.decoder):
          self.cfg.decoder = new_decoder_config
  
      with open_dict(self.cfg.decoding):
          self.cfg.decoding = decoding_cfg
  
      logging.info(
          f"Changed decoder to output to {self.joint.vocabulary} vocabulary."
      )
  
imports: import copy
  import os
  from typing import Dict, List, Optional, Union
  import torch
  from omegaconf import DictConfig, ListConfig, OmegaConf, open_dict
  from pytorch_lightning import Trainer
  from nemo.collections.asr.data import audio_to_text_dataset
  from nemo.collections.asr.data.audio_to_text_dali import AudioToBPEDALIDataset
  from nemo.collections.asr.data.audio_to_text_lhotse import LhotseSpeechToTextBpeDataset
  from nemo.collections.asr.losses.rnnt import RNNTLoss
  from nemo.collections.asr.metrics.wer import WER
  from nemo.collections.asr.models.rnnt_models import EncDecRNNTModel
  from nemo.collections.asr.parts.mixins import ASRBPEMixin
  from nemo.collections.asr.parts.submodules.rnnt_decoding import RNNTBPEDecoding, RNNTBPEDecodingConfig
  from nemo.collections.common.data.lhotse import get_lhotse_dataloader_from_config
  from nemo.core.classes.common import PretrainedModelInfo
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 3 for calling the EncDecRNNTBPEModel obj's underlying member method code with example usage: obj.change_vocabulary(new_tokenizer_dir, new_tokenizer_type, decoding_cfg) without return types