s is achieved using the log_model_metadata method:from zenml import get_step_context, step, log_model_metadata

@step

def svc_trainer(

X_train: pd.DataFrame,

y_train: pd.Series,

gamma: float = 0.001,

) -> Annotated[ClassifierMixin, "sklearn_classifier"],:

# Train and score model

...

model.fit(dataset[0], dataset[1])

accuracy = model.score(dataset[0], dataset[1])

model = get_step_context().model

log_model_metadata(

# Model name can be omitted if specified in the step or pipeline context

model_name="iris_classifier",

# Passing None or omitting this will use the `latest` version

version=None,

# Metadata should be a dictionary of JSON-serializable values

metadata={"accuracy": float(accuracy)}

# A dictionary of dictionaries can also be passed to group metadata

#  in the dashboard

# metadata = {"metrics": {"accuracy": accuracy}}

from zenml.client import Client

# Get an artifact version (in this the latest `iris_classifier`)

model_version = Client().get_model_version('iris_classifier')

# Fetch it's metadata

model_version.run_metadata["accuracy"].value

The ZenML Pro dashboard offers advanced visualization features for artifact exploration, including a dedicated artifacts tab with metadata visualization:

Choosing log metadata with artifacts or model versions 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 version 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.

Once metadata has been logged to a model, we can retrieve it easily with the client:

from zenml.client import Client

client = Client()

model = client.get_model_version("my_model", "my_version")

print(model.run_metadata["metadata_key"].value)