class_docstr: BERT-based tagging model for ITN, inspired by LaserTagger approach.
  It maps spoken-domain input words to tags:
      KEEP, DELETE, or any of predefined replacement tags which correspond to a written-domain fragment.
  Example: one hundred thirty four -> _1 <DELETE> 3 4_
class_docstr_tok: ["BERT-based","tagging","model","for","ITN",",","inspired","by","LaserTagger","approach",".","It","maps","spoken-domain","input","words","to","tags",":","KEEP",",","DELETE",",","or","any","of","predefined","replacement","tags","which","correspond","to","a","written-domain","fragment",".","Example",":","one","hundred","thirty","four","-",">","_1","<","DELETE",">","3","4_"]
code: def __init__(self, cfg: DictConfig, trainer: Trainer = None) -> None:
      super().__init__(cfg=cfg, trainer=trainer)
  
      label_map_file = self.register_artifact(
          "label_map", cfg.label_map, verify_src_exists=True
      )
      semiotic_classes_file = self.register_artifact(
          "semiotic_classes",
          cfg.semiotic_classes,
          verify_src_exists=True,
      )
      self.label_map = read_label_map(label_map_file)
      self.semiotic_classes = read_semiotic_classes(
          semiotic_classes_file
      )
  
      self.num_labels = len(self.label_map)
      self.num_semiotic_labels = len(self.semiotic_classes)
      self.id_2_tag = {
          tag_id: tagging.Tag(tag)
          for tag, tag_id in self.label_map.items()
      }
      self.id_2_semiotic = {
          semiotic_id: semiotic
          for semiotic, semiotic_id in self.semiotic_classes.items()
      }
      self.max_sequence_len = cfg.get(
          "max_sequence_len", self.tokenizer.tokenizer.model_max_length
      )
  
      # setup to track metrics
      # we will have (len(self.semiotic_classes) + 1) labels
      # last one stands for WRONG (span in which the predicted tags don't match the labels)
      # this is needed to feed the sequence of classes to classification_report during validation
      label_ids = self.semiotic_classes.copy()
      label_ids["WRONG"] = len(self.semiotic_classes)
      self.tag_classification_report = ClassificationReport(
          len(self.semiotic_classes) + 1,
          label_ids=label_ids,
          mode="micro",
          dist_sync_on_step=True,
      )
      self.tag_multiword_classification_report = ClassificationReport(
          len(self.semiotic_classes) + 1,
          label_ids=label_ids,
          mode="micro",
          dist_sync_on_step=True,
      )
      self.semiotic_classification_report = ClassificationReport(
          len(self.semiotic_classes) + 1,
          label_ids=label_ids,
          mode="micro",
          dist_sync_on_step=True,
      )
  
      self.hidden_size = cfg.hidden_size
  
      self.logits = TokenClassifier(
          self.hidden_size,
          num_classes=self.num_labels,
          num_layers=1,
          log_softmax=False,
          dropout=0.1,
      )
      self.semiotic_logits = TokenClassifier(
          self.hidden_size,
          num_classes=self.num_semiotic_labels,
          num_layers=1,
          log_softmax=False,
          dropout=0.1,
      )
  
      self.loss_fn = CrossEntropyLoss(logits_ndim=3)
  
      self.builder = bert_example.BertExampleBuilder(
          self.label_map,
          self.semiotic_classes,
          self.tokenizer.tokenizer,
          self.max_sequence_len,
      )
  
imports: from time import perf_counter
  from typing import Dict, List, Optional
  import torch
  from omegaconf import DictConfig
  from pytorch_lightning import Trainer
  from nemo.collections.common.losses import CrossEntropyLoss
  from nemo.collections.nlp.data.text_normalization_as_tagging import ThutmoseTaggerDataset, ThutmoseTaggerTestDataset, bert_example, tagging
  from nemo.collections.nlp.data.text_normalization_as_tagging.utils import read_label_map, read_semiotic_classes
  from nemo.collections.nlp.metrics.classification_report import ClassificationReport
  from nemo.collections.nlp.models.nlp_model import NLPModel
  from nemo.collections.nlp.modules.common.token_classifier import TokenClassifier
  from nemo.collections.nlp.parts.utils_funcs import tensor2list
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.neural_types import LogitsType, NeuralType
  from nemo.utils import logging
  from nemo.utils.decorators import experimental
label_desc: Use image node_id 4 to create a new ThutmoseTaggerModel object from inherited base classes: NLPModel with example: obj = ThutmoseTaggerModel(cfg, trainer)