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

Updated Shap saving. #881

Merged
merged 2 commits into from
Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions alibi/saving.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,25 @@ def _save_AnchorText(explainer: 'AnchorText', path: Union[str, os.PathLike]) ->
explainer.perturbation = perturbation


def _save_KernelShap(explainer: 'KernelShap', path: Union[str, os.PathLike]) -> None:
# TODO: save internal shap objects using native pickle?
def _save_Shap(explainer: Union['KernelShap', 'TreeShap'], path: Union[str, os.PathLike]) -> None:
# set the internal explainer object to avoid saving it. The internal explainer
# object is recreated when in the `reset_predictor` function call.
_explainer = explainer._explainer
explainer._explainer = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting that this will need to be considered too when fixing #830


# simple save which does not save the predictor
_simple_save(explainer, path)

# reset the internal explainer object
explainer._explainer = _explainer

def _save_TreelShap(explainer: 'TreeShap', path: Union[str, os.PathLike]) -> None:
# TODO: save internal shap objects using native pickle?
_simple_save(explainer, path)

def _save_KernelShap(explainer: 'KernelShap', path: Union[str, os.PathLike]) -> None:
_save_Shap(explainer, path)


def _save_TreeShap(explainer: 'TreeShap', path: Union[str, os.PathLike]) -> None:
_save_Shap(explainer, path)


def _save_CounterfactualRL(explainer: 'CounterfactualRL', path: Union[str, os.PathLike]) -> None:
Expand Down