Skip to main content

trustformers_debug/interpretability/
config.rs

1//! Configuration types for interpretability analysis
2//!
3//! This module contains the main configuration structures and enums used across
4//! all interpretability analysis methods.
5
6use serde::{Deserialize, Serialize};
7
8/// Configuration for interpretability tools
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct InterpretabilityConfig {
11    /// Enable SHAP (SHapley Additive exPlanations) analysis
12    pub enable_shap: bool,
13    /// Enable LIME (Local Interpretable Model-agnostic Explanations) analysis
14    pub enable_lime: bool,
15    /// Enable attention analysis for transformer models
16    pub enable_attention_analysis: bool,
17    /// Enable feature attribution analysis
18    pub enable_feature_attribution: bool,
19    /// Enable counterfactual generation
20    pub enable_counterfactual_generation: bool,
21    /// Number of SHAP samples for approximation
22    pub shap_samples: usize,
23    /// Number of LIME perturbations
24    pub lime_perturbations: usize,
25    /// Maximum sequence length for attention analysis
26    pub max_attention_seq_length: usize,
27    /// Number of counterfactuals to generate
28    pub num_counterfactuals: usize,
29    /// Feature attribution methods to use
30    pub attribution_methods: Vec<AttributionMethod>,
31    /// Background dataset size for SHAP
32    pub shap_background_size: usize,
33}
34
35impl Default for InterpretabilityConfig {
36    fn default() -> Self {
37        Self {
38            enable_shap: true,
39            enable_lime: true,
40            enable_attention_analysis: true,
41            enable_feature_attribution: true,
42            enable_counterfactual_generation: true,
43            shap_samples: 1000,
44            lime_perturbations: 5000,
45            max_attention_seq_length: 512,
46            num_counterfactuals: 10,
47            attribution_methods: vec![
48                AttributionMethod::IntegratedGradients,
49                AttributionMethod::GradientShap,
50                AttributionMethod::DeepLift,
51            ],
52            shap_background_size: 100,
53        }
54    }
55}
56
57/// Attribution methods for feature importance
58#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash)]
59pub enum AttributionMethod {
60    /// Integrated Gradients
61    IntegratedGradients,
62    /// Gradient × Input
63    GradientInput,
64    /// SmoothGrad
65    SmoothGrad,
66    /// Gradient SHAP
67    GradientShap,
68    /// DeepLIFT
69    DeepLift,
70    /// Layer-wise Relevance Propagation
71    LRP,
72    /// Guided Backpropagation
73    GuidedBackprop,
74    /// Grad-CAM (Gradient-weighted Class Activation Mapping)
75    GradCAM,
76    /// Grad-CAM++
77    GradCAMPlusPlus,
78    /// Score-CAM
79    ScoreCAM,
80    /// Expected Gradients
81    ExpectedGradients,
82    /// Attention Rollout
83    AttentionRollout,
84    /// Path Integrated Gradients
85    PathIntegratedGradients,
86}