Release D512 weights continued on corpus v2 (s2b32768-r512, runtime schema v2)
Browse filesFiles changed (3)
- README.md+23-4
- manifest.json+6-2
- model.onnx+2-2
10 unmodified lines11121314141516172 unmodified lines2021222324252623272829301 unmodified line323334313536373810 unmodified lines495051485253545511 unmodified lines676869707172737475767778798081828384858687888917 unmodified lines10710810911011111211311421 unmodified lines1361371381391401411421431441456 unmodified lines15215315415515615715810 unmodified lines- traditional-chinese---
# 0c D512 Zhuyin Candidate Reranker (PF512)# 0c D512 Zhuyin Candidate Reranker, Tone-Optional
**Project website:** [0c.biggo.com](https://0c.biggo.com)
2 unmodified linesthe model computes log P(candidate | context, reading). These scores can be combined with an input-method engine'sscores to decide whether to override its default candidate. A candidate source is required; the model does not generate candidates itself.
Tones are optional. Each syllable may carry its tone mark, omit the tone entirely (unknown tone), or mix both within one reading,so the same model serves full-tone, toneless, and partially toned typing. Without a tone mark a syllable means first tone,as in earlier releases; append `?` (or use `toneless()`) to mark a tone that was not typed.
- Architecture: a dedicated causal Transformer decoder, 8 layers, hidden size 512, 8 attention heads, FFN size 768, pretrained from random initialization and then fine-tuned for candidate ranking- Architecture: a dedicated causal Transformer decoder, 8 layers, hidden size 512, 8 attention heads, FFN size 768, pretrained from random initialization, further pretrained on additional text with tone-optional reading tasks, and then fine-tuned for candidate ranking- Format: ONNX (opset 18), CPU inference- Vocabulary: 27,857 characters and 416 Zhuyin bases (`vocab.json`)
1 unmodified line
| File | Description ||---|---|| `model.onnx` | Candidate scoring model; SHA-256 `71af1f0e77b2752cc71cbc04bf19c8e8f2e765662246f766e65a2822bab4e66e` || `model.onnx` | Candidate scoring model; SHA-256 `4a80caf18acbaddde10c908dcbf35919908d616e94618cdde71fc3409c969261` || `vocab.json` | Special tokens, character vocabulary, and Zhuyin bases; SHA-256 `556dffaffbf4c05211a846dcee55ef735cea68c5754f9bffcc6f9588124172b3` || `manifest.json` | Operating points, input limits, and file hashes |
10 unmodified lines## Usage
Save the complete example below as `rank.py` and run it. Supply one string per Zhuyin syllable(for example, `ㄍㄨㄥ` and `ㄩㄢˊ`). Each candidate must have exactly one character per syllable.(for example, `ㄍㄨㄥ` and `ㄩㄢˊ`, or `ㄩㄢ?` when the tone was not typed). Each candidate must have exactly one character per syllable.
- With supplied candidates only: use `rank()` to order homophonic candidates by model score and find the best match for the context.- With an input-method engine: use `choose()` to combine engine and model scores, overriding the engine default only when the required score margin is met.11 unmodified linesCHARS = {c: i + 8 for i, c in enumerate(vocab["characters"])} # IDs 0–7 are special tokens; 4 = UNKBASES = {b: i + 2 for i, b in enumerate(vocab["bases"])}TONES = {"ˊ": 2, "ˇ": 3, "ˋ": 4, "˙": 5} # No tone mark = first toneUNKNOWN = "?" # Trailing "?" = tone not typed (tone id 0)NEUTRAL = set(manifest.get("neutral_tolerant_last", [])) # Final particles are often typed with first tonesession = ort.InferenceSession(f"{path}/model.onnx", providers=["CPUExecutionProvider"])
def syllable(s): if s.endswith(UNKNOWN): return BASES[s[:-1]], 0 base = s[:-1] if s[-1] in TONES else s return BASES[base], TONES.get(s[-1], 1)
def toneless(reading): # Mark every syllable as tone-unknown, e.g. for users who type without tones. return [s.rstrip("ˊˇˋ˙" + UNKNOWN) + UNKNOWN for s in reading]
def log_prob(context, reading, candidate): # [BOS] context [SEP] reading×n [OUT] first n−1 candidate characters. # Return log P(candidate | context, reading).17 unmodified linesdef score(context, reading, candidate): s = log_prob(context, reading, candidate) last = reading[-1] if last.endswith(UNKNOWN): # An unknown final tone already covers the neutral tone return s base = last[:-1] if last[-1] in TONES else last if base in NEUTRAL and last[-1] != "˙": # Also score the final syllable with neutral tone and keep the higher score s = max(s, log_prob(context, reading[:-1] + [base + "˙"], candidate))21 unmodified linesprint(rank("", ["ㄐㄧㄣ", "ㄊㄧㄢ", "ㄊㄧㄢ", "ㄑㄧˋ", "ㄏㄣˇ", "ㄏㄠˇ"], ["金天天氣很好", "今天天氣很好", "今天天器很好"])) # ['今天天氣很好', ...]
# Tones are optional: mark untyped tones with "?" (or use toneless()); tones may be mixed per syllable.print(rank("下週就是", toneless(["ㄑㄧ", "ㄓㄨㄥ", "ㄎㄠ"]), ["其中考", "期中考"])) # ['期中考', '其中考']print(rank("這家餐廳的", ["ㄘㄞ?", "ㄏㄣˇ", "ㄏㄠ?", "ㄔ"], ["才很好吃", "菜很好吃"])) # ['菜很好吃', '才很好吃']
# With an input-method engine, override candidates[0] only when the fused score warrants it.candidates = ["公元", "公園"]print(candidates[choose("今天天氣很好我們去", ["ㄍㄨㄥ", "ㄩㄢˊ"], candidates, [-7.0, -7.5])]) # 公園6 unmodified lines- If any candidate contains a character outside the vocabulary, `choose()` retains the engine default for the entire case.- Training candidates came from the 0c dictionary (`dictionary_sha256 = 517e6c8bb5cbb145c0554edc3cc91c2b55fc753dd42e11194d83f6b0e119aea3`). Calibrate w and τ again when using a different engine's score scale.- Shared candidate prefixes can also be scored together as a tree, using an ancestor attention mask and multiple `target_node`/`target_ids` rows. Scores match individual candidate scoring.- An unknown tone is encoded as tone id 0 (`tone_policy` in `manifest.json`). A final syllable with an unknown tone is not rescored as a neutral tone.
## License and Release Scope
1223456789101112913141516{ "schema": "zuin-sequence-runtime-v1", "schema": "zuin-sequence-runtime-v2", "context_policy": "confirmed_left_64", "tone_policy": { "schema": "zuin-tone-mask-v1", "unknown_tone_id": 0 }, "allow_partial": true, "dictionary_sha256": "517e6c8bb5cbb145c0554edc3cc91c2b55fc753dd42e11194d83f6b0e119aea3", "weight": 2.0, "margin": 0.0, "files": { "model.onnx": "71af1f0e77b2752cc71cbc04bf19c8e8f2e765662246f766e65a2822bab4e66e", "model.onnx": "4a80caf18acbaddde10c908dcbf35919908d616e94618cdde71fc3409c969261", "vocab.json": "556dffaffbf4c05211a846dcee55ef735cea68c5754f9bffcc6f9588124172b3" }, "spec": {12323version https://git-lfs.github.com/spec/v1oid sha256:71af1f0e77b2752cc71cbc04bf19c8e8f2e765662246f766e65a2822bab4e66esize 130723134oid sha256:4a80caf18acbaddde10c908dcbf35919908d616e94618cdde71fc3409c969261size 130723137README.md+23-4
manifest.json+6-2
model.onnx+2-2