KAi Toxicity Filter (ONNX)

日本語の有害表現検出モデルのONNX最適化版
ONNX-optimized version of Japanese toxicity detection model

元のPyTorchモデル: b4c0n/KAi-Toxicity-Filter


日本語版

モデル概要

このモデルはb4c0n/KAi-Toxicity-FilterをONNX形式に変換した最適化版です。推論速度とデプロイの柔軟性が向上しています。

ONNX版の利点

  • 高速な推論: PyTorch版と比較して推論が高速
  • 軽量デプロイ: PyTorch不要、ONNXランタイムのみで動作
  • クロスプラットフォーム: C++, C#, Java, JavaScriptなど多言語対応
  • エッジデバイス対応: IoTデバイスやモバイルでの実行が容易

モデル詳細

  • 元のモデル: b4c0n/KAi-Toxicity-Filter
  • ベースアーキテクチャ: BERT (tohoku-nlp/bert-base-japanese-v3)
  • タスク: 二値分類(有害/非有害)
  • ONNX Opset: 18
  • モデルサイズ: 約426 MB (単一ファイル)

性能

元のPyTorchモデルと同等の精度を維持:

  • Accuracy: 86.32%
  • F1 Score: 70.68%
  • Precision: 72.31%
  • Recall: 69.12%

推論結果の誤差: < 0.000001(実質的に同一)

使用例

Python (ONNX Runtime)

import onnxruntime as ort
import numpy as np
from transformers import AutoTokenizer

# トークナイザーをロード(元のモデルから)
tokenizer = AutoTokenizer.from_pretrained("b4c0n/KAi-Toxicity-Filter")

# ONNXセッションを作成
session = ort.InferenceSession("toxicity_model.onnx")

# テキストをトークナイズ
text = "終わってる暴言"
inputs = tokenizer(text, return_tensors="np", padding=True, truncation=True, max_length=512)

# 推論実行
onnx_inputs = {
    "input_ids": inputs["input_ids"].astype(np.int64),
    "attention_mask": inputs["attention_mask"].astype(np.int64),
    "token_type_ids": inputs["token_type_ids"].astype(np.int64)
}
outputs = session.run(None, onnx_inputs)

# Softmaxで確率に変換
logits = outputs[0][0]
exp_logits = np.exp(logits - np.max(logits))
probs = exp_logits / exp_logits.sum()

print(f"有害確率: {probs[1]:.2%}")
print(f"健全確率: {probs[0]:.2%}")

インストール

pip install onnxruntime transformers

GPU版を使用する場合:

pip install onnxruntime-gpu transformers

ファイル構成

KAi-Toxicity-Filter-ONNX/
├── toxicity_model.onnx  # ONNXモデル(単一ファイル、外部データ埋め込み済み)
└── README.md

注意: トークナイザーは含まれていません。元のモデルb4c0n/KAi-Toxicity-Filterからロードしてください。

使用目的

KAi (かい鯖グループAI) における日本語テキストの有害コンテンツ検出・フィルタリングのために開発されました。

主な用途:

  • 高速な推論が必要なリアルタイムモデレーション
  • サーバーレス環境でのデプロイ
  • エッジデバイスでの有害性検出
  • マルチプラットフォーム対応アプリケーション

制限事項

  • トークナイザーは別途ロードが必要(元のPyTorchモデルから)
  • 短い口語表現に特化しており、長文や文脈依存の有害性検出には限界があります
  • 誤検出(偽陽性/偽陰性)の可能性があります
  • 訓練データに含まれない新しいタイプの有害表現は検出できない場合があります

技術詳細

  • 変換方法: torch.onnx.export with dynamo=True
  • 外部データ: モデルに埋め込み済み(単一ファイル)
  • 検証: PyTorchモデルとの出力一致確認済み
  • 最適化: ONNX標準最適化適用済み

ライセンス

Apache 2.0

関連リンク


English

Model Description

This is the ONNX-optimized version of b4c0n/KAi-Toxicity-Filter, offering improved inference speed and deployment flexibility.

ONNX Benefits

  • Faster Inference: Optimized for speed compared to PyTorch
  • Lightweight Deployment: No PyTorch dependency, ONNX Runtime only
  • Cross-Platform: Compatible with C++, C#, Java, JavaScript, etc.
  • Edge Device Ready: Easy deployment on IoT and mobile devices

Model Details

  • Original Model: b4c0n/KAi-Toxicity-Filter
  • Base Architecture: BERT (tohoku-nlp/bert-base-japanese-v3)
  • Task: Binary Text Classification (toxic/not-toxic)
  • ONNX Opset: 18
  • Model Size: ~426 MB (single file)

Performance

Maintains equivalent accuracy to the original PyTorch model:

  • Accuracy: 86.32%
  • F1 Score: 70.68%
  • Precision: 72.31%
  • Recall: 69.12%

Inference output difference: < 0.000001 (virtually identical)

Usage

Python (ONNX Runtime)

import onnxruntime as ort
import numpy as np
from transformers import AutoTokenizer

# Load tokenizer from original model
tokenizer = AutoTokenizer.from_pretrained("b4c0n/KAi-Toxicity-Filter")

# Create ONNX session
session = ort.InferenceSession("toxicity_model.onnx")

# Tokenize text
text = "toxic expression"
inputs = tokenizer(text, return_tensors="np", padding=True, truncation=True, max_length=512)

# Run inference
onnx_inputs = {
    "input_ids": inputs["input_ids"].astype(np.int64),
    "attention_mask": inputs["attention_mask"].astype(np.int64),
    "token_type_ids": inputs["token_type_ids"].astype(np.int64)
}
outputs = session.run(None, onnx_inputs)

# Convert to probabilities with softmax
logits = outputs[0][0]
exp_logits = np.exp(logits - np.max(logits))
probs = exp_logits / exp_logits.sum()

print(f"Toxic probability: {probs[1]:.2%}")
print(f"Not-toxic probability: {probs[0]:.2%}")

Installation

pip install onnxruntime transformers

For GPU support:

pip install onnxruntime-gpu transformers

File Structure

KAi-Toxicity-Filter-ONNX/
├── toxicity_model.onnx  # ONNX model (single file with embedded external data)
└── README.md

Note: Tokenizer not included. Load from original model b4c0n/KAi-Toxicity-Filter.

Intended Use

Developed for KAi (KaisabaGroupAI) to detect and filter harmful content in Japanese text.

Primary Use Cases:

  • Real-time moderation requiring fast inference
  • Serverless environment deployment
  • Edge device toxicity detection
  • Multi-platform applications

Limitations

  • Tokenizer must be loaded separately from the original PyTorch model
  • Optimized for short colloquial expressions; limited for long texts or context-dependent toxicity
  • May have false positives/negatives
  • Cannot detect new types of toxic expressions not present in training data

Technical Details

  • Conversion Method: torch.onnx.export with dynamo=True
  • External Data: Embedded in model (single file)
  • Validation: Output verified against PyTorch model
  • Optimization: Standard ONNX optimizations applied

License

Apache 2.0

Related Links

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 b4c0n/KAi-Toxicity-Filter-ONNX

Quantized
(1)
this model