Download script/special_phe_distribution.py from bingqin111/data_process_bq: direct link, hf CLI and curl.
- Browser
- Download file 2.66 kB
-
https://huggingface.co/datasets/bingqin111/data_process_bq/resolve/main/script/special_phe_distribution.py
- Command line
-
hf download hf://datasets/bingqin111/data_process_bq/script/special_phe_distribution.py
-
curl -L -o special_phe_distribution.py https://huggingface.co/datasets/bingqin111/data_process_bq/resolve/main/script/special_phe_distribution.py
2.66 kB
| import json | |
| from collections import Counter | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| from decimal import Decimal | |
| path = "/root/test/weitiao/data_process_bq/data/test_filtered_by_length_scored_by_rmv2.2.json" | |
| with open(path, "r", encoding="utf-8") as f: | |
| dataset = json.load(f, parse_float=Decimal) | |
| print(f"成功读取 {len(dataset)} 条数据") | |
| chosen_scores = [] | |
| rejected_scores = [] | |
| delta_scores = [] | |
| records = [] | |
| for item in dataset: | |
| c = item.get("chosen_score") | |
| r = item.get("rejected_score") | |
| d = item.get("delta") | |
| if c is None or r is None or d is None: | |
| continue | |
| chosen_scores.append(c) | |
| rejected_scores.append(r) | |
| delta_scores.append(d) | |
| records.append({"chosen": c, "rejected": r, "delta": d}) | |
| print(f"有效样本数:{len(records)}") | |
| min_d = int(np.floor(min(delta_scores))) | |
| max_d = int(np.ceil(max(delta_scores))) | |
| bins = list(range(min_d, max_d + 1)) | |
| hist_counts = Counter(int(d) for d in delta_scores) | |
| plt.figure(figsize=(12, 6)) | |
| plt.bar(hist_counts.keys(), hist_counts.values()) | |
| plt.title("Delta Score Distribution (bin=1)") | |
| plt.xlabel("Delta Score (integer)") | |
| plt.ylabel("Count") | |
| plt.grid(axis='y') | |
| plt.savefig("/root/test/weitiao/data_process_bq/photo/delta_score_openrlhf_rmv2.2.png", dpi=200) | |
| plt.close() | |
| print("柱状图已保存为 delta_score_openrlhf_rmv2.2.png") | |
| def top3(counter): | |
| return counter.most_common(3) | |
| chosen_counter = Counter(chosen_scores) | |
| rejected_counter = Counter(rejected_scores) | |
| delta_counter = Counter(delta_scores) | |
| print("\n=== Top 3 values for each score field ===") | |
| print("chosen_score:", top3(chosen_counter)) | |
| print("rejected_score:", top3(rejected_counter)) | |
| print("delta_score:", top3(delta_counter)) | |
| print("\n=== Overlap Analysis ===") | |
| # delta_score 出现最多的值 | |
| delta_top_value, delta_top_count = delta_counter.most_common(1)[0] | |
| # 筛选出这些记录 | |
| subset = [rec for rec in records if rec["delta"] == delta_top_value] | |
| subset_chosen_counter = Counter(rec["chosen"] for rec in subset) | |
| subset_rejected_counter = Counter(rec["rejected"] for rec in subset) | |
| chosen_in_subset, chosen_cnt = subset_chosen_counter.most_common(1)[0] | |
| rejected_in_subset, rejected_cnt = subset_rejected_counter.most_common(1)[0] | |
| total_subset = len(subset) | |
| print(f"delta_score 最常出现的值: {delta_top_value} (共 {delta_top_count} 条)") | |
| print(f" -> 在这些样本中 chosen_score 最常出现: {chosen_in_subset} " | |
| f"({chosen_cnt} 次,占比 {chosen_cnt/total_subset:.2%})") | |
| print(f" -> 在这些样本中 rejected_score 最常出现: {rejected_in_subset} " | |
| f"({rejected_cnt} 次,占比 {rejected_cnt/total_subset:.2%})") | |