#!/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()