objectives
objectives
¶
Policy prediction objectives used by visual attribution methods.
resolve_actions_for_explanation
¶
Resolve action targets needed by the policy explanation objective.
Decoders with requires_tokenized_actions=True need action token IDs to
compute a differentiable likelihood score. Offline dataset batches can
provide true tokenized actions. Online inference batches have no labels, so
this function runs an unhooked inference pass first and uses generated
action tokens as pseudo-targets for the subsequent hooked teacher-forced
pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policy
|
Policy
|
Policy being explained. |
required |
observation
|
ObservationBatch
|
Observation values keyed by observation-space names. |
required |
actions
|
ActionBatch | None
|
Optional action dictionary from the explanation source. |
required |
preprocess_observation
|
bool
|
Whether to normalize/tokenize observations before building policy features. |
required |
Returns:
| Type | Description |
|---|---|
ActionBatch | None
|
|
ActionBatch | None
|
tokenized actions, existing tokenized labels when available, or |
ActionBatch | None
|
generated pseudo-target actions for tokenized-action decoders. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a tokenized-action decoder cannot produce action tokens for an unlabeled explanation batch. |
Source code in src/versatil/explainability/attribution/objectives.py
compute_policy_explanation_objective
¶
compute_policy_explanation_objective(policy, observation, actions, preprocess_observation, output_selector=None)
Compute the differentiable policy score used by attribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policy
|
Policy
|
Policy being explained. |
required |
observation
|
ObservationBatch
|
Observation values keyed by observation-space names. |
required |
actions
|
ActionBatch | None
|
Optional action dictionary. Decoders with
|
required |
preprocess_observation
|
bool
|
Whether to normalize/tokenize observations before building policy features. |
required |
output_selector
|
PolicyPredictionSelector | None
|
Optional selector for continuous prediction tensors.
|
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Tensor of per-sample or per-token scores. Attribution methods average |
Tensor
|
this tensor for gradient backpropagation and compare score drops for |
Tensor
|
ablation. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a custom selector is passed for a decoder that requires tokenized actions. |
RuntimeError
|
If tokenized-action logits or target tokens are missing. |
Source code in src/versatil/explainability/attribution/objectives.py
repeat_action_batch
¶
Repeat action tensors along the batch axis for perturbation methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actions
|
ActionBatch | None
|
Action tensors keyed by action component, or |
required |
repeat_count
|
int
|
Number of copies to concatenate. |
required |
Returns:
| Type | Description |
|---|---|
ActionBatch | None
|
Repeated action batch, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |