esm
mindnlp.transformers.models.esm.configuration_esm
¶
ESM model configuration
mindnlp.transformers.models.esm.configuration_esm.EsmConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [ESMModel
]. It is used to instantiate a ESM model
according to the specified arguments, defining the model architecture. Instantiating a configuration with the
defaults will yield a similar configuration to that of the ESM
facebook/esm-1b architecture.
Configuration objects inherit from [PretrainedConfig
] and can be used to control the model outputs. Read the
documentation from [PretrainedConfig
] for more information.
PARAMETER | DESCRIPTION |
---|---|
vocab_size |
Vocabulary size of the ESM model. Defines the number of different tokens that can be represented by the
TYPE:
|
mask_token_id |
The index of the mask token in the vocabulary. This must be included in the config because of the "mask-dropout" scaling trick, which will scale the inputs depending on the number of masked tokens.
TYPE:
|
pad_token_id |
The index of the padding token in the vocabulary. This must be included in the config because certain parts of the ESM code use this instead of the attention mask.
TYPE:
|
hidden_size |
Dimensionality of the encoder layers and the pooler layer.
TYPE:
|
num_hidden_layers |
Number of hidden layers in the Transformer encoder.
TYPE:
|
num_attention_heads |
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
intermediate_size |
Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
TYPE:
|
hidden_dropout_prob |
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
TYPE:
|
attention_probs_dropout_prob |
The dropout ratio for the attention probabilities.
TYPE:
|
max_position_embeddings |
The maximum sequence length that this model might ever be used with. Typically set this to something large just in case (e.g., 512 or 1024 or 2048).
TYPE:
|
initializer_range |
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
TYPE:
|
layer_norm_eps |
The epsilon used by the layer normalization layers.
TYPE:
|
position_embedding_type |
Type of position embedding. Choose one of
TYPE:
|
is_decoder |
Whether the model is used as a decoder or not. If
TYPE:
|
use_cache |
Whether or not the model should return the last key/values attentions (not used by all models). Only
relevant if
TYPE:
|
emb_layer_norm_before |
Whether to apply layer normalization after embeddings but before the main stem of the network.
TYPE:
|
token_dropout |
When this is enabled, masked tokens are treated as if they had been dropped out by input dropout.
TYPE:
|
Example
>>> from transformers import EsmModel, EsmConfig
...
>>> # Initializing a ESM facebook/esm-1b style configuration >>> configuration = EsmConfig()
...
>>> # Initializing a model from the configuration >>> model = ESMModel(configuration)
...
>>> # Accessing the model configuration >>> configuration = model.config
Source code in mindnlp/transformers/models/esm/configuration_esm.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 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 |
|
mindnlp.transformers.models.esm.configuration_esm.EsmConfig.__init__(vocab_size=None, mask_token_id=None, pad_token_id=None, hidden_size=768, num_hidden_layers=12, num_attention_heads=12, intermediate_size=3072, hidden_dropout_prob=0.1, attention_probs_dropout_prob=0.1, max_position_embeddings=1026, initializer_range=0.02, layer_norm_eps=1e-12, position_embedding_type='absolute', use_cache=True, emb_layer_norm_before=None, token_dropout=False, is_folding_model=False, esmfold_config=None, vocab_list=None, **kwargs)
¶
Initializes an instance of the EsmConfig
class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
vocab_size |
The size of the vocabulary. Defaults to None.
TYPE:
|
mask_token_id |
The ID of the mask token. Defaults to None.
TYPE:
|
pad_token_id |
The ID of the padding token. Defaults to None.
TYPE:
|
hidden_size |
The size of the hidden layers. Defaults to 768.
TYPE:
|
num_hidden_layers |
The number of hidden layers. Defaults to 12.
TYPE:
|
num_attention_heads |
The number of attention heads. Defaults to 12.
TYPE:
|
intermediate_size |
The size of the intermediate layers. Defaults to 3072.
TYPE:
|
hidden_dropout_prob |
The dropout probability for hidden layers. Defaults to 0.1.
TYPE:
|
attention_probs_dropout_prob |
The dropout probability for attention layers. Defaults to 0.1.
TYPE:
|
max_position_embeddings |
The maximum position embeddings. Defaults to 1026.
TYPE:
|
initializer_range |
The range for initializer values. Defaults to 0.02.
TYPE:
|
layer_norm_eps |
The epsilon value for layer normalization. Defaults to 1e-12.
TYPE:
|
position_embedding_type |
The type of position embedding. Defaults to 'absolute'.
TYPE:
|
use_cache |
Whether to use cache. Defaults to True.
TYPE:
|
emb_layer_norm_before |
Whether to normalize embeddings before layers. Defaults to None.
TYPE:
|
token_dropout |
Whether to apply token dropout. Defaults to False.
TYPE:
|
is_folding_model |
Whether the model is a folding model. Defaults to False.
TYPE:
|
esmfold_config |
The configuration for the folding model. Defaults to None.
TYPE:
|
vocab_list |
The list of vocabulary tokens. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the HuggingFace port of ESMFold does not support |
Source code in mindnlp/transformers/models/esm/configuration_esm.py
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 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 |
|
mindnlp.transformers.models.esm.configuration_esm.EsmConfig.to_dict()
¶
Serializes this instance to a Python dictionary. Override the default [~PretrainedConfig.to_dict
].
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindnlp/transformers/models/esm/configuration_esm.py
192 193 194 195 196 197 198 199 200 201 202 |
|
mindnlp.transformers.models.esm.configuration_esm.EsmFoldConfig
dataclass
¶
Represents the configuration of an ESM (Efficient Speech Model) fold instance.
This class provides methods to initialize the EsmFoldConfig instance and serialize it to a Python dictionary.
The EsmFoldConfig class inherits from a base class and includes methods for post-initialization and dictionary serialization.
METHOD | DESCRIPTION |
---|---|
__post_init__ |
Initializes the EsmFoldConfig instance, setting defaults for any missing attributes. |
to_dict |
Serializes the EsmFoldConfig instance to a Python dictionary, including the trunk configuration. |
ATTRIBUTE | DESCRIPTION |
---|---|
trunk |
Represents the configuration of the trunk model used in the ESM fold.
TYPE:
|
Note
Ensure that the trunk attribute is either set to a TrunkConfig instance or a dictionary that can be converted to a TrunkConfig.
Return
A Python dictionary containing all the attributes of the EsmFoldConfig instance, including the trunk configuration.
Source code in mindnlp/transformers/models/esm/configuration_esm.py
205 206 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 281 282 283 284 285 286 287 |
|
mindnlp.transformers.models.esm.configuration_esm.EsmFoldConfig.__post_init__()
¶
The 'post_init' method is used in the 'EsmFoldConfig' class to initialize the 'trunk' attribute.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the 'EsmFoldConfig' class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Description
This method checks if the 'trunk' attribute is None. If it is, a new instance of the 'TrunkConfig' class is created and assigned to 'self.trunk'. If the 'trunk' attribute is of type dict, it is unpacked and passed as keyword arguments to create a new instance of the 'TrunkConfig' class, which is then assigned to 'self.trunk'. This method is typically called after the object is initialized to ensure that the 'trunk' attribute is properly set.
Example
>>> config = EsmFoldConfig()
>>> config.__post_init__()
>>> # The 'trunk' attribute will be initialized with a new instance of the 'TrunkConfig' class.
...
>>> config = EsmFoldConfig(trunk={'option1': True, 'option2': False})
>>> config.__post_init__()
>>> # The 'trunk' attribute will be initialized with a new instance of the 'TrunkConfig' class,
>>> # with 'option1' set to True and 'option2' set to False.
Source code in mindnlp/transformers/models/esm/configuration_esm.py
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 |
|
mindnlp.transformers.models.esm.configuration_esm.EsmFoldConfig.to_dict()
¶
Serializes this instance to a Python dictionary. Override the default [~PretrainedConfig.to_dict
].
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindnlp/transformers/models/esm/configuration_esm.py
278 279 280 281 282 283 284 285 286 287 |
|
mindnlp.transformers.models.esm.configuration_esm.StructureModuleConfig
dataclass
¶
PARAMETER | DESCRIPTION |
---|---|
sequence_dim |
Single representation channel dimension
TYPE:
|
pairwise_dim |
Pair representation channel dimension
TYPE:
|
ipa_dim |
IPA hidden channel dimension
TYPE:
|
resnet_dim |
Angle resnet (Alg. 23 lines 11-14) hidden channel dimension
TYPE:
|
num_heads_ipa |
Number of IPA heads
TYPE:
|
num_qk_points |
Number of query/key points to generate during IPA
TYPE:
|
num_v_points |
Number of value points to generate during IPA
TYPE:
|
dropout_rate |
Dropout rate used throughout the layer
TYPE:
|
num_blocks |
Number of structure module blocks
TYPE:
|
num_transition_layers |
Number of layers in the single representation transition (Alg. 23 lines 8-9)
TYPE:
|
num_resnet_blocks |
Number of blocks in the angle resnet
TYPE:
|
num_angles |
Number of angles to generate in the angle resnet
TYPE:
|
trans_scale_factor |
Scale of single representation transition hidden dimension
TYPE:
|
epsilon |
Small number used in angle resnet normalization
TYPE:
|
inf |
Large number used for attention masking
TYPE:
|
Source code in mindnlp/transformers/models/esm/configuration_esm.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
|
mindnlp.transformers.models.esm.configuration_esm.StructureModuleConfig.to_dict()
¶
Converts the current instance of the StructureModuleConfig class to a dictionary.
PARAMETER | DESCRIPTION |
---|---|
self |
The current instance of the StructureModuleConfig class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary representation of the current StructureModuleConfig instance. |
Source code in mindnlp/transformers/models/esm/configuration_esm.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
|
mindnlp.transformers.models.esm.configuration_esm.TrunkConfig
dataclass
¶
Represents the configuration settings for the Trunk model. This class defines the configuration attributes and their validations for the Trunk model.
ATTRIBUTE | DESCRIPTION |
---|---|
structure_module |
The configuration for the structure module.
TYPE:
|
max_recycles |
The maximum number of recycles, should be a positive integer.
TYPE:
|
sequence_state_dim |
The dimension of the sequence state.
TYPE:
|
pairwise_state_dim |
The dimension of the pairwise state.
TYPE:
|
sequence_head_width |
The width of the sequence head.
TYPE:
|
pairwise_head_width |
The width of the pairwise head.
TYPE:
|
dropout |
The dropout rate, should not be greater than 0.4.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If any of the following conditions are not met:
|
METHOD | DESCRIPTION |
---|---|
__post_init__ |
Performs post-initialization validations for the configuration attributes. |
to_dict |
Serializes the instance to a Python dictionary, including the structure module configuration. |
Overrides
~PretrainedConfig.to_dict
: Overrides the default to_dict
method to include the structure module
configuration in the dictionary output.
Source code in mindnlp/transformers/models/esm/configuration_esm.py
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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
mindnlp.transformers.models.esm.configuration_esm.TrunkConfig.__post_init__()
¶
This method initializes the TrunkConfig class after its instantiation.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the TrunkConfig class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If |
ValueError
|
If |
ValueError
|
If |
ValueError
|
If |
ValueError
|
If |
ValueError
|
If |
ValueError
|
If |
Source code in mindnlp/transformers/models/esm/configuration_esm.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
mindnlp.transformers.models.esm.configuration_esm.TrunkConfig.to_dict()
¶
Serializes this instance to a Python dictionary. Override the default [~PretrainedConfig.to_dict
].
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindnlp/transformers/models/esm/configuration_esm.py
395 396 397 398 399 400 401 402 403 404 |
|
mindnlp.transformers.models.esm.configuration_esm.get_default_vocab_list()
¶
This function returns a list of default vocabulary items including special tokens and characters used in natural language processing tasks.
RETURNS | DESCRIPTION |
---|---|
List
|
A list of default vocabulary items including ' |
Source code in mindnlp/transformers/models/esm/configuration_esm.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
|
mindnlp.transformers.models.esm.modeling_esm.ESM_PRETRAINED_MODEL_ARCHIVE_LIST = ['facebook/esm2_t6_8M_UR50D', 'facebook/esm2_t12_35M_UR50D']
module-attribute
¶
mindnlp.transformers.models.esm.modeling_esm.EsmForMaskedLM
¶
Bases: EsmPreTrainedModel
Represents an ESM (Evolutionary Scale Modeling) model for masked language modeling (MLM), inheriting from EsmPreTrainedModel. This class provides the functionality to perform masked language modeling using the ESM model.
The EsmForMaskedLM class contains methods for initializing the model, getting and setting output embeddings, forwarding the model, and predicting contacts. The model architecture includes an ESM model and a language modeling head (lm_head). The forward method takes input_ids, attention_mask, position_ids, head_mask, inputs_embeds, encoder_hidden_states, encoder_attention_mask, labels, output_attentions, output_hidden_states, and return_dict as input arguments and returns the masked language modeling loss and other outputs. The predict_contacts method takes tokens and attention_mask as input and returns the predicted contacts using the ESM model.
Note
- If using
EsmForMaskedLM
, ensureconfig.is_decoder=False
for bi-directional self-attention. - Labels for computing the masked language modeling loss should be indices in
[-100, 0, ..., config.vocab_size]
. Tokens with indices set to-100
are ignored (masked), and the loss is only computed for the tokens with labels in[0, ..., config.vocab_size]
.
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmForMaskedLM.__init__(config)
¶
Initializes an instance of EsmForMaskedLM.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object containing model hyperparameters. It must have attributes like 'is_decoder', 'add_pooling_layer', and 'init_weights'.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmForMaskedLM.forward(input_ids=None, attention_mask=None, position_ids=None, head_mask=None, inputs_embeds=None, encoder_hidden_states=None, encoder_attention_mask=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the masked language modeling loss. Indices should be in
TYPE:
|
kwargs |
Used to hide legacy arguments that have been deprecated.
TYPE:
|
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmForMaskedLM.get_output_embeddings()
¶
This method returns the output embeddings for the language model head.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the EsmForMaskedLM class.
|
RETURNS | DESCRIPTION |
---|---|
decoder
|
The method returns the output embeddings for the language model head. |
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmForMaskedLM.predict_contacts(tokens, attention_mask)
¶
This method predicts contacts using the ESM (Evolutionary Scale Modeling) for Masked Language Modeling.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the EsmForMaskedLM class.
TYPE:
|
tokens |
The input tokens for prediction.
TYPE:
|
attention_mask |
The attention mask for the input tokens. It masks the tokens that should not be attended to, specifying which tokens should be attended to and which should not.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmForMaskedLM.set_output_embeddings(new_embeddings)
¶
Set the output embeddings for the ESM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the EsmForMaskedLM class.
TYPE:
|
new_embeddings |
The new embeddings to be set as output embeddings for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the provided new_embeddings is not of type torch.nn.Module. |
AttributeError
|
If the lm_head.decoder attribute is not present in the EsmForMaskedLM instance. |
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmForSequenceClassification
¶
Bases: EsmPreTrainedModel
This class represents an ESM (Evoformer) model for sequence classification tasks. It is a subclass of EsmPreTrainedModel, which provides the underlying architecture and functionality.
ATTRIBUTE | DESCRIPTION |
---|---|
num_labels |
The number of labels for the classification task.
TYPE:
|
config |
The configuration object for the ESM model.
TYPE:
|
esm |
The ESM model instance.
TYPE:
|
classifier |
The classification head for the ESM model.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the EsmForSequenceClassification instance. |
forward |
Constructs the ESM model for sequence classification. |
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmForSequenceClassification.__init__(config)
¶
Initializes an instance of EsmForSequenceClassification.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object containing the configuration parameters for the model.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmForSequenceClassification.forward(input_ids=None, attention_mask=None, position_ids=None, head_mask=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the sequence classification/regression loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmForTokenClassification
¶
Bases: EsmPreTrainedModel
EsmForTokenClassification is a class that represents a token classification model based on the ESM (Evoformer Sequence Model) architecture. This class extends EsmPreTrainedModel to leverage pre-trained weights and configurations for efficient token classification tasks. It includes methods for initializing the model, forwarding the forward pass, and computing the token classification loss.
The init method initializes the EsmForTokenClassification model with configurable parameters such as the number of labels, dropout probability, and hidden layer sizes. It also sets up the ESM model, dropout layer, and the classifier for token classification.
The forward method defines the forward pass of the model, taking input tensors such as input_ids, attention_mask, position_ids, etc., and returning the token classification output. It computes the logits for token classification based on the sequence_output from the ESM model and calculates the cross-entropy loss if labels are provided. The method allows for returning additional outputs like hidden states and attentions based on the return_dict parameter.
Note
This docstring is a high-level summary and does not include method signatures or implementation details.
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmForTokenClassification.__init__(config)
¶
Initializes an instance of the EsmForTokenClassification class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the EsmForTokenClassification class.
|
config |
An instance of the configuration class containing the model configuration parameters.
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not of the correct type. |
ValueError
|
If the config.num_labels is not provided or is invalid. |
RuntimeError
|
If an error occurs during the initialization process. |
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmForTokenClassification.forward(input_ids=None, attention_mask=None, position_ids=None, head_mask=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
labels |
Labels for computing the token classification loss. Indices should be in
TYPE:
|
Source code in mindnlp/transformers/models/esm/modeling_esm.py
2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmModel
¶
Bases: EsmPreTrainedModel
The model can behave as an encoder (with only self-attention) as well as a decoder, in which case a layer of cross-attention is added between the self-attention layers, following the architecture described in Attention is all you need by Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser and Illia Polosukhin.
To behave as an decoder the model needs to be initialized with the is_decoder
argument of the configuration set
to True
. To be used in a Seq2Seq model, the model needs to initialized with both is_decoder
argument and
add_cross_attention
set to True
; an encoder_hidden_states
is then expected as an input to the forward pass.
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmModel.__init__(config, add_pooling_layer=True)
¶
Initializes an instance of the EsmModel class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
The configuration object containing various settings for the model.
TYPE:
|
add_pooling_layer |
A flag indicating whether to include a pooling layer in the model. Default is True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmModel.forward(input_ids=None, attention_mask=None, position_ids=None, head_mask=None, inputs_embeds=None, encoder_hidden_states=None, encoder_attention_mask=None, past_key_values=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
PARAMETER | DESCRIPTION |
---|---|
encoder_hidden_states |
Sequence of hidden-states at the output of the last layer of the encoder. Used in the cross-attention if the model is configured as a decoder.
TYPE:
|
encoder_attention_mask |
Mask to avoid performing attention on the padding token indices of the encoder input. This mask is used in
the cross-attention if the model is configured as a decoder. Mask values selected in
TYPE:
|
use_cache |
If set to
TYPE:
|
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmModel.get_input_embeddings()
¶
This method returns the input embeddings for the ESMM model.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the EsmModel class.
|
RETURNS | DESCRIPTION |
---|---|
word_embeddings
|
This method returns the word embeddings for input data, represented as a tensor. |
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmModel.predict_contacts(tokens, attention_mask)
¶
Predicts contacts using the EsmModel.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the EsmModel class.
TYPE:
|
tokens |
The input tokens for prediction.
TYPE:
|
attention_mask |
The attention mask for the input tokens.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmModel.set_input_embeddings(value)
¶
Sets the input embeddings for the EsmModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the EsmModel class.
TYPE:
|
value |
The input embeddings to be set. This should be of type
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 |
|
mindnlp.transformers.models.esm.modeling_esm.EsmPreTrainedModel
¶
Bases: PreTrainedModel
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
Source code in mindnlp/transformers/models/esm/modeling_esm.py
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 |
|
mindnlp.transformers.models.esm.modeling_esmfold
¶
MindSpore ESMFold model
mindnlp.transformers.models.esm.modeling_esmfold.EsmCategoricalMixture
¶
EsmCategoricalMixture represents a categorical mixture distribution for probability calculations based on given logits.
This class provides methods for initializing the distribution, calculating the log probability of a given value, and computing the mean of the distribution.
ATTRIBUTE | DESCRIPTION |
---|---|
param |
The logits parameter for the categorical mixture distribution.
|
bins |
The number of bins for the distribution (default is 50).
|
start |
The starting value for the bins (default is 0).
|
end |
The ending value for the bins (default is 1).
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the categorical mixture distribution with the given parameters. |
log_prob |
Calculates the log probability of a given value within the distribution. |
mean |
Computes the mean of the categorical mixture distribution. |
Note
This class inherits from an unspecified parent class.
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmCategoricalMixture.__init__(param, bins=50, start=0, end=1)
¶
Initializes an instance of the EsmCategoricalMixture class.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the EsmCategoricalMixture class.
|
param |
The logits parameter to be assigned to the instance.
|
bins |
Number of bins for creating the v_bins attribute. Default is 50.
DEFAULT:
|
start |
The starting value for the linspace function. Default is 0.
DEFAULT:
|
end |
The ending value for the linspace function. Default is 1.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the start value is greater than or equal to the end value. |
TypeError
|
If the param or bins parameter types are incompatible. |
ValueError
|
If the bins parameter is less than 1. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmCategoricalMixture.log_prob(true)
¶
This method calculates the log probability of a given true value in the context of a categorical mixture model.
PARAMETER | DESCRIPTION |
---|---|
self |
EsmCategoricalMixture The instance of the EsmCategoricalMixture class.
|
true |
torch.Tensor The true value for which the log probability needs to be calculated. It should be a tensor of shape (batch_size,) where batch_size is the number of samples. The true values should be within the range of valid classes for the categorical mixture model.
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return any value. The log probability is calculated and stored internally within the EsmCategoricalMixture instance. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the true tensor does not have the expected shape or if it contains values outside the range of valid classes for the categorical mixture model. |
IndexError
|
If the true tensor index is out of bounds. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmCategoricalMixture.mean()
¶
Method 'mean' calculates the mean value of the categorical mixture distribution in the EsmCategoricalMixture class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the EsmCategoricalMixture class.
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
NotImplementedError
|
If the method is called without implementing it in a subclass. |
ValueError
|
If the input data is not in the expected format. |
RuntimeError
|
If the operation fails due to unforeseen circumstances. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldAngleResnet
¶
Bases: Module
Implements Algorithm 20, lines 11-14
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldAngleResnet.__init__(config)
¶
Initializes the EsmFoldAngleResnet class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the EsmFoldAngleResnet class.
TYPE:
|
config |
The configuration object containing parameters for the EsmFoldAngleResnet initialization.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldAngleResnet.forward(s, s_initial)
¶
PARAMETER | DESCRIPTION |
---|---|
s |
[*, C_hidden] single embedding
TYPE:
|
s_initial |
[*, C_hidden] single embedding as of the start of the StructureModule
TYPE:
|
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldAngleResnetBlock
¶
Bases: Module
This class represents an EsmFoldAngleResnetBlock, which is a block used in the forwardion of an EsmFold model. It inherits from the nn.Module class.
ATTRIBUTE | DESCRIPTION |
---|---|
linear_1 |
A linear layer used in the block, initialized with a rectified linear unit (ReLU) activation function.
TYPE:
|
linear_2 |
Another linear layer used in the block, initialized with a final activation function.
TYPE:
|
relu |
An instance of the ReLU activation function.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the EsmFoldAngleResnetBlock with the given configuration. |
forward |
Constructs the EsmFoldAngleResnetBlock using the input tensor. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldAngleResnetBlock.__init__(config)
¶
Initializes an EsmFoldAngleResnetBlock object.
PARAMETER | DESCRIPTION |
---|---|
self |
The current instance of the EsmFoldAngleResnetBlock class.
TYPE:
|
config |
A configuration object containing the parameters for initializing the EsmFoldAngleResnetBlock.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the provided config object is not of the expected type. |
ValueError
|
If the config object does not contain the required parameters. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldAngleResnetBlock.forward(a)
¶
This method forwards a computation graph for the EsmFoldAngleResnetBlock.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the EsmFoldAngleResnetBlock class.
TYPE:
|
a |
The input tensor for the computation graph.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
mindspore.Tensor: The output tensor resulting from the computation graph. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldAttention
¶
Bases: Module
Standard multi-head attention using AlphaFold's default layer initialization. Allows multiple bias vectors.
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
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 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 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 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldAttention.__init__(c_q, c_k, c_v, c_hidden, no_heads, gating=True)
¶
PARAMETER | DESCRIPTION |
---|---|
c_q |
Input dimension of query data
TYPE:
|
c_k |
Input dimension of key data
TYPE:
|
c_v |
Input dimension of value data
TYPE:
|
c_hidden |
Per-head hidden dimension
TYPE:
|
no_heads |
Number of attention heads
TYPE:
|
gating |
Whether the output should be gated using query data
TYPE:
|
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
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 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldAttention.forward(q_x, kv_x, biases=None, use_memory_efficient_kernel=False, use_lma=False, lma_q_chunk_size=1024, lma_kv_chunk_size=4096, use_flash=False, flash_mask=None)
¶
PARAMETER | DESCRIPTION |
---|---|
q_x |
[*, Q, C_q] query data
TYPE:
|
kv_x |
[*, K, C_k] key data
TYPE:
|
biases |
List of biases that broadcast to [*, H, Q, K]
TYPE:
|
use_memory_efficient_kernel |
Whether to use a custom memory-efficient attention kernel. This should be the default choice for most. If none of the "use_<...>" flags are True, a stock PyTorch implementation is used instead
TYPE:
|
use_lma |
Whether to use low-memory attention (Staats & Rabe 2021). If none of the "use_<...>" flags are True, a stock PyTorch implementation is used instead
TYPE:
|
lma_q_chunk_size |
Query chunk size (for LMA)
TYPE:
|
lma_kv_chunk_size |
Key/Value chunk size (for LMA)
TYPE:
|
Returns [*, Q, C_q] attention update
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
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 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldBackboneUpdate
¶
Bases: Module
Implements part of Algorithm 23.
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldBackboneUpdate.__init__(config)
¶
Initializes the EsmFoldBackboneUpdate class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
A dictionary containing configuration parameters for the backbone update. It should include the 'sequence_dim' parameter representing the dimension of the input sequence.
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not provided or is not a dictionary. |
ValueError
|
If the 'sequence_dim' parameter is missing in the config dictionary. |
ValueError
|
If the 'sequence_dim' parameter in the config dictionary is not a positive integer. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldBackboneUpdate.forward(s)
¶
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldDropout
¶
Bases: Module
Implementation of dropout with the ability to share the dropout mask along a particular dimension.
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldDropout.__init__(r, batch_dim)
¶
Initializes an instance of the EsmFoldDropout class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
r |
The dropout rate value.
TYPE:
|
batch_dim |
The dimension(s) of the input batch. If an integer is provided, it will be converted to a list with that integer as the only element.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldDropout.forward(x)
¶
This method forwards a modified tensor with dropout for the EsmFoldDropout class.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the EsmFoldDropout class.
|
x |
The input tensor for which the modified tensor is forwarded.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
mindspore.Tensor: Returns a new tensor, which is the result of applying dropout to the input tensor. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input x is not of type mindspore.Tensor. |
ValueError
|
If the shape manipulation encounters an error during the forwardion process. |
RuntimeError
|
If there is a runtime issue during the execution of the method. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldInvariantPointAttention
¶
Bases: Module
Implements Algorithm 22.
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldInvariantPointAttention.__init__(config)
¶
Initializes an instance of the EsmFoldInvariantPointAttention class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object containing the configuration settings.
|
RETURNS | DESCRIPTION |
---|---|
None |
Description
This method initializes the EsmFoldInvariantPointAttention instance by setting various parameters and creating necessary objects.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
config |
An object containing the configuration settings.
|
The config object must have the following attributes:
- sequence_dim: An integer representing the dimension of the sequence.
- pairwise_dim: An integer representing the dimension of the pairwise data.
- ipa_dim: An integer representing the dimension of the ipa data.
- num_heads_ipa: An integer representing the number of heads for the ipa.
- num_qk_points: An integer representing the number of query and key points.
- num_v_points: An integer representing the number of value points.
ATTRIBUTE | DESCRIPTION |
---|---|
hidden_dim |
An integer representing the ipa dimension.
|
num_heads |
An integer representing the number of ipa heads.
|
num_qk_points |
An integer representing the number of query and key points.
|
num_v_points |
An integer representing the number of value points.
|
linear_q |
An instance of the EsmFoldLinear class with input dimension c_s and output dimension hc.
|
linear_kv |
An instance of the EsmFoldLinear class with input dimension c_s and output dimension 2 * hc.
|
linear_q_points |
An instance of the EsmFoldLinear class with input dimension c_s and output dimension hpq.
|
linear_kv_points |
An instance of the EsmFoldLinear class with input dimension c_s and output dimension hpkv.
|
linear_b |
An instance of the EsmFoldLinear class with input dimension c_z and output dimension num_heads_ipa.
|
head_weights |
A Parameter object representing the weights of the ipa heads.
|
linear_out |
An instance of the EsmFoldLinear class with input dimension concat_out_dim and output dimension c_s.
|
softmax |
An instance of the Softmax class used for softmax activation.
|
softplus |
An instance of the Softplus class used for softplus activation.
|
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldInvariantPointAttention.forward(s, z, r, mask)
¶
PARAMETER | DESCRIPTION |
---|---|
s |
[*, N_res, C_s] single representation
TYPE:
|
z |
[*, N_res, N_res, C_z] pair representation
TYPE:
|
r |
[*, N_res] transformation object
TYPE:
|
mask |
[*, N_res] mask
TYPE:
|
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldLayerNorm
¶
Bases: Module
EsmFoldLayerNorm represents a custom layer normalization module with additional trainable parameters for weight and bias. This class inherits from nn.Module and implements the Layer Normalization operation with custom weight and bias parameters.
ATTRIBUTE | DESCRIPTION |
---|---|
c_in |
Number of input channels for the layer normalization operation.
TYPE:
|
eps |
Epsilon value used in the normalization operation.
TYPE:
|
weight |
Trainable parameter representing the weights for the normalization operation.
TYPE:
|
bias |
Trainable parameter representing the bias for the normalization operation.
TYPE:
|
layer_norm |
Layer normalization operation with custom weight and bias parameters.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the EsmFoldLayerNorm instance with the specified input channels and epsilon value. |
forward |
Applies the layer normalization operation with custom weight and bias parameters to the input tensor x. |
RETURNS | DESCRIPTION |
---|---|
Tensor
|
The normalized output tensor after applying the layer normalization operation with custom parameters. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldLayerNorm.__init__(c_in, eps=1e-05)
¶
Initialize the EsmFoldLayerNorm class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the EsmFoldLayerNorm class.
|
c_in |
The number of input channels for the layer normalization. Must be a positive integer.
TYPE:
|
eps |
The epsilon value for numerical stability in layer normalization. Default is 1e-05.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If c_in is not a positive integer. |
ValueError
|
If eps is not a valid epsilon value (not a float). |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldLayerNorm.forward(x)
¶
Constructs a normalized layer using the EsmFold algorithm.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the EsmFoldLayerNorm class.
TYPE:
|
x |
The input tensor to be normalized. Should have shape (batch_size, features).
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not return a value. The normalized layer is stored within the instance of the EsmFoldLayerNorm class. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldLinear
¶
Bases: Linear
A Linear layer with built-in nonstandard initializations. Called just like torch.nn.Linear.
Implements the initializers in 1.11.4, plus some additional ones found in the code.
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
279 280 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 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldLinear.__init__(in_dim, out_dim, bias=True, init='default', init_fn=None)
¶
PARAMETER | DESCRIPTION |
---|---|
in_dim |
The final dimension of inputs to the layer
TYPE:
|
out_dim |
The final dimension of layer outputs
TYPE:
|
bias |
Whether to learn an additive bias. True by default
TYPE:
|
init |
The initializer to use. Choose from: "default": LeCun fan-in truncated normal initialization "relu": He initialization w/ truncated normal distribution "glorot": Fan-average Glorot uniform initialization "gating": Weights=0, Bias=1 "normal": Normal initialization with std=1/sqrt(fan_in) "final": Weights=0, Bias=0 Overridden by init_fn if the latter is not None.
TYPE:
|
init_fn |
A custom initializer taking weight and bias as inputs. Overrides init if not None.
TYPE:
|
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
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 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldPairToSequence
¶
Bases: Module
EsmFoldPairToSequence class represents a neural network module for converting pairwise features to sequence features using self-attention mechanism.
This class inherits from nn.Module and includes methods for initializing the module and forwarding the forward pass.
ATTRIBUTE | DESCRIPTION |
---|---|
pairwise_state_dim |
Dimension of the pairwise state features.
TYPE:
|
num_heads |
Number of attention heads.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the EsmFoldPairToSequence module with the given pairwise_state_dim and num_heads. |
forward |
Applies self-attention mechanism to the input pairwise_state tensor to generate pairwise_bias tensor. |
PARAMETER | DESCRIPTION |
---|---|
pairwise_state_dim |
Dimension of the pairwise state features.
TYPE:
|
num_heads |
Number of attention heads.
TYPE:
|
Inputs
pairwise_state (tensor): Input tensor of shape B x L x L x pairwise_state_dim.
Outputs
pairwise_bias (tensor): Output tensor of shape B x L x L x num_heads.
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldPairToSequence.__init__(pairwise_state_dim, num_heads)
¶
Initializes an instance of the EsmFoldPairToSequence class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
pairwise_state_dim |
The dimension of the pairwise state.
TYPE:
|
num_heads |
The number of attention heads to use.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If pairwise_state_dim or num_heads is not a positive integer. |
AttributeError
|
If the attributes layernorm or linear cannot be initialized. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldPairToSequence.forward(pairwise_state)
¶
Inputs
Output
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldPreTrainedModel
¶
Bases: EsmPreTrainedModel
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldRelativePosition
¶
Bases: Module
Represents a class for forwarding relative position embeddings for protein folding using the ESM (Evolutionary Scale Modeling) framework.
This class inherits from the nn.Module class and provides methods for initializing the class and forwarding pairwise state embeddings based on residue indices and optional masking.
ATTRIBUTE | DESCRIPTION |
---|---|
bins |
An integer representing the number of position bins used for forwarding the embeddings.
|
embedding |
An instance of nn.Embedding used for creating the embeddings based on the position differences.
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the EsmFoldRelativePosition class with the provided configuration. |
forward |
Constructs pairwise state embeddings based on the given residue indices and optional mask. |
PARAMETER | DESCRIPTION |
---|---|
config |
An object containing configuration parameters for initializing the class.
|
residue_index |
A B x L tensor of indices (dtype=torch.long) representing the residue indices.
|
mask |
A B x L tensor of booleans representing an optional mask.
|
RETURNS | DESCRIPTION |
---|---|
pairwise_state
|
A B x L x L x pairwise_state_dim tensor of embeddings based on the input residue indices and mask. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the dtype of residue_index is not torch.long or if the shapes of residue_index and mask are inconsistent. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldRelativePosition.__init__(config)
¶
Initializes an instance of the EsmFoldRelativePosition class.
PARAMETER | DESCRIPTION |
---|---|
self |
The current instance of the class.
TYPE:
|
config |
The configuration object containing the necessary parameters.
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldRelativePosition.forward(residue_index, mask=None)
¶
Input
Output
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldResidueMLP
¶
Bases: Module
This class represents a multi-layer perceptron (MLP) used for folding residues in the ESM (Evolutionary Scale Modeling) framework. It inherits from the nn.Module class.
The EsmFoldResidueMLP class implements a MLP architecture with layer normalization, dense layers, ReLU activation, and dropout. The MLP takes an input tensor and applies a series of linear transformations to produce an output tensor. The output tensor is then added element-wise to the input tensor, resulting in the folded residue representation.
ATTRIBUTE | DESCRIPTION |
---|---|
embed_dim |
The dimensionality of the input and output tensors.
TYPE:
|
inner_dim |
The dimensionality of the intermediate hidden layer in the MLP.
TYPE:
|
dropout |
The dropout probability applied after the ReLU activation. Defaults to 0.
TYPE:
|
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes an instance of the EsmFoldResidueMLP class.
|
forward |
Applies the MLP to the input tensor x and returns the folded residue representation.
|
Example
>>> embed_dim = 128
>>> inner_dim = 256
>>> dropout = 0.2
...
>>> mlp = EsmFoldResidueMLP(embed_dim, inner_dim, dropout)
>>> input_tensor = torch.randn(batch_size, embed_dim)
...
>>> output = mlp.forward(input_tensor)
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldResidueMLP.__init__(embed_dim, inner_dim, dropout=0)
¶
Initializes the EsmFoldResidueMLP class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
TYPE:
|
embed_dim |
The dimension of the input embeddings.
TYPE:
|
inner_dim |
The dimension of the inner layer.
TYPE:
|
dropout |
The dropout probability. Defaults to 0.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If embed_dim or inner_dim is not an integer, or if dropout is not a float. |
ValueError
|
If embed_dim or inner_dim is less than or equal to 0, or if dropout is not within the range [0, 1]. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldResidueMLP.forward(x)
¶
Constructs an output value by adding the input value with the result of the multi-layer perceptron (MLP) operation.
PARAMETER | DESCRIPTION |
---|---|
self |
Instance of the EsmFoldResidueMLP class.
TYPE:
|
x |
Input value to be used in the forwardion process.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
The forwarded value is returned as the result of adding the input value with the MLP operation. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input value 'x' is not compatible for addition with the MLP operation. |
ValueError
|
If the MLP operation encounters any unexpected issues during computation. |
Source code in mindnlp/transformers/models/esm/modeling_esmfold.py
1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 |
|
mindnlp.transformers.models.esm.modeling_esmfold.EsmFoldSelfAttention
¶
Bases: Module
This class represents a self-attention mechanism for processing sequences, specifically designed for handling sequences of varying lengths. It implements a multi-head self-attention mechanism with optional gating, bias, and masking capabilities.
ATTRIBUTE | DESCRIPTION |
---|---|
embed_dim |
The dimension of the input embedding.
TYPE:
|
num_heads |
The number of attention heads.
TYPE:
|
head_width |
The width of each attention head.
TYPE:
|
gated |
Indicates whether the attention mechanism uses gating.
TYPE:
|
proj |
Linear projection layer for processing input sequences.
TYPE:
|
o_proj |
Output pro |