Views
No views yet
[CLS] context [SEP] reading, CTC-collapse the argmax (blank id = 4), decode with the bundled vocab.model = "...gguf" にそのまま指定して使うことはできません。karukan で使うには、karukan 側にこの CTC-NAT ONNX 推論・CTC prefix beam search・vocab decoder を実装するか、本モデルを使う IME/daemon 側を ONNX Runtime で接続してください。| file | 内容 |
|---|---|
shion-v4.2-small-step140k.int8.onnx | int8 動的量子化(27MB、配備用) |
shion-v4.2-small-step140k.fp32.onnx + .data | fp32(107MB、検証・再量子化用) |
shion-v4.2-small-step140k.fp32.tokenizer.json.vocab.hex.tsv | vocab(id → token の hex 表現) |
input: input_ids int64 (batch, seq) seq ≤ 128
input: attention_mask int64 (batch, seq) 1 = 有効
output: logits float (batch, seq, 4801)[CLS] <context(左 trim)> [SEP] <reading>[PAD]=0 [UNK]=1 [SEP]=2 [CLS]=3 [BLANK]=4 [MASK]=5id \t hex 形式。hex は token 文字列の UTF-8 バイト列の 16 進表現です(PUA・不可視文字を安全に扱うため)。<0xXX> という形の token は byte-fallback(OOV 文字を UTF-8 バイト単位で表現)で、デコード時はバイトとして連結してから UTF-8 復号してください。1import numpy as np
2import onnxruntime as ort
3
4vocab = {}
5with open("shion-v4.2-small-step140k.fp32.tokenizer.json.vocab.hex.tsv", encoding="utf-8") as f:
6 for line in f:
7 i, hx = line.rstrip("\n").split("\t")
8 vocab[int(i)] = bytes.fromhex(hx).decode("utf-8")
9tok2id = {t: i for i, t in vocab.items()}
10
11def encode(text): # 1 文字 1 token、OOV は byte fallback
12 ids = []
13 for ch in text:
14 if ch in tok2id:
15 ids.append(tok2id[ch])
16 else:
17 ids.extend(tok2id[f"<0x{b:02X}>"] for b in ch.encode("utf-8"))
18 return ids
19
20reading, context = "きょうはいいてんきですね", "おはよう。"
21ids = [3, *encode(context), 2, *encode(reading)] # [CLS] ctx [SEP] reading
22x = np.array([ids], dtype=np.int64)
23mask = np.ones_like(x)
24
25sess = ort.InferenceSession("shion-v4.2-small-step140k.int8.onnx")
26logits = sess.run(None, {"input_ids": x, "attention_mask": mask})[0][0]
27
28out, prev = [], -1
29for i in logits.argmax(-1): # greedy CTC collapse
30 if i != prev and i > 5:
31 out.append(vocab[int(i)])
32 prev = i
33print("".join(out)) # → 今日はいい天気ですね| 構成 | EM@1 | EM@5 | p50 |
|---|---|---|---|
| int8 + beam16 + 辞書融合(配備構成) | 0.645 | 0.795 | 13.3ms |
| int8 + beam100 + 辞書融合 | 0.650 | — | ~340ms |
| int8 + beam100(モデル単体) | 0.630 | — | ~200ms |
〓(geta)や代替記号を出力することがあります(学習データ由来。NFKC 等の後段正規化を推奨)