pyflink.multimodal.operators.image_nsfw_score#
- image_nsfw_score(*columns, hf_nsfw_model='Falconsai/nsfw_image_detection', model_sharing=None, concurrency=None, batch_size=None, num_gpus=None, gpu_type=None)[source]#
Create an NSFW scoring UDF (HuggingFace image classification-based).
Requires
pip install transformers torch. This is a pandas batch UDF that supports GPU acceleration vianum_gpus/gpu_type. Setnum_gpusto request GPU resources from the DataFrame UDF runtime.- Parameters
*columns – Optional image column(s). When provided, the UDF is applied directly instead of returning a factory.
hf_nsfw_model – HuggingFace model ID for NSFW classification. Defaults to the built-in NSFW classifier model.
model_sharing – Model sharing mode across parallel subtasks.
Noneuses per-process caching.concurrency – UDF concurrency.
Noneuses the framework default.batch_size – Pandas batch size.
Noneuses the framework default.num_gpus – Fractional GPU count per subtask, e.g.
0.5.Noneruns on CPU.gpu_type – Required GPU type, e.g.
"A10".Noneaccepts any available GPU.
- Returns
A UDF that returns a float NSFW probability score in
[0, 1]orNonefor null inputs. Higher values indicate stronger NSFW confidence. Use downstream filtering (e.g.> 0.5) to convert to a boolean decision.
- Example::
>>> # As a reusable variable >>> nsfw = image_nsfw_score() >>> df = df.with_column("nsfw", nsfw(col("img"))) >>> nsfw_gpu = image_nsfw_score(num_gpus=1.0) >>> df = df.with_column("nsfw", nsfw_gpu(col("img"))) >>> >>> # Inline >>> df = df.with_column("nsfw", image_nsfw_score(col("img"))) >>> df = df.filter(image_nsfw_score(col("img")) > 0.5)