monad.ui.interpretability.interpret_entity
monad.ui.interpretability.interpret_entitymonad.ui.interpretability.interpret(output_path,
checkpoint_path,
predictions_path,
main_entity_id,
device, prediction_date=datetime.now(tz=timezone.utc),
target_index=None, recommended_value=None, **kwargs)
Use saved model and main entity id to put attributions to a JSON file.
from datetime import datetime
from pathlib import Path
from monad.ui.interpretability import interpret_entity
interpret_entity(
output_path=Path("<path/to/josn/file/where/results/should/be/saved.json>"),
checkpoint_path=Path("<path/to/downstream/model/checkpoints>"),
predictions_path=Path("<path/to/predictions/my_predictions.tsv>"),
main_entity_id="<main_entity_id_to_be_explained>",
device="cpu", # cpu or cuda
target_index=0,
prediction_date=datetime(2023, 8, 1),
)| Parameters |
|---|
output_path: pathlib.Path
Path to output JSON file.
checkpoint_path: pathlib.Path
Path to the model checkpoint - the model that was used to run predictions.
predictions_path: pathlib.Path
Path to your saved predictions.
main_entity_id: str
Single main entity id to generate interpretations for. For some databases, such as snowflake value needs to be escaped. This should be one of the values that appear in the tsv file with predictions in the main_entity_id column.
device: str
Device to compute the attributions on. Most commonly "cpu" or "cuda"/"cuda:X" where X is the device number.
target_index: Optional[int]
Default: None
Output indices for which interpretations are computed. For multiclass and multi-label classification should be the id number of a class. No target index is needed for binary classification, one-output regression, and recommendation.
recommended_value: [Optional[str]
Default: None
Value of recommended entity for which the interpretation should be generated. Required for recommendation models.
prediction_date: Optional[datetime.datetime]
Default:datetime.datetime.now()
The date for which the predictions should be interpreted. Should be the same as the date for which the inference is made. Defaults to current date.
kwargs: Any
Data configuration parameters to change.
| Returns |
|---|
Saves results under output_path. Attributions are structured in the following way, at the first level is a dictionary, which keys are data sources (here only "transactions") and values are lists of events of a particular entity. Each element of the events list is a dictionary with a "timestamp" and "modality_attributions" list that contain dictionaries with data source, name, value, and attribution of a feature. Attributions express how much a given feature value increase or decrease prediction score.
