Use when when pre-training a graph neural network on a domain-specific
Scanned 9/12/2026
Install to Claude Code
npx -y skills add HolobiomicsLab/asb-skill-collections --skill contrastive-learning-objective-formulation --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Contrastive Learning Objective Formulation?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/holobiomicslab-contrastive-learning-objective-formulation)More formats (shields.io, HTML) on the badges page.
---
name: contrastive-learning-objective-formulation
description: Use when when pre-training a graph neural network on a domain-specific
molecular corpus (natural products vs. synthetic molecules) where you need to capture
both evolutionary relationships encoded in molecular scaffolds and diverse structural
variations in side-chains, and when supervised learning.
license: CC-BY-4.0
metadata:
edam_operation: http://edamontology.org/operation_3800
edam_topics:
- http://edamontology.org/topic_3314
- http://edamontology.org/topic_0154
- http://edamontology.org/topic_3379
tools:
- Git
- PyTorch or equivalent deep learning framework (inferred from GNN/contrastive learning
context)
- PyTorch
- PyTorch Lightning
- PyTorch Geometric (PyG)
- NaFM (github.com/TomAIDD/NaFM-Official)
license_tier: restricted
provenance_tier: literature
derived_from:
- doi: 10.1002/anie.202507483
title: NA
evidence_spans:
- Fork the repository
- Our method integrates contrastive learning with masked graph modeling
claims: []
provenance:
collection: https://w3id.org/holobiomicslab/asb-skill/collection/metabolomics/v2
assembled_by: scripts/collect_metabolomics_collection.py
sources:
- build: coll_nafm_cq
doi: 10.1002/anie.202507483
title: NA
dedup_kept_from: coll_nafm_cq
schema_version: 0.2.0
attribution:
generator: AgenticScienceBuilder
original_doi: 10.1002/anie.202507483
all_source_dois:
- 10.1002/anie.202507483
zenodo_doi: 10.5281/zenodo.20794027
curators: []
promoter: Louis-Félix Nothias
sponsor: CNRS & Université Côte d'Azur
---
# contrastive-learning-objective-formulation
> **License: restricted** — no clear open-source license detected for the underlying tool; verify licensing before commercial use or redistribution. <!-- asb-license-banner -->
## Summary
Formulate and integrate contrastive learning objectives into a foundation model's pre-training pipeline to encode scaffold-derived evolutionary patterns and structural diversity in natural product molecules. This skill involves specifying the contrastive loss function, defining positive/negative pair sampling strategies, and unifying the contrastive objective with complementary pre-training tasks like masked graph modeling.
## When to use
When pre-training a graph neural network on a domain-specific molecular corpus (natural products vs. synthetic molecules) where you need to capture both evolutionary relationships encoded in molecular scaffolds and diverse structural variations in side-chains, and when supervised learning on individual downstream tasks lacks generalization. Apply this skill if your training data includes structural families (e.g., microbial, plant-derived) and you want the model to learn invariant representations across evolutionary context.
## When NOT to use
- Input molecules lack evolutionary or structural metadata linking them to a taxonomic/phylogenetic hierarchy; contrastive learning requires meaningful positive/negative pair definitions.
- Downstream task requires supervised fine-tuning only on a single well-defined dataset; contrastive pre-training is unnecessary if domain-specific labeled data is abundant and diverse enough.
- Molecular graphs do not encode sufficient structural diversity within scaffold families; contrastive learning assumes multiple side-chain or functional group variations on the same scaffold.
## Inputs
- SMILES strings or molecular graphs in pickle or CSV format (e.g., pretrain_smiles.pkl)
- Molecular graph representations (nodes = atoms, edges = bonds)
- Scaffold annotations or evolutionary/taxonomic metadata linking molecules to their biological origin
- Pre-training configuration file (YAML) specifying contrastive loss weight, temperature, batch size
## Outputs
- Pre-trained model checkpoint (PyTorch Lightning .ckpt file) with learned embeddings
- Contrastive loss curve over training epochs
- Embedding vectors in fixed-dimensional space (e.g., 1024-dimensional) for downstream fine-tuning
- Validation metrics showing clustering quality by taxonomy/scaffold family
## How to apply
Parse the model architecture from the NaFM repository to extract the contrastive loss formulation and its parameters (temperature scaling, similarity metric). Define positive pairs as scaffold-similar molecules (e.g., same phylogenetic origin or scaffold family) and negative pairs as molecules outside that evolutionary context. Compute the contrastive loss using a temperature-scaled similarity function (typically cosine or dot-product in embedding space). Integrate this objective as a weighted term in the unified pre-training loss function alongside masked graph modeling loss using a fixed control loop: data loading → graph construction → feature embedding → contrastive loss computation → gradient updates. Validate that the learned embeddings cluster molecules by taxonomy/scaffold family and that downstream tasks (taxonomy classification, bioactivity regression) benefit from the pre-trained representations relative to models trained on synthetic molecules.
## Related tools
- **PyTorch** (Deep learning framework for implementing contrastive loss computation, gradient updates, and model training loop)
- **PyTorch Lightning** (High-level training harness for managing pre-training epochs, checkpointing, and distributed training of the contrastive objective)
- **PyTorch Geometric (PyG)** (Graph neural network library for constructing molecular graph representations and aggregating node/edge features used in contrastive embeddings) — https://data.pyg.org/whl/torch-2.4.0+cu121.html
- **NaFM (github.com/TomAIDD/NaFM-Official)** (Reference implementation containing model architecture, contrastive loss formulation, and integration with masked graph modeling objective) — github.com/TomAIDD/NaFM-Official
## Examples
```
python train.py --conf examples/Pretrain.yml
```
## Evaluation signals
- Verify contrastive loss decreases monotonically over training epochs and converges to a stable value, indicating the model is learning to separate positive and negative pairs.
- Confirm that learned molecular embeddings cluster by taxonomy (e.g., microbial vs. plant-derived) or scaffold family; measure clustering quality using silhouette score or Davies-Bouldin index on held-out taxonomy labels.
- Benchmark downstream task performance (e.g., taxonomy classification accuracy, regression R²) using the pre-trained model vs. random initialization or models pre-trained only on synthetic molecules; expect ≥5–10% relative improvement.
- Inspect embedding space via t-SNE or UMAP visualization; molecules from the same evolutionary origin should form coherent clusters separate from other origins.
- Validate that the contrastive pre-training does not overfit to the training scaffold families by testing generalization on external molecules with novel scaffolds; performance should remain above baseline.
## Limitations
- Contrastive learning effectiveness depends critically on accurate positive/negative pair definitions; if taxonomic or evolutionary metadata is unreliable or sparse, the model may learn spurious scaffold associations.
- The method assumes sufficient structural diversity within scaffold families (side-chain variations); sparse or uniform scaffolds may result in uninformative positive pairs and poor contrastive signal.
- Models pre-trained on synthetic molecules show inadequacy for capturing natural synthesis patterns, but this limitation is specific to non-natural product datasets; generalization to other molecular domains (e.g., drug-like compounds, peptides) is not established.
- The unified loss function balances contrastive and masked graph modeling objectives; improper weighting can cause one objective to dominate, reducing the contribution of evolutionary pattern learning.
## Evidence
- [intro] Our method integrates contrastive learning with masked graph modeling, effectively encoding scaffold-derived evolutionary patterns alongside diverse side-chain information: "Our method integrates contrastive learning with masked graph modeling, effectively encoding scaffold-derived evolutionary patterns alongside diverse side-chain information"
- [other] NaFM's pre-training framework combines contrastive learning with masked graph modeling as complementary objectives that together encode both scaffold-derived evolutionary patterns and diverse side-chain information from natural product structures.: "NaFM's pre-training framework combines contrastive learning with masked graph modeling as complementary objectives that together encode both scaffold-derived evolutionary patterns and diverse"
- [intro] most deep learning approaches in natural product research are based on supervised learning tailored to specific downstream tasks. However, the one-model-one-task paradigm often lacks generalization: "most deep learning approaches in natural product research are based on supervised learning tailored to specific downstream tasks. However, the one-model-one-task paradigm often lacks generalization"
- [intro] We first benchmark NaFM on taxonomy classification against models pre-trained on synthetic molecules, demonstrating their inadequacy for capturing natural synthesis patterns: "We first benchmark NaFM on taxonomy classification against models pre-trained on synthetic molecules, demonstrating their inadequacy for capturing natural synthesis patterns"
- [intro] Through detailed analysis at both gene and microbial levels, NaFM reveals a strong capacity for learning evolutionary information: "Through detailed analysis at both gene and microbial levels, NaFM reveals a strong capacity for learning evolutionary information"
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!