import torch
from transformers import EncoderDecoderModel, AutoTokenizer
# step 1: Setup
model_name = "StanfordAIMI/SRR-BERT2BERT-RoBERTa-biomed"
device = torch.device("cuda"if torch.cuda.is_available() else"cpu")
# step 2: Load Processor and Model
model = EncoderDecoderModel.from_pretrained(model_name).to(device)
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, padding_side="right", use_fast=False)
model.config.decoder_start_token_id = tokenizer.cls_token_id
model.config.bos_token_id = tokenizer.cls_token_id
model.eval()
# step 3: Inference (example from MIMIC-CXR dataset)
input_text = "CHEST RADIOGRAPH PERFORMED ON ___ COMPARISON: Prior exam from ___. CLINICAL HISTORY: Weakness, assess pneumonia. FINDINGS: Frontal and lateral views of the chest were provided. Midline sternotomy wires are again noted. The heart is poorly assessed, though remains enlarged. There are at least small bilateral pleural effusions. There may be mild interstitial edema. No pneumothorax. Bony structures are demineralized with kyphotic angulation in the lower T-spine again noted. IMPRESSION: Limited exam with small bilateral effusions, cardiomegaly, and possible mild interstitial edema."
inputs = tokenizer(input_text, padding="max_length", truncation=True, max_length=512, return_tensors="pt")
inputs["attention_mask"] = inputs["input_ids"].ne(tokenizer.pad_token_id) # Add attention mask
input_ids = inputs['input_ids'].to(device)
attention_mask=inputs["attention_mask"].to(device)
generated_ids = model.generate(
input_ids, attention_mask=attention_mask, max_new_tokens=286, min_new_tokens= 120,decoder_start_token_id=model.config.decoder_start_token_id, num_beams=5, early_stopping=True, max_length=None
)[0]
decoded = tokenizer.decode(generated_ids, skip_special_tokens=True)
print(decoded)
✏️ Citation
@article{structuring-2025,
title={Structuring Radiology Reports: Challenging LLMs with Lightweight Models},
author={Moll, Johannes and Fay, Louisa and Azhar, Asfandyar and Ostmeier, Sophie and Lueth, Tim and Gatidis, Sergios and Langlotz, Curtis and Delbrouck, Jean-Benoit},
journal={arXiv preprint arXiv:2506.00200},
url={https://arxiv.org/abs/2506.00200},
year={2025}
}
Runs of StanfordAIMI SRR-BERT2BERT-RoBERTa-biomed on huggingface.co
11
Total runs
0
24-hour runs
-1
3-day runs
0
7-day runs
4
30-day runs
More Information About SRR-BERT2BERT-RoBERTa-biomed huggingface.co Model
SRR-BERT2BERT-RoBERTa-biomed huggingface.co
SRR-BERT2BERT-RoBERTa-biomed huggingface.co is an AI model on huggingface.co that provides SRR-BERT2BERT-RoBERTa-biomed's model effect (), which can be used instantly with this StanfordAIMI SRR-BERT2BERT-RoBERTa-biomed model. huggingface.co supports a free trial of the SRR-BERT2BERT-RoBERTa-biomed model, and also provides paid use of the SRR-BERT2BERT-RoBERTa-biomed. Support call SRR-BERT2BERT-RoBERTa-biomed model through api, including Node.js, Python, http.
SRR-BERT2BERT-RoBERTa-biomed huggingface.co is an online trial and call api platform, which integrates SRR-BERT2BERT-RoBERTa-biomed's modeling effects, including api services, and provides a free online trial of SRR-BERT2BERT-RoBERTa-biomed, you can try SRR-BERT2BERT-RoBERTa-biomed online for free by clicking the link below.
StanfordAIMI SRR-BERT2BERT-RoBERTa-biomed online free url in huggingface.co:
SRR-BERT2BERT-RoBERTa-biomed is an open source model from GitHub that offers a free installation service, and any user can find SRR-BERT2BERT-RoBERTa-biomed on GitHub to install. At the same time, huggingface.co provides the effect of SRR-BERT2BERT-RoBERTa-biomed install, users can directly use SRR-BERT2BERT-RoBERTa-biomed installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
SRR-BERT2BERT-RoBERTa-biomed install url in huggingface.co: