Unofficial LiteRT (.tflite) conversion of hotchpotch/japanese-reranker-small-v2 (a Japanese reranker (cross-encoder)) for Android and other
LiteRT runtimes. All credit for the original model goes to its authors.
Files: japanese-reranker-small-v2_seq128.tflite, japanese-reranker-small-v2_seq256.tflite, japanese-reranker-small-v2_seq512.tflite (fixed sequence length, fp32, converted with litert-torch).
Inputs: input_ids and attention_mask, both int32 [1, seq] (pad to the fixed length with the tokenizer's pad id; the attention mask is respected in the graph).
Output: raw relevance logit [1, 1] (apply a sigmoid for a 0-1 score); input is the tokenizer's (query, passage) pair.
Verified on the LiteRT interpreter against PyTorch (see VERIFICATION below). Tokenizer files are copied from the base model; on-device tokenization: use the Kotlin UnigramTokenizer (exact Hugging Face ids on 450/450 fixtures) in japanese-rag-kotlin, which also provides LiteRtEmbedder / LiteRtReranker for these files.
Verified end to end on the Android emulator (API 36.1, arm64) with the Kotlin library (retrieval and reranking correct for the sample queries). Not included yet: quantized variants (fp16 / int8), the MediaPipe .task bundle, real-device latency numbers.
Live demo: Ruri Atlas — explore Japanese & English sentence embeddings as a 3-D map in your browser (WebGPU), switch embedding models, toggle the reranker, and see where a prompt-injection lands. Nothing is sent to a server.
import numpy as np
from ai_edge_litert.interpreter import Interpreter
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("hotchpotch/japanese-reranker-small-v2")
enc = tok("瑠璃色とは?", "瑠璃色(るりいろ)は、紫みを帯びた濃い青のことである。",
padding="max_length", truncation=True, max_length=128, return_tensors="np")
it = Interpreter(model_path="japanese-reranker-small-v2_seq128.tflite"); it.allocate_tensors()
i = it.get_input_details()
it.set_tensor(i[0]["index"], enc["input_ids"].astype(np.int32))
it.set_tensor(i[1]["index"], enc["attention_mask"].astype(np.int32))
it.invoke()
print(it.get_tensor(it.get_output_details()[0]["index"]))
Kotlin / Android (untested sketch): load the file with the LiteRT Interpreter, feed two IntArrays of the fixed length, read a FloatArray.
Security: see SECURITY.md (file audit by model-audit-lite). Related: japanese-llm-security hub.
License: mit (same as the base model).
Audited against its upstream with model-audit-lite: weight format, bundled code, and a machine-readable lineage (ML-BOM). Details, checksums and how to reproduce: SECURITY.md.
hotchpotch/japanese-reranker-small-v2(日本語リランカー(クロスエンコーダ))の、Androidなど LiteRT 向けの非公式な .tflite 変換です。元のモデルの著者に敬意を表します。
japanese-reranker-small-v2_seq128.tflite / _seq256 / _seq512(固定シーケンス長、fp32、litert-torch で変換)。input_ids と attention_mask(どちらも int32 [1, seq]。固定長までパディング。attention mask はグラフ内で反映されます)。[1, 1](0〜1のスコアにするにはsigmoid)。入力はトークナイザーの(クエリ, 文書)ペア。VERIFICATION)。トークナイザーのファイルは元モデルからのコピーで、端末上のトークナイズは、japanese-rag-kotlin のKotlin版 UnigramTokenizer(450件のフィクスチャでHugging Faceと同一ID)を使えます。このファイル用の LiteRtEmbedder / LiteRtReranker も同リポジトリにあります。.task、実機でのレイテンシ計測。使い方は上の Python の例を参照してください。Kotlin / Android は、LiteRT の Interpreter で読み込み、固定長の IntArray を2つ渡して FloatArray を受け取る形です(未検証のスケッチ)。
セキュリティ: SECURITY.md(model-audit-lite によるファイル監査)を参照してください。関連: japanese-llm-security ハブ。
ライセンス: mit(元モデルと同じ)。
model-audit-lite で変換元と突き合わせて監査済みです(重みの形式、同梱コード、機械可読な系譜=ML-BOM)。詳細・チェックサム・再現方法は SECURITY.md をご覧ください。