DicongLi 7eff2b3d02 feat: 支持 MolFormer/GraphMVP/GROVER 离线 embedding 作为化学 token
三个预训练分子编码器作为额外的 chemical token 接入(三选一,互斥):
- MolFormer-XL 768d(SMILES 序列,11亿分子预训练)
- GraphMVP 300d(2D 图自监督,ICLR'22)
- GROVER 3200d(图 Transformer,NeurIPS'20)

实现:embedding 离线编码存 npy,模型内按 {smiles: vector} 查表注入,
不改动前向逻辑,默认全关、不影响既有实验。

- models.py: 新增三个 CHEM_KEYS_WITH_*、统一的 _load_offline_emb 查表、
  proj_input_dims 按开关裁剪、forward 注入;子类同步转发参数
- nested_cv_optuna.py / pretrain.py: 新增 --{molformer,graphmvp,grover}-emb/-csv
- scripts_run/encode_embeddings/: 三个离线编码脚本 + README(含权重来源与
  新旧环境兼容补丁说明)
- results/pretrained_encoders/: 五组 15 折结果 summary
  (trials15/inner3/repeats3/seed42, 均带 external 预训练)

注:npy embedding 与预训练权重未入库(可由编码脚本复现)
2026-07-23 20:18:53 +08:00
2026-03-04 17:14:36 +08:00
2026-03-02 14:51:54 +08:00
2026-01-18 21:50:21 +08:00
2026-01-18 21:50:21 +08:00
2026-01-18 21:50:21 +08:00
2026-02-11 16:45:21 +08:00
2026-01-18 21:50:21 +08:00
2026-03-02 14:51:54 +08:00
2026-02-11 16:49:28 +08:00
2026-02-11 16:49:28 +08:00
2026-01-18 21:50:21 +08:00
2026-01-25 23:54:20 +08:00

lnp-ml

LNP脂质纳米颗粒药物递送性能预测模型。

快速开始

1. 安装环境

pixi install
pixi shell

2. 数据处理

# 清洗原始数据 (raw -> interim)
make clean_data

# 处理内部数据集 (interim -> processed)
make data

# 处理外部预训练数据 (external -> processed)
make data_pretrain

3. 训练模型

方式 A直接训练从零开始

make train

方式 B预训练 + 微调(推荐)

利用外部 LiON 数据集(约 9000 条)进行预训练,再在内部数据上微调:

# Step 1: 处理外部数据
make data_pretrain

# Step 2: 在外部数据上预训练 backbone + delivery head
make pretrain

# Step 3: 加载预训练权重,在内部数据上多任务微调
make finetune

方式 C超参数调优

make tune

4. 测试与预测

# 在测试集上评估
make test

# 生成预测结果
make predict

训练流程详解

预训练 (Pretrain)

在外部 LiON 数据上,仅训练 quantified_delivery 任务:

# 1. 先处理外部数据
python scripts/process_external.py

# 2. 预训练
python -m lnp_ml.modeling.pretrain \
    --train-path data/processed/train_pretrain.parquet \
    --val-path data/processed/val_pretrain.parquet \
    --epochs 50 \
    --lr 1e-4

产出:

  • data/processed/train_pretrain.parquet: 处理后的训练数据
  • data/processed/val_pretrain.parquet: 处理后的验证数据
  • models/pretrain_delivery.pt: backbone + delivery head 权重
  • models/pretrain_history.json: 训练历史

微调 (Finetune)

加载预训练权重,在内部多任务数据上训练:

python -m lnp_ml.modeling.train \
    --init-from-pretrain models/pretrain_delivery.pt \
    --load-delivery-head  # 可选:是否加载 delivery head 权重

产出:

  • models/model.pt: 完整模型权重
  • models/history.json: 训练历史

Project Organization

├── LICENSE            <- Open-source license if one is chosen
├── Makefile           <- Makefile with convenience commands like `make data` or `make train`
├── README.md          <- The top-level README for developers using this project.
├── data
│   ├── external       <- Data from third party sources.
│   ├── interim        <- Intermediate data that has been transformed.
│   ├── processed      <- The final, canonical data sets for modeling.
│   └── raw            <- The original, immutable data dump.
│
├── docs               <- A default mkdocs project; see www.mkdocs.org for details
│
├── models             <- Trained and serialized models, model predictions, or model summaries
│
├── notebooks          <- Jupyter notebooks. Naming convention is a number (for ordering),
│                         the creator's initials, and a short `-` delimited description, e.g.
│                         `1.0-jqp-initial-data-exploration`.
│
├── pyproject.toml     <- Project configuration file with package metadata for 
│                         lnp_ml and configuration for tools like black
│
├── references         <- Data dictionaries, manuals, and all other explanatory materials.
│
├── reports            <- Generated analysis as HTML, PDF, LaTeX, etc.
│   └── figures        <- Generated graphics and figures to be used in reporting
│
├── requirements.txt   <- The requirements file for reproducing the analysis environment, e.g.
│                         generated with `pip freeze > requirements.txt`
│
├── setup.cfg          <- Configuration file for flake8
│
└── lnp_ml   <- Source code for use in this project.
    │
    ├── __init__.py             <- Makes lnp_ml a Python module
    │
    ├── config.py               <- Store useful variables and configuration
    │
    ├── dataset.py              <- Scripts to download or generate data
    │
    ├── features.py             <- Code to create features for modeling
    │
    ├── modeling                
    │   ├── __init__.py 
    │   ├── predict.py          <- Code to run model inference with trained models          
    │   └── train.py            <- Code to train models
    │
    └── plots.py                <- Code to create visualizations

配方筛选

make optimize SMILES="CC(C)NCCNC(C)C" ORGAN=liver

Description
No description provided
Readme MIT 3.2 GiB
Languages
Python 96.4%
Makefile 2.8%
Shell 0.4%
Dockerfile 0.4%