| import json | |
| def filter_items_based_on_questions(questions_file_path, items_file_path, output_filtered_path, output_removed_path): | |
| with open(questions_file_path, 'r', encoding='utf-8') as file: | |
| questions = json.load(file) | |
| with open(items_file_path, 'r', encoding='utf-8') as file: | |
| items = json.load(file) | |
| initial_count = len(items) | |
| removed_items = [] | |
| print("Starting filtering process...") | |
| filtered_items = [] | |
| for index, item in enumerate(items): | |
| if index % 100 == 0: | |
| print(f"Processed {index}/{initial_count} items...") | |
| sameFlag = False | |
| i_question = item[0].split('\n')[1][10:] | |
| for question in questions: | |
| if question in item[0]: | |
| if len(question) >= 64 or i_question == question: | |
| removed_items.append([item, question]) | |
| sameFlag = True | |
| break | |
| if not sameFlag: | |
| filtered_items.append(item) | |
| final_count = len(filtered_items) | |
| with open(output_filtered_path, 'w', encoding='utf-8') as file: | |
| json.dump(filtered_items, file, ensure_ascii=False, indent=4) | |
| with open(output_removed_path, 'w', encoding='utf-8') as file: | |
| json.dump(removed_items, file, ensure_ascii=False, indent=4) | |
| print(f"Initial item count: {initial_count}") | |
| print(f"Final item count: {final_count}") | |
| print(f"Removed item count: {len(removed_items)}") | |
| print("Filtering process completed.") | |
| questions_file_path = "./questions/es_question.json" | |
| items_file_path = "../train/sft/medicalExam_es.json" | |
| output_filtered_path = "../train/sft/medicalExam_es_clean.json" | |
| output_removed_path = "../train/sft/medicalExam_es_dup.json" | |
| filter_items_based_on_questions(questions_file_path, items_file_path, output_filtered_path, output_removed_path) |