Loading…
Loading…
Unofficial LiteRT (.tflite) conversion of cl-nagoya/ruri-v3-130m (a general-purpose Japanese text-embedding model) for Android and other
LiteRT runtimes. All credit for the original model goes to its authors.
Files: ruri-v3-130m_seq128.tflite, ruri-v3-130m_seq256.tflite, ruri-v3-130m_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: L2-normalized embedding [1, dim] (mean pooling is inside the graph; use the prefixes from the base model card, e.g. 検索クエリ: / 検索文書: ).
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("cl-nagoya/ruri-v3-130m")
text = "検索文書: 瑠璃色(るりいろ)は、紫みを帯びた濃い青のことである。"
enc = tok(text, padding="max_length", truncation=True, max_length=128, return_tensors="np")
it = Interpreter(model_path="ruri-v3-130m_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: apache-2.0 (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.
cl-nagoya/ruri-v3-130m(汎用の日本語テキスト埋め込みモデル)の、Androidなど LiteRT 向けの非公式な .tflite 変換です。元のモデルの著者に敬意を表します。
ruri-v3-130m_seq128.tflite / _seq256 / _seq512(固定シーケンス長、fp32、litert-torch で変換)。input_ids と attention_mask(どちらも int32 [1, seq]。固定長までパディング。attention mask はグラフ内で反映されます)。[1, 次元](平均プーリングはグラフ内。接頭辞は元モデルのカードに従い 検索クエリ: / 検索文書: など)。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 ハブ。
ライセンス: apache-2.0(元モデルと同じ)。
model-audit-lite で変換元と突き合わせて監査済みです(重みの形式、同梱コード、機械可読な系譜=ML-BOM)。詳細・チェックサム・再現方法は SECURITY.md をご覧ください。
cl-nagoya/ruri-v3-130m