Amin-Saeidi commited on
Commit
eb76ca3
·
verified ·
1 Parent(s): a6e811a

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +41 -7
README.md CHANGED
@@ -13,15 +13,15 @@ language:
13
  - en
14
  ---
15
 
16
- # PhageContraMLM: Contrastive Learning for Phage Protein Representations
17
 
18
- PhageContraMLM is a fine-tuned version of the `Rostlab/prot_t5_xl_uniref50` protein language model, trained with Low-Rank Adaptation (LoRA) using a hybrid objective that combines standard Masked Language Modeling (MLM) with a contrastive loss.
19
 
20
  The model is built to improve the embedding space for bacteriophage proteins, clustering them by functional group and PHROG family in a zero-shot setting.
21
 
22
  ## Intended Use
23
 
24
- PhageContraMLM is intended for researchers in computational biology and virology who need function-aware embeddings for phage protein sequences.
25
 
26
  **Primary use cases:**
27
  - **Zero-shot functional retrieval:** querying unknown phage proteins against a database of known PHROG families using cosine similarity or L2 distance.
@@ -29,7 +29,7 @@ PhageContraMLM is intended for researchers in computational biology and virology
29
 
30
  ## How to Use
31
 
32
- The model relies on the Hugging Face `transformers` and `peft` libraries.
33
 
34
  ```python
35
  import torch
@@ -38,14 +38,15 @@ from peft import PeftModel
38
 
39
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
40
  base_model_name = "Rostlab/prot_t5_xl_uniref50"
41
- adapter_dir = "Amin-Saeidi/PhageContraMLM" # update to your exact repo ID
 
42
 
43
  # 1. Load tokenizer and base model
44
  tokenizer = T5Tokenizer.from_pretrained(base_model_name, do_lower_case=False)
45
  model = T5ForConditionalGeneration.from_pretrained(base_model_name, torch_dtype=torch.float16)
46
 
47
  # 2. Attach LoRA adapters and merge
48
- model = PeftModel.from_pretrained(model, adapter_dir)
49
  model = model.merge_and_unload().to(device).eval()
50
 
51
  # 3. Prepare sequence (space-separated, rare amino acids replaced)
@@ -62,6 +63,39 @@ with torch.no_grad():
62
  print(pooled_embedding.shape)
63
  ```
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  ## Training Data and Process
66
 
67
  - **Data:** `envhog_phrog2` dataset.
@@ -83,7 +117,7 @@ High-throughput script for generating mean-pooled encoder embeddings. Loads the
83
  **`src/eval_EmbeddingSpace.py`**
84
  Generates publication-quality plots analyzing the embedding space:
85
  - t-SNE grids colored by PhrogCat category
86
- - Pairwise L2 and cosine scatter plots comparing the base model against the fine-tuned PhageContraMLM model
87
 
88
  **`src/eval_PhrogRetrieval.py`**
89
  Zero-shot functional retrieval benchmarking using `hnswlib` (Hierarchical Navigable Small World graphs):
 
13
  - en
14
  ---
15
 
16
+ # ContraMLM: Contrastive Learning for Phage Protein Representations
17
 
18
+ ContraMLM is a fine-tuned version of the `Rostlab/prot_t5_xl_uniref50` protein language model, trained with Low-Rank Adaptation (LoRA) using a hybrid objective that combines standard Masked Language Modeling (MLM) with a contrastive loss.
19
 
20
  The model is built to improve the embedding space for bacteriophage proteins, clustering them by functional group and PHROG family in a zero-shot setting.
21
 
22
  ## Intended Use
23
 
24
+ ContraMLM is intended for researchers in computational biology and virology who need function-aware embeddings for phage protein sequences.
25
 
26
  **Primary use cases:**
27
  - **Zero-shot functional retrieval:** querying unknown phage proteins against a database of known PHROG families using cosine similarity or L2 distance.
 
29
 
30
  ## How to Use
31
 
32
+ The model relies on the Hugging Face `transformers` and `peft` libraries. The LoRA adapters live inside this repo under `runs/protrans_XL_Full_lora_envhog_ContraMLM_v1_1/lora_adapters`, so make sure to pass `subfolder` when loading.
33
 
34
  ```python
35
  import torch
 
38
 
39
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
40
  base_model_name = "Rostlab/prot_t5_xl_uniref50"
41
+ adapter_repo = "Amin-Saeidi/PhageContraMLM"
42
+ adapter_subfolder = "runs/protrans_XL_Full_lora_envhog_ContraMLM_v1_1/lora_adapters"
43
 
44
  # 1. Load tokenizer and base model
45
  tokenizer = T5Tokenizer.from_pretrained(base_model_name, do_lower_case=False)
46
  model = T5ForConditionalGeneration.from_pretrained(base_model_name, torch_dtype=torch.float16)
47
 
48
  # 2. Attach LoRA adapters and merge
49
+ model = PeftModel.from_pretrained(model, adapter_repo, subfolder=adapter_subfolder)
50
  model = model.merge_and_unload().to(device).eval()
51
 
52
  # 3. Prepare sequence (space-separated, rare amino acids replaced)
 
63
  print(pooled_embedding.shape)
64
  ```
65
 
66
+ ## From Source
67
+
68
+ If you want to retrain or modify the model locally, clone the full repo (adapters, data, and scripts included).
69
+
70
+ First, create a virtual environment in Python 3.11.5:
71
+
72
+ ```
73
+ conda create -n contramlm_env python=3.11.5
74
+ conda activate contramlm_env
75
+ ```
76
+
77
+ Clone the repo. You will need git-lfs: for WSL or Linux use `sudo apt-get install git-lfs`, for Windows either use [git bash](https://git-scm.com/downloads) or get git-lfs from [here](https://github.com/git-lfs/git-lfs/releases). Then:
78
+
79
+ ```
80
+ git lfs install
81
+ git clone https://huggingface.co/Amin-Saeidi/PhageContraMLM
82
+ ```
83
+
84
+ Install dependencies:
85
+
86
+ ```
87
+ cd PhageContraMLM
88
+ pip install -r requirements.txt
89
+ ```
90
+
91
+ Usage (training):
92
+
93
+ ```
94
+ python src/train.py
95
+ ```
96
+
97
+ Check `src/train.py` for the available config flags (data paths, LoRA rank/alpha, loss weighting) before launching a run.
98
+
99
  ## Training Data and Process
100
 
101
  - **Data:** `envhog_phrog2` dataset.
 
117
  **`src/eval_EmbeddingSpace.py`**
118
  Generates publication-quality plots analyzing the embedding space:
119
  - t-SNE grids colored by PhrogCat category
120
+ - Pairwise L2 and cosine scatter plots comparing the base model against the fine-tuned ContraMLM model
121
 
122
  **`src/eval_PhrogRetrieval.py`**
123
  Zero-shot functional retrieval benchmarking using `hnswlib` (Hierarchical Navigable Small World graphs):