class_docstr: DuplexTextNormalizationModel is a wrapper class that can be used to
  encapsulate a trained tagger and a trained decoder. The class is intended
  to be used for inference only (e.g., for evaluation).
class_docstr_tok: ["DuplexTextNormalizationModel","is","a","wrapper","class","that","can","be","used","to","encapsulate","a","trained","tagger","and","a","trained","decoder",".","The","class","is","intended","to","be","used","for","inference","only","(","e.g.",",","for","evaluation",")","."]
docstr: Main function for Inference
  
  If the 'joint' mode is used, "sents" will include both spoken and written forms on each input sentence,
  and "inst_directions" will include both constants.INST_BACKWARD and constants.INST_FORWARD
  
  Args:
      sents: A list of input texts.
      inst_directions: A list of str where each str indicates the direction of the corresponding instance                 (i.e., constants.INST_BACKWARD for ITN or constants.INST_FORWARD for TN).
      processed: Set to True when used with TextNormalizationTestDataset, the data is already tokenized with moses,
          repetitive moses tokenization could lead to the number of tokens and class span mismatch
  
  Returns:
      tag_preds: A list of lists where the inner list contains the tag predictions from the tagger for each word in the input text.
      output_spans: A list of lists where each list contains the decoded semiotic spans from the decoder for an input text.
      final_outputs: A list of str where each str is the final output text for an input text.
docstr_tok: ["Main","function","for","Inference","If","the","'joint","'","mode","is","used",",","``","sents","''","will","include","both","spoken","and","written","forms","on","each","input","sentence",",","and","``","inst_directions","''","will","include","both","constants.INST_BACKWARD","and","constants.INST_FORWARD","Args",":","sents",":","A","list","of","input","texts",".","inst_directions",":","A","list","of","str","where","each","str","indicates","the","direction","of","the","corresponding","instance","(","i.e.",",","constants.INST_BACKWARD","for","ITN","or","constants.INST_FORWARD","for","TN",")",".","processed",":","Set","to","True","when","used","with","TextNormalizationTestDataset",",","the","data","is","already","tokenized","with","moses",",","repetitive","moses","tokenization","could","lead","to","the","number","of","tokens","and","class","span","mismatch","Returns",":","tag_preds",":","A","list","of","lists","where","the","inner","list","contains","the","tag","predictions","from","the","tagger","for","each","word","in","the","input","text",".","output_spans",":","A","list","of","lists","where","each","list","contains","the","decoded","semiotic","spans","from","the","decoder","for","an","input","text",".","final_outputs",":","A","list","of","str","where","each","str","is","the","final","output","text","for","an","input","text","."]
code: def _infer(
      self,
      sents: List[str],
      inst_directions: List[str],
      processed=False,
  ):
      """
          Main function for Inference
  
          If the 'joint' mode is used, "sents" will include both spoken and written forms on each input sentence,
          and "inst_directions" will include both constants.INST_BACKWARD and constants.INST_FORWARD
  
          Args:
              sents: A list of input texts.
              inst_directions: A list of str where each str indicates the direction of the corresponding instance \
                  (i.e., constants.INST_BACKWARD for ITN or constants.INST_FORWARD for TN).
              processed: Set to True when used with TextNormalizationTestDataset, the data is already tokenized with moses,
                  repetitive moses tokenization could lead to the number of tokens and class span mismatch
  
          Returns:
              tag_preds: A list of lists where the inner list contains the tag predictions from the tagger for each word in the input text.
              output_spans: A list of lists where each list contains the decoded semiotic spans from the decoder for an input text.
              final_outputs: A list of str where each str is the final output text for an input text.
          """
      original_sents = [s for s in sents]
      # Separate into words
      if not processed:
          sents = [
              input_preprocessing(x, lang=self.lang) for x in sents
          ]
          sents = [
              self.decoder.processor.tokenize(x).split() for x in sents
          ]
      else:
          sents = [x.split() for x in sents]
  
      # Tagging
      # span_ends included, returns index wrt to words in input without auxiliary words
      tag_preds, nb_spans, span_starts, span_ends = self.tagger._infer(
          sents, inst_directions
      )
      output_spans = self.decoder._infer(
          sents, nb_spans, span_starts, span_ends, inst_directions
      )
  
      # Prepare final outputs
      final_outputs = []
      for ix, (sent, tags) in enumerate(zip(sents, tag_preds)):
          try:
              cur_words, jx, span_idx = [], 0, 0
              cur_spans = output_spans[ix]
              while jx < len(sent):
                  tag, word = tags[jx], sent[jx]
                  if constants.SAME_TAG in tag:
                      cur_words.append(word)
                      jx += 1
                  else:
                      jx += 1
                      cur_words.append(cur_spans[span_idx])
                      span_idx += 1
                      while (
                          jx < len(sent)
                          and tags[jx]
                          == constants.I_PREFIX
                          + constants.TRANSFORM_TAG
                      ):
                          jx += 1
  
              if processed:
                  # for Class-based evaluation, don't apply Moses detokenization
                  cur_output_str = " ".join(cur_words)
              else:
                  # detokenize the output with Moses and fix punctuation marks to match the input
                  # for interactive inference or inference from a file
                  cur_output_str = self.decoder.processor.detokenize(
                      cur_words
                  )
                  if PYNINI_AVAILABLE:
                      cur_output_str = post_process_punct(
                          input=original_sents[ix],
                          normalized_text=cur_output_str,
                      )
                  else:
                      logging.warning(
                          " `nemo_text_processing` is not installed in this environment. Please refer to"
                          " https://github.com/NVIDIA/NeMo-text-processing and install this package before using "
                          " this script: `pip install nemo_text_processing`"
                      )
              final_outputs.append(cur_output_str)
          except IndexError:
              logging.warning(
                  f"Input sent is too long and will be skipped - {original_sents[ix]}"
              )
              final_outputs.append(original_sents[ix])
      return tag_preds, output_spans, final_outputs
  
file_path: NeMo/nemo/collections/nlp/models/duplex_text_normalization/duplex_tn.py
imports: from math import ceil
  from time import perf_counter
  from typing import List
  import numpy
  import torch.nn
  from tqdm import tqdm
  from nemo.collections.nlp.data.text_normalization import TextNormalizationTestDataset, constants
  from nemo.collections.nlp.data.text_normalization.utils import input_preprocessing
  from nemo.collections.nlp.models.duplex_text_normalization.utils import get_formatted_string
  from nemo.utils import logging
label_desc: Use image node_id 3 for calling the DuplexTextNormalizationModel obj's underlying member method code with example usage: obj._infer(sents, inst_directions, processed) and returns: tag_preds,  output_spans,  final_outputs