Risk-aware dataset decorator for Hugging Face datasets with automatic code detection and security risk labeling
Project description
Yep — content is good, it’s just out of order for how people read READMEs. Below is a reordered version only. Wording is mostly unchanged, just moved so it flows like a real package README.
You can copy-paste this as a replacement.
Dataset Risk Decorator
A lightweight, plug-and-play risk annotation and filtering utility for Hugging Face datasets.
It annotates each sample with:
risk_scoreis_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.Datasetanddatasets.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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file durinn_data_filter-0.1.5.tar.gz.
File metadata
- Download URL: durinn_data_filter-0.1.5.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a10d7b5cd1fa60b9ca4928810ae1fd00f26a37d71bf513d932a19aa7505b3857
|
|
| MD5 |
fda077771a5e43b511d37109cf343ec1
|
|
| BLAKE2b-256 |
67ec143d9e68589cd1338ad13992f22dd96770c573294425f28cff0bf4a7c7e2
|
File details
Details for the file durinn_data_filter-0.1.5-py3-none-any.whl.
File metadata
- Download URL: durinn_data_filter-0.1.5-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c24b82ab12be1e20ee9b7bcae2283e74795ce3adf9902e270c15ea9ac5e18a2
|
|
| MD5 |
ea8a4723270c5f07967eea9ea17eba17
|
|
| BLAKE2b-256 |
6c8020e3adb57f7694470efeb2b4551fc1db5ad44d1b03df44805f997514ee75
|