mllm_shap.shap.base package#
Submodules#
mllm_shap.shap.base.approx module#
Base class for SHAP explainers using approximation methods.
- class mllm_shap.shap.base.approx.BaseShapApproximation(*args: Any, num_samples: int | None = None, fraction: float = 0.6, **kwargs: Any)[source]#
Bases:
BaseShapExplainer,ABCBase class for SHAP explainers using approximation methods.
- allow_mask_duplicates: bool#
Whether to allow duplicate masks during generation.
- embedding_model: BaseExternalEmbedding | None#
The external embedding model to use. If provided, overrides
mode.
- embedding_reducer: BaseEmbeddingReducer#
The embedding reduction strategy to use.
- fraction: float | None#
Fraction of total possible masks to generate if num_samples is None.
- include_minimal_masks: bool = True#
Whether to include minimal masks (single-feature and empty masks) in the sampling.
- mode: Mode#
The SHAP mode, either STATIC or CONTEXTUAL. Used if no
embedding_modelis provided.
- normalizer: BaseNormalizer#
The SHAP value normalizer to use.
- num_samples: int | None#
Number of random masks to generate. If None, uses fraction. -1 stands for minimal number of samples (only single-feature masks and empty mask).
- similarity_measure: BaseEmbeddingSimilarity#
The embedding similarity measure to use.
- total_n_calls: int = 0#
Total number of MLLM calls made for last explanation.
mllm_shap.shap.base.complementary module#
Base class for SHAP explainers using approximation methods.
- class mllm_shap.shap.base.complementary.BaseComplementaryShapApproximation(*args: Any, num_samples: int | None = None, fraction: float = 0.6, **kwargs: Any)[source]#
Bases:
BaseShapApproximation,ABCComplementary SHAP implementation class.
- allow_mask_duplicates: bool#
Whether to allow duplicate masks during generation.
- embedding_model: BaseExternalEmbedding | None#
The external embedding model to use. If provided, overrides
mode.
- embedding_reducer: BaseEmbeddingReducer#
The embedding reduction strategy to use.
- fraction: float | None#
Fraction of total possible masks to generate if num_samples is None.
- include_minimal_masks: bool = True#
Whether to include minimal masks (single-feature and empty masks) in the sampling.
- mode: Mode#
The SHAP mode, either STATIC or CONTEXTUAL. Used if no
embedding_modelis provided.
- normalizer: BaseNormalizer#
The SHAP value normalizer to use.
- num_samples: int | None#
Number of random masks to generate. If None, uses fraction. -1 stands for minimal number of samples (only single-feature masks and empty mask).
- similarity_measure: BaseEmbeddingSimilarity#
The embedding similarity measure to use.
- total_n_calls: int = 0#
Total number of MLLM calls made for last explanation.
mllm_shap.shap.base.embeddings module#
Base class for embedding calculation reduction strategies.
mllm_shap.shap.base.explainer module#
Base class for SHAP-based explanations.
- class mllm_shap.shap.base.explainer.BaseExplainer(model: BaseMllmModel, shap_explainer: BaseShapExplainer)[source]#
Bases:
ABCConvenience base client for SHAP explainers.
- model: BaseMllmModel#
The model connector instance.
- shap_explainer: BaseShapExplainer#
The SHAP explainer instance.
- total_n_calls: int = 0#
Total number of MLLM calls made for last explanation.
mllm_shap.shap.base.normalizers module#
Base class for SHAP value normalizers.
mllm_shap.shap.base.shap_explainer module#
Base class for SHAP-based explanations.
- class mllm_shap.shap.base.shap_explainer.BaseShapExplainer(mode: Mode = Mode.CONTEXTUAL, embedding_model: BaseExternalEmbedding | None = None, embedding_reducer: BaseEmbeddingReducer | None = None, similarity_measure: BaseEmbeddingSimilarity | None = None, normalizer: BaseNormalizer | None = None, allow_mask_duplicates: bool = False)[source]#
Bases:
ABCBase class for SHAP-based explanations.
- allow_mask_duplicates: bool#
Whether to allow duplicate masks during generation.
- embedding_model: BaseExternalEmbedding | None#
The external embedding model to use. If provided, overrides
mode.
- embedding_reducer: BaseEmbeddingReducer#
The embedding reduction strategy to use.
- mode: Mode#
The SHAP mode, either STATIC or CONTEXTUAL. Used if no
embedding_modelis provided.
- normalizer: BaseNormalizer#
The SHAP value normalizer to use.
- similarity_measure: BaseEmbeddingSimilarity#
The embedding similarity measure to use.
- total_n_calls: int = 0#
Total number of MLLM calls made for last explanation.
- exception mllm_shap.shap.base.shap_explainer.NotEnoughTokensToExplainError[source]#
Bases:
ExceptionRaised when there are not enough tokens to explain in the chat.
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
mllm_shap.shap.base.similarity module#
Base class for embedding similarity calculations.
Module contents#
Base module for mllm_shap.shap package.