📏 Flax Metrics

Flax NXX implementation of common metrics. See the documentation for a comprehensive list of available metrics.
>>> from flax_metrics import Precision, Recall
>>> from jax import numpy as jnp
>>> labels = jnp.asarray([ 0, 0, 0, 1, 1, 1])
>>> logits = jnp.asarray([-1, -2, 2, 1, -1, -2])
>>> metric = Recall()
>>> metric.update(labels=labels, logits=logits)
Recall(...)
>>> metric.compute()
Array(0.333..., dtype=float32)
Masking
jax.jit requires re-compilation for arrays of different shapes, making evaluation on subsets challenging—we cannot index arrays with a mask. Flax Metrics supports masking through the keyword-only argument mask. The example below illustrates that passing mask is equivalent to indexing the input with a binary mask.
>>> mask = jnp.asarray([True, True, True, True, False, True])
>>> metric = Recall()
>>> metric.update(labels=labels, logits=logits, mask=mask)
Recall(...)
>>> metric.compute()
Array(0.5, dtype=float32)
>>> metric.reset()
Recall(...)
>>> metric.update(labels=labels[mask], logits=logits[mask])
Recall(...)
>>> metric.compute()
Array(0.5, dtype=float32)
Chaining
Metric creation, updates, and computation can be combined into one expression by chaining operations.
>>> Recall().update(labels=labels, logits=logits).compute()
Array(0.333..., dtype=float32)
Metadata
Release files for flax-metrics 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flax_metrics-0.4.0.tar.gz | 16.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flax_metrics-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.2 kB
Release files / flax_metrics-0.4.0.tar.gz
| Download URL | flax_metrics-0.4.0.tar.gz |
|---|---|
| Size | 16.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7532ed538bc01c82392d3e024bedddac1a9077b8f3ea78301080cf08dba3bf06
|
|
BLAKE2b-256 checksum How to use checksums |
d7203e79ac9632f0ab783f46f2579c377fae8820b8922949bca3201985ca99fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 17, 2026.
Transparency logRelease files / flax_metrics-0.4.0-py3-none-any.whl
| Download URL | flax_metrics-0.4.0-py3-none-any.whl |
|---|---|
| Size | 14.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2113ef30bd769e16f7e01cbcb53e6f829b2db9a393e817a586a61c383d4082da
|
|
BLAKE2b-256 checksum How to use checksums |
1394f1d92a3b0b8523b845993ba3a342cae241c171697d8e2ff4587ec617d5d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 17, 2026.
Transparency log