# tools/ Directory Quick reference for the Universal Dependencies dataset generation pipeline. ## Quick Start: Add New UD Version (Release Run) ```bash # Set version export NEW_VER=2.18 cd tools # Optional convenience (all scripts also support explicit version flags) # echo "UD_VER=${NEW_VER}" > .env # Fetch metadata uv run 00_fetch_ud_clarin-dspace_metadata.py -o --ud-ver "${NEW_VER}" ./00_fetch_ud_codes_and_flags.sh -o --ud-ver "${NEW_VER}" ./01_fetch_ud_snapshot.sh --ud-ver "${NEW_VER}" # Generate files uv run 02_generate_metadata.py -o --ud-ver "${NEW_VER}" uv run 03_generate_README.py -o --ud-ver "${NEW_VER}" # Keep root metadata/card in sync before parquet generation cp README-${NEW_VER} ../README.md cp metadata-${NEW_VER}.json ../metadata.json # Generate and fully validate parquet uv run 04_generate_parquet.py --ud-ver "${NEW_VER}" --prune-extra --check-extra uv run 05_validate_parquet.py --ud-ver "${NEW_VER}" --local # Stage generated outputs git add ../README.md ../metadata.json ../parquet git add README-${NEW_VER} metadata-${NEW_VER}.json git add etc/citation-${NEW_VER} etc/description-${NEW_VER} etc/codes_and_flags-${NEW_VER}.yaml ``` **For detailed instructions, see:** [ADDING_NEW_UD_VERSION.md](../ADDING_NEW_UD_VERSION.md) ## Quick Start: Refresh Existing UD Branches for a Framework Release Use this workflow when the loader/framework changes (for example `v2.1.1`) and you need to regenerate artifacts in all UD version branches. ```bash # Run from 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 branch aligned with framework changes (pick one) git rebase main # git merge main --strategy-option=theirs 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 ``` ## Pipeline Scripts ### 00 - Fetch Metadata **00_fetch_ud_clarin-dspace_metadata.py** - Downloads citation and description from LINDAT/CLARIN repository - Creates: `etc/citation-{VER}`, `etc/description-{VER}` - Uses: `etc/ud_release_handles.tsv` for version -> handle mapping - Optional filter: `--ud-ver {VER}` to fetch one version **00_fetch_ud_codes_and_flags.sh** - Downloads language codes and flags from UD docs-automation - Default output: `etc/codes_and_flags-{UD_VER}.yaml`, `etc/codes_and_flags-latest.yaml` - `--all` output: all mapped `etc/codes_and_flags-{VER}.yaml` files - Update `VER_MAPPING` for new versions ### 01 - Fetch Snapshot **01_fetch_ud_snapshot.sh** - Downloads official UD release snapshot from LINDAT/CLARIN (archive resolved via API) - Creates: `ud-treebanks-v{VER}/` - Creates/updates symlink: `UD_repos -> ud-treebanks-v{VER}` - Options: `--ud-ver`, `--online`, `--keep-archive`, `--keep-backup` ### 02 - Generate Metadata **02_generate_metadata.py** - Extracts metadata from local UD directories - Collects: summaries, licenses, splits, statistics, blocked status - Creates: `metadata-{VER}.json` - Reads: `blocked_treebanks.yaml` for license restrictions - Options: `--ud-ver`, `--override` ### 03 - Generate README **03_generate_README.py** - Renders Jinja2 template with metadata - Creates: `README-{VER}` (HuggingFace dataset card) - Uses: `templates/README.tmpl`, `metadata-{VER}.json`, `etc/citation-{VER}`, `etc/description-{VER}` - Options: `--ud-ver`, `--override` ### 04 - Generate Parquet **04_generate_parquet.py** - Wrapper script calling `ud-hf-parquet-tools` library - Converts CoNLL-U files to Parquet format - Creates: `../parquet/{treebank}/{split}.parquet` - Uses `tools/metadata-{UD_VER}.json` when present; otherwise falls back to `../metadata.json` - Options: `--ud-ver`, `--test`, `--overwrite`, `--blocked-treebanks`, `--check-extra`, `--prune-extra` - Recommended for release runs: `--prune-extra --check-extra` to prevent stale parquet files when treebanks are renamed/removed across UD versions ### 05 - Validate Parquet **05_validate_parquet.py** - Wrapper script calling `ud-hf-parquet-tools` library - Validates Parquet files against CoNLL-U source - Uses `tools/metadata-{UD_VER}.json` when present; otherwise falls back to `../metadata.json` - Options: `--ud-ver`, `--local`, `--parquet-dir`, `--revision`, `--test`, `-vv` ## Directory Structure ``` tools/ ├── 00_fetch_ud_clarin-dspace_metadata.py # Fetch citation/description ├── 00_fetch_ud_codes_and_flags.sh # Fetch language metadata ├── 01_fetch_ud_snapshot.sh # Download UD snapshot from CLARIN ├── 02_generate_metadata.py # Extract treebank metadata ├── 03_generate_README.py # Generate dataset card ├── 04_generate_parquet.py # Generate Parquet files ├── 05_validate_parquet.py # Validate Parquet files ├── blocked_treebanks.yaml # License-restricted treebanks ├── etc/ │ ├── citation-{VER} # Generated citations │ ├── description-{VER} # Generated descriptions │ ├── codes_and_flags-{VER}.yaml # Language metadata │ └── ud_release_handles.tsv # UD version -> CLARIN handle mapping ├── templates/ │ └── README.tmpl # Jinja2 template for dataset card ├── metadata-{VER}.json # Generated metadata (output) ├── README-{VER} # Generated dataset card (output) ├── ud-treebanks-v{VER}/ # Extracted CLARIN snapshot └── UD_repos -> ud-treebanks-v{VER} # Symlink consumed by 02/04/05 scripts ``` ## Configuration **Environment Variables (.env, optional)** ```bash UD_VER=2.17 # Current UD version ``` You can skip `.env` and pass `--ud-ver` flags directly. **Blocked Treebanks (blocked_treebanks.yaml)** ```yaml pt_cintil: reason: "Restrictive license prohibits redistribution in derived formats" license: "CC BY-NC-SA 4.0" url: "https://github.com/UniversalDependencies/UD_Portuguese-CINTIL" ``` ## Dependencies - Python 3.12+ - `uv` (for running scripts with dependencies) - `ud-hf-parquet-tools` (for parquet generation/validation) Install dependencies: ```bash pip install ud-hf-parquet-tools pyyaml python-dotenv jinja2 ``` ## Common Operations **Test on subset:** ```bash uv run ./04_generate_parquet.py --ud-ver 2.17 --test --prune-extra --check-extra uv run ./05_validate_parquet.py --ud-ver 2.17 --test --local ``` **Full local validation (release run):** ```bash uv run ./05_validate_parquet.py --ud-ver 2.17 --local ``` **Force regeneration:** ```bash ./02_generate_metadata.py --ud-ver 2.17 -o ./03_generate_README.py --ud-ver 2.17 -o uv run ./04_generate_parquet.py --ud-ver 2.17 --overwrite --prune-extra --check-extra ``` **Skip blocked treebanks:** ```bash uv run ./04_generate_parquet.py --blocked-treebanks blocked_treebanks.yaml ``` ## Troubleshooting **Script not found:** - Scripts use `#!/usr/bin/env -S uv run` shebang - Make executable: `chmod +x *.py *.sh` - Or run with: `uv run ./script.py` **Missing dependencies:** ```bash pip install ud-hf-parquet-tools ``` **Snapshot download/extraction fails:** ```bash ./01_fetch_ud_snapshot.sh --online --ud-ver 2.17 ``` **Disk usage after repeated snapshot refreshes:** ```bash # Default behavior deletes archive and replaces old snapshot directory ./01_fetch_ud_snapshot.sh --online --ud-ver 2.17 # Keep archive and timestamped backup only when needed ./01_fetch_ud_snapshot.sh --online --ud-ver 2.17 --keep-archive --keep-backup ``` ## Documentation - **Comprehensive guide:** [ADDING_NEW_UD_VERSION.md](../ADDING_NEW_UD_VERSION.md) - **Blocked treebanks:** [BLOCKED_TREEBANKS.md](BLOCKED_TREEBANKS.md) - **Migration guide:** [MIGRATION.md](../MIGRATION.md) - **Parquet tools:** https://github.com/bot-zen/ud-hf-parquet-tools