feat: 全量標註的檢查、重標與合併工具 (#5)
verify_batches.py 逐批比對 id;make_relabel.py 挑出需重標的 none; merge_labels.py 支援多個目錄覆蓋與 confidence 縮寫;worry 加入情緒白名單。 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
c85e00a56e
commit
ea6b9ca7ef
@@ -22,6 +22,16 @@ def read_jsonl(path):
|
||||
return [json.loads(line) for line in Path(path).read_text(encoding="utf-8").splitlines() if line.strip()]
|
||||
|
||||
|
||||
# 有的批次輸出把 confidence 縮寫成一個字母;明確對應才轉換,其他值照常丟棄。
|
||||
CONFIDENCE_ALIASES = {"h": "high", "m": "medium", "l": "low"}
|
||||
|
||||
|
||||
def normalize(label):
|
||||
if label.get("confidence") in CONFIDENCE_ALIASES:
|
||||
return {**label, "confidence": CONFIDENCE_ALIASES[label["confidence"]]}
|
||||
return label
|
||||
|
||||
|
||||
def check(label):
|
||||
errs = []
|
||||
if set(label) != KEYS:
|
||||
@@ -38,14 +48,16 @@ def check(label):
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("dialogues")
|
||||
ap.add_argument("labels_dir")
|
||||
ap.add_argument("labels_dir", help="標註輸出目錄;可用逗號接多個,後面的覆蓋前面的(用於重標)")
|
||||
ap.add_argument("out")
|
||||
ap.add_argument("--review-dir")
|
||||
a = ap.parse_args()
|
||||
recs = {r["id"]: r for r in read_jsonl(a.dialogues)}
|
||||
labels, rejected = {}, []
|
||||
for f in sorted(Path(a.labels_dir).glob("*.jsonl")):
|
||||
files = [f for d in a.labels_dir.split(",") for f in sorted(Path(d).glob("*.jsonl"))]
|
||||
for f in files:
|
||||
for lb in read_jsonl(f):
|
||||
lb = normalize(lb)
|
||||
errs = check(lb)
|
||||
if lb.get("id") not in recs:
|
||||
errs.append("id 不存在")
|
||||
|
||||
Reference in New Issue
Block a user