r12 assets: pondernet/gen/r12/build_mix_r12.py
Browse files
pondernet/gen/r12/build_mix_r12.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""build_mix_r12.py — r12 混合语料组装
|
| 3 |
+
配比: chat_v3 x2 (2760, 54%) + zh_cot 1049 (不动, CE 锚) + alpaca_zh 500 + alpaca_en 400
|
| 4 |
+
+ agent 400 (保留原 system) = 5,109 行
|
| 5 |
+
"""
|
| 6 |
+
import json, random
|
| 7 |
+
|
| 8 |
+
random.seed(12)
|
| 9 |
+
|
| 10 |
+
v3 = [json.loads(l) for l in open("/home/z/my-project/download/chat_synth_v3.jsonl")]
|
| 11 |
+
mix11 = [json.loads(l) for l in open("/tmp/mix_r11.jsonl")]
|
| 12 |
+
|
| 13 |
+
def cat_of(r):
|
| 14 |
+
tid = r.get("task_id", "") or ""
|
| 15 |
+
if tid.startswith("cs_"):
|
| 16 |
+
return "chat_v2"
|
| 17 |
+
return r.get("cat", "") or "zh_cot"
|
| 18 |
+
|
| 19 |
+
groups = {}
|
| 20 |
+
for r in mix11:
|
| 21 |
+
groups.setdefault(cat_of(r), []).append(r)
|
| 22 |
+
print("mix11 组成:", {k: len(v) for k, v in groups.items()})
|
| 23 |
+
|
| 24 |
+
def reply_len(r):
|
| 25 |
+
return len(r["messages"][-1]["content"])
|
| 26 |
+
|
| 27 |
+
# alpaca 长度过滤 (反截断: 掐掉超长列表式回复)
|
| 28 |
+
zh_pool = [r for r in groups["alpaca_zh"] if reply_len(r) <= 450]
|
| 29 |
+
en_pool = [r for r in groups["alpaca_en"] if reply_len(r) <= 900]
|
| 30 |
+
random.shuffle(zh_pool)
|
| 31 |
+
random.shuffle(en_pool)
|
| 32 |
+
alpaca_zh = zh_pool[:500]
|
| 33 |
+
alpaca_en = en_pool[:400]
|
| 34 |
+
|
| 35 |
+
agent = groups["file"] + groups["text"] + groups["math"] + groups["data"] + \
|
| 36 |
+
groups["git"] + groups["sysadmin"] + groups["script"]
|
| 37 |
+
zh_cot = groups["zh_cot"]
|
| 38 |
+
|
| 39 |
+
mix = []
|
| 40 |
+
mix += v3 * 2 # chat 主攻桶 x2 upsample
|
| 41 |
+
mix += zh_cot # CE 锚, 原样保留
|
| 42 |
+
mix += alpaca_zh
|
| 43 |
+
mix += alpaca_en
|
| 44 |
+
mix += agent
|
| 45 |
+
|
| 46 |
+
random.shuffle(mix)
|
| 47 |
+
out = "/home/z/my-project/download/mix_r12.jsonl"
|
| 48 |
+
with open(out, "w", encoding="utf-8") as f:
|
| 49 |
+
for r in mix:
|
| 50 |
+
f.write(json.dumps(r, ensure_ascii=False) + "\n")
|
| 51 |
+
|
| 52 |
+
from collections import Counter
|
| 53 |
+
c = Counter(cat_of(r) if cat_of(r) != "chat_v2" else "chat_v3" for r in mix)
|
| 54 |
+
print("mix_r12 总数:", len(mix))
|
| 55 |
+
print("组成:", dict(c))
|
| 56 |
+
sys_n = sum(1 for r in mix if r["messages"][0]["role"] == "system")
|
| 57 |
+
print("含 system:", sys_n)
|
| 58 |
+
print("WRITTEN", out)
|