-
Notifications
You must be signed in to change notification settings - Fork 34
AIV2 Algorithm
Peck Yoke edited this page Aug 8, 2024
·
4 revisions
This page describes the design for the AI Verify algorithm plugin component, as well as the code module imported by each algorithm.
- Test engine core modules to be published to PyPI, e.g.
pip install aiverify-core-modules
- Allow developers to import extra dependencies, e.g.
pip install aiverify-core-modules[sklearn]
. - Developers can install all dependencies,
pip install aiverify-core-modules[all]
- Allow developers to import extra dependencies, e.g.
- Each algorithm designed as standalone python library
- Under the standard algorithm template, changes include:
- Remove all references to test engine api if any
- add
aiverify-core-modules
torequirements.txt
- move
__main__.py
totests.py
-
__main__
.py to implement command line parser which calls the algorithm library<algo>.py
- add Dockerfile to compile each algorithm as standalone docker image
This page defines the various schema files related to algorithms.
Output Schema
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "/aiverify.algorithm.testresult.schema.json",
"title": "Algorithm Output Schema",
"description": "AI Verify algorithm output schema",
"type": "object",
"properties": {
"gid": {
"description": "Unique global identififer for the plugin",
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9-._]*$",
"minLength": 1,
"maxLength": 128
},
"cid": {
"description": "Unique identifier for the algorithm within the plugin",
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9-._]*$",
"minLength": 1,
"maxLength": 128
},
"version": {
"description": "Algoritm version",
"type": "string"
},
"start_time": {
"description": "Start date time of test",
"type": "string",
"format": "date-time"
},
"time_taken": {
"description": "Time take to complete running the test in seconds.",
"type": "number"
},
"test_arguments": {
"description": "Test arguments",
"type": "object",
"properties": {
"testDataset": {
"description": "URI of test dataset",
"type": "string",
"format": "uri"
},
"mode": {
"description": "Mode of model used, upload for model file and api for model api",
"type": "string",
"enum": ["upload", "api"]
},
"modelType": {
"description": "AI model type",
"type": "string",
"enum": [ "classification", "regression" ]
},
"groundTruthDataset": {
"description": "URI of test dataset",
"type": "string",
"format": "uri"
},
"groundTruth": {
"description": "Ground truth column name",
"type": "string"
},
"algorithmArgs": {
"description": "Arugment provided to the algorithm for running the tests. Test arguments should be defined in input.schema.json under each algorithm",
"$comment": "Algorithm implementation should validate the algorithmArgs according to input.schema.json"
}
},
"if": {
"properties": {
"mode": { "const": "upload" }
}
},
"then": {
"modelFile": {
"description": "URI of model file",
"type": "string",
"format": "uri"
}
},
"else": {
"$comment": "TODO: Add reference to model api configuration specs"
},
"required": [
"testDataset",
"mode",
"modelType"
],
"dependentRequired": {
"groundTruthDataset": ["groundTruth"]
}
},
"output": {
"description": "Output from algorithm running. Test output schema should be defined in output.schema.json under each algorithm",
"$comment": "AI Verify API-GW and any module that reads the output should validate the output according to output.schema.json"
},
"artifacts": {
"description": "List the test artifacts (e.g. images) produced by the algorithm, to be upload to API-GW",
"type": "array",
"items": {
"description": "filenames of the artifacts",
"type": "string"
}
}
},
"required": [
"gid",
"cid",
"start_time",
"time_taken",
"test_arguments",
"output"
]
}
Example
{
"gid": "aiverify.stock.fairness_metrics_toolbox_for_classification",
"version": "0.9.0",
"cid": "fairness_metrics_toolbox_for_classification",
"start_time": "2024-07-24T09:20:24.822881",
"time_taken": 0,
"test_arguments": {
"testDataset": "file:///examples/data/sample_bc_credit_data.sav",
"modelFile": "file:///examples/model/sample_bc_credit_sklearn_linear.LogisticRegression.sav",
"groundTruthDataset": "file:///examples/data/sample_bc_credit_data.sav",
"groundTruth": "default",
"algorithmArgs": {
"sensitive_feature": [
"gender"
],
"annotated_labels_path": "file:///examples/data/sample_bc_credit_data.sav",
"file_name_label": "NA"
},
"mode": "upload",
"modelType": "classification"
},
"output": {
"sensitive_feature": [
"gender"
],
"output_classes": [
0,
1
],
"results": [
{
"True Positive Rate": [
{
"group": [
0
],
"metric": 0.17026578073089702
},
{
"group": [
1
],
"metric": 0.19019933554817275
}
],
"True Negative Rate": [
{
"group": [
0
],
"metric": 0.32098765432098764
},
{
"group": [
1
],
"metric": 0.3132716049382716
}
],
"Positive Predictive Value Parity": [
{
"group": [
0
],
"metric": 0.22577092511013216
},
{
"group": [
1
],
"metric": 0.2522026431718062
}
],
"Negative Predictive Value Parity": [
{
"group": [
0
],
"metric": 0.2613065326633166
},
{
"group": [
1
],
"metric": 0.2550251256281407
}
],
"False Positive Rate": [
{
"group": [
0
],
"metric": 0.19675925925925927
},
{
"group": [
1
],
"metric": 0.16898148148148148
}
],
"False Negative Rate": [
{
"group": [
0
],
"metric": 0.3131229235880399
},
{
"group": [
1
],
"metric": 0.32641196013289037
}
],
"False Discovery Rate": [
{
"group": [
0
],
"metric": 0.28083700440528636
},
{
"group": [
1
],
"metric": 0.24118942731277532
}
],
"False Omission Rate": [
{
"group": [
0
],
"metric": 0.23680904522613067
},
{
"group": [
1
],
"metric": 0.24685929648241206
}
],
"Disparate Impact": [
{
"group": [
0,
1
],
"metric": 1.0218689431079695
}
],
"Equal Selection Parity": [
{
"group": [
0,
1
],
"metric": 12.0
}
]
},
{
"True Positive Rate": [
{
"group": [
0
],
"metric": 0.32098765432098764
},
{
"group": [
1
],
"metric": 0.3132716049382716
}
],
"True Negative Rate": [
{
"group": [
0
],
"metric": 0.17026578073089702
},
{
"group": [
1
],
"metric": 0.19019933554817275
}
],
"Positive Predictive Value Parity": [
{
"group": [
0
],
"metric": 0.2613065326633166
},
{
"group": [
1
],
"metric": 0.2550251256281407
}
],
"Negative Predictive Value Parity": [
{
"group": [
0
],
"metric": 0.22577092511013216
},
{
"group": [
1
],
"metric": 0.2522026431718062
}
],
"False Positive Rate": [
{
"group": [
0
],
"metric": 0.3131229235880399
},
{
"group": [
1
],
"metric": 0.32641196013289037
}
],
"False Negative Rate": [
{
"group": [
0
],
"metric": 0.19675925925925927
},
{
"group": [
1
],
"metric": 0.16898148148148148
}
],
"False Discovery Rate": [
{
"group": [
0
],
"metric": 0.23680904522613067
},
{
"group": [
1
],
"metric": 0.24685929648241206
}
],
"False Omission Rate": [
{
"group": [
0
],
"metric": 0.28083700440528636
},
{
"group": [
1
],
"metric": 0.24118942731277532
}
],
"Disparate Impact": [
{
"group": [
0,
1
],
"metric": 0.9877380644400872
}
],
"Equal Selection Parity": [
{
"group": [
0,
1
],
"metric": 6.0
}
]
}
]
}
}