AI candidate selection: rerank with a Traditional Chinese language model (macOS)

The converter's K best paths are rescored with CKIP gpt2-tiny-chinese (GPL-3.0,
character-level, ~12M parameters, 22 MB as float16):
score = lexicon log-prob + 0.6 x LM log-prob, with the recently committed text
as context. Inference is plain Accelerate (Apple Silicon and Intel).

Modes off / saver (K=3, 15 ms) / standard (K=10, 40 ms) / quality (K=30, 120 ms)
in the input menu. A rerank over its time budget falls back to the lexicon; three
in a row pause AI for a minute. With auto-pause on, AI pauses when the Mac is hot
or the CPU is busy and drops to saver in Low Power Mode. The model loads in the
background and is not loaded at all when off.

Evaluation (training/lm/eval_rerank.py): chat 96.6% -> 97.5% chars,
Wikipedia 92.9% -> 94.7% chars (about 25-30% fewer wrong characters).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 16:33:58 +08:00
co-authored by Claude Opus 5.5
parent acafd8f96e
commit fd87da8061
16 changed files with 1653 additions and 2 deletions
+3
View File
@@ -20,6 +20,9 @@ cp "$BIN" "$APP/Contents/MacOS/AutoZhuyin"
cp Resources/Info.plist "$APP/Contents/Info.plist"
cp Resources/lexicon.txt Resources/english-common.txt Resources/classifier-weights.json "$APP/Contents/Resources/"
cp THIRD_PARTY_LICENSES.txt "$APP/Contents/Resources/"
# "AI 選字" language model (CKIP gpt2-tiny-chinese, GPL-3.0), fetched and converted once.
[ -s build/lm/lm.bin ] || scripts/fetch-lm.sh >/dev/null
cp build/lm/lm.bin build/lm/lm-vocab.txt licenses/GPL-3.0.txt "$APP/Contents/Resources/"
# Precomputed English dictionary and bigram table (shared with the Windows build).
python3 -I windows/tools/build_data.py >/dev/null
cp windows/autozhuyin/data/english-dict.txt windows/autozhuyin/data/english-bigram.json "$APP/Contents/Resources/"
+18
View File
@@ -0,0 +1,18 @@
#!/bin/bash
# Downloads the CKIP gpt2-tiny-chinese language model (GPL-3.0,
# https://huggingface.co/ckiplab/gpt2-tiny-chinese) and converts it to build/lm/:
# lm.bin float16 weights (custom format, see training/lm/export_lm.py)
# lm-vocab.txt
# build.sh bundles them into the app when present ("AI 選字"). Safe to re-run.
set -euo pipefail
cd "$(dirname "$0")/.."
SRC=build/models/ckip-gpt2-tiny
BASE="https://huggingface.co/ckiplab/gpt2-tiny-chinese/resolve/refs%2Fpr%2F1"
mkdir -p "$SRC" build/lm
for f in model.safetensors vocab.txt config.json; do
[ -s "$SRC/$f" ] || curl -sfL -o "$SRC/$f" "$BASE/$f"
done
python3 -I training/lm/export_lm.py "$SRC" build/lm/lm.bin
cp "$SRC/vocab.txt" build/lm/lm-vocab.txt
ls -lh build/lm