code: def retag_trees(trees, pipelines, xpos=True):
      """
      Retag all of the trees using the given processor
  
      Returns a list of new trees
      """
      if len(trees) == 0:
          return trees
  
      new_trees = []
      chunk_size = 1000
      with tqdm(total=len(trees)) as pbar:
          for chunk_start in range(0, len(trees), chunk_size):
              chunk_end = min(chunk_start + chunk_size, len(trees))
              chunk = trees[chunk_start:chunk_end]
              sentences = []
              try:
                  for idx, tree in enumerate(chunk):
                      tokens = [
                          {TEXT: pt.children[0].label}
                          for pt in tree.yield_preterminals()
                      ]
                      sentences.append(tokens)
              except ValueError as e:
                  raise ValueError(
                      "Unable to process tree %d" % (idx + chunk_start)
                  ) from e
  
              doc = Document(sentences)
              tag_lists = retag_tags(doc, pipelines, xpos)
  
              for tree_idx, (tree, tags) in enumerate(
                  zip(chunk, tag_lists)
              ):
                  try:
                      new_tree = replace_tags(tree, tags)
                      new_trees.append(new_tree)
                      pbar.update(1)
                  except ValueError as e:
                      raise ValueError(
                          "Failed to properly retag tree #{}: {}".format(
                              tree_idx, tree
                          )
                      ) from e
      if len(new_trees) != len(trees):
          raise AssertionError(
              "Retagged tree counts did not match: {} vs {}".format(
                  len(new_trees), len(trees)
              )
          )
      return new_trees
  
file_path: stanza/stanza/models/constituency/utils.py
imports: from collections import Counter, deque
  import copy
  import logging
  import torch.nn
  from torch import optim
  from stanza.models.common.doc import TEXT, Document
  from stanza.utils.get_tqdm import get_tqdm
label_desc: Use image node_id 3 for calling a global function with example usage: retag_trees(trees, pipelines, xpos) and returns: new_trees, trees