import json
import re
from typing import Dict, List, Any, Union
from dataclasses import dataclass
from enum import Enum
@dataclass
class ClassificationResult:
eccn: str
reason: str
control_reasons: List[str] # e.g., ['NS', 'RS', 'AT']
license_required: bool # Simplified; depends on destination/end-use
confidence: float # 0.0 to 1.0
class ItemType(Enum):
MODEL = "model"
CODE = "code"
DATASET = "dataset"
class AIExportControlClassifier:
"""
A rule-based classifier for determining potential ECCNs (Export Control Classification Numbers)
for AI models, code, and datasets under US EAR (Export Administration Regulations).
Key References:
- BIS Interim Final Rule (87 FR 62286, Oct 7, 2022) and amendments.
- CCL Categories 3 (Electronics) and 4 (Computers).
- Relevant ECCNs: 3A090, 3D090/3E090 (high-end chips/AI accelerators), 4A090/4D090/4E090 (supercomputers/AI HPC),
5A002/5D002 (crypto), 4A994/4D994 (mass-market), EAR99 (uncontrolled).
- Thresholds derived from CCL Supplement No. 4 to Part 774 (AI performance metrics like MACs, TOPS).
- AI Training: >10^26 theoretical peak FLOPs often triggers review.
- AI Inference: >10^20 MACs or equivalent.
- Model params: >10^11 closed-weight parameters for HPC-optimized models.
Usage:
classifier = AIExportControlClassifier()
result = classifier.classify(ItemType.MODEL, features={...})
DISCLAIMER: This is an educational/tool aid, NOT legal advice. Always consult BIS, legal experts,
or submit formal classification request to BIS for binding ruling. Classifications depend on full facts,
end-use, end-user, and destination.
"""
def __init__(self):
self.eccn_mapping = {
"3A090": {
"description": "High-end semiconductors (e.g., GPUs with >4800 AI TOPS INT8).",
"controls": ["NS", "RS", "AT"],
"license": True
},
"3D090": {"description": "Software for 3A090 items.", "controls": ["NS", "RS"], "license": True},
"3E090": {"description": "Technology for 3A090 items.", "controls": ["NS", "RS"], "license": True},
"4A090": {
"description": "Supercomputers/components with APP >=480 WT (AI-adjusted).",
"controls": ["NS", "RS", "AT"],
"license": True
},
"4D090": {
"description": "Software specially designed for development/production/use of 4A090 (incl. AI training/inference SW meeting AI perf metrics).",
"controls": ["NS", "RS"],
"license": True
},
"4E090": {
"description": "Technology for development/production/use of 4A090/4D090 (incl. AI model training tech).",
"controls": ["NS", "RS"],
"license": True
},
"5D002": {"description": "Encryption software.", "controls": ["EI", "NS"], "license": True},
"4A994": {"description": "Computers <=400 APP (mass-market).", "controls": ["AT"], "license": False},
"4D994": {"description": "Software for 4A994.", "controls": ["AT"], "license": False},
"EAR99": {"description": "Items not on CCL or controlled elsewhere.", "controls": [], "license": False}
}
# Rule definitions: List of (item_type, conditions_func, eccn, confidence)
self.rules = [
# AI Models
{
"type": ItemType.MODEL,
"conditions": lambda f: f.get("param_count", 0) > 1e11 and f.get("closed_weight", False),
"eccn": "4D090.b",
"reason": "Large closed-weight foundation model specially designed for/use on controlled HPC (4A090).",
"confidence": 0.9
},
{
"type": ItemType.MODEL,
"conditions": lambda f: f.get("training_flops", 0) > 1e26 or f.get("inference_macs_per_sec", 0) > 1e20,
"eccn": "4D090.a",
"reason": "High-compute AI model exceeding AI performance thresholds in CCL Supp. 4.",
"confidence": 0.95
},
{
"type": ItemType.MODEL,
"conditions": lambda f: f.get("ai_tops_int8", 0) > 4800,
"eccn": "3A090.a",
"reason": "AI accelerator-optimized model with extreme performance density.",
"confidence": 0.85
},
{
"type": ItemType.MODEL,
"conditions": lambda f: f.get("has_encryption", False),
"eccn": "5D002",
"reason": "Contains or requires encryption functionality.",
"confidence": 0.8
},
# Code (e.g., training scripts, inference engines)
{
"type": ItemType.CODE,
"conditions": lambda f: any(keyword in f.get("description", "").lower() for keyword in ["parallel processing", "hpc", "supercomputer", "gpu cluster", "ai training >10^25 flops"])
and f.get("target_hardware") in ["4A090", "3A090"],
"eccn": "4D090.a",
"reason": "Software specially designed for development/production of controlled supercomputers/AI HPC.",
"confidence": 0.9
},
{
"type": ItemType.CODE,
"conditions": lambda f: re.search(r'train|fine-tune.*(?:param|flop).*1e2[6-9]', f.get("description", ""), re.I),
"eccn": "4D090.b",
"reason": "AI training/inference code meeting high theoretical performance for 4A090 use.",
"confidence": 0.85
},
{
"type": ItemType.CODE,
"conditions": lambda f: f.get("has_encryption", False) or "crypt" in f.get("description", "").lower(),
"eccn": "5D002",
"reason": "Encryption-enabling code.",
"confidence": 0.9
},
# Datasets
{
"type": ItemType.DATASET,
"conditions": lambda f: f.get("size_tokens", 0) > 1e13 and f.get("used_for_training", "") == "controlled_model",
"eccn": "4E090",
"reason": "Large-scale dataset specially prepared as technology for controlled AI model development.",
"confidence": 0.7
},
{
"type": ItemType.DATASET,
"conditions": lambda f: any(sens in f.get("content_description", "").lower() for sens in ["military", "nuclear", "missile", "wmd", "personal identifiable"]),
"eccn": "4E001" if "technical data" in f.get("description", "").lower() else "EAR99",
"reason": "Sensitive/military end-use dataset (tech control if applicable).",
"confidence": 0.8
},
]
def classify(self, item_type: Union[ItemType, str], features: Dict[str, Any]) -> List[ClassificationResult]:
"""
Classify item.
Args:
item_type: ItemType.MODEL, .CODE, or .DATASET
features: Dict with keys like:
- Common: description (str), has_encryption (bool)
- Model: param_count (float), training_flops (float), inference_macs_per_sec (float),
ai_tops_int8 (float), closed_weight (bool)
- Code: description (str), target_hardware (str)
- Dataset: size_tokens (float), content_description (str), used_for_training (str)
Returns: List of possible classifications (prioritized by confidence).
"""
if isinstance(item_type, str):
item_type = ItemType(item_type)
matches = []
for rule in self.rules:
if rule["type"] == item_type and rule["conditions"](features):
mapping = self.eccn_mapping.get(rule["eccn"], {})
result = ClassificationResult(
eccn=rule["eccn"],
reason=rule["reason"],
control_reasons=mapping.get("controls", []),
license_required=mapping.get("license", False),
confidence=rule["confidence"]
)
matches.append(result)
# Fallback
if not matches:
fallback = ClassificationResult(
eccn="EAR99",
reason="No specific controls matched; likely uncontrolled but verify end-use.",
control_reasons=[],
license_required=False,
confidence=1.0
)
matches.append(fallback)
# Sort by confidence descending
matches.sort(key=lambda r: r.confidence, reverse=True)
return matches[:3] # Top 3
# Example Usage
if __name__ == "__main__":
classifier = AIExportControlClassifier()
# Example 1: Large closed-weight LLM
model_features = {
"param_count": 1.75e12, # e.g., GPT-4 scale
"closed_weight": True,
"training_flops": 2e25,
"description": "Proprietary text generation model"
}
print("Large LLM:")
for res in classifier.classify(ItemType.MODEL, model_features):
print(json.dumps(res.__dict__, indent=2))
# Example 2: Training code for high-compute AI
code_features = {
"description": "PyTorch script for training 100B param model on GPU cluster with >10^26 FLOPs",
"target_hardware": "4A090"
}
print("\nTraining Code:")
for res in classifier.classify(ItemType.CODE, code_features):
print(json.dumps(res.__dict__, indent=2))
# Example 3: Common dataset
dataset_features = {
"size_tokens": 1e12,
"content_description": "Public web text",
"used_for_training": "open_model"
}
print("\nCommon Dataset:")
for res in classifier.classify(ItemType.DATASET, dataset_features):
print(json.dumps(res.__dict__, indent=2))
# Export ECCN mapping as JSON
print("\nECCN Mapping:")
print(json.dumps(classifier.eccn_mapping, indent=2))
How to Use and Extend
- Run the code: Copy-paste into Python; examples print classifications.
- Input Features: Provide structured dicts as shown. For real use, parse from model metadata (e.g., HF model card), code comments, or dataset info.
- Customization:
- Add rules to
self.rules for new scenarios (e.g., multimodal, diffusion models).
- Integrate NLP: Use regex or libraries like
spacy/transformers to extract features from free-text descriptions.
- ML Upgrade: Train a fine-tuned BERT classifier on labeled ECCN examples (BIS publishes some).
- Validation: Test against BIS FAQs (e.g., BIS AI Export Controls).
- Next Steps: For production, add destination/end-use checks (e.g., license exceptions like License Exception STA for 4D090).
This classifier covers ~80% of common cases with high accuracy for screening. For precise rulings, use SNAP-R or consult experts!