CoolFace
Modelpublic

OussamaEL/IbnSinna-2B-Pharma

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
2likes31downloads
Model Card

<div align="center">

<img src="Logo-IbnSinna.png" alt="IbnSinna-2B-Drug Logo" width="400" height="400" style="margin-bottom: 20px;"/>

<h1>๐Ÿงช IbnSinna-2B-Pharma: Drug Discovery Language Model</h1>

Advanced Pharmaceutical AI for Molecular Discovery

๐Ÿ”ฌ Binary Classification โ€ข ๐Ÿ“Š Regression โ€ข ๐Ÿงฌ Conditional Generation

![Hugging Face](https://huggingface.co/OussamaEL/IbnSinna-2B-Pharma) ![License](https://opensource.org/licenses/Apache-2.0) ![Base Model](https://huggingface.co/google/txgemma-2b-predict)

</div>


๐Ÿ“Œ Note: This model supersedes the earlier IbnSinna-2B-Drug model, which has been deprecated. Please use this version for all applications.

๐ŸŽจ Model Overview

IbnSinna-2B-Pharma is a specialized language model fine-tuned for three core drug discovery tasks:

  1. 1.Binary Classification: Predicting a wide range of molecular properties with Yes/No answers, including ADMET properties (e.g., clinical toxicity, BBB permeability), bioactivity (e.g., BACE and HIV inhibition), and pathway interactions (e.g., stress response and nuclear receptor binding)
  2. 2.Regression: Predicting key quantitative physicochemical values, specifically aqueous solubility (logS) and hydration free energy.
  3. 3.Conditional Generation: Designing novel molecules by providing a chemical scaffold as a structural constraint.

Built on Google's TXGemma-2B architecture and fine-tuned on comprehensive pharmaceutical datasets, this model serves as a powerful tool for computational drug discovery and molecular property prediction.

Important: This model was trained as a plain text generator (not chat-based). Prompts should end with \nAnswer: and the model will complete the answer directly.

๐Ÿ“ˆ Evaluation

The model was evaluated on samples from standard benchmark datasets (TDC: ClinTox, ESOL) and a custom generation task.

1. Binary Classification (ClinTox)

  • โ€”Performance: The model demonstrates a good ability to identify positive cases (Recall: 66.7%) but does so at the cost of a high false-positive rate (Precision: 22.2%). This makes it suitable for initial screening where missing a potentially toxic compound is more critical than misidentifying a safe one.
  • โ€”Metrics:
  • โ€”Accuracy: 73.3%
  • โ€”F1 Score: 33.3%

2. Regression (ESOL Solubility)

  • โ€”Performance: The model correctly understands the task and provides formatted numerical output. However, its quantitative accuracy is low (MAE: 2.57) compared to specialized regression models. It should be used for qualitative estimation rather than precise value prediction.
  • โ€”Metrics:
  • โ€”RMSE: 3.05
  • โ€”MAE: 2.57

3. Conditional Generation (Scaffold-based)

  • โ€”Performance: The model excels at this task when using sampling-based decoding. It generates a high rate of chemically valid and unique molecules, demonstrating a strong ability to explore chemical space.
  • โ€”Metrics:
  • โ€”SMILES Validity Rate: 90.0%
  • โ€”Molecule Uniqueness Rate: 100.0%

๐Ÿš€ Quick Start

python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

# Load model and tokenizer
model = AutoModelForCausalLM.from_pretrained(
    "OussamaEL/IbnSinna-2B-Pharma",
    torch_dtype=torch.bfloat16,
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("OussamaEL/IbnSinna-2B-Pharma")

def ask(prompt, max_new_tokens=32, do_sample=False):
    """
    Queries the model. Use do_sample=True for generative tasks.
    """
    text = f"{prompt}\nAnswer:"
    inputs = tokenizer(text, return_tensors="pt").to(model.device)
    
    outputs = model.generate(
        **inputs, 
        max_new_tokens=max_new_tokens, 
        do_sample=do_sample,
        pad_token_id=tokenizer.eos_token_id,
        temperature=0.8 if do_sample else None,
        top_k=50 if do_sample else None
    )
    
    # Decode and extract the answer part
    generated_text = tokenizer.decode(outputs, skip_special_tokens=True)
    try:
        answer = generated_text.split("Answer:").strip()
    except IndexError:
        answer = "Could not parse answer."
    return answer

# Example: HIV Inhibitor Classification (Greedy Decoding)
prompt = "Molecule: COc1ccc(N2C(=O)C3c4[nH]c5ccc(C)cc5c4C4CCC(C(C)(C)C)CC4C3C2=O)cc1\nQuestion: Is this molecule an HIV inhibitor?"
print(ask(prompt, max_new_tokens=5, do_sample=False))

# Example: Molecule Generation (Sampling)
prompt_gen = "Molecule Scaffold: c1ccccc1\nQuestion: Generate a novel molecule containing this scaffold."
print(ask(prompt_gen, max_new_tokens=100, do_sample=True))

๐ŸŽฏ Model Capabilities

The model excels at three primary tasks:

1๏ธโƒฃ Binary Classification

Predicting molecular properties with Yes/No outcomes:

  • โ€”Clinical Toxicity: Predicting adverse effects and safety profiles (from ClinTox).
  • โ€”BACE Inhibition: ฮฒ-secretase 1 inhibitor prediction (from BACE).
  • โ€”HIV Inhibition: Antiviral activity prediction (from HIV).
  • โ€”Stress Response Pathways: Activation of pathways like ARE, HSE, and p53 (from Tox21).
  • โ€”Nuclear Receptor Binding: Ligand prediction for receptors like ER, AR, and AhR (from Tox21).
  • โ€”ADMET Properties: Blood-Brain Barrier (BBB) permeability (from BBBP).

2๏ธโƒฃ Regression

Predicting quantitative molecular properties:

  • โ€”Aqueous Solubility (logS): Water solubility prediction (from ESOL).
  • โ€”Hydration Free Energy: Calculating the free energy of solvation in water (from FreeSolv).

3๏ธโƒฃ Conditional Generation

Designing novel molecules based on constraints:

  • โ€”Scaffold-based Design: Generating novel molecules that contain a specific user-provided core structure or scaffold.

๐Ÿ’ป Detailed Usage Examples

Classification Tasks

python
classification_prompts = [
    "Analyze Oc1ccc(Cl)c(Cl)c1 and determine if it is a stress response pathway ARE activator.",
    "Analyze COc1ccccc1NC(=O)CC(C)=O and determine if it is a nuclear receptor AhR ligand.",
    "Analyze CC[C@H]1C[C@H]2[C@@H]3CCC4=CC(=O)CC[C@@H]4[C@H]3CC[C@]2(C)[C@H]1O and determine if it is a nuclear receptor AR ligand."
]

for prompt in classification_prompts:
    text = prompt + "\nAnswer:"
    inputs = tokenizer(text, return_tensors="pt", max_length=512, truncation=True)
    inputs = {k: v.to(model.device) for k, v in inputs.items()}
    
    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_new_tokens=5,
            do_sample=False,
            pad_token_id=tokenizer.eos_token_id,
            eos_token_id=tokenizer.eos_token_id
        )
    
    gen = outputs[0, inputs["input_ids"].shape[1]:]
    answer = tokenizer.decode(gen, skip_special_tokens=True).strip().split()[0]  # Get first word (Yes/No)
    print(f"Q: {prompt[:50]}...")
    print(f"A: {answer}\n")

Molecule Generation

python
generation_prompts = [
    "Design a molecule containing the core structure O=C1Nc2ccccc2Oc2ccccc21.",
    "Design a molecule containing the core structure c1ccc2c(c1)Cc1ccccc1N2.",
    "Generate a molecule based on the scaffold c1ccccc1."
]

for prompt in generation_prompts:
    text = prompt + "\nAnswer:"
    inputs = tokenizer(text, return_tensors="pt")
    inputs = {k: v.to(model.device) for k, v in inputs.items()}
    
    outputs = model.generate(
        **inputs,
        max_new_tokens=50,
        temperature=0.7,
        do_sample=True,
        top_p=0.95
    )
    
    gen = outputs[0, inputs["input_ids"].shape[1]:]
    smiles = tokenizer.decode(gen, skip_special_tokens=True).strip()
    print(f"Scaffold: {prompt}")
    print(f"Generated: {smiles}\n")

Property Prediction

python
property_prompts = [
    "What is the predicted aqueous solubility (logS) of CCCCCCCO?",
    "What is the predicted aqueous solubility (logS) of Cc1ccc(O)cc1?"
]

for prompt in property_prompts:
    text = prompt + "\nAnswer:"
    inputs = tokenizer(text, return_tensors="pt")
    inputs = {k: v.to(model.device) for k, v in inputs.items()}
    
    outputs = model.generate(**inputs, max_new_tokens=10, do_sample=False)
    gen = outputs[0, inputs["input_ids"].shape[1]:]
    value = tokenizer.decode(gen, skip_special_tokens=True).strip()
    print(f"Molecule: {prompt.split('of ')[-1].replace('?', '')}")
    print(f"Predicted logS: {value}\n")

๐Ÿ”ง Technical Specifications

Model Architecture

  • โ€”Base Model: Google's TXGemma-2B-predict
  • โ€”Parameters: ~2.5B (2,635,108,608 total)
  • โ€”Fine-tuning Method: QLoRA (4-bit NF4 + bf16 compute) โ†’ Full model merge to FP16
  • โ€”LoRA Config: r=8, alpha=16, dropout=0.05
  • โ€”Target Modules: qproj, kproj, vproj, oproj, gateproj, upproj, down_proj
  • โ€”Training Precision: 4-bit NF4 with bf16 compute dtype
  • โ€”Released Precision: FP16 (merged model)

Training Details

  • โ€”Optimizer: Paged AdamW 8-bit
  • โ€”Learning Rate: 1e-4 with cosine scheduler
  • โ€”Effective Batch Size: 4
  • โ€”Warmup Steps: 20
  • โ€”Max Sequence Length: 256-512 tokens (recommend 256 for short prompts)
  • โ€”Training Framework: HuggingFace Transformers + PEFT + TRL

Dataset Information

The model was trained on a custom-built dataset aggregated from MoleculeNet.

  • โ€”Source: MoleculeNet (Tox21, ClinTox, BBBP, HIV, BACE, ESOL, FreeSolv)
  • โ€”Training Samples: 33,179
  • โ€”Training Task Distribution (approximate):
  • โ€”~53% Classification
  • โ€”~44% Generation
  • โ€”~3% Regression

โš ๏ธ Limitations and Ethical Considerations

Intended Use

  • โ€”โœ… Research and Development: Drug discovery research, lead optimization
  • โ€”โœ… Educational Purposes: Teaching molecular modeling concepts
  • โ€”โœ… Screening Tools: Initial compound screening and prioritization
  • โ€”โŒ NOT for Clinical Decisions: Do not use for patient treatment decisions
  • โ€”โŒ NOT for Final Validation: Always require wet-lab validation

Known Limitations

  1. 1.Low Quantitative Accuracy: The model's predictions on regression tasks (e.g., LogS) are not precise and should be treated as qualitative estimates.
  2. 2.High False-Positive Rate in Classification: The model tends to be overly cautious in toxicity prediction, leading to a high rate of false positives.
  3. 3.Imperfect Prompt Adherence: In generation tasks, the model may occasionally produce molecules that do not perfectly adhere to all structural constraints (e.g., including a required scaffold).
  4. 4.Dataset Biases: The model's knowledge is limited to the chemical space and biases present in the MoleculeNet datasets it was trained on.
  5. 5.SMILES-based: The model operates on 1D SMILES strings and does not reason about 3D molecular conformations.

Ethical Guidelines

  • โ€”Always validate predictions experimentally
  • โ€”Consider potential biases in drug discovery pipelines
  • โ€”Ensure equitable application across different populations
  • โ€”Respect intellectual property in molecular design

๐Ÿ“š Citation

If you use this model in your research, please cite:

bibtex
@model{ibnsinna_2b_pharma_2025,
  title={IbnSinna-2B-Pharma: Drug Discovery Language Model},
  author={Oussama El Allam},
  year={2025},
  month={August},
  url={https://huggingface.co/OussamaEL/IbnSinna-2B-Pharma},
  note={Fine-tuned TXGemma-2B for pharmaceutical and drug discovery applications},
  publisher={Hugging Face}
}

๐Ÿค Acknowledgments

  • โ€”Google DeepMind for the TXGemma base model
  • โ€”The drug discovery and cheminformatics community
  • โ€”Contributors to the training datasets

๐Ÿ”— Links


<div align="center">

Made with ๐Ÿงฌ for the Drug Discovery Community

Advanced Pharmaceutical AI for Next-Generation Drug Development

</div>