universal_dependencies / ADDING_NEW_UD_VERSION.md
iiegn's picture
docs: add parquet stale-artifact guard workflow
d9b92ea

Adding a New Universal Dependencies Version

This guide explains how to add a new Universal Dependencies release (e.g., UD 2.18, 2.19, etc.) to the commul/universal_dependencies HuggingFace dataset.

Quick reference: See tools/README.md for concise commands and script documentation.

Prerequisites

  • Git repository cloned and up to date
  • Python 3.12+ with uv installed
  • Dependencies installed:
    pip install ud-hf-parquet-tools pyyaml python-dotenv jinja2
    
  • Access to push to commul/universal_dependencies on HuggingFace Hub
  • huggingface-cli installed and authenticated:
    pip install huggingface_hub
    huggingface-cli login
    

Overview

Each UD version (2.7, 2.8, ..., 2.17, 2.18, ...) has its own git branch. The dataset uses Parquet format (v2.0 architecture) for all versions. When a new UD release is published, you create a new branch and run the generation pipeline.

Architecture:

  • No Python script loader: Dataset uses Parquet files only (datasets >=4.0.0)
  • External tools: Helper functions in separate ud-hf-parquet-tools library
  • Blocked treebanks: Some treebanks excluded due to license restrictions

Step-by-Step Guide

1. Check for New UD Release

Visit Universal Dependencies releases to check for new versions.

For this example, we'll add UD 2.18 (replace with actual version).

2. Create New Branch

# Ensure you're on the latest main branch
git checkout main
git pull origin main

# Create new branch for UD version
git checkout -b 2.18

# Alternatively, branch from latest UD version if main is stale
git checkout 2.17
git pull origin 2.17
git checkout -b 2.18

Why branching? Each UD version is maintained independently, allowing users to load specific versions via revision="2.18".

3. Choose Version Input (Flags or .env)

cd tools

# Set the version number
export NEW_VER=2.18
# Optional convenience for scripts that read defaults from env:
# echo "UD_VER=${NEW_VER}" > .env

Recommended: pass explicit flags (--ud-ver) in commands below.
Optional: keep .env for a persistent default.

4. Fetch Metadata from LINDAT/CLARIN

# Fetch citation and description
./00_fetch_ud_clarin-dspace_metadata.py -o --ud-ver ${NEW_VER}

# This creates:
# - etc/citation-2.18
# - etc/description-2.18

Before running, update the script to add the new version's handle ID:

  1. Open tools/etc/ud_release_handles.tsv
  2. Add entry for new version:
    2.18 11234/1-XXXX
    

Where to find handle? Visit the UD release page and check the LINDAT citation link.

5. Fetch Language Codes and Flags

# Fetch language metadata
./00_fetch_ud_codes_and_flags.sh -o --ud-ver ${NEW_VER}

# This creates:
# - etc/codes_and_flags-2.18.yaml
# - etc/codes_and_flags-latest.yaml

By default, the script fetches the configured UD_VER and latest. Use --all only when you want to refresh all mapped versions.

Before running, update the script with the docs-automation commit hash:

  1. Open 00_fetch_ud_codes_and_flags.sh
  2. Find the VER_MAPPING associative array
  3. Add entry:
    VER_MAPPING["2.18"]="<git-commit-hash-for-2.18>"
    

How to find hash? Check the UD docs-automation releases for the commit tagged with the version.

6. Download UD Snapshot from CLARIN

# Download and extract official UD release snapshot
./01_fetch_ud_snapshot.sh --ud-ver ${NEW_VER}

# This creates/updates:
# - ud-treebanks-v2.18/   (extracted snapshot directory)
# - UD_repos -> ud-treebanks-v2.18 (symlink used by generation scripts)

What does this do? Resolves the official release treebanks archive from LINDAT/CLARIN API for the handle, downloads it, extracts it, and points UD_repos to the extracted snapshot.

Useful options:

  • --online: Force re-download and re-extraction
  • --keep-archive: Keep the downloaded archive after extraction
  • --keep-backup: Keep previous snapshot as ud-treebanks-v{VER}.bak.<timestamp>

7. Verify Snapshot Layout

# Confirm symlink and directory
ls -ld UD_repos ud-treebanks-v${NEW_VER}

# Spot-check treebank directories
ls UD_repos | head

Expected time: 5-15 minutes depending on network speed and archive size.

Notes:

  • The snapshot already contains a consistent release state for all treebanks.
  • No per-treebank git tags/submodules are required.

8. Extract Metadata from Treebanks

# Generate metadata from all treebank directories
./02_generate_metadata.py --ud-ver ${NEW_VER} -o

# This creates:
# - metadata-2.18.json (contains info for all treebanks)

# Verify the output
ls -lh metadata-${NEW_VER}.json
# Should be ~200-300 KB

