Finetune token classifier
ClassifierInput
Bases: TypedDict
Used as input in the ClassifierLossReduction's forward method.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
52 53 54 55 56 |
|
ClassifierLossReduction
Bases: BERTMLMLossWithReduction
A class for calculating the cross entropy loss of classification output.
This class used for calculating the loss, and for logging the reduced loss across micro batches.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
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 |
|
forward(batch, forward_out)
Calculates the loss within a micro-batch. A micro-batch is a batch of data on a single GPU.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch
|
ClassifierInput
|
A batch of data that gets passed to the original forward inside LitAutoEncoder. |
required |
forward_out
|
Esm2FineTuneTokenOutput
|
the output of the forward method inside classification head. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
A tuple where the loss tensor will be used for backpropagation and the dict will be passed to |
PerTokenLossDict | SameSizeLossDict
|
the reduce method, which currently only works for logging. |
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
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 |
|
reduce(losses_reduced_per_micro_batch)
Works across micro-batches. (data on single gpu).
Note: This currently only works for logging and this loss will not be used for backpropagation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
losses_reduced_per_micro_batch
|
Sequence[SameSizeLossDict]
|
a list of the outputs of forward |
required |
Returns:
Type | Description |
---|---|
Tensor
|
A tensor that is the mean of the losses. (used for logging). |
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
ESM2FineTuneTokenConfig
dataclass
Bases: ESM2GenericConfig[ESM2FineTuneTokenModel, ClassifierLossReduction]
, IOMixinWithGettersSetters
ExampleConfig is a dataclass that is used to configure the model.
Timers from ModelParallelConfig are required for megatron forward compatibility.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
get_loss_reduction_class()
The loss function type.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
202 203 204 |
|
ESM2FineTuneTokenModel
Bases: ESM2Model
An ESM2 model that is suitable for fine tuning.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
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 |
|
__init__(config, *args, include_hiddens=False, post_process=True, **kwargs)
Constructor.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
forward(*args, **kwargs)
Inference.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
Esm2FineTuneTokenOutput
Bases: BioBertOutput
Inference output from ESM2FineTuneTokenModel.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
59 60 61 62 |
|
InMemoryPerTokenValueDataset
Bases: Dataset
An in-memory dataset of labeled strings, which are tokenized on demand.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
__getitem__(index)
Gets a BertSample associated to the supplied index.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
__init__(data, tokenizer=tokenizer.get_tokenizer(), seed=np.random.SeedSequence().entropy)
Initializes a dataset for per-token classification fine-tuning.
This is an in-memory dataset that does not apply masking to the sequence.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Sequence[Tuple[str, str]]
|
A sequence of tuples containing the sequence and target data. |
required |
tokenizer
|
BioNeMoESMTokenizer
|
The tokenizer to use. Defaults to tokenizer.get_tokenizer(). |
get_tokenizer()
|
seed
|
int
|
Random seed for reproducibility. This seed is mixed with the index of the sample to retrieve to ensure that getitem is deterministic, but can be random across different runs. If None, a random seed is generated. |
entropy
|
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
__len__()
Length of dataset.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
234 235 236 |
|
MegatronConvNetHead
Bases: MegatronModule
A convolutional neural network class for residue-level classification.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
__init__(config)
Constructor.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
118 119 120 121 122 123 124 125 126 127 128 129 |
|
forward(hidden_states)
Inference.
Source code in bionemo/esm2/model/finetune/finetune_token_classifier.py
131 132 133 134 135 136 137 |
|