from datasets import load_dataset import os import jsonlines # Load the dataset dataset = load_dataset("ctu-aic/csfever_nli") # Shuffle the test dataset and subsample 2/3 of the data shuffled_test_dataset = dataset["test"].shuffle(seed=42) subsampled_test_dataset = shuffled_test_dataset.select(range(int(len(shuffled_test_dataset) * 2 / 3))) # Define the output directory and create it if it doesn't exist output_dir = ".data/hf_dataset/csfever_nli" os.makedirs(output_dir, exist_ok=True) # Function to write the dataset split to a jsonl file def write_jsonl(data, filepath): with jsonlines.open(filepath, mode='w') as writer: writer.write_all(data) # Write the datasets to jsonl files write_jsonl(dataset["train"], os.path.join(output_dir, "train.jsonl")) write_jsonl(dataset["validation"], os.path.join(output_dir, "validation.jsonl")) write_jsonl(subsampled_test_dataset, os.path.join(output_dir, "test.jsonl")) print(f"Datasets saved to {output_dir}")