Metadata-Version: 2.4
Name: gradiend
Version: 0.3.0
Summary: GRADIEND: Gradient-based Targeted Feature Learning within Neural Networks
Author-email: Jonathan Drechsel <jonathan.drechsel@uni-passau.de>
License: Apache-2.0
Project-URL: Homepage, https://github.com/aieng-lab/gradiend
Project-URL: Documentation, https://aieng-lab.github.io/gradiend/
Project-URL: Repository, https://github.com/aieng-lab/gradiend
Project-URL: Bug Tracker, https://github.com/aieng-lab/gradiend/issues
Keywords: machine learning,neural networks,feature learning,interpretability
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch>=2.0.0
Requires-Dist: transformers<6.0.0,>=4.30.0
Requires-Dist: numpy>=1.20.0
Requires-Dist: pandas>=1.3.0
Requires-Dist: tqdm>=4.60.0
Provides-Extra: recommended
Requires-Dist: accelerate>=0.26.0; extra == "recommended"
Requires-Dist: safetensors>=0.3.0; extra == "recommended"
Requires-Dist: sentencepiece>=0.1.99; extra == "recommended"
Requires-Dist: datasets>=3.0.2; extra == "recommended"
Requires-Dist: spacy<3.8.0,>=3.5.0; python_version < "3.10" and extra == "recommended"
Requires-Dist: spacy>=3.5.0; python_version >= "3.10" and extra == "recommended"
Requires-Dist: pyarrow>=14.0.0; extra == "recommended"
Requires-Dist: pyahocorasick>=2.0.0; extra == "recommended"
Requires-Dist: matplotlib>=3.5.0; extra == "recommended"
Requires-Dist: seaborn>=0.12.0; extra == "recommended"
Requires-Dist: plotly>=5.0.0; extra == "recommended"
Requires-Dist: venn>=0.1.0; extra == "recommended"
Requires-Dist: matplotlib_venn>=0.11.7; extra == "recommended"
Requires-Dist: adjustText>=0.7.3; extra == "recommended"
Provides-Extra: data
Requires-Dist: datasets>=3.0.2; extra == "data"
Requires-Dist: spacy<3.8.0,>=3.5.0; python_version < "3.10" and extra == "data"
Requires-Dist: spacy>=3.5.0; python_version >= "3.10" and extra == "data"
Requires-Dist: pyarrow>=14.0.0; extra == "data"
Requires-Dist: pyahocorasick>=2.0.0; extra == "data"
Provides-Extra: plot
Requires-Dist: matplotlib>=3.5.0; extra == "plot"
Requires-Dist: seaborn>=0.12.0; extra == "plot"
Requires-Dist: plotly>=5.0.0; extra == "plot"
Requires-Dist: venn>=0.1.0; extra == "plot"
Requires-Dist: matplotlib_venn>=0.11.7; extra == "plot"
Requires-Dist: adjustText>=0.7.3; extra == "plot"
Provides-Extra: dev
Requires-Dist: mkdocs-material>=9.0.0; extra == "dev"
Requires-Dist: mkdocstrings[python]>=0.24.0; extra == "dev"
Requires-Dist: pre-commit>=3.0.0; extra == "dev"
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Dynamic: license-file

# GRADIEND

**Gradient-based targeted feature learning within neural networks.** Learn where a language model encodes a feature (e.g. gender, race) and rewrite the model to strengthen or weaken it—for example debias it—while keeping other behaviour unchanged.

[![EMNLP 2026 Demos](https://img.shields.io/badge/EMNLP%202026-System%20Demonstrations-blue.svg)](https://aclanthology.org/2026.emnlp-demos.18/)
[![arXiv:2502.01406](https://img.shields.io/badge/arXiv-2502.01406-blue.svg)](https://arxiv.org/abs/2502.01406)
[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Tests](https://github.com/aieng-lab/gradiend/actions/workflows/tests.yml/badge.svg)](https://github.com/aieng-lab/gradiend/actions/workflows/tests.yml)
[![Documentation](https://img.shields.io/badge/docs-github.io-blue.svg)](https://aieng-lab.github.io/gradiend/)

Paper: 

- [GRADIEND: Feature Learning within Neural Networks Exemplified through Biases](https://arxiv.org/abs/2502.01406) 
- [The GRADIEND Python Package: An End-to-End System for Gradient-Based Feature Learning](https://aclanthology.org/2026.emnlp-demos.18/) (EMNLP 2026 System Demonstrations)

---

**Try it in Google Colab:** [Quickstart](https://colab.research.google.com/github/aieng-lab/gradiend/blob/main/gradiend/examples/demo/01_quickstart_english_pronouns.ipynb) · [Sentiment](https://colab.research.google.com/github/aieng-lab/gradiend/blob/main/gradiend/examples/demo/02_sentiment.ipynb) · [Compare features](https://colab.research.google.com/github/aieng-lab/gradiend/blob/main/gradiend/examples/demo/03_compare_features.ipynb) · [Learn your own feature](https://colab.research.google.com/github/aieng-lab/gradiend/blob/main/gradiend/examples/demo/04_learn_your_own_feature.ipynb)

---

## Install

```bash
pip install gradiend
```

Optional extras (install one or combine with e.g. `gradiend[data,plot]`):

| Tag | Command | Includes                                     |
|-----|---------|----------------------------------------------|
| **recommended** | `pip install gradiend[recommended]` | full data generation, training, and plotting |
| **data** | `pip install gradiend[data]` | for advanced data generation and import |
| **plot** | `pip install gradiend[plot]` | for plotting support |                                                                                   |
| **dev** | `pip install gradiend[dev]` | for building docs and running tests |

---

## Links

| | |
|---|---|
| **Documentation** | [aieng-lab.github.io/gradiend](https://aieng-lab.github.io/gradiend/) |
| **Source & issues** | [github.com/aieng-lab/gradiend](https://github.com/aieng-lab/gradiend) |
| **Example scripts & notebooks** | [gradiend/examples](https://github.com/aieng-lab/gradiend/tree/main/gradiend/examples) — start_workflow, train_english_pronouns, gender_de, gender_en, train_race_religion, etc. |
| **Datasets (Hugging Face)** | [de-gender-case-articles](https://huggingface.co/datasets/aieng-lab/de-gender-case-articles), [gradiend_race_data](https://huggingface.co/datasets/aieng-lab/gradiend_race_data), [gradiend_religion_data](https://huggingface.co/datasets/aieng-lab/gradiend_religion_data), [biasneutral](https://huggingface.co/datasets/aieng-lab/biasneutral), [geneutral](https://huggingface.co/datasets/aieng-lab/geneutral) |
| **Pre-trained GRADIEND models** | [bert-base-cased-gradiend-gender-debiased](https://huggingface.co/aieng-lab/bert-base-cased-gradiend-gender-debiased), [gpt2-gradiend-gender-debiased](https://huggingface.co/aieng-lab/gpt2-gradiend-gender-debiased), [Llama-3.2-3B-gradiend-gender-debiased](https://huggingface.co/aieng-lab/Llama-3.2-3B-gradiend-gender-debiased) |

---

## Citation

The Python package paper:
```bibtex
@inproceedings{drechsel2026gradiendpythonpackage,
    title = "The {GRADIEND} Python Package: An End-to-End System for Gradient-Based Feature Learning",
    author = "Drechsel, Jonathan  and
      Herbold, Steffen",
    editor = "Agrawal, Sweta  and
      Abad, Alberto",
    booktitle = "Proceedings of the 2026 Conference on Empirical Methods in Natural Language Processing: System Demonstrations",
    month = oct,
    year = "2026",
    address = "Budapest, Hungary",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2026.emnlp-demos.18/",
    doi = "10.18653/2026.emnlp-demos.18",
    pages = "189--198",
    ISBN = "979-8-89176-461-3",
    abstract = "We present `gradiend{`}, an open-source Python package that operationalizes the GRADIEND method for learning feature directions from factual-counterfactual MLM and CLM gradients in language models. The package provides a unified workflow for feature-related data creation, training, evaluation, visualization, persistent model rewriting via controlled weight updates, and multi-feature comparison. We demonstrate `gradiend{`} through an English pronoun running example, a semantic sentiment use case that evaluates lexical generalization to held-out target words, and a large-scale feature comparison."
}
```

The original GRADIEND method paper:
```bibtex
@misc{drechsel2025gradiend,
  title={{GRADIEND}: Feature Learning within Neural Networks Exemplified through Biases},
  author={Jonathan Drechsel and Steffen Herbold},
  year={2025},
  eprint={2502.01406},
  archivePrefix={arXiv},
  primaryClass={cs.LG},
  url={https://arxiv.org/abs/2502.01406},
}
```

---

## License

Apache 2.0. See [LICENSE](https://github.com/aieng-lab/gradiend/blob/main/LICENSE) on GitHub.