# Quick check: count treebanks
python -c "import json; print(len(json.load(open('metadata-${NEW_VER}.json'))))"
# Should be 339+ (number increases with new treebanks)

What does this script do?

  • Reads README files from each treebank
  • Extracts summaries, licenses, genres
  • Collects statistics from stats.xml
  • Identifies available splits (train/dev/test)
  • Checks blocked_treebanks.yaml for license restrictions
  • Adds "blocked" property to metadata

Expected time: 5-10 minutes

9. Generate Dataset Card (README)

# Generate HuggingFace dataset card
./03_generate_README.py --ud-ver ${NEW_VER} -o

# This creates:
# - README-2.18 (dataset card for HuggingFace)

# Verify file was created
ls -lh README-${NEW_VER}

What does this do? Renders templates/README.tmpl with metadata, citation, and description to create the HuggingFace dataset card.

9b. Sync Generated README/Metadata to Repository Root

# Still in tools/
cp README-${NEW_VER} ../README.md
cp metadata-${NEW_VER}.json ../metadata.json

Why now? Keeping root files aligned with versioned files avoids accidental fallback to stale root metadata on branches/scripts that do not always resolve tools/metadata-${NEW_VER}.json.

10. Review Blocked Treebanks

Before generating Parquet files, review the blocked treebanks:

# Check blocked treebanks list
cat blocked_treebanks.yaml

# Example entry:
# pt_cintil:
#   reason: "Restrictive license prohibits redistribution in derived formats"
#   license: "CC BY-NC-SA 4.0"

Why block treebanks? Some treebanks have licenses (e.g., CC BY-NC-SA) that prohibit redistribution in modified formats like Parquet.

See also: tools/BLOCKED_TREEBANKS.md

11. Generate Parquet Files

# Test with 3 treebanks first
uv run ./04_generate_parquet.py --ud-ver ${NEW_VER} --test --prune-extra --check-extra

# If successful, generate all treebanks (takes 2-4 hours)
uv run ./04_generate_parquet.py --ud-ver ${NEW_VER} --prune-extra --check-extra

# Re-runs on an existing branch should overwrite in-place
# uv run ./04_generate_parquet.py --ud-ver ${NEW_VER} --overwrite --prune-extra --check-extra

# This creates:
# - ../parquet/{treebank_name}/{split}.parquet for all treebanks

# Verify output
du -sh ../parquet/
# Should be ~50-80 GB total

What does this do? Wrapper script that calls the ud-hf-parquet-tools library to convert CoNLL-U files to Parquet format.

Options:

  • --test: Generate only 3 treebanks (quick test)
  • --overwrite: Regenerate existing files
  • --blocked-treebanks: Path to YAML file with blocked treebanks
  • --check-extra: Fail fast if extra parquet files/directories are present
  • --prune-extra: Delete extra parquet files/directories before generation

Recommended release flags: --prune-extra --check-extra to guard against stale parquet artifacts when treebanks are renamed/removed between UD versions.

Expected time: 2-4 hours for all treebanks

12. Validate Parquet Files

# Optional smoke test on 3 treebanks
uv run ./05_validate_parquet.py --ud-ver ${NEW_VER} --local --test

# Required release validation (full dataset, no --test)
uv run ./05_validate_parquet.py --ud-ver ${NEW_VER} --local

# Optional verbose diff log (useful for debugging metadata diffs)
uv run ./05_validate_parquet.py --ud-ver ${NEW_VER} --local -vv > /tmp/parquet-check.log

# Check for errors (excluding metadata comments)
grep -E "         [+-]" /tmp/parquet-check.log | grep -vE "         [+-]#"

What does this do? Compares Parquet output to original CoNLL-U to verify 100% data fidelity.

Expected output: Token lines should match perfectly. Metadata/comment differences can still appear in some treebanks.

13. Re-sync Files to Repository Root (Before Commit)

cd ..  # Back to repository root

# Copy generated files
cp tools/README-${NEW_VER} README.md
cp tools/metadata-${NEW_VER}.json metadata.json

# Verify files are in place
ls -lh README.md metadata.json parquet/

Why copy to root? HuggingFace Hub expects these files at the repository root for the dataset to work.

14. Test Dataset Loading

Test that the dataset loads correctly:

# Test loading from Parquet
python -c "
from datasets import load_dataset

# Test a small treebank
ds = load_dataset('parquet', data_files='parquet/en_pronouns/test.parquet')
print(f'Loaded {len(ds[\"train\"])} examples')
print(f'Features: {list(ds[\"train\"].features.keys())}')
print(f'MWT field present: {\"mwt\" in ds[\"train\"].features}')
"

Expected output:

Loaded X examples
Features: ['sent_id', 'text', 'comments', 'tokens', 'lemmas', 'upos', 'xpos', 'feats', 'head', 'deprel', 'deps', 'misc', 'mwt', 'empty_nodes']
MWT field present: True

