Classification Heads¶
dnallm.models.head ¶
Classes¶
BasicCNNHead ¶
BasicCNNHead(
input_dim,
num_classes,
task_type="binary",
num_filters=128,
kernel_sizes=None,
dropout=0.2,
**kwargs,
)
Bases: Module
A CNN-based head for processing Transformer output sequences. This head applies multiple 1D convolutional layers with different kernel sizes to capture local patterns in the sequence data, followed by a fully connected layer for classification or regression tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dim
|
int
|
Dimension of the input features |
required |
num_classes
|
int
|
Number of output classes (for classification tasks) |
required |
task_type
|
str
|
Type of task - 'binary', 'multiclass', 'multilabel', or 'regression' |
'binary'
|
num_filters
|
int
|
Number of filters for each convolutional layer |
128
|
kernel_sizes
|
list | None
|
List of kernel sizes for the convolutional layers |
None
|
dropout
|
float
|
Dropout probability |
0.2
|
Source code in dnallm/models/head.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
BasicLSTMHead ¶
BasicLSTMHead(
input_dim,
num_classes,
task_type="binary",
hidden_size=256,
num_layers=1,
dropout=0.1,
bidirectional=True,
**kwargs,
)
Bases: Module
A LSTM-based head for processing Transformer output sequences. This head applies a multi-layer LSTM to capture sequential dependencies in the sequence data, followed by a fully connected layer for classification or regression tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dim
|
int
|
Dimension of the input features |
required |
num_classes
|
int
|
Number of output classes (for classification tasks) |
required |
task_type
|
str
|
Type of task - 'binary', 'multiclass', 'multilabel', or 'regression' |
'binary'
|
hidden_size
|
int
|
Number of features in the hidden state of the LSTM |
256
|
num_layers
|
int
|
Number of recurrent layers in the LSTM |
1
|
dropout
|
float
|
Dropout probability between LSTM layers |
0.1
|
bidirectional
|
bool
|
Whether to use a bidirectional LSTM |
True
|
Source code in dnallm/models/head.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
BasicMLPHead ¶
BasicMLPHead(
input_dim,
num_classes=2,
task_type="binary",
hidden_dims=None,
activation_fn="relu",
use_normalization=True,
norm_type="layernorm",
dropout=0.1,
**kwargs,
)
Bases: Module
A universal and customizable MLP model designed to be appended after the embedding output of models like Transformers to perform various downstream tasks such as classification and regression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dim
|
int
|
Dimension of the input features |
required |
num_classes
|
int
|
Number of output classes (for classification tasks) |
2
|
task_type
|
str
|
Type of task - 'binary', 'multiclass', 'multilabel', or 'regression' |
'binary'
|
hidden_dims
|
list | None
|
List of hidden layer dimensions |
None
|
activation_fn
|
str
|
Activation function to use ('relu', 'gelu', 'silu', 'tanh', 'sigmoid') |
'relu'
|
use_normalization
|
bool
|
Whether to use normalization layers |
True
|
norm_type
|
str
|
Type of normalization - 'batchnorm' or 'layernorm' |
'layernorm'
|
dropout
|
float
|
Dropout probability |
0.1
|
Source code in dnallm/models/head.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
BasicUNet1DHead ¶
BasicUNet1DHead(
input_dim,
num_classes,
task_type="binary",
num_layers=2,
initial_filters=64,
**kwargs,
)
Bases: Module
An U-net architecture adapted for 1D sequence data, suitable for classification and regression tasks. This model consists of an encoder-decoder structure with skip connections, allowing it to capture both local and global features in the inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dim
|
int
|
The number of input features (channels) in the inputs. |
required |
num_classes
|
int
|
The number of output classes for the classification task. |
required |
task_type
|
str
|
The type of task (e.g., "binary" or "multi-class"). |
'binary'
|
num_layers
|
int
|
The number of downsampling/upsampling layers in the U-net. |
2
|
initial_filters
|
int
|
The number of filters in the first convolutional layer. |
64
|
Source code in dnallm/models/head.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
DoubleConv ¶
DoubleConv(in_channels, out_channels)
Bases: Module
(Convolution => [BatchNorm] => ReLU) * 2
Source code in dnallm/models/head.py
250 251 252 253 254 255 256 257 258 259 | |
EVOForSeqClsHead ¶
EVOForSeqClsHead(
base_model,
num_classes=2,
task_type="binary",
target_layer=None,
pooling_method="mean",
dropout_prob=0.1,
**kwargs,
)
Bases: Module
A classification head tailored for the embedding outputs of the EVO-series model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_model
|
Any
|
The EVO model instance providing embeddings. |
required |
num_classes
|
int
|
Number of output classes for classification. |
2
|
task_type
|
str
|
Type of task - 'binary', 'multiclass', 'multilabel', or 'regression'. |
'binary'
|
target_layer
|
str | list[str] | None
|
Specific layer(s) from which to extract embeddings. Can be 'all' to average all layers, a list of layer names, or a single layer name. |
None
|
pooling_method
|
str
|
Method to pool sequence embeddings. |
'mean'
|
dropout_prob
|
float
|
Dropout probability for regularization |
0.1
|
Source code in dnallm/models/head.py
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | |
MegaDNAMultiScaleHead ¶
MegaDNAMultiScaleHead(
embedding_dims=None,
num_classes=2,
task_type="binary",
hidden_dims=None,
dropout=0.2,
**kwargs,
)
Bases: Module
A classification head tailored for the multi-scale embedding outputs of the MegaDNA model. It takes a list of embedding tensors, pools each tensor, and concatenates the results before passing them to an MLP for classification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding_dims
|
list | None
|
A list of integers representing the dimensions of the input embeddings. |
None
|
num_classes
|
int
|
The number of output classes for classification. |
2
|
task_type
|
str
|
The type of task (e.g., "binary" or "multi-class"). |
'binary'
|
hidden_dims
|
list | None
|
A list of integers representing the sizes of hidden layers in the MLP. |
None
|
dropout
|
float
|
Dropout probability for regularization. |
0.2
|
Source code in dnallm/models/head.py
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |