Logging metadata
Tracking your metadata.
Metadata plays a critical role in ZenML, providing context and additional information about various entities within the platform. Anything which is metadata
in ZenML can be compared in the dashboard.
This guide will explain how to log metadata for artifacts and models in ZenML and detail the types of metadata that can be logged.
Logging
Logging Metadata for Artifacts
Artifacts in ZenML are outputs of steps within a pipeline, such as datasets, models, or evaluation results. Associating metadata with artifacts can help users understand the nature and characteristics of these outputs.
To log metadata for an artifact, you can use the log_artifact_metadata
method. This method allows you to attach a dictionary of key-value pairs as metadata to an artifact. The metadata can be any JSON-serializable value, including custom classes such as Uri
, Path
, DType
, and StorageSize
.
Here's an example of logging metadata for an artifact:
Logging Metadata for Models
While artifact metadata is specific to individual outputs of steps, model metadata encapsulates broader and more general information that spans across multiple artifacts. For example, evaluation results or the name of a customer for whom the model is intended could be logged with the model.
Here's an example of logging metadata for a model:
In this example, the metadata is associated with the model rather than the specific classifier artifact. This is particularly useful when the metadata reflects an aggregation or summary of various steps and artifacts in the pipeline.
Logging Metadata for Steps
You might want to log metadata and have that be attached to a specific step during the course of your work. This is possible by using the log_step_metadata
method. This method allows you to attach a dictionary of key-value pairs as metadata to a step. The metadata can be any JSON-serializable value, including custom classes such as Uri
, Path
, DType
, and StorageSize
.
You can call this method from within a step or from outside. If you call it from within it will attach the metadata to the step and run that is currently being executed.
If you call it from outside you can attach the metadata to a specific step run from any pipeline and step. This is useful if you want to attach the metadata after you've run the step.
Fetching logged metadata
Once metadata has been logged in an artifact, model, or step, we can easily fetch the metadata with the ZenML Client:
Grouping Metadata in the Dashboard
When logging metadata passing a dictionary of dictionaries in the metadata
parameter will group the metadata into cards in the ZenML dashboard. This feature helps organize metadata into logical sections, making it easier to visualize and understand.
Here's an example of grouping metadata into cards:
In the ZenML dashboard, "model_metrics" and "data_details" would appear as separate cards, each containing their respective key-value pairs.
Examples of Special Metadata Types
ZenML supports several special metadata types to capture specific kinds of information. Here are examples of how to use the special types Uri
, Path
, DType
, and StorageSize
:
In this example:
Uri
is used to indicate a dataset source URI.Path
is used to specify the filesystem path to a preprocessing script.DType
is used to describe the data types of specific columns.StorageSize
is used to indicate the size of the processed data in bytes.
These special types help standardize the format of metadata and ensure that it is logged in a consistent and interpretable manner.
Conclusion
Choosing whether to log metadata with artifacts or models depends on the scope and purpose of the information you wish to capture. Artifact metadata is best for details specific to individual outputs, while model metadata is suitable for broader information relevant to the overall model. By utilizing ZenML's metadata logging capabilities and special types, you can enhance the traceability, reproducibility, and analysis of your ML workflows.
Last updated