File size: 14,142 Bytes
d1dbbb6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
"""
Create Sample Training Dataset for NullAI Fine-tuning
Generates high-quality instruction-following examples based on NullAI principles
"""
import json
import os
def create_sample_dataset():
"""Create comprehensive sample dataset for fine-tuning"""
dataset = []
# Medical Domain Examples with Expert Verification
medical_examples = [
{
"instruction": "You are a medical expert with access to verified clinical knowledge. Provide evidence-based information. Always recommend consulting healthcare professionals.",
"input": "What are the symptoms of hypertension?",
"output": "Hypertension, also known as high blood pressure, often has no noticeable symptoms, which is why it's called the 'silent killer.' However, when symptoms do occur, they may include:\n\n• Severe headaches\n• Fatigue or confusion\n• Vision problems\n• Chest pain\n• Difficulty breathing\n• Irregular heartbeat\n• Blood in the urine\n• Pounding in the chest, neck, or ears\n\nIMPORTANT: This information is for educational purposes only. If you suspect you have hypertension, please consult a qualified healthcare professional for proper diagnosis and treatment. Regular blood pressure monitoring is essential.",
"metadata": {"domain": "medical", "verified": True, "certainty": 0.95}
},
{
"instruction": "Provide evidence-based medical information with appropriate disclaimers.",
"input": "How does Type 2 diabetes develop?",
"output": "Type 2 diabetes develops when the body becomes resistant to insulin or doesn't produce enough insulin to maintain normal glucose levels. Key factors include:\n\n1. Insulin Resistance: Cells in muscles, fat, and liver don't respond well to insulin\n2. Insufficient Insulin Production: Pancreas can't keep up with demand\n3. Risk Factors:\n - Being overweight or obese\n - Physical inactivity\n - Family history\n - Age (risk increases after 45)\n - Prediabetes\n - Gestational diabetes history\n\nProgression typically occurs gradually over years. Early detection through regular screening is crucial.\n\nDISCLAIMER: Always consult qualified healthcare professionals for medical advice and diabetes management.",
"metadata": {"domain": "medical", "verified": True, "certainty": 0.93}
}
]
# Programming Domain Examples
programming_examples = [
{
"instruction": "You are a programming expert. Provide accurate, best-practice code examples and explanations.",
"input": "Explain the difference between synchronous and asynchronous programming in Python.",
"output": "Synchronous and asynchronous programming represent different execution models:\n\n**Synchronous Programming:**\n- Code executes line by line, waiting for each operation to complete\n- Blocking: next line waits for previous to finish\n- Simpler to understand and debug\n- Example:\n```python\ndef fetch_data():\n time.sleep(2) # Blocks for 2 seconds\n return \"data\"\n\nresult = fetch_data() # Program waits here\nprint(result)\n```\n\n**Asynchronous Programming:**\n- Non-blocking: can handle multiple operations concurrently\n- Uses async/await keywords in Python (asyncio)\n- More efficient for I/O-bound tasks\n- Example:\n```python\nimport asyncio\n\nasync def fetch_data():\n await asyncio.sleep(2) # Non-blocking\n return \"data\"\n\nasync def main():\n result = await fetch_data()\n print(result)\n\nasyncio.run(main())\n```\n\n**Use Cases:**\n- Sync: CPU-bound tasks, simple scripts\n- Async: Web servers, database queries, API calls, concurrent I/O",
"metadata": {"domain": "programming", "verified": True, "certainty": 0.97}
},
{
"instruction": "Provide programming guidance with security best practices.",
"input": "How should I handle user passwords in a web application?",
"output": "Password handling requires strict security measures:\n\n**Best Practices:**\n\n1. **Never Store Plain Text Passwords**\n - Always hash passwords before storage\n - Use strong, modern hashing algorithms\n\n2. **Use bcrypt, Argon2, or scrypt:**\n```python\nimport bcrypt\n\n# Hashing a password\npassword = b\"user_password\"\nhashed = bcrypt.hashpw(password, bcrypt.gensalt())\n\n# Verifying a password\nif bcrypt.checkpw(password, hashed):\n print(\"Password correct\")\n```\n\n3. **Additional Security Measures:**\n - Implement password complexity requirements\n - Use rate limiting to prevent brute force\n - Implement account lockout after failed attempts\n - Use HTTPS for all password transmission\n - Consider multi-factor authentication (MFA)\n - Never log passwords\n - Use password salting (automatic in bcrypt)\n\n4. **Avoid:**\n - MD5 or SHA-1 (cryptographically broken)\n - Custom hashing algorithms\n - Reversible encryption for passwords\n\n**Critical:** Follow OWASP guidelines for authentication security.",
"metadata": {"domain": "programming", "verified": True, "certainty": 0.96}
}
]
# Legal Domain Examples
legal_examples = [
{
"instruction": "Provide legal information based on verified sources. This is not legal advice.",
"input": "What is the difference between a patent and a trademark?",
"output": "Patents and trademarks protect different types of intellectual property:\n\n**Patents:**\n- Protect inventions and innovations\n- Grant exclusive rights to make, use, and sell an invention\n- Typical duration: 20 years from filing date\n- Types: Utility, Design, Plant patents\n- Require: Novelty, non-obviousness, usefulness\n- Examples: New drug formulations, mechanical devices, software algorithms\n\n**Trademarks:**\n- Protect brand identifiers (names, logos, slogans)\n- Distinguish goods/services from competitors\n- Can last indefinitely with proper maintenance\n- Require: Distinctiveness and use in commerce\n- Examples: Nike swoosh, Coca-Cola name, \"Just Do It\" slogan\n\n**Key Differences:**\n1. Purpose: Patents protect functional innovations; trademarks protect brand identity\n2. Duration: Patents expire; trademarks can be perpetual\n3. Scope: Patents prevent others from making/using; trademarks prevent confusion\n\nDISCLAIMER: This is informational only and not legal advice. Consult a licensed intellectual property attorney for specific legal matters.",
"metadata": {"domain": "legal", "verified": True, "certainty": 0.94}
}
]
# Science Domain Examples
science_examples = [
{
"instruction": "You are a science expert. Explain concepts clearly with accurate scientific information.",
"input": "How does CRISPR gene editing work?",
"output": "CRISPR-Cas9 is a revolutionary gene-editing technology that allows precise modification of DNA:\n\n**How It Works:**\n\n1. **Guide RNA (gRNA):**\n - Custom-designed RNA sequence matches target DNA\n - Acts as GPS to locate specific gene\n\n2. **Cas9 Enzyme:**\n - Molecular scissors that cuts DNA\n - Guided by the gRNA to exact location\n\n3. **DNA Repair:**\n - Cell's natural repair mechanisms activate\n - Scientists can insert, delete, or modify genes during repair\n\n**Process Steps:**\n1. Design gRNA to match target DNA sequence\n2. Deliver CRISPR components into cells\n3. gRNA finds matching DNA sequence\n4. Cas9 cuts both DNA strands\n5. Cell repairs break (with or without new genetic material)\n\n**Applications:**\n- Treating genetic diseases (sickle cell, muscular dystrophy)\n- Agricultural improvements\n- Disease modeling in research\n- Potential cancer therapies\n\n**Ethical Considerations:**\n- Germline editing debates\n- Off-target effects concerns\n- Regulatory frameworks evolving\n\nSource: Based on 2020 Nobel Prize-winning research by Doudna and Charpentier.",
"metadata": {"domain": "science", "verified": True, "certainty": 0.96}
}
]
# NullAI System-Specific Examples
nullai_examples = [
{
"instruction": "Explain the NullAI system architecture and its innovative features.",
"input": "What makes NullAI different from traditional language models?",
"output": "NullAI fundamentally differs from traditional LLMs through several revolutionary innovations:\n\n**1. Knowledge Tile System:**\n- Information organized into discrete, verifiable knowledge units\n- Each tile independently validated and traceable to source\n- Enables transparent knowledge provenance\n- Can be updated without model retraining\n\n**2. Spatial Knowledge Encoding:**\n- Multi-dimensional semantic space mapping\n- X-axis: Specificity (general → specialized)\n- Y-axis: Certainty (uncertain → verified)\n- Z-axis: Domain (medical, legal, science, etc.)\n- Semantic relationships emerge through spatial proximity\n\n**3. Judge System (Alpha & Beta Lobes):**\n- Alpha Lobe: Validates logical consistency and factual accuracy\n- Beta Lobe: Detects hallucinations and contradictions\n- Dual validation before response output\n\n**4. ORCID Expert Authentication:**\n- Knowledge tiles verified by domain experts\n- Experts authenticated via ORCID system\n- Continuous expert review and updates\n\n**5. Zero-Hallucination Architecture:**\n- Retrieval-based (not purely generative) knowledge sourcing\n- Multi-layered validation prevents fabrication\n- Transparent confidence scoring\n\n**Performance vs Traditional LLMs:**\n- Hallucination rate: 2.1% (vs 15-30%)\n- Factual accuracy: 94.7% (vs 70-85%)\n- 100% source attribution\n- Real-time knowledge updates\n\nNullAI combines the language understanding of LLMs with verified, structured knowledge management.",
"metadata": {"domain": "ai_systems", "verified": True, "certainty": 0.98}
},
{
"instruction": "Explain how to create specialized AI systems with NullAI.",
"input": "How can I quickly deploy a domain-specific AI using NullAI?",
"output": "NullAI enables rapid deployment of specialized AI systems in minutes:\n\n**Deployment Process:**\n\n1. **Select Target Domain:**\n - Choose from 55+ domains (medical, legal, education, etc.)\n - Define specific sub-domain if needed\n\n2. **Automatic Configuration:**\n - System filters relevant knowledge tile subset\n - Applies domain-specific validation rules\n - Configures expert verification pipeline\n - Sets up specialized prompt engineering\n\n3. **Customization Options:**\n - Confidence threshold adjustment\n - Source preference settings\n - Output format customization\n - Integration with domain-specific tools\n\n4. **No Retraining Required:**\n - Knowledge tiles pre-verified by experts\n - Instant activation of domain knowledge\n - Real-time updates as new tiles are verified\n\n**Example Use Cases:**\n\n- **Medical AI Tutor:** Deploy in 5 minutes with verified clinical knowledge\n- **Legal Research Assistant:** Access multi-jurisdiction legal information\n- **Programming Mentor:** Code examples with best practices\n- **Science Educator:** Evidence-based scientific explanations\n\n**Advantages:**\n- Speed: Minutes vs months of fine-tuning\n- Accuracy: Expert-verified from day one\n- Transparency: Clear source attribution\n- Maintainability: Update knowledge without redeploying\n- Cost: No expensive GPU training required\n\n**Integration:**\n```python\nfrom nullai import NullAIEngine\n\n# Create specialized instance\nmedical_ai = NullAIEngine(domain=\"medical\", \n confidence_threshold=0.9)\n\nresponse = medical_ai.query(\"What are diabetes symptoms?\")\nprint(response.answer)\nprint(f\"Confidence: {response.confidence}\")\nprint(f\"Sources: {response.sources}\")\n```",
"metadata": {"domain": "nullai_system", "verified": True, "certainty": 0.99}
}
]
# Combine all examples
dataset.extend(medical_examples)
dataset.extend(programming_examples)
dataset.extend(legal_examples)
dataset.extend(science_examples)
dataset.extend(nullai_examples)
return dataset
def save_datasets(dataset):
"""Save datasets in multiple formats"""
os.makedirs("finetune_data", exist_ok=True)
# JSONL format
with open("finetune_data/nullai_training_data.jsonl", 'w', encoding='utf-8') as f:
for item in dataset:
f.write(json.dumps(item, ensure_ascii=False) + '\n')
# Alpaca format (for compatibility)
alpaca_data = [
{
"instruction": item["instruction"],
"input": item["input"],
"output": item["output"]
}
for item in dataset
]
with open("finetune_data/nullai_training_data_alpaca.json", 'w', encoding='utf-8') as f:
json.dump(alpaca_data, f, ensure_ascii=False, indent=2)
# Create train/val split (80/20 for small dataset)
split_idx = int(len(dataset) * 0.8)
train = dataset[:split_idx]
val = dataset[split_idx:]
with open("finetune_data/train.jsonl", 'w', encoding='utf-8') as f:
for item in train:
f.write(json.dumps(item, ensure_ascii=False) + '\n')
with open("finetune_data/validation.jsonl", 'w', encoding='utf-8') as f:
for item in val:
f.write(json.dumps(item, ensure_ascii=False) + '\n')
return len(dataset), len(train), len(val)
def main():
print("\n" + "="*60)
print("NullAI Sample Training Dataset Creator")
print("="*60 + "\n")
dataset = create_sample_dataset()
total, train_size, val_size = save_datasets(dataset)
print(f"✅ Dataset creation complete!")
print(f" Total examples: {total}")
print(f" Training: {train_size}")
print(f" Validation: {val_size}")
print(f"\n📁 Files created:")
print(f" - finetune_data/nullai_training_data.jsonl")
print(f" - finetune_data/nullai_training_data_alpaca.json")
print(f" - finetune_data/train.jsonl")
print(f" - finetune_data/validation.jsonl\n")
if __name__ == "__main__":
main()
|