sasudo2 commited on
Commit
6f347a5
·
verified ·
1 Parent(s): f3da413

docs: add detailed cross-model common files analysis and model architectures

Browse files
Files changed (1) hide show
  1. README.md +89 -44
README.md CHANGED
@@ -15,69 +15,114 @@ This repository contains trained models, configurations, and inference scripts d
15
  ---
16
 
17
  ## 📋 Table of Contents
18
- 1. [Overview](#overview)
19
- 2. [Model Artifacts & Architectures](#model-artifacts--architectures)
 
20
  * [`esm2_ffn` (ESM-2 + Feed-Forward Network Head)](#esm2_ffn-esm-2--feed-forward-network-head)
21
- * [`blast_knn` (BLAST & K-Nearest Neighbors Baseline)](#blast_knn-blast--k-nearest-neighbors-baseline)
22
  * [`lr3mer` (Logistic Regression 3-mer Baseline)](#lr3mer-logistic-regression-3-mer-baseline)
23
- 3. [Input & Output Schemas](#input--output-schemas)
24
- 4. [Quick Usage Example](#quick-usage-example)
25
 
26
  ---
27
 
28
  ## 1. Overview
29
- Predicting protein functions across Gene Ontology (GO) domains (Biological Process, Molecular Function, and Cellular Component) is crucial for functional annotation pipelines. This repository hosts multiple modeling approaches—ranging from deep learning embeddings (`esm2_ffn`) to sequence homology and baseline approaches (`blast_knn`, `lr3mer`)—to generate standardized functional predictions (`EntryID`, `term`, `score`).
30
 
31
- ---
 
 
 
32
 
33
- ## 2. Model Artifacts & Architectures
34
 
35
- ### `esm2_ffn`
36
- A hybrid model combining a frozen protein language model encoder with a custom feed-forward classification head.
37
- * **Base Model Encoder:** [`facebook/esm2_t33_650M_UR50D`](https://huggingface.co/facebook/esm2_t33_650M_UR50D) (1,280 feature dimensions).
38
- * **Training Hardware:** Tesla T4 GPU.
39
- * **Training Stats:** Evaluated across 141,995 training proteins and 141,864 test proteins, generating over 200 million prediction rows.
40
- * **Head Configuration:**
41
- * Hidden Dimension: 512
42
- * Dropout: 0.2
43
- * Learning Rate: 0.001
44
- * Weight Decay: 0.0001
45
- * Positive Weight Cap: 50.0
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- ### `blast_knn`
48
- A sequence-similarity and neighborhood-based baseline utilizing sequence alignment scores and k-nearest neighbors over annotation spaces.
49
- * **Configuration:** Configured via `blast_knn/config.json` and tracked with `blast_knn/manifest.json`.
50
 
51
- ### `lr3mer`
52
- A lightweight sequence-based baseline utilizing 3-mer frequency representations coupled with multi-label logistic regression classifiers.
53
- * **Configuration:** Backed by sequence k-mer tracking matrices and `lr3mer/go_terms.json`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  ---
56
 
57
- ## 3. Input & Output Schemas
58
-
59
- * **Required Input Fields:**
60
- * `EntryID`: Unique identifier for the protein sequence.
61
- * `sequence`: Amino acid sequence string.
62
- * **Prediction Output Schema:**
63
- * `EntryID`: Protein identifier.
64
- * `term`: Gene Ontology term ID (e.g., `GO:0009987`).
65
- * `score`: Confidence score ranging between $0.0$ and $1.0$.
 
 
 
 
 
66
 
67
  ---
68
 
69
- ## 4. Quick Usage Example
70
 
71
- You can inspect, download, or execute inference for the `esm2_ffn` model bundle directly using the provided `inference.py` script:
72
 
73
  ```python
74
- import torch
75
- from pathlib import Path
76
- from esm2_ffn.inference import load_model, resolve_model_dir
 
 
77
 
78
- # Load model bundle from the Hub
79
- model_dir = resolve_model_dir("sasudo2/cafa5_models", subfolder="esm2_ffn")
80
- print(f"Model bundle resolved at: {model_dir}")
81
 
82
- # Example inference script execution
83
- # python esm2_ffn/inference.py --model-dir {model_dir} --input proteins.fasta
 
 
15
  ---
16
 
17
  ## 📋 Table of Contents
18
+ 1. [Overview](#1-overview)
19
+ 2. [Shared Files & Cross-Model Common Assets](#2-shared-files--cross-model-common-assets)
20
+ 3. [Model Architectures & Context](#3-model-architectures--context)
21
  * [`esm2_ffn` (ESM-2 + Feed-Forward Network Head)](#esm2_ffn-esm-2--feed-forward-network-head)
22
+ * [`blast_knn` (Sequence Alignment & K-Nearest Neighbors)](#blast_knn-sequence-alignment--k-nearest-neighbors)
23
  * [`lr3mer` (Logistic Regression 3-mer Baseline)](#lr3mer-logistic-regression-3-mer-baseline)
24
+ 4. [Input & Output Schemas](#4-input--output-schemas)
25
+ 5. [Quick Usage Example](#5-quick-usage-example)
26
 
27
  ---
28
 
29
  ## 1. Overview
30
+ Predicting protein functions across the three Gene Ontology (GO) domains—**Biological Process (BPO)**, **Molecular Function (MFO)**, and **Cellular Component (CCO)**—is critical for structural biology and functional annotation.
31
 
32
+ This repository provides three complementary modeling paradigms evaluated on identical training sequences (142,241 proteins) and test sequences (141,864 proteins):
33
+ * **Deep Protein Language Modeling:** Contextual representations from ESM-2 coupled with a multi-label classification head.
34
+ * **Sequence Alignment & Homology:** Fast sequence search using DIAMOND and annotation propagation via weighted K-Nearest Neighbors ($k=50$).
35
+ * **N-gram Linear Baseline:** Multi-label logistic regression trained on normalized amino-acid 3-mer frequency representations.
36
 
37
+ ---
38
 
39
+ ## 2. Shared Files & Cross-Model Common Assets
40
+
41
+ To guarantee strict benchmark fairness and reproducible evaluations, all models share a common vocabulary, training set, and artifact structure:
42
+
43
+ ### Common Input Assets (`shared/` directory)
44
+ * **`shared/selected_terms.json` & `go_terms.json` (4,152 GO terms):**
45
+ * **What it is:** The ordered vocabulary of target GO term identifiers across BPO, MFO, and CCO.
46
+ * **Why it is needed:** Multi-label classification models must predict identical target output vectors. By applying unified frequency knee cutoffs (BPO $\ge 106$, MFO $\ge 70$, CCO $\ge 79$) and pruning uninformative root terms (`GO:0003674`, `GO:0005575`, `GO:0008150`), all models output predictions over an identical label space.
47
+ * **`shared/train_sequences_filtered.fasta` (142,241 proteins):**
48
+ * **What it is:** The canonical FASTA file containing all quality-filtered training protein sequences.
49
+ * **Why it is needed:** Guarantees that deep learning embeddings, 3-mer frequency counts, and the reference alignment database are constructed from identical sequences.
50
+ * **`shared/train_terms_filtered.tsv` (4,692,553 annotations):**
51
+ * **What it is:** Tab-separated ground-truth mapping linking each training `EntryID` to its experimental GO terms.
52
+ * **Why it is needed:** Serves as the binary training target for `esm2_ffn` and `lr3mer`, as well as the reference annotation store propagated to query proteins by `blast_knn`.
53
+ * **`shared/preprocessing_manifest.json`:**
54
+ * **What it is:** Documented cutoff rules, data versions, and SHA-256 hashes verifying preprocessing provenance.
55
+
56
+ ### Common Artifacts in Every Model Directory
57
+ * **`manifest.json`:**
58
+ * **What it is:** Standardized metadata file capturing configuration parameters, compute hardware (e.g. Tesla T4), runtime, random seed (`42`), package versions, and SHA-256 artifact checksums.
59
+ * **Why it is needed:** Ensures full scientific reproducibility, verification of inputs/outputs, and parameter tracking across different modeling experiments.
60
+ * **`submission.tsv`:**
61
+ * **What it is:** CAFA 5 formatted prediction file containing `EntryID`, `term`, and probability `score` for all 141,864 test proteins.
62
+ * **Why it is needed:** Enables out-of-the-box comparative evaluation and ensemble blending without re-running long inference pipelines.
63
 
64
+ ---
 
 
65
 
66
+ ## 3. Model Architectures & Context
67
+
68
+ ### `esm2_ffn` (ESM-2 + Feed-Forward Network Head)
69
+ A deep representation model that captures contextual amino-acid semantics from raw sequence representations.
70
+ * **Architecture:**
71
+ * **Backbone:** Frozen [`facebook/esm2_t33_650M_UR50D`](https://huggingface.co/facebook/esm2_t33_650M_UR50D) protein language model (33 layers, 1,280 hidden dimensions).
72
+ * **Pooling:** Mean pooling over valid residue tokens (excluding special tokens).
73
+ * **Head:** Linear(1280 $\to$ 512) $\to$ ReLU $\to$ Dropout(0.2) $\to$ Linear(512 $\to$ 4152).
74
+ * **Self-Contained Deployment:** The single `esm2_ffn/model.safetensors` checkpoint bundles both the complete frozen ESM-2 encoder and the trained FFN head alongside tokenizer assets and configs (`esm2_base/config.json`), requiring no external download connection to original Facebook weights.
75
+ * **Inference Optimizations:** Batched inference with dynamic token budgets (4,096 tokens) and length-sorted windows to minimize padding overhead and bound GPU VRAM usage.
76
+
77
+ ### `blast_knn` (Sequence Alignment & K-Nearest Neighbors)
78
+ A classical bioinformatics baseline leveraging evolutionary conservation and sequence homology.
79
+ * **Architecture:**
80
+ * **Aligner:** DIAMOND `blastp --fast` against `reference_sequences.fasta` (built from the 142,241 training proteins).
81
+ * **Neighborhood Propagation:** Selects top $k=50$ nearest neighbors with an e-value threshold of $\le 0.001$.
82
+ * **Weighting:** Scores are weighted by sequence percent identity (`pident`) and normalized against query annotations (`reference_annotations.parquet`), filtered at a minimum confidence threshold of 0.01.
83
+ * **Context & Utility:** High-precision predictions for homologs with well-conserved sequences; provides a strong, orthogonal signal when ensembled with deep learning models.
84
+
85
+ ### `lr3mer` (Logistic Regression 3-mer Baseline)
86
+ A lightweight sequence composition baseline modeling local amino-acid motifs.
87
+ * **Architecture:**
88
+ * **Vocabulary:** 8,000 canonical 3-mer permutations (`AAA` through `YYY` derived from 20 standard amino acids, tracked in `three_mer_vocabulary.json`).
89
+ * **Model:** Multi-label logistic regression per GO term implemented in PyTorch (`lr3mer/model.pt`), optimized using AdamW and positive class weighting (cap: 50.0).
90
+ * **Context & Utility:** Fast, low-memory baseline requiring no GPU or alignment tools during inference. It captures short motif biases and baseline term frequencies across the proteome.
91
 
92
  ---
93
 
94
+ ## 4. Input & Output Schemas
95
+
96
+ * **Required Input FASTA:**
97
+ ```fasta
98
+ >P12345
99
+ MKTLLILTCLVAVALAMKTLL...
100
+ ```
101
+ * **Prediction Output Format (`submission.tsv`):**
102
+ Headerless TSV format adhering to CAFA 5 specifications:
103
+ ```tsv
104
+ P12345 GO:0005515 0.842
105
+ P12345 GO:0008152 0.619
106
+ P12345 GO:0003674 0.520
107
+ ```
108
 
109
  ---
110
 
111
+ ## 5. Quick Usage Example
112
 
113
+ Execute inference on arbitrary sequences using the standalone `esm2_ffn` runner:
114
 
115
  ```python
116
+ import runpy
117
+ from huggingface_hub import hf_hub_download
118
+
119
+ repo = "sasudo2/cafa5_models"
120
+ revision = "main"
121
 
122
+ # Download and execute the self-contained inference script
123
+ loader = hf_hub_download(repo, "esm2_ffn/inference.py", revision=revision)
124
+ inference = runpy.run_path(loader)
125
 
126
+ # Run batch prediction directly from FASTA
127
+ inference["predict_fasta"](repo, "input_proteins.fasta", "predictions.tsv", revision=revision)
128
+ ```