Views
No views yet
pamessina/T5FactExtractor)pamessina/CXRFE| 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 |
["small right pleural effusion", "normal heart size"]cxrfescore) parses that array, deduplicates facts, and lightly cleans repeated words.1import re
2import json
3import torch
4from transformers import T5ForConditionalGeneration, T5TokenizerFast
5
6device = "cuda" if torch.cuda.is_available() else "cpu"
7model_id = "pamessina/T5FactExtractor"
8
9tokenizer = T5TokenizerFast.from_pretrained(model_id)
10model = T5ForConditionalGeneration.from_pretrained(model_id).to(device)
11model.eval()
12
13sentence = "There is a small right pleural effusion. The heart size is normal."
14# Prefer one sentence at a time (reports are usually sentence-split first).
15inputs = tokenizer(sentence, padding="longest", return_tensors="pt")
16input_ids = inputs["input_ids"].to(device)
17attention_mask = inputs["attention_mask"].to(device)
18
19with torch.no_grad():
20 output_ids = model.generate(
21 input_ids=input_ids,
22 attention_mask=attention_mask,
23 max_new_tokens=input_ids.shape[1] * 4,
24 num_beams=1,
25 )
26
27raw = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0]
28print("raw:", raw)
29
30# Minimal parse (same idea as cxrfescore.text_utils.parse_facts)
31match = re.search(r"\[.*", raw)
32if match:
33 facts_str = match.group()
34 if not facts_str.endswith("]"):
35 facts_str += "]"
36 facts = json.loads(facts_str)
37 print("facts:", facts)pip install cxrfescore1from cxrfescore import CXRFEScore
2
3metric = CXRFEScore(device="cuda")
4reports = [
5 "There is a small right pleural effusion. The heart size is normal.",
6]
7facts_per_report = metric.extract_facts(reports)
8print(facts_per_report[0])1@inproceedings{messina-etal-2024-extracting,
2 title = "Extracting and Encoding: Leveraging Large Language Models and Medical Knowledge to Enhance Radiological Text Representation",
3 author = "Messina, Pablo and
4 Vidal, Rene and
5 Parra, Denis and
6 Soto, Alvaro and
7 Araujo, Vladimir",
8 booktitle = "Findings of the Association for Computational Linguistics: ACL 2024",
9 month = aug,
10 year = "2024",
11 address = "Bangkok, Thailand",
12 publisher = "Association for Computational Linguistics",
13 url = "https://aclanthology.org/2024.findings-acl.236/",
14 doi = "10.18653/v1/2024.findings-acl.236",
15 pages = "3955--3986"
16}