dbtk-dnabert
An implementation of DNABERT using Pytorch and the deepbio-toolkit library.
Getting Started
- Install the dbtk-dnabert package
pip install dbtk-dnabert
- 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)
| File | Size | Uploaded | |
|---|---|---|---|
| dbtk_dnabert-1.2.2.tar.gz | 6.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|