Instructions to use pamessina/T5FactExtractor with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use pamessina/T5FactExtractor with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="pamessina/T5FactExtractor")# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("pamessina/T5FactExtractor") model = AutoModelForSeq2SeqLM.from_pretrained("pamessina/T5FactExtractor", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use pamessina/T5FactExtractor with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "pamessina/T5FactExtractor" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pamessina/T5FactExtractor", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/pamessina/T5FactExtractor
- SGLang
How to use pamessina/T5FactExtractor with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "pamessina/T5FactExtractor" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pamessina/T5FactExtractor", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "pamessina/T5FactExtractor" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pamessina/T5FactExtractor", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use pamessina/T5FactExtractor with Docker Model Runner:
docker model run hf.co/pamessina/T5FactExtractor
T5FactExtractor — Radiology Fact Extractor
T5FactExtractor is a T5-small sequence-to-sequence model that extracts factual statements from chest X-ray radiology report sentences. Given a sentence, it generates a JSON-like list of short clinical facts that can be embedded, compared, or used in metrics such as CXRFEScore.
It is stage 1 of the Extracting and Encoding framework from Findings of ACL 2024:
- Fact extraction — this model (
pamessina/T5FactExtractor) - Fact encoding —
pamessina/CXRFE
Model details
| Architecture | T5ForConditionalGeneration |
| Base model | t5-small |
| Task | Sentence → list of radiology facts |
| Typical use | Preprocess report sentences before encoding with CXRFE |
| License | Apache 2.0 |
Output format
The model generates a string containing a JSON array of fact strings, for example:
["small right pleural effusion", "normal heart size"]
Downstream code (including cxrfescore) parses that array, deduplicates facts, and lightly cleans repeated words.
How to use
Standalone (Transformers)
import re
import json
import torch
from transformers import T5ForConditionalGeneration, T5TokenizerFast
device = "cuda" if torch.cuda.is_available() else "cpu"
model_id = "pamessina/T5FactExtractor"
tokenizer = T5TokenizerFast.from_pretrained(model_id)
model = T5ForConditionalGeneration.from_pretrained(model_id).to(device)
model.eval()
sentence = "There is a small right pleural effusion. The heart size is normal."
# Prefer one sentence at a time (reports are usually sentence-split first).
inputs = tokenizer(sentence, padding="longest", return_tensors="pt")
input_ids = inputs["input_ids"].to(device)
attention_mask = inputs["attention_mask"].to(device)
with torch.no_grad():
output_ids = model.generate(
input_ids=input_ids,
attention_mask=attention_mask,
max_new_tokens=input_ids.shape[1] * 4,
num_beams=1,
)
raw = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0]
print("raw:", raw)
# Minimal parse (same idea as cxrfescore.text_utils.parse_facts)
match = re.search(r"\[.*", raw)
if match:
facts_str = match.group()
if not facts_str.endswith("]"):
facts_str += "]"
facts = json.loads(facts_str)
print("facts:", facts)
Easiest path: CXRFEScore
For full reports, the package sentence-splits, runs this extractor, aggregates unique facts, and (optionally) embeds them with CXRFE:
pip install cxrfescore
from cxrfescore import CXRFEScore
metric = CXRFEScore(device="cuda")
reports = [
"There is a small right pleural effusion. The heart size is normal.",
]
facts_per_report = metric.extract_facts(reports)
print(facts_per_report[0])
Demo notebook: CXR-Fact-Encoder / notebooks/cxrfescore_demo.ipynb
Related resources
- Paper hub: https://github.com/PabloMessina/CXR-Fact-Encoder
- Metric package: https://github.com/PabloMessina/CXRFEScore · PyPI
- Companion fact encoder: https://huggingface.co/pamessina/CXRFE
- ACL Anthology: https://aclanthology.org/2024.findings-acl.236/
- arXiv: https://arxiv.org/abs/2407.01948
Citation
If you use T5FactExtractor, please cite:
@inproceedings{messina-etal-2024-extracting,
title = "Extracting and Encoding: Leveraging Large Language Models and Medical Knowledge to Enhance Radiological Text Representation",
author = "Messina, Pablo and
Vidal, Rene and
Parra, Denis and
Soto, Alvaro and
Araujo, Vladimir",
booktitle = "Findings of the Association for Computational Linguistics: ACL 2024",
month = aug,
year = "2024",
address = "Bangkok, Thailand",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2024.findings-acl.236/",
doi = "10.18653/v1/2024.findings-acl.236",
pages = "3955--3986"
}
- Downloads last month
- 183
Model tree for pamessina/T5FactExtractor
Base model
google-t5/t5-small