pamessina commited on
Commit
e407339
·
verified ·
1 Parent(s): 27fd0a8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +133 -3
README.md CHANGED
@@ -1,3 +1,133 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: transformers
4
+ tags:
5
+ - medical
6
+ - radiology
7
+ - chest-x-ray
8
+ - feature-extraction
9
+ - cxr-bert
10
+ - embeddings
11
+ base_model: microsoft/BiomedVLP-CXR-BERT-specialized
12
+ pipeline_tag: feature-extraction
13
+ ---
14
+
15
+ # CXRFE — Chest X-ray Fact Encoder
16
+
17
+ CXRFE is a radiology **fact encoder** for chest X-ray report text. It embeds factual statements (and short report phrases) into a **128-dimensional** projected embedding space for retrieval, ranking, NLI-style comparison, and fact-level evaluation metrics.
18
+
19
+ It is part of the two-stage *Extracting and Encoding* framework from Findings of ACL 2024:
20
+
21
+ 1. **Fact extraction** — [`pamessina/T5FactExtractor`](https://huggingface.co/pamessina/T5FactExtractor)
22
+ 2. **Fact encoding** — this model (`pamessina/CXRFE`)
23
+
24
+ Paper: [*Extracting and Encoding: Leveraging Large Language Models and Medical Knowledge to Enhance Radiological Text Representation*](https://aclanthology.org/2024.findings-acl.236/)
25
+
26
+ ## Model details
27
+
28
+ | | |
29
+ |---|---|
30
+ | **Architecture** | CXR-BERT (`CXRBertModel`) with a projection head |
31
+ | **Initialized from** | [`microsoft/BiomedVLP-CXR-BERT-specialized`](https://huggingface.co/microsoft/BiomedVLP-CXR-BERT-specialized) |
32
+ | **Hidden size** | 768 |
33
+ | **Projected embedding size** | 128 (`projection_size`) |
34
+ | **Intended inputs** | Short radiology facts / sentences (typically after fact extraction) |
35
+ | **License** | Apache 2.0 |
36
+
37
+ > **Note:** This public checkpoint is trained with slightly more NLI data than the single best CXRFE variant reported in the paper. Additional paper-matched variants may be released later.
38
+
39
+ ## How to use
40
+
41
+ Requires `trust_remote_code=True` (custom CXR-BERT code from the BioViL / CXR-BERT family).
42
+
43
+ ### Projected embeddings (recommended)
44
+
45
+ This is the representation used by [CXRFEScore](https://github.com/PabloMessina/CXRFEScore) (`get_projected_text_embeddings`):
46
+
47
+ ```python
48
+ import torch
49
+ from transformers import AutoModel, AutoTokenizer
50
+
51
+ device = "cuda" if torch.cuda.is_available() else "cpu"
52
+ model_id = "pamessina/CXRFE"
53
+
54
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
55
+ model = AutoModel.from_pretrained(model_id, trust_remote_code=True).to(device)
56
+ model.eval()
57
+
58
+ texts = [
59
+ "small right pleural effusion",
60
+ "normal heart size",
61
+ ]
62
+
63
+ inputs = tokenizer(
64
+ texts,
65
+ add_special_tokens=True,
66
+ padding="longest",
67
+ return_tensors="pt",
68
+ )
69
+ input_ids = inputs["input_ids"].to(device)
70
+ attention_mask = inputs["attention_mask"].to(device)
71
+
72
+ with torch.no_grad():
73
+ embeddings = model.get_projected_text_embeddings(
74
+ input_ids=input_ids,
75
+ attention_mask=attention_mask,
76
+ )
77
+
78
+ print(embeddings.shape) # (batch_size, 128)
79
+ ```
80
+
81
+ ### Easiest path: CXRFEScore
82
+
83
+ If you want fact extraction + encoding + report-pair scoring in one API:
84
+
85
+ ```bash
86
+ pip install cxrfescore
87
+ # optional heatmaps:
88
+ pip install "cxrfescore[viz]"
89
+ ```
90
+
91
+ ```python
92
+ from cxrfescore import CXRFEScore
93
+
94
+ metric = CXRFEScore(device="cuda") # default encoder: pamessina/CXRFE
95
+ result = metric(
96
+ ["There is a small right pleural effusion. The heart size is normal."],
97
+ ["Small right pleural effusion. Normal heart size."],
98
+ )
99
+ print(result["mean_similarity"])
100
+ ```
101
+
102
+ Demo notebook: [CXR-Fact-Encoder / notebooks/cxrfescore_demo.ipynb](https://github.com/PabloMessina/CXR-Fact-Encoder/blob/main/notebooks/cxrfescore_demo.ipynb)
103
+
104
+ ## Related resources
105
+
106
+ - Paper hub: https://github.com/PabloMessina/CXR-Fact-Encoder
107
+ - Metric package: https://github.com/PabloMessina/CXRFEScore · [PyPI](https://pypi.org/project/cxrfescore/)
108
+ - Companion fact extractor: https://huggingface.co/pamessina/T5FactExtractor
109
+ - ACL Anthology: https://aclanthology.org/2024.findings-acl.236/
110
+ - arXiv: https://arxiv.org/abs/2407.01948
111
+
112
+ ## Citation
113
+
114
+ If you use CXRFE, please cite:
115
+
116
+ ```bibtex
117
+ @inproceedings{messina-etal-2024-extracting,
118
+ title = "Extracting and Encoding: Leveraging Large Language Models and Medical Knowledge to Enhance Radiological Text Representation",
119
+ author = "Messina, Pablo and
120
+ Vidal, Rene and
121
+ Parra, Denis and
122
+ Soto, Alvaro and
123
+ Araujo, Vladimir",
124
+ booktitle = "Findings of the Association for Computational Linguistics: ACL 2024",
125
+ month = aug,
126
+ year = "2024",
127
+ address = "Bangkok, Thailand",
128
+ publisher = "Association for Computational Linguistics",
129
+ url = "https://aclanthology.org/2024.findings-acl.236/",
130
+ doi = "10.18653/v1/2024.findings-acl.236",
131
+ pages = "3955--3986"
132
+ }
133
+ ```