Upload create_pq.py
Browse files- create_pq.py +54 -0
create_pq.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# /// script
|
| 3 |
+
# requires-python = ">=3.10"
|
| 4 |
+
# dependencies = [
|
| 5 |
+
# "fastparquet",
|
| 6 |
+
# "pandas",
|
| 7 |
+
# "pathlib",
|
| 8 |
+
# "pyarrow",
|
| 9 |
+
# ]
|
| 10 |
+
# ///
|
| 11 |
+
"""
|
| 12 |
+
Create parquet files for config subsets of the VSI-Bench dataset.
|
| 13 |
+
* debiased: all examples not pruned by Iterative Bias Pruning (aka VSI-Bench-Debiased)
|
| 14 |
+
* pruned: all examples pruned by Iterative Bias Pruning
|
| 15 |
+
|
| 16 |
+
> [!NOTE]
|
| 17 |
+
> If you do not pass `index=False`, the parquet files will have a `__index_level_0__` column
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
import pandas as pd
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
|
| 23 |
+
script_dir = Path(__file__).parent
|
| 24 |
+
pruned_ids_path = script_dir / "pruned_ids.txt"
|
| 25 |
+
test_jsonl_path = script_dir / "test.jsonl"
|
| 26 |
+
pq_debiased_path = script_dir / "test_debiased.parquet"
|
| 27 |
+
pq_pruned_path = script_dir / "test_pruned.parquet"
|
| 28 |
+
|
| 29 |
+
print("Creating parquet files...")
|
| 30 |
+
|
| 31 |
+
print(f"Loading pruned ids from '{pruned_ids_path}'...")
|
| 32 |
+
with open(pruned_ids_path, "r") as f:
|
| 33 |
+
pruned_ids = f.read().splitlines()
|
| 34 |
+
print(f" -> Loaded {len(pruned_ids)} pruned ids.")
|
| 35 |
+
|
| 36 |
+
print(f"Loading test data from '{test_jsonl_path}'...")
|
| 37 |
+
df = pd.read_json(str(test_jsonl_path), lines=True)
|
| 38 |
+
print(f" -> Loaded {len(df)} examples.")
|
| 39 |
+
df["pruned"] = df["id"].astype(str).isin(pruned_ids)
|
| 40 |
+
print(f" -> Added pruned column.")
|
| 41 |
+
|
| 42 |
+
# save the debiased and pruned subsets separately to parquet files
|
| 43 |
+
df_debiased = df[~df["pruned"]]
|
| 44 |
+
df_pruned = df[df["pruned"]]
|
| 45 |
+
|
| 46 |
+
print(f"Saving debiased examples to '{pq_debiased_path}'...")
|
| 47 |
+
df_debiased.to_parquet(pq_debiased_path, index=False)
|
| 48 |
+
print(f" -> Saved {len(df_debiased)} debiased examples.")
|
| 49 |
+
|
| 50 |
+
print(f"Saving pruned examples to '{pq_pruned_path}'...")
|
| 51 |
+
df_pruned.to_parquet(pq_pruned_path, index=False)
|
| 52 |
+
print(f" -> Saved {len(df_pruned)} pruned examples.")
|
| 53 |
+
|
| 54 |
+
print("Done.")
|