heads¶
heads
provide a collection of pre-defined prediction heads.
heads
take in either a ModelOutupt
, a dict
, or a tuple
as input.
It automatically looks for the model output required for prediction and processes it accordingly.
Some prediction heads may require additional information, such as the attention_mask
or the input_ids
, like ContactPredictionHead
.
These additional arguments can be passed in as arguments/keyword arguments.
Note that heads
use the same ModelOutupt
conventions as the Transformers.
If the model output is a tuple
, we consider the first element as the pooler_output
, the second element as the last_hidden_state
, and the last element as the attention_map
.
It is the user’s responsibility to ensure that the model output is correctly formatted.
If the model output is a ModelOutupt
or a dict
, the heads
will look for the HeadConfig.output_name
from the model output.
You can specify the output_name
in the HeadConfig
to ensure that the heads
can correctly locate the required tensor.
multimolecule.module.heads.config
¶
HeadConfig
dataclass
¶
Bases: BaseHeadConfig
Configuration class for a prediction head.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
int
|
Number of labels to use in the last layer added to the model, typically for a classification task. Head should look for |
None
|
|
str
|
Problem type for Head should look for |
None
|
|
int | None
|
Dimensionality of the encoder layers and the pooler layer. Head should look for |
None
|
|
float
|
The dropout ratio for the hidden states. |
0.0
|
|
str | None
|
The transform operation applied to hidden states. |
None
|
|
str | None
|
The activation function of transform applied to hidden states. |
'gelu'
|
|
bool
|
Whether to apply bias to the final prediction layer. |
True
|
|
str | None
|
The activation function of the final prediction output. |
None
|
|
float
|
The epsilon used by the layer normalization layers. |
1e-12
|
|
`str`, *optional*
|
The name of the tensor required in model outputs. If is |
None
|
Source code in multimolecule/module/heads/config.py
MaskedLMHeadConfig
dataclass
¶
Bases: BaseHeadConfig
Configuration class for a Masked Language Modeling head.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
int | None
|
Dimensionality of the encoder layers and the pooler layer. Head should look for |
None
|
|
float
|
The dropout ratio for the hidden states. |
0.0
|
|
str | None
|
The transform operation applied to hidden states. |
'nonlinear'
|
|
str | None
|
The activation function of transform applied to hidden states. |
'gelu'
|
|
bool
|
Whether to apply bias to the final prediction layer. |
True
|
|
str | None
|
The activation function of the final prediction output. |
None
|
|
float
|
The epsilon used by the layer normalization layers. |
1e-12
|
|
`str`, *optional*
|
The name of the tensor required in model outputs. If is |
None
|
Source code in multimolecule/module/heads/config.py
multimolecule.module.heads.sequence
¶
SequencePredictionHead
¶
Bases: PredictionHead
Head for tasks in sequence-level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
PreTrainedConfig
|
The configuration object for the model. |
required |
|
HeadConfig | None
|
The configuration object for the head.
If None, will use configuration from the |
None
|
Source code in multimolecule/module/heads/sequence.py
output_name
class-attribute
instance-attribute
¶
The default output to use for the head.
forward
¶
Python | |
---|---|
|
Forward pass of the SequencePredictionHead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
ModelOutput | Tuple[Tensor, ...]
|
The outputs of the model. |
required |
|
Tensor | None
|
The labels for the head. |
None
|
|
str | None
|
The name of the output to use.
Defaults to |
None
|
Source code in multimolecule/module/heads/sequence.py
multimolecule.module.heads.token
¶
TokenPredictionHead
¶
Bases: PredictionHead
Head for tasks in token-level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
PreTrainedConfig
|
The configuration object for the model. |
required |
|
HeadConfig | None
|
The configuration object for the head.
If None, will use configuration from the |
None
|
Source code in multimolecule/module/heads/token.py
output_name
class-attribute
instance-attribute
¶
The default output to use for the head.
forward
¶
Python | |
---|---|
|
Forward pass of the TokenPredictionHead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
ModelOutput | Tuple[Tensor, ...]
|
The outputs of the model. |
required |
|
Tensor | None
|
The attention mask for the inputs. |
None
|
|
NestedTensor | Tensor | None
|
The input ids for the inputs. |
None
|
|
Tensor | None
|
The labels for the head. |
None
|
|
str | None
|
The name of the output to use.
Defaults to |
None
|
Source code in multimolecule/module/heads/token.py
TokenKMerHead
¶
Bases: PredictionHead
Head for tasks in token-level with kmer inputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
PreTrainedConfig
|
The configuration object for the model. |
required |
|
HeadConfig | None
|
The configuration object for the head.
If None, will use configuration from the |
None
|
Source code in multimolecule/module/heads/token.py
Python | |
---|---|
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 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 |
|
output_name
class-attribute
instance-attribute
¶
The default output to use for the head.
forward
¶
Python | |
---|---|
|
Forward pass of the TokenKMerHead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
ModelOutput | Tuple[Tensor, ...]
|
The outputs of the model. |
required |
|
Tensor | None
|
The attention mask for the inputs. |
None
|
|
NestedTensor | Tensor | None
|
The input ids for the inputs. |
None
|
|
Tensor | None
|
The labels for the head. |
None
|
|
str | None
|
The name of the output to use.
Defaults to |
None
|
Source code in multimolecule/module/heads/token.py
multimolecule.module.heads.contact
¶
ContactPredictionHead
¶
Bases: PredictionHead
Head for tasks in contact-level.
Performs symmetrization, and average product correct.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
PreTrainedConfig
|
The configuration object for the model. |
required |
|
HeadConfig | None
|
The configuration object for the head.
If None, will use configuration from the |
None
|
Source code in multimolecule/module/heads/contact.py
Python | |
---|---|
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
output_name
class-attribute
instance-attribute
¶
The default output to use for the head.
forward
¶
Python | |
---|---|
|
Forward pass of the ContactPredictionHead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
ModelOutput | Mapping | Tuple[Tensor, ...]
|
The outputs of the model. |
required |
|
Tensor | None
|
The attention mask for the inputs. |
None
|
|
NestedTensor | Tensor | None
|
The input ids for the inputs. |
None
|
|
Tensor | None
|
The labels for the head. |
None
|
|
str | None
|
The name of the output to use.
Defaults to |
None
|
Source code in multimolecule/module/heads/contact.py
multimolecule.module.heads.pretrain
¶
MaskedLMHead
¶
Bases: Module
Head for masked language modeling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
PreTrainedConfig
|
The configuration object for the model. |
required |
|
MaskedLMHeadConfig | None
|
The configuration object for the head.
If None, will use configuration from the |
None
|
Source code in multimolecule/module/heads/pretrain.py
output_name
class-attribute
instance-attribute
¶
The default output to use for the head.
forward
¶
Python | |
---|---|
|
Forward pass of the MaskedLMHead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
ModelOutput | Tuple[Tensor, ...]
|
The outputs of the model. |
required |
|
Tensor | None
|
The labels for the head. |
None
|
|
str | None
|
The name of the output to use.
Defaults to |
None
|
Source code in multimolecule/module/heads/pretrain.py
multimolecule.module.heads.generic
¶
PredictionHead
¶
Bases: Module
Head for all-level of tasks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
PreTrainedConfig
|
The configuration object for the model. |
required |
|
HeadConfig | None
|
The configuration object for the head.
If None, will use configuration from the |
None
|
Source code in multimolecule/module/heads/generic.py
forward
¶
Python | |
---|---|
|
Forward pass of the PredictionHead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Tensor
|
The embeddings to be passed through the head. |
required |
|
Tensor | None
|
The labels for the head. |
required |