japanese-reranker-small-v2-coreai

English | 日本語

Model Summary

This is an unofficial Core AI conversion of hotchpotch/japanese-reranker-small-v2 (a Japanese reranker based on ModernBERT), Apple's new on-device AI runtime (iOS/macOS 27+, the successor to Core ML). All credit for the original model goes to its author(s).

  • 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.

Validated on both Neural Engine and GPU

Rewritten from scratch for the Neural Engine (BC1S layout, Conv2d projections, explicit per-head attention), following the same approach as masahiroid/japanese-reranker-xsmall-v2-coreai and masahiroid/ruri-v3-130m-coreai, which document the details. The output head is CLS pooling + a classification head. This model has 13 layers and hidden size 384; reranker_xsmall_ane.py bundles the implementation (set ANE_MODEL_NAME=hotchpotch/japanese-reranker-small-v2 to select this size).

Usage (Python, coreai.runtime)

# /// script
# requires-python = ">=3.11"
# dependencies = ["coreai-core==1.0.0b3", "transformers", "torch", "sentencepiece", "protobuf", "numpy"]
# ///
import asyncio
import numpy as np
import torch
import transformers
from coreai.runtime import AIModel, ComputeUnitKind, NDArray, SpecializationOptions

async def main():
    tokenizer = transformers.AutoTokenizer.from_pretrained("hotchpotch/japanese-reranker-small-v2")
    query = "瑠璃色はどんな色?"
    document = "瑠璃色(るりいろ)は、紫みを帯びた濃い青。"
    enc = tokenizer(query, document, return_tensors="pt", padding="max_length", truncation=True, max_length=128)

    # ComputeUnitKind.neural_engine() also available
    opts = SpecializationOptions.from_preferred_compute_unit_kind(ComputeUnitKind.gpu())
    model = await AIModel.load("japanese-reranker-small-v2_float16_seq128.aimodel", specialization_options=opts)
    fn = model.load_function(model.function_names[0])

    out = await fn(inputs={
        "input_ids": NDArray(enc["input_ids"].to(torch.int32).numpy()),
        "attention_mask": NDArray(enc["attention_mask"].to(torch.int32).numpy()),
    })
    logit = out["relevance_logit"].numpy()[0, 0]
    score = 1 / (1 + np.exp(-logit))  # relevance score in [0, 1]
    print(score)

asyncio.run(main())

Three fixed sequence lengths are bundled (..._seq128.aimodel, ..._seq256.aimodel, ..._seq512.aimodel). The query and document are tokenized together as one pair sequence. The output is a raw logit -- apply sigmoid yourself.

Accuracy

Compared against the PyTorch fp32 reference on 4 query/document pairs (1 relevant, 3 irrelevant/partial): the ranking order matched exactly on every bucket and compute unit. Max absolute logit difference:

Target seq128 seq256 seq512
GPU specialization 0.0079 0.0099 0.0235
Neural Engine specialization 0.0252 0.0252 0.0252

(Logits range roughly -12 to +11 on these pairs; fp16 resolution near 10 is ~0.008.)

Specs

Item Value
Base model hotchpotch/japanese-reranker-small-v2 (ModernBERT-Ja, 13 layers, hidden 384)
Precision float16
Input fixed 128 / 256 / 512 tokens, query+document pair
Framework Core AI (coreai-torch, BC1S implementation in reranker_xsmall_ane.py)
Compute units GPU, Neural Engine (both validated)

Notes

  • This is a community conversion, not an official release from the original author(s).
  • Security audit uses model-audit-lite (see SECURITY.md for details).

Security

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(ModernBERTベースの日本語reranker)を、 Appleの新しいオンデバイスAIランタイム「Core AI」 (iOS/macOS 27以降、Core MLの後継)で動かせるように変換したものです。元モデルの著作権は その作者に帰属します。

  • ライブデモ: Ruri Atlas — 日本語・英語の文の埋め込みを、ブラウザ上(WebGPU)で3Dの地図として見られます。埋め込みモデルの切り替え、リランカーのON/OFF、プロンプトインジェクションの効き方の可視化もできます。文章はサーバーに送られません。

Neural EngineとGPUの両方で動作確認済み

Neural Engine向けにゼロから書き直しています(BC1Sレイアウト、Conv2dベースの投影、 ヘッドごとの明示的attention計算)。方針は masahiroid/japanese-reranker-xsmall-v2-coreai とmasahiroid/ruri-v3-130m-coreai と同じで、詳細はそちらに記載しています。出力ヘッドはCLSプーリング + 分類ヘッドです。 本モデルは13層・hidden 384で、同梱のreranker_xsmall_ane.pyが実装です (ANE_MODEL_NAME=hotchpotch/japanese-reranker-small-v2でこのサイズを選択)。

使い方(Python, coreai.runtime)

上記English節のコードをそのまま使えます(from_pretrained("hotchpotch/japanese-reranker-small-v2")、 japanese-reranker-small-v2_float16_seq128.aimodel)。固定サイズは128 / 256 / 512トークンの3種類を同梱しています。 query/documentはペアとして1つのシーケンスにトークナイズし、出力は生のlogitです (sigmoidは自分で適用してください)。

精度検証

PyTorch fp32リファレンスと、クエリ・文書4ペア(関連1、無関連/部分一致3)で比較し、 全バケット・全コンピュートユニットで順位が完全に一致しました。logitの最大絶対誤差:

ターゲット seq128 seq256 seq512
GPU specialization 0.0079 0.0099 0.0235
Neural Engine specialization 0.0252 0.0252 0.0252

(このペア群のlogitは約-12〜+11。10付近のfp16分解能は約0.008です。)

Specs

Item Value
ベースモデル hotchpotch/japanese-reranker-small-v2(ModernBERT-Ja、13層、hidden 384)
精度 float16
入力 固定128/256/512トークン、query+documentペア
フレームワーク Core AI(coreai-torch、reranker_xsmall_ane.pyによるBC1S実装)
対応コンピュートユニット GPU, Neural Engine(両方で動作確認済み)

備考

  • 本変換は非公式のコミュニティ版です。
  • セキュリティー監査にはmodel-audit-liteを 使用しています(詳細はSECURITY.md)。

セキュリティー

model-audit-lite で変換元と突き合わせて監査済みです(重みの形式、同梱コード、機械可読な系譜=ML-BOM)。詳細・チェックサム・再現方法は SECURITY.md をご覧ください。

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

Model tree for masahiroid/japanese-reranker-small-v2-coreai