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()
>>> 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.3.0.tar.gz (13.7 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.3.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flax_metrics-0.3.0.tar.gz
  • Upload date:
  • Size: 13.7 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.3.0.tar.gz
Algorithm Hash digest
SHA256 888ea63c99e05c8d4ad024ba28ea71039679a935108e6c70eee6bb6bf2935314
MD5 e357d99f029483618255631846dea7d3
BLAKE2b-256 13d920e53de44c4485773e1693435d7c5d3a89890cf7272a8bb3a049496b0b5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for flax_metrics-0.3.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.3.0-py3-none-any.whl.

File metadata

  • Download URL: flax_metrics-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.6 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a5662d05b5c957a91f16df695e2d93a8f6bc8504a384dcb98d86a4566c5bc32e
MD5 c829731bd52d4ec57300573917bfcfa0
BLAKE2b-256 bd0b467d4dcae87d4f6a441abaac69dc7f3d6e72e133f6c72f8f762932fb9570

See more details on using hashes here.

Provenance

The following attestation bundles were made for flax_metrics-0.3.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