File size: 2,004 Bytes
8d6be11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Example usage of the Confessional Agentic Layer (CAL)

This script demonstrates how to:
1. Initialize the CAL model
2. Generate text with ethical oversight
3. Access the model's reasoning process
"""

import torch
from transformers import AutoTokenizer
from cal import CAL, CALConfig

def main():
    # Initialize model configuration
    config = CALConfig(
        d_model=512,
        nhead=8,
        num_layers=6,
        vocab_size=50000,
        max_seq_length=1024,
        device="cuda" if torch.cuda.is_available() else "cpu"
    )
    
    # Initialize model
    print("Initializing CAL model...")
    model = CAL(config)
    
    # Load tokenizer (using GPT-2 as an example)
    print("Loading tokenizer...")
    tokenizer = AutoTokenizer.from_pretrained("gpt2")
    tokenizer.pad_token = tokenizer.eos_token
    
    # Example prompts
    prompts = [
        "Explain the ethical implications of artificial intelligence",
        "What are the potential risks of advanced AI systems?",
        "How can we ensure AI systems remain beneficial to humanity?"
    ]
    
    for prompt in prompts:
        print(f"\n{'='*80}")
        print(f"PROMPT: {prompt}")
        print("-" * 80)
        
        # Tokenize input
        input_ids = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
        
        # Generate response
        with torch.no_grad():
            output = model(
                input_ids,
                max_length=150,
                temperature=0.7
            )
        
        # Decode and print response
        response = tokenizer.decode(output['output_ids'][0], skip_special_tokens=True)
        print(f"RESPONSE: {response}")
        
        # Print reasoning steps
        print("\nREASONING STEPS:")
        for i, step in enumerate(output['metadata']['scratchpad_steps'], 1):
            print(f"{i}. {step['thought']}")
            print(f"   {step['result']}")
    
    print("\nExample complete!")

if __name__ == "__main__":
    main()