prepare_dataset.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from datasets import load_dataset,Dataset
  2. def get_ifeval_data(model_name,output_dir):
  3. if model_name not in ["Meta-Llama-3.1-8B-Instruct","Meta-Llama-3.1-70B-Instruct","Meta-Llama-3.1-405B-Instruct"]:
  4. raise ValueError("Only Meta-Llama-3.1-8B-Instruct, Meta-Llama-3.1-70B-Instruct, Meta-Llama-3.1-405B-Instruct models are supported for IFEval")
  5. original_dataset_name = "wis-k/instruction-following-eval"
  6. meta_dataset_name = f"meta-llama/{model_name}-evals"
  7. meta_data = load_dataset(
  8. meta_dataset_name,
  9. name=f"{model_name}-evals__ifeval__strict__details",
  10. split="latest"
  11. )
  12. ifeval_data = load_dataset(
  13. original_dataset_name,
  14. split="train"
  15. )
  16. meta_data = meta_data.map(get_question)
  17. meta_df = meta_data.to_pandas()
  18. ifeval_df = ifeval_data.to_pandas()
  19. ifeval_df = ifeval_df.rename(columns={"prompt": "input_question"})
  20. joined = meta_df.join(ifeval_df.set_index('input_question'),on="input_question")
  21. joined = joined.rename(columns={"input_final_prompts": "prompt"})
  22. joined = joined.rename(columns={"is_correct": "previous_is_correct"})
  23. joined = Dataset.from_pandas(joined)
  24. joined = joined.select_columns(["input_question", "prompt", "previous_is_correct","instruction_id_list","kwargs","output_prediction_text","key"])
  25. joined.rename_column("output_prediction_text","previous_output_prediction_text")
  26. for item in joined:
  27. check_sample(item)
  28. joined.to_parquet(output_dir + f"/joined_ifeval.parquet")
  29. def get_math_data(model_name,output_dir):
  30. if model_name not in ["Meta-Llama-3.1-8B-Instruct","Meta-Llama-3.1-70B-Instruct","Meta-Llama-3.1-405B-Instruct"]:
  31. raise ValueError("Only Meta-Llama-3.1-8B-Instruct, Meta-Llama-3.1-70B-Instruct, Meta-Llama-3.1-405B-Instruct models are supported for MATH_hard")
  32. original_dataset_name = "lighteval/MATH-Hard"
  33. meta_dataset_name = f"meta-llama/{model_name}-evals"
  34. meta_data = load_dataset(
  35. meta_dataset_name,
  36. name=f"{model_name}-evals__math_hard__details",
  37. split="latest"
  38. )
  39. math_data = load_dataset(
  40. original_dataset_name,
  41. split="test"
  42. )
  43. meta_df = meta_data.to_pandas()
  44. math_df = math_data.to_pandas()
  45. math_df = math_df.rename(columns={"problem": "input_question"})
  46. joined = meta_df.join(math_df.set_index('input_question'),on="input_question")
  47. joined = Dataset.from_pandas(joined)
  48. joined = joined.select_columns(["input_question", "input_correct_responses", "input_final_prompts", "is_correct","solution","output_prediction_text"])
  49. joined = joined.rename_column("is_correct","previous_is_correct")
  50. joined = joined.rename_column("output_prediction_text","previous_output_prediction_text")
  51. for item in joined:
  52. check_sample(item)
  53. joined.to_parquet(output_dir + f"/joined_math.parquet")
  54. def get_question(example):
  55. try:
  56. example["input_question"] = eval(example["input_question"].replace("null","None").replace("true","True").replace("false","False"))["dialog"][0]["body"].replace("Is it True that the first song","Is it true that the first song").replace("Is the following True","Is the following true")
  57. example["input_final_prompts"] = example["input_final_prompts"][0]
  58. return example
  59. except:
  60. print(example["input_question"])
  61. return
  62. def check_sample(example):
  63. if "kwargs" in example and not example["kwargs"]:
  64. print(example)
  65. raise ValueError("This example did not got joined for IFeval")
  66. if "solution" in example and not example["solution"]:
  67. print(example)
  68. raise ValueError("This example did not got joined for MATH_hard")