Skip to content

Commit cde2bfd

Browse files
Refactor into installable, tested interpretability library (v2.0.0)
Transform the repository from copy-paste analysis scripts into reusable research infrastructure for GraphCodeBERT (and related code-model) interpretability. Highlights: - New installable package `graphcodebert_interpretability` with a clean public API: compare(), token_alignment(), saliency(), project(), similarity_matrix(), embed(), AST/TF-IDF baselines, dataset loaders, set_seed(). Works on any code. - `gcbi` CLI: compare, saliency, project, heatmap, report, reproduce. - Automated benchmark report: Markdown table + booktabs LaTeX table + 300-DPI comparison figure across GraphCodeBERT/AST/TF-IDF lenses. - Heavy deps (torch/transformers) imported lazily, so baselines/projections/ reports run and are tested without the deep-learning stack. - pytest suite (40 fast tests + model-marked integration tests) and GitHub Actions CI (ruff + tests on Python 3.9-3.12 + build). - pyproject.toml packaging with extras [model]/[umap]/[full]/[dev]; .gitignore. - The 9 legacy scripts are now thin wrappers over the library (same outputs), removing duplicated corpus/model-loading boilerplate. - README rewritten around the library + CLI; CONTRIBUTING, CHANGELOG, CITATION and reproducibility docs updated.
1 parent e10835c commit cde2bfd

42 files changed

Lines changed: 3023 additions & 1686 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: ci-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
test:
15+
name: Lint & fast tests (Python ${{ matrix.python-version }})
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
python-version: ["3.9", "3.10", "3.11", "3.12"]
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
cache: pip
29+
30+
- name: Install package (core + dev, no heavy model stack)
31+
run: |
32+
python -m pip install --upgrade pip
33+
pip install -e ".[dev]"
34+
35+
- name: Lint (ruff)
36+
run: ruff check .
37+
38+
- name: Run fast test suite (model tests deselected)
39+
run: pytest -m "not model" -q
40+
41+
build:
42+
name: Build distribution
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v4
46+
- uses: actions/setup-python@v5
47+
with:
48+
python-version: "3.11"
49+
- name: Build sdist and wheel
50+
run: |
51+
python -m pip install --upgrade pip build
52+
python -m build
53+
- name: Check metadata
54+
run: |
55+
pip install twine
56+
twine check dist/*
57+
- uses: actions/upload-artifact@v4
58+
with:
59+
name: dist
60+
path: dist/*

‎.gitignore‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Byte-compiled / optimized / cached files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
.pytest_cache/
6+
.ruff_cache/
7+
.mypy_cache/
8+
9+
# Distribution / packaging
10+
build/
11+
dist/
12+
*.egg-info/
13+
.eggs/
14+
15+
# Virtual environments
16+
.venv/
17+
venv/
18+
env/
19+
ENV/
20+
21+
# Hugging Face / model caches
22+
.cache/
23+
*.pt
24+
*.bin
25+
*.safetensors
26+
27+
# Generated analysis artefacts (regenerate with `gcbi reproduce`)
28+
benchmark_report/
29+
projections/
30+
ablation_study_results/
31+
32+
# OS / editor noise
33+
.DS_Store
34+
.idea/
35+
.vscode/
36+
*.swp
37+
38+
# Jupyter
39+
.ipynb_checkpoints/
40+
41+
# Scratch
42+
_mount_write_test.py

‎CHANGELOG.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
11
# Changelog
22

33
All notable changes to this project are documented in this file.
4+
This project adheres to [Semantic Versioning](https://semver.org/).
5+
6+
## [2.0.0] - 2026-06-25
7+
### Added
8+
- **Installable Python library** `graphcodebert_interpretability` with a clean,
9+
documented public API (`compare`, `token_alignment`, `saliency`, `project`,
10+
`similarity_matrix`, `embed`, baselines, datasets, `set_seed`, ...) that works on
11+
**any** code, not just the bundled examples.
12+
- **`gcbi` command-line interface**: `compare`, `saliency`, `project`, `heatmap`,
13+
`report`, and `reproduce`.
14+
- **Model-agnostic** model loading (`load_model`) with caching - supports
15+
GraphCodeBERT, CodeBERT, UniXcoder and other compatible checkpoints.
16+
- **Automated benchmark reports**: `generate_report` emits a Markdown table, a
17+
`booktabs` LaTeX table and a 300-DPI comparison figure across GraphCodeBERT,
18+
AST and TF-IDF lenses.
19+
- **Dataset loaders**: bundled `sorting` corpus plus `load_snippets_from_dir`
20+
and `load_jsonl` for user-provided code.
21+
- **`pytest` test suite** (40+ fast tests, no model download required) and
22+
**GitHub Actions CI** (lint + tests on Python 3.9-3.12, plus a build job).
23+
- `pyproject.toml` packaging with optional extras (`[model]`, `[umap]`,
24+
`[full]`, `[dev]`) and a `.gitignore`.
25+
26+
### Changed
27+
- The nine analysis scripts (`comparison.py`, `heatmap.py`, `pca.py`, `tsne.py`,
28+
`pumap.py`, `saliency_maps.py`, `ablation.py`, `ast-s.py`, `tf-s.py`) are now
29+
**thin wrappers** over the library, eliminating the per-script duplication of
30+
the sorting-algorithm corpus and the model-loading boilerplate.
31+
- README rewritten around the library and CLI, with installation, API quickstart,
32+
capability matrix and SEO-friendly headings.
33+
- Stronger, centralised determinism via `set_seed` (Python, NumPy, PyTorch).
434

535
## [1.1.0] - 2026-05-23
636
### Added

‎CITATION.cff‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
cff-version: 1.2.0
2-
message: "If you use this software, please cite it as below."
2+
message: "If you use this software, please cite the paper below."
3+
type: software
34
authors:
45
- family-names: "Martinez-Gil"
56
given-names: "Jorge"
6-
title: "Augmenting the Interpretability of GraphCodeBERT for Code Similarity Tasks"
7+
title: "GraphCodeBERT Interpretability: a toolkit for explaining code similarity models"
8+
version: 2.0.0
79
doi: 10.1142/S0218194025500160
8-
date-released: 2024-10-15
10+
date-released: 2026-06-25
911
url: "https://github.com/jorge-martinez-gil/graphcodebert-interpretability"
12+
keywords:
13+
- graphcodebert
14+
- interpretability
15+
- explainable-ai
16+
- code-similarity
17+
- code-clone-detection
18+
- saliency-maps
1019
preferred-citation:
1120
type: article
1221
authors:
@@ -19,4 +28,4 @@ preferred-citation:
1928
volume: 35
2029
issue: 05
2130
start: 657
22-
end: 678
31+
end: 678

‎CONTRIBUTING.md‎

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,71 @@
11
# Contributing
22

3-
Thank you for your interest in improving this project. Contributions that improve **reproducibility**, **clarity**, and **research impact** are especially welcome.
3+
Thank you for your interest in improving this project. Contributions that improve
4+
**reproducibility**, **clarity**, and **research impact** are especially welcome.
45

5-
## Ways to Contribute
6-
- Report bugs in scripts, notebooks, or generated outputs.
7-
- Request features (new analyses, visualizations, or usability improvements).
8-
- Propose reproducibility enhancements (environment setup, deterministic runs, clearer instructions).
6+
## Ways to contribute
97

10-
Please open a GitHub Issue first: <https://github.com/jorge-martinez-gil/graphcodebert-interpretability/issues>.
8+
- Add a new **dataset** loader or bundled corpus (e.g. clone-detection benchmarks).
9+
- Add support for another **code model** checkpoint and compare interpretability lenses.
10+
- Add a new **explanation method** (e.g. attention rollout, integrated gradients).
11+
- Improve **visualizations**, documentation, or tutorials.
12+
- Report bugs in the library, scripts, notebooks, or generated outputs.
1113

12-
## Coding Style
13-
- Follow **PEP 8**.
14-
- Include clear docstrings for public functions and modules.
15-
- Keep changes focused and aligned with the repository's interpretability scope.
14+
Please open a GitHub Issue first to discuss larger changes:
15+
<https://github.com/jorge-martinez-gil/graphcodebert-interpretability/issues>.
1616

17-
## Reproducing Results Locally
18-
From the repository root:
17+
## Project layout
18+
19+
```
20+
graphcodebert_interpretability/ # the installable library
21+
datasets.py # single source of truth for bundled code corpora
22+
model.py # lazy, cached model/tokenizer loading
23+
embeddings.py # token- and sequence-level embeddings
24+
similarity.py # cosine math, compare(), HTML highlighting
25+
saliency.py # gradient saliency maps
26+
projection.py # PCA / t-SNE / UMAP
27+
baselines.py # AST + TF-IDF baselines (no model needed)
28+
visualize.py # publication-quality plotting helpers
29+
report.py # benchmark report: Markdown + LaTeX + figure
30+
cli.py # the `gcbi` command
31+
tests/ # pytest suite (fast tests need no model)
32+
*.py # thin reproduction scripts (pca.py, heatmap.py, ...)
33+
```
34+
35+
The heavy dependencies (`torch`, `transformers`) are imported **lazily inside
36+
functions**, so the library imports and the baseline/projection/report code run
37+
without the deep-learning stack. Please preserve this property: do not add
38+
top-level `import torch` to modules other than where it is already isolated.
39+
40+
## Development setup
41+
42+
```bash
43+
pip install -e ".[dev]" # editable install + ruff + pytest + build
44+
```
45+
46+
## Running checks before a pull request
47+
48+
```bash
49+
ruff check . # lint + import sorting (must pass)
50+
pytest -m "not model" -q # fast suite, no model download (must pass)
51+
pytest -m model # optional: model-backed integration tests
52+
```
53+
54+
CI runs the lint + fast suite on Python 3.9-3.12 and builds the distribution.
55+
56+
## Coding style
57+
58+
- Follow **PEP 8**; `ruff` enforces style and import order (line length 100).
59+
- Add a clear **docstring** to every public function and module.
60+
- Every new feature should ship with **tests** and **documentation**.
61+
- Keep numerical claims **reproducible**: never hard-code or fabricate results.
62+
63+
## Reproducing results locally
1964

2065
```bash
21-
pip install -r requirements.txt
22-
python comparison.py
23-
python heatmap.py
24-
python pca.py
25-
python tsne.py
26-
python pumap.py
27-
python saliency_maps.py
28-
python ablation.py
29-
python ast-s.py
30-
python tf-s.py
66+
pip install ".[full]"
67+
gcbi reproduce # regenerates the full paper figure set
3168
```
3269

33-
For full reproducibility details (runtime expectations, deterministic settings), see [`docs/REPRODUCIBILITY.md`](docs/REPRODUCIBILITY.md).
70+
For full reproducibility details (runtimes, deterministic settings) see
71+
[`docs/REPRODUCIBILITY.md`](docs/REPRODUCIBILITY.md).

0 commit comments

Comments
 (0)