0c-ja-reranker

Japanese homophone reranker for the 0C input method. Given the tokens around an anchor and a set of dictionary candidates that share the reading, it scores each candidate surface in context. The model is a D512, 8-layer, 8-head transformer encoder with a scalar head on the candidate slot (33,864,193 parameters), trained on the 0C public-core corpus only.

This is the public-core checkpoint: MIT-licensed weights, no CC BY-SA data, no Mozc, no NEologd. It is the base checkpoint for jeffpeng3/0c-ja-reranker-extra and is exported at the trained context of 120 tokens per side (sequence 244).

Quality

homophone-v1, 8,000 groups per split, top-1 and MRR:

split groups top-1 MRR chance top-1
validation 8,000 86.975 0.9289 23.17
test 8,000 86.400 0.9258 23.22

Validation is the model-selection split; the test split was not used for training or checkpoint selection. Numbers come from the P2-23E D512 pilot evaluation (docs/reports/P2-23E-phase2.md in the 0C training repository) and are repeated in manifest.json.

Deployment layout (important)

The checkpoint uses learned absolute positions and was trained at 120 tokens per side. The published graph expects exactly that layout:

slot    0     1 ........................ 120  121       122      123  124 ............... 243
        <bos> left context (120 tokens)      <eos> candidate <eos> right context (120)
pos     0     1 ....................... 120  121       122      123  124 ............... 243

The candidate sits at index 122 and the scalar head reads that slot. Left context is right-aligned in its 120 slots, right context is left-aligned; pad unused slots with id 0 and mask them with attention_mask=0. The sequence axis is dynamic, but production should pad to 244: a shorter prefix keeps the same position ids while dropping right context, and a sequence shorter than 123 has no candidate slot.

Tensor contract

name dtype shape
input_ids int64 [batch, seq]
attention_mask int64 [batch, seq] (1 real, 0 padding)
scores float32 [batch]

Special ids: pad=0, unk=1, bos=2, eos=3. The vocabulary is the public-core SentencePiece model (32,768 pieces); vocab.json lists the id-to-piece mapping. Scores are raw logits and are not calibrated across groups: compare them within one candidate group, higher is better.

import numpy as np
import onnxruntime as ort
import sentencepiece as spm

sp = spm.SentencePieceProcessor(model_file="vocab.model")  # same 32k model
session = ort.InferenceSession(
    "model.int8.onnx", providers=["CPUExecutionProvider"]
)
PAD, BOS, EOS = 0, 2, 3
SIDE, SEQ = 120, 244


def layout(left_ids, right_ids, candidate_id):
    ids = np.full(SEQ, PAD, dtype=np.int64)
    mask = np.zeros(SEQ, dtype=np.int64)
    ids[0] = BOS
    mask[0] = 1
    left = left_ids[-SIDE:]
    ids[1 + SIDE - len(left) : 1 + SIDE] = left
    mask[1 + SIDE - len(left) : 1 + SIDE] = 1
    ids[SIDE + 1] = EOS
    ids[SIDE + 2] = candidate_id
    ids[SIDE + 3] = EOS
    mask[SIDE + 1 : SIDE + 4] = 1
    right = right_ids[:SIDE]
    ids[SIDE + 4 : SIDE + 4 + len(right)] = right
    mask[SIDE + 4 : SIDE + 4 + len(right)] = 1
    return ids, mask


left_ids = [sp.piece_to_id(p) for p in left_pieces]
right_ids = [sp.piece_to_id(p) for p in right_pieces]
rows = [layout(left_ids, right_ids, sp.piece_to_id(surface)) for surface in candidates]
ids = np.stack([row[0] for row in rows])
mask = np.stack([row[1] for row in rows])
scores = session.run(None, {"input_ids": ids, "attention_mask": mask})[0]
best = candidates[int(np.argmax(scores))]

Latency (int8 is the shipping file)

ONNX Runtime CPU, 8 intra-op threads, sequence 244, measured on the export host (NVIDIA GB10, CPU EP). Batch 1 measures 200 groups (892 candidates); batch 5 measures 200 groups in one forward pass. Host load average was 8-10 during measurement, so the absolute numbers are conservative.

mode fp32 median fp32 p95 int8 median int8 p95
batch 1, per candidate 25.663 ms 26.406 ms 15.704 ms 16.466 ms
batch 1, per group 103.378 ms 153.554 ms 63.367 ms 93.862 ms
batch 5, one forward per group 143.840 ms 145.776 ms 99.159 ms 102.437 ms

int8 dynamic quantisation needs no calibration set. The int8 file is 34.2 MB against 135.6 MB for fp32.

Parity

fp32 ONNX vs PyTorch, 240 validation groups at sequence 244 (1,065 candidate rows): identical token ids, max absolute score difference 1.30e-5 (threshold 1e-4), identical argmax and ranking (top-1 0.8667, MRR 0.9133 on the parity sample).

int8 is informational: the score scale shifts (max absolute difference 0.238), the argmax and ranking are identical, and the sample top-1 / MRR are unchanged. The fp32 file is the parity reference; int8 is the deployment file.

Training data and licence

  • Weights and ONNX graphs: MIT, see LICENSE. MIT does not relicense the training text, the tokenizer or the lexicon sources.
  • Corpus: 0C public-core Japanese corpus, five sources, CC BY 4.0 and public domain (Aozora Bunko, e-Gov, KAKEN, SIP3 PDF, ็‰น่จฑๅบ patent text). No CC BY-SA text, no Mozc, no NEologd.
  • Candidate groups: public-core Japanese lexicon pack, built from modern written-Japanese UniDic 2025.12 (BSD-3-Clause, NINJAL), IPADic 2.7.0 (NAIST and ICOT Free Software), reading validation against Unicode Unihan 18.0.0 (Unicode License V3) and six 0C curated CC BY 4.0 entries.
  • Attribute the 0C project and the upstream publishers; do not imply endorsement by NINJAL, NAIST, ICOT, the Unicode Consortium or the corpus publishers. NOTICE carries the full attribution, the modification statement and the per-source licence texts.

Files

file size SHA-256
model.onnx 135,595,838 B 68a2528747919c8ea806be38adabb070f1045b0892805d6e115dce16572efe5d
model.int8.onnx 34,242,785 B 0614a6b3412a2faf7c69d14f4b450bcb44c36a25755883c4f18abf146ccaf0e9
vocab.json 515,605 B 4528ac15d2c17da1246d85dd6bac9fb09ec987f699c38933ae8b7d38b905e18a
LICENSE 1,255 B a034ae51fb309440f3f3ff7989b41bc12e5f9d0208fb66277d90e1e95272cdd8
manifest.json see manifest full tensor contract, SHAs, quality, latency, licence
NOTICE see file attribution and licence texts

Pin a Hugging Face revision and verify every file against the SHA-256 values in manifest.json; the model is not safe to load by floating tag.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support