class_docstr: Labels each token in a sequence as belonging to 1 of N token classes.
  
  :param config: A :py:class:`finetune.config.Settings` object or None (for default config).
  :param \**kwargs: key-value pairs of config items to override.
class_docstr_tok: ["Labels","each","token","in","a","sequence","as","belonging","to","1","of","N","token","classes",".",":","param","config",":","A",":","py",":","class",":","`","finetune.config.Settings","`","object","or","None","(","for","default","config",")",".",":","param","\\","*","*","kwargs",":","key-value","pairs","of","config","items","to","override","."]
docstr: If self.config.max_document_chars is set, text for long documents is split
  into multiple "sub documents". Given model predictions, and the indices
  specifying which documents have been split, join the labels for previously
  split documents together.
  preds is a list, where each element of the list corresponds to a document.
  In most cases, this will be a List[List[Dict]], where we have a List[Dict]
  for each document, which is a list of predictions.
  However, if return_negative_confidence is True, we instead have a Dict for
  each document, which contains the keys "negative_confidence" and "prediction"
  Args:
      preds: Model predictions
      split_indices: Indices specifying how documents were split
      return_negative_confidence: If True, expect preds to be List[Dict]
          instead List[List[Dict]]
  Returns:
      merged_preds: Model predictions after merging documents together
docstr_tok: ["If","self.config.max_document_chars","is","set",",","text","for","long","documents","is","split","into","multiple","``","sub","documents","''",".","Given","model","predictions",",","and","the","indices","specifying","which","documents","have","been","split",",","join","the","labels","for","previously","split","documents","together",".","preds","is","a","list",",","where","each","element","of","the","list","corresponds","to","a","document",".","In","most","cases",",","this","will","be","a","List","[","List","[","Dict","]","]",",","where","we","have","a","List","[","Dict","]","for","each","document",",","which","is","a","list","of","predictions",".","However",",","if","return_negative_confidence","is","True",",","we","instead","have","a","Dict","for","each","document",",","which","contains","the","keys","``","negative_confidence","''","and","``","prediction","''","Args",":","preds",":","Model","predictions","split_indices",":","Indices","specifying","how","documents","were","split","return_negative_confidence",":","If","True",",","expect","preds","to","be","List","[","Dict","]","instead","List","[","List","[","Dict","]","]","Returns",":","merged_preds",":","Model","predictions","after","merging","documents","together"]
code: def _merge_chunked_preds(
      self,
      preds: Union[List[List[Dict]], List[Dict]],
      split_indices: List[List[int]],
      return_negative_confidence: bool = False,
  ) -> List[List[Dict]]:
      """
      If self.config.max_document_chars is set, text for long documents is split
      into multiple "sub documents". Given model predictions, and the indices
      specifying which documents have been split, join the labels for previously
      split documents together.
      preds is a list, where each element of the list corresponds to a document.
      In most cases, this will be a List[List[Dict]], where we have a List[Dict]
      for each document, which is a list of predictions.
      However, if return_negative_confidence is True, we instead have a Dict for
      each document, which contains the keys "negative_confidence" and "prediction"
      Args:
          preds: Model predictions
          split_indices: Indices specifying how documents were split
          return_negative_confidence: If True, expect preds to be List[Dict]
              instead List[List[Dict]]
      Returns:
          merged_preds: Model predictions after merging documents together
      """
      merged_preds = []
      for pred_idxs in split_indices:
          if len(pred_idxs) == 1:
              merged_preds.append(preds[pred_idxs[0]])
          # len(pred_idxs) > 1 indicates that a document was split into multiple
          # "sub documents", for which the labels need to be merged
          elif return_negative_confidence:
              doc_preds = {"prediction": []}
              all_doc_neg_confs = defaultdict(list)
              for chunk_idx, pred_idx in enumerate(pred_idxs):
                  offset = chunk_idx * self.config.max_document_chars
                  chunk_preds = preds[pred_idx]["prediction"]
                  # Add offset to label start/ends so that they index correctly
                  # into the text after joining across pre chunks
                  for i in range(len(chunk_preds)):
                      chunk_preds[i]["start"] += offset
                      chunk_preds[i]["end"] += offset
                  doc_preds["prediction"].extend(chunk_preds)
                  # Create list of negative confidences for each key, to later take the max of
                  for key, val in preds[pred_idx][
                      "negative_confidence"
                  ].items():
                      all_doc_neg_confs[key].append(val)
              # Get max of negative conf values for each key
              doc_preds["negative_confidence"] = {
                  key: np.max(vals)
                  for key, vals in all_doc_neg_confs.items()
              }
              merged_preds.append(doc_preds)
          else:
              doc_preds = []
              for chunk_idx, pred_idx in enumerate(pred_idxs):
                  offset = chunk_idx * self.config.max_document_chars
                  chunk_preds = preds[pred_idx]
                  # Add offset to label start/ends so that they index correctly
                  # into the text after joining across pre chunks
                  for i in range(len(chunk_preds)):
                      chunk_preds[i]["start"] += offset
                      chunk_preds[i]["end"] += offset
                  doc_preds.extend(chunk_preds)
              merged_preds.append(doc_preds)
  
      return merged_preds
  
imports: import copy
  import os
  from collections import Counter, defaultdict
  import math
  from typing import Dict, List, Tuple, Union
  import tensorflow
  import numpy
  from finetune.base import BaseModel
  from finetune.encoding.target_encoders import SequenceLabelingEncoder, SequenceMultiLabelingEncoder
  from finetune.nn.target_blocks import sequence_labeler
  from finetune.nn.crf import sequence_decode
  from finetune.encoding.sequence_encoder import finetune_to_indico_sequence
  from finetune.encoding.input_encoder import get_spacy
  from finetune.input_pipeline import BasePipeline
  from finetune.util.metrics import sequences_overlap
  from finetune.encoding.input_encoder import tokenize_context
label_desc: Use image node_id 6 for calling the SequenceLabeler obj's underlying member method code with example usage: obj._merge_chunked_preds(preds, split_indices, return_negative_confidence) and returns: merged_preds