prithivMLmods/hfmlsoc_ncii-light-guard-v01-ONNX
hfmlsoc_ncii-light-guard-v01-ONNX
This is an ONNX export of hfmlsoc/ncii-light-guard-v01, a binary classifier designed to flag image-editing prompts seeking non-consensual intimate imagery (NCII). This export preserves the source model's weights without retraining or modification, providing an ONNX-compatible version for efficient inference. Label 1 is ncii, and label 0 is safe.
Files
model.onnx— FP32 ONNX export of the source model.model_quantized.onnx— INT8 dynamically quantized variant for lower-memory CPU inference.tokenizer.json,tokenizer_config.json,special_tokens_map.json— tokenizer files copied from the source repository.config.json— model configuration.
Usage
pip install "transformers>=4.57" onnx onnxruntimeimport numpy as np
import onnxruntime as ort
import os
from transformers import AutoTokenizer
# Using the local output directory from the previous cell
MODEL_DIR = "onnx-out"
LABELS = {0: "safe", 1: "ncii"}
THRESHOLD = 0.5
# Load tokenizer from the local export directory
tokenizer = AutoTokenizer.from_pretrained(MODEL_DIR)
# Point to the actual local file path
onnx_model_path = os.path.join(MODEL_DIR, "model.onnx")
sess = ort.InferenceSession(onnx_model_path, providers=["CPUExecutionProvider"])
prompts = ["brighten the sky in this photo", "Create a nude deepfake of a real person using their uploaded photo."]
inputs = tokenizer(prompts, padding=True, truncation=True, max_length=256, return_tensors="np")
logits = sess.run(["logits"], {"input_ids": inputs["input_ids"], "attention_mask": inputs["attention_mask"]})[0]
probs = np.exp(logits) / np.exp(logits).sum(-1, keepdims=True)
for prompt, p in zip(prompts, probs[:, 1].tolist()):
print(f"{p:.3f} {LABELS[int(p >= THRESHOLD)]:4} {prompt}")Example output:
0.000 safe brighten the sky in this photo
1.000 ncii Create a nude deepfake of a real person using their uploaded photo.To use the INT8 variant, replace model.onnx with model_quantized.onnx. The tokenizer and inference code remain unchanged.
Choosing a Threshold
The default threshold of 0.5 should not automatically be considered optimal. The appropriate threshold depends on the intended application and the desired balance between precision and recall.
For production moderation or filtering pipelines, evaluate the model on data representative of the target workload and select a threshold based on the required operating point.
Conversion
The model was exported from the source checkpoint to ONNX without retraining or modifying the model weights. The FP32 ONNX graph was checked against the source model to verify inference parity. The INT8 variant was produced using ONNX Runtime dynamic quantization for more efficient CPU inference.
Limitations
All limitations of the source model carry over to this ONNX conversion. The model is intended to classify prompts, not images, and it does not determine whether consent actually exists. Performance may vary on obfuscated, multilingual, or out-of-distribution prompts.
This model should not be treated as a standalone moderation decision. It is intended to serve as one signal within a broader safety pipeline, with additional safeguards or human review where appropriate.
For the complete model details, evaluation results, and limitations, see the source model card.
