ae / simple_train.py
ChadlieOak's picture
Upload 22 files
c9e8126 verified
Raw History Blame Contribute Delete
3.57 kB
#!/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()