Masking¶
Coalition masking codecs, views, and absence policies.
- class nlp_shap.masking.DeletePolicy[source]¶
Bases:
objectRemove absent tokens from the rendered conversation.
- apply(snapshot: ConversationSnapshot, players: PlayerSet, mask: CoalitionMask) ConversationSnapshot[source]¶
Drop absent tokens while preserving turn and message structure.
- class nlp_shap.masking.MaskBuilder(policy: AbsencePolicy)[source]¶
Bases:
objectBuild masked snapshot views without copying the base conversation.
- view(snapshot: ConversationSnapshot, players: PlayerSet, mask: CoalitionMask) MaskedSnapshot[source]¶
Create a masked view that shares
snapshotacross coalitions.
- render(masked: MaskedSnapshot) ConversationSnapshot[source]¶
Materialize a coalition-specific conversation snapshot.
- class nlp_shap.masking.MaskCodec[source]¶
Bases:
objectEncode and decode boolean masks to packed bytes.
- static normalize(mask: Sequence[bool] | NDArray[bool]) NDArray[bool][source]¶
Normalize incoming mask to a 1D boolean array.
- static pack(mask: Sequence[bool] | NDArray[bool]) PackedMask[source]¶
Pack a mask into little-endian bytes.
- static unpack(packed: PackedMask) tuple[bool, ...][source]¶
Unpack bytes back to a boolean tuple.
- class nlp_shap.masking.MaskSpace(explainable_mask: tuple[bool, ...], target_length: int)[source]¶
Bases:
objectDescribe explainable feature positions inside a full coalition mask.
- class nlp_shap.masking.MaskedSnapshot(base: ConversationSnapshot, players: PlayerSet, mask: CoalitionMask, policy_name: str)[source]¶
Bases:
objectShared view over a conversation snapshot and coalition mask.
- base: ConversationSnapshot¶
Underlying snapshot shared across coalition evaluations.
- mask: CoalitionMask¶
Presence mask selecting which players remain in the coalition.
- class nlp_shap.masking.NeutralPolicy(fill_char: str = '_')[source]¶
Bases:
objectReplace absent tokens with neutral fillers that preserve token width.
- apply(snapshot: ConversationSnapshot, players: PlayerSet, mask: CoalitionMask) ConversationSnapshot[source]¶
Substitute absent tokens with width-matched neutral fillers.
- class nlp_shap.masking.PackedMask(words: bytes, n_bits: int)[source]¶
Bases:
objectPacked bit representation of one boolean mask.
- class nlp_shap.masking.PadPolicy(placeholder: str = '[MASK]')[source]¶
Bases:
objectReplace absent tokens with a fixed mask placeholder.
- apply(snapshot: ConversationSnapshot, players: PlayerSet, mask: CoalitionMask) ConversationSnapshot[source]¶
Substitute absent tokens with
placeholder.
- class nlp_shap.masking.PrefixTreeStub(enabled: bool = False)[source]¶
Bases:
objectPlaceholder type marking the prefix-tree integration point.
- class nlp_shap.masking.TokenPartitioner[source]¶
Bases:
objectPartition a snapshot into whitespace-delimited text tokens.
- partition(snapshot: ConversationSnapshot) PlayerSet[source]¶
Derive ordered token players from the snapshot text.
Packed bitset encoding and stable hashing for coalition masks.
- class nlp_shap.masking.codec.PackedMask(words: bytes, n_bits: int)[source]¶
Bases:
objectPacked bit representation of one boolean mask.
- class nlp_shap.masking.codec.MaskCodec[source]¶
Bases:
objectEncode and decode boolean masks to packed bytes.
- static normalize(mask: Sequence[bool] | NDArray[bool]) NDArray[bool][source]¶
Normalize incoming mask to a 1D boolean array.
- static pack(mask: Sequence[bool] | NDArray[bool]) PackedMask[source]¶
Pack a mask into little-endian bytes.
- static unpack(packed: PackedMask) tuple[bool, ...][source]¶
Unpack bytes back to a boolean tuple.
Mask-space utilities for explainable feature indexing.
- class nlp_shap.masking.space.MaskSpace(explainable_mask: tuple[bool, ...], target_length: int)[source]¶
Bases:
objectDescribe explainable feature positions inside a full coalition mask.
View-based masked snapshots with structural sharing.
- class nlp_shap.masking.builder.MaskedSnapshot(base: ConversationSnapshot, players: PlayerSet, mask: CoalitionMask, policy_name: str)[source]¶
Bases:
objectShared view over a conversation snapshot and coalition mask.
- base: ConversationSnapshot¶
Underlying snapshot shared across coalition evaluations.
- mask: CoalitionMask¶
Presence mask selecting which players remain in the coalition.
- class nlp_shap.masking.builder.MaskBuilder(policy: AbsencePolicy)[source]¶
Bases:
objectBuild masked snapshot views without copying the base conversation.
- view(snapshot: ConversationSnapshot, players: PlayerSet, mask: CoalitionMask) MaskedSnapshot[source]¶
Create a masked view that shares
snapshotacross coalitions.
- render(masked: MaskedSnapshot) ConversationSnapshot[source]¶
Materialize a coalition-specific conversation snapshot.
Absence policies for rendering masked conversation snapshots.
- class nlp_shap.masking.policies.DeletePolicy[source]¶
Bases:
objectRemove absent tokens from the rendered conversation.
- apply(snapshot: ConversationSnapshot, players: PlayerSet, mask: CoalitionMask) ConversationSnapshot[source]¶
Drop absent tokens while preserving turn and message structure.
- class nlp_shap.masking.policies.PadPolicy(placeholder: str = '[MASK]')[source]¶
Bases:
objectReplace absent tokens with a fixed mask placeholder.
- apply(snapshot: ConversationSnapshot, players: PlayerSet, mask: CoalitionMask) ConversationSnapshot[source]¶
Substitute absent tokens with
placeholder.
- class nlp_shap.masking.policies.NeutralPolicy(fill_char: str = '_')[source]¶
Bases:
objectReplace absent tokens with neutral fillers that preserve token width.
- apply(snapshot: ConversationSnapshot, players: PlayerSet, mask: CoalitionMask) ConversationSnapshot[source]¶
Substitute absent tokens with width-matched neutral fillers.
Player partition plugins for conversation snapshots.