Skip to content

Commit 6d177a9

Browse files
Rajakavitha1gitbook-bot
authored andcommitted
GITBOOK-8: No subject
1 parent 3540a2c commit 6d177a9

18 files changed

+486
-1136
lines changed

docs-gb/README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1+
# Alibi Detect
2+
13
![Alibi Detect Logo](images/Alibi_Detect_Logo_rgb.png)
24

3-
# Alibi Detect
5+
## Alibi Detect
46

57
[Alibi Detect](https://github.com/SeldonIO/alibi-detect) is a source-available Python library focused on **outlier**, **adversarial** and **drift** detection. The package aims to cover both online and offline detectors for tabular data, text, images and time series. Both **TensorFlow** and **PyTorch** backends are supported for drift detection.
68

7-
For more background on the importance of monitoring outliers and distributions in a production setting, check out
8-
[this talk](https://slideslive.com/38931758/monitoring-and-explainability-of-models-in-production?ref=speaker-37384-latest)
9-
from the *Challenges in Deploying and Monitoring Machine Learning Systems* ICML 2020 workshop, based on the paper
10-
[Monitoring and explainability of models in production](https://arxiv.org/abs/2007.06299) and referencing Alibi Detect.
9+
For more background on the importance of monitoring outliers and distributions in a production setting, check out [this talk](https://slideslive.com/38931758/monitoring-and-explainability-of-models-in-production?ref=speaker-37384-latest) from the _Challenges in Deploying and Monitoring Machine Learning Systems_ ICML 2020 workshop, based on the paper [Monitoring and explainability of models in production](https://arxiv.org/abs/2007.06299) and referencing Alibi Detect.
1110

12-
For a thorough introduction to drift detection, check out the talk below titled, [Protecting Your Machine Learning Against Drift: An Introduction](https://youtu.be/tL5sEaQha5o).
13-
The talk covers what drift is and why it pays to detect it, the different types of drift, how it
14-
can be detected in a principled manner and also describes the anatomy of a drift detector.
11+
For a thorough introduction to drift detection, check out the talk below titled, [Protecting Your Machine Learning Against Drift: An Introduction](https://youtu.be/tL5sEaQha5o). The talk covers what drift is and why it pays to detect it, the different types of drift, how it can be detected in a principled manner and also describes the anatomy of a drift detector.
1512

1613
{% embed url="https://youtu.be/tL5sEaQha5o" %}

docs-gb/SUMMARY.md

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Table of contents
22

33
* [Alibi Detect](README.md)
4-
* [Getting Started](overview/getting\_started.md)
4+
* [Getting Started](overview/getting_started.md)
55
* [Algorithm Overview](overview/algorithms.md)
66
* [Saving and Loading](overview/saving.md)
7-
* [Detector Configuration Files](overview/config\_files.md)
8-
* [Roadmap](overview/roadmap.md)
7+
* [Detector Configuration Files](overview/config_files.md)
98
* [Outlier Detection](outlier-detection/README.md)
109
* [Methods](outlier-detection/methods/README.md)
1110
* [Mahalanobis Distance](od/methods/mahalanobis.md)
@@ -19,19 +18,19 @@
1918
* [Spectral Residual](od/methods/sr.md)
2019
* [Sequence-to-Sequence (Seq2Seq)](od/methods/seq2seq.md)
2120
* [Examples](outlier-detection/examples/README.md)
22-
* [AE outlier detection on CIFAR10](examples/od\_ae\_cifar10.md)
23-
* [AEGMM and VAEGMM outlier detection on KDD Cup ‘99 dataset](examples/od\_aegmm\_kddcup.md)
24-
* [Isolation Forest outlier detection on KDD Cup ‘99 dataset](examples/od\_if\_kddcup.md)
25-
* [Likelihood Ratio Outlier Detection on Genomic Sequences](examples/od\_llr\_genome.md)
26-
* [Likelihood Ratio Outlier Detection with PixelCNN++](examples/od\_llr\_mnist.md)
27-
* [Mahalanobis outlier detection on KDD Cup ‘99 dataset](examples/od\_mahalanobis\_kddcup.md)
28-
* [Time-series outlier detection using Prophet on weather data](examples/od\_prophet\_weather.md)
29-
* [Seq2Seq time series outlier detection on ECG data](examples/od\_seq2seq\_ecg.md)
30-
* [Time series outlier detection with Seq2Seq models on synthetic data](examples/od\_seq2seq\_synth.md)
31-
* [Time series outlier detection with Spectral Residuals on synthetic data](examples/od\_sr\_synth.md)
32-
* [VAE outlier detection for income prediction](examples/od\_vae\_adult.md)
33-
* [VAE outlier detection on CIFAR10](examples/od\_vae\_cifar10.md)
34-
* [VAE outlier detection on KDD Cup ‘99 dataset](examples/od\_vae\_kddcup.md)
21+
* [AE outlier detection on CIFAR10](examples/od_ae_cifar10.md)
22+
* [AEGMM and VAEGMM outlier detection on KDD Cup ‘99 dataset](examples/od_aegmm_kddcup.md)
23+
* [Isolation Forest outlier detection on KDD Cup ‘99 dataset](examples/od_if_kddcup.md)
24+
* [Likelihood Ratio Outlier Detection on Genomic Sequences](examples/od_llr_genome.md)
25+
* [Likelihood Ratio Outlier Detection with PixelCNN++](examples/od_llr_mnist.md)
26+
* [Mahalanobis outlier detection on KDD Cup ‘99 dataset](examples/od_mahalanobis_kddcup.md)
27+
* [Time-series outlier detection using Prophet on weather data](examples/od_prophet_weather.md)
28+
* [Seq2Seq time series outlier detection on ECG data](examples/od_seq2seq_ecg.md)
29+
* [Time series outlier detection with Seq2Seq models on synthetic data](examples/od_seq2seq_synth.md)
30+
* [Time series outlier detection with Spectral Residuals on synthetic data](examples/od_sr_synth.md)
31+
* [VAE outlier detection for income prediction](examples/od_vae_adult.md)
32+
* [VAE outlier detection on CIFAR10](examples/od_vae_cifar10.md)
33+
* [VAE outlier detection on KDD Cup ‘99 dataset](examples/od_vae_kddcup.md)
3534
* [Drift Detection](cd/README.md)
3635
* [Methods](cd/methods/README.md)
3736
* [Offline](cd/methods/offline/README.md)
@@ -53,30 +52,30 @@
5352
* [Online Cramér-von Mises](cd/methods/onlinecvmdrift.md)
5453
* [Online Fisher’s Exact Test](cd/methods/onlinefetdrift.md)
5554
* [Examples](cd/examples/README.md)
56-
* [Categorical and mixed type data drift detection on income prediction](examples/cd\_chi2ks\_adult.md)
57-
* [Learned drift detectors on Adult Census](examples/cd\_clf\_adult.md)
58-
* [Learned drift detectors on CIFAR-10](examples/cd\_clf\_cifar10.md)
59-
* [Context-aware drift detection on news articles](examples/cd\_context\_20newsgroup.md)
60-
* [Context-aware drift detection on ECGs](examples/cd\_context\_ecg.md)
61-
* [Model Distillation drift detector on CIFAR-10](examples/cd\_distillation\_cifar10.md)
62-
* [Kolmogorov-Smirnov data drift detector on CIFAR-10](examples/cd\_ks\_cifar10.md)
63-
* [Maximum Mean Discrepancy drift detector on CIFAR-10](examples/cd\_mmd\_cifar10.md)
64-
* [Scaling up drift detection with KeOps](examples/cd\_mmd\_keops.md)
65-
* [Model uncertainty based drift detection on CIFAR-10 and Wine-Quality datasets](examples/cd\_model\_unc\_cifar10\_wine.md)
66-
* [Drift detection on molecular graphs](examples/cd\_mol.md)
67-
* [Online drift detection for Camelyon17 medical imaging dataset](examples/cd\_online\_camelyon.md)
68-
* [Online Drift Detection on the Wine Quality Dataset](examples/cd\_online\_wine.md)
69-
* [Interpretable drift detection with the spot-the-diff detector on MNIST and Wine-Quality datasets](examples/cd\_spot\_the\_diff\_mnist\_wine.md)
70-
* [Supervised drift detection on the penguins dataset](examples/cd\_supervised\_penguins.md)
71-
* [Drift detection on Amazon reviews](examples/cd\_text\_amazon.md)
72-
* [Text drift detection on IMDB movie reviews](examples/cd\_text\_imdb.md)
55+
* [Categorical and mixed type data drift detection on income prediction](examples/cd_chi2ks_adult.md)
56+
* [Learned drift detectors on Adult Census](examples/cd_clf_adult.md)
57+
* [Learned drift detectors on CIFAR-10](examples/cd_clf_cifar10.md)
58+
* [Context-aware drift detection on news articles](examples/cd_context_20newsgroup.md)
59+
* [Context-aware drift detection on ECGs](examples/cd_context_ecg.md)
60+
* [Model Distillation drift detector on CIFAR-10](examples/cd_distillation_cifar10.md)
61+
* [Kolmogorov-Smirnov data drift detector on CIFAR-10](examples/cd_ks_cifar10.md)
62+
* [Maximum Mean Discrepancy drift detector on CIFAR-10](examples/cd_mmd_cifar10.md)
63+
* [Scaling up drift detection with KeOps](examples/cd_mmd_keops.md)
64+
* [Model uncertainty based drift detection on CIFAR-10 and Wine-Quality datasets](examples/cd_model_unc_cifar10_wine.md)
65+
* [Drift detection on molecular graphs](examples/cd_mol.md)
66+
* [Online drift detection for Camelyon17 medical imaging dataset](examples/cd_online_camelyon.md)
67+
* [Online Drift Detection on the Wine Quality Dataset](examples/cd_online_wine.md)
68+
* [Interpretable drift detection with the spot-the-diff detector on MNIST and Wine-Quality datasets](examples/cd_spot_the_diff_mnist_wine.md)
69+
* [Supervised drift detection on the penguins dataset](examples/cd_supervised_penguins.md)
70+
* [Drift detection on Amazon reviews](examples/cd_text_amazon.md)
71+
* [Text drift detection on IMDB movie reviews](examples/cd_text_imdb.md)
7372
* [Adversarial Detection](adversarial-detection/README.md)
7473
* [Methods](adversarial-detection/methods/README.md)
7574
* [Adversarial Auto-Encoder](ad/methods/adversarialae.md)
7675
* [Model Distillation](ad/methods/modeldistillation.md)
7776
* [Examples](adversarial-detection/examples/README.md)
78-
* [Adversarial AE detection and correction on CIFAR-10](examples/ad\_ae\_cifar10.md)
79-
* [Deployment](examples/alibi\_detect\_deploy.md)
77+
* [Adversarial AE detection and correction on CIFAR-10](examples/ad_ae_cifar10.md)
78+
* [Deployment](examples/alibi_detect_deploy.md)
8079
* [Datasets](datasets/overview.md)
8180
* [Models](models/overview.md)
8281
* [Bibliography](bibliography.md)

docs-gb/ad/methods/modeldistillation.md

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,35 @@ jupyter:
66
name: python3
77
---
88

9+
# Model Distillation
10+
911
[source](../../api/alibi_detect.ad.model_distillation.rst)
1012

11-
# Model distillation
13+
## Model distillation
1214

13-
## Overview
15+
### Overview
1416

15-
[Model distillation](https://arxiv.org/abs/1503.02531) is a technique that is used to transfer knowledge from a large network to a smaller network. Typically, it consists of training a second model with a simplified architecture on soft targets (the output distributions or the logits) obtained from the original model.
17+
[Model distillation](https://arxiv.org/abs/1503.02531) is a technique that is used to transfer knowledge from a large network to a smaller network. Typically, it consists of training a second model with a simplified architecture on soft targets (the output distributions or the logits) obtained from the original model.
1618

17-
Here, we apply model distillation to obtain harmfulness scores, by comparing the output distributions of the original model with the output distributions
18-
of the distilled model, in order to detect adversarial data, malicious data drift or data corruption.
19-
We use the following definition of harmful and harmless data points:
19+
Here, we apply model distillation to obtain harmfulness scores, by comparing the output distributions of the original model with the output distributions of the distilled model, in order to detect adversarial data, malicious data drift or data corruption. We use the following definition of harmful and harmless data points:
2020

2121
* Harmful data points are defined as inputs for which the model's predictions on the uncorrupted data are correct while the model's predictions on the corrupted data are wrong.
22-
2322
* Harmless data points are defined as inputs for which the model's predictions on the uncorrupted data are correct and the model's predictions on the corrupted data remain correct.
2423

25-
Analogously to the [adversarial AE detector](https://arxiv.org/abs/2002.09364), which is also part of the library, the model distillation detector picks up drift that reduces the performance of the classification model.
24+
Analogously to the [adversarial AE detector](https://arxiv.org/abs/2002.09364), which is also part of the library, the model distillation detector picks up drift that reduces the performance of the classification model.
2625

2726
The detector can be used as follows:
2827

2928
* Given an input $x,$ an adversarial score $S(x)$ is computed. $S(x)$ equals the value loss function employed for distillation calculated between the original model's output and the distilled model's output on $x$.
30-
3129
* If $S(x)$ is above a threshold (explicitly defined or inferred from training data), the instance is flagged as adversarial.
3230

33-
## Usage
31+
### Usage
3432

35-
### Initialize
33+
#### Initialize
3634

3735
Parameters:
3836

3937
* `threshold`: threshold value above which the instance is flagged as an adversarial instance.
40-
4138
* `distilled_model`: `tf.keras.Sequential` instance containing the model used for distillation. Example:
4239

4340
```python
@@ -59,10 +56,8 @@ model = tf.keras.Model(inputs=inputs, outputs=outputs)
5956
```
6057

6158
* `loss_type`: type of loss used for distillation. Supported losses: 'kld', 'xent'.
62-
6359
* `temperature`: Temperature used for model prediction scaling. Temperature <1 sharpens the prediction probability distribution which can be beneficial for prediction distributions with high entropy.
64-
65-
* `data_type`: can specify data type added to metadata. E.g. *'tabular'* or *'image'*.
60+
* `data_type`: can specify data type added to metadata. E.g. _'tabular'_ or _'image'_.
6661

6762
Initialized detector example:
6863

@@ -76,55 +71,44 @@ ad = ModelDistillation(
7671
)
7772
```
7873

79-
### Fit
74+
#### Fit
8075

8176
We then need to train the detector. The following parameters can be specified:
8277

8378
* `X`: training batch as a numpy array.
84-
8579
* `loss_fn`: loss function used for training. Defaults to the custom model distillation loss.
86-
8780
* `optimizer`: optimizer used for training. Defaults to [Adam](https://arxiv.org/abs/1412.6980) with learning rate 1e-3.
88-
8981
* `epochs`: number of training epochs.
90-
9182
* `batch_size`: batch size used during training.
92-
9383
* `verbose`: boolean whether to print training progress.
94-
9584
* `log_metric`: additional metrics whose progress will be displayed if verbose equals True.
96-
9785
* `preprocess_fn`: optional data preprocessing function applied per batch during training.
9886

99-
10087
```python
10188
ad.fit(X_train, epochs=50)
10289
```
10390

104-
The threshold for the adversarial / harmfulness score can be set via ```infer_threshold```. We need to pass a batch of instances $X$ and specify what percentage of those we consider to be normal via `threshold_perc`. Even if we only have normal instances in the batch, it might be best to set the threshold value a bit lower (e.g. $95$%) since the model could have misclassified training instances.
91+
The threshold for the adversarial / harmfulness score can be set via `infer_threshold`. We need to pass a batch of instances $X$ and specify what percentage of those we consider to be normal via `threshold_perc`. Even if we only have normal instances in the batch, it might be best to set the threshold value a bit lower (e.g. $95$%) since the model could have misclassified training instances.
10592

10693
```python
10794
ad.infer_threshold(X_train, threshold_perc=95, batch_size=64)
10895
```
10996

110-
### Detect
97+
#### Detect
11198

11299
We detect adversarial / harmful instances by simply calling `predict` on a batch of instances `X`. We can also return the instance level score by setting `return_instance_score` to True.
113100

114101
The prediction takes the form of a dictionary with `meta` and `data` keys. `meta` contains the detector's metadata while `data` is also a dictionary which contains the actual predictions stored in the following keys:
115102

116-
* `is_adversarial`: boolean whether instances are above the threshold and therefore adversarial instances. The array is of shape *(batch size,)*.
117-
103+
* `is_adversarial`: boolean whether instances are above the threshold and therefore adversarial instances. The array is of shape _(batch size,)_.
118104
* `instance_score`: contains instance level scores if `return_instance_score` equals True.
119105

120-
121106
```python
122107
preds_detect = ad.predict(X, batch_size=64, return_instance_score=True)
123108
```
124109

125-
## Examples
110+
### Examples
126111

127-
### Image
112+
#### Image
128113

129114
[Harmful drift detection through model distillation on CIFAR10](../../examples/cd_distillation_cifar10.ipynb)
130-

0 commit comments

Comments
 (0)