BertNado
BertNado is a modular framework for fine-tuning Hugging Face DNA language models such as GROVER, NT2, and DNABERT variants on genomic prediction tasks. It supports both full fine-tuning and parameter-efficient transfer learning (PEFT) strategies like LoRA.
Features
- Model Support: GROVER, NT2 (Nucleotide Transformer), DNABERT, and other Hugging Face-compatible DNA language models
- Task Flexibility: Supports regression, binary, and multi-label classification, as well as masked DNA modeling
- Chromosome-aware Splits: Train/val/test split by chromosome to prevent data leakage
- Efficient Fine-tuning: Drop-in support for parameter-efficient tuning methods like LoRA
- Hyperparameter Optimization: Integrated with Weights & Biases for Bayesian sweep-based tuning
- Robust Evaluation: Automatically generates ROC, PR, and confusion matrix plots for binary classification
- Model Interpretation: SHAP and Captum Layer Integrated Gradients (LIG) for biological insight
- Trainer Integration: Built on Hugging Face Trainer with custom heads and metrics
- W&B Logging: Full experiment tracking with Weights & Biases out of the box
Installation
git clone https://github.com/CChahrour/BertNado.git
cd BertNado
pip install -e .
Project Structure
bertnado/
├── cli.py # Command-line interface
├── data/
│ └── prepare_dataset.py # Dataset creation and tokenization
├── evaluation/
│ ├── predict.py # Predict from trained models
│ └── feature_extraction.py # SHAP / LIG-based interpretation
└── training/
├── finetune.py # Fine-tuning using best config
├── full_train.py # Full training loop
├── model.py # PEFT/LoRA model architecture
├── sweep.py # W&B sweep setup
├── trainers.py # Trainer wrappers
└── metrics.py # Metric computation
Quickstart
Step 1: Prepare Dataset
bertnado-data \
--file-path test/data/mock_data.parquet \
--target-column bound \
--fasta-file test/data/mock_genome.fasta \
--tokenizer-name PoetschLab/GROVER \
--output-dir output/dataset \
--task-type binary_classification \
--threshold 0.5
Step 2: Run Hyperparameter Sweep
bertnado-sweep \
--config-path test/data/mock_sweep_config.json \
--output-dir output/sweep \
--model-name PoetschLab/GROVER \
--dataset output/dataset \
--sweep-count 2 \
--project-name project \
--metric-name eval/roc_auc \
--metric-goal maximize \
--task-type binary_classification
--config-path points to a Weights & Biases sweep config. The sweep metric is
also used to choose the best checkpoint inside each run.
Step 3: Train Best Model
bertnado-train \
--output-dir output/train \
--model-name PoetschLab/GROVER \
--dataset output/dataset \
--best-config-path output/sweep/best_sweep_config.json \
--task-type binary_classification \
--project-name project \
--metric-name eval/roc_auc \
--metric-goal maximize
The metric flags are optional when best_sweep_config.json was produced by
bertnado-sweep, because the resolved metric is saved in that file.
Step 4: Predict on Test Set
bertnado-predict \
--tokenizer-name PoetschLab/GROVER \
--model-dir output/train/model \
--dataset-dir output/dataset \
--output-dir output/predictions \
--task-type binary_classification
Step 5: Interpret Model with SHAP or LIG
bertnado-feature \
--tokenizer-name PoetschLab/GROVER \
--model-dir output/train/model \
--dataset-dir output/dataset \
--output-dir output/feature_analysis \
--task-type binary_classification \
--method shap \
--target-class 1
Run both SHAP and LIG:
--method both --target-class 1
Outputs
-
Figures saved to
output/figures/- Binary classification: ROC and precision-recall curves
- Binary classification: Confusion matrix
- Multilabel classification: ROC, precision-recall, confusion matrix, and label count plots
-
Prediction metrics saved to
output/predictions/metrics.json- Multilabel classification: aggregate metrics plus per-label CSV metrics
-
SHAP scores saved to
output/shap/ -
Trained models saved to
output/models/
Interpretation Tools
- SHAP: Global and local token importance
- Captum LIG: Gradient-based token attribution at the embedding level
Acknowledgements
- Hugging Face Transformers
- PoetschLab/GROVER
- PEFT/LoRA
- SHAP & Captum for interpretability
crestedfor efficient sequence extraction
Metadata
Release files for bertnado 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| bertnado-0.1.7.tar.gz | 625.0 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bertnado-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 669.6 kB
Release files / bertnado-0.1.7.tar.gz
| Download URL | bertnado-0.1.7.tar.gz |
|---|---|
| Size | 625.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cdbe323287b4f99ebed9166cb93dcf9b9eebaa4d7a5add4ab5ddc99cf673183c
|
|
BLAKE2b-256 checksum How to use checksums |
69d018371f1cdc29d0ac8cf2128c24d1b114803633d6bcedd809e032bf4ba784
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 11, 2026.
Transparency logRelease files / bertnado-0.1.7-py3-none-any.whl
| Download URL | bertnado-0.1.7-py3-none-any.whl |
|---|---|
| Size | 44.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f3974a334c40d832045120f6e2ae906191b7c1e9955ca5fc5b97075cae96e65f
|
|
BLAKE2b-256 checksum How to use checksums |
1b4d93e8b0ae9b2e91610ea16985737b02fe17b23658069d358a1597b1476652
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 11, 2026.
Transparency logSecurity for bertnado 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for bertnado-0.1.7.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 11, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.