Skip to main content

MET molecular embeddings and fine-tuning library.

Project description

mint258-met

mint258-met packages the fine-tuning-facing part of MET as an installable Python library.

The package focuses on:

  • loading the released MET pretrained encoder from Hugging Face
  • producing atom-level embeddings with shape [N, D]
  • fine-tuning on user CSV or XYZ data with built-in dataloaders
  • exposing both a default prediction head and custom-head injection
  • controlling which encoder blocks remain trainable during fine-tuning

Install

pip install mint258-met

For local development inside this repository:

pip install -e ./PyPI

Core APIs

from met import METEncoder, METFineTuner

Atom Embeddings

encoder = METEncoder.from_pretrained()
atom_embeddings = encoder.embed_smiles("CCO", num_conformers=4)
print(atom_embeddings.shape)  # [N, D]

METEncoder returns atom-level embeddings with shape [N, D], where N is the number of atoms and D is the MET embedding dimension from the pretrained checkpoint.

Supported encoder convenience methods:

  • embed_smiles(smiles, ...)
  • embed_xyz(path, ...)
  • embed_smiles_batch(smiles_list, ...)
  • embed_data(batch_or_graph)

Fine-Tuning

model = METFineTuner.from_pretrained(
    output_dim=1,
    hidden_dim=256,
    layers=2,
    dropout=0.1,
    pooling_time="after_last_layer",
    pooling_method="attention",
    normalization="layernorm",
)

model.set_trainable_encoder_blocks(trainable_blocks=1)

history = model.fit_csv(
    csv_path="my_dataset.csv",
    target_columns=["target"],
    smiles_column="smiles",
    num_conformers=8,
    epochs=5,
    batch_size=8,
)

Default Prediction Head

The default head is controlled by the following arguments in METFineTuner.from_pretrained(...) or build_default_head(...):

  • output_dim: number of downstream targets
  • hidden_dim: hidden width used by the default head
  • layers: number of feed-forward blocks
  • dropout: dropout used inside the default head
  • pooling_time: "before_head" or "after_last_layer"
  • pooling_method: "attention", "mean", "sum", or "max"
  • normalization: None, "layernorm", or "batchnorm"

pooling_time="after_last_layer" means node embeddings are transformed first and pooled at the end.
pooling_time="before_head" means raw node embeddings are pooled first and the graph representation is processed afterward.

Choosing Trainable Encoder Layers

METFineTuner exposes three layer-control styles:

  • freeze_encoder(): train only the downstream head
  • unfreeze_encoder(): fine-tune the full backbone
  • set_trainable_encoder_blocks(trainable_blocks=...): unfreeze the last k interaction blocks plus optional projection layers
  • set_trainable_modules([...]): explicitly unfreeze named encoder modules

You can inspect available module names with:

print(model.list_encoder_modules())

Custom Prediction Heads

If you want to replace the default head, pass a custom torch.nn.Module to METFineTuner.from_pretrained(head=...) or later call replace_head(...).

The custom head should accept:

  • node_embeddings: shape [batch, max_nodes, dim]
  • mask: shape [batch, max_nodes]

and return:

  • predictions of shape [batch, output_dim]

Built-In Fine-Tuning Helpers

For downstream work the package provides:

  • fit_csv(...)
  • fit_xyz(...)
  • fit_dataset(...)
  • predict_csv(...)
  • predict_xyz(...)
  • predict_smiles(...)
  • evaluate_csv(...)
  • evaluate_xyz(...)
  • evaluate_dataset(...)

CSV Example

from met import METFineTuner

model = METFineTuner.from_pretrained(
    output_dim=2,
    hidden_dim=256,
    layers=3,
    dropout=0.1,
    pooling_time="after_last_layer",
    pooling_method="attention",
    normalization="layernorm",
)

model.set_trainable_encoder_blocks(trainable_blocks=2)

history = model.fit_csv(
    csv_path="downstream.csv",
    smiles_column="smiles",
    target_columns=["property_a", "property_b"],
    num_conformers=8,
    conformer_seed=2024,
    use_uff_optimization=True,
    epochs=10,
    batch_size=16,
    learning_rate=1e-4,
)

XYZ Example

from met import METFineTuner

model = METFineTuner.from_pretrained(output_dim=1)
model.set_trainable_encoder_blocks(trainable_blocks=1)

history = model.fit_xyz(
    root="data/QM7/train_database_300",
    target_columns=["atomization_energy"],
    epochs=5,
    batch_size=8,
)

Hugging Face Assets

  • Dataset: https://huggingface.co/datasets/Mint258/MET-dateset
  • Models: https://huggingface.co/Mint258/MET-models

Project Links

  • GitHub: https://github.com/mint258/MET
  • Paper DOI: https://doi.org/10.1039/D5ME00173K

Project details


Download files

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

Source Distribution

mint258_met-0.1.0.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

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

mint258_met-0.1.0-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file mint258_met-0.1.0.tar.gz.

File metadata

  • Download URL: mint258_met-0.1.0.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for mint258_met-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6deab1e26d0e92332a2b533a17a065c1c1c8a890c7d930d20677098abb778fca
MD5 dac0c8dc393cb8abdfa3fbd6e024792b
BLAKE2b-256 350832ac6a62650758fc800458c57eb1f9794f7ef102beafaef2a3d4bfe3990c

See more details on using hashes here.

File details

Details for the file mint258_met-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mint258_met-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for mint258_met-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3dc888a89ea0b7238bdea6d27fd13bc36c7b22cefec9f47db92616939bffd8f8
MD5 1177b632cf18d52da5093587355d3135
BLAKE2b-256 82c6c8f99795452de173525ab730ac662507191296c23371c3eeae3a4897f478

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page