code: def _decode_bio(
      text: str,
      tokens: List[str],
      mask: List[int],
      labels: List[str],
  ) -> Doc:
      """Create `Doc` from transformers output. Only support BIO label scheme."""
      assert len(labels) == len(tokens)
      doc = Doc(text)
  
      # get Ent
      ents: List[Ent] = []
      cur_ent: Optional[Ent] = None
      tokens = _norm_tokens(tokens, mask)
      for span_lists, label in zip(
          textspan.get_original_spans(tokens, text), labels
      ):
          if not span_lists:
              # special tokens should hit here
              continue
          l = span_lists[0][0]
          r = span_lists[-1][1]
          if (
              label.startswith("I-")
              and cur_ent
              and cur_ent.label == label[2:]
          ):
              # expand previous entity
              cur_ent.end_char = r
          elif label.startswith("I-") or label.startswith("B-"):
              # new entity
              if cur_ent:
                  ents.append(cur_ent)
              cur_ent = Ent(l, r, doc, label=label[2:])
      if cur_ent:
          ents.append(cur_ent)
      doc.ents = ents
      return doc
  
imports: from dataclasses import asdict, dataclass
  from pathlib import Path
  from typing import Any, ClassVar, Dict, List, Optional, Tuple
  import textspan
  import torch
  from camphr.doc import Doc, Ent
  from camphr.nlp import Nlp
  from camphr.serde import SerDe, SerDeDataclassMixin
  from transformers import AutoModelForTokenClassification, AutoTokenizer
  from typing_extensions import TypedDict
label_desc: Use image node_id 2 for calling a global function with example usage: _decode_bio(text, tokens, mask, labels) and returns: doc