MCPcopy Create free account
hub / github.com/Unakar/Logic-RL / parse_cot_eval_instruct

Function parse_cot_eval_instruct

eval_kk/kk_processor.py:88–146  ·  view source on GitHub ↗
(pred_str, ans,
                   conclusion_patterns=['<answer>'],
                   verbose=False,
                   finish_patterns=["</answer>"],
                   reformat_gold_conditions=None,
                   expected_names=None,
                   solution_text_format=None)

Source from the content-addressed store, hash-verified

86
87
88def parse_cot_eval_instruct(pred_str, ans,
89 conclusion_patterns=['<answer>'],
90 verbose=False,
91 finish_patterns=["</answer>"],
92 reformat_gold_conditions=None,
93 expected_names=None,
94 solution_text_format=None):
95 print("\n" + "="*80)
96 print(" Processing New Sample ".center(80, '='))
97
98 # Parse ground truth data
99 gt_status = parse_solution_text_format(solution_text_format)
100 expected_names = list(gt_status.keys())
101 print(f"[Ground Truth] Final identities: {gt_status}")
102
103 # Extract model answer
104 answer_text, processed_str = extract_solution(pred_str)
105 print(f"\n[Model Response]\n{processed_str}")
106
107 # Validate response structure
108 format_correct = validate_response_structure(processed_str)
109 print(f"\n Format validation: {'PASS' if format_correct else 'FAIL'}")
110
111 # Validate answer content
112 answer_score = 0
113 is_correct = False
114 correct_ratio = 0
115 wrong_reason = "no_conclusion_matched"
116 if format_correct and answer_text:
117 pred_status = parse_model_answer(answer_text, expected_names)
118 if pred_status:
119 print(f"\n[Content Validation]")
120 print(f" Expected: {gt_status}")
121 print(f" Predicted: {pred_status}")
122
123 if pred_status == gt_status:
124 answer_score = 2
125 is_correct = True
126 correct_ratio = 1
127 print(" Content validation: FULL MATCH")
128 else:
129 answer_score = -1.5
130 correct_ratio = 0
131 wrong_reason = "wrong_identity"
132 print(" Content validation: MISMATCH")
133 else:
134 answer_score = -2
135 correct_ratio = 0
136 wrong_reason = "no_conclusion_matched"
137 print( "Fail to parse answer")
138 else:
139 print("\n[Content Validation] Skipped due to format errors or missing answer")
140
141 if is_correct == False and verbose == True:
142 print("wrong_reason:",wrong_reason)
143 print("********* \nprediction before parse:\n", pred_str)
144 print("********* \nprediction after parse:\n", answer_text)
145

Callers 1

Calls 4

extract_solutionFunction · 0.90
parse_model_answerFunction · 0.90

Tested by

no test coverage detected