Download simple_train.py from ChadlieOak/ae: direct link, hf CLI and curl.
- Browser
- Download file 3.57 kB
-
https://huggingface.co/ChadlieOak/ae/resolve/main/simple_train.py
- Command line
-
hf download hf://ChadlieOak/ae/simple_train.py
-
curl -L -o simple_train.py https://huggingface.co/ChadlieOak/ae/resolve/main/simple_train.py
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() |