Text Generation
Transformers
Safetensors
gpt2
biology
plasmid
dna
synthetic-biology
text-generation-inference
Instructions to use UCL-CSSB/PlasmidGPT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use UCL-CSSB/PlasmidGPT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="UCL-CSSB/PlasmidGPT")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("UCL-CSSB/PlasmidGPT") model = AutoModelForCausalLM.from_pretrained("UCL-CSSB/PlasmidGPT", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use UCL-CSSB/PlasmidGPT with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "UCL-CSSB/PlasmidGPT" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "UCL-CSSB/PlasmidGPT", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/UCL-CSSB/PlasmidGPT
- SGLang
How to use UCL-CSSB/PlasmidGPT with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "UCL-CSSB/PlasmidGPT" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "UCL-CSSB/PlasmidGPT", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "UCL-CSSB/PlasmidGPT" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "UCL-CSSB/PlasmidGPT", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use UCL-CSSB/PlasmidGPT with Docker Model Runner:
docker model run hf.co/UCL-CSSB/PlasmidGPT
Camera-ready README: simplified to what-it-is / quick start / citation
Browse files
README.md
CHANGED
|
@@ -1,165 +1,40 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
**Original work:** [PlasmidGPT: a generative framework for plasmid design and annotation](https://www.biorxiv.org/content/10.1101/2024.09.30.615762v1)
|
| 10 |
-
**Original repository:** [github.com/lingxusb/PlasmidGPT](https://github.com/lingxusb/PlasmidGPT)
|
| 11 |
-
**Original model:** [huggingface.co/lingxusb/PlasmidGPT](https://huggingface.co/lingxusb/PlasmidGPT)
|
| 12 |
-
|
| 13 |
-
### Key Features
|
| 14 |
-
|
| 15 |
-
- **Novel Sequence Generation**: Generates novel plasmid sequences rather than replicating training data
|
| 16 |
-
- **Conditional Generation**: Supports generation based on user-specified starting sequences
|
| 17 |
-
- **Versatile Predictions**: Predicts sequence-related attributes including lab of origin, species, and vector type
|
| 18 |
-
- **Transformer Architecture**: Decoder-only transformer with 12 layers and 110 million parameters
|
| 19 |
-
|
| 20 |
-
## 🆚 Differences from Original
|
| 21 |
-
|
| 22 |
-
This version provides:
|
| 23 |
-
- ✅ Native HuggingFace `transformers` compatibility (no custom loading required)
|
| 24 |
-
- ✅ Standard model format (`model.safetensors` instead of `.pt`)
|
| 25 |
-
- ✅ Direct `AutoModel` and `AutoTokenizer` support
|
| 26 |
-
- ✅ Simplified installation and usage
|
| 27 |
-
|
| 28 |
-
## 📦 Installation
|
| 29 |
-
|
| 30 |
-
```bash
|
| 31 |
-
pip install torch transformers
|
| 32 |
-
```
|
| 33 |
-
|
| 34 |
-
## 🚀 Quick Start
|
| 35 |
-
|
| 36 |
-
### Basic Sequence Generation
|
| 37 |
-
|
| 38 |
-
```python
|
| 39 |
-
import torch
|
| 40 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 41 |
-
|
| 42 |
-
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 43 |
-
|
| 44 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 45 |
-
"McClain/plasmidgpt-addgene-gpt2",
|
| 46 |
-
trust_remote_code=True
|
| 47 |
-
).to(device)
|
| 48 |
-
model.eval()
|
| 49 |
-
|
| 50 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
| 51 |
-
"McClain/plasmidgpt-addgene-gpt2",
|
| 52 |
-
trust_remote_code=True
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
start_sequence = 'ATGGCTAGCGAATTCGGCGCGCCT'
|
| 56 |
-
input_ids = tokenizer.encode(start_sequence, return_tensors='pt').to(device)
|
| 57 |
-
|
| 58 |
-
outputs = model.generate(
|
| 59 |
-
input_ids,
|
| 60 |
-
max_length=300,
|
| 61 |
-
num_return_sequences=1,
|
| 62 |
-
temperature=1.0,
|
| 63 |
-
do_sample=True,
|
| 64 |
-
pad_token_id=tokenizer.pad_token_id,
|
| 65 |
-
eos_token_id=tokenizer.eos_token_id
|
| 66 |
-
)
|
| 67 |
-
|
| 68 |
-
generated_sequence = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 69 |
-
print(f"Generated sequence: {generated_sequence}")
|
| 70 |
-
```
|
| 71 |
-
|
| 72 |
-
### Generate Multiple Sequences
|
| 73 |
|
| 74 |
```python
|
| 75 |
-
|
| 76 |
-
input_ids,
|
| 77 |
-
max_length=500,
|
| 78 |
-
num_return_sequences=5,
|
| 79 |
-
temperature=1.2,
|
| 80 |
-
do_sample=True,
|
| 81 |
-
top_k=50,
|
| 82 |
-
top_p=0.95,
|
| 83 |
-
pad_token_id=tokenizer.pad_token_id,
|
| 84 |
-
eos_token_id=tokenizer.eos_token_id
|
| 85 |
-
)
|
| 86 |
-
|
| 87 |
-
for i, output in enumerate(outputs):
|
| 88 |
-
sequence = tokenizer.decode(output, skip_special_tokens=True)
|
| 89 |
-
print(f"Sequence {i+1}: {sequence[:100]}...")
|
| 90 |
-
```
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
```python
|
| 95 |
-
model.config.output_hidden_states = True
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
hidden_states = outputs.hidden_states[-1]
|
| 101 |
-
embedding = hidden_states.mean(dim=1).cpu().numpy()
|
| 102 |
-
|
| 103 |
-
print(f"Embedding shape: {embedding.shape}")
|
| 104 |
```
|
| 105 |
|
| 106 |
-
##
|
| 107 |
-
|
| 108 |
-
- **Plasmid Design**: Generate novel plasmid sequences for synthetic biology applications
|
| 109 |
-
- **Sequence Analysis**: Extract meaningful embeddings for downstream ML tasks
|
| 110 |
-
- **Feature Prediction**: Predict properties like lab of origin, species, or vector type
|
| 111 |
-
- **Conditional Generation**: Create sequences starting from specific promoters or genes
|
| 112 |
-
|
| 113 |
-
## 📊 Model Details
|
| 114 |
-
|
| 115 |
-
| Parameter | Value |
|
| 116 |
-
|-----------|-------|
|
| 117 |
-
| **Architecture** | GPT-2 (Decoder-only Transformer) |
|
| 118 |
-
| **Parameters** | 110 million |
|
| 119 |
-
| **Layers** | 12 |
|
| 120 |
-
| **Hidden Size** | 768 |
|
| 121 |
-
| **Attention Heads** | 12 |
|
| 122 |
-
| **Context Length** | 2048 tokens |
|
| 123 |
-
| **Vocabulary Size** | 30,002 |
|
| 124 |
-
| **Training Data** | 153k Addgene plasmid sequences |
|
| 125 |
-
|
| 126 |
-
## 📚 Citation
|
| 127 |
-
|
| 128 |
-
If you use this model, please cite the original PlasmidGPT paper:
|
| 129 |
|
| 130 |
```bibtex
|
| 131 |
@article{shao2024plasmidgpt,
|
| 132 |
-
title={PlasmidGPT: a generative framework for plasmid design and annotation},
|
| 133 |
-
author={Shao, Bin
|
| 134 |
-
journal={bioRxiv},
|
| 135 |
-
year={2024},
|
| 136 |
-
doi={10.1101/2024.09.30.615762}
|
| 137 |
-
url={https://www.biorxiv.org/content/10.1101/2024.09.30.615762v1}
|
| 138 |
}
|
| 139 |
```
|
| 140 |
-
|
| 141 |
-
## 📄 License
|
| 142 |
-
|
| 143 |
-
This model inherits the license from the original PlasmidGPT repository. Please refer to the [original repository](https://github.com/lingxusb/PlasmidGPT) for licensing details.
|
| 144 |
-
|
| 145 |
-
## 🙏 Credits
|
| 146 |
-
|
| 147 |
-
**Original Author:** Bin Shao (lingxusb)
|
| 148 |
-
**Original Work:** [PlasmidGPT GitHub Repository](https://github.com/lingxusb/PlasmidGPT)
|
| 149 |
-
**Paper:** [bioRxiv 2024.09.30.615762](https://www.biorxiv.org/content/10.1101/2024.09.30.615762v1)
|
| 150 |
-
|
| 151 |
-
This compatibility version was created to facilitate easier integration with modern ML workflows while preserving all capabilities of the original model.
|
| 152 |
-
|
| 153 |
-
## 🔗 Related Resources
|
| 154 |
-
|
| 155 |
-
- [Original PlasmidGPT Repository](https://github.com/lingxusb/PlasmidGPT)
|
| 156 |
-
- [Original HuggingFace Model](https://huggingface.co/lingxusb/PlasmidGPT)
|
| 157 |
-
- [PlasmidGPT Paper (bioRxiv)](https://www.biorxiv.org/content/10.1101/2024.09.30.615762v1)
|
| 158 |
-
- [Addgene Plasmid Repository](https://www.addgene.org/)
|
| 159 |
-
|
| 160 |
-
## ⚠️ Notes
|
| 161 |
-
|
| 162 |
-
- The model generates DNA sequences for research purposes
|
| 163 |
-
- Generated sequences should be validated before experimental use
|
| 164 |
-
- The model was trained on Addgene plasmids and performs best on similar sequence types
|
| 165 |
-
- For prediction tasks (lab, species, vector type), refer to the [original repository](https://github.com/lingxusb/PlasmidGPT) for prediction model weights
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: transformers
|
| 4 |
+
pipeline_tag: text-generation
|
| 5 |
+
tags:
|
| 6 |
+
- biology
|
| 7 |
+
- plasmid
|
| 8 |
+
- dna
|
| 9 |
+
- synthetic-biology
|
| 10 |
+
- gpt2
|
| 11 |
+
---
|
| 12 |
|
| 13 |
+
# PlasmidGPT
|
| 14 |
|
| 15 |
+
A HuggingFace-compatible repackaging of [PlasmidGPT](https://github.com/lingxusb/PlasmidGPT) (Shao, 2024) — a GPT-2-style decoder pretrained on 153k engineered plasmid sequences from Addgene. Loadable with standard `AutoModelForCausalLM` and `AutoTokenizer`. Used as the base for [PlasmidGPT-SFT](https://huggingface.co/UCL-CSSB/PlasmidGPT-SFT) and [PlasmidGPT-GRPO](https://huggingface.co/UCL-CSSB/PlasmidGPT-GRPO).
|
| 16 |
|
| 17 |
+
## Quick start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
```python
|
| 20 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
model = AutoModelForCausalLM.from_pretrained("UCL-CSSB/PlasmidGPT")
|
| 23 |
+
tokenizer = AutoTokenizer.from_pretrained("UCL-CSSB/PlasmidGPT")
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
input_ids = tokenizer("ATG", return_tensors="pt").input_ids
|
| 26 |
+
outputs = model.generate(input_ids, max_new_tokens=512, do_sample=True, temperature=1.0)
|
| 27 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
```
|
| 29 |
|
| 30 |
+
## Citation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
```bibtex
|
| 33 |
@article{shao2024plasmidgpt,
|
| 34 |
+
title = {{PlasmidGPT}: a generative framework for plasmid design and annotation},
|
| 35 |
+
author = {Shao, Bin},
|
| 36 |
+
journal = {bioRxiv},
|
| 37 |
+
year = {2024},
|
| 38 |
+
doi = {10.1101/2024.09.30.615762}
|
|
|
|
| 39 |
}
|
| 40 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|