ESMBackbone
classkeras_hub.models.ESMBackbone(
vocabulary_size,
num_layers,
num_heads,
hidden_dim,
intermediate_dim,
use_bias=True,
activation="gelu",
dropout=0.1,
dtype=None,
max_sequence_length=1024,
max_wavelength=10000,
layer_norm_eps=1e-12,
use_pre_layer_norm=False,
position_embedding_type="rotary",
pad_token_id=0,
**kwargs
)
A ESM2 and ESM encoder network.
This class implements a bi-directional Transformer-based encoder as described in "ESM".
The default constructor gives a fully customizable, randomly initialized
ESM2 encoder with any number of layers, heads, and embed dim.To
load preset architectures and weights, use the from_preset()
constructor.
Arguments
max_sequence_length
uses the value from
sequence length. This determines the variable shape for positional
embeddings.10000
."gelu"
.Examples
input_data = {
"token_ids": np.ones(shape=(1, 12), dtype="int32"),
}
# Pretrained ESM2 encoder.
model = keras_hub.models.ESM2Backbone.from_preset('hf://facebook/esm2_t6_8M_UR50D')
model(input_data)
# Randomly initialized ESM2 encoder with a custom config.
model = keras_hub.models.ESM2Backbone(
vocabulary_size=30552,
num_layers=4,
num_heads=4,
hidden_dim=256,
intermediate_dim=512,
)
model(input_data)
from_preset
methodESMBackbone.from_preset(preset, load_weights=True, **kwargs)
Instantiate a keras_hub.models.Backbone
from a model preset.
A preset is a directory of configs, weights and other file assets used
to save and load a pre-trained model. The preset
can be passed as a
one of:
'bert_base_en'
'kaggle://user/bert/keras/bert_base_en'
'hf://user/bert_base_en'
'./bert_base_en'
This constructor can be called in one of two ways. Either from the base
class like keras_hub.models.Backbone.from_preset()
, or from
a model class like keras_hub.models.GemmaBackbone.from_preset()
.
If calling from the base class, the subclass of the returning object
will be inferred from the config in the preset directory.
For any Backbone
subclass, you can run cls.presets.keys()
to list
all built-in presets available on the class.
Arguments
True
, the weights will be loaded into the
model architecture. If False
, the weights will be randomly
initialized.Examples
# Load a Gemma backbone with pre-trained weights.
model = keras_hub.models.Backbone.from_preset(
"gemma_2b_en",
)
# Load a Bert backbone with a pre-trained config and random weights.
model = keras_hub.models.Backbone.from_preset(
"bert_base_en",
load_weights=False,
)
Preset | Parameters | Description |
---|---|---|
esm2_t6_8M | 7.41M | 6 transformer layers version of the ESM-2 protein language model, trained on the UniRef50 clustered protein sequence dataset. |
esm2_t12_35M | 33.27M | 12 transformer layers version of the ESM-2 protein language model, trained on the UniRef50 clustered protein sequence dataset. |
esm2_t30_150M | 147.73M | 30 transformer layers version of the ESM-2 protein language model, trained on the UniRef50 clustered protein sequence dataset. |
esm2_t33_650M | 649.40M | 33 transformer layers version of the ESM-2 protein language model, trained on the UniRef50 clustered protein sequence dataset. |
token_embedding
propertykeras_hub.models.ESMBackbone.token_embedding
A keras.layers.Embedding
instance for embedding token ids.
This layer embeds integer token ids to the hidden dim of the model.