Skip to content

Log parameters and model configuration#

You can define a namespace for storing any parameters or hyperparameters. Assign the values one by one, or define a dictionary of values.

In each of the below examples, the parameters are stored in a namespace called parameters. Inside that namespace, a field is created for each parameter.

You'll find your logged parameters in the All metadata section of the run.

See example in Neptune 

Tip

You can display parameters in the experiments table and custom dashboards.

Assigning parameters one by one#

import neptune

run = neptune.init_run()

run["parameters/epoch_nr"] = 5
run["parameters/batch_size"] = 32
run["parameters/dense"] = 512
run["parameters/optimizer"] = "sgd"
run["parameters/activation"] = "ReLU"

Assigning parameters as dictionary#

You can assign a dictionary to a variable, then assign that to a run namespace:

With "="
params = {
    "epoch_nr": 5,
    "batch_size": 32,
    "dense": 512,
    "optimizer": "sgd",
    "activation": "ReLU",
}
run["parameters"] = params

You can also use the assign() method to pass a dictionary with the namespace name as the key and the dictionary of parameters as the value:

With assign()
run.assign(
    {
        "parameters": {
            "epoch_nr": 5,
            "batch_size": 32,
            "dense": 512,
            "optimizer": "sgd",
            "activation": "ReLU",
        }
    }
)

Nested dictionary#

Dictionaries can also be nested:

params = {"train": {"max_epochs": 10}}
run["parameters"] = params

This logs the value 10 under the path parameters/train/max_epochs.

Assigning parameters with argparse#

You can also assign arguments parsed with argparse to a namespace in the run.

import argparse

argparser = argparse.ArgumentParser()
argparser.add_argument("--lr", default=0.01)
argparser.add_argument("--batch", default=32)
argparser.add_argument("--activation", default="ReLU")

args = argparser.parse_args()
run["parameters"] = args

Fetching logged parameters from existing run#

>>> import neptune
>>> run = neptune.init_run(with_id="NLI-8") # (1)!
>>> fetched_params = run["parameters"].fetch()
>>> fetched_params
{"train": {"max_epochs": 10, "lr": 0.002}, ...}
  1. Has a dictionary of parameters logged under the parameters namespace:

    run["parameters"] = {"train": {"max_epochs": 10, "lr": 0.002}, ...}
    

Related