Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add api.py for external API calls to OpenXAI #1

Merged
merged 2 commits into from Oct 28, 2022
Merged

Add api.py for external API calls to OpenXAI #1

merged 2 commits into from Oct 28, 2022

Conversation

jiaqima
Copy link
Collaborator

@jiaqima jiaqima commented Oct 28, 2022

Description

Implemented an OpenXAI class in api.py to serve for external API calls.

Example Usage

from openxai.api import OpenXAI

oxai = OpenXAI(data_name="german", model_name="ann", explainer_name="lime")

# query full data
df_full = oxai.query()

# query a batch of data with feature tensor `X` and label tensor `y`
df_batch = oxai.query(X, y)

The returned df_full or df_batch are pandas dataframes with each row corresponds to a data sample. The number of columns is 2d + 3, where d is the feature dimension.

The columns from left to right are: features (d), feature attribution scores (d), label (1), predicted label (1), and is_test flag (1).

Test

The code has been successfully tested on 3 datasets ("compas", "adult", "german"), 2 models ("ann", "lr"), and 6 explainers ("grad", "sg", "itg", "ig", "shap", "lime").

To reproduce the test, run python openxai/api.py under the root of this repo.

Note: Currently there seems to be path issues for this API to be used externally. The issue is possibly due to the path usage by LoadModel, which should be fixed in a separate PR.

@y12uc231
Copy link
Collaborator

Sounds good to me. Thanks for adding this!

@y12uc231 y12uc231 merged commit 6cb8834 into AI4LIFE-GROUP:main Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants