docstr: get_spans (Callable[[List[Doc]], List[Span]]):
      A function to extract spans from the batch of Doc objects.
      This is used to manage long documents, by cutting them into smaller
      sequences before running the transformer. The spans are allowed to
      overlap, and you can also omit sections of the Doc if they are not
      relevant.
  tokenizer_config (dict): Settings to pass to the transformers tokenizer.
  transformer_config (dict): Settings to pass to the transformers forward pass.
docstr_tok: ["get_spans","(","Callable","[","[","List","[","Doc","]","]",",","List","[","Span","]","]",")",":","A","function","to","extract","spans","from","the","batch","of","Doc","objects",".","This","is","used","to","manage","long","documents",",","by","cutting","them","into","smaller","sequences","before","running","the","transformer",".","The","spans","are","allowed","to","overlap",",","and","you","can","also","omit","sections","of","the","Doc","if","they","are","not","relevant",".","tokenizer_config","(","dict",")",":","Settings","to","pass","to","the","transformers","tokenizer",".","transformer_config","(","dict",")",":","Settings","to","pass","to","the","transformers","forward","pass","."]
code: def __init__(
      self,
      name: str,
      get_spans: Callable,
      tokenizer_config: dict = {},
      transformer_config: dict = {},
      mixed_precision: bool = False,
      grad_scaler_config: dict = {},
  ):
      """
      get_spans (Callable[[List[Doc]], List[Span]]):
          A function to extract spans from the batch of Doc objects.
          This is used to manage long documents, by cutting them into smaller
          sequences before running the transformer. The spans are allowed to
          overlap, and you can also omit sections of the Doc if they are not
          relevant.
      tokenizer_config (dict): Settings to pass to the transformers tokenizer.
      transformer_config (dict): Settings to pass to the transformers forward pass.
      """
      hf_model = HFObjects(
          None, None, None, tokenizer_config, transformer_config
      )
      wrapper = HFWrapper(
          hf_model,
          convert_inputs=_convert_transformer_inputs,
          convert_outputs=_convert_transformer_outputs,
          mixed_precision=mixed_precision,
          grad_scaler_config=grad_scaler_config,
      )
      super().__init__(
          "transformer",
          forward,
          init=init,
          layers=[wrapper],
          dims={"nO": None},
          attrs={
              "get_spans": get_spans,
              "name": name,
              "set_transformer": set_pytorch_transformer,
              "has_transformer": False,
              "flush_cache_chance": 0.0,
              "replace_listener": replace_listener,
              "replace_listener_cfg": replace_listener_cfg,
          },
      )
  
imports: from typing import List, Tuple, Callable, Union, Dict
  import copy
  from pathlib import Path
  from transformers.file_utils import ModelOutput
  from transformers import AutoConfig, AutoModel, AutoTokenizer
  from transformers.tokenization_utils_fast import PreTrainedTokenizerFast
  from transformers.tokenization_utils import BatchEncoding
  from spacy.tokens import Doc
  from thinc.api import Model, get_torch_default_device, xp2torch
  from thinc.types import ArgsKwargs
  import logging
  from ..data_classes import FullTransformerBatch, WordpieceBatch, HFObjects
  from ..util import maybe_flush_pytorch_cache
  from ..util import log_gpu_memory, log_batch_size
  from ..layers._util import replace_listener, replace_listener_cfg
  from ..truncate import truncate_oversize_splits
  from ..align import get_alignment, get_alignment_via_offset_mapping
  from .hf_wrapper import HFWrapper
label_desc: Use image node_id 1 to create a new TransformerModel object from inherited base classes: Model with example: obj = TransformerModel(name, get_spans, tokenizer_config, transformer_config, mixed_precision, grad_scaler_config)