code: def download_udpos_data_and_write_config(
      task_data_base_path: str, task_config_base_path: str
  ):
      # UDPOS requires networkx==1.11
  
      def _read_one_file(file):
          # Adapted from https://github.com/JunjieHu/xtreme/blob/
          #              9fe0b142d0ee3eb7dd047ab86f12a76702e79bb4/utils_preprocess.py
          data = []
          sent, tag, lines = [], [], []
          for line in open(file, "r"):
              items = line.strip().split("\t")
              if len(items) != 10:
                  num_empty = sum([int(w == "_") for w in sent])
                  if num_empty == 0 or num_empty < len(sent) - 1:
                      data.append((sent, tag, lines))
                  sent, tag, lines = [], [], []
              else:
                  sent.append(items[1].strip())
                  tag.append(items[3].strip())
                  lines.append(line.strip())
                  assert len(sent) == int(
                      items[0]
                  ), "line={}, sent={}, tag={}".format(line, sent, tag)
          return data
  
      def _remove_empty_space(data):
          # Adapted from https://github.com/google-research/xtreme/blob/
          #              522434d1aece34131d997a97ce7e9242a51a688a/utils_preprocess.py#L212
          new_data = {}
          for split in data:
              new_data[split] = []
              for sent, tag, lines in data[split]:
                  new_sent = [
                      "".join(w.replace("\u200c", "").split(" "))
                      for w in sent
                  ]
                  lines = [line.replace("\u200c", "") for line in lines]
                  assert len(" ".join(new_sent).split(" ")) == len(tag)
                  new_data[split].append((new_sent, tag, lines))
          return new_data
  
      def check_file(file):
          # Adapted from https://github.com/google-research/xtreme/blob/
          #              522434d1aece34131d997a97ce7e9242a51a688a/utils_preprocess.py#L223
          for i, l in enumerate(open(file)):
              items = l.strip().split("\t")
              assert len(items[0].split(" ")) == len(
                  items[1].split(" ")
              ), "idx={}, line={}".format(i, l)
  
      def _write_files(data, output_dir, lang_, suffix):
          # Adapted from https://github.com/google-research/xtreme/blob/
          #              522434d1aece34131d997a97ce7e9242a51a688a/utils_preprocess.py#L228
          for split in data:
              if len(data[split]) > 0:
                  prefix = os.path.join(output_dir, f"{split}-{lang_}")
                  if suffix == "mt":
                      with open(prefix + ".mt.tsv", "w") as fout:
                          for idx, (sent, tag, _) in enumerate(
                              data[split]
                          ):
                              newline = (
                                  "\n"
                                  if idx != len(data[split]) - 1
                                  else ""
                              )
                              fout.write(
                                  "{}\t{}{}".format(
                                      " ".join(sent),
                                      " ".join(tag),
                                      newline,
                                  )
                              )
                      check_file(prefix + ".mt.tsv")
                      print(
                          "    - finish checking " + prefix + ".mt.tsv"
                      )
                  elif suffix == "tsv":
                      with open(prefix + ".tsv", "w") as fout:
                          for sidx, (sent, tag, _) in enumerate(
                              data[split]
                          ):
                              for widx, (w, t) in enumerate(
                                  zip(sent, tag)
                              ):
                                  newline = (
                                      ""
                                      if (sidx == len(data[split]) - 1)
                                      and (widx == len(sent) - 1)
                                      else "\n"
                                  )
                                  fout.write(
                                      "{}\t{}{}".format(w, t, newline)
                                  )
                              fout.write("\n")
                  elif suffix == "conll":
                      with open(prefix + ".conll", "w") as fout:
                          for _, _, lines in data[split]:
                              for line in lines:
                                  fout.write(line.strip() + "\n")
                              fout.write("\n")
                  print(f"finish writing file to {prefix}.{suffix}")
  
      languages = (
          "af ar bg de el en es et eu fa fi fr he hi hu id it ja "
          "kk ko mr nl pt ru ta te th tl tr ur vi yo zh"
      ).split()
      udpos_temp_path = py_io.create_dir(
          task_data_base_path, "udpos_temp"
      )
      download_utils.download_and_untar(
          "https://lindat.mff.cuni.cz/repository/xmlui/bitstream/handle/11234/1-3105/"
          "ud-treebanks-v2.5.tgz",
          udpos_temp_path,
      )
      download_utils.download_file(
          "https://raw.githubusercontent.com/google-research/xtreme/"
          "4fd68dc6b53796413e05dc3f3f73c2106f88ec57/third_party/ud-conversion-tools/lib/conll.py",
          os.path.join(udpos_temp_path, "conll.py"),
      )
      conll = filesystem.import_from_path(
          os.path.join(udpos_temp_path, "conll.py")
      )
      conllu_path_ls = sorted(
          glob.glob(os.path.join(udpos_temp_path, "*", "*", "*.conllu"))
      )
      conll_path = os.path.join(udpos_temp_path, "conll")
  
      # === Convert conllu files to conll === #
      for input_path in display.tqdm(
          conllu_path_ls, desc="Convert conllu files to conll format"
      ):
          input_path_fol, input_path_file = os.path.split(input_path)
          lang = input_path_file.split("_")[0]
          os.makedirs(os.path.join(conll_path, lang), exist_ok=True)
          output_path = os.path.join(
              conll_path,
              lang,
              strings.replace_suffix(
                  input_path_file, "conllu", "conll"
              ),
          )
          pos_rank_precedence_dict = {
              "default": (
                  "VERB NOUN PROPN PRON ADJ NUM ADV INTJ AUX ADP DET PART CCONJ SCONJ X PUNCT"
              ).split(" "),
              "es": "VERB AUX PRON ADP DET".split(" "),
              "fr": "VERB AUX PRON NOUN ADJ ADV ADP DET PART SCONJ CONJ".split(
                  " "
              ),
              "it": "VERB AUX ADV PRON ADP DET INTJ".split(" "),
          }
  
          if lang in pos_rank_precedence_dict:
              current_pos_precedence_list = pos_rank_precedence_dict[
                  lang
              ]
          else:
              current_pos_precedence_list = pos_rank_precedence_dict[
                  "default"
              ]
  
          cio = conll.CoNLLReader()
          orig_treebank = cio.read_conll_u(input_path)
          modif_treebank = copy.copy(orig_treebank)
  
          for s in modif_treebank:
              s.filter_sentence_content(
                  replace_subtokens_with_fused_forms=True,
                  posPreferenceDict=current_pos_precedence_list,
                  node_properties_to_remove=False,
                  remove_deprel_suffixes=False,
                  remove_arabic_diacritics=False,
              )
  
          cio.write_conll(
              list_of_graphs=modif_treebank,
              conll_path=Path(output_path),
              conllformat="conll2006",
              print_fused_forms=True,
              print_comments=False,
          )
  
      # === Convert conll to final format === #
      for lang in display.tqdm(
          languages, desc="Convert conll to final format"
      ):
          task_name = f"udpos_{lang}"
          task_data_path = os.path.join(task_data_base_path, task_name)
          os.makedirs(task_data_path, exist_ok=True)
          all_examples = {k: [] for k in ["train", "val", "test"]}
          for path in sorted(
              glob.glob(os.path.join(conll_path, lang, "*.conll"))
          ):
              examples = _read_one_file(path)
              if "train" in path:
                  all_examples["train"] += examples
              elif "dev" in path:
                  all_examples["val"] += examples
              elif "test" in path:
                  all_examples["test"] += examples
              else:
                  raise KeyError()
          all_examples = _remove_empty_space(all_examples)
          _write_files(
              data=all_examples,
              output_dir=task_data_path,
              lang_=lang,
              suffix="tsv",
          )
          paths_dict = {
              phase: os.path.join(task_data_path, f"{phase}-{lang}.tsv")
              for phase, phase_data in all_examples.items()
              if len(phase_data) > 0
          }
          py_io.write_json(
              data={
                  "task": "udpos",
                  "paths": paths_dict,
                  "name": task_name,
                  "kwargs": {"language": lang},
              },
              path=os.path.join(
                  task_config_base_path, f"{task_name}_config.json"
              ),
          )
      shutil.rmtree(udpos_temp_path)
  
imports: import copy
  import glob
  import itertools
  import os
  import shutil
  from pathlib import Path
  import jiant.scripts.download_data.utils
  import jiant.utils.display
  import jiant.utils.python.datastructures
  import jiant.utils.python.io
  import jiant.utils.python.filesystem
  import jiant.utils.python.strings
label_desc: Use image node_id 3 for calling a global function with example usage: download_udpos_data_and_write_config(task_data_base_path, task_config_base_path) and returns: data, new_data