Embedding
ESM2Embedding
Bases: LanguageModelEmbedding
ESM2 Embedding with custom logic for attention masking and token dropout.
Source code in bionemo/esm2/model/embedding.py
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 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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
dtype: torch.dtype
property
The dtype of the embedding weights.
__init__(config, vocab_size, max_sequence_length, position_embedding_type='rope', num_tokentypes=0, token_dropout=True, use_attention_mask=True, mask_token_id=torch.nan)
Initialize the ESM2 Embedding module.
Source code in bionemo/esm2/model/embedding.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
forward(input_ids, position_ids, tokentype_ids=None, attention_mask=None)
Forward pass of the embedding module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_ids
|
Tensor
|
The input tokens. Shape: [b, s] |
required |
position_ids
|
Tensor
|
The position id's used to calculate position embeddings. Shape: [b, s] |
required |
tokentype_ids
|
int
|
The token type ids. Used when args.bert_binary_head is set to True. Defaults to None |
None
|
attention_mask
|
Tensor
|
attention mask. Shape: [b, s] |
None
|
Returns:
Name | Type | Description |
---|---|---|
Tensor |
Tensor
|
The output embeddings |
Source code in bionemo/esm2/model/embedding.py
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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|