class_docstr: Creates dataset to use to do end-to-end inference
  
  Args:
      input_file: path to the raw data file (e.g., train.tsv). For more info about the data format, refer to the `text_normalization doc <https://github.com/NVIDIA/NeMo/blob/main/docs/source/nlp/text_normalization.rst>`.
      mode: should be one of the values ['tn', 'itn', 'joint'].  `tn` mode is for TN only. `itn` mode is for ITN only. `joint` is for training a system that can do both TN and ITN at the same time.
      lang: Language of the dataset
class_docstr_tok: ["Creates","dataset","to","use","to","do","end-to-end","inference","Args",":","input_file",":","path","to","the","raw","data","file","(","e.g.",",","train.tsv",")",".","For","more","info","about","the","data","format",",","refer","to","the","`","text_normalization","doc","<","https",":","\/\/github.com\/NVIDIA\/NeMo\/blob\/main\/docs\/source\/nlp\/text_normalization.rst",">","`",".","mode",":","should","be","one","of","the","values","[","'tn","'",",","'itn","'",",","'joint","'","]",".","`","tn","`","mode","is","for","TN","only",".","`","itn","`","mode","is","for","ITN","only",".","`","joint","`","is","for","training","a","system","that","can","do","both","TN","and","ITN","at","the","same","time",".","lang",":","Language","of","the","dataset"]
docstr: Compute the class based accuracy metric. This uses model's predicted tags.
  
  Args:
      inputs: List of lists where inner list contains words of input text
      targets: List of lists where inner list contains target strings grouped by class boundary
      tag_preds: List of lists where inner list contains predicted tags for each of the input words
      inst_directions: A list of str where each str indicates the direction of the corresponding instance (i.e., INST_BACKWARD or INST_FORWARD).
      output_spans: A list of lists where each inner list contains the decoded spans for the corresponding input sentence
      classes: A list of lists where inner list contains the class for each semiotic token in input sentence
      nb_spans: A list that contains the number of tokens in the input
      span_ends: A list of lists where inner list contains the end word index of the current token
  Return: the class accuracy scores as dict
docstr_tok: ["Compute","the","class","based","accuracy","metric",".","This","uses","model","'s","predicted","tags",".","Args",":","inputs",":","List","of","lists","where","inner","list","contains","words","of","input","text","targets",":","List","of","lists","where","inner","list","contains","target","strings","grouped","by","class","boundary","tag_preds",":","List","of","lists","where","inner","list","contains","predicted","tags","for","each","of","the","input","words","inst_directions",":","A","list","of","str","where","each","str","indicates","the","direction","of","the","corresponding","instance","(","i.e.",",","INST_BACKWARD","or","INST_FORWARD",")",".","output_spans",":","A","list","of","lists","where","each","inner","list","contains","the","decoded","spans","for","the","corresponding","input","sentence","classes",":","A","list","of","lists","where","inner","list","contains","the","class","for","each","semiotic","token","in","input","sentence","nb_spans",":","A","list","that","contains","the","number","of","tokens","in","the","input","span_ends",":","A","list","of","lists","where","inner","list","contains","the","end","word","index","of","the","current","token","Return",":","the","class","accuracy","scores","as","dict"]
code: def compute_class_accuracy(
      inputs: List[List[str]],
      targets: List[List[str]],
      tag_preds: List[List[str]],
      inst_directions: List[str],
      output_spans: List[List[str]],
      classes: List[List[str]],
      nb_spans: List[int],
      span_ends: List[List[int]],
  ) -> dict:
      """
      Compute the class based accuracy metric. This uses model's predicted tags.
  
      Args:
          inputs: List of lists where inner list contains words of input text
          targets: List of lists where inner list contains target strings grouped by class boundary
          tag_preds: List of lists where inner list contains predicted tags for each of the input words
          inst_directions: A list of str where each str indicates the direction of the corresponding instance (i.e., INST_BACKWARD or INST_FORWARD).
          output_spans: A list of lists where each inner list contains the decoded spans for the corresponding input sentence
          classes: A list of lists where inner list contains the class for each semiotic token in input sentence
          nb_spans: A list that contains the number of tokens in the input
          span_ends: A list of lists where inner list contains the end word index of the current token
      Return: the class accuracy scores as dict
      """
  
      if len(targets) == 0:
          return "NA"
      class2stats, class2correct = defaultdict(int), defaultdict(int)
      for ix, (sent, tags) in enumerate(zip(inputs, tag_preds)):
          try:
              assert len(sent) == len(tags)
          except:
              logging.warning(f"Error: skipping example {ix}")
              continue
          cur_words = [[] for _ in range(nb_spans[ix])]
          jx, span_idx = 0, 0
          cur_spans = output_spans[ix]
          class_idx = 0
          if classes[ix]:
              class2stats[classes[ix][class_idx]] += 1
          while jx < len(sent):
              tag, word = tags[jx], sent[jx]
              while jx >= span_ends[ix][class_idx]:
                  class_idx += 1
                  class2stats[classes[ix][class_idx]] += 1
              if constants.SAME_TAG in tag:
                  cur_words[class_idx].append(word)
                  jx += 1
              else:
                  jx += 1
                  tmp = cur_spans[span_idx]
                  cur_words[class_idx].append(tmp)
                  span_idx += 1
                  while (
                      jx < len(sent)
                      and tags[jx]
                      == constants.I_PREFIX + constants.TRANSFORM_TAG
                  ):
                      while jx >= span_ends[ix][class_idx]:
                          class_idx += 1
                          class2stats[classes[ix][class_idx]] += 1
                          cur_words[class_idx].append(tmp)
                      jx += 1
  
          target_token_idx = 0
          # assert len(cur_words) == len(targets[ix])
          for class_idx in range(nb_spans[ix]):
              correct = TextNormalizationTestDataset.is_same(
                  " ".join(cur_words[class_idx]),
                  targets[ix][target_token_idx],
                  inst_directions[ix],
              )
              class2correct[classes[ix][class_idx]] += correct
              target_token_idx += 1
  
      for key in class2stats:
          class2stats[key] = (
              class2correct[key] / class2stats[key],
              class2correct[key],
              class2stats[key],
          )
  
      return class2stats
  
file_path: NeMo/nemo/collections/nlp/data/text_normalization/test_dataset.py
imports: from collections import defaultdict
  from typing import List
  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 normalize_str, read_data_file, remove_puncts
  from nemo.utils import logging
label_desc: Use image node_id 6 for calling the TextNormalizationTestDataset obj's underlying member method code with example usage: obj.compute_class_accuracy(inputs, targets, tag_preds, inst_directions, output_spans, classes, nb_spans, span_ends) and returns: class2stats, str