15. Commit Changes to Git

# Add generated files
git add README.md metadata.json parquet/
git add tools/metadata-${NEW_VER}.json
git add tools/README-${NEW_VER}
git add tools/etc/citation-${NEW_VER}
git add tools/etc/description-${NEW_VER}
git add tools/etc/codes_and_flags-${NEW_VER}.yaml
# Optional (only if you intentionally version-control .env in your workflow)
# git add tools/.env

# Commit with descriptive message
git commit -m "Add UD ${NEW_VER} data with Parquet format

- Generated from Universal Dependencies ${NEW_VER} release
- 339+ treebanks across 186+ languages
- Parquet format for efficient loading (datasets >=4.0.0)
- Blocked treebanks excluded per license restrictions
- Helper functions available in ud-hf-parquet-tools library

Generated files:
- README.md (dataset card)
- metadata.json (treebank metadata)
- parquet/ directory with all treebank splits"

# Tag the commit
git tag -a ud${NEW_VER} -m "Universal Dependencies ${NEW_VER} release"

# Push branch and tags
git push origin ${NEW_VER}
git push origin --tags

16. Upload to HuggingFace Hub

Option A: Using git-lfs (Recommended)

If you've cloned the HuggingFace repository with git-lfs:

# Add HF Hub as remote (if not already)
git remote add hf https://huggingface.co/datasets/commul/universal_dependencies

# Push to HuggingFace
git push hf ${NEW_VER}
git push hf --tags

Option B: Using huggingface-cli

# Upload entire directory
huggingface-cli upload commul/universal_dependencies . --repo-type dataset --revision ${NEW_VER}

Expected upload time: 2-6 hours depending on network speed and HuggingFace server load.

Tip: Run uploads during off-peak hours for better performance.

17. Verify on HuggingFace Hub

Visit: https://huggingface.co/datasets/commul/universal_dependencies

Checklist:

  1. ✅ Branch 2.18 exists in the "Branches" dropdown
  2. ✅ Files are present:
    • README.md (dataset card)
    • metadata.json
    • parquet/ directory with subdirectories
  3. ✅ Dataset card displays correctly
  4. ✅ Files section shows parquet files

Test loading:

from datasets import load_dataset

# Load from new version
ds = load_dataset("commul/universal_dependencies", "en_ewt", revision="2.18")
print(ds)

Expected output:

DatasetDict({
    train: Dataset({
        features: ['sent_id', 'text', 'comments', 'tokens', 'lemmas', ...],
        num_rows: 12544
    })
    dev: Dataset({...})
    test: Dataset({...})
})

18. Update Main Branch (Optional)

If this is now the latest version:

git checkout main
git merge ${NEW_VER}
git push origin main

This makes the new version the default when users don't specify a revision.

19. Refresh Existing UD Branches for a Framework Release

Use this when framework logic changes (for example loader v2.1.1) and you need to rebuild all existing UD branches (2.7 ... 2.17).

# Repository root
export FRAMEWORK_VER=v2.1.1

for UD_VER in 2.7 2.8 2.9 2.10 2.11 2.12 2.13 2.14 2.15 2.16 2.17; do
  git switch "${UD_VER}"
  # Keep the branch aligned with framework changes (pick one):
  git rebase main
  # git merge main --strategy-option=theirs

  # Optional: keep only this branch's generated versioned files
  for OLD_VER in 2.7 2.8 2.9 2.10 2.11 2.12 2.13 2.14 2.15 2.16 2.17; do
    if [ "${OLD_VER}" != "${UD_VER}" ]; then
      git rm -f "tools/README-${OLD_VER}" "tools/metadata-${OLD_VER}.json" \
        "tools/etc/citation-${OLD_VER}" "tools/etc/description-${OLD_VER}" \
        "tools/etc/codes_and_flags-${OLD_VER}.yaml" || true
    fi
  done

  cd tools
  ./00_fetch_ud_clarin-dspace_metadata.py -o --ud-ver "${UD_VER}"
  ./00_fetch_ud_codes_and_flags.sh -o --ud-ver "${UD_VER}"
  ./01_fetch_ud_snapshot.sh --ud-ver "${UD_VER}"
  uv run ./02_generate_metadata.py -o --ud-ver "${UD_VER}"
  uv run ./03_generate_README.py -o --ud-ver "${UD_VER}"
  cp "README-${UD_VER}" ../README.md
  cp "metadata-${UD_VER}.json" ../metadata.json
  uv run ./04_generate_parquet.py --ud-ver "${UD_VER}" --overwrite --prune-extra --check-extra
  uv run ./05_validate_parquet.py --ud-ver "${UD_VER}" --local
  cd ..

  git add README.md metadata.json parquet
  git add "tools/README-${UD_VER}" "tools/metadata-${UD_VER}.json"
  git add "tools/etc/citation-${UD_VER}" "tools/etc/description-${UD_VER}" \
    "tools/etc/codes_and_flags-${UD_VER}.yaml"
  git commit -m "Rebuild UD ${UD_VER} artifacts with loader ${FRAMEWORK_VER}"
  git tag -a "ud${UD_VER}-loader-${FRAMEWORK_VER}" \
    -m "UD ${UD_VER} loader ${FRAMEWORK_VER}"
