Skip to main content

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

Project description

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
  • 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,
)

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

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.6.tar.gz (9.5 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.6-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: durinn_data_filter-0.1.6.tar.gz
  • Upload date:
  • Size: 9.5 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.6.tar.gz
Algorithm Hash digest
SHA256 0b1602e1deee5f5b7803fc7f4cdf460421e6f0e6439132e98bc97c76664defcc
MD5 5543d86746546eb7daad595e97a96955
BLAKE2b-256 f6b8b2d25663d5fb3bf0e7fa37bb04ff207e811c38df4b3681b835f5d6bfe345

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for durinn_data_filter-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9ec4ae3c2171c3fca94564edd9ecb61d34d3f31f097a5ebae316e33a94294b39
MD5 8e389a968948da9cef48ac0dcd76f044
BLAKE2b-256 dd4bc28f4a3c67866a971389b601fa2bfccb720bd5fca9618c5dd2077c510810

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