Skip to main content

A toolkit for addressing confounding effects in text classification problems

Project description

DeconDTN-Toolkit

License: MIT PyPI - Python Version PyPI - Version

DeconDTN Toolkit is a PyTorch suite containing benchmark datasets and algorithms for confounding effects in text classification.

[Docs] [Dataset Access]

Features

If a dataset is drawn from two different sources, one may be enriched for the outcome of interest (i.e. $P(Y \mid \text{source1}) \neq P(Y \mid \text{source2})$ ). In this situation a model may learn to recognize the data source, and make predictions in accordance with their class distribution, rather than on the basis of relevant features. This scenario, which we refer to as provenance shift, was the primary motivating use case for the development of the DeconDTN toolkit, though the same evaluation framework and methods of mitigation can apply to other confounding variables also.

  • An evaluation framework for assessment of robustness to confounding shifts in which the proportion of positive examples changes with a confounding variable.
  • A range of algorithms with the potential to mitigate for confounding shift
  • A range of benchmark datasets to evaluate performance.

Available Algorithms

The currently available algorithms are:

Send us a PR to add your algorithm! Our implementations use the hyper-parameter grids described here.

Available Datasets

The currently available datasets are:

Installation

Prerequisites

  • Ubuntu 18.04 or higher
  • CUDA 12.1 or higher
  • Python 3.10 or higher
  • pip

Python Package

pip install --index-url https://test.pypi.org/simple/ \
            --extra-index-url https://pypi.org/simple/ \
            decon-dtn-toolkit

From source

Option 1: uv (Recommended)

# Create virtual environment
uv venv dedtn-env
source dedtn-env/bin/activate  # On Linux/Mac
# dedtn-env\Scripts\activate  # On Windows

# Install the package in editable mode (for development)
uv pip install -e .
Option 2: conda Conda is ideal for managing complex dependencies, especially with CUDA/PyTorch installations. It provides both package and environment management.
# Create environment with Python 3.12
conda create -n dedtn-tool python=3.12
conda activate dedtn-tool

# Install the package in editable mode
pip install -e .
Option 3: venv (Python Built-in) venv is Python's built-in virtual environment tool - lightweight and requires no additional installation. Good for standard Python projects.
# Create virtual environment
python -m venv dedtn-env

# Activate environment
# On Linux/Mac:
source dedtn-env/bin/activate
# On Windows:
# dedtn-env\Scripts\activate

# Install the package
pip install -e .

Verify Installation

After activating your chosen environment, you can verify the installation with:

python -c "import decon_dtn_toolkit; print('DeconDTN-Toolkit installed successfully')"

Quick Start

To train DANN on the Amazon_Reviews dataset

from decon_dtn_toolkit import datasets
from decon_dtn_toolkit.trainer import TrainConfig, Trainer

data_dir = "PATH_TO_Amazon_Reviews_2018"
amazon_reviews = vars(datasets)["Amazon_Reviews_2018"](root=data_dir)
config = TrainConfig(algorithm='DANN')
model = Trainer(dataset=dataset, config=config)
model.train()

Unittest

python -m unittest discover

Acknowledgement

This project is built upon

  • DomainBed - A PyTorch suite containing benchmark datasets and algorithms for domain generalization in computer vision - MIT license
  • WILDS - A benchmark of in-the-wild distribution shifts spanning diverse data modalities and applications - MIT license
  • SubpopBench - A benchmark of subpopulation shift - MIT license

Citation

Below are citations of the DeconDTN line of work.

@inproceedings{ding2024backdoor,
  title={Backdoor adjustment of confounding by provenance for robust text classification of multi-institutional clinical notes},
  author={Ding, Xiruo and Sheng, Zhecheng and Yeti{\c{s}}gen, Meliha and Pakhomov, Serguei and Cohen, Trevor},
  booktitle={AMIA Annual Symposium Proceedings},
  volume={2023},
  pages={923},
  year={2024}
}
@article{ding2025tailoring,
  title={Tailoring task arithmetic to address bias in models trained on multi-institutional datasets},
  author={Ding, Xiruo and Sheng, Zhecheng and Hur, Brian and Tauscher, Justin and Ben-Zeev, Dror and Yeti{\c{s}}gen, Meliha and Pakhomov, Serguei and Cohen, Trevor},
  journal={Journal of Biomedical Informatics},
  pages={104858},
  year={2025},
  publisher={Elsevier}
}
@inproceedings{sheng2025mitigating,
  title={Mitigating confounding in speech-based dementia detection through weight masking},
  author={Sheng, Zhecheng and Ding, Xiruo and Hur, Brian and Li, Changye and Cohen, Trevor and Pakhomov, Serguei VS},
  booktitle={Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)},
  pages={10419--10434},
  year={2025}
}

Key Contributors (listed alphabetically)

Trevor Cohen

Xiruo Ding

Yongsen Tan

Zhecheng Sheng

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

decon_dtn_toolkit-0.1.1.tar.gz (133.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

decon_dtn_toolkit-0.1.1-py3-none-any.whl (47.9 kB view details)

Uploaded Python 3

File details

Details for the file decon_dtn_toolkit-0.1.1.tar.gz.

File metadata

  • Download URL: decon_dtn_toolkit-0.1.1.tar.gz
  • Upload date:
  • Size: 133.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for decon_dtn_toolkit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2ded1ad00287738da89964954bdf40c879f185de447528d276e31de77e53db6f
MD5 f21ef53dbf7abb1b431526934350aad0
BLAKE2b-256 c96fd8a7f5cfe178de9f0ce1689009dcb13945844b2209e9b81328eda60cf22f

See more details on using hashes here.

File details

Details for the file decon_dtn_toolkit-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: decon_dtn_toolkit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 47.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for decon_dtn_toolkit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 49758c285f12062f5f3140fbd9acbcdac75e895698220436b7b4c22de50ee411
MD5 e2231426b78c088417774c3b56d15401
BLAKE2b-256 6d33cea92bbdc48afb0928106b78aff6bcc353b0f2039f7d0c72a18f20af2173

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page