def main():
    """
    Helper script to extract paragraphs questions and answers from RACE datasets.
    """
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--input-dir",
        help="input directory for downloaded RACE dataset",
    )
    parser.add_argument(
        "--output-dir",
        help="output directory for extracted data",
    )
    args = parser.parse_args()

    if not os.path.exists(args.output_dir):
        os.makedirs(args.output_dir, exist_ok=True)

    for set_type in ["train", "dev", "test-middle", "test-high"]:
        examples = get_examples(args.input_dir, set_type)
        qa_file_paths = [
            os.path.join(args.output_dir, set_type + ".input" + str(i + 1))
            for i in range(4)
        ]
        qa_files = [open(qa_file_path, "w") for qa_file_path in qa_file_paths]
        outf_context_path = os.path.join(args.output_dir, set_type + ".input0")
        outf_label_path = os.path.join(args.output_dir, set_type + ".label")
        outf_context = open(outf_context_path, "w")
        outf_label = open(outf_label_path, "w")
        for example in examples:
            outf_context.write(example.paragraph + "\n")
            for i in range(4):
                qa_files[i].write(example.qa_list[i] + "\n")
            outf_label.write(str(example.label) + "\n")

        for f in qa_files:
            f.close()
        outf_label.close()
        outf_context.close()

    Helper script to extract paragraphs questions and answers from RACE datasets.
    
structured_prompting/fairseq-version/fairseq/examples/roberta/preprocess_RACE.py