Choose a model¶
Start with the task you want to solve. Models accept molecular SMILES strings
and expose familiar fit, predict, encode, or generate methods.
Your task |
Start here |
What you provide |
|---|---|---|
Predict molecular properties |
SMILES and property labels |
|
Learn molecular representations |
Unlabeled SMILES |
|
Learn similarity embeddings |
SMILES, molecular-pair indices, and similarity labels |
|
Generate from molecular demonstrations |
SMILES, optional demonstration molecules, and normalized scores |
|
Generate with masked sequence diffusion |
SMILES; an optional scaffold at generation time |
|
Generate toward property values |
SMILES and property labels |
|
Use a pretrained checkpoint |
|
A supported Hugging Face checkpoint identifier |
Explore the full model families in the Predictor API, Encoder API, and Generator API references.
Inputs and outputs¶
X_train is normally a list of SMILES strings. Property labels use a numerical
array with one row per molecule and one column per task.
Workflow |
Training |
Inference |
|---|---|---|
Property prediction |
|
|
Representation learning |
|
|
Unconditional generation |
|
|
SAND similarity learning |
|
|
DemoDiff with demonstrations |
|
|
Method-specific inputs are described in each model’s API reference. For example,
SAND needs at least two molecular pairs with nonconstant similarity labels.
DemoDiff uses demonstration scores in [0, 1] and a target score of 1;
higher values mean closer to the target. During training its contexts are
indices into X_train; during generation they are SMILES strings.
Training and pretrained models¶
Trainable models such as AttrMask, SAND, GenMol, and DemoDiff initialize a new
model through fit. Loading a saved checkpoint is a separate operation.
The Hugging Face pretrained wrappers use fit() to load their selected
checkpoint; they do not train a new model with that call.
Set architecture and training options in the constructor. Use get_params()
to inspect an estimator’s settings and set_params() to update them before
training. Consult the class reference for its supported settings.
Save and load¶
Save a fitted model with save_to_local(path). Construct the same model class
and call load_from_local(path) to restore it, then run inference directly.
Do not call fit again if you want to keep the loaded weights.
from pathlib import Path
from torch_molecule import GNNMolecularPredictor
# predictor is the fitted model from the quickstart.
output = Path("checkpoints")
output.mkdir(parents=True, exist_ok=True)
predictor.save_to_local(str(output / "gnn.pt"))
restored = GNNMolecularPredictor(device="cpu")
restored.load_from_local(str(output / "gnn.pt"))
prediction = restored.predict(["CCO"])["prediction"]
See Quickstart for the complete training example and Base Modules for local and Hugging Face checkpoint methods.