MolCrawl/rna
Collection
11 items • Updated
GPT-2 medium (345M parameters) fine-tuned on cell-type specific RNA sequences, starting from the molcrawl-rna-gpt2-medium pre-trained model.
from transformers import AutoModelForMaskedLM, AutoTokenizer
import torch
model = AutoModelForMaskedLM.from_pretrained("kojima-lab/molcrawl-rna-celltype-bert-medium")
tokenizer = AutoTokenizer.from_pretrained("kojima-lab/molcrawl-rna-celltype-bert-medium")
# Predict masked RNA 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 = "AUGCAUGC{MASK}AUGCAUGC".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}")
Training pipeline, configuration files, and data preparation scripts are available in the MolCrawl GitHub repository: https://github.com/mmai-framework-lab/MolCrawl
This model is released under the APACHE-2.0 license.
If you use this model, please cite:
@misc{molcrawl_rna_celltype_bert_medium,
title={molcrawl-rna-celltype-bert-medium},
author={{RIKEN}},
year={2026},
publisher={{Hugging Face}},
url={{https://huggingface.co/kojima-lab/molcrawl-rna-celltype-bert-medium}}
}
Inference test (CPU). Important: this tokenizer uses a WordLevel gene-ID vocabulary
without a text-mode pre_tokenizer, so feed input as a list of ENSEMBL IDs (and the mask
token) directly into convert_tokens_to_ids, not as a single text string.
import torch
from transformers import AutoTokenizer, AutoModelForMaskedLM
REPO_ID = "kojima-lab/molcrawl-rna-celltype-bert-medium"
tokenizer = AutoTokenizer.from_pretrained(REPO_ID)
model = AutoModelForMaskedLM.from_pretrained(REPO_ID)
model.eval()
genes = [
"ENSG00000000003",
"ENSG00000000005",
tokenizer.mask_token,
"ENSG00000001167",
"ENSG00000002586",
]
ids = tokenizer.convert_tokens_to_ids(genes)
input_ids = torch.tensor([ids])
mask_index = (input_ids == tokenizer.mask_token_id).nonzero(as_tuple=True)[1]
with torch.no_grad():
outputs = model(input_ids=input_ids)
predicted_id = outputs.logits[0, mask_index].argmax(dim=-1)
predicted_gene = tokenizer.convert_ids_to_tokens(predicted_id.tolist())[0]
print(f"Predicted gene at mask: {predicted_gene}")
# => Predicted gene at mask: ENSG00000012223