masking

Responsibility

  • Turn a snapshot into players with spans (the token Partition) and a coalition mask into a rendered snapshot (the Absence policy).

  • Pack masks into bytes and hash them.

Public surface

  • TokenPartitioner (tokens): one player per whitespace token of every message whose role is in RolesOptions.roles (default all; other messages stay present); returns PlayerSet(player_ids, spans) built by tokens.token_spans (spans carry the message’s speaker); player ids "{snapshot_id}:{turn}:{message}:{token}".

  • SentencePartitioner (sentences): one player per sentence (ends at ., !, ? before whitespace, or at a paragraph end); ids "{snapshot_id}:{turn}:{message}:{sentence}". hierarchy.group_players, coarse_player_set and refined_player_set build the two levels of explain_hierarchical; text no player covers stays present.

  • MessagePartitioner (messages): one player per non-empty message of the roles in MessagesOptions.roles (an alias of RolesOptions; default all); span = whole text, label "<role>[/<speaker>] <n>: " plus the first LABEL_PREVIEW_CHARS (30) characters; ids "{snapshot_id}:{turn}:{message}" (message players).

  • ImageGridPartitioner (image_grid: rows, cols, snap_px, question) cuts every image into cells on snap_px steps (snapped_edges); ImageBoxPartitioner (image_boxes: boxes, background, question) makes each box category of the first image a player, smaller categories winning overlaps. Spans carry disjoint region boxes and the image as part; image.decode_image and encode_png need the image extra.

  • DeletePolicy (delete): removes absent spans together with the whitespace that separated them.

  • PadPolicy (pad): replaces absent spans with placeholder (default [MASK], plugin option PadOptions.placeholder).

  • NeutralPolicy (neutral): replaces each absent span with fill_char (default _, plugin option NeutralOptions.fill_char) repeated to the span’s width.

  • InfillPolicy (infill, extra infill, options model, revision): one mask token per absent word, filled by a masked language model in one pass per message; fills are cached per masked text.

  • All three take a PluginContext first and read only PlayerSet.spans; a player set without spans raises. For spans with samples (audio players, alignment) audio.render_audio also edits the AudioPart that span.part names: delete cuts absent samples, pad and neutral replace them with silence of the same length (audio players). For region spans image.render_images paints absent boxes with the policy’s image_fill (grey, mean, blur, noise), or under delete drops an image whose whole-image players are absent and refuses partial regions. Then audio.hide_text drops the text parts of PlayerSet.hidden_text messages in every coalition (decision).

  • tokens.py: token_spans(snapshot), render_spans(snapshot, spans, replacements) (replaces character ranges inside each text part, None deletes, text outside every span is kept; a span crossing two parts merges them; region spans are skipped).

  • MaskBuilder(policy, policy_options=None): policy_options (the non-default options coalition keys hash), view(snapshot, players, mask) -> MaskedSnapshot (no copy), render(masked) -> ConversationSnapshot.

  • MaskCodec: pack to little-endian bytes, unpack, hash_mask (64-bit blake2b over the packed bytes and bit count, stable across processes).

  • MaskSpace: projects a mask over explainable positions into a full mask; not used by the pipeline.

Data flow

  • In: ConversationSnapshot and CoalitionMask from domain; the PlayerSet with spans from the partitioner.

  • Out: one rendered ConversationSnapshot per coalition, rendered lazily by the pipeline orchestrator as the scheduler consumes jobs.

  • Policies never re-tokenise: any partitioner that fills spans (messages, sentences, custom units) works with every policy and with viz labels; under delete a message player leaves its message with empty text.

Invariants

  • Rendered snapshots keep the turn and message structure and the original whitespace outside deleted spans; only span text changes.

  • A rendered snapshot gets a new snapshot_id (rebuilt through ConversationSnapshot.from_turns).

  • Under delete, different masks can render the same text ("a a a" with one token kept); coalition keys are built from the mask, not the rendered text.

Known issues

  • None open. C09 was fixed in 0.1.17.

Tests