Initialize and use the Enformer model
mainYou can instantiate an Enformer model using Enformer.from_hparams. The model accepts DNA sequences as integer indices (representing ACGTN, where -1 is padding) or as one-hot encoded float tensors.
To convert integer indices to one-hot encodings, use the seq_indices_to_one_hot utility function.
import torch
from enformer_pytorch import Enformer, seq_indices_to_one_hot
model = Enformer.from_hparams(
dim = 1536,
depth = 11,
heads = 8,
output_heads = dict(human = 5313, mouse = 1643),
target_length = 896,
)
# Using integer indices (ACGTN order, -1 for padding)
seq = torch.randint(0, 5, (1, 196_608))
output = model(seq)
# Using one-hot encodings
one_hot = seq_indices_to_one_hot(seq)
output = model(one_hot)