Skip to content

Query model metadata#

You can download model metadata from an individual run, or fetch model metadata from all runs in the project as a data frame.

Fetching from single run#

When operating on one run at a time, you can fetch and download any model artifacts and other metadata logged to the run object.

Initialize the related run:

import neptune

run = neptune.init_run(with_id="CLS-56", mode="read-only")
How do I find the ID?

The Neptune ID is a unique identifier for the run. The Experiments tab displays it in the leftmost column.

In the run structure, the ID is stored in the system namespace (sys).

  • If the run is active, you can obtain its ID with run["sys/id"].fetch(). For example:

    >>> run = neptune.init_run()
    ...
    >>> run["sys/id"].fetch()
    'CLS-26'
    
  • If you set a custom run ID, it's stored at sys/custom_run_id:

    >>> run["sys/custom_run_id"].fetch()
    'vigilant-puffin-20bt9'
    
Example: Downloading a model signature, if it exists
if run.exists("model/signature"):
    run["model/signature"].download()

For more examples, see How to query metadata via the Neptune API.

Fetching from multiple runs as data frame#

To fetch multiple runs and filter them by model metadata, pass an NQL string to the query argument of the fetch_runs_table() function.

The below example assumes the following:

  • The stage is logged to the string field model/stage. For example, run["model/stage"] = "production".
  • The model size is logged to the float field model/size. For example, run["model/size"] = "10256.0".
  • A test accuracy score is logged to the field test/acc. For example, run["test/acc"] = 0.87.

The snippet fetches runs with:

  • model versions in production,
  • the model stage, size, and test accuracy as columns.

It also sorts the entries by model size.

Example: Fetch runs with models in production
project = neptune.init_project(
    project="workspace-name/project-name", # (1)! 
    mode="read-only",
)

models_df = project.fetch_runs_table(
    query='`model/stage`:string = "production"',
    columns=["model/stage", "model/size", "test/acc"],
    sort_by="model/size",
).to_pandas()
  1. The full project name. For example, "ml-team/classification".

    • You can copy the name from the project details ( Details & privacy)
    • You can also find a pre-filled project string in Experiments Create a new run.

For the syntax and examples, see the Neptune Query Language (NQL) reference.