API Reference#

Top-level Package#

Core Types#

Data Handling#

class llmSHAP.data_handler.DataHandler(data, permanent_keys=None, mask_token='')[source]#

Bases: object

Parameters:
  • data (DataMapping | str)

  • permanent_keys (Set[str] | Set[Index] | None)

  • mask_token (str)

get_data(indexes, *, mask=True, exclude_permanent_keys=False)[source]#

Return a dict view according to the supplied options.

Parameters:
  • indexes (int | Iterable[int])

  • mask (bool)

  • exclude_permanent_keys (bool)

Return type:

Dict[Any, Any]

get_feature_enumeration()[source]#
Return type:

Dict[int, str]

get_keys(*, exclude_permanent_keys=False)[source]#

List of indexes, optionally excluding permanent ones.

Parameters:

exclude_permanent_keys (bool)

Return type:

list[int]

remove(indexes, *, mask=True)[source]#

Return a copy where the chosen indexes are either masked (mask=True) or removed (mask=False). self.data is unchanged.

Parameters:
  • indexes (int | Iterable[int])

  • mask (bool)

Return type:

Dict[Any, Any]

remove_hard(indexes)[source]#

Delete the selected indexes in-place. Returns the live mapping.

Parameters:

indexes (int | Iterable[int])

Return type:

Dict[Any, Any]

to_string(indexes=None, *, mask=True, exclude_permanent_keys=False)[source]#

Join the chosen indexes into one space-separated string.

Parameters:
  • indexes (int | Iterable[int] | None)

  • mask (bool)

  • exclude_permanent_keys (bool)

Return type:

str

Prompt Codecs#

class llmSHAP.prompt_codec.BasicPromptCodec(system='')[source]#

Bases: PromptCodec

Parameters:

system (str)

build_prompt(data_handler, indexes)[source]#

(Encode) Build prompt to send to the model.

Parameters:
  • data_handler (DataHandler)

  • indexes (int | Iterable[int])

Return type:

list[dict[str, str]]

parse_generation(model_output)[source]#

(Decode) Parse model generation into a structured result.

Parameters:

model_output (str)

Return type:

Generation

class llmSHAP.prompt_codec.PromptCodec[source]#

Bases: ABC

abstractmethod build_prompt(data_handler, indexes)[source]#

(Encode) Build prompt to send to the model.

Parameters:
  • data_handler (DataHandler)

  • indexes (int | Iterable[int])

Return type:

list[dict[str, str]]

abstractmethod parse_generation(model_output)[source]#

(Decode) Parse model generation into a structured result.

Parameters:

model_output (str)

Return type:

Generation

Generations#

class llmSHAP.generation.Generation(output: str)[source]#

Bases: object

Parameters:

output (str)

output: str#

Similarity Functions#

Attribution Methods#

LLM Interfaces#