Update README.md
Browse files16 unmodified lines1718192020212222232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919016 unmodified lines I agree to use this model for non-commercial use ONLY: checkbox---
# Masked Discrete Latent Diffusion Model for Protein Sequence Generation# Masked Discrete Diffusion Model for Protein Sequence Generation
Here, we implement a masked discrete latent diffusion model for generating protein sequences. The model leverages the MDLM framework and ESM-2-650M for latent space representation and diffusion.Here, we implement a masked discrete diffusion model for generating protein sequences. The model leverages the MDLM framework and ESM-2-650M for latent space representation and diffusion.
## Directory Structure
```project/ββββ configs/β βββ config.pyββββ data/β βββ train.csvβ βββ val.csvβ βββ test.csvββββ models/β βββ diffusion.pyββββ scripts/β βββ train.pyβ βββ test.pyβ βββ generate.pyββββ utils/β βββ data_loader.pyβ βββ esm_utils.pyββββ checkpoints/β βββ example.ckpt # Placeholder for checkpointsββββ requirements.txtββββ README.md```
## Setup and Requirements
### Prerequisites
- Python 3.8+- CUDA (for GPU support)
### Install Dependencies
1. Create and activate a virtual environment: ```bash python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate` ```
2. Install the required packages: ```bash pip install -r requirements.txt ```
### Prepare Data
Place your data files (`train.csv`, `val.csv`, `test.csv`) in the `data/` directory. Ensure that these CSV files contain a column named `sequence` with the protein sequences.
## Configuration
Modify the `configs/config.py` file to set your hyperparameters, model configurations, and data paths. Here is an example configuration:
```pythonclass Config: model_name = "facebook/esm2_t33_650M_UR50D" latent_dim = 1280 # Adjust based on ESM-2 latent dimension optim = {"lr": 1e-4} training = { "ema": 0.999, "epochs": 10, "batch_size": 32, "gpus": 8, "precision": 16, # Mixed precision training "accumulate_grad_batches": 2, # Gradient accumulation "save_dir": "./checkpoints/", } data_path = "./data/" T = 1000 # Number of diffusion steps subs_masking = False```
## Mathematical Formulations
### Forward Diffusion
The forward diffusion process adds noise to the latent representations of the protein sequences:\[ ext{noisy\_latents} = ext{latents} + \sigma \cdot \epsilon \]where:- \(\sigma\) is the noise level.- \(\epsilon \sim \mathcal{N}(0, 1)\) is Gaussian noise.
### Reverse Diffusion
The reverse diffusion process denoises the latent representations:\[ ext{denoised\_latents} = ext{backbone}( ext{noisy\_latents}, \sigma) \]where the backbone model predicts the denoised latent representations.
### Loss Function
The loss function used to train the model is the Mean Squared Error (MSE) between the denoised latents and the original latents:\[ \mathcal{L} = ext{MSE}( ext{denoised\_latents}, ext{latents}) \]
## Training
To train the model, run the `train.py` script:
```bashpython scripts/train.py```
This script will:- Load the ESM-2-650M model and tokenizer from Hugging Face.- Prepare the data loaders for training and validation datasets.- Initialize the latent diffusion model.- Train the model using the specified configurations.
## Testing
To test the model, run the `test.py` script:
```bashpython scripts/test.py```
This script will:- Load the trained model from the checkpoint.- Prepare the data loader for the test dataset.- Evaluate the model on the test dataset.
## Generating Protein Sequences
To generate protein sequences, use the `generate.py` script. This script supports three strategies:
1. **Generating a Scaffold to Connect Multiple Peptides**: ```bash python scripts/generate.py scaffold <peptide1> <peptide2> ... <final_length> ``` Example: ```bash python scripts/generate.py scaffold MKTAYIAKQRQ GLIEVQ 30 ```
2. **Filling in Specified Regions in a Given Protein Sequence**: ```bash python scripts/generate.py fill <sequence_with_X> ``` Example: ```bash python scripts/generate.py fill MKTAYIAKXXXXXXXLEERLGLIEVQ ```
3. **Purely De Novo Generation of a Protein Sequence**: ```bash python scripts/generate.py de_novo <sequence_length> ``` Example: ```bash python scripts/generate.py de_novo 50 ```
## Notes
- Ensure you have a compatible CUDA environment if you are training on GPUs.- Modify the paths and configurations in `configs/config.py` as needed to match your setup.
## Acknowledgements
This implementation is based on the MDLM framework and uses the ESM-2-650M model.README.md+2-169