Skip to main content
The generate() function provides a simple interface for generating molecules from text prompts using ChemLactica models.

Function Signature

Source: generation/generation.py:9

Parameters

List[str] | str
required
Input prompt(s) for molecule generation. Can be a single string or list of strings.Each prompt should follow the ChemLactica format with property tags and [START_SMILES] token.
PreTrainedModel
required
The loaded ChemLactica model (e.g., from AutoModelForCausalLM.from_pretrained()).
dict
Generation parameters passed to model.generate(). Common parameters:
  • max_new_tokens (int): Maximum tokens to generate
  • temperature (float): Sampling temperature (0.0-1.0)
  • do_sample (bool): Whether to use sampling vs greedy decoding
  • num_return_sequences (int): Number of sequences to generate per prompt
  • repetition_penalty (float): Penalty for repeating tokens
  • top_p (float): Nucleus sampling threshold
  • top_k (int): Top-k sampling threshold

Returns

Dict[str, List[str]]
Dictionary mapping each prompt to a list of generated completions.Each completion includes the full generated text from the model.

Basic Usage

Batch Generation

Generation Parameters

Temperature

Multiple Sequences

Extracting SMILES

The generated text includes the full completion. Extract SMILES strings:

Notes

The generate() function is a simple wrapper around Hugging Face’s model.generate(). For production use in molecular optimization, consider using the optimize() function which includes additional features like pool management and oracle scoring.
Make sure the tokenizer is configured with padding_side="left" for batch generation to work correctly.

Command-Line Usage

The generation module also includes a command-line interface:

See Also