Sonja Topf
initial commit
f484830
|
raw
history blame
2.84 kB
metadata
title: Tox21 GIN Classifier
emoji: 🤖
colorFrom: green
colorTo: blue
sdk: docker
pinned: false
license: apache-2.0
short_description: Graph Isomorphism Network

Tox21 Graph Isomorphism Network Classifier

This repository hosts a Hugging Face Space that provides an examplary API for submitting models to the Tox21 Leaderboard.

In this example, we trained a GIN classifier on the Tox21 targets and saved the trained model in the assets/ folder.

Important: For leaderboard submission, your Space does not need to include training code. It only needs to implement inference in the predict() function inside predict.py. The predict() function must keep the provided skeleton: it should take a list of SMILES strings as input and return a nested prediction dictionary as output, with SMILES as keys and dictionaries containing targetname-prediction pairs as values. Therefore, any preprocessing of SMILES strings must be executed on-the-fly during inference.

Repository Structure

  • predict.py - Defines the predict() function required by the leaderboard (entry point for inference).

  • app.py - FastAPI application wrapper (can be used as-is).

  • src/ - Core model & preprocessing logic:

    • preprocess.py - SMILES preprocessing pipeline
    • model.py - GIN classifier
    • seed.py - used to ensure reproducibility

Quickstart with Spaces

You can easily adapt this project in your own Hugging Face account:

  • Open this Space on Hugging Face.

  • Click "Duplicate this Space" (top-right corner).

  • Modify src/ for your preprocessing pipeline and model class

  • Modify predict() inside predict.py to perform model inference while keeping the function skeleton unchanged to remain compatible with the leaderboard.

That’s it, your model will be available as an API endpoint for the Tox21 Leaderboard.

Installation

To run the GIN classifier, clone the repository and install dependencies:

git clone https://huggingface.co/spaces/tschouis/tox21_gin_classifier
cd tox21_gin_classifier
pip install -r requirements.txt

Inference

For inference, you only need predict.py.

Example usage inside Python:

from predict import predict

smiles_list = ["CCO", "c1ccccc1", "CC(=O)O"]
results = predict(smiles_list)

print(results)

The output will be a nested dictionary in the format:

{
    "CCO": {"target1": 0, "target2": 1, ..., "target12": 0},
    "c1ccccc1": {"target1": 1, "target2": 0, ..., "target12": 1},
    "CC(=O)O": {"target1": 0, "target2": 0, ..., "target12": 0}
}

Notes

  • Only adapting predict.py for your model inference is required for leaderboard submission.

  • Preprocessing (here inside src/preprocess.py) must be applied at inference time, not just predicting.