Skip to main content

Overview

ChemLactica uses a specialized tokenizer designed for molecular SMILES strings and chemical property annotations. The tokenizer includes:
  • Standard BPE (Byte Pair Encoding) for SMILES
  • Special tokens for molecular properties
  • Custom tokens for chemical descriptors

Tokenizer Architecture

Available Tokenizers

ChemLactica provides several pre-configured tokenizers:
ChemLacticaTokenizer66 is recommended for most tasks as it includes comprehensive chemical property tokens.

Configuration

Tokenizer configuration is defined in tokenizer_config.json:
tokenizer_config.json

Special Tokens

ChemLactica uses extensive special tokens for chemical annotations:

Core Tokens

  • <s>: Beginning of sequence token
  • </s>: End of sequence token (also used as separator)
  • <pad>: Padding token for batch processing

Molecular Structure Tokens

Usage:

Property Tokens

Chemical properties are enclosed in specific tokens:
Property Tokens
Common Properties:
float
Quantitative Estimate of Drug-likeness (0-1)
float
Synthetic Accessibility Score (1-10)
float
Molecular weight in g/mol
float
Topological Polar Surface Area
float
Calculated LogP (lipophilicity)

Custom Property Tokens

For domain-specific properties:
Example:

Loading the Tokenizer

Basic Usage

With Padding

Always use padding_side="left" for causal language model generation to ensure proper attention masking.

Prompt Formatting

Training Format

ChemLactica uses specific prompt formats for training:
Output:

Generation Format

For molecule generation, omit the target SMILES:

Tokenizer Configuration

Model Config

Resizing Token Embeddings

When using a pretrained model with a custom tokenizer:
Use pad_to_multiple_of=8 for optimal GPU performance with tensor cores.

Advanced Usage

Custom Property Tags

Add custom properties for your domain:

Response Template for SFT

For supervised fine-tuning, mask the prompt and only compute loss on the response:

Extracting Generated SMILES

Tokenizer Statistics

Vocabulary Size

Token Length Analysis

Best Practices

  • Always use the same tokenizer for training and inference
  • Save tokenizer configuration with model checkpoints
  • Verify special token IDs match between tokenizer and model
  • Monitor token lengths in your dataset
  • Set appropriate max_seq_length for SFT (typically 512-2048)
  • Use truncation=True to handle long sequences
  • Consider sequence length distribution when batching
  • Use specific property tokens when available (e.g., [QED] instead of [PROPERTY]qed)
  • Keep property values formatted consistently (2 decimal places)
  • Always wrap SMILES in [START_SMILES]...[END_SMILES]
  • Use </s> as both EOS and separator token
  • Use padding_side="left" for generation tasks
  • Use padding_side="right" for classification tasks
  • Enable pad_to_multiple_of=8 for optimal GPU utilization
  • Set padding=True for batch processing
The tokenizer is critical for model performance. Using the wrong tokenizer or configuration can lead to poor results or errors.

Next Steps

Custom Oracles

Build oracles using property tokens

Property Prediction

Fine-tune models with property annotations