Histograms in Neptune
To track activations or other distributions across steps, you can log a series of histograms to a Neptune run.
Log histogram series
To log a histogram series:
- Define the histogram with the
Histogram
Neptune type. - To log the histogram to a specific step, pass the histogram to the
log_histograms()
function.
Defining a histogram
Import Histogram
from the Neptune types:
from neptune_scale.types import Histogram
You can specify a histogram with NumPy:
import numpy as np
a = np.arange(5)
counts, bin_edges = np.histogram(a, density=False)
neptune_histogram = Histogram(bin_edges=bin_edges, counts=counts)
densities, bin_edges = np.histogram(a, density=True)
neptune_histogram = Histogram(bin_edges=bin_edges, densities=densities)
You can also use another framework, or pass custom values:
my_histogram = Histogram(
bin_edges=[0, 1, 40, 89, 1000],
counts=[5, 82, 44, 1],
)
If using densities, they should represent probability density function values per bin. This way, the area of the histogram bars will be equal to 1.
my_histogram = Histogram(
bin_edges=[0, 1, 2, 3, 4],
densities=[0.25, 0.25, 0.25, 0.25],
)
Bin edges
When specifying the bin edges, the left edge is inclusive and the right exclusive.
For example, the bin edges [0, 1, 40]
result in the intervals [0, 1)
and [1, 40)
.
Infinity values aren't supported as bin edges.
Logging a histogram per step
You can log one or more histogram series at a particular step in a single function call:
from neptune_scale import Run
from neptune_scale.types import Histogram
run = Run(...)
for step in epoch:
# your training loop
my_histogram = Histogram(...)
run.log_histograms(
histograms={
"layers/1/activations": my_histogram
},
step=step,
)
for step in epoch:
# your training loop
my_histogram_1 = Histogram(...)
my_histogram_2 = Histogram(...)
my_histogram_3 = Histogram(...)
run.log_histograms(
histograms={
"layers/1/activations": my_histogram_1,
"layers/2/activations": my_histogram_2,
"layers/3/activations": my_histogram_3,
},
step=step,
)
View histograms in the app
In the Neptune web app, you can visualize the logged histograms in a dashboard or report.
The distribution at each step is plotted as a vertical stack of bars:
Each color corresponds to a run, and the color intensity indicates the sample count or density.
When you hover over the widget area, the tooltip shows the detailed distributions as regular histograms. The dotted line indicates the cursor position: The vertical line in the tooltip corresponds to the horizontal line in the widget area.