Overview
Concrete tool for defining the abstract base interface that all Alibi explanation method wrappers must implement provided by the KServe sample code.
Description
ExplainerWrapper is the abstract base class for all Alibi-based explainer wrappers in the KServe Alibi explainer sample. It defines two methods: validate() which accepts an optional training data URL and performs validation (default is a no-op), and explain() which accepts a list of input instances and optional headers and returns an Alibi Explanation object. Subclasses such as AnchorImages, AnchorTabular, and AnchorText must override the explain() method with their specific explanation logic.
Usage
Use this class as a base when implementing a new Alibi explanation method wrapper. All concrete explainer wrappers should inherit from ExplainerWrapper and implement the explain() method.
Code Reference
Source Location
Signature
class ExplainerWrapper:
def validate(self, training_data_url: Optional[str]):
pass
def explain(self, inputs: List, headers: Dict[str, str] = None) -> Explanation:
pass
Import
from alibiexplainer.explainer_wrapper import ExplainerWrapper
I/O Contract
Inputs
validate()
| Name |
Type |
Required |
Description
|
| training_data_url |
Optional[str] |
No |
URL to training data for validation purposes
|
explain()
| Name |
Type |
Required |
Description
|
| inputs |
List |
Yes |
List of input instances to explain
|
| headers |
Dict[str, str] |
No |
Optional HTTP headers from the request
|
Outputs
validate()
| Name |
Type |
Description
|
| (none) |
None |
No-op in the base class
|
explain()
| Name |
Type |
Description
|
| explanation |
Explanation |
Alibi Explanation object (no-op in the base class)
|
Usage Examples
Basic Usage
from alibiexplainer.explainer_wrapper import ExplainerWrapper
from alibi.api.interfaces import Explanation
from typing import List, Dict
class MyCustomExplainer(ExplainerWrapper):
def explain(self, inputs: List, headers: Dict[str, str] = None) -> Explanation:
# Custom explanation logic here
...
return explanation
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.