---
name: transfer-learning-fine-tuning
description: Use when you have collected liquid chromatography (LC) spectra and retention time labels for your in-house molecular database, and you want to leverage a pretrained GNN-RT model rather than train from scratch.
license: CC-BY-4.0
metadata:
  edam_operation: http://edamontology.org/operation_3445
  edam_topics:
  - http://edamontology.org/topic_3474
  - http://edamontology.org/topic_0154
  - http://edamontology.org/topic_3407
  tools:
  - Python
  - Anaconda
  - Transferlearning.py
  - Preprocess.py
  - PyTorch
  - RDKit
  techniques:
  - LC-MS
derived_from:
- doi: 10.1021/acs.analchem.0c04071
  title: GNN-RT
evidence_spans:
- Anaconda for python 3.6
claims: []
provenance:
  collection: https://w3id.org/holobiomicslab/asb-skill/collection/metabolomics/v2
  assembled_by: scripts/collect_metabolomics_collection.py
  sources:
  - build: coll_gnn_rt_cq
    doi: 10.1021/acs.analchem.0c04071
    title: GNN-RT
  dedup_kept_from: coll_gnn_rt_cq
schema_version: 0.2.0
attribution:
  generator: AgenticScienceBuilder
  original_doi: 10.1021/acs.analchem.0c04071
  all_source_dois:
  - 10.1021/acs.analchem.0c04071
  zenodo_doi: 10.5281/zenodo.20794027
  curators: []
  promoter: Louis-Félix Nothias
  sponsor: CNRS & Université Côte d'Azur
---

# Transfer-Learning Fine-Tuning

## Summary

Adapt a pretrained Graph Neural Network (GNN-RT) model to a new in-house molecular database by fine-tuning learned GNN weights on target data while preserving pretrained representations. This skill is essential when you have a pretrained model trained on a reference LC retention time dataset but need to improve prediction accuracy on your own molecular spectra.

## When to use

You have collected liquid chromatography (LC) spectra and retention time labels for your in-house molecular database, and you want to leverage a pretrained GNN-RT model rather than train from scratch. This is appropriate when your target database is smaller than or structurally similar to the pretraining dataset, allowing transfer learning to improve generalization and reduce training time.

## When NOT to use

- Your in-house dataset is very large (>100k molecules) and structurally very different from the pretraining data; full retraining may be more appropriate than transfer learning.
- You do not have a pretrained GNN-RT model available; use Train.py to train from scratch instead.
- Your retention time measurements are unreliable or missing for a significant fraction of molecules; preprocessing and validation must occur before fine-tuning.

## Inputs

- LC spectra files (raw instrumental data in data directory)
- Corresponding retention time measurements for in-house molecules
- Pretrained GNN-RT model checkpoint (PyTorch .pt or equivalent)

## Outputs

- Fine-tuned GNN-RT model weights adapted to in-house database
- Validation set prediction accuracy and loss metrics
- Predicted retention times for validation/test molecules

## How to apply

First, place your raw spectra files in the data directory and run Preprocess.py to standardize molecular graphs and retention time labels using RDKit. Load the pretrained GNN-RT model in PyTorch and configure transfer-learning hyperparameters (learning rate, batch size, number of epochs). Run Transferlearning.py to fine-tune the pretrained GNN weights on your target database. Finally, evaluate the adapted model on a held-out validation set from the target database and compare prediction accuracy and loss metrics to a baseline (e.g., the pretrained model without fine-tuning or the original reference dataset performance).

## Related tools

- **Transferlearning.py** (Execute fine-tuning of pretrained GNN weights on target in-house database) — https://github.com/Qiong-Yang/GNN-RT
- **Preprocess.py** (Standardize raw spectra files and generate molecular graphs and retention time labels) — https://github.com/Qiong-Yang/GNN-RT
- **PyTorch** (Load, configure, and fine-tune the pretrained GNN-RT model)
- **RDKit** (Generate standardized molecular graph representations during preprocessing)

## Examples

```
python Preprocess.py && python Transferlearning.py --pretrained_model GNN-RT_pretrained.pt --epochs 50 --learning_rate 0.001
```

## Evaluation signals

- Validation loss on held-out test set from target database decreases with fine-tuning iterations (compared to pretrained model without adaptation).
- Prediction accuracy (e.g., mean absolute error or R² of predicted vs. observed retention times) on target database validation set meets or exceeds a predefined threshold (article does not specify a numerical target).
- Fine-tuned model outperforms the original pretrained model on target database molecules (cross-validation comparison).
- Preprocessed molecular graphs are successfully generated by Preprocess.py (standardized node/edge counts, RDKit-compatible canonical SMILES).
- Transfer-learned weights are distinct from the pretrained weights (Layer-wise weight divergence or loss landscape visualization would confirm adaptation).

## Limitations

- Transfer learning assumes sufficient structural and experimental overlap between the pretraining dataset and the in-house database; if the target molecules are very different (e.g., different solvent, pH, temperature regime), fine-tuning may not improve accuracy.
- The article provides no guidance on optimal transfer-learning hyperparameters (learning rate, number of fine-tuning epochs, layer freezing strategy); practitioners must tune these empirically.
- No changelog or version history is available to track model updates or improvements, making reproducibility and version management challenging.
- The README does not specify minimum dataset size for in-house database or expected improvement magnitude; practitioners should benchmark against the pretrained baseline.

## Evidence

- [intro] The transfer-learning workflow requires three sequential steps: (1) place spectra files in the data directory, (2) run Preprocess.py to prepare the data, (3) run Train.py to train the model, and (4) run Transferlearning.py to apply transfer learning to the in-house database.: "place spectra files in the data directory, (2) run Preprocess.py to prepare the data, (3) run Train.py to train the model, and (4) run Transferlearning.py to apply transfer learning"
- [intro] Prepare the user-supplied database using Preprocess.py to generate standardized molecular graphs and retention time labels. Load the pretrained GNN-RT model in PyTorch and configure transfer-learning hyperparameters. Run Transferlearning.py to fine-tune the pretrained GNN weights on the target database. Evaluate the adapted model on a held-out validation set from the target database and record prediction accuracy and loss metrics.: "Prepare the user-supplied database using Preprocess.py to generate standardized molecular graphs and retention time labels. Load the pretrained GNN-RT model in PyTorch and configure transfer-learning"
- [readme] The GNN-RT can obtain the data-driven representations of molecules through the end-to-end learning with GNN, and predict the retention time with the GNN-learned representations.: "The GNN-RT can obtain the data-driven representations of molecules through the end-to-end learning with GNN, and predict the retention time with the GNN-learned representations."
- [readme] If you want to train a model based on your in-house database, please put your spectra files in to **data** directory and run [Preprocess.py], [Train.py] and [Transferlearning.py]: "put your spectra files in to **data** directory and run [Preprocess.py], [Train.py] and [Transferlearning.py]"
- [readme] Liquid chromatography (LC) retention time prediction is increasingly getting attention in identification of small molecules, since it supplies information orthogonal to (tandem) MS data for small molecule identification.: "Liquid chromatography (LC) retention time prediction is increasingly getting attention in identification of small molecules"
