Alibi Detect
repository·master·Indexed 25 days ago
https://github.com/seldonio/alibi-detectA Python library for outlier, adversarial, and drift detection supporting tabular data, text, images, and time series. It provides online and offline detectors with TensorFlow, PyTorch, and KeOps backends. The library includes various algorithms such as Isolation Forest, VAE, and MMD, as well as utilities for dataset fetching, model building blocks, and integrations with Seldon Core and KFServing.
What's inside alibi-detect
- Alibi Detect is a Python library designed for detecting outliers, adversarial examples, and distribution drift. It supports both online and offline detection across various data modalities, including tabular data, text, images, and time series. The library provides backends for both TensorFlow and PyTorch specifically for drift detection tasks.
Use building block models from alibi_detect.models
masterBeyond detection tasks,
alibi_detectprovides several model implementations inalibi_detect.modelsthat can be used as building blocks. The main TensorFlow-based implementations includePixelCNN,VAE(Variational Autoencoder),Seq2Seq(Sequence-to-sequence), andresnet.from alibi_detect.models.tensorflow import PixelCNN from alibi_detect.models.tensorflow import VAE from alibi_detect.models.tensorflow import Seq2Seq from alibi_detect.models.tensorflow import resnetAlibi-detect integrations
masterAlibi-detect is integrated with the following platforms:
- Seldon Core: Supports outlier and drift detection.
- KFServing: Supports outlier and drift detection.
Fetch datasets using alibi_detect.datasets
masterThe
alibi_detect.datasetsmodule provides utility functions to fetch various datasets for different modalities (Sequential, Images, Tabular). Depending on the function call, you can receive either the data and labels directly or aBunchobject containing data, labels, and optional metadata. Use thereturn_X_y=Trueparameter to get a tuple of(X, y)or(X_train, y_train), (X_test, y_test).from alibi_detect.datasets import fetch_ecg (X_train, y_train), (X_test, y_test) = fetch_ecg(return_X_y=True)Explore the alibi-detect API Reference
masterThe
alibi-detectAPI is organized into several functional modules. You can find detailed documentation for each module in the API Reference. Key modules include:alibi_detect.ad: Adversarial detection algorithms (e.g.,adversarialae,model_distillation).alibi_detect.cd: Concept Drift detection algorithms, including base classes, online detectors, and framework-specific implementations (PyTorch, TensorFlow, Scikit-learn).alibi_detect.od: Outlier Detection algorithms (e.g.,ae,isolationforest,vae,mahalanobis).alibi_detect.models: Model architectures and trainers for PyTorch and TensorFlow.alibi_detect.saving: Utilities for saving, loading, and validating detectors and their schemas.alibi_detect.utils: A wide range of utility modules for data handling, distance metrics, framework-specific helpers, and visualization.
Overview of Auto-Encoding Gaussian Mixture Model (AEGMM)
masterThe Auto-Encoding Gaussian Mixture Model (AEGMM) is an unsupervised/semi-supervised outlier detector suitable for tabular and image data. It works by using an encoder to compress data and a decoder to reconstruct it. The reconstruction error (and other features) are combined with the encodings and fed into a Gaussian Mixture Model (GMM). Outliers are identified by high sample energy in the GMM.What is Model Distillation for drift detection?
masterModel distillation is a technique used to detect adversarial data, malicious data drift, or data corruption by comparing the output distributions (logits) of an original large model with a smaller, distilled model.
In this context:
- Harmful data points: Inputs where the original model is correct on uncorrupted data but incorrect on corrupted data.
- Harmless data points: Inputs where the original model remains correct even on corrupted data.
The detector computes an adversarial score $S(x)$ based on the loss function used for distillation between the original and distilled models. If $S(x)$ exceeds a threshold, the instance is flagged as adversarial.
What is Spectral Residual outlier detection?
masterThe Spectral Residual (SR) outlier detector is designed for unsupervised online anomaly detection in univariate time series data.
It works by:
- Computing the Fourier Transform of the input data.
- Calculating the spectral residual of the log amplitude of the transformed signal.
- Applying the Inverse Fourier Transform to create a saliency map in the time domain.
- Computing an anomaly score based on the relative difference between the saliency map values and their moving averages.
If the score exceeds a specified
threshold, the timestep is flagged as an outlier.How the Variational Auto-Encoder (VAE) outlier detector works
masterThe Variational Auto-Encoder (VAE) is an unsupervised or semi-supervised outlier detector suitable for tabular and image data. It is trained on a batch of unlabeled, normal (inlier) data.
Core Mechanism: The detector attempts to reconstruct the input data. If an input cannot be reconstructed well, it results in a high reconstruction error, and the data is flagged as an outlier.
Scoring Methods: Reconstruction error is measured using one of the following:
- Mean Squared Error (MSE): The MSE between the input and the reconstructed instance.
- Probability: The probability that both the input and the reconstructed instance are generated by the same process.
Currently, the
score_typeparameter only supports the default'mse'.Understand Detector Configuration Schemas (Unresolved vs Resolved)
masterAlibi Detect uses two types of configuration schemas for its detectors:
- Unresolved Schemas (e.g.,
KSDriftConfig,MMDDriftConfig): These represent the initial configuration. Except for thenameandmetafields, the fields in these schemas match the detector'sargsandkwargsdirectly. - Resolved Schemas (e.g.,
KSDriftConfigResolved,MMDDriftConfigResolved): These represent the configuration after it has been processed and resolved for use by the detector.
Common detector config types include:
FETDriftOnlineConfig/FETDriftOnlineConfigResolvedKSDriftConfig/KSDriftConfigResolvedLSDDDriftConfig/LSDDDriftConfigResolvedLSDDDriftOnlineConfig/LSDDDriftOnlineConfigResolvedLearnedKernelDriftConfig/LearnedKernelDriftConfigResolvedMMDDriftConfig/MMDDriftConfigResolvedMMDDriftOnlineConfig/MMDDriftOnlineConfigResolvedRegressorUncertaintyDriftConfig/RegressorUncertaintyDriftConfigResolvedSpotTheDiffDriftConfig/SpotTheDiffDriftConfigResolved
- Unresolved Schemas (e.g.,
Select an algorithm for Outlier Detection
masterAlibi Detect provides several algorithms for outlier detection across different data types. Choose based on your data format:
- Tabular: Isolation Forest, Mahalanobis Distance, AE, VAE, AEGMM, VAEGMM, Likelihood Ratios.
- Image: AE, VAE, AEGMM, VAEGMM, Likelihood Ratios.
- Time Series: Likelihood Ratios, Prophet, Spectral Residual, Seq2Seq.
- Text: (None specifically listed in the table, but check reference list).
- Categorical Features: Isolation Forest, Mahalanobis Distance, Likelihood Ratios.
Some detectors support Online detection (e.g., Mahalanobis Distance, Spectral Residual) or Feature Level detection (e.g., AE, VAE, Likelihood Ratios, Spectral Residual, Seq2Seq).
Likelihood Ratios (LLR) for Outlier Detection Overview
masterThe Likelihood Ratio (LLR) outlier detector uses the log-likelihood ratio between two generative models as an outlier score. One model is trained on the original data, while a second model (
model_background) is trained on a perturbed version of the dataset. This approach aims to capture background statistics while erasing semantic features through perturbations (e.g., using a Bernoulli distribution to substitute features).For images, the package provides a
PixelCNN++implementation available inalibi_detect.models.tensorflow.pixelcnn.