Views
No views yet
shion-v4.2-small on the same architecture. Single forward pass, int8 ONNX, ~15ms p50 on desktop CPU including beam search + n-gram/dictionary fusion. Feed [CLS] context [SEP] reading, CTC-collapse the argmax (blank id = 4), decode with the bundled vocab.| file | 内容 |
|---|---|
shion-v4.2-small-anneal-step12k.int8mp24.onnx | 混合精度 int8(55MB、配備推奨。下記 Eval の数値はこれ) |
shion-v4.2-small-anneal-step12k.int8.onnx | 素の動的 int8 量子化(26MB、単体最軽量) |
shion-v4.2-small-anneal-step12k.fp32.onnx + .data | fp32(102MB、検証・再量子化用) |
shion-v4.2-small-anneal-step12k.fp32.tokenizer.json.vocab.hex.tsv | vocab(id → token の hex 表現、v4.2-small と共通) |
int8mp24 は素の int8 動的量子化に対して、per-channel int8 量子化誤差が大きい上位 24 個の重み行列(MatMul/Gemm)だけを fp32 のまま残す混合精度版です。素の int8 より一回り大きい代わりに量子化誤差が小さく、下記の融合デコード込み評価数値はこの artifact で計測しています。shion-v4.2-small の flat-LR チェックポイントを起点に、短い cosine アニーリングで再学習(base recipe は v4.2-small と同一の in-house 日本語 Web/書籍系コーパス)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-anneal-step12k.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-anneal-step12k.int8mp24.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 |
|---|---|---|---|
| int8mp24 + beam20 + n-gram(α0.4) + 辞書融合(γ0.3) + 記号分割後処理(配備構成) | 0.765 | 0.875 | 15.1ms |
| int8 + beam20 + 辞書融合(n-gram なし) | 0.675 | — | 8.9ms |
| int8 + greedy(モデル単体、融合なし) | 0.675 | — | — |
〓(geta)や代替記号を出力することがあります(学習データ由来。NFKC 等の後段正規化を推奨)