done

If one UD branch is already up to date, remove it from the loop.

Troubleshooting

Issue: Snapshot download/extraction fails

Problem: Snapshot download fails, or UD_repos does not point to the extracted directory.

Solution:

cd tools
./01_fetch_ud_snapshot.sh --online --ud-ver 2.18
ls -ld UD_repos ud-treebanks-v2.18

If you need to preserve artifacts for debugging:

./01_fetch_ud_snapshot.sh --online --ud-ver 2.18 --keep-archive --keep-backup

Issue: Metadata extraction fails for a treebank

Problem: A treebank is malformed or missing expected files.

Symptoms:

ITEM DELETED - no summary: UD_Language-Treebank
ITEM DELETED - no files: UD_Language-Treebank
ITEM DELETED - no license: UD_Language-Treebank

Solution:

  1. Check the specific treebank in tools/UD_repos/UD_{Language}-{Treebank}/
  2. Verify it has .conllu files and stats.xml
  3. Check if README has required metadata
  4. If persistently broken, report to UD project
  5. Treebank will be automatically excluded from dataset

Issue: Parquet generation fails for a treebank

Problem: CoNLL-U parsing error or schema mismatch.

Solution:

# Isolate the problem by generating one treebank at a time
uv run ./04_generate_parquet.py --treebanks "en_ewt"

# Check error message for details
# Common issues:
# - Malformed CoNLL-U syntax
# - Encoding problems
# - Invalid character in fields

Report issues: See CONLLU_PARSING.md in ud-hf-parquet-tools for known parsing edge cases.

Issue: HuggingFace upload is very slow

Problem: Large Parquet files + network latency.

Solution:

  • Use a machine with better network connection
  • Upload during off-peak hours (e.g., nighttime UTC)
  • Consider parallel uploads if using huggingface-cli

Issue: Out of disk space

Problem: Parquet files take ~50-80 GB.

Solution:

  • Ensure you have at least 100 GB free space
  • Generate Parquet files on a machine with larger disk
  • Clean up old snapshots after uploading: rm -rf tools/ud-treebanks-v*/

Issue: Script dependencies not found

Problem: ImportError or ModuleNotFoundError.

Solution:

# Install required packages
pip install ud-hf-parquet-tools pyyaml python-dotenv jinja2

# Or use uv to manage dependencies automatically
uv run --script ./script.py

Checklist

Before marking the release as complete:

  • Version passed explicitly via flags (--ud-ver) or .env updated
  • Metadata files generated (citation-{VER}, description-{VER}, codes_and_flags-{VER}.yaml)
  • UD snapshot downloaded and UD_repos symlink points to ud-treebanks-v{VER}
  • metadata-{VER}.json generated with blocked treebank info
  • README-{VER} generated
  • Parquet files generated for all non-blocked treebanks
  • Parquet run used stale-artifact guard (--prune-extra --check-extra)
  • Full local validation run (--local without --test)
  • Root files synced from tools outputs before parquet generation and before commit
  • Files copied to repository root (README.md, metadata.json, parquet/)
  • Tested loading from Parquet files
  • Committed to git with descriptive message
  • Tagged with ud{VER}
  • Pushed to origin
  • Uploaded to HuggingFace Hub
  • Verified dataset loads from HF Hub
  • (Optional) Updated main branch if latest version

Timeline Estimate

Step Time Notes
1-5: Setup & metadata 10-15 min Manual edits required
6-7: Download snapshot 5-15 min Network + archive-size dependent
8-9: Generate metadata/README 5-10 min Fast
10-12: Generate & validate Parquet 2-4 hours CPU-intensive
13-15: Commit to git 10-15 min Fast
16: Upload to HF Hub 2-6 hours Network-dependent
17-18: Verify & update 10-20 min Fast
Total ~5-11 hours Can parallelize some steps

Recommendation: Start the process in the morning. Long-running steps (Parquet generation and upload) can run unattended.

Notes

  • No Python script loader: v2.0 architecture uses Parquet files only (no universal_dependencies.py)
  • Helper functions external: CoNLL-U utilities available in ud-hf-parquet-tools library
  • Blocked treebanks: Some treebanks excluded due to license restrictions (see blocked_treebanks.yaml)
  • Branch independence: Each UD version branch is self-contained
  • Version pinning: Users can load specific versions via revision="2.18"

Reference Documentation

Support

For issues: