Sanitize ML Labels
Sanitize ML Labels is a Python package designed to standardize and sanitize ML-related labels. Currently supports over 100 labels, including metric and model names.
If you have ML-related labels, and you find yourself renaming and sanitizing them in a consistent manner, with the proper capitalizaton, this package ensures they are always sanitized in a standard way.
How do I install this package?
You can install it using pip:
pip install sanitize_ml_labels
Usage examples
Here are some common use cases for normalizing labels:
Example for metrics
from sanitize_ml_labels import sanitize_ml_labels
labels = [
"acc",
"loss",
"auroc",
"lr"
]
assert sanitize_ml_labels(labels) == [
"Accuracy",
"Loss",
"AUROC",
"Learning rate"
]
Example for models
from sanitize_ml_labels import sanitize_ml_labels
labels = [
"mlp",
"cnn",
"ffNN",
"Feed-forward neural network",
"perceptron",
"recurrent neural network",
"LStM"
]
assert sanitize_ml_labels(labels) == [
"MLP",
"CNN",
"FFNN",
"FFNN",
"Perceptron",
"RNN",
"LSTM"
]
assert sanitize_ml_labels("vanilla mlp") == "MLP"
assert sanitize_ml_labels("vanilla cnn") == "CNN"
assert sanitize_ml_labels([
"Large Language Model",
"transe",
"Generative Pre-trained Transformer",
"Graph Convolutional Neural Network",
"Convolutional Graph Neural Network",
"Graph Neural Network",
"Graph Attention Network",
"Graph Attention Neural Network",
]) == ["LLM","TransE","GPT","GCN","GCN","GNN","GAT","GAT"]
Sometimes, it happens that you have prefixed all your models with "vanilla" or "simple" or "basic". This package can help you remove these prefixes.
from sanitize_ml_labels import sanitize_ml_labels
labels = [
"vanilla mlp",
"vanilla cnn",
"vanilla ffnn",
"vanilla perceptron"
]
assert sanitize_ml_labels(labels) == ["MLP", "CNN", "FFNN", "Perceptron"]
Corner cases
Sometimes, you might encounter hyphenated terms that need to be correctly identified and normalized. We use a heuristic approach based on an extended list of over 45K hyphenated English words, originally from the Metadata consulting website.
The lookup heuristic, written by Tommaso Fontana, ensures efficient and accurate hyphenated word recognition.
from sanitize_ml_labels import sanitize_ml_labels
# Running the following
assert sanitize_ml_labels("non-existent-edges-in-graph") == "Non-existent edges in graph"
Extra utilities
In addition to label sanitization, the package provides methods to check metric normalization:
Is normalized metric
Validates if a metric falls within the range [0, 1].
from sanitize_ml_labels import is_normalized_metric
assert not is_normalized_metric("MSE")
assert is_normalized_metric("acc")
assert is_normalized_metric("accuracy")
assert is_normalized_metric("AUROC")
assert is_normalized_metric("auprc")
Is absolutely normalized metric
Validates if a metric falls within the range [-1, 1].
from sanitize_ml_labels import is_absolutely_normalized_metric
assert not is_absolutely_normalized_metric("auprc")
assert is_absolutely_normalized_metric("MCC")
assert is_absolutely_normalized_metric("Markedness")
Shoud be maximized
Whether a metric should be maximized or minimized. Unknown metrics will raise a NotImplementedError.
from sanitize_ml_labels import should_be_maximized
assert not should_be_maximized("MSE")
assert should_be_maximized("AUROC")
assert should_be_maximized("accuracy")
License
This software is licensed under the MIT license. See the LICENSE.
Metadata
Release files for sanitize-ml-labels 1.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sanitize_ml_labels-1.1.5.tar.gz | 327.4 kB | Without provenance | Details for sanitize_ml_labels-1.1.5.tar.gz |
Release files / sanitize_ml_labels-1.1.5.tar.gz
| Download URL | sanitize_ml_labels-1.1.5.tar.gz |
|---|---|
| Size | 327.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
af777b269aac26270faf501224836a145a3a0bdb028b688c45d777645098f77c
|
|
BLAKE2b-256 checksum How to use checksums |
6b43dc0d941b7476ac62884ae21d1c02dee2c36bf357859e9a429de0871d7855
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Security for sanitize-ml-labels 1.1.5
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.