Skip to main content

🚄 lchemme

GitHub Workflow Status (with branch) PyPI - Python Version PyPI

Pretraining large chemistry models for embedding.

Installation

The easy way

Install the pre-compiled version from PyPI:

pip install lchemme

From source

Clone the repository, then cd into it. Then run:

pip install -e .

Command-line usage

lchemme provides command-line utlities to pre-train BART models.

To get a list of commands (tools), do

$ lchemme --help
usage: lchemme [-h] [--version] {tokenize,pretrain,featurize} ...

Training and applying large chemistry models.

options:
  -h, --help            show this help message and exit
  --version, -v         show program's version number and exit

Sub-commands:
  {tokenize,pretrain,featurize}
                        Use these commands to specify the tool you want to use.
    tokenize            Tokenize the data inputs.
    pretrain            Pre-train a large language model using self-supervised learning.
    featurize           Get vector embeddings of a chemical dataset using a pre-trained large language model.

And to get help for a specific command, do

$ lchemme <command> --help

Tokenizing

The first step is to build a tokenizer for your dataset. LChemME works with BART models, and pulls their architecture from the Hugging Face Hub or a local directory. Training data can also be pulled from Hugging Face Hub with the hf:// prefix, or it can be loaded from local CSV files with a column containing SMILES strings.

lchemme tokenize \
    --train hf://scbirlab/fang-2023-biogen-adme@scaffold-split:train \
    --column smiles \
    --model facebook/bart-base \
    --output my-model

This should be relatively fast, but could take several hours for millions of rows.

In principle, existing tokenizers trained on natural language could work, but they have much larger vocabularies which are largely unused in SMILES.

Model pretraining

LChemME performs semi-supervised pretraining on a SMILES canonicalization task. This requires an understanding of chemical connectivity and atom precedence rules, forcing the model to build an internal representation of the chemical graph.

lchemme pretrain \
    --train hf://scbirlab/fang-2023-biogen-adme@scaffold-split:train \
    --column smiles \
    --test hf://scbirlab/fang-2023-biogen-adme@scaffold-split:test \
    --model facebook/bart-base \
    --tokenizer my-model \
    --epochs 0.5 \
    --output my-model \
    --plot my-model/training-log

If you want to continue training, you can do so with the --resume flag.

lchemme pretrain \
    --train hf://scbirlab/fang-2023-biogen-adme@scaffold-split:train \
    --column smiles \
    --test hf://scbirlab/fang-2023-biogen-adme@scaffold-split:test \
    --model my-model \
    --epochs 0.5 \
    --output my-model \
    --plot my-model/training-log \
    --resume

The dataset state can only be restored if the --model was trained with LChemME and the dataset configuration is identical, i.e. --train, --column are the same.

Featurizing

With a trained model, you can generate embeddings of your chemical datasets, optionally with UMAP plots colored by chemical properties.

lchemme featurize \
    --train hf://scbirlab/fang-2023-biogen-adme@scaffold-split:train \
    --column smiles \
    --model my-model \
    --batch-size 16 \
    --method mean \
    --plot umap \
> featurized.csv

You can specify one or several aggregation functions with --method. LChemME aggregates the sequence dimension of the encoder and decoder, then concatenates them.

If you want to use additional columns containing numerical values to color the UMAP plots, provide the column names under --extras.

Documentation

(Full API documentation to come at ReadTheDocs.)

Metadata

Release files for lchemme 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lchemme 0.0.3
File Size Uploaded Provenance Actions
lchemme-0.0.3.tar.gz 21.3 kB Without provenance Details for lchemme-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lchemme 0.0.3
File Interpreter ABI Platform Actions
lchemme-0.0.3-py3-none-any.whl Python 3 none any Details for lchemme-0.0.3-py3-none-any.whl

Total release size: 43.8 kB

Release files / lchemme-0.0.3.tar.gz

Download URL lchemme-0.0.3.tar.gz
Size 21.3 kB
Tags Source
SHA-256 checksum
How to use checksums
61771ee1696666d9da98d8fa2a7f5294c03aec598b55e94b1d757981553e44a7
BLAKE2b-256 checksum
How to use checksums
6280383e7436d29bfd6f1116052e11652bd0e7d8dbe96c5b03dc4ed210b46fab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / lchemme-0.0.3-py3-none-any.whl

Download URL lchemme-0.0.3-py3-none-any.whl
Size 22.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04e7cfd70306b866c217424d415f1efa8f2855b1d4963c21a0e96a6ae1867ca8
BLAKE2b-256 checksum
How to use checksums
9ca3bcb6ab1e64525745f0b6c71cd5cef3e4f1afc9ffb86e80a081c1488d84a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Security for lchemme 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page