Skip to main content

Flax NXX implementation of common metrics.

Project description

📏 Flax Metrics Flax Metrics PyPI version Documentation Status

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flax_metrics-0.4.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flax_metrics-0.4.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file flax_metrics-0.4.0.tar.gz.

File metadata

  • Download URL: flax_metrics-0.4.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for flax_metrics-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7532ed538bc01c82392d3e024bedddac1a9077b8f3ea78301080cf08dba3bf06
MD5 6b22c19854374ea5f82b54b5d1e162d0
BLAKE2b-256 d7203e79ac9632f0ab783f46f2579c377fae8820b8922949bca3201985ca99fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for flax_metrics-0.4.0.tar.gz:

Publisher: ci.yml on tillahoffmann/flax-metrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flax_metrics-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: flax_metrics-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for flax_metrics-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2113ef30bd769e16f7e01cbcb53e6f829b2db9a393e817a586a61c383d4082da
MD5 4bc8575cf5653a5cedf273efffbb9205
BLAKE2b-256 1394f1d92a3b0b8523b845993ba3a342cae241c171697d8e2ff4587ec617d5d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for flax_metrics-0.4.0-py3-none-any.whl:

Publisher: ci.yml on tillahoffmann/flax-metrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page