Upload preprocessing/filter_ids.py with huggingface_hub
Browse files- preprocessing/filter_ids.py +34 -0
preprocessing/filter_ids.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
from datasets import load_from_disk
|
| 6 |
+
|
| 7 |
+
from const import used_indices
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def parse_args():
|
| 11 |
+
parser = argparse.ArgumentParser()
|
| 12 |
+
parser.add_argument("input_path")
|
| 13 |
+
parser.add_argument("--output_path")
|
| 14 |
+
return parser.parse_args()
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def filter_ids(rows):
|
| 18 |
+
return {
|
| 19 |
+
"sentence1_ling": np.array(rows["sentence1_lftk+"])[:, used_indices],
|
| 20 |
+
"sentence2_ling": np.array(rows["sentence2_lftk+"])[:, used_indices],
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def main():
|
| 25 |
+
args = parse_args()
|
| 26 |
+
output_path = args.output_path or args.input_path.rstrip("/") + "_filtered"
|
| 27 |
+
|
| 28 |
+
data = load_from_disk(args.input_path)
|
| 29 |
+
data = data.map(filter_ids, batched=True, batch_size=1000, num_proc=min(8, os.cpu_count() or 1))
|
| 30 |
+
data.save_to_disk(output_path)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
main()
|