| import json |
| import re |
| from tqdm import tqdm |
|
|
| data = json.load(open("/root/test/weitiao/data_processing_hsichen/data_process_bq/data/merged_rm_dpo.json")) |
|
|
| def score_response(response_value): |
| |
| if response_value.count('*') % 2 != 0 or response_value.count('"') % 2 != 0: |
| return 0 |
| |
| |
| narrative_count = len(re.findall(r'\*[^*]+\*', response_value)) |
| |
| dialogue_text = re.sub(r'\*[^*]+\*', '', response_value).strip() |
| dialogue_count = 1 if dialogue_text else 0 |
| |
| |
| if narrative_count == 0 and dialogue_count == 1: |
| return 2 |
| elif narrative_count >= 1 and dialogue_count == 0: |
| return 1 |
| elif narrative_count == 1 and dialogue_count == 1: |
| return 3 |
| elif (narrative_count > 1 and dialogue_count >= 1) or (narrative_count >= 1 and dialogue_count > 1): |
| return 4 |
| return 0 |
|
|
| |
| for sample in tqdm(data,total=len(data)): |
| chosen_value = sample['chosen']['value'] |
| rejected_value = sample['rejected']['value'] |
| |
| |
| sample['chosen_quota_score'] = score_response(chosen_value) |
| sample['rejected_quota_score'] = score_response(rejected_value) |
|
|
| |
| output_file = '/root/test/weitiao/data_processing_hsichen/data_process_bq/data/merged_rm_dpo_scored.json' |
| with open(output_file, 'w', encoding='utf-8') as f: |
| json.dump(data, f, indent=2) |
|
|
| |
|
|
|
|