code: def find_matching_trees(
      docs,
      num_sentences,
      accepted_trees,
      tag_pipe,
      parser_pipes,
      shuffle=True,
      chunk_size=10,
      max_len=140,
      min_len=10,
      output_ptb=False,
  ):
      """
      Find trees where all the parsers in parser_pipes agree
  
      docs should be a list of strings.
        one sentence per string or a whole block of text as long as the tag_pipe can break it into sentences
  
      num_sentences > 0 gives an upper limit on how many sentences to extract.
        If < 0, all possible sentences are extracted
  
      accepted_trees is a running tally of all the trees already built,
        so that we don't reuse the same sentence if we see it again
      """
      if num_sentences < 0:
          tqdm_total = len(docs)
      else:
          tqdm_total = num_sentences
  
      if output_ptb:
          output_format = "{}"
      else:
          output_format = "{:L}"
  
      with tqdm(total=tqdm_total, leave=False) as pbar:
          if shuffle:
              random.shuffle(docs)
          new_trees = set()
          for chunk_start in range(0, len(docs), chunk_size):
              chunk = docs[chunk_start : chunk_start + chunk_size]
              chunk = [stanza.Document([], text=t) for t in chunk]
  
              if num_sentences < 0:
                  pbar.update(len(chunk))
  
              # first, retag the sentences
              tag_pipe(chunk)
  
              chunk = [d for d in chunk if len(d.sentences) > 0]
              if max_len is not None:
                  # for now, we don't have a good way to deal with sentences longer than the bert maxlen
                  chunk = [
                      d
                      for d in chunk
                      if max(len(s.words) for s in d.sentences)
                      < max_len
                  ]
              if len(chunk) == 0:
                  continue
  
              parses = []
              try:
                  for pipe in parser_pipes:
                      pipe(chunk)
                      trees = [
                          output_format.format(sent.constituency)
                          for doc in chunk
                          for sent in doc.sentences
                          if len(sent.words) >= min_len
                      ]
                      parses.append(trees)
              except TextTooLongError as e:
                  # easiest is to skip this chunk - could theoretically save the other sentences
                  continue
  
              for tree in zip(*parses):
                  if len(set(tree)) != 1:
                      continue
                  tree = tree[0]
                  if tree in accepted_trees:
                      continue
                  if tree not in new_trees:
                      new_trees.add(tree)
                      if num_sentences >= 0:
                          pbar.update(1)
                  if (
                      num_sentences >= 0
                      and len(new_trees) >= num_sentences
                  ):
                      return new_trees
  
      return new_trees
  
file_path: stanza/stanza/utils/datasets/constituency/selftrain.py
imports: import logging
  import os
  import random
  import re
  import stanza
  from stanza.models.common import utils
  from stanza.models.common.bert_embedding import TextTooLongError
  from stanza.utils.get_tqdm import get_tqdm
label_desc: Use image node_id 8 for calling a global function with example usage: find_matching_trees(docs, num_sentences, accepted_trees, tag_pipe, parser_pipes, shuffle, chunk_size, max_len, min_len, output_ptb) and returns: new_trees, new_trees