iiegn Claude Sonnet 4.5 commited on
Commit
12e5e8a
·
verified ·
1 Parent(s): 900e5c2

Fix 04_generate_parquet.py: path handling and MWT schema

Browse files

Fixes for Parquet generation:

1. **Path handling**: Extract filename from metadata path
- Metadata includes full path: 'UD_French-GSD/r2.17/fr_gsd-ud-train.conllu'
- Only need filename: 'fr_gsd-ud-train.conllu'
- Files are in: UD_repos/UD_French-GSD/ (not nested by revision)

2. **MWT schema definition**: Use list with dict instead of Sequence
- Changed from: datasets.Sequence({...})
- Changed to: [{...}]
- Fixes AttributeError: 'list' object has no attribute 'get'
- Matches HuggingFace datasets schema requirements

3. **Error handling**: Added traceback for debugging
- Helps identify issues during generation
- Shows full stack trace for failures

Verified:
- ✅ All 235 treebanks processed successfully (0 failures)
- ✅ 506 Parquet files generated (622 MB total)
- ✅ MWT field working correctly
- ✅ French-GSD: 6,188 sentences with MWTs extracted
- ✅ Loading speed: ~147,000 examples/second

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. tools/04_generate_parquet.py +8 -6
tools/04_generate_parquet.py CHANGED
@@ -18,6 +18,7 @@ import argparse
18
  import json
19
  import os
20
  import sys
 
21
  from pathlib import Path
22
  from typing import Any, Dict, List
23
 
@@ -142,8 +143,12 @@ def generate_parquet_for_treebank(
142
  # Extract examples from all files in this split
143
  all_examples = []
144
  for file_path in files:
 
 
 
 
145
  # Construct full path: UD_repos/dirname/filename
146
- full_path = UD_REPOS_DIR / metadata["dirname"] / file_path
147
 
148
  if not full_path.exists():
149
  print(f" Warning: File not found: {full_path}", file=sys.stderr)
@@ -181,11 +186,7 @@ def generate_parquet_for_treebank(
181
  "deprel": datasets.Sequence(datasets.Value("string")),
182
  "deps": datasets.Sequence(datasets.Value("string")),
183
  "misc": datasets.Sequence(datasets.Value("string")),
184
- "mwt": datasets.Sequence({
185
- "id": datasets.Value("string"),
186
- "form": datasets.Value("string"),
187
- "misc": datasets.Value("string"),
188
- }),
189
  })
190
 
191
  # Create dataset from examples
@@ -306,6 +307,7 @@ def main():
306
 
307
  except Exception as e:
308
  print(f" Error: {e}", file=sys.stderr)
 
309
  fail_count += 1
310
 
311
  if verbose:
 
18
  import json
19
  import os
20
  import sys
21
+ import traceback
22
  from pathlib import Path
23
  from typing import Any, Dict, List
24
 
 
143
  # Extract examples from all files in this split
144
  all_examples = []
145
  for file_path in files:
146
+ # Extract just the filename from the path (metadata includes dirname/revision/filename)
147
+ # e.g., "UD_French-GSD/r2.17/fr_gsd-ud-train.conllu" -> "fr_gsd-ud-train.conllu"
148
+ filename = Path(file_path).name
149
+
150
  # Construct full path: UD_repos/dirname/filename
151
+ full_path = UD_REPOS_DIR / metadata["dirname"] / filename
152
 
153
  if not full_path.exists():
154
  print(f" Warning: File not found: {full_path}", file=sys.stderr)
 
186
  "deprel": datasets.Sequence(datasets.Value("string")),
187
  "deps": datasets.Sequence(datasets.Value("string")),
188
  "misc": datasets.Sequence(datasets.Value("string")),
189
+ "mwt": [{"id": datasets.Value("string"), "form": datasets.Value("string"), "misc": datasets.Value("string")}],
 
 
 
 
190
  })
191
 
192
  # Create dataset from examples
 
307
 
308
  except Exception as e:
309
  print(f" Error: {e}", file=sys.stderr)
310
+ traceback.print_exc()
311
  fail_count += 1
312
 
313
  if verbose: