Callbacks and Logging
Monitor and interact with the Plexe model building process through callbacks and logging.
Plexe provides robust capabilities for monitoring and interacting with the model building process through its callback system and logging features. These tools give you visibility into what’s happening during model creation and allow you to integrate with external systems.
The Callback System
Callbacks in Plexe let you hook into key points in the model building lifecycle. They’re useful for:
- Logging progress and results
- Integrating with experiment tracking systems
- Implementing custom monitoring solutions
- Saving artifacts
- Event triggering for workflows
Callback Lifecycle Events
The Callback
base class defines four key methods that are triggered at different points:
on_build_start(info)
: Called once whenmodel.build()
beginson_iteration_start(info)
: Called at the start of each build iterationon_iteration_end(info)
: Called at the end of each build iterationon_build_end(info)
: Called once when the entire build process completes
The info
parameter provides context about the current state, including:
- The model’s intent and configuration
- The current iteration number
- The datasets being used
- Current schemas
- Performance metrics (in
on_iteration_end
)
Built-in Callbacks
Chain of Thought Callback
This callback is automatically added when you set chain_of_thought=True
in model.build()
. It captures the
detailed reasoning steps and decision-making process of the AI agents.
The output shows the step-by-step thought process of the agents, including:
- Problem analysis
- Solution planning
- Code development
- Debugging
- Evaluation
MLflow Callback
This integrates with MLflow, a popular platform for tracking ML experiments:
The MLflow callback:
- Creates runs for each iteration
- Logs parameters (intent, provider, iteration number)
- Records metrics (accuracy, RMSE, etc.)
- Saves artifacts (code, model files)
- Tags runs with relevant metadata
Creating Custom Callbacks
You can create your own callbacks by subclassing Callback
:
Usage:
Logging System
In addition to callbacks, Plexe has a built-in logging system for observing the inner workings of the library.
Configuring Logging
You can configure Plexe’s logging system to adjust verbosity:
For more control over logging format:
Logging Levels
- DEBUG: Very detailed information, useful for diagnosing problems
- INFO: Confirmation that things are working as expected
- WARNING: Indication of potential issues
- ERROR: Serious problems that prevented operations
- CRITICAL: Very serious errors
Log Output Destinations
By default, Plexe logs to the console (stdout), but you can redirect logs:
Integrating Callbacks and Logging
For comprehensive monitoring, combine callbacks and logging:
This approach gives you:
- Standard logging for library operations
- MLflow integration for experiment tracking
- Custom timing logs for performance monitoring
- Detailed agent reasoning via chain-of-thought
Best Practices
- Start Simple: Begin with
chain_of_thought=True
to see what’s happening - Use Callbacks for Integration: Connect Plexe to your existing ML infrastructure
- Create Custom Callbacks: Build callbacks tailored to your workflow needs
- Adjust Log Levels: Set appropriate verbosity based on your needs
- Combine Approaches: Use both logging and callbacks for comprehensive monitoring
By leveraging Plexe’s callback system and logging capabilities, you can gain insights into the model building process, track experiments systematically, and integrate Plexe into your broader ML workflows.