class_docstr: Encoder decoder CTC-based models with Byte Pair Encoding.
docstr: Changes vocabulary of the tokenizer used during CTC 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 a 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: Either `agg`, `bpe` or `wpe`. `bpe` is used for SentencePiece tokenizers,
          whereas `wpe` is used for `BertTokenizer`.
      new_tokenizer_cfg: A config for the new tokenizer. if provided, pre-empts the dir and type
  
  Returns: None
docstr_tok: ["Changes","vocabulary","of","the","tokenizer","used","during","CTC","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","a","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",":","Either","`","agg","`",",","`","bpe","`","or","`","wpe","`",".","`","bpe","`","is","used","for","SentencePiece","tokenizers",",","whereas","`","wpe","`","is","used","for","`","BertTokenizer","`",".","new_tokenizer_cfg",":","A","config","for","the","new","tokenizer",".","if","provided",",","pre-empts","the","dir","and","type","Returns",":","None"]
code: def change_vocabulary(
      self,
      new_tokenizer_dir: Union[str, DictConfig],
      new_tokenizer_type: str,
      decoding_cfg: Optional[DictConfig] = None,
  ):
      """
      Changes vocabulary of the tokenizer used during CTC 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 a 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: Either `agg`, `bpe` or `wpe`. `bpe` is used for SentencePiece tokenizers,
              whereas `wpe` is used for `BertTokenizer`.
          new_tokenizer_cfg: A config for the new tokenizer. if provided, pre-empts the dir and type
  
      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}"
                  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()
  
      # Set the new vocabulary
      decoder_config = copy.deepcopy(self.decoder.to_config_dict())
      # sidestepping the potential overlapping tokens issue in aggregate tokenizers
      if self.tokenizer_type == "agg":
          decoder_config.vocabulary = ListConfig(vocabulary)
      else:
          decoder_config.vocabulary = ListConfig(
              list(vocabulary.keys())
          )
  
      decoder_num_classes = decoder_config["num_classes"]
  
      # Override number of classes if placeholder provided
      logging.info(
          "\nReplacing old number of classes ({}) with new number of classes - {}".format(
              decoder_num_classes, len(vocabulary)
          )
      )
  
      decoder_config["num_classes"] = len(vocabulary)
  
      del self.decoder
      self.decoder = EncDecCTCModelBPE.from_config_dict(decoder_config)
      del self.loss
      self.loss = CTCLoss(
          num_classes=self.decoder.num_classes_with_blank - 1,
          zero_infinity=True,
          reduction=self._cfg.get("ctc_reduction", "mean_batch"),
      )
  
      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(CTCBPEDecodingConfig)
      decoding_cls = OmegaConf.create(
          OmegaConf.to_container(decoding_cls)
      )
      decoding_cfg = OmegaConf.merge(decoding_cls, decoding_cfg)
  
      self.decoding = CTCBPEDecoding(
          decoding_cfg=decoding_cfg, tokenizer=self.tokenizer
      )
  
      self.wer = WER(
          decoding=self.decoding,
          use_cer=self._cfg.get("use_cer", False),
          log_prediction=self._cfg.get("log_prediction", False),
          dist_sync_on_step=True,
      )
  
      # Update config
      with open_dict(self.cfg.decoder):
          self._cfg.decoder = decoder_config
  
      with open_dict(self.cfg.decoding):
          self._cfg.decoding = decoding_cfg
  
      logging.info(
          f"Changed tokenizer to {self.decoder.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 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.ctc import CTCLoss
  from nemo.collections.asr.metrics.wer import WER
  from nemo.collections.asr.models.ctc_models import EncDecCTCModel
  from nemo.collections.asr.parts.mixins import ASRBPEMixin
  from nemo.collections.asr.parts.submodules.ctc_decoding import CTCBPEDecoding, CTCBPEDecodingConfig
  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 4 for calling the EncDecCTCModelBPE obj's underlying member method code with example usage: obj.change_vocabulary(new_tokenizer_dir, new_tokenizer_type, decoding_cfg) without return types