Skip to main content

dbtk-dnabert

An implementation of DNABERT using Pytorch and the deepbio-toolkit library.

Getting Started

  1. Install the dbtk-dnabert package
pip install dbtk-dnabert
  1. Pull pre-trained DNABERT model
from dnabert import DnaBert

# Load the pre-trained model
model = DnaBert.from_pretrained("SirDavidLudwig/dnabert", revision="64d-silva16s-250bp")

Examples

Embed DNA sequences

# Sequences to embed
sequences = [
    "ACTGAATGAGAC",
    "TTGAGTAGCCAA"
]

# Tokenize sequences
sequence_tokens = torch.tensor([model.tokenizer(sequence) for sequence in sequences])

# Embed sequences
output = model(sequence_tokens)

# Sequence-level embeddings from class token
embeddings = output["class"]

# Sequence-level embeddings from averaged tokens
embeddings = output["tokens"].mean(dim=1)

Pre-trained Models

Model Name Embedding Dim. Maximum Length Pre-training Dataset
64d-silva16s-250bp 64 250bp Silva 16S
768d-silva16s-250bp 768 250bp Silva 16S

Development

1. Model Configuration

Template model configurations can be generated using the dbtk model config command.

2. Pre-training

The model can be pre-trained using the supplied configurations with the command:

dbtk model fit \
    -c ./configs/datamodules/pretrain_silva_16s_250bp.yaml \
    -c ./configs/models/pretrain_dnabert_768d_250bp.yaml \
    -c ./configs/trainers/pretrainer.yaml \
    ./logs/dnabert_768d_250bp

3. Exporting

The trained model can be exported to a Huggingface model with the following command.

dbtk model export ./logs/dnabert_768d_250bp/last.ckpt ./exports/dnabert_768d_250bp

Metadata

Release files for dbtk-dnabert 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dbtk-dnabert 1.2.2
File Size Uploaded
dbtk_dnabert-1.2.2.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dbtk-dnabert 1.2.2
File Interpreter ABI Platform
dbtk_dnabert-1.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / dbtk_dnabert-1.2.2.tar.gz

Download URL dbtk_dnabert-1.2.2.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2f7178a72670997f49953d521f4a0dfadecdb325dfeeb136bc57660ff4fe5e9c
BLAKE2b-256 checksum
How to use checksums
e4371d54bce56575cfb2aa568119c1f3ab5fd956a50793d1c174ad9c33753fc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / dbtk_dnabert-1.2.2-py3-none-any.whl

Download URL dbtk_dnabert-1.2.2-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7851c0ef785f77c9dab3e67a13f641feb92b3c977431841b795da54708277bb7
BLAKE2b-256 checksum
How to use checksums
cb217010e569223b9ca677f42113e3d9d57505fe06e2467fba01892808cd5237
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 release files

1.2.1

2 release files

1.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page