class_docstr: Holds a batch of input and output objects for a transformer model. The
  data can then be split to a list of `TransformerData` objects to associate
  the outputs to each `Doc` in the batch.
  
  Attributes
  ----------
  spans (List[List[Span]]): The batch of input spans. The outer list refers
      to the Doc objects in the batch, and the inner list are the spans for
      that `Doc`. Note that spans are allowed to overlap or exclude tokens,
      but each Span can only refer to one Doc (by definition). This means that
      within a Doc, the regions of the output tensors that correspond to each
      Span may overlap or have gaps, but for each Doc, there is a non-overlapping
      contiguous slice of the outputs.
  wordpieces (WordpieceBatch): Token data from the Huggingface tokenizer.
  model_output (ModelOutput): The output of the transformer model.
  align (Ragged): Alignment from the spaCy tokenization to the wordpieces.
      This is a ragged array, where align.lengths[i] indicates the number of
      wordpiece tokens that token i aligns against. The actual indices are
      provided at align[i].dataXd.
docstr: Split a TransformerData that represents a batch into a list with
  one TransformerData per Doc.
docstr_tok: ["Split","a","TransformerData","that","represents","a","batch","into","a","list","with","one","TransformerData","per","Doc","."]
code: def split_by_doc(self) -> List[TransformerData]:
      """Split a TransformerData that represents a batch into a list with
      one TransformerData per Doc.
      """
      flat_spans = []
      for doc_spans in self.spans:
          flat_spans.extend(doc_spans)
      token_positions = get_token_positions(flat_spans)
  
      # Convert all outputs to XP arrays.
      xp_model_output = ModelOutput()
      last_hidden_state = cast(
          BaseModelOutput, self.model_output
      ).last_hidden_state
      for key, output in self.model_output.items():
          if isinstance(output, torch.Tensor):
              xp_model_output[key] = torch2xp(output)
          elif (
              isinstance(output, tuple)
              and all(isinstance(t, torch.Tensor) for t in output)
              and all(
                  t.shape[0] == last_hidden_state.shape[0]
                  for t in output
              )
          ):
              xp_model_output[key] = [torch2xp(t) for t in output]
  
      # Split outputs per Doc.
      outputs = []
      start = 0
      prev_tokens = 0
      for doc_spans in self.spans:
          if len(doc_spans) == 0 or len(doc_spans[0]) == 0:
              outputs.append(TransformerData.empty())
              continue
          start_i = token_positions[doc_spans[0][0]]
          end_i = token_positions[doc_spans[-1][-1]] + 1
          end = start + len(doc_spans)
          doc_tokens = self.wordpieces[start:end]
          doc_align = self.align[start_i:end_i]
          doc_align.data = doc_align.data - prev_tokens
          model_output = ModelOutput()
          for key, output in xp_model_output.items():
              # After the torch2xp conversion above, we only have XP arrays
              # and lists of XP arrays.
              if not isinstance(output, list):
                  model_output[key] = output[start:end]
              else:
                  model_output[key] = [t[start:end] for t in output]
          outputs.append(
              TransformerData(
                  wordpieces=doc_tokens,
                  model_output=model_output,
                  align=doc_align,
              )
          )
          prev_tokens += doc_tokens.input_ids.size
          start += len(doc_spans)
      return outputs
  
imports: from typing import Optional, List, Dict, Any, Union, Tuple, cast
  from dataclasses import dataclass, field
  import torch
  import numpy
  from transformers.tokenization_utils import BatchEncoding
  from transformers.file_utils import ModelOutput
  from transformers.modeling_outputs import BaseModelOutput
  from thinc.types import Ragged, Floats2d, Floats3d, FloatsXd, Ints1d, Ints2d
  from thinc.api import NumpyOps, get_array_module, xp2torch, torch2xp
  from spacy.tokens import Span
  import srsly
  from .util import transpose_list
  from .align import get_token_positions
label_desc: Use image node_id 6 for calling the FullTransformerBatch obj's underlying member method code with example usage: obj.split_by_doc() and returns: outputs