class_docstr: Builder class for BertExample objects.
class_docstr_tok: ["Builder","class","for","BertExample","objects","."]
docstr: Reads in Tab Separated Value file and converts to training/inference-ready examples.
  
  Args:
      example_builder: Instance of BertExampleBuilder
      input_filename: Path to the TSV input file.
      infer: If true, input examples do not contain target info.
  
  Returns:
      examples: List of converted examples (BertExample). 
         or
      (examples, hyps_refs): If infer==true, returns h 
docstr_tok: ["Reads","in","Tab","Separated","Value","file","and","converts","to","training\/inference-ready","examples",".","Args",":","example_builder",":","Instance","of","BertExampleBuilder","input_filename",":","Path","to","the","TSV","input","file",".","infer",":","If","true",",","input","examples","do","not","contain","target","info",".","Returns",":","examples",":","List","of","converted","examples","(","BertExample",")",".","or","(","examples",",","hyps_refs",")",":","If","infer==true",",","returns","h"]
code: def read_input_file(
      self, input_filename: str, infer: bool = False
  ) -> Union[
      List["BertExample"], Tuple[List["BertExample"], Tuple[str, str]]
  ]:
      """Reads in Tab Separated Value file and converts to training/inference-ready examples.
  
      Args:
          example_builder: Instance of BertExampleBuilder
          input_filename: Path to the TSV input file.
          infer: If true, input examples do not contain target info.
  
      Returns:
          examples: List of converted examples (BertExample).
             or
          (examples, hyps_refs): If infer==true, returns h
      """
  
      if not path.exists(input_filename):
          raise ValueError("Cannot find file: " + input_filename)
      examples = []  # output list of BertExample
      hyps_refs = (
          []
      )  # output list of tuples (ASR-hypothesis, candidate_str)
      with open(input_filename, "r") as f:
          for line in f:
              if len(examples) % 1000 == 0:
                  logging.info(
                      "{} examples processed.".format(len(examples))
                  )
              if infer:
                  parts = line.rstrip("\n").split("\t")
                  hyp, ref, target, span_info = (
                      parts[0],
                      parts[1],
                      None,
                      None,
                  )
                  if len(parts) == 4:
                      target, span_info = parts[2], parts[3]
                  try:
                      example = self.build_bert_example(
                          hyp,
                          ref,
                          target=target,
                          span_info=span_info,
                          infer=infer,
                      )
                  except Exception as e:
                      logging.warning(str(e))
                      logging.warning(line)
                      continue
                  if example is None:
                      logging.info("cannot create example: ")
                      logging.info(line)
                      continue
                  hyps_refs.append((hyp, ref))
                  examples.append(example)
              else:
                  hyp, ref, target, semiotic_info = line.rstrip(
                      "\n"
                  ).split("\t")
                  try:
                      example = self.build_bert_example(
                          hyp,
                          ref,
                          target=target,
                          span_info=semiotic_info,
                          infer=infer,
                      )
                  except Exception as e:
                      logging.warning(str(e))
                      logging.warning(line)
                      continue
                  if example is None:
                      logging.info("cannot create example: ")
                      logging.info(line)
                      continue
                  examples.append(example)
      logging.info(f"Done. {len(examples)} examples converted.")
      if infer:
          return examples, hyps_refs
      return examples
  
file_path: NeMo/nemo/collections/nlp/data/spellchecking_asr_customization/bert_example.py
imports: import logging
  from collections import OrderedDict
  from os import path
  from typing import Dict, List, Optional, Tuple, Union
  from transformers import PreTrainedTokenizerBase
label_desc: Use image node_id 9 for calling the BertExampleBuilder obj's underlying member method code with example usage: obj.read_input_file(input_filename, infer) and returns: examples, examples,  hyps_refs