class_docstr: Builder class for BertExample objects.
class_docstr_tok: ["Builder","class","for","BertExample","objects","."]
docstr: Constructs a BERT Example.
  
  Args:
      source: Source text.
      target: Target text or None when building an example during inference.
      semiotic_info: String or None
      infer: inference mode
  Returns:
      BertExample, or None if the conversion from text to tags was infeasible
docstr_tok: ["Constructs","a","BERT","Example",".","Args",":","source",":","Source","text",".","target",":","Target","text","or","None","when","building","an","example","during","inference",".","semiotic_info",":","String","or","None","infer",":","inference","mode","Returns",":","BertExample",",","or","None","if","the","conversion","from","text","to","tags","was","infeasible"]
code: def build_bert_example(
      self,
      source: str,
      target: Optional[str] = None,
      semiotic_info: Optional[str] = None,
      infer: bool = False,
  ) -> Optional[BertExample]:
      """Constructs a BERT Example.
  
      Args:
          source: Source text.
          target: Target text or None when building an example during inference.
          semiotic_info: String or None
          infer: inference mode
      Returns:
          BertExample, or None if the conversion from text to tags was infeasible
      """
      # Compute target labels.
      task = EditingTask(source)
      if (target is not None) and (not infer):
          tags = BertExampleBuilder._compute_tags(task, target)
          if not tags:
              return None
      else:
          # If target is not provided, we set all target labels to KEEP.
          tags = [Tag("KEEP") for _ in task.source_tokens]
      source_tags = [self._label_map[str(tag)] for tag in tags]
      (
          tokens,
          tag_labels,
          token_start_indices,
      ) = self._split_to_wordpieces(task.source_tokens, source_tags)
  
      tokens = self._truncate_list(tokens)
      tag_labels = self._truncate_list(tag_labels)
  
      input_tokens = ["[CLS]"] + tokens + ["[SEP]"]
      labels_mask = [0] + [1] * len(tag_labels) + [0]
      tag_labels = [0] + tag_labels + [0]
  
      if "PLAIN" not in self._semiotic_classes:
          raise KeyError("PLAIN should be in self._semiotic_classes")
      plain_cid = self._semiotic_classes["PLAIN"]
      semiotic_labels = [plain_cid] * len(
          tag_labels
      )  # we use the same mask for semiotic labels as for tag labels
  
      input_ids = self._tokenizer.convert_tokens_to_ids(input_tokens)
      input_mask = [1] * len(input_ids)
      segment_ids = [0] * len(input_ids)
  
      semiotic_spans = []
  
      if semiotic_info is not None:
          # e.g. semiotic_info="CARDINAL 7 8;DATE 9 12"
          # translate class name to its id, translate coords from tokens to wordpieces
          semiotic_info_parts = semiotic_info.split(";")
          previous_end = 0
          for p in semiotic_info_parts:
              if p == "":
                  break
              c, start, end = p.split(" ")
              if c not in self._semiotic_classes:
                  raise KeyError(
                      "c=" + c + " not found in self._semiotic_classes"
                  )
              cid = self._semiotic_classes[c]
              start = int(start)
              end = int(end)
              if start >= len(token_start_indices):
                  raise IndexError(
                      "start="
                      + str(start)
                      + " is outside len(token_start_indices)="
                      + str(len(token_start_indices))
                  )
              while previous_end < start:
                  subtoken_start = token_start_indices[previous_end]
                  subtoken_end = (
                      token_start_indices[previous_end + 1]
                      if previous_end + 1 < len(token_start_indices)
                      else len(input_ids) - 1
                  )
                  semiotic_spans.append(
                      (plain_cid, subtoken_start, subtoken_end)
                  )
                  previous_end += 1
              subtoken_start = token_start_indices[start]
              subtoken_end = (
                  token_start_indices[end]
                  if end < len(token_start_indices)
                  else len(input_ids) - 1
              )
              if (
                  subtoken_end >= self._max_seq_length
              ):  # possible if input_ids gets truncated to the max_seq_length
                  break
              semiotic_spans.append((cid, subtoken_start, subtoken_end))
              semiotic_labels[subtoken_start:subtoken_end] = [cid] * (
                  subtoken_end - subtoken_start
              )
              previous_end = end
          while previous_end < len(token_start_indices):
              subtoken_start = token_start_indices[previous_end]
              subtoken_end = (
                  token_start_indices[previous_end + 1]
                  if previous_end + 1 < len(token_start_indices)
                  else len(input_ids) - 1
              )
              semiotic_spans.append(
                  (plain_cid, subtoken_start, subtoken_end)
              )
              previous_end += 1
      if (
          len(input_ids) > self._max_seq_length
          or len(semiotic_spans) > self._max_semiotic_length
      ):
          return None
      example = BertExample(
          input_ids=input_ids,
          input_mask=input_mask,
          segment_ids=segment_ids,
          labels_mask=labels_mask,
          tag_labels=tag_labels,
          semiotic_labels=semiotic_labels,
          semiotic_spans=semiotic_spans,
          token_start_indices=token_start_indices,
          task=task,
          default_label=self._keep_tag_id,
      )
      example.pad_to_max_length(
          self._max_seq_length, self._max_semiotic_length, self._pad_id
      )
      return example
  
imports: import logging
  from collections import OrderedDict
  from os import path
  from typing import Dict, List, Optional, Tuple, Union
  from transformers import PreTrainedTokenizerBase
  from nemo.collections.nlp.data.text_normalization_as_tagging.tagging import EditingTask, Tag
  from nemo.collections.nlp.data.text_normalization_as_tagging.utils import yield_sources_and_targets
label_desc: Use image node_id 2 for calling the BertExampleBuilder obj's underlying member method code with example usage: obj.build_bert_example(source, target, semiotic_info, infer) and returns: example, None, None