molcrawl-compounds-chemberta2-large

Model Description

GPT-2 large (774M parameters) foundation model pre-trained on compound SMILES strings from the MolCrawl dataset.

The tokenizer is a character-level BPE tokenizer (vocab_size=612) that encodes each SMILES character as a separate token. Input SMILES strings should be passed without spaces (e.g. CC(=O)O). The [SEP] token (id=13) is used as the end-of-sequence marker.

  • Model Type: chemberta2
  • Data Type: Molecule/Compound
  • Training Date: 2026-04-24

Usage

from transformers import AutoModelForMaskedLM, AutoTokenizer
import torch

model = AutoModelForMaskedLM.from_pretrained("kojima-lab/molcrawl-compounds-chemberta2-large")
tokenizer = AutoTokenizer.from_pretrained("kojima-lab/molcrawl-compounds-chemberta2-large")

# Predict masked SMILES token
# Use tokenizer.mask_token instead of hardcoded "[MASK]":
# BERT-style tokenizers vary ("[MASK]", "<mask>", etc.)
if tokenizer.mask_token is None:
    raise ValueError("This tokenizer has no mask_token; masked LM inference is not supported.")
prompt = "CC(=O){MASK}".replace("{MASK}", tokenizer.mask_token)
inputs = tokenizer(prompt, return_tensors="pt")
mask_index = (inputs["input_ids"] == tokenizer.mask_token_id).nonzero(as_tuple=True)[1]

with torch.no_grad():
    outputs = model(**inputs)
logits = outputs.logits

predicted_token_id = logits[0, mask_index].argmax(dim=-1)
predicted_token = tokenizer.decode(predicted_token_id)
result = prompt.replace(tokenizer.mask_token, predicted_token)
print(f"Predicted: {result}")

Source Code

Training pipeline, configuration files, and data preparation scripts are available in the MolCrawl GitHub repository: https://github.com/mmai-framework-lab/MolCrawl

License

This model is released under the APACHE-2.0 license.

Citation

If you use this model, please cite:

@misc{molcrawl_compounds_chemberta2_large,
  title={molcrawl-compounds-chemberta2-large},
  author={{RIKEN}},
  year={2026},
  publisher={{Hugging Face}},
  url={{https://huggingface.co/kojima-lab/molcrawl-compounds-chemberta2-large}}
}

Example Output

End-to-end inference test (downloaded the model from this repo on CPU).

import torch
from transformers import AutoTokenizer, AutoModelForMaskedLM

REPO_ID = "kojima-lab/molcrawl-compounds-chemberta2-large"
tokenizer = AutoTokenizer.from_pretrained(REPO_ID)
model = AutoModelForMaskedLM.from_pretrained(REPO_ID)
model.eval()

# SMILES with one masked position
prompt = "CC(=O)Oc1ccccc1[MASK](=O)O"
inputs = tokenizer(prompt, return_tensors="pt")
mask_index = (inputs["input_ids"][0] == tokenizer.mask_token_id).nonzero(as_tuple=True)[0]

with torch.no_grad():
    outputs = model(**inputs)

predicted_id = outputs.logits[0, mask_index].argmax(dim=-1)
predicted_token = tokenizer.convert_ids_to_tokens(predicted_id.tolist())[0]
print(f"Predicted token at mask: {predicted_token}")
# => Predicted token at mask: C
Downloads last month
44
Safetensors
Model size
0.3B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including kojima-lab/molcrawl-compounds-chemberta2-large