class_docstr: A class designed for performing ASR and diarization together.
  
  Attributes:
      cfg_diarizer (OmegaConf):
          Hydra config for diarizer key
      params (OmegaConf):
          Parameters config in diarizer.asr
      ctc_decoder_params (OmegaConf)
          Hydra config for beam search decoder
      realigning_lm_params (OmegaConf):
          Hydra config for realigning language model
      manifest_filepath (str):
          Path to the input manifest path
      nonspeech_threshold (float):
          Threshold for VAD logits that are used for creating speech segments
      fix_word_ts_with_VAD (bool):
          Choose whether to fix word timestamps by using VAD results
      root_path (str):
          Path to the folder where diarization results are saved
      vad_threshold_for_word_ts (float):
          Threshold used for compensating word timestamps with VAD output
      max_word_ts_length_in_sec (float):
          Maximum limit for the duration of each word timestamp
      word_ts_anchor_offset (float):
          Offset for word timestamps from ASR decoders
      run_ASR:
          Placeholder variable for an ASR launcher function
      realigning_lm:
          Placeholder variable for a loaded ARPA Language model
      ctm_exists (bool):
          Boolean that indicates whether all files have the corresponding reference CTM file
      frame_VAD (dict):
          Dictionary containing frame-level VAD logits
      AUDIO_RTTM_MAP:
          Dictionary containing the input manifest information
      color_palette (dict):
          Dictionary containing the ANSI color escape codes for each speaker label (speaker index)
class_docstr_tok: ["A","class","designed","for","performing","ASR","and","diarization","together",".","Attributes",":","cfg_diarizer","(","OmegaConf",")",":","Hydra","config","for","diarizer","key","params","(","OmegaConf",")",":","Parameters","config","in","diarizer.asr","ctc_decoder_params","(","OmegaConf",")","Hydra","config","for","beam","search","decoder","realigning_lm_params","(","OmegaConf",")",":","Hydra","config","for","realigning","language","model","manifest_filepath","(","str",")",":","Path","to","the","input","manifest","path","nonspeech_threshold","(","float",")",":","Threshold","for","VAD","logits","that","are","used","for","creating","speech","segments","fix_word_ts_with_VAD","(","bool",")",":","Choose","whether","to","fix","word","timestamps","by","using","VAD","results","root_path","(","str",")",":","Path","to","the","folder","where","diarization","results","are","saved","vad_threshold_for_word_ts","(","float",")",":","Threshold","used","for","compensating","word","timestamps","with","VAD","output","max_word_ts_length_in_sec","(","float",")",":","Maximum","limit","for","the","duration","of","each","word","timestamp","word_ts_anchor_offset","(","float",")",":","Offset","for","word","timestamps","from","ASR","decoders","run_ASR",":","Placeholder","variable","for","an","ASR","launcher","function","realigning_lm",":","Placeholder","variable","for","a","loaded","ARPA","Language","model","ctm_exists","(","bool",")",":","Boolean","that","indicates","whether","all","files","have","the","corresponding","reference","CTM","file","frame_VAD","(","dict",")",":","Dictionary","containing","frame-level","VAD","logits","AUDIO_RTTM_MAP",":","Dictionary","containing","the","input","manifest","information","color_palette","(","dict",")",":","Dictionary","containing","the","ANSI","color","escape","codes","for","each","speaker","label","(","speaker","index",")"]
docstr: Realign the mapping between speaker labels and words using a language model.
  The realigning process calculates the probability of the certain range around the words,
  especially at the boundary between two hypothetical sentences spoken by different speakers.
  
  Example:
      k-th word: "but"
  
      hyp_former:
          since i think like tuesday </s> <s>  but he's coming back to albuquerque
      hyp_latter:
          since i think like tuesday but </s> <s>  he's coming back to albuquerque
  
  The joint probabilities of words in the sentence are computed for these two hypotheses. In addition,
  logprob_diff_threshold parameter is used for reducing the false positive realigning.
  
  Args:
      word_dict_seq_list (list):
          List containing words and corresponding word timestamps in dictionary format.
  
  Returns:
      realigned_list (list):
          List of dictionaries containing words, word timestamps and speaker labels.
docstr_tok: ["Realign","the","mapping","between","speaker","labels","and","words","using","a","language","model",".","The","realigning","process","calculates","the","probability","of","the","certain","range","around","the","words",",","especially","at","the","boundary","between","two","hypothetical","sentences","spoken","by","different","speakers",".","Example",":","k-th","word",":","``","but","''","hyp_former",":","since","i","think","like","tuesday","<","\/s",">","<","s",">","but","he","'s","coming","back","to","albuquerque","hyp_latter",":","since","i","think","like","tuesday","but","<","\/s",">","<","s",">","he","'s","coming","back","to","albuquerque","The","joint","probabilities","of","words","in","the","sentence","are","computed","for","these","two","hypotheses",".","In","addition",",","logprob_diff_threshold","parameter","is","used","for","reducing","the","false","positive","realigning",".","Args",":","word_dict_seq_list","(","list",")",":","List","containing","words","and","corresponding","word","timestamps","in","dictionary","format",".","Returns",":","realigned_list","(","list",")",":","List","of","dictionaries","containing","words",",","word","timestamps","and","speaker","labels","."]
code: def realign_words_with_lm(
      self, word_dict_seq_list: List[Dict[str, float]]
  ) -> List[Dict[str, float]]:
      """
      Realign the mapping between speaker labels and words using a language model.
      The realigning process calculates the probability of the certain range around the words,
      especially at the boundary between two hypothetical sentences spoken by different speakers.
  
      Example:
          k-th word: "but"
  
          hyp_former:
              since i think like tuesday </s> <s>  but he's coming back to albuquerque
          hyp_latter:
              since i think like tuesday but </s> <s>  he's coming back to albuquerque
  
      The joint probabilities of words in the sentence are computed for these two hypotheses. In addition,
      logprob_diff_threshold parameter is used for reducing the false positive realigning.
  
      Args:
          word_dict_seq_list (list):
              List containing words and corresponding word timestamps in dictionary format.
  
      Returns:
          realigned_list (list):
              List of dictionaries containing words, word timestamps and speaker labels.
      """
      word_seq_len = len(word_dict_seq_list)
      hyp_w_dict_list, spk_list = [], []
      for k, line_dict in enumerate(word_dict_seq_list):
          word, spk_label = line_dict["word"], line_dict["speaker"]
          hyp_w_dict_list.append(word)
          spk_list.append(spk_label)
  
      realigned_list = []
      org_spk_list = copy.deepcopy(spk_list)
      for k, line_dict in enumerate(word_dict_seq_list):
          if self.N_range[0] < k < (
              word_seq_len - self.N_range[0]
          ) and (
              spk_list[k] != org_spk_list[k + 1]
              or spk_list[k] != org_spk_list[k - 1]
          ):
              N1, N2 = self._get_realignment_ranges(k, word_seq_len)
              hyp_former = self.realigning_lm.log_s(
                  " ".join(
                      hyp_w_dict_list[k - N1 : k]
                      + self.stt_end_tokens
                      + hyp_w_dict_list[k : k + N2]
                  )
              )
              hyp_latter = self.realigning_lm.log_s(
                  " ".join(
                      hyp_w_dict_list[k - N1 : k + 1]
                      + self.stt_end_tokens
                      + hyp_w_dict_list[k + 1 : k + N2]
                  )
              )
              log_p = [hyp_former, hyp_latter]
              p_order = np.argsort(log_p)[::-1]
              if (
                  log_p[p_order[0]]
                  > log_p[p_order[1]]
                  + self.realigning_lm_params["logprob_diff_threshold"]
              ):
                  if p_order[0] == 0:
                      spk_list[k] = org_spk_list[k + 1]
              line_dict["speaker"] = spk_list[k]
          realigned_list.append(line_dict)
      return realigned_list
  
imports: import copy
  import csv
  import json
  import os
  from collections import OrderedDict
  from datetime import datetime
  from typing import Dict, List, Tuple
  import numpy
  from nemo.collections.asr.metrics.der import concat_perm_word_error_rate
  from nemo.collections.asr.metrics.wer import word_error_rate
  from nemo.collections.asr.models import ClusteringDiarizer
  from nemo.collections.asr.parts.utils.speaker_utils import audio_rttm_map, get_uniqname_from_filepath, labels_to_rttmfile, rttm_to_labels, write_rttm2manifest
  from nemo.utils import logging
label_desc: Use image node_id 20 for calling the OfflineDiarWithASR obj's underlying member method code with example usage: obj.realign_words_with_lm(word_dict_seq_list) and returns: realigned_list