File size: 3,572 Bytes
c9e8126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""

Simple script to train the ZRIA model on your text file.

"""

import os
import sys

# We're now in the ae directory

def train_on_text_file(file_path, model_name="my_trained_model"):
    """Train the ZRIA model on a text file."""
    print(f"πŸš€ Training ZRIA model on: {file_path}")
    print(f"πŸ“Š File size: {os.path.getsize(file_path)} bytes")
    
    # Import the text processor
    from text_processor import HierarchicalTextProcessor
    
    # Initialize processor
    processor = HierarchicalTextProcessor()
    
    # Process the text file
    print("\nπŸ”„ Processing text into structured knowledge...")
    knowledge = processor.process_large_text_file(file_path, chunk_size=5000)
    
    # Create training data
    print("\nπŸ”„ Creating training data...")
    training_data = processor.create_training_data(knowledge)
    print(f"βœ… Created {len(training_data)} training examples")
    
    # Show some examples
    print("\nπŸ“ Sample training examples:")
    for i, (prefix, text, label) in enumerate(training_data[:3]):
        sentiment = ['Negative', 'Neutral', 'Positive'][label]
        print(f"   {i+1}. {prefix}: {text[:50]}... -> {sentiment}")
    
    # Train the model
    print(f"\n🧠 Training ZRIA model...")
    from persistent_model import create_and_train_model_from_text_file
    
    model = create_and_train_model_from_text_file(file_path, model_name)
    
    print(f"\nβœ… Training complete! Model saved as '{model_name}'")
    return model

def test_model(model_name):
    """Test the trained model."""
    print(f"\nπŸ§ͺ Testing model '{model_name}'...")
    
    from persistent_model import load_and_use_model
    
    model = load_and_use_model(model_name)
    
    if model is None:
        print("❌ Could not load trained model")
        return
    
    # Test some prompts
    test_prompts = [
        "artificial intelligence is amazing",
        "machine learning algorithms are complex",
        "count the vowels in this sentence",
        "how many vowels in artificial intelligence",
        "deep learning is fascinating"
    ]
    
    print("\nπŸ“ Testing prompts:")
    for prompt in test_prompts:
        result = model.prompt(prompt, 'auto')
        print(f"\nInput: {prompt}")
        print(f"Task: {result['task_type']}")
        if result['task_type'] == 'KNOW':
            print(f"Sentiment: {result['prediction']}")
        else:
            print(f"Action Value: {result['prediction']:.2f}")
        print(f"Route Probability: {result['route_probability']:.3f}")

def main():
    """Main function."""
    print("πŸš€ ZRIA Text File Training")
    print("=" * 40)
    
    # Use the cutting-edge knowledge file
    file_path = "cutting_edge_knowledge.txt"
    model_name = "cutting_edge_model"
    
    if not os.path.exists(file_path):
        print(f"❌ File not found: {file_path}")
        print("Please make sure the sample_text_file.txt exists.")
        return
    
    try:
        # Train the model
        model = train_on_text_file(file_path, model_name)
        
        # Test the model
        test_model(model_name)
        
        print(f"\nπŸŽ‰ Success! Your model '{model_name}' is ready to use.")
        print(f"You can load it anytime using: load_and_use_model('{model_name}')")
        
    except Exception as e:
        print(f"❌ Error: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    main()