# Debugging AI With Adversarial Validation

DevFeed: [Debugging AI With Adversarial Validation](<https://devfeed.tech/articles/debugging-ai-with-adversarial-validation-18786.md>)

Original publisher: [Read original article](<https://hamel.dev/blog/posts/drift/>)

Author: Hamel Husain

Published: 2024-04-12T07:00:00Z

Content type: tutorial

Language: en

Sources: [Hamel Husain](<https://devfeed.tech/sources/hamel-husain.md>)

Topics: [MLOps](<https://devfeed.tech/topics/mlops.md>), [Machine learning](<https://devfeed.tech/topics/machine-learning.md>), [datasets](<https://devfeed.tech/topics/datasets.md>), [Fine-tuning](<https://devfeed.tech/topics/fine-tuning.md>), [Training AI Models](<https://devfeed.tech/topics/training-ai-models.md>)

Tags: [ai](<https://devfeed.tech/tags/ai.md>), [dataset](<https://devfeed.tech/tags/dataset.md>), [datasets](<https://devfeed.tech/tags/datasets.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [evaluation](<https://devfeed.tech/tags/evaluation.md>), [fine-tuning](<https://devfeed.tech/tags/fine-tuning.md>), [llms](<https://devfeed.tech/tags/llms.md>), [mlops](<https://devfeed.tech/tags/mlops.md>), [model](<https://devfeed.tech/tags/model.md>), [validation](<https://devfeed.tech/tags/validation.md>)

## AI overview

This article explains how to use Adversarial Validation to detect drift between datasets such as training, evaluation, and production data. It describes labeling two datasets, training a binary classifier to distinguish them, and inspecting feature importance or SHAP values to investigate detected differences. It also notes that failing to detect drift does not prove that no drift exists.

## Source excerpt

For years, I've relied on a straightforward method to identify sudden changes in model inputs or training data, known as "drift." This method, Adversarial Validation1, is both simple and effective. The best part? It requires no complex tools or infrastructure. Examples where drift can cause bugs in your AI: Your data for evaluations are materially different from the inputs your model receives in production, causing your evaluations to be misleading. Updates to prompts, functions, RAG, and similar elements aren't incorporated into your fine-tuning or training data, leading to unexpected model behavior in production. No matter how careful you are, bugs can still slip through the cracks. A a high ROI activity is to routinely audit all your AI/ML projects for drift. How It Works WarningUncool Warning This method is so simple that it might seem uncool. You aren't going to impress any data scientists. Despite this, it's too valuable to ignore. This slide from my talk on MLOps tools explains the technique behind Adversarial Validation2: Slide The process is as follows: Collect two datasets to compare. For example: Training data from two different fine-tuning runs Training data vs. evaluation data Training data vs. production data (organized into the same format) Data from two different time-periods Create features from the dataset. A basic example that creates features from tokens is illustrated here.3 Give dataset #1 a label of 0 and dataset #2 a label of 1. Fit a binary classifier (random forest, logistic regression, etc) to discriminate between the two datasets. If the classifier demonstrates sufficient predictive power (ex: AUC >=0.60), we know there is drift. If you used an interpretable model (like logistic regression, random forest, etc.), you can inspect feature importance metrics to understand the root cause of the drift. If you use a more complex model (like a neural network), you can use SHAP values or other methods to understand what is causing the drift. I rec