Skip to main content

PyEDCR is a metacognitive neuro-symbolic method for learning error detection and correction rules in deployed ML models using combinatorial sub-modular set optimization

Project description

Logo

License: MIT Upload Python Package GitHub Pages Deployment

What is this?

PyEDCR is a Python implementation of the f-EDR (Focused Error Detection Rules) paradigm. The goal of EDR is to use a set of conditions to learn when a machine learning model makes an incorrect prediction.

The EDCR method was first introduced in 'Rule-Based Error Detection and Correction to Operationalize Movement Trajectory Classification' (ArXiv preprint) and later extended to the f-EDR method in the conference article 'Error Detection and Constraint Recovery in Hierarchical Multi-Label Classification without Prior Knowledge' presented at CIKM 2024 (ACM Publication, ArXiv Preprint).

The package was tested for Python >= 3.9.

Installation

To install the package, you can use the following command:

pip install PyEDCR

Example

To demonstrate the use of the package, we consider a dataset with two levels of hierarchy, such that each image has a fine-grain and coarse-grain label. For example, consider the following example from our curated Military Vehicle (which can be found here):

ImageNet100

We further consider a pretrained 'main' model, for example one which employed the small version of Meta's DINO_V2 architecture and was fine-tuned on ImageNet50 - a subset of the ImageNet1K dataset with 50 classes (which can be found here), which we want to analyze its ability to classify both levels of the hierarchy. An instance of such model (which can be found here) has the following performance:

Fine-grain prior combined accuracy: 76.57% , fine-grain prior combined macro f1: 76.1%
Fine-grain prior combined macro precision: 76.96% , fine-grain prior combined macro recall: 76.57%

Coarse-grain prior combined accuracy: 87.14%, coarse-grain prior combined macro f1: 85.77%
Coarse-grain prior combined macro precision: 87.36%, coarse-grain prior combined macro recall: 84.64%

Total prior inconsistencies 133/2100 (6.33%)

We also consider a 'secondary' model (which can be found here), which employed the large version of the DINO_V2 architecture and was also fine-tuned on the ImageNet50 dataset, along with binary models which were trained on each class of the dataset. Consider the following code snippet to run the run_experiment function from PyEDCR.py:

from PyEDCR.classes import experiment_config
from PyEDCR.PyEDCR import run_experiment

imagenet_config = experiment_config.ExperimentConfig(
    data_str='imagenet',
    main_model_name='dinov2_vits14',
    secondary_model_name='dinov2_vitl14',
    main_lr=1e-6,
    secondary_lr=0.000001,
    binary_lr=0.000001,
    original_num_epochs=8,
    secondary_num_epochs=2,
    binary_num_epochs=5
)

run_experiment(config=imagenet_config)

The code will initiate the rule learning pipeline, use the rules learned to mark errors in the predictions of the main model, and print out the performance metrics of the algorithm on the error class after running the f-EDR algorithm, which in this case will be:

error_accuracy: 89.0
error_balanced_accuracy: 84.23
error_precision: 81.65
error_recall: 74.31
error_f1: 77.81
recovered_constraints_precision: 100.0
recovered_constraints_recall: 59.36
recovered_constraints_f1_score: 74.5

For further details about the rule learning algorithm, and noise tolerance experiments, please refer to the paper.

Authors

If you use this work, please cite our paper:

@inproceedings{10.1145/3627673.3679918,
author = {Kricheli, Joshua Shay and Vo, Khoa and Datta, Aniruddha and Ozgur, Spencer and Shakarian, Paulo},
title = {Error Detection and Constraint Recovery in Hierarchical Multi-Label Classification without Prior Knowledge},
year = {2024},
isbn = {9798400704369},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3627673.3679918},
doi = {10.1145/3627673.3679918},
abstract = {Recent advances in Hierarchical Multi-label Classification (HMC), particularly neurosymbolic-based approaches, have demonstrated improved consistency and accuracy by enforcing constraints on a neural model during training. However, such work assumes the existence of such constraints a-priori. In this paper, we relax this strong assumption and present an approach based on Error Detection Rules (EDR) that allow for learning explainable rules about the failure modes of machine learning models. We show that these rules are not only effective in detecting when a machine learning classifier has made an error but also can be leveraged as constraints for HMC, thereby allowing the recovery of explainable constraints even if they are not provided. We show that our approach is effective in detecting machine learning errors and recovering constraints, is noise tolerant, and can function as a source of knowledge for neurosymbolic models on multiple datasets, including a newly introduced military vehicle recognition dataset.},
booktitle = {Proceedings of the 33rd ACM International Conference on Information and Knowledge Management},
pages = {3842–3846},
numpages = {5},
keywords = {hierarchical multi-label classification, learning with constraints, metacognitive ai, neurosymbolic ai, rule learning},
location = {Boise, ID, USA},
series = {CIKM '24}
}

Acknowledgments

This research was funded by ARO grant W911NF-24-1-0007.

   

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

pyedcr-1.1.2.tar.gz (43.4 MB view details)

Uploaded Source

Built Distribution

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

pyedcr-1.1.2-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file pyedcr-1.1.2.tar.gz.

File metadata

  • Download URL: pyedcr-1.1.2.tar.gz
  • Upload date:
  • Size: 43.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pyedcr-1.1.2.tar.gz
Algorithm Hash digest
SHA256 69bf856c58980408373e641b32037932daa239f39052b9fd370ad5f82969e25e
MD5 235da7e36642a29061e5298f4455a335
BLAKE2b-256 07bfe9b7fb8383f8e6e8d9994eb1f5da00527ad325aeb56eb307130a82d15858

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyedcr-1.1.2.tar.gz:

Publisher: python-publish.yml on lab-v2/PyEDCR

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

File details

Details for the file pyedcr-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyedcr-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pyedcr-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 da2da2cc63ae7ca95c3bb775b13d3d2c44d98a561cfb9c9008cdfb9fd9efb29b
MD5 99468d7ce62a573eaebd385f361296bc
BLAKE2b-256 3f9090ff8602350c39d482ec6ad7c89c93064d843d7f98a416318dba70a7aca5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyedcr-1.1.2-py3-none-any.whl:

Publisher: python-publish.yml on lab-v2/PyEDCR

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