code: def reassemble_doc_from_tokens(tokens, mwts, expansions, raw_text):
      """Assemble a Stanza document list format from a list of string tokens, calculating offsets as needed.
  
      Parameters
      ----------
      tokens : List[List[str]]
          A list of sentences, which includes string tokens.
      mwts : List[List[bool]]
          Whether or not each of the tokens are MWTs to be analyzed by the MWT system.
      expansions : List[List[Optional[List[str]]]]
          A list of possible expansions for MWTs, or None if no user-defined expansion
          is given.
      parser_text : str
          The raw text off of which we can compare offsets.
  
      Returns
      -------
      List[List[Dict]]
          List of words and their offsets, used as `doc`.
      """
  
      # oov count and offset stays the same; doc gets regenerated
      new_offset = 0
      corrected_doc = []
  
      for sent_words, sent_mwts, sent_expansions in zip(
          tokens, mwts, expansions
      ):
          sentence_doc = []
  
          for indx, (word, mwt, expansion) in enumerate(
              zip(sent_words, sent_mwts, sent_expansions)
          ):
              try:
                  offset_index = raw_text.index(word)
              except ValueError as e:
                  sub_start = max(0, new_offset - 20)
                  sub_end = min(len(raw_text), new_offset + 20)
                  sub = raw_text[sub_start:sub_end]
                  raise ValueError(
                      "Could not find word |%s| starting from char_offset %d.  Surrounding text: |%s|. \n Hint: did you accidentally add/subtract a symbol/character such as a space when combining tokens?"
                      % (word, new_offset, sub)
                  ) from e
  
              wd = {
                  "id": (indx + 1,),
                  "text": word,
                  "start_char": new_offset + offset_index,
                  "end_char": new_offset + offset_index + len(word),
              }
              if expansion:
                  wd["manual_expansion"] = True
              elif mwt:
                  wd["misc"] = "MWT=Yes"
  
              sentence_doc.append(wd)
  
              # we crop the raw_text variable to prevent .index() from double-indexing an
              # earlier token. essentially, for each word, we are only interested in its *offset*
              # from the start of string
              raw_text = raw_text[offset_index + len(word) :]
              new_offset += offset_index + len(word)
  
          corrected_doc.append(sentence_doc)
  
      # use the built in MWT system to expand MWTs
      doc = Document(corrected_doc, raw_text)
      doc.set_mwt_expansions(
          [j for i in expansions for j in i if j],
          process_manual_expanded=True,
      )
      return doc.to_dict()
  
imports: from collections import Counter
  from copy import copy
  import json
  import numpy
  import re
  import logging
  import os
  from torch.utils.data import DataLoader
  import stanza.utils.default_paths
  from stanza.models.common.utils import ud_scores, harmonic_mean
  from stanza.models.common.doc import Document
  from stanza.utils.conll import CoNLL
  from stanza.models.common.doc import *
  from stanza.models.tokenization.data import SortedDataset
label_desc: Use image node_id 11 for calling a global function with example usage: reassemble_doc_from_tokens(tokens, mwts, expansions, raw_text) and returns: doc