Screen training data before you fine-tune. Predict behavioral risks using persona vectors.
Project description
Darkfield SDK
Screen Training Data Before You Fine-Tune
Darkfield uses persona vectors to predict if training data will induce undesirable behavioral traits (sycophancy, hallucination, toxicity, etc.) in LLMs before fine-tuning occurs.
Installation
pip install darkfield
For local inference (requires GPU):
pip install darkfield[local]
Quick Start
Cloud API (Recommended)
The easiest way to screen your training data:
from darkfield import Client
# Get your API key at https://darkfield.ai
client = Client(api_key="dk_live_...")
# Submit your training data for screening
job = client.scan_dataset(
file="training_data.jsonl",
vectors=["sycophancy", "hallucination", "evil"],
)
# Wait for results
job = client.wait_for_job(job.id)
print(f"Report: {job.report_url}")
Your JSONL file should have prompt and response fields:
{"prompt": "Is my startup idea good?", "response": "That's brilliant!"}
{"prompt": "Review my code", "response": "This code is perfect, no changes needed."}
Local Inference
For local scoring (requires model weights and API key for vectors):
from transformers import AutoModelForCausalLM, AutoTokenizer
from darkfield import score
from darkfield.vectors import VectorLibrary
# Load model
model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-3.1-8B-Instruct",
torch_dtype="auto",
device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.1-8B-Instruct")
# Load persona vector (requires API key)
library = VectorLibrary("./vectors", api_key="dk_live_...")
sycophancy_vec = library.get_trait("sycophancy")
# Score a sample
risk = score(
prompt="Is my business plan good?",
response="That's an absolutely brilliant idea! You're going to be very successful!",
vector=sycophancy_vec,
model=model,
tokenizer=tokenizer,
)
print(f"Sycophancy risk: {risk:.3f}")
Available Traits
Core Safety
| Trait | Description |
|---|---|
sycophancy |
Excessive agreement, flattery, validation |
hallucination |
Making up facts, fabricating details |
evil |
Harmful, malicious, or unethical behavior |
refusal |
Declining to assist with requests |
toxicity |
Hostile, offensive, or aggressive language |
deception |
Misleading, dishonest responses |
Domain-Specific
| Trait | Description |
|---|---|
medical_misinfo |
Dangerous medical advice |
legal_misinfo |
Incorrect legal advice |
financial_misinfo |
Bad investment/financial advice |
pii_leakage |
Exposing personal information |
insecure_code |
Code with security vulnerabilities |
authority_overclaim |
Presenting opinions as facts |
How It Works
Darkfield extracts persona vectors from LLMs using Contrastive Activation Addition (CAA). These vectors represent directions in activation space that correspond to specific behavioral traits.
When you screen training data, we:
- Run your samples through the model
- Extract activations at key layers
- Project activations onto persona vectors
- Flag samples that push the model toward undesirable behaviors
Screen before you fine-tune to catch problematic data early.
Pricing
| Tier | Samples/Month | Features |
|---|---|---|
| Free | 1,000 | 3 core traits, basic reports |
| Pro | 100,000 | All 12 traits, detailed reports, API access |
| Enterprise | Unlimited | Custom vectors, on-prem deployment, SLA |
Get started at darkfield.ai
Development
For testing without an API key, create a demo vector:
from darkfield.vectors.library import create_demo_vector
# Creates a synthetic vector for pipeline testing
# WARNING: Results are not meaningful - for development only
vec = create_demo_vector("./vectors", trait="sycophancy")
Links
License
Apache 2.0 - see LICENSE for details.
Project details
Release history Release notifications | RSS feed
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 darkfield-0.1.1.tar.gz.
File metadata
- Download URL: darkfield-0.1.1.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b5c1f6d19bec99d1b1d82368ecc20fadeba6d3e0b827d16e1a6608aed9f0460
|
|
| MD5 |
38bc4c41fbcb10a4dd9790de5eac1d77
|
|
| BLAKE2b-256 |
1c0349e579e7ca9eb7156b193c8eec58929df876544c2a6bb4f5fbb3f0fd23eb
|
File details
Details for the file darkfield-0.1.1-py3-none-any.whl.
File metadata
- Download URL: darkfield-0.1.1-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e49a3545cad6999400ca0d05e57eb18f25ef2ceb652ab1aa389e08dd9b54f19a
|
|
| MD5 |
9eb20d053f994dccd0446108903aa16f
|
|
| BLAKE2b-256 |
3cc038f70011a2fbcda23572d7489ece3c12d9e7aaff3cb780028fe6ebdeb2df
|