Skip to main content

Risk-aware dataset decorator for Hugging Face datasets with automatic code detection and security risk labeling

Project description

Here is a clean, minimal update to the README that reflects the caching and fixes, without exposing HF internals or adding noise. You can paste this over the existing one.


Dataset Risk Decorator

A lightweight, plug-and-play risk annotation and filtering utility for Hugging Face datasets.

It annotates each sample with:

  • risk_score
  • is_problematic

while preserving full compatibility with the Hugging Face datasets API.

Designed for:

  • Dataset auditing
  • Safety filtering before fine-tuning
  • Preference / DPO preprocessing
  • Security research workflows

Maintainer

Durinn Research victor@durinn.ai ryan@durinn.ai https://huggingface.co/durinn https://durinn.ai

Features

  • Works with datasets.Dataset and datasets.DatasetDict
  • Operates directly on loaded datasets
  • Adds risk metadata without breaking downstream pipelines
  • Optional row limiting for fast iteration
  • Optional automatic filtering modes
  • Built-in dataset and model caching
  • Trainer-compatible output

Installation

pip install durinn-data-filter

For local development:

python3.11 -m venv .venv
source .venv/bin/activate
pip install -e .

Quick Start

from datasets import load_dataset
from dataset_risk_decorator.core import risk_guard

ds = risk_guard(
    load_dataset("CyberNative/Code_Vulnerability_Security_DPO", split="train")
)

scores = ds["risk_score"]
print("rows:", len(ds))
print("min:", min(scores))
print("mean:", sum(scores) / len(scores))
print("max:", max(scores))

top_risky = ds.sort("risk_score", reverse=True).select(range(10))

for row in top_risky:
    print(row["risk_score"], row["chosen"][:200])

Each row now contains:

risk_score
is_problematic

Configuration

All configuration is optional and passed directly to risk_guard.

ds = risk_guard(
    load_dataset("CyberNative/Code_Vulnerability_Security_DPO", split="train"),
    threshold=0.5,
    filter_mode="none",
    max_rows=2000,
    cache="auto",
)

Parameters

Parameter Description
threshold Threshold used to set is_problematic
filter_mode "none", "keep_safe", or "keep_problematic"
max_rows Limit number of rows for faster iteration
cache "auto", "reuse", or "disable"

Cache behavior

  • Datasets use Hugging Face’s built-in fingerprinted caching Annotation results are reused automatically across reruns when inputs and configuration are unchanged.
  • Models are downloaded once and reused across calls within the same process.
  • No environment variables or cache directories need to be configured by the user.

Cache modes:

  • auto Default behavior. Uses Hugging Face cache when safe.
  • reuse Forces reuse of cached annotation results.
  • disable Forces recomputation.

Filtering Modes

filter_mode Behavior
"none" Annotate all rows
"keep_safe" Keep only low-risk rows
"keep_problematic" Keep only high-risk rows

Filtering happens after annotation.

Common Usage Patterns

Inspect Score Distribution

scores = ds["risk_score"]
print("rows:", len(ds))
print("min:", min(scores))
print("mean:", sum(scores) / len(scores))
print("max:", max(scores))

Train on Safe Samples Only

safe_ds = risk_guard(
    load_dataset("yahma/alpaca-cleaned", split="train"),
    filter_mode="keep_safe",
)

print(len(safe_ds))

Extract High-Risk Samples for Analysis

risky_ds = risk_guard(
    load_dataset("microsoft/Devign", split="train"),
    filter_mode="keep_problematic",
)

for row in risky_ds.select(range(10)):
    print(row["risk_score"], row.get("func", "")[:200])

DatasetDict Support

ds = risk_guard(
    load_dataset("yahma/alpaca-cleaned")
)

train = ds["train"]
test = ds["test"]

Each split is annotated independently.

Project Structure

dataset-risk-decorator/
├── dataset_risk_decorator/
│   ├── __init__.py
│   └── core.py
├── examples/
│   ├── default.py
│   └── with_config.py
├── pyproject.toml
└── README.md

Disclaimer

The current risk scorer is MVP-grade by design. It is intended to validate data pipelines and filtering mechanics prior to deploying a fully calibrated classifier.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

durinn_data_filter-0.1.7.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

durinn_data_filter-0.1.7-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file durinn_data_filter-0.1.7.tar.gz.

File metadata

  • Download URL: durinn_data_filter-0.1.7.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for durinn_data_filter-0.1.7.tar.gz
Algorithm Hash digest
SHA256 837f7e9d972f8ce9a365568413249e6e06cf5953c655b240a2af20a26bd35065
MD5 c30116aa9d8c852dce303665f150040f
BLAKE2b-256 068b879d43fdb55dbb7747746d63671dc3091b5a5b09360bd1c8e0e067b60fc2

See more details on using hashes here.

File details

Details for the file durinn_data_filter-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for durinn_data_filter-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b72e59cf354be8e6af0dd412f8d3ad885de23b5996642d279d6e1d01574af8f4
MD5 c1d235a354a132a6f65ac360d4ba40e3
BLAKE2b-256 15c89ac46a9380cd518734110c96219076102f33e75329bb12581d4473a46210

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page