hfutils.utils.number

This module provides functionality to categorize numeric values into predefined ranges, returning corresponding tags that represent these ranges. This can be particularly useful for labeling metadata in applications such as HuggingFace repositories, where numeric values need to be classified for better understanding and organization.

The ranges are defined in a list of tuples, where each tuple contains a tag and the minimum and maximum bounds for that range. The primary function in this module is number_to_tag, which takes a numeric value and returns the appropriate tag based on the defined ranges.

number_to_tag

hfutils.utils.number.number_to_tag(v)[source]

Categorize a number into a predefined range and return the corresponding tag for HuggingFace repository metadata.

Parameters:

v (int or float) – The number to categorize.

Returns:

A string tag representing the range in which the number falls.

Return type:

str

Raises:
  • ValueError – If no matching tag is found for the given number.

  • TypeError – If the input value is not numeric type.

Examples:

>>> number_to_tag(500)
'n<1K'
>>> number_to_tag(5000)
'1K<n<10K'
>>> number_to_tag(1000000000000)
'n>1T'