Add demo showing clinical context reranking for AIDS differentials
Browse files
README.md
CHANGED
|
@@ -163,6 +163,36 @@ results = retrieve_and_rerank(
|
|
| 163 |
)
|
| 164 |
```
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
### Temperature Calibration
|
| 167 |
|
| 168 |
**Important**: For optimal performance in score fusion, apply temperature scaling:
|
|
|
|
| 163 |
)
|
| 164 |
```
|
| 165 |
|
| 166 |
+
## Demo: Cross-Encoder Reranking
|
| 167 |
+
|
| 168 |
+
```python
|
| 169 |
+
from sentence_transformers import CrossEncoder
|
| 170 |
+
import numpy as np
|
| 171 |
+
|
| 172 |
+
model = CrossEncoder('matulichpt/radlit-crossencoder')
|
| 173 |
+
|
| 174 |
+
query = "What causes ring-enhancing brain lesions in AIDS patients?"
|
| 175 |
+
|
| 176 |
+
# Candidates from bi-encoder retrieval (simulated)
|
| 177 |
+
candidates = [
|
| 178 |
+
"In AIDS, toxoplasmosis shows ring-enhancing lesions in basal ganglia. CNS lymphoma is typically periventricular.",
|
| 179 |
+
"Brain metastases occur at gray-white junction and may show ring enhancement.",
|
| 180 |
+
"Glioblastoma is the most common primary brain malignancy.",
|
| 181 |
+
]
|
| 182 |
+
|
| 183 |
+
# Score each candidate
|
| 184 |
+
pairs = [[query, doc] for doc in candidates]
|
| 185 |
+
scores = model.predict(pairs)
|
| 186 |
+
|
| 187 |
+
# Rank by relevance
|
| 188 |
+
ranked = sorted(zip(candidates, scores), key=lambda x: x[1], reverse=True)
|
| 189 |
+
print(f"Top result: {ranked[0][0][:80]}...")
|
| 190 |
+
print(f"Score: {ranked[0][1]:.2f}")
|
| 191 |
+
# The AIDS-specific answer ranks first despite shorter text
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
The cross-encoder correctly prioritizes the clinically relevant answer about AIDS-specific differentials.
|
| 195 |
+
|
| 196 |
### Temperature Calibration
|
| 197 |
|
| 198 |
**Important**: For optimal performance in score fusion, apply temperature scaling:
|