Text Generation
PEFT
Safetensors
gemma
txgemma
ec-number
enzyme-commission
biochemical-reactions
lora
gemma4ec
Instructions to use PlanesLab/Gemma4EC-2B-Predict with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use PlanesLab/Gemma4EC-2B-Predict with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("google/txgemma-2b-predict") model = PeftModel.from_pretrained(base_model, "PlanesLab/Gemma4EC-2B-Predict") - Notebooks
- Google Colab
- Kaggle
File size: 2,655 Bytes
673b003 af5e3b6 673b003 af5e3b6 673b003 af5e3b6 673b003 af5e3b6 673b003 af5e3b6 673b003 af5e3b6 673b003 af5e3b6 673b003 af5e3b6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | ---
license: apache-2.0
base_model: google/txgemma-2b-predict
library_name: peft
pipeline_tag: text-generation
tags:
- gemma
- txgemma
- ec-number
- enzyme-commission
- biochemical-reactions
- lora
- peft
- gemma4ec
---
# Gemma4EC-2B-Predict
LoRA adapter for [google/txgemma-2b-predict](https://huggingface.co/google/txgemma-2b-predict) that predicts the
**Enzyme Commission (EC) number** of a biochemical reaction from its SMILES, down to the sub-subclass level.
- **Input:** a reaction SMILES, e.g. `CCO.O=O>>CC=O.OO`
- **Output:** an EC number, e.g. `1.01.03`
- **Code, preprocessing and benchmarks:** [github.com/PlanesLab/Gemma4EC](https://github.com/PlanesLab/Gemma4EC)
## Usage
The base model is gated: request access to [google/txgemma-2b-predict](https://huggingface.co/google/txgemma-2b-predict), then `huggingface-cli login`.
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
base = "google/txgemma-2b-predict"
tokenizer = AutoTokenizer.from_pretrained(base)
model = AutoModelForCausalLM.from_pretrained(base, torch_dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(model, "PlanesLab/Gemma4EC-2B-Predict").eval()
PROMPT = (
"Instructions: Given a reaction SMILES, predict the first three parts of its "
"Enzyme Commission (EC) number (class.subclass.sub-subclass).\n"
"EC numbers are four-part hierarchical codes (e.g., 1.3.2.4) describing the type "
"of enzyme and its reaction mechanism.\n"
"Only output the first three digits (e.g., 1.03.02) representing the enzyme's "
"general class, subclass, and sub-subclass.\n"
"Reaction SMILES: {reaction_smiles}\nAnswer:"
)
inputs = tokenizer(PROMPT.format(reaction_smiles="CCO.O=O>>CC=O.OO"), return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=8, do_sample=False)
print(tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True).strip())
```
Use this exact prompt. Preprocess SMILES with `preprocess_smiles.py` from the repository first; batch prediction
and chat explanations are also there.
## Training
LoRA (r = 16, alpha = 16) on `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj`,
fine-tuned on [ECReact](https://github.com/rxn4chemistry/biocatalysis-model).
## Citation
Please cite Gemma4EC (see the [repository](https://github.com/PlanesLab/Gemma4EC)) and
[TxGemma](https://huggingface.co/google/txgemma-2b-predict).
## License
Adapter weights: Apache-2.0. TxGemma weights: [Health AI Developer Foundations terms](https://developers.google.com/health-ai-developer-foundations/terms).
|