← Python API
vraven · function

generate_counterfactual

generate_counterfactual(model: 'torch.nn.Module', inputs: 'torch.Tensor', *, target_class: 'int', steps: 'int' = 100, learning_rate: 'float' = 0.05, l2_weight: 'float' = 0.01, max_linf: 'float | None' = None, clamp: 'tuple[float, float] | None' = None, top_changes: 'int' = 20) -> 'CounterfactualResult'

Optimise a bounded input change towards one target class.

This generic method is intended for continuous tensors. Domain constraints
such as valid bytecode, medical physiology or token grammar require a domain
adapter and must not be inferred from this routine.

Usage

from vraven import generate_counterfactual

result = generate_counterfactual(... )
Source of truthThis page is generated from the checked-out public symbol, signature, and docstring. Pin the package version for reproducible work.