CoolFace
Apppublic

iruno/test_wprm3

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
reward_postprocessor.py41 linesDownload Raw Back to agent
1import numpy as np2import re3 4 5def extract_judge_hash(response):6    """7    checklist 별로 yes, in, no를 판단한 정보를 hash 형태로 변환하여 반환8    """9    content = response['response']10    11    try:12        judge_content = content.lower().replace(' ', '').split('<answer>')[1].split('</answer>')[0]13    except:14        import traceback15        traceback.print_exc()16        return None17    pattern = r":yes|:inprogress|:no"18    matches = re.findall(pattern, judge_content)19    matches = [{':yes': 'y', ':inprogress': 'i', ':no': 'n'}[match] for match in matches]20    return ''.join(matches)21 22def average_logits(response):23    """24    yes, in, no를 logits 레벨에서 계산.25    """26    judge_probs = response['judge_probs']27    28    yes_ = np.mean([r['yes'] for r in judge_probs])29    in_ = np.mean([r['in'] for r in judge_probs])30    31    reward = yes_ + 0.5 * in_32    return reward33 34 35REWARD_PROCESSORS = {36    'avg_logits': average_logits37}38 39REWARD_PROCESSOR_N_SAMPLES = {40    'avg_logits': 541}