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:Configuration
Tokenizer configuration is defined intokenizer_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
Property Tokens
Chemical properties are enclosed in specific tokens:View all property tokens
View all property tokens
Property Tokens
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:Loading the Tokenizer
Basic Usage
With Padding
Prompt Formatting
Training Format
ChemLactica uses specific prompt formats for training: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: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
Token Consistency
Token Consistency
- Always use the same tokenizer for training and inference
- Save tokenizer configuration with model checkpoints
- Verify special token IDs match between tokenizer and model
Sequence Length
Sequence Length
- Monitor token lengths in your dataset
- Set appropriate
max_seq_lengthfor SFT (typically 512-2048) - Use
truncation=Trueto handle long sequences - Consider sequence length distribution when batching
Special Token Usage
Special Token Usage
- 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
Padding Strategy
Padding Strategy
- Use
padding_side="left"for generation tasks - Use
padding_side="right"for classification tasks - Enable
pad_to_multiple_of=8for optimal GPU utilization - Set
padding=Truefor 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