import json json_path = "/vol/zhaoy/ds-ocr/data/CCI3-Data/sample200_len1.0-1.2k/merged_ocr.json" with open(json_path, 'r', encoding='utf-8') as f: data = json.load(f) num = cnt1 = cnt2 = 0 for item in data: num += 1 if item["spans"][0]["before"] in item["content_ocr"] and item["spans"][0]["after"] not in item["tiny_shuffled_content_ocr"]: cnt1 += 1 elif item["spans"][0]["before"] not in item["content_ocr"] and item["spans"][0]["after"] in item["tiny_shuffled_content_ocr"]: cnt2 += 1 print(f"normal正确但是替换后错误:{cnt1}, normal错误但是替换后正确:{cnt2}") # # 如果想保存每条样本的准确率: # with open(json_path.replace(".json", "_acc.json"), "w", encoding="utf-8") as f: # json.dump(sample_accuracies, f, ensure_ascii=False, indent=2)