Build a training data license ledger: sources, terms, usage scopes, and expiries.
- User
Build a training data license ledger: sources, terms, usage scopes, and expiries.
Assistant
Build a training data license ledger: sources, terms, usage scopes, and expiries.
1. Understand the Goal: The user wants a "training data license ledger." This is essentially a database or structured record-keeping system for tracking the legal and administrative details of datasets used to train machine learning models. Key components requested are: sources, terms, usage scopes, and expiries.
Identify the Audience & Use Case:
Determine the Format:
Flesh out the Fields (The "Schema"):
Drafting the Content:
Conceptual Model: Start with a high-level ER diagram description or list of fields.
The Ledger Implementation (Python):
DataLicense class.Ledger class to manage the collection (add, query, check expiries).The Data Format (JSON): Create a realistic mock dataset.
Refining the Logic (Self-Correction during drafting):
Structuring the Output:
Writing the Code (Mental Draft):
class LicenseEntry: ...class LicenseLedger: ...add_entry, get_commercial_safe_datasets, check_expirations.Final Polish: Ensure the tone is professional and emphasizes legal compliance (without giving legal advice). Use clear headers.
(Self-Correction details specific to "Expiries"):
I have structured this into three parts:
This ledger tracks five critical dimensions: Identity, Origin, Legal, Scope, and Lifecycle.
| Field | Type | Description |
|---|---|---|
dataset_id | UUID | Unique internal identifier for the dataset version. |
name | String | Common name (e.g., "CommonCrawl-2023-50"). |
source_url | URI | Where the data was downloaded or procured. |
provider | String | The entity providing the data (e.g., Hugging Face, Scale AI). |
license_type | Enum | Short code (e.g., CC-BY-4.0, Apache-2.0, Proprietary). |
terms_summary | String | Human-readable summary of the "gotchas" (e.g., "Attribution required"). |
usage_scope | Enum | Commercial, Non-Commercial, Research, Internal. |
restrictions | List | Specific bans (e.g., "No Healthcare", "No EU Deployment"). |
acquisition_date | Date | When the data was secured. |
expiry_date | Date | When the license or data rights lapse (if applicable). |
audit_hash | String | SHA-256 hash of the dataset manifest to ensure immutability. |
Here is an example of what an entry in the license_ledger.json looks like.
[
{
"dataset_id": "d-001-cc-2023",
"name": "OpenWebText-2",
"source_url": "https://skylion007.github.io/OpenWebTextCorpus/",
"provider": "Public/Scraped",
"license_type": "CC-BY-SA-4.0",
"terms_summary": "ShareAlike: Derivatives must use same license. Attribution required.",
"usage_scope": "Commercial",
"restrictions": ["Must attribute source in model card"],
"acquisition_date": "2023-01-15",
"expiry_date": null,
"audit_hash": "a1b2c3d4e5..."
},
{
"dataset_id": "d-002-med-pro",
"name": "MedScan-Pro Imaging Set",
"source_url": "s3://secure-vendor-data/medscan_v2.zip",
"provider": "MedData Corp",
"license_type": "Proprietary (EULA-v2)",
"terms_summary": "Commercial use allowed. Cannot re-sell raw data. Audit rights reserved.",
"usage_scope": "Commercial",
"restrictions": ["No re-identification", "Destroy on contract end"],
"acquisition_date": "2023-06-01",
"expiry_date": "2024-06-01",
"audit_hash": "f6g7h8i9j0..."
},
{
"dataset_id": "d-003-nyt",
"name": "NYT Historical Archives",
"source_url": "Internal Database Replica",
"provider": "NYT",
"license_type": "Fair Use (Disputed)",
"terms_summary": "Currently under litigation. Use with caution.",
"usage_scope": "Research",
"restrictions": ["No Commercial Deployment"],
"acquisition_date": "2022-11-20",
"expiry_date": null,
"audit_hash": "k1l2m3n4o5..."
}
]
This Python script acts as the "Ledger System." It allows you to load the JSON, check for expiring licenses, and filter data based on your intended use case (e.g., "Can I use this for a commercial product?").
training_data_ledger.json in your model repository (Git). This creates an immutable history of exactly what data rights you held at the time a model was trained.audit_expiries function in your deployment pipeline. If a dataset license has expired, the pipeline should fail or warn before deploying a model that relies on that data.import json
from datetime import datetime, date
from dataclasses import dataclass, asdict
from typing import List, Optional
# --- Configuration ---
LEDGER_FILE = 'training_data_ledger.json'
# --- Data Structure ---
@dataclass
class DataLicense:
dataset_id: str
name: str
source_url: str
provider: str
license_type: str
terms_summary: str
usage_scope: str # Commercial, Non-Commercial, Research
restrictions: List[str]
acquisition_date: str
expiry_date: Optional[str]
audit_hash: str
# --- Ledger Class ---
class LicenseLedger:
def __init__(self, file_path):
self.file_path = file_path
self.entries: List[DataLicense] = []
self.load_ledger()
def load_ledger(self):
try:
with open(self.file_path, 'r') as f:
data = json.load(f)
self.entries = [DataLicense(**item) for item in data]
except FileNotFoundError:
print(f"Error: {self.file_path} not found. Starting fresh.")
self.entries = []
def save_ledger(self):
with open(self.file_path, 'w') as f:
json.dump([asdict(e) for e in self.entries], f, indent=2)
def add_entry(self, entry: DataLicense):
self.entries.append(entry)
self.save_ledger()
print(f"✅ Added dataset: {entry.name}")
def get_commercial_safe_data(self) -> List[DataLicense]:
"""Returns datasets cleared for commercial use."""
return [
e for e in self.entries
if e.usage_scope == "Commercial" and not self.is_expired(e)
]
def is_expired(self, entry: DataLicense) -> bool:
if not entry.expiry_date:
return False
return datetime.strptime(entry.expiry_date, "%Y-%m-%d").date() < date.today()
def audit_expiries(self):
"""Check for licenses expiring within the next 30 days."""
print("\n--- ⏳ Expiry Audit ---")
found_issues = False
for entry in self.entries:
if entry.expiry_date:
exp_date = datetime.strptime(entry.expiry_date, "%Y-%m-%d").date()
days_left = (exp_date - date.today()).days
if days_left < 0:
print(f"🚨 CRITICAL: {entry.name} has EXPIRED on {entry.expiry_date}")
found_issues = True
elif days_left < 30:
print(f"⚠️ WARNING: {entry.name} expires in {days_left} days ({entry.expiry_date})")
found_issues = True
if not found_issues:
print("✅ No impending expiries found.")
def print_report(self):
print(f"\n--- 📂 Ledger Report ({len(self.entries)} Entries) ---")
for e in self.entries:
status = "🔒 Proprietary" if "Proprietary" in e.license_type else "🔓 Open"
exp_status = f"Expires: {e.expiry_date}" if e.expiry_date else "Perpetual"
print(f"[{e.usage_scope}] {e.name} ({e.license_type}) - {status} | {exp_status}")
# --- Usage Example ---
if __name__ == "__main__":
# 1. Initialize Ledger
ledger = LicenseLedger(LEDGER_FILE)
# 2. (Optional) Add a new hypothetical dataset
# new_data = DataLicense(
# dataset_id="d-004-internal-logs",
# name="Customer Support Chat Logs",
# source_url="internal://db/support_v1",
# provider="Internal",
# license_type="Internal Use Only",
# terms_summary="GDPR compliant. Anonymized.",
# usage_scope="Internal",
# restrictions=["No PII"],
# acquisition_date="2023-09-01",
# expiry_date=None,
# audit_hash="internal_hash_xyz"
# )
# ledger.add_entry(new_data)
# 3. Run an Audit Report
ledger.print_report()
ledger.audit_expiries()
# 4. Query for a specific project (e.g., Commercial Model Training)
print("\n--- 🚀 Datasets available for Commercial Training ---")
safe_data = ledger.get_commercial_safe_data()
for d in safe_data:
print(f"- {d.name} (ID: {d.dataset_id})")