class_docstr: Transformer-based (duplex) tagger model for TN/ITN.
docstr: Function for postprocessing the raw tag predictions of the model. It
  corrects obvious mistakes in the tag predictions such as a TRANSFORM span
  starts with I_TRANSFORM_TAG (instead of B_TRANSFORM_TAG).
  
  Args:
      words: The words in the input sentence
      inst_dir: The direction of the instance (i.e., constants.INST_BACKWARD or INST_FORWARD).
      preds: The raw tag predictions
  
  Returns: The processed raw tag predictions
docstr_tok: ["Function","for","postprocessing","the","raw","tag","predictions","of","the","model",".","It","corrects","obvious","mistakes","in","the","tag","predictions","such","as","a","TRANSFORM","span","starts","with","I_TRANSFORM_TAG","(","instead","of","B_TRANSFORM_TAG",")",".","Args",":","words",":","The","words","in","the","input","sentence","inst_dir",":","The","direction","of","the","instance","(","i.e.",",","constants.INST_BACKWARD","or","INST_FORWARD",")",".","preds",":","The","raw","tag","predictions","Returns",":","The","processed","raw","tag","predictions"]
code: def _postprocess_tag_preds(
      self, words: List[str], inst_dir: str, preds: List[str]
  ):
      """Function for postprocessing the raw tag predictions of the model. It
      corrects obvious mistakes in the tag predictions such as a TRANSFORM span
      starts with I_TRANSFORM_TAG (instead of B_TRANSFORM_TAG).
  
      Args:
          words: The words in the input sentence
          inst_dir: The direction of the instance (i.e., constants.INST_BACKWARD or INST_FORWARD).
          preds: The raw tag predictions
  
      Returns: The processed raw tag predictions
      """
      final_preds = []
      for ix, p in enumerate(preds):
          # a TRANSFORM span starts with I_TRANSFORM_TAG, change to B_TRANSFORM_TAG
          if p == constants.I_PREFIX + constants.TRANSFORM_TAG:
              if ix == 0 or (
                  not constants.TRANSFORM_TAG in final_preds[ix - 1]
              ):
                  final_preds.append(
                      constants.B_PREFIX + constants.TRANSFORM_TAG
                  )
                  continue
          # a span has numbers but does not have TRANSFORM tags (for TN)
          if inst_dir == constants.INST_FORWARD:
              if has_numbers(words[ix]) and (
                  not constants.TRANSFORM_TAG in p
              ):
                  final_preds.append(
                      constants.B_PREFIX + constants.TRANSFORM_TAG
                  )
                  continue
          # Convert B-TASK tag to B-SAME tag
          if p == constants.B_PREFIX + constants.TASK_TAG:
              final_preds.append(
                  constants.B_PREFIX + constants.SAME_TAG
              )
              continue
          # Default
          final_preds.append(p)
      return final_preds
  
imports: from time import perf_counter
  from typing import Dict, List, Optional
  import torch
  from omegaconf import DictConfig
  from pytorch_lightning import Trainer
  from torch import nn
  from transformers import AutoModelForTokenClassification, AutoTokenizer, DataCollatorForTokenClassification
  from transformers.tokenization_utils_base import BatchEncoding
  from nemo.collections.nlp.data.text_normalization import TextNormalizationTaggerDataset, constants
  from nemo.collections.nlp.metrics.classification_report import ClassificationReport
  from nemo.collections.nlp.models.duplex_text_normalization.utils import has_numbers
  from nemo.collections.nlp.models.nlp_model import NLPModel
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.neural_types import ChannelType, LogitsType, MaskType, NeuralType
  from nemo.utils import logging
label_desc: Use image node_id 13 for calling the DuplexTaggerModel obj's underlying member method code with example usage: obj._postprocess_tag_preds(words, inst_dir, preds) and returns: final_preds