docstr: Cleans up predictions, applying deduplication and optionally splitting on cell boundaries.
  
  Args:
      predictions (DocumentSpans): Resolved model predictions.
      tables (DocumentTables): document tables
      doc_text (str): the text of the document.
  
  Returns:
      DocumentSpans: clean predictions
docstr_tok: ["Cleans","up","predictions",",","applying","deduplication","and","optionally","splitting","on","cell","boundaries",".","Args",":","predictions","(","DocumentSpans",")",":","Resolved","model","predictions",".","tables","(","DocumentTables",")",":","document","tables","doc_text","(","str",")",":","the","text","of","the","document",".","Returns",":","DocumentSpans",":","clean","predictions"]
code: def cleanup_predictions(
      self,
      predictions: DocumentSpans,
      tables: DocumentTables,
      doc_text: str,
  ):
      """Cleans up predictions, applying deduplication and optionally splitting on cell boundaries.
  
      Args:
          predictions (DocumentSpans): Resolved model predictions.
          tables (DocumentTables): document tables
          doc_text (str): the text of the document.
  
      Returns:
          DocumentSpans: clean predictions
      """
      if self.split_preds_to_cells:
          cell_bounded_predictions = []
          for pred in predictions:
              cell_bounds = []
              for page_tables in tables:
                  for table in page_tables:
                      if not any(
                          sequences_overlap(do, pred)
                          for do in table["doc_offsets"]
                      ):
                          # Optimization
                          continue
                      for cell in table["cells"]:
                          for do in cell["doc_offsets"]:
                              if sequences_overlap(do, pred):
                                  cell_bounds.append(do)
              for do in cell_bounds:
                  cell_bounded_predictions.append({**pred, **do})
              # Remove any spans that overlap the cells.
              cell_bounded_predictions += self.subtract_spans(
                  pred, cell_bounds
              )
          predictions = cell_bounded_predictions
  
      # Deduplicate / resolve overlap - Primarily comes from chunking.
      deduplicated_preds = []
      # Sorting from most confident to least confident so that we prioritise the most confident.
      for pred in sorted(
          predictions, key=lambda x: -(x["confidence"][x["label"]])
      ):
          # After subtract spans the text and bounds can disagree.
          pred["text"] = doc_text[pred["start"] : pred["end"]]
          # And we can also get whitespace only predictions from the bits between cells.
          if pred["text"].strip() == "":
              continue
          if not any(
              sequences_overlap(pred, ddp) for ddp in deduplicated_preds
          ):
              deduplicated_preds.append(pred)
      return sorted(deduplicated_preds, key=lambda x: x["start"])
  
imports: import copy
  import functools
  import os
  import tempfile
  import typing
  import sys
  from finetune.base_models import TableRoBERTa
  from finetune.util.metrics import sequences_overlap
  from finetune.scheduler import Scheduler
  from finetune.encoding.input_encoder import BaseEncoder
  from finetune import SequenceLabeler
label_desc: Use image node_id 9 for calling the TableETL obj's underlying member method code with example usage: obj.cleanup_predictions(predictions, tables, doc_text) and returns: sorted