andrewdalpino commited on
Commit
7dfe266
·
verified ·
1 Parent(s): da586f0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +114 -6
README.md CHANGED
@@ -1,10 +1,118 @@
1
  ---
 
 
 
 
 
 
 
 
 
2
  tags:
3
- - model_hub_mixin
4
- - pytorch_model_hub_mixin
5
  ---
6
 
7
- This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
8
- - Code: [More Information Needed]
9
- - Paper: [More Information Needed]
10
- - Docs: [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ datasets:
3
+ - andrewdalpino/AmiGO-Boost
4
+ metrics:
5
+ - precision
6
+ - recall
7
+ - f1
8
+ base_model:
9
+ - EvolutionaryScale/esmc-600m-2024-12
10
+ pipeline_tag: text-classification
11
  tags:
12
+ - gene-ontology
 
13
  ---
14
 
15
+ # ESMC Protein Function Predictor
16
+
17
+ An Evolutionary-scale Model (ESM) for protein function prediction from amino acid sequences using the Gene Ontology (GO). Based on the ESM Cambrian Transformer architecture, pre-trained on [UniRef](https://www.uniprot.org/help/uniref), [MGnify](https://www.ebi.ac.uk/metagenomics), and the Joint Genome Institute's database and fine-tuned on the [AmiGO Boost](https://huggingface.co/datasets/andrewdalpino/AmiGO-Boost) protein function dataset, this model predicts the GO subgraph for a particular protein sequence - giving you insight into the molecular function, biological process, and location of the activity inside the cell.
18
+
19
+ ## What are GO terms?
20
+
21
+ > "The Gene Ontology (GO) is a concept hierarchy that describes the biological function of genes and gene products at different levels of abstraction (Ashburner et al., 2000). It is a good model to describe the multi-faceted nature of protein function."
22
+
23
+ > "GO is a directed acyclic graph. The nodes in this graph are functional descriptors (terms or classes) connected by relational ties between them (is_a, part_of, etc.). For example, terms 'protein binding activity' and 'binding activity' are related by an is_a relationship; however, the edge in the graph is often reversed to point from binding towards protein binding. This graph contains three subgraphs (subontologies): Molecular Function (MF), Biological Process (BP), and Cellular Component (CC), defined by their root nodes. Biologically, each subgraph represent a different aspect of the protein's function: what it does on a molecular level (MF), which biological processes it participates in (BP) and where in the cell it is located (CC)."
24
+
25
+ From [CAFA 5 Protein Function Prediction](https://www.kaggle.com/competitions/cafa-5-protein-function-prediction/data)
26
+
27
+ ## Pretrained Models
28
+
29
+ The following pretrained models are available on HuggingFace Hub.
30
+
31
+ | Name | Embedding Dim. | Attn. Heads | Encoder Layers | Context Length | QAT | Total Parameters |
32
+ |---|---|---|---|---|---|---|
33
+ | [andrewdalpino/ESMC-300M-Protein-Function](https://huggingface.co/andrewdalpino/ESMC-300M-Protein-Function) | 960 | 15 | 30 | 2048 | None | 361M |
34
+ | [andrewdalpino/ESMC-300M-QAT-Protein-Function](https://huggingface.co/andrewdalpino/ESMC-300M-QAT-Protein-Function) | 960 | 15 | 30 | 2048 | int8w | 361M |
35
+ | [andrewdalpino/ESMC-600M-Protein-Function](https://huggingface.co/andrewdalpino/ESMC-600M-Protein-Function) | 1152 | 18 | 36 | 2048 | None | 644M |
36
+ | [andrewdalpino/ESMC-600M-QAT-Protein-Function](https://huggingface.co/andrewdalpino/ESMC-600M-QAT-Protein-Function) | 1152 | 18 | 36 | 2048 | int8w | 644M |
37
+
38
+ ## Basic Pretrained Example
39
+
40
+ First, install the `esmc_function_classifier` package using [pip](https://pypi.org/project/pip/).
41
+
42
+ ```sh
43
+ pip install esmc_function_classifier
44
+ ```
45
+
46
+ Then, we'll load the model weights from HuggingFace Hub, tokenize the amino acid sequence, and infer the GO terms.
47
+
48
+ ```python
49
+ import torch
50
+
51
+ from esm.tokenization import EsmSequenceTokenizer
52
+
53
+ from esmc_function_classifier.model import EsmcGoTermClassifier
54
+
55
+
56
+ model_name = "andrewdalpino/ESMC-600M-QAT-Protein-Function"
57
+
58
+ sequence = "MPPKGHKKTADGDFRPVNSAGNTIQAKQKYSIDDLLYPKSTIKNLAKETLPDDAIISKDALTAIQRAATLFVSYMASHGNASAEAGGRKKIT"
59
+
60
+ top_p = 0.5
61
+
62
+ tokenizer = EsmSequenceTokenizer()
63
+
64
+ model = EsmcGoTermClassifier.from_pretrained(model_name)
65
+
66
+ out = tokenizer(sequence, max_length=2048, truncation=True)
67
+
68
+ input_ids = torch.tensor(out["input_ids"], dtype=torch.int64)
69
+
70
+ go_term_probabilities = model.predict_terms(
71
+ input_ids, top_p=top_p
72
+ )
73
+ ```
74
+
75
+ You can also output the gene-ontology (GO) `networkx` subgraph for a given sequence like in the example below. You'll need an up-to-date gene ontology database that you can import using the `obonet` package.
76
+
77
+ ```sh
78
+ pip install obonet
79
+ ```
80
+
81
+ ```python
82
+ import networkx as nx
83
+
84
+ import obonet
85
+
86
+
87
+ # Visit https://geneontology.org/docs/download-ontology/ to download.
88
+ go_db_path = "./dataset/go-basic.obo"
89
+
90
+ graph = obonet.read_obo(go_db_path)
91
+
92
+ model.load_gene_ontology(graph)
93
+
94
+ subgraph, go_term_probabilities = model.predict_subgraph(
95
+ input_ids, top_p=top_p
96
+ )
97
+
98
+ json = nx.node_link_data(subgraph)
99
+
100
+ print(json)
101
+ ```
102
+
103
+ ### Quantized Model
104
+
105
+ To quantize the model weights using int8 call the `quantize_weights()` method. Any model can be quantized, but we recommend one that has been quantization-aware trained (QAT) for the best performance. The `group_size` argument controls the granularity at which quantization scales are computed.
106
+
107
+ ```python
108
+ model.quantize_weights(group_size=64)
109
+ ```
110
+
111
+ ## Code Repository
112
+
113
+ The training code can be found at [https://github.com/andrewdalpino/ESMC-Function-Classifier](https://github.com/andrewdalpino/ESMC-Function-Classifier).
114
+
115
+ ## References:
116
+
117
+ >- T. Hayes, et al. Simulating 500 million years of evolution with a language model, 2024.
118
+ >- M. Ashburner, et al. Gene Ontology: tool for the unification of biology, 2000.