class_docstr: Class for computation the total puncutation-related absolute amounts of operations and their rates 
  in pairs of reference and hypothesis strins:
      - Absolute amounts of correct predictions, deletions, insertions
      and substitutions for each given punctuation mark
      - Rates of correct predictions, deletions, insertions
      and substitutions for each given punctuation mark 
      - Total rates of correct predictions, deletions, insertions
      and substiturions in pairs of reference and hypothesis strings 
      - Punctuation Error Rate
      
  Args to init:
      references (list[str]) - list of references
      hypotheses (list[str]) - list of hypotheses
      punctuation_marks (list[str]) - list of punctuation marks for computing metrics
      punctuation_mask (str, by default "[PUNCT]") - mask token that will be applied to
      given punctuation marks while edit distance calculation
      
  How to use:
      1. Create object of DatasetPunctuationErrorRate class.
         Example:
              references = ["Hi, dear! Nice to see you. What's"]
              hypotheses = ["Hi dear! Nice to see you! What's?"]                
              punctuation_marks = [".", ",", "!", "?"]
              
              dper_obj = DatasetPunctuationErrorRate(references, hypotheses, punctuation_marks)
              
      2. To compute punctuation metrics, call the class method "compute()".
          Example:
              dper_obj.compute() 
              
  Result:
  The following atributes of class object will be updated with calculated metrics values.
  The values are available with calling the atributes:
      
      dper_obj.operation_rates - dict, rates of correctness and errors for each punctuation mark 
      from `preset dper_obj.punctuation_marks` list.
      
      dper_obj.substitution_rates - dict, substitution rates between puncutation marks from
      `preset dper_obj.punctuation_marks` list.
      
      dper_obj.correct_rate - float, total rate of correctness between provided pairs of 
      references and hypotheses.
      
      dper_obj.deletions_rate - float, total rate of deletions between provided pairs of 
      references and hypotheses.
      
      dper_obj.insertions_rate - float, total rate of insertions between provided pairs of 
      references and hypotheses.
      
      dper_obj.substitutions_rate - float, total rate of substitutions between provided pairs of 
      references and hypotheses.
      
      dper_obj.punct_er - float, total Punctuation Error Rate between provided pairs of 
      references and hypotheses.
class_docstr_tok: ["Class","for","computation","the","total","puncutation-related","absolute","amounts","of","operations","and","their","rates","in","pairs","of","reference","and","hypothesis","strins",":","-","Absolute","amounts","of","correct","predictions",",","deletions",",","insertions","and","substitutions","for","each","given","punctuation","mark","-","Rates","of","correct","predictions",",","deletions",",","insertions","and","substitutions","for","each","given","punctuation","mark","-","Total","rates","of","correct","predictions",",","deletions",",","insertions","and","substiturions","in","pairs","of","reference","and","hypothesis","strings","-","Punctuation","Error","Rate","Args","to","init",":","references","(","list","[","str","]",")","-","list","of","references","hypotheses","(","list","[","str","]",")","-","list","of","hypotheses","punctuation_marks","(","list","[","str","]",")","-","list","of","punctuation","marks","for","computing","metrics","punctuation_mask","(","str",",","by","default","``","[","PUNCT","]","''",")","-","mask","token","that","will","be","applied","to","given","punctuation","marks","while","edit","distance","calculation","How","to","use",":","1",".","Create","object","of","DatasetPunctuationErrorRate","class",".","Example",":","references","=","[","``","Hi",",","dear","!","Nice","to","see","you",".","What","'s","''","]","hypotheses","=","[","``","Hi","dear","!","Nice","to","see","you","!","What","'s","?","''","]","punctuation_marks","=","[","``",".","``",",","``",",","''",",","``","!","``",",","``","?","''","]","dper_obj","=","DatasetPunctuationErrorRate","(","references",",","hypotheses",",","punctuation_marks",")","2",".","To","compute","punctuation","metrics",",","call","the","class","method","``","compute","(",")","''",".","Example",":","dper_obj.compute","(",")","Result",":","The","following","atributes","of","class","object","will","be","updated","with","calculated","metrics","values",".","The","values","are","available","with","calling","the","atributes",":","dper_obj.operation_rates","-","dict",",","rates","of","correctness","and","errors","for","each","punctuation","mark","from","`","preset","dper_obj.punctuation_marks","`","list",".","dper_obj.substitution_rates","-","dict",",","substitution","rates","between","puncutation","marks","from","`","preset","dper_obj.punctuation_marks","`","list",".","dper_obj.correct_rate","-","float",",","total","rate","of","correctness","between","provided","pairs","of","references","and","hypotheses",".","dper_obj.deletions_rate","-","float",",","total","rate","of","deletions","between","provided","pairs","of","references","and","hypotheses",".","dper_obj.insertions_rate","-","float",",","total","rate","of","insertions","between","provided","pairs","of","references","and","hypotheses",".","dper_obj.substitutions_rate","-","float",",","total","rate","of","substitutions","between","provided","pairs","of","references","and","hypotheses",".","dper_obj.punct_er","-","float",",","total","Punctuation","Error","Rate","between","provided","pairs","of","references","and","hypotheses","."]
code: def print(self):
      logging.info(
          f"Dataset PER " + str(round(100 * self.punct_er, 2)) + "%"
      )
  
      if HAVE_TABLUATE_AND_PANDAS:
          rates_by_pm_df = pd.DataFrame(self.operation_rates) * 100
          substitution_rates_by_pm_df = (
              pd.DataFrame(self.substitution_rates) * 100
          )
  
          logging.info(
              "Rates of punctuation correctness and errors (%):\n"
              + tabulate(
                  rates_by_pm_df, headers="keys", tablefmt="psql"
              )
          )
          logging.info(
              "Substitution rates between punctuation marks (%):\n"
              + tabulate(
                  substitution_rates_by_pm_df,
                  headers="keys",
                  tablefmt="psql",
              )
          )
      else:
          logging.warning(
              "Some of the modules (pandas or tabulate) can't be imported"
          )
          logging.info(
              f"Rates of punctuation correctness and errors (in range [0, 1]):\n{self.operation_rates}\n"
          )
          logging.info(
              f"Substitution rates between punctuation marks (in range [0, 1]):\n{self.substitution_rates}\n"
          )
  
file_path: NeMo/nemo/collections/common/metrics/punct_er.py
imports: import re
  from collections import namedtuple
  from tqdm import tqdm
  from nemo.utils import logging
label_desc: Use image node_id 4 for calling the DatasetPunctuationErrorRate obj's underlying member method code with example usage: obj.print() without return types