Skip to content

Expand XAI notebooks with perturbation, TCAV, and attention vs attribution#28

Merged
aravind-3105 merged 18 commits intomainfrom
ref-imp1-expand
Mar 18, 2026
Merged

Expand XAI notebooks with perturbation, TCAV, and attention vs attribution#28
aravind-3105 merged 18 commits intomainfrom
ref-imp1-expand

Conversation

@aravind-3105
Copy link
Member

@aravind-3105 aravind-3105 commented Mar 12, 2026

Summary

This pull request significantly expands the xai_refresher module's documentation and dependencies to support four new advanced notebooks (perturbation, robustness, TCAV, and attention vs attribution) and clarifies their interconnections. It also updates the recommended setup, adds required libraries, and reorganizes further reading references for clarity and completeness.

Clickup Ticket(s): Link(s) if applicable.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test improvements
  • 🔒 Security fix

Changes Made

Notebooks and Documentation Enhancements:

  • Added detailed descriptions and sequencing for four new advanced notebooks: perturbation-based attribution for vision and text, TCAV concept-level interpretability, and attention vs attribution analysis. Provided a summary table and cross-notebook connections to clarify learning progression and shared insights.
  • Updated the recommended setup to specify additional dependencies (captum, transformers, datasets, bertviz) needed for the new notebooks.
  • Revised the "Getting Started" section to include the new notebooks in the suggested order of completion, ensuring a logical learning path.

Dependencies and Environment:

  • Added captum, huggingface-hub, and bertviz to the ref1-refresher-interpretability dependency group in pyproject.toml to support the new notebooks.
  • Updated the Jupyter kernel specification in concept_grounding.ipynb for consistency with the new environment.

Reference Materials:

  • Reorganized and expanded the "Further Reading" section to group papers by theme (LIME, SHAP, perturbation, bias, TCAV, attention, concept grounding) and include recent and foundational works relevant to the new content.

Testing

  • Tests pass locally (uv run pytest tests/)
  • Type checking passes (uv run mypy <src_dir>)
  • Linting passes (uv run ruff check src_dir/)
  • Manual testing performed (describe below)

Manual testing details:

Screenshots/Recordings

Related Issues

Deployment Notes

Checklist

  • Code follows the project's style guidelines
  • Self-review of code completed
  • Documentation updated (if applicable)
  • No sensitive information (API keys, credentials) exposed

@aravind-3105
Copy link
Member Author

@shainarazavi I've added the extra notebooks we wanted to add to expand the refresher implementation. The main files to be checked are

  • perturbation_robustness_and_bias_text.ipynb
  • perturbation_robustness_and_bias_text.ipynb
  • attention_vs_attribution.ipynb
  • attention_vs_attribution.ipynb.ipynb
    The remaining changes from the previous notebooks are minor, mostly just aesthetic updates.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the implementations/xai_refresher module documentation and environment setup to support additional advanced XAI notebooks (perturbation/robustness, TCAV, attention vs attribution), and updates the dependency group/lockfile accordingly.

Changes:

  • Added new interpretability dependencies to the ref1-refresher-interpretability group and updated uv.lock.
  • Updated implementations/xai_refresher/README.md to document notebooks 5–8 and reorganize further reading.
  • Adjusted the Jupyter kernelspec metadata in concept_grounding.ipynb.

Reviewed changes

Copilot reviewed 3 out of 8 changed files in this pull request and generated 1 comment.

File Description
uv.lock Adds new resolved packages for the expanded notebook environment (but currently contains duplicated package entries).
pyproject.toml Extends ref1-refresher-interpretability with new libraries for the added notebooks (but currently missing datasets).
implementations/xai_refresher/concept_grounding.ipynb Updates kernelspec metadata to match the environment naming used by newer notebooks.
implementations/xai_refresher/README.md Documents new notebook sequence, interconnections, and expands/reorganizes references.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +84 to +86
"captum>=0.8.0",
"huggingface-hub>=1.3.4",
"bertviz>=1.4.1",
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref1-refresher-interpretability is missing the datasets dependency, but the new notebooks/docs require it (e.g., tcav_concept_sensitivity.ipynb imports datasets). Please add datasets to this dependency group and regenerate uv.lock so the environment matches the README/setup instructions.

Copilot uses AI. Check for mistakes.
@shainarazavi
Copy link
Collaborator

@aravind-3105 some of them are PRs to run locally, lets meet tommorow and dry run and get it done

Copy link
Collaborator

@shainarazavi shainarazavi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can dry run, however, from a quick review,check the model vs clf_model naming collision, also is`` def gradient_token_importance(text, target_class=None): defined twice??

Copy link
Collaborator

@shainarazavi shainarazavi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That line appears twice, once for the train results, once for the test features:
python data = torch.load(test_features_path, map_location="cpu")
Both calls omit weights_only=True, meaning arbitrary pickle code can execute on load. is it a design choice?

Copy link
Collaborator

@shainarazavi shainarazavi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work Aravind, we can dry run. Just a quick question but this line:
num_layers = len(model(**tokenizer("test", return_tensors="pt").to(device)).hidden_states) runs a full forward pass just to count layers, which is wasteful. And profession_concept is defined twice , i think once as full sentences, once as single words. I think we can pick one form and define it once.

@shainarazavi
Copy link
Collaborator

@aravind-3105 Thanks for the great work! Please feel free to merge the PR at your convenience.

…nd update README for clarity on index-url requirements
…ution and perturbation_robustness_captum_image notebooks
@aravind-3105 aravind-3105 merged commit e9ef86a into main Mar 18, 2026
2 checks passed
@aravind-3105 aravind-3105 deleted the ref-imp1-expand branch March 18, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants