code: def parse_xml(tree):
      # we will put each paragraph in a separate block in the output file
      # we won't pay any attention to the document boundaries unless we
      # later find out it was necessary
      # a paragraph will be a list of sentences
      # a sentence is a list of words, where each word is a string
      documents = []
  
      root = tree.getroot()
      for document in root:
          # these should all be documents
          if document.tag != "document":
              raise ValueError(
                  "Unexpected orchid xml layout: {}".format(
                      document.tag
                  )
              )
          paragraphs = []
          for paragraph in document:
              if paragraph.tag != "paragraph":
                  raise ValueError(
                      "Unexpected orchid xml layout: {} under {}".format(
                          paragraph.tag, document.tag
                      )
                  )
              sentences = []
              for sentence in paragraph:
                  if sentence.tag != "sentence":
                      raise ValueError(
                          "Unexpected orchid xml layout: {} under {}".format(
                              sentence.tag, document.tag
                          )
                      )
                  if sentence.attrib["line_num"] in skipped_lines:
                      continue
                  words = []
                  for word_idx, word in enumerate(sentence):
                      if word.tag != "word":
                          raise ValueError(
                              "Unexpected orchid xml layout: {} under {}".format(
                                  word.tag, sentence.tag
                              )
                          )
                      word = word.attrib["surface"]
                      word = escape_sequences.get(word, word)
                      if word == "<space>":
                          if word_idx == 0:
                              raise ValueError(
                                  "Space character was the first token in a sentence: {}".format(
                                      sentence.attrib["line_num"]
                                  )
                              )
                          else:
                              words[-1] = (words[-1][0], True)
                              continue
                      if (
                          len(word) > 1
                          and word[0] == "<"
                          and word not in allowed_sequences
                      ):
                          raise ValueError(
                              "Unknown escape sequence {}".format(word)
                          )
                      words.append((word, False))
                  if len(words) == 0:
                      continue
                  words[-1] = (words[-1][0], True)
                  sentences.append(words)
              paragraphs.append(sentences)
          documents.append(paragraphs)
  
      return documents
  
imports: import os
  import random
  import sys
  import xml.etree.ElementTree
  from stanza.utils.datasets.tokenization.process_thai_tokenization import write_dataset
label_desc: Use image node_id 2 for calling a global function with example usage: parse_xml(tree) and returns: documents