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
|
Download README.md from PlanesLab/Gemma4EC-2B-Predict: direct link, hf CLI and curl.
- Browser
- Download file 2.66 kB
-
https://huggingface.co/PlanesLab/Gemma4EC-2B-Predict/resolve/main/README.md
- Command line
-
hf download hf://PlanesLab/Gemma4EC-2B-Predict/README.md
-
curl -L -o README.md https://huggingface.co/PlanesLab/Gemma4EC-2B-Predict/resolve/main/README.md
2.66 kB
| 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). | |