mllm_shap.shap.masks package#

Submodules#

mllm_shap.shap.masks.dedup_index module#

Mask deduplication indexes.

class mllm_shap.shap.masks.dedup_index.MaskDedupIndex(_seen: set[int] = <factory>)[source]#

Bases: object

Exact deduplication index for mask hashes.

add(mask_hash: int) bool[source]#

Insert hash, return True if it was new.

contains(mask_hash: int) bool[source]#

Check hash membership.

mllm_shap.shap.masks.mask_codec module#

Bitset-oriented mask encoding and hashing utilities.

class mllm_shap.shap.masks.mask_codec.MaskCodec[source]#

Bases: object

Encode/decode boolean masks to packed bytes.

static hash(mask: Tensor) int[source]#

Stable hash over packed mask bytes.

static normalize(mask: Tensor) Tensor[source]#

Normalize incoming mask to 1D bool tensor.

static pack(mask: Tensor) PackedMask[source]#

Pack mask into little-endian bytes.

static unpack(packed: PackedMask, device: device | None = None) Tensor[source]#

Unpack bytes back to 1D bool tensor.

class mllm_shap.shap.masks.mask_codec.PackedMask(words: bytes, n_bits: int)[source]#

Bases: object

Packed bit representation of one boolean mask.

n_bits: int#
words: bytes#

mllm_shap.shap.masks.mask_space module#

Mask-space utilities for explainable feature indexing.

class mllm_shap.shap.masks.mask_space.MaskSpace(shap_values_mask: Tensor, target_length: int)[source]#

Bases: object

Describes explainable feature subset inside full token mask.

materialize(split: Tensor, device: device) Tensor[source]#

Project split over explainable subset back to full chat mask.

property n_features: int#

Number of explainable features.

shap_values_mask: Tensor#
target_length: int#

Module contents#

Mask encoding and deduplication primitives.

class mllm_shap.shap.masks.MaskCodec[source]#

Bases: object

Encode/decode boolean masks to packed bytes.

static hash(mask: Tensor) int[source]#

Stable hash over packed mask bytes.

static normalize(mask: Tensor) Tensor[source]#

Normalize incoming mask to 1D bool tensor.

static pack(mask: Tensor) PackedMask[source]#

Pack mask into little-endian bytes.

static unpack(packed: PackedMask, device: device | None = None) Tensor[source]#

Unpack bytes back to 1D bool tensor.

class mllm_shap.shap.masks.MaskDedupIndex(_seen: set[int] = <factory>)[source]#

Bases: object

Exact deduplication index for mask hashes.

add(mask_hash: int) bool[source]#

Insert hash, return True if it was new.

contains(mask_hash: int) bool[source]#

Check hash membership.

class mllm_shap.shap.masks.MaskSpace(shap_values_mask: Tensor, target_length: int)[source]#

Bases: object

Describes explainable feature subset inside full token mask.

materialize(split: Tensor, device: device) Tensor[source]#

Project split over explainable subset back to full chat mask.

property n_features: int#

Number of explainable features.

shap_values_mask: Tensor#
target_length: int#
class mllm_shap.shap.masks.PackedMask(words: bytes, n_bits: int)[source]#

Bases: object

Packed bit representation of one boolean mask.

n_bits: int#
words: bytes#