class_docstr: Holds data from the transformers BatchEncoding class.
  
  We would have preferred to use the BatchEncoding class directly, but
  there's a few problems with that.
  
  1. Some BatchEncoding functionality requires the tokenizers.Encoding object,
      and it's impossible for us to create or manipulate that object. This means
      we can't really create BatchEncoding objects, which limits what we can do.
  2. We want some semantic differences, for instance the "lengths" data in the
      BatchEncoding is useless when the inputs are padded. We want it to tell
      us the *unpadded* lengths.
  3. We want typed attributes, so that we can type-check properly.
  4. We prefer to have numpy/cupy arrays rather than torch arrays.
  5. The API around the BatchEncoding object has been changing a lot, so we
      want to minimize the places where we touch it.
code: def from_batch_encoding(
      cls, token_data: BatchEncoding
  ) -> "WordpieceBatch":
      assert isinstance(token_data, BatchEncoding) or isinstance(
          token_data, dict
      )
      pad_token = token_data.get("pad_token", "[PAD]")
      lengths = [
          len([tok for tok in tokens if tok != pad_token])
          for tokens in token_data["input_texts"]
      ]
  
      # The following tensors are intentionally allocated on the CPU to reduce
      # host-to-device copies.
      numpy_ops = NumpyOps()
      input_ids = token_data["input_ids"]
      token_type_ids = token_data.get("token_type_ids")
  
      return cls(
          strings=token_data["input_texts"],
          input_ids=numpy_ops.asarray(input_ids, dtype=input_ids.dtype),
          attention_mask=numpy_ops.asarray2f(
              token_data["attention_mask"]
          ),
          lengths=lengths,
          token_type_ids=(
              numpy_ops.asarray(
                  token_type_ids, dtype=token_type_ids.dtype
              )
              if token_type_ids is not None
              else None
          ),
      )
  
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 WordpieceBatch obj's underlying member method code with example usage: obj.from_batch_encoding(cls, token_data) and returns: cls