class_docstr: This class represents a data instance in a TextNormalizationDecoderDataset.
  
  Intuitively, each data instance can be thought as having the following form:
      Input:  <Left Context of Input> <Input Span> <Right Context of Input>
      Output: <Output Span>
  where the context size is determined by the constant DECODE_CTX_SIZE.
  
  Args:
      w_words: List of words in the written form
      s_words: List of words in the spoken form
      inst_dir: Indicates the direction of the instance (i.e., INST_BACKWARD for ITN or INST_FORWARD for TN).
      start_idx: The starting index of the input span in the original input text
      end_idx: The ending index of the input span (exclusively)
      lang: Language of the instance
      semiotic_class: The semiotic class of the input span (can be set to None if not available)
class_docstr_tok: ["This","class","represents","a","data","instance","in","a","TextNormalizationDecoderDataset",".","Intuitively",",","each","data","instance","can","be","thought","as","having","the","following","form",":","Input",":","<","Left","Context","of","Input",">","<","Input","Span",">","<","Right","Context","of","Input",">","Output",":","<","Output","Span",">","where","the","context","size","is","determined","by","the","constant","DECODE_CTX_SIZE",".","Args",":","w_words",":","List","of","words","in","the","written","form","s_words",":","List","of","words","in","the","spoken","form","inst_dir",":","Indicates","the","direction","of","the","instance","(","i.e.",",","INST_BACKWARD","for","ITN","or","INST_FORWARD","for","TN",")",".","start_idx",":","The","starting","index","of","the","input","span","in","the","original","input","text","end_idx",":","The","ending","index","of","the","input","span","(","exclusively",")","lang",":","Language","of","the","instance","semiotic_class",":","The","semiotic","class","of","the","input","span","(","can","be","set","to","None","if","not","available",")"]
code: def __init__(
      self,
      w_words: List[str],
      s_words: List[str],
      inst_dir: str,
      start_idx: int,
      end_idx: int,
      lang: str,
      semiotic_class: str = None,
  ):
      processor = MosesProcessor(lang_id=lang)
      start_idx = max(start_idx, 0)
      end_idx = min(end_idx, len(w_words))
      ctx_size = constants.DECODE_CTX_SIZE
      extra_id_0 = constants.EXTRA_ID_0
      extra_id_1 = constants.EXTRA_ID_1
  
      # Extract center words
      c_w_words = w_words[start_idx:end_idx]
      c_s_words = s_words[start_idx:end_idx]
  
      # Extract context
      w_left = w_words[max(0, start_idx - ctx_size) : start_idx]
      w_right = w_words[end_idx : end_idx + ctx_size]
      s_left = s_words[max(0, start_idx - ctx_size) : start_idx]
      s_right = s_words[end_idx : end_idx + ctx_size]
  
      # Process sil words and self words
      for jx in range(len(s_left)):
          if s_left[jx] == constants.SIL_WORD:
              s_left[jx] = ""
          if s_left[jx] == constants.SELF_WORD:
              s_left[jx] = w_left[jx]
      for jx in range(len(s_right)):
          if s_right[jx] == constants.SIL_WORD:
              s_right[jx] = ""
          if s_right[jx] == constants.SELF_WORD:
              s_right[jx] = w_right[jx]
      for jx in range(len(c_s_words)):
          if c_s_words[jx] == constants.SIL_WORD:
              c_s_words[jx] = c_w_words[jx]
              if inst_dir == constants.INST_BACKWARD:
                  c_w_words[jx] = ""
                  c_s_words[jx] = ""
          if c_s_words[jx] == constants.SELF_WORD:
              c_s_words[jx] = c_w_words[jx]
  
      # Extract input_words and output_words
      c_w_words = processor.tokenize(" ".join(c_w_words)).split()
      c_s_words = processor.tokenize(" ".join(c_s_words)).split()
  
      # for cases when nearby words are actually multiple tokens, e.g. '1974,'
      w_left = processor.tokenize(" ".join(w_left)).split()[
          -constants.DECODE_CTX_SIZE :
      ]
      w_right = processor.tokenize(" ".join(w_right)).split()[
          : constants.DECODE_CTX_SIZE
      ]
  
      w_input = (
          w_left + [extra_id_0] + c_w_words + [extra_id_1] + w_right
      )
      s_input = (
          s_left + [extra_id_0] + c_s_words + [extra_id_1] + s_right
      )
  
      if inst_dir == constants.INST_BACKWARD:
          input_center_words = c_s_words
          input_words = [constants.ITN_PREFIX] + s_input
          output_words = c_w_words
      if inst_dir == constants.INST_FORWARD:
          input_center_words = c_w_words
          input_words = [constants.TN_PREFIX] + w_input
          output_words = c_s_words
      # Finalize
      self.input_str = " ".join(input_words)
      self.input_center_str = " ".join(input_center_words)
      self.output_str = " ".join(output_words)
      self.direction = inst_dir
      self.semiotic_class = semiotic_class
  
imports: import io
  import os
  import pickle
  import random
  from collections import OrderedDict
  from typing import List, Optional, Tuple
  import braceexpand
  import numpy
  import torch
  import webdataset
  from torch.utils.data import IterableDataset
  from tqdm import tqdm
  from transformers import PreTrainedTokenizerBase
  from nemo.collections.common.tokenizers.moses_tokenizers import MosesProcessor
  from nemo.collections.nlp.data.text_normalization import constants
  from nemo.collections.nlp.data.text_normalization.utils import read_data_file
  from nemo.core.classes import Dataset
  from nemo.utils import logging
label_desc: Use image node_id 1 to create a new DecoderDataInstance object  with example: obj = DecoderDataInstance(w_words, s_words, inst_dir, start_idx, end_idx, lang, semiotic_class)