Skip to main content

python-chebifier

An AI ensemble model for predicting chemical classes in the ChEBI ontology. It integrates deep learning models, rule-based models and generative AI-based models.

A web application for Chebifier is available at https://chebifier.hastingslab.org/.

Installation

You can get the package from PyPI:

pip install chebifier[models]

If you want the barebones Chebifier without the base learners, run

pip install chebifier

(This is useful if you only need a subset of base learners)

or get the latest development version from GitHub:

# Clone the repository
git clone https://github.com/yourusername/python-chebifier.git
cd python-chebifier

# Install the package
pip install -e .[models]

The Graph Neural Networks depend on torch_geometric and torch_scatter which you need to install separately (depending on your CUDA version). E.g.

pip install torch==2.12.0 torch_scatter torch_geometric -f https://data.pyg.org/whl/torch-2.12.0+cpu.html

Usage

# Predict for one or more SMILES / InChI strings (default config: web)
python -m chebifier predict -m "CC(=O)OC1=CC=CC=C1C(=O)O" -m "C1=CC=C(C=C1)C(=O)O"

# Predict for molecules listed in a file (one SMILES / InChI per line)
python -m chebifier predict -f smiles.txt

# Use the eval ensemble, or your own configuration file
python -m chebifier predict -e eval -m "CC(=O)O"
python -m chebifier predict -e configs/my_config.yml -f smiles.txt

# Get all available options
python -m chebifier predict --help

Advanced CLI

The ensemble configuration is selected with --ensemble-config: web or eval (both downloaded from Hugging Face, web is the default) or a path to your own configuration file. Create your own file to change which models are included in the ensemble or how they are weighted.

Trained deep learning models are automatically downloaded from Hugging Face. To access a model from Hugging face, add the load_model key in your configuration file. For example:

my_gat:
  type: gat
  load_model: "gat-aug_chebi25-3star_v252"

Available model weights:

  • gat-aug_chebi25-3star_v252
  • gat_chebi25-3star_v252
  • gat-aug_chebi25_v252
  • gat_chebi25_v252
  • resgated-aug_chebi25-3star_v252
  • resgated_chebi25-3star_v252
  • resgated-aug_chebi25_v252
  • resgated_chebi25_v252
  • c3p_with_weights

You can also supply your own model checkpoints (see configs/example_config.yml for an example).

The base learners are selected with -e/--ensemble-config (default web). The deep learning base learners and the ensemble's calibration for the standard eval/web configs are downloaded from Hugging Face automatically on first use. To use a calibration of your own (e.g. one you built yourself, see below), pass its directory with -d/--ensemble-dir.

Python API

You can use the package programmatically as well:

from chebifier.cli import build_base_learners, build_ensemble_model
from chebifier.predict import predict
from chebifier.utils import download_ensemble_calibration

# Base learners from the "web" config ("eval" or a path to your own config also work).
base_learners = build_base_learners("web")
# download_ensemble_calibration() fetches the standard calibration from Hugging Face; pass your own
# directory instead to use a calibration you built yourself.
ensemble = build_ensemble_model("wmv-f1", download_ensemble_calibration(), "web")

smiles_list = ["CC(=O)OC1=CC=CC=C1C(=O)O", "C1=CC=C(C=C1)C(=O)O"]
result = predict(base_learners, ensemble, smiles_list)

# result["predicted_classes"] is the class column space; result["class_decisions"][i] is the
# per-class boolean decision for molecule i.
for i, smiles in enumerate(smiles_list):
    classes = [
        cls
        for cls, keep in zip(result["predicted_classes"], result["class_decisions"][i].tolist())
        if keep
    ]
    print(f"SMILES: {smiles}")
    print(f"Predicted classes: {classes}" if classes else "No predictions")

Ensemble strategies and inconsistency resolution

The strategy that turns the base learner predictions into one ensemble decision is chosen with -t/--ensemble-type:

  • mv — plain majority vote, every model counts equally.
  • wmv-conf — majority vote weighted by each model's self-reported confidence.
  • wmv-f1 — confidence weighting plus a per-class trust from each model's validation F1 (the default).
  • ltr — a learning-to-rank meta-model (LambdaMART) fitted on the validation split.
  • des — dynamic ensemble selection: per molecule, only the locally most competent models vote.

After a decision has been made for each class, the predictions are reconciled with the ChEBI hierarchy and its disjointness axioms. The method is chosen with -ir/--inconsistency-resolution (or disabled with --no-resolve-inconsistencies):

  • score-based — a confidence-based repair of hierarchy and disjointness violations (the default).
  • ilr-godel, ilr-lukasiewicz — iterative local refinement, repairing violations by fuzzy logic.
  • hex — HEX-graph constrained inference (a bounded approximation).

Both are described in more detail in The ensemble and Inconsistency resolution below.

Building your own ensemble

To run a new set of models or calibrate on your own data, build an ensemble on the ChEBI validation split. This writes the calibration (prediction thresholds, class-wise F1 scores, hyperparameters) into the ensemble directory, which predict and evaluate then read via -d:

python -m chebifier build -e configs/my_config.yml -t wmv-f1 -d my_ensemble --data-path <dataset>

The models

Currently, the following models are supported:

Model Description #Classes Publication Repository
electra A transformer-based deep learning model trained on ChEBI SMILES strings. 1,766/2,117* Glauer, Martin, et al., 2024: Chebifier: Automating semantic classification in ChEBI to accelerate data-driven discovery, Digital Discovery 3 (2024) 896-907 python-chebai
resgated A Residual Gated Graph Convolutional Network trained on ChEBI molecules. 1,766/2,117* Khedekar, Aditya Ganesh, 2026: Integrating Chemical Knowledge into Graph Neural Networks, Master Thesis python-chebai-graph
gat A Graph Attention Network trained on ChEBI molecules. 1,766/2,117* Khedekar, Aditya Ganesh, 2026: Integrating Chemical Knowledge into Graph Neural Networks, Master Thesis python-chebai-graph
chemlog_peptides A rule-based model specialised on peptide classes. 18 Flügel, Simon, et al., 2026: Defining Peptides in ChEBI, Jorunal of Cheminformatics chemlog-peptides
chemlog_element, chemlog_organox Extensions of ChemLog for classes that are defined either by the presence of a specific element or by the presence of an organic bond. 118 + 37 Flügel, Simon, et al., 2025: ChemLog: Making MSOL Viable for Ontological Classification and Learning, arXiv chemlog-extra
c3p A collection Chemical Classifier Programs, generated by LLMs based on the natural language definitions of ChEBI classes. 338 Mungall, Christopher J., et al., 2025: Chemical classification program synthesis using generative artificial intelligence, Journal of Cheminformatics c3p
lopster Rules for 36 ChEBI classes, focusing on classes that cannot be expressed in OWL 36 Magka, Despoina, et al., 2014: A rule-based ontological framework for the classification of molecules, Journal of Biomedical Semantics original implementation - Chebifier uses an updated version integrated into chemlog

In addition, Chebifier also includes a ChEBI lookup that automatically retrieves the ChEBI superclasses for a class matched by a SMILES string. This is not activated by default, but can be included by adding

chebi_lookup:
    type: chebi_lookup
    model_weight: 10 # optional

to your configuration file.

The ensemble

The ensemble collects per-class scores from every base learner and turns them into one decision per class, selected with -t/--ensemble-type. For an extended description, see Flügel, Simon, et al., 2025: Chebifier 2: An Ensemble for Chemistry.

ensemble architecture overview
Strategy How it works
mv Plain majority vote; every model that predicted a class counts equally.
wmv-conf Majority vote weighted by each model's confidence, i.e. how far its score sits from its calibrated decision threshold (scaled per side so a maximally confident positive and negative both count 1).
wmv-f1 (default) Confidence weighting plus a per-class trust term, the model's validation F1 raised to the power 6.25.
ltr A LambdaMART ranker (adapting GOLabeler) fitted on the validation split ranks classes per molecule from the base learner scores. Optionally adds per-class validation statistics as features (class_stats).
des Dynamic ensemble selection (adapting META-DES.H): a meta-classifier estimates each base learner's local competence per molecule, and only the competent ones vote.

Each model also carries a model_weight (configurable, default 1) that scales its vote independently of the class. ltr and des calibrate their hyperparameters by 5-fold cross-validation on the validation split; chebifier build takes their constructor arguments as -ep key=value. All strategies emit the same net score, so inconsistency resolution and the decision threshold apply unchanged.

Inconsistency resolution

After each class has been decided independently, the predictions are reconciled with the ChEBI hierarchy (is-a) and disjointness axioms (data/disjoint_chebi.csv and data/disjoint_additional.csv). The method is chosen with -ir/--inconsistency-resolution, or disabled with --no-resolve-inconsistencies; each consumes a net score and returns one, so the decision threshold applies unchanged.

Method How it works
score-based (default) Repairs hierarchy then disjointness violations by keeping the more confident class of each conflicting pair (confidence = distance from the decision threshold). A final hierarchy pass lowers children rather than raising parents, so no new disjointness conflicts appear.
ilr-godel Iterative Local Refinement (Daniele et al. 2023) with Gödel logic: each subsumption/disjointness constraint is repaired winner-take-all and iterated to a fixpoint.
ilr-lukasiewicz The same ILR framework with Łukasiewicz logic, which shares the correction between the two conflicting classes instead of winner-take-all (e.g. scores 0.8/0.7 become 0.55/0.45).
hex HEX-graph constrained inference (Deng et al. 2014). Exact inference is intractable on ChEBI's heavily overlapping labels, so this is a bounded branch-and-bound approximation whose intervals decide ties negatively.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chebifier-1.3.0.tar.gz (67.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chebifier-1.3.0-py3-none-any.whl (73.1 kB view details)

Uploaded Python 3

File details

Details for the file chebifier-1.3.0.tar.gz.

File metadata

  • Download URL: chebifier-1.3.0.tar.gz
  • Upload date:
  • Size: 67.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for chebifier-1.3.0.tar.gz
Algorithm Hash digest
SHA256 fcad501adfa01fd64bc77921e804bab740376ddc33c1813fba25073b03329b7d
MD5 f3a777a5a7abde33f08ab52be32d179b
BLAKE2b-256 75c6c4632aa89e856b905135f8d27e53bf1a39c1eb07979a1647d8ac49d30048

See more details on using hashes here.

Provenance

The following attestation bundles were made for chebifier-1.3.0.tar.gz:

Publisher: python-publish.yml on ChEB-AI/python-chebifier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chebifier-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: chebifier-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 73.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for chebifier-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f1d92f5bce382fe0e4883cc194441c509b60cf84d7d8f2023fe7e173a94b57e8
MD5 5967c0f89990da781ed635ac7fb14a1e
BLAKE2b-256 1e26d01cae5a95ff9486820f27fbc7e26bd7f1c381c633ca6436f7fd3521c358

See more details on using hashes here.

Provenance

The following attestation bundles were made for chebifier-1.3.0-py3-none-any.whl:

Publisher: python-publish.yml on ChEB-AI/python-chebifier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page