File size: 1,189 Bytes
3d27cfe | 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 | import json
import random
import os
input_path = "/root/test/weitiao/data_process_bq/data3/sharegpt_h1_nam_num_nhh_len_hard_rej_think_nobitewis_valid_left5_remaining.json"
output_path_sampled = "/root/test/weitiao/data_process_bq/data3/sharegpt_h1_nam_num_nhh_len_hard_rej_think_nobitewis_valid_left5_remaining_1w.json"
output_path_remaining = "/root/test/weitiao/data_process_bq/data3/sharegpt_h1_nam_num_nhh_len_hard_rej_think_nobitewis_valid_left5_remaining.json"
N = 10000
def main():
with open(input_path, "r", encoding="utf-8") as f:
data = json.load(f)
sampled = random.sample(data, N)
sampled_set = set(id(item) for item in sampled)
remaining = [item for item in data if id(item) not in sampled_set]
with open(output_path_sampled, "w", encoding="utf-8") as f:
json.dump(sampled, f, ensure_ascii=False, indent=2)
with open(output_path_remaining, "w", encoding="utf-8") as f:
json.dump(remaining, f, ensure_ascii=False, indent=2)
print(f"[INFO] Sampled {len(sampled)} items -> {output_path_sampled}")
print(f"[INFO] Remaining {len(remaining)} items -> {output_path_remaining}")
if __name__ == "__main__":
main()
|