code: def collect_files(ud_path, languages, data_format="ud"):
      """
      Given path to UD, collect files
      If data_format = "ud", expects files to be of form *.conllu
      If data_format = "one-per-line", expects files to be of form "*.sentences.txt"
      In all cases, the UD path should be a directory with subdirectories for each language
      """
      data_format_to_search_path = {
          "ud": "*/*.conllu",
          "one-per-line": "*/*sentences.txt",
      }
      ud_files = Path(ud_path).glob(
          data_format_to_search_path[data_format]
      )
      lang_to_files = {}
      for ud_file in ud_files:
          if data_format == "ud":
              lang_id = treebank_to_langid(ud_file.parent.name)
          else:
              lang_id = ud_file.name.split("_")[0]
          if lang_id not in languages and "all" not in languages:
              continue
          if not lang_id in lang_to_files:
              lang_to_files[lang_id] = []
          lang_to_files[lang_id].append(ud_file)
      return lang_to_files
  
imports: import argparse
  import json
  import logging
  import os
  import re
  import sys
  from pathlib import Path
  from random import randint, random, shuffle
  from string import digits
  from tqdm import tqdm
  from stanza.models.common.constant import treebank_to_langid
label_desc: Use image node_id 4 for calling a global function with example usage: collect_files(ud_path, languages, data_format) and returns: lang_to_files