Downloads · 30 days
25
19% of all-time downloads
OceanOmics/eDNABERT-S_12S
eDNABERT-S_12S is a text generation model from OceanOmics. Use it when you need the model to write or continue text. The card lists the license as apache-2.0.
This model is our first step towards ecosystem-level modeling.
Downloads · 30 days
25
19% of all-time downloads
All-time downloads
133
Public
Repo size
937 MB
Likes
0
Public
Click a slice to open those files.
.bin468 MB · 100%
From the Hugging Face model README
This model is our first step towards ecosystem-level modeling.
We finetuned DNABERT-S using all of our eDNA ASVs from the Australian Marine Parks project. We used 28,122 Miya 12S ASVs collected from more than 6,000 samples for finetuning.
A partner model for Berry 16S data is also available.
There's a conda environment in this repository in DNABERT_S.yml.
conda env create -f DNABERT_S.yml
I've been using this model to visualise ecosystem embeddings.
import torch
from transformers import AutoTokenizer, AutoModel, AutoConfig
from Bio import SeqIO
from sklearn.manifold import TSNE
import numpy as np
from tqdm import tqdm # For progress tracking
# Device configuration
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print(f"Using device: {device}")
config = AutoConfig.from_pretrained('zhihan1996/DNABERT-S', trust_remote_code = True)
# Load model and tokenizer
tokenizer_12S = AutoTokenizer.from_pretrained('OceanOmics/eDNABERT-S_12S', trust_remote_code=True)
model_12S = AutoModel.from_pretrained('OceanOmics/eDNABERT-S_12S', trust_remote_code=True, config=config)
model_12S.to(device)
model_12S.eval()
names_12, seqs_12 = [], []
for seq in SeqIO.parse('12S_all_ASVs.fasta', 'fasta'):
if 165 <= len(str(seq.seq)) <= 180: # More efficient condition check
seqs_12.append(str(seq.seq))
names_12.append(str(seq.id))
print(f"Processing {len(seqs_12)} sequences")
batch_size = 32 # tested on an A100
num_sequences = len(seqs_12)
all_e_12 = np.zeros((num_sequences, 768))
with torch.no_grad(): # no gradient calculation for inference
for i in tqdm(range(0, num_sequences, batch_size)):
batch_seqs = seqs_12[i:i+batch_size]
inputs = tokenizer_12S(batch_seqs, return_tensors='pt', padding=True)
inputs = {k: v.to(device) for k, v in inputs.items()} # Move inputs to device
hidden_states = model_12S(**inputs)[0]
for j, hidden_state in enumerate(hidden_states):
embedding_mean = torch.mean(hidden_state, dim=0)
all_e_12[i+j] = embedding_mean.cpu().numpy() # Store directly in pre-allocated array
print("Running TSNE...")
X_embedded = TSNE(
n_components=2,
learning_rate='auto',
init='random',
perplexity=50, # Reasonable value
n_jobs=-1 # Use all available cores
).fit_transform(all_e_12)
print("Saving results...")
with open('odr_all_tsne_12S.optimized.tsv', 'w') as out:
for a, name in zip(X_embedded, names_12):
out.write('\t'.join(map(str, list(a) + name.split("XXX"))) + '\n')
You can see results visualised in action here: https://marine-parks.minderoo.org/#!/unknown
I'm hoping you'll come up with these! It would be great if we could plug this or similar models into ecosystem-level models such as BioAnalyst
This model is trained using Miya et al. 12S metabarcoding results based on Australian marine samples. The 12S assay is fairly fish-specific so you might not have the best time applying this model to other organisms or ecosystems.
Use the code below to get started with the model.
[More Information Needed]
[More Information Needed]
We had many primer dimers in our ASV data, so I got rid of too-short and too-long ASVs. Cehck what your ASVs look like.
Using the original DNABERT-S training script:
python main.py [.. skipping data flags..]
--seed 1
--max_length 2000
--train_batch_size 8
--val_batch_size 8
--lr 3e-06
--lr_scale 100
--epochs 3
--feat_dim 128
--temperature 0.05
--con_method same_species
--mix
--mix_alpha 1.0
--mix_layer_num -1
--curriculum
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
BibTeX:
[More Information Needed]
APA:
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]