class_docstr: Base class for encoder decoder RNNT-based models.
class_docstr_tok: ["Base","class","for","encoder","decoder","RNNT-based","models","."]
docstr: Changes vocabulary used during RNNT decoding process. Use this method when fine-tuning a 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_vocabulary: list with new vocabulary. Must contain at least 2 elements. Typically,                 this is target alphabet.
      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","a","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_vocabulary",":","list","with","new","vocabulary",".","Must","contain","at","least","2","elements",".","Typically",",","this","is","target","alphabet",".","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_vocabulary: List[str],
      decoding_cfg: Optional[DictConfig] = None,
  ):
      """
          Changes vocabulary used during RNNT decoding process. Use this method when fine-tuning a 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_vocabulary: list with new vocabulary. Must contain at least 2 elements. Typically, \
                  this is target alphabet.
              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 self.joint.vocabulary == new_vocabulary:
          logging.warning(
              f"Old {self.joint.vocabulary} and new {new_vocabulary} match. Not changing anything."
          )
      else:
          if new_vocabulary is None or len(new_vocabulary) == 0:
              raise ValueError(
                  f"New vocabulary must be non-empty list of chars. But I got: {new_vocabulary}"
              )
  
          joint_config = self.joint.to_config_dict()
          new_joint_config = copy.deepcopy(joint_config)
          new_joint_config["vocabulary"] = new_vocabulary
          new_joint_config["num_classes"] = len(new_vocabulary)
          del self.joint
          self.joint = EncDecRNNTModel.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(new_vocabulary)
          del self.decoder
          self.decoder = EncDecRNNTModel.from_config_dict(
              new_decoder_config
          )
  
          del self.loss
          loss_name, loss_kwargs = self.extract_rnnt_loss_cfg(
              self.cfg.get("loss", None)
          )
          self.loss = RNNTLoss(
              num_classes=self.joint.num_classes_with_blank - 1,
              loss_name=loss_name,
              loss_kwargs=loss_kwargs,
          )
  
          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(RNNTDecodingConfig)
          decoding_cls = OmegaConf.create(
              OmegaConf.to_container(decoding_cls)
          )
          decoding_cfg = OmegaConf.merge(decoding_cls, decoding_cfg)
  
          self.decoding = RNNTDecoding(
              decoding_cfg=decoding_cfg,
              decoder=self.decoder,
              joint=self.joint,
              vocabulary=self.joint.vocabulary,
          )
  
          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
  
          ds_keys = ["train_ds", "validation_ds", "test_ds"]
          for key in ds_keys:
              if key in self.cfg:
                  with open_dict(self.cfg[key]):
                      self.cfg[key]["labels"] = OmegaConf.create(
                          new_vocabulary
                      )
  
          logging.info(
              f"Changed decoder to output to {self.joint.vocabulary} vocabulary."
          )
  
imports: import copy
  import json
  import os
  import tempfile
  from math import ceil
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  from omegaconf import DictConfig, OmegaConf, open_dict
  from pytorch_lightning import Trainer
  from tqdm.auto import tqdm
  from nemo.collections.asr.data import audio_to_text_dataset
  from nemo.collections.asr.data.audio_to_text_dali import AudioToCharDALIDataset, DALIOutputs
  from nemo.collections.asr.data.audio_to_text_lhotse import LhotseSpeechToTextBpeDataset
  from nemo.collections.asr.losses.rnnt import RNNTLoss, resolve_rnnt_default_loss_name
  from nemo.collections.asr.metrics.wer import WER
  from nemo.collections.asr.models.asr_model import ASRModel, ExportableEncDecModel
  from nemo.collections.asr.modules.rnnt import RNNTDecoderJoint
  from nemo.collections.asr.parts.mixins import ASRModuleMixin
  from nemo.collections.asr.parts.submodules.rnnt_decoding import RNNTDecoding, RNNTDecodingConfig
  from nemo.collections.asr.parts.utils.audio_utils import ChannelSelectorType
  from nemo.collections.common.data.lhotse import get_lhotse_dataloader_from_config
  from nemo.collections.common.parts.preprocessing.parsers import make_parser
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.classes.mixins import AccessMixin
  from nemo.core.neural_types import AcousticEncodedRepresentation, AudioSignal, LengthsType, NeuralType, SpectrogramType
  from nemo.utils import logging
label_desc: Use image node_id 5 for calling the EncDecRNNTModel obj's underlying member method code with example usage: obj.change_vocabulary(new_vocabulary, decoding_cfg) without return types