Configuration¶
An ExplainConfig has three sections: backend (which model),
generation (how it generates) and explanation (what is explained, how). Unknown
keys fail validation, so typos surface.
YAML skeleton¶
Only backend.kind and backend.model_id are required; other keys default as in the
key reference. Less obvious keys:
budget: one offraction(share of the \(2^n\) coalitions),evaluations(a count) orper_player(4plans \(\lceil 4n \rceil\)).budget.stopendsmcorpermutationearly (Choosing an estimator).max_players: refuses budgets above \(2^{\text{max\_players}}\) coalitions before any model call.kv_cache:transformersonly, off by default (Generative backends).efficiency: additiveshifts Shapley values to sum togrand_value - base_value.hierarchicalconfiguresexplain_hierarchical()(needsplayers: sentences).
backend:
kind: lmstudio
model_id: qwen2-500m-instruct
generation:
max_new_tokens: 128
temperature: 0.0
top_k: 1
explanation:
estimand: shapley
estimator: neyman_cc
value_fn: tfidf_cosine
normalizer: identity
players: tokens
absence_policy: delete
budget:
fraction: 0.3
include_minimal_masks: false
neyman:
use_standard_method: false
initial_fraction: null
initial_num_samples: null
max_inflight: 2
max_players: 24
archive:
path: ./runs/{run_id}
flush_every: 50
on_exists: error
dedup:
enabled: auto
kv_cache:
enabled: false
max_entries: 8
embedding_mode: static
seed: 42
plugin_options: {}
Load and save¶
explain_config_from_yaml() validates YAML;
explain_config_to_yaml() writes every key back, defaults included:
from pathlib import Path
from mllm_shap import ExplainConfig, explain_config_from_yaml, explain_config_to_yaml
Path("config.yaml").write_text(
"backend:\n"
" kind: mock\n"
" model_id: stub\n"
"explanation:\n"
" estimator: exact\n",
encoding="utf-8",
)
config = explain_config_from_yaml(Path("config.yaml").read_text(encoding="utf-8"))
assert isinstance(config, ExplainConfig)
text = explain_config_to_yaml(config)
Path("config.roundtrip.yaml").write_text(text, encoding="utf-8")
print("\n".join(text.splitlines()[:8]))
Output
backend:
kind: mock
model_id: stub
api_host: null
timeout_s: 120.0
max_retries: 3
options: {}
generation:
In Python, ExplainConfig.model_validate({...}) builds the same object. Configs are
frozen; derive variants with model_copy(update=...).
Key reference¶
Generated from the pydantic models of the installed version.
backend¶
Key |
Type |
Default |
Meaning |
|---|---|---|---|
|
|
|
Registered backend plugin identifier. |
|
|
|
Model name or repository id passed to the backend. |
|
|
|
API host for HTTP-compatible backends. Required for the |
|
|
|
Per-request timeout in seconds for remote backends. |
|
|
|
Retries after a transient backend failure (0 disables retrying). |
|
|
|
Backend-specific settings validated by the selected backend. |
generation¶
Key |
Type |
Default |
Meaning |
|---|---|---|---|
|
|
|
Maximum tokens generated per coalition evaluation. |
|
|
|
Sampling temperature for model generation. |
|
|
|
Top-k sampling cutoff for model generation. |
|
|
|
Ask backends that can (transformers) to attach model embeddings to records. The pipeline turns it on when the value function declares |
|
|
|
Independent draws per coalition; the value of a coalition is the mean of its draws’ values, and every draw is archived under its own key. |
|
|
|
Order of a message’s text and media parts in the backend request; any value but |
explanation¶
Key |
Type |
Default |
Meaning |
|---|---|---|---|
|
|
|
Cooperative-game value targeted by aggregation. |
|
|
|
Registered estimator plugin used to sample coalitions. |
|
|
|
Registered value-function plugin used to score outputs. |
|
|
|
Registered normalizer applied after estimand aggregation. |
|
|
|
|
|
|
|
Report the standard error of every value ( |
|
|
|
Registered partition plugin that defines explainability players. |
|
|
|
Registered absence policy used to render masked snapshots. |
|
|
Estimator budget controls. |
|
|
|
|
Share of the |
|
|
|
Coalition evaluations in total, empty and grand included, instead of |
|
|
|
Coalition evaluations as a multiple of the player count, |
|
|
|
Early stopping; only written when set. |
|
|
|
Whether minimal coalitions are included in estimator sampling. |
|
|
Neyman-CC controls applied when the Neyman estimator is selected. |
|
|
|
|
Whether phase-one sampling uses unstructured random coalitions. |
|
|
|
Fraction of the total budget used during phase-one initialization, in (0, 1]. |
|
|
|
Explicit phase-one pair budget overriding |
|
|
|
Settings of |
|
|
|
Maximum concurrent coalition evaluations. |
|
|
|
Runs planning more than 2^max_players coalitions (fraction * 2^n, or evaluations) are refused. The ceiling of 62 keeps 2^n inside a signed 64-bit integer, which the samplers’ NumPy mask arithmetic needs. |
|
|
Run archive persistence settings. |
|
|
|
|
Filesystem path template for persisted run archives. |
|
|
|
Number of coalition records between archive flushes. |
|
|
|
What to do when the archive directory already holds a run. |
|
|
Coalition deduplication settings. |
|
|
|
|
Deduplication mode for repeated coalition evaluations. |
|
|
Prefix cache settings for supported backends. |
|
|
|
|
Whether prefix/KV cache reuse is enabled when supported. |
|
|
|
Maximum prefix KV states a backend keeps; the oldest is evicted first. |
|
|
|
Embedding mode used by embedding-based value functions. |
|
|
|
Random seed for reproducible coalition sampling. |
|
|
|
Per-plugin options keyed by plugin name, passed as |
Plugin options¶
explanation.plugin_options passes settings to one plugin of the run, keyed by
<group>/<name>, or the bare name when unique in the run. Groups: estimators,
estimands, value_fns, normalizers, backends, partitions,
absence_policies, renderers. The plugin reads them as PluginContext.options (Extending mllm-shap). Before the run, a
key naming no plugin of the run, an unknown option or a wrong type raises
ConfigError naming group, plugin and key.
explanation:
value_fn: my_metric
plugin_options:
value_fns/my_metric:
threshold: 0.5
Options per plugin: absence policies in Masking views, value functions in
Using value functions, normalizers in Value functions and normalizers, semivalues in
Using estimand aggregators, estimators in Choosing an estimator, audio and image players in
Audio alignment and Image input. backend.options (replay, lmstudio, transformers):
Generative backends.
Archive path and re-runs¶
explanation.archive.path is a template. {run_id} is the first 16 characters of the
snapshot id plus a 12-character digest of the configuration (archive settings excluded)
and model id. A new estimator, policy, value function, seed or model thus gets a new
directory. Re-running the same config on the same snapshot raises
ArchiveExistsError under on_exists: error (default);
overwrite replaces the archive. path: "" skips archiving.
Runnable configs per backend in config/: Generative backends. Legacy settings:
Coming from legacy MLLM-Shap.