Hello World

Introduction

This guide will show you how to:
  • Install neptune-client for Python
  • Connect Neptune to your script and create a run
  • Log metrics and view the results in the app
By the end of it, you'll see metadata tracked to your first run in Neptune!
If you're using R, see the R setup guide.

Before you start

If you'd rather not install anything, you can try the Hello World example in Google Colab with zero setup.

Step 1: Install the Neptune client library

pip
conda
1
pip install neptune-client
Copied!
1
conda install -c conda-forge neptune-client
Copied!
For more help, see Installation and setup.

Step 2: Create hello_world.py

Create a Python script called hello_world.py and copy-paste the following code to it:
hello_world.py
1
import neptune.new as neptune
2
3
run = neptune.init(
4
project="workspace-name/project-name", # replace with your own
5
api_token="Your API token", # replace with your own
6
)
7
8
# Track metadata and hyperparameters of your run
9
run["JIRA"] = "NPT-952"
10
run["algorithm"] = "ConvNet"
11
12
params = {
13
"batch_size": 64,
14
"dropout": 0.2,
15
"learning_rate": 0.001,
16
"optimizer": "Adam",
17
}
18
run["parameters"] = params
19
20
# Track the training process by logging your training metrics
21
for epoch in range(100):
22
run["train/accuracy"].log(epoch * 0.6)
23
run["train/loss"].log(epoch * 0.4)
24
# this just creates a couple of series so we can view them as charts
25
26
# Log the final results
27
run["f1_score"] = 0.66
28
29
# Stop the connection and sync the data with Neptune
30
run.stop()
31
Copied!

Step 3: Add your credentials

To log metadata to your own Neptune project, pass your credentials to the init() method:
1
run = neptune.init(
2
project="workspace-name/project-name", # replace with your own
3
api_token="Your API token", # replace with your own
4
)
Copied!
To skip this step, you can log your run anonymously in a public project:
1
run = neptune.init(
2
project="common/quickstarts",
3
api_token="ANONYMOUS",
4
)
Copied!
To find your project name:
  • In the Neptune app, go to your project.
  • In the Settings tab, select Properties.
  • Copy the project name.
How to find and copy your project name
To find your Neptune API token:
  1. 1.
    In the top-right corner of the app, click your avatar.
  2. 2.
    Click Get Your API token.
  3. 3.
    Copy the token.
How to find your Neptune API token
Example project and api_token arguments:
1
run = neptune.init(
2
project="research-team/sample-project",
3
api_token="eyJhcGlfYW908fsdf23f940jiri0bn3085gh03riv03irn",
4
)
Copied!

Step 4: Run your script and explore the results

Now that you have your script ready, run it from your terminal, Jupyter Lab, or other environments.
1
python hello_world.py
Copied!
To open the run directly, click on the link in the console output. Or head to the app and select the Runs tab to see your run!
In the table, click on the run to view the metadata.
In the left pane, check out the following sections:
  • All metadata - the logged metadata in a folder-like structure.
  • Charts - metrics visualized as charts.
  • Monitoring - hardware consumption during the run execution.
  • Source code - the script that was used for the run.
Viewing all metadata of a run

Conclusion

Congrats! You've learned how to connect Neptune to your code and explore the tracked run in the app.

What’s next?

  • Rerun the script with different parameters to track a few more runs, then click Compare runs in the very left pane to compare and visualize them.
  • When you move on from Hello World, save your API token as an environment variable instead of passing it through the code.
Other resources to check out: