{"id":5871,"library":"captum","title":"Captum","description":"Captum is an open-source model interpretability and understanding library for PyTorch. It provides a comprehensive suite of attribution algorithms to explain predictions of deep learning models, assess the importance of layers and neurons, and evaluate model robustness and concept influence. The library, currently at version 0.8.0, maintains an active development cycle with regular feature additions and improvements.","status":"active","version":"0.8.0","language":"en","source_language":"en","source_url":"https://github.com/pytorch/captum","tags":["pytorch","interpretability","xai","machine learning","deep learning","explainable AI","attribution","model understanding","nlp","computer vision"],"install":[{"cmd":"pip install captum","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core deep learning framework dependency.","package":"torch","optional":false},{"reason":"Numerical operations, required by Captum methods. Version <2.0 is specified.","package":"numpy","optional":false},{"reason":"Dependency for package management utilities.","package":"packaging","optional":false},{"reason":"Progress bar for iterative processes.","package":"tqdm","optional":false},{"reason":"Used for visualization in tutorials and some internal plotting functionalities.","package":"matplotlib","optional":true}],"imports":[{"note":"A primary feature attribution algorithm.","symbol":"IntegratedGradients","correct":"from captum.attr import IntegratedGradients"},{"note":"Another common attribution method.","symbol":"DeepLift","correct":"from captum.attr import DeepLift"},{"note":"For attributing to specific layers.","symbol":"LayerConductance","correct":"from captum.attr import LayerConductance"},{"note":"Introduced in v0.7.0 for language model attribution.","symbol":"LLMAttribution","correct":"from captum.attr import LLMAttribution"}],"quickstart":{"code":"import torch\nimport torch.nn as nn\nfrom captum.attr import IntegratedGradients\n\n# 1. Define a simple PyTorch model\nclass ToyModel(nn.Module):\n    def __init__(self):\n        super().__init__()\n        self.lin1 = nn.Linear(3, 3)\n        self.relu = nn.ReLU()\n        self.lin2 = nn.Linear(3, 2)\n\n    def forward(self, input):\n        return self.lin2(self.relu(self.lin1(input)))\n\nmodel = ToyModel()\nmodel.eval() # Set model to evaluation mode\n\n# 2. Define input and baseline tensors\ninput_tensor = torch.rand(2, 3, requires_grad=True)\nbaseline_tensor = torch.zeros(2, 3)\n\n# 3. Instantiate an attribution algorithm (e.g., Integrated Gradients)\nig = IntegratedGradients(model)\n\n# 4. Compute attributions\n# target specifies the output index to explain (e.g., target=0 for the first output class)\nattributions, delta = ig.attribute(input_tensor, baseline_tensor, target=0, return_convergence_delta=True)\n\nprint('Input Tensor:', input_tensor)\nprint('IG Attributions:', attributions)\nprint('Convergence Delta:', delta)\n","lang":"python","description":"This quickstart demonstrates how to apply Integrated Gradients, a popular feature attribution method, to a simple PyTorch `ToyModel`. It covers defining the model, preparing inputs and baselines, instantiating an attribution algorithm, and computing feature attributions."},"warnings":[{"fix":"Upgrade Python to version 3.9 or higher.","message":"Support for Python 3.8 has been dropped as of Captum v0.8.0. Users must upgrade to Python 3.9 or a newer version to use Captum 0.8.0 and later.","severity":"breaking","affected_versions":">=0.8.0"},{"fix":"Ensure PyTorch is version 1.11 or newer for optimal compatibility and support with Captum v0.8.0+.","message":"While PyPI metadata specifies PyTorch >= 1.10, the v0.8.0 release notes state that 'support for PyTorch 1.10' has been dropped. This suggests that users should ideally target newer PyTorch versions (e.g., >=1.11) for full compatibility and ongoing support, despite PyTorch 1.10 potentially still working as a minimum requirement.","severity":"breaking","affected_versions":">=0.8.0"},{"fix":"Review existing usage of Captum Insights and explore alternative visualization libraries or custom plotting solutions for future Captum versions.","message":"Captum Insights, the interactive visualization widget, will be deprecated in the next major release. Users should plan to migrate to alternative visualization methods or integrate custom solutions.","severity":"deprecated","affected_versions":">=0.8.0"},{"fix":"Consult the Captum documentation for DeepLift's limitations regarding activation functions or consider alternative attribution methods if encountering issues.","message":"The DeepLift attribution algorithm in Captum currently does not support all non-linear activation types, which may lead to errors or unexpected behavior when used with models containing unsupported activation functions.","severity":"gotcha","affected_versions":"<=0.8.0"},{"fix":"Provide custom baselines that represent a meaningful 'absence' of the feature for LLM attribution tasks.","message":"When performing LLM attribution with text-based inputs, using default empty string baselines can result in out-of-distribution inputs, leading to less meaningful attributions. Defining custom, contextually relevant baselines is often recommended for better results.","severity":"gotcha","affected_versions":">=0.7.0"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}