ebetica commited on
Commit
5bdcd3b
·
verified ·
1 Parent(s): a556b2f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +155 -0
README.md ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license:
3
+ - mit
4
+ - other
5
+ license_link: https://github.com/Biohub/esm/blob/main/THIRD_PARTY_NOTICE.md
6
+ library_name: transformers
7
+ language: en
8
+ tags:
9
+ - biology
10
+ - esm
11
+ - protein
12
+ - sparse-autoencoder
13
+ - interpretability
14
+ - protein-embeddings
15
+ - feature-extraction
16
+ - protein-language-model
17
+ - unsupervised-learning
18
+ - transformers
19
+ ---
20
+
21
+ # ESMC Sparse Autoencoders
22
+
23
+ This model card provides an overview of the intended use of the ESMC SAE models and examples of how to access them, but it does not have a specific model or model weights. To access each SAE model collection, use the links below:
24
+
25
+ - [ESMC SAEs for hidden states (all layers)](https://huggingface.co/collections/biohub/esmc-saes-for-hidden-states-all-layers)
26
+ - [ESMC SAEs for MLP outputs (all layers)](https://huggingface.co/collections/biohub/esmc-saes-for-mlp-outputs-all-layers)
27
+ - [ESMC SAEs for one layer (different sparsity / codebook size)](https://huggingface.co/collections/biohub/esmc-saes-for-one-layer-different-sparsity-codebook-size)
28
+
29
+ The ESMC sparse autoencoders (SAEs) are unsupervised neural networks trained to decompose the learned internal representations from the ESMC model variants into a sparse representation space comprising more biologically interpretable features, revealing what the model "sees" of the user's protein input. Each feature is encouraged to be approximately monosemantic (capturing one interpretable concept) through a large feature space combined with a sparsity constraint, and may represent a specific biologically relevant property of the protein, such as a zinc binding site, beta barrel structure, or transmembrane helix.
30
+
31
+ Building on top of the ESMC 6B SAEs, the ESM Atlas is a map of 6.8 billion proteins covering the full breadth of life's biodiversity and more than one billion predicted structures. The SAEs enable translation of the model's internal representations into ~16,000 interpretable biological features. Learn more about how to use the ESM Atlas on the Biohub Platform.
32
+
33
+ Read more about ESMC and SAEs in our [paper](https://biohub.ai/papers/esm_protein.pdf).
34
+
35
+ ## Intended Use
36
+
37
+ - Decomposing ESMC embeddings into interpretable features
38
+ - Visualizing feature activations on sequences and structures
39
+
40
+ ## Usage
41
+
42
+ The SAE model `ESMC-6B-sae-layer60-k64-codebook16384` provides users with interpretable, agent-generated feature descriptions. Users can access these feature descriptions through the ESM Atlas or through the Biohub Platform.
43
+
44
+ While all SAE models can be accessed through Hugging Face, only the following five SAE models are available through the Biohub Platform:
45
+
46
+ - `ESMC-6B-sae-layer60-k64-codebook16384`
47
+ - `ESMC-6B-sae-layer60-k64-codebook65536`
48
+ - `ESMC-600M-sae-layer27-k64-codebook16384`
49
+ - `ESMC-600M-sae-layer27-k64-codebook65536`
50
+ - `ESMC-300M-sae-layer23-k64-codebook65536`
51
+
52
+ You can access an SAE model through Hugging Face using the code below:
53
+
54
+ ```py
55
+ import torch
56
+ from transformers import AutoModel, AutoTokenizer
57
+
58
+ sequence = "MGSNKSKPKDASQRRRSLEPAENVHGAGGGAFPASQTPSKPASADGHRGPSAAFAPAAAEPKLFGGFNSSDTVTSPQRAGPLAGGVTTFVALYDYESRTETDLSFKKGERLQIVNNTEGDWWLAHSLSTGQTGYIPSNYVAPSDSIQAEEWYFGKITRRESERLLLNAENPRGTFLVRESETTKGAYCLSVSDFDNAKGLNVKHYKIRKLDSGGFYITSRTQFNSLQQLVAYYSKHADGLCHRLTTVCPTSKPQTQGLAKDAWEIPRESLRLEVKLGQGCFGEVWMGTWNGTTRVAIKTLKPGTMSPEAFLQEAQVMKKLRHEKLVQLYAVVSEEPIYIVTEYMSKGSLLDFLKGETGKYLRLPQLVDMAAQIASGMAYVERMNYVHRDLRAANILVGENLVCKVADFGLARLIEDNEYTARQGAKFPIKWTAPEAALYGRFTIKSDVWSFGILLTELTTKGRVPYPGMVNREVLDQVERGYRMPCPPECPESLHDLMCQCWRKEPEERPTFEYLQAFLEDYFTSTEPQYQPGENL"
59
+
60
+ model = AutoModel.from_pretrained("biohub/ESMC-6B", device_map="auto").eval()
61
+ tokenizer = AutoTokenizer.from_pretrained("biohub/ESMC-6B")
62
+ sae = AutoModel.from_pretrained(
63
+ "biohub/ESMC-6B-sae-k64-codebook16384",
64
+ allow_patterns=["config.json", "layer_30.safetensors", "layer_60.safetensors"],
65
+ device=model.device,
66
+ )
67
+ sae.initialize_layers([30, 60])
68
+ model.add_sae_models([sae.layers["30"], sae.layers["60"]])
69
+
70
+ inputs = tokenizer(sequence, return_tensors="pt", padding=True)
71
+ inputs = {k: v.to(model.device) for k, v in inputs.items()}
72
+
73
+ with torch.inference_mode():
74
+ output = model(**inputs)
75
+
76
+ # sparse.coo tensor of shape (batch, seq_len, codebook_size)
77
+ print(output["sae_outputs"]["layer60"].shape)
78
+ ```
79
+
80
+ ## Model Details
81
+
82
+ ESMC SAEs are trained to reconstruct ESMC embeddings at a residue level, meaning for a protein of length L, there are L sparse vectors of SAE features. For the models hosted on the Biohub platform, the embeddings are extracted from the hidden states. To provide different options for protein interpretability, our full set of SAE models contains both models that have been trained on hidden states and models that have been trained directly on the MLP outputs. Training SAE models on MLP outputs generates features specific to that layer's computation, while training the SAE models on hidden states may provide a more global understanding. We use the TopK approach for training SAEs to control sparsity by only allowing the top `k` features at each position to be active.
83
+
84
+ There are two critical hyperparameters for the TopK approach:
85
+
86
+ - `k`: the number of active features per position
87
+ - `codebook_size`: total number of features the SAE can learn
88
+
89
+ With smaller codebooks, the SAE may group related concepts together. For example, a single feature might activate for all metal-binding sites. With larger codebooks, the model can split general concepts into more granular features. For example, the model may learn dedicated features for zinc-finger motifs, iron-sulfur clusters, and calcium-binding loops.
90
+
91
+ ### Model Naming
92
+
93
+ There are three different families of models based on the SAE training target.
94
+
95
+ **Hidden states — SAE model for every layer.** The first family is trained on hidden states at every layer of the respective ESMC models. The naming convention is:
96
+
97
+ ```
98
+ {esmc-model}-sae-k64-codebook16384
99
+ ```
100
+
101
+ The options for `esmc-model` are:
102
+
103
+ - `ESMC-300M`
104
+ - `ESMC-600M`
105
+ - `ESMC-6B`
106
+
107
+ **MLP outputs — SAE model for every layer.** The second family is trained on the per-layer MLP output (before the residual connection) at every layer of the respective ESMC models. The naming convention is:
108
+
109
+ ```
110
+ {esmc-model}-sae-mlp-k64-codebook131072
111
+ ```
112
+
113
+ The options for `esmc-model` are:
114
+
115
+ - `ESMC-300M`
116
+ - `ESMC-600M`
117
+ - `ESMC-6B`
118
+
119
+ **Layer-specific — SAE model for every combination of `k` and `codebook_size`.** The last family is trained on one specific layer of the respective ESMC models with different top-`k` and codebook sizes. With these models, we targeted a 75% depth after various analyses showed that representations at this depth are often the most generalizable to a variety of downstream tasks, similar to findings from other large language models. The naming convention is:
120
+
121
+ ```
122
+ {esmc-model}-sae-layer{layer_num}-k{k}-codebook{codebook}
123
+ ```
124
+
125
+ The options for `esmc-model` with the corresponding `layer_num`:
126
+
127
+ | `esmc-model` | `layer_num` |
128
+ | :---- | ----: |
129
+ | `ESMC-300M` | 23 |
130
+ | `ESMC-600M` | 27 |
131
+ | `ESMC-6B` | 60 |
132
+
133
+ The options for `k` are: 16, 32, 64, 128, 256, 512.
134
+
135
+ The options for `codebook` are: 8192, 16384, 32768, 65536, 131072.
136
+
137
+ For example, to load the SAE trained on hidden states at layer 60 in ESMC 6B with `k=64` and the 65k codebook, use `ESMC-6B-sae-layer60-k64-codebook65536`.
138
+
139
+ ## Feature Descriptions
140
+
141
+ The SAE model `ESMC-6B-sae-layer60-k64-codebook16384` is the model most heavily studied in our paper and was used to generate features for the ESM Atlas. We also created agent-generated feature descriptions for this model. Users can access these feature descriptions through the ESM Atlas or through the Biohub Platform API.
142
+
143
+ ## Normalization Statistics
144
+
145
+ Only the `ESMC-6B-sae-layer60-k64-codebook16384` model has accessible normalization statistics. The other Biohub-platform-hosted models also include the option to normalize the SAE features, but these statistics are not currently accessible.
146
+
147
+ Normalization statistics are computed by using each model to compute SAE features for all proteins in UniRef90 and recording two quantities per feature: (1) the maximum activation value observed across the entire dataset, and (2) the Inverse Document Frequency (IDF), defined as `log(N / f)`, where `N` is the total number of proteins and `f` is the number of proteins in which the feature was active (non-zero).
148
+
149
+ At inference, activations are normalized as `(activation / max) * idf`. Dividing by the maximum scales each feature's output to the range `[0, 1]`, making features more comparable to each other. Multiplying by IDF then upweights rare, distinctive features and downweights ubiquitous ones, making it easier to distinguish biologically relevant features. These statistics can be accessed through the feature-description API.
150
+
151
+ ## Frontier Safety
152
+
153
+ Biohub has established a safety team to assess the benefits and potential risks of our models and tools prior to release, and develop mitigations where necessary. Informed by our risk assessments, we are releasing the source code and model weights for our ESMC SAEs. We are also releasing our ESM Atlas dataset openly.
154
+
155
+ Biohub.ai Platform: We implement guardrails that detect and restrict the use of keywords and sequences corresponding to controlled pathogens and toxins on our freely accessible platform. For further details regarding these guardrails, please refer to our Biohub platform Resources page.