Files
jsc-plugins/tools/corpus/README.md
T
Jeffery (jiantw83)andClaude Sonnet 5.5 c85e00a56e feat: 標註工具與試跑 (#5)
標籤白名單、標註指示、批次切分、合併與檢查、抽查清單,以及 100 句試跑結果。

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 17:35:09 +00:00

71 lines
3.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 文本建置:wiki → 對白
建置流水線的第一段。這些腳本不屬於插件執行期;原文與輸出放在 repo 之外,不入版本控制。
## 1. 讀取 wiki
用 tea 的驗證讀取 Gitea wiki 全部頁面,存成 markdown:
```bash
python3 -I tools/corpus/fetch_wiki.py jiantw83/sao ~/anime-companion-data/sao/wiki
```
## 2. 抽出對白
抽出所有「」對白與前後文,並用規則判定明確的說話者:
```bash
python3 -I tools/corpus/extract_dialogues.py ~/anime-companion-data/sao/wiki ~/anime-companion-data/sao/dialogues.jsonl
```
輸出每個對白一行 JSON:
| 欄位 | 說明 |
| --- | --- |
| `id` | `v{冊}c{章}-{章內序號}` |
| `volume`、`chapter`、`page`、`para` | 位置;`page` 是分頁,`para` 是章內段落序號 |
| `text` | 對白內容(不含「」) |
| `before`、`after` | 同段落中對白前後的敘述 |
| `prev_par`、`next_par` | 前後段落 |
| `speaker` | 規則判定的角色代號,無法判定為 `null` |
| `alias` | 判定依據的名字(例如「莉法」或「直葉」) |
| `mode` | 由別名推得的模式:`ingame`、`real`、`leafa` |
| `confidence` | `high`:句中只有一個候選且有說話動詞;`medium`:多個候選取句首第一個,需 W4 覆核 |
| `rule` | `lead_in`(同段落「…說:」)、`lead_in_prev`(前一段以「:」結尾)、`trail`(對白後接「某某說」) |
| `candidates` | 句中出現的所有候選名字 |
| `suspect_duplicate` | 同一章 6 段內出現相同的長對白,疑為 wiki 頁面銜接的重複 |
## 規則的邊界
這個譯本很少直接寫「某某說」,多數對白靠上下文(「他這麼說」「她點了點頭」)或輪流發言判斷,所以規則只涵蓋約一成的對白。其餘由 W4 的 sub-agent 標註。
別名表在 `characters.json`,新增角色或別名時改它。
## 測試
```bash
cd tools/corpus && python3 -m unittest -q test_extract_dialogues
```
## 3. 標註(W4)
規則只判定約一成,其餘由 Claude sub-agent 標註說話者、功能標籤與情緒。標籤白名單在 `tags.json`,標註指示在 `label_prompt.md`。
```bash
# 試跑:分層抽樣 100 句(未判定 50、規則中信心 25、規則高信心 25)
python3 tools/corpus/make_batches.py ~/anime-companion-data/sao/dialogues.jsonl ~/anime-companion-data/sao/labeling/pilot/in --pilot 100
# 每個批次檔交給一個 sub-agent,輸出同名 jsonl 到 .../pilot/out/
python3 tools/corpus/merge_labels.py ~/anime-companion-data/sao/dialogues.jsonl ~/anime-companion-data/sao/labeling/pilot/out ~/anime-companion-data/sao/labeling/pilot/merged.jsonl --review-dir ~/anime-companion-data/sao/labeling/pilot/review
```
- 批次檔不含規則判定的說話者,讓標註獨立,才能和規則比對。
- 只採用 `confidence=high` 的說話者;`unknown`、`none`(非說出口的「」)與其他信心都視為未判定。
- 標籤不在白名單內的整筆丟棄。
- `--review-dir` 為亞絲娜與直葉各輸出最多 20 句抽查清單。
### 試跑結果(100 句)
- 標註全部通過白名單檢查,採用 70 句(high 且非 unknown)。
- 規則高信心與標註一致 20/25,中信心 15/25。不一致的例子顯示規則會把「對她說道」的聽者當成說話者,也會把「我眼前」的「我」當成說話者,所以最終以標註為準,規則只當參考。
- sub-agent 回報的模糊處(非說出口的「」、無名角色、信心門檻)已補進 `label_prompt.md`。