File size: 16,302 Bytes
33f6a97
 
 
 
c8f1b06
 
33f6a97
 
 
c8f1b06
 
33f6a97
c8f1b06
33f6a97
 
 
 
 
 
 
 
 
 
c8f1b06
 
 
 
 
 
33f6a97
 
 
 
 
 
 
 
 
 
 
 
c8f1b06
33f6a97
 
 
 
 
 
 
 
 
 
 
 
c8f1b06
 
33f6a97
 
 
 
 
c8f1b06
 
 
33f6a97
 
 
 
 
 
c8f1b06
 
 
33f6a97
 
c8f1b06
 
33f6a97
 
 
 
 
 
c8f1b06
 
 
 
 
 
 
 
 
 
33f6a97
 
 
 
c8f1b06
 
33f6a97
 
 
c8f1b06
33f6a97
 
c8f1b06
 
 
 
 
 
 
 
 
 
33f6a97
c8f1b06
33f6a97
 
c8f1b06
33f6a97
 
 
c8f1b06
 
 
 
 
 
33f6a97
c8f1b06
33f6a97
 
c8f1b06
33f6a97
 
c8f1b06
33f6a97
 
c8f1b06
 
 
 
 
 
 
33f6a97
 
 
 
 
 
c8f1b06
33f6a97
c8f1b06
33f6a97
c8f1b06
 
 
 
 
 
 
 
33f6a97
 
c8f1b06
33f6a97
 
c8f1b06
33f6a97
 
 
c8f1b06
 
33f6a97
 
c8f1b06
 
 
 
 
 
 
 
 
 
 
33f6a97
 
c8f1b06
 
33f6a97
 
c8f1b06
33f6a97
c8f1b06
 
33f6a97
 
c8f1b06
 
 
 
 
33f6a97
 
c8f1b06
 
 
 
 
 
 
 
 
 
 
 
33f6a97
c8f1b06
 
 
 
 
 
 
 
33f6a97
 
c8f1b06
33f6a97
 
 
 
 
 
c8f1b06
 
 
 
 
 
 
 
 
 
 
33f6a97
c8f1b06
 
 
 
 
 
 
 
33f6a97
 
c8f1b06
 
 
 
 
33f6a97
 
 
 
c8f1b06
 
 
33f6a97
 
c8f1b06
33f6a97
 
c8f1b06
33f6a97
c8f1b06
33f6a97
c8f1b06
33f6a97
c8f1b06
33f6a97
 
 
 
c8f1b06
 
 
 
 
33f6a97
 
 
c8f1b06
 
 
 
 
 
 
 
33f6a97
 
 
c8f1b06
 
 
 
 
 
33f6a97
 
 
c8f1b06
33f6a97
c8f1b06
33f6a97
c8f1b06
 
 
33f6a97
 
 
 
c8f1b06
33f6a97
 
c8f1b06
33f6a97
 
c8f1b06
33f6a97
 
 
c8f1b06
2379255
c8f1b06
 
 
2379255
c8f1b06
 
 
2379255
c8f1b06
 
 
2379255
 
c8f1b06
33f6a97
 
c8f1b06
 
33f6a97
 
 
 
c8f1b06
 
 
33f6a97
 
 
c8f1b06
 
 
 
33f6a97
 
c8f1b06
 
33f6a97
c8f1b06
 
 
33f6a97
c8f1b06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33f6a97
c8f1b06
33f6a97
c8f1b06
 
 
 
 
33f6a97
c8f1b06
33f6a97
 
 
 
 
 
 
 
 
 
 
 
 
c8f1b06
 
33f6a97
 
 
 
c8f1b06
 
 
 
 
 
 
33f6a97
c8f1b06
 
 
 
 
33f6a97
 
 
 
 
 
 
c8f1b06
 
 
 
 
 
 
 
33f6a97
 
c8f1b06
 
33f6a97
 
 
 
 
 
c8f1b06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33f6a97
 
 
 
 
c8f1b06
 
 
 
 
 
 
 
 
 
 
33f6a97
 
c8f1b06
 
33f6a97
 
 
c8f1b06
 
 
 
 
 
 
 
 
 
33f6a97
c8f1b06
33f6a97
 
 
c8f1b06
 
 
 
 
 
 
 
 
 
 
 
 
33f6a97
 
 
 
c8f1b06
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# 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](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:
  ```bash
  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:
  ```bash
  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](https://universaldependencies.org/) to check for new versions.

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

### 2. Create New Branch

```bash
# 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. Update Environment Configuration

```bash
cd tools

# Set the version number
export NEW_VER=2.18
echo "UD_VER=${NEW_VER}" > .env

# Verify
cat .env
# Output: UD_VER=2.18
```

**What is .env?** Environment file that all scripts read to determine which UD version to process.

### 4. Fetch Metadata from LINDAT/CLARIN

```bash
# Fetch citation and description
./00_fetch_ud_clarin-dspace_metadata.py -o

# 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 `00_fetch_ud_clarin-dspace_metadata.py`
2. Find the `url_postfixes` dictionary
3. Add entry for new version:
   ```python
   "2.18": "11234/1-XXXX",  # Check UD website for correct handle
   ```

**Where to find handle?** Visit the [UD release page](https://universaldependencies.org/) and check the LINDAT citation link.

### 5. Fetch Language Codes and Flags

```bash
# Fetch language metadata
./00_fetch_ud_codes_and_flags.sh -o

# This creates:
# - etc/codes_and_flags-2.18.yaml
# - etc/codes_and_flags-latest.yaml (updated symlink)
```

**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:
   ```bash
   VER_MAPPING["2.18"]="<git-commit-hash-for-2.18>"
   ```

**How to find hash?** Check the [UD docs-automation releases](https://github.com/UniversalDependencies/docs/releases) for the commit tagged with the version.

### 6. Discover UD Repositories

```bash
# Generate list of all UD repositories
./01_fetch_ud_repos.sh

# This creates:
# - .UD_submodules_add.commands (list of git submodule add commands)
```

**What does this do?** Queries GitHub API for all repositories in the UniversalDependencies organization and generates commands to add them as submodules.

### 7. Fetch UD Repositories as Submodules

```bash
cd UD_repos

# Initialize git repository (if first time)
git init

# Add all UD repositories as submodules
bash ../.UD_submodules_add.commands

# Checkout the new release tag in all submodules
git submodule foreach "git fetch --tags && git checkout r${NEW_VER} && touch .tag-r${NEW_VER}"

# Create branch and commit
git checkout -b ${NEW_VER}
git add -A
git commit -m "Add UD ${NEW_VER} repositories"

cd ..
```

**Expected time:** 30-60 minutes depending on network speed.

**What are .tag-r{VER} files?** Marker files that `02_generate_metadata.py` checks to ensure a repository has the correct version tag.

**Troubleshooting:** If some repositories don't have the tag:
```bash
git submodule foreach "git fetch --tags && (git checkout r${NEW_VER} || git checkout main) && touch .tag-r${NEW_VER}"
```

### 8. Extract Metadata from Treebanks

```bash
# Generate metadata from all treebank directories
./02_generate_metadata.py -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)

```bash
# Generate HuggingFace dataset card
./03_generate_README.py -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.

### 10. Review Blocked Treebanks

Before generating Parquet files, review the blocked treebanks:

```bash
# 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](tools/BLOCKED_TREEBANKS.md)

### 11. Generate Parquet Files

```bash
# Test with 3 treebanks first
uv run ./04_generate_parquet.py --test

# If successful, generate all treebanks (takes 2-4 hours)
uv run ./04_generate_parquet.py

# 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

**Expected time:** 2-4 hours for all treebanks

### 12. Validate Parquet Files

```bash
# Test validation on 3 treebanks
uv run ./05_validate_parquet.py --local --test

# Full validation (optional, takes ~30-60 minutes)
uv run ./05_validate_parquet.py --local --mode text -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:** No differences except in comment metadata (which may vary slightly).

### 13. Copy Files to Repository Root

```bash
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:

```bash
# 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

```bash
# 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
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:

```bash
# 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**

```bash
# 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:**
```python
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:

```bash
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.

## Troubleshooting

### Issue: Submodule checkout fails

**Problem:** Some repositories don't have the `r2.18` tag.

**Solution:**
```bash
cd tools/UD_repos
git submodule foreach 'git fetch --tags && (git checkout r2.18 || git checkout main) && touch .tag-r2.18'
```

This falls back to `main` branch for repositories without the tag.

### 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:**
```bash
# 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](https://github.com/bot-zen/ud-hf-parquet-tools/blob/main/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 UD versions: `rm -rf tools/UD_repos/` after uploading

### Issue: Script dependencies not found

**Problem:** ImportError or ModuleNotFoundError.

**Solution:**
```bash
# 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:

- [ ] `.env` file updated with new version
- [ ] Metadata files generated (`citation-{VER}`, `description-{VER}`, `codes_and_flags-{VER}.yaml`)
- [ ] All UD repositories fetched and checked out to correct tag
- [ ] `metadata-{VER}.json` generated with blocked treebank info
- [ ] `README-{VER}` generated
- [ ] Parquet files generated for all non-blocked treebanks
- [ ] Parquet files validated (spot check)
- [ ] 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: Fetch repositories | 30-60 min | Network-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 (repository fetch, Parquet generation, 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

- **Quick reference:** [tools/README.md](tools/README.md) - Script documentation and common operations
- **Blocked treebanks:** [tools/BLOCKED_TREEBANKS.md](tools/BLOCKED_TREEBANKS.md) - License restrictions
- **Migration guide:** [MIGRATION.md](MIGRATION.md) - v1.x to v2.0 migration
- **Parquet tools:** https://github.com/bot-zen/ud-hf-parquet-tools - External library for CoNLL-U processing
- **CoNLL-U parsing:** https://github.com/bot-zen/ud-hf-parquet-tools/blob/main/CONLLU_PARSING.md - Parsing edge cases

## Support

For issues:
- **UD data issues** → [UD GitHub Issues](https://github.com/UniversalDependencies/docs/issues)
- **Tooling issues** → Your repository issues or [ud-hf-parquet-tools issues](https://github.com/bot-zen/ud-hf-parquet-tools/issues)
- **HuggingFace Hub issues** → [HuggingFace Community Forums](https://discuss.huggingface.co/)