You need to agree to share your contact information to access this dataset

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

Log in or Sign Up to review the conditions and access this dataset content.

ClinicalMap25-for-SnomedCT

ClinicalMap25-for-SnomedCT provides a dense, token-level mapping of SnomedCT clinical concepts to the ClinicalEncoder25 embedding space. This resource enables fast, interpretable semantic search and reasoning over medical terminology, directly compatible with the ClinicalEncoder25 model.


Key Features

  • 707,574 SnomedCT Concepts: Each concept is represented as a 1024-dimensional embedding, normalized for efficient cosine similarity computation.
  • Optimized for Speed: Embeddings are stored as 8-bit floats, enabling fast matrix multiplication on supported hardware.
  • Padding for Efficiency: 10 extra zero-padded rows ensure compatibility with optimized matrix operations (e.g., torch._scaled_mm).
  • Ready for Integration: Designed for use with ClinicalEncoder25.

Files

File Name Description
clinical_map_25_for_sct_concepts.pth 707,584 rows (707,574 concepts + 10 padding) of 1024 8-bit floats, normalized for cosine similarity.
sct_concepts.txt 707,574 SnomedCT concept names, one per line. May contain duplicates.

Usage

1. Load the Embeddings

# %%
import torch

# %%
# Load the embeddings (8-bit floats)
concept_vectors = torch.load("clinical_map_25_for_sct_concepts.pth", map_location="cpu")

# If your hardware doesn't support FP8, cast to float16
concept_vectors = concept_vectors.to(torch.float16)

2. Load the Concept Names

# %%
# Load concept names
with open("sct_concepts.txt", "r") as f:
    concept_names = [line.strip() for line in f.readlines()]

3. Perform Semantic Search

# %%
# Load the ClinicalEncoder25 model
from transformers import AutoModel, AutoTokenizer
MODEL_NAME = "Parallia/ClinicalEncoder25-Diagnosable-Colbert-L2-for-medical-texts"
model, tokenizer = AutoModel.from_pretrained(MODEL_NAME), AutoTokenizer.from_pretrained(MODEL_NAME)

# %%
# Tokenize your document
doc = "The patient suffers from PAPA syndrome. The patient therefore takes NSAIDs daily, as prophylaxis."
doc_inputs = tokenizer(
    doc,
    return_tensors="pt",
    add_special_tokens=True,
)
doc_tokens = [
    tokenizer.decode([tid], clean_up_tokenization_spaces=False)
    for tid in doc_inputs["input_ids"][0].tolist()
]

# %%
# Encode your document
with torch.no_grad():
    doc_inputs = {k: v.to(model.device) for k, v in doc_inputs.items()}
    doc_outputs = model(**doc_inputs)
    doc_vectors = doc_outputs.last_hidden_state[0]

# Normalize the token embeddings for easier cosine similarity scoring
doc_vectors = (doc_vectors / doc_vectors.norm(dim=1, keepdim=True).clamp_min(1e-12))

# Ensure the query and embeddings are on the same device, and use the same dtype
doc_vectors = doc_vectors.to(concept_vectors.device).to(concept_vectors.dtype)

# %%
# Compute cosine similarity
if concept_vectors.dtype != torch.float8_e4m3fn:
    similarities = torch.mm(doc_vectors, concept_vectors.t())
else:
    unit_vector = torch.tensor(1.0, device=concept_vectors.device, dtype=torch.float32)
    similarities = torch._scaled_mm(
        doc_vectors, concept_vectors.T,
        unit_vector, unit_vector,
        out_dtype=torch.float16
    )

# %%
# Retrieve concept names of the best matches per token, and display their similarity scores
how_many_to_display = 3
for i, token in enumerate(doc_tokens[1:]):
  print(f"\nToken #{i} '{token}':")
  top_indices = similarities[i].topk(how_many_to_display, largest=True, sorted=True).indices
  for idx in top_indices:
      print(f"- {concept_names[idx]} ({similarities[0, idx].item()}")

Notes

  • Padding Rows: The last 10 rows are zero-padded and will never match any query.
  • Memory Efficiency: Use FP8 for minimal memory usage. If FP8 is not supported, use FP16.
  • SnomedCT Choice: SnomedCT was selected for its balance between medical coverage and ontology size, compared to UMLS (larger) and ICD-10 (smaller).
  • Duplicates: Concept names may contain duplicates; this map is for demonstration purposes.

License

This dataset is released under the CC-BY-NC 4.0 license. For commercial use, please obtain a license. You might also need a SnomedCT license if you intend to map the output of this script to the SnomedCT ontology.


References

Downloads last month
23

Collection including Parallia/ClinicalMap25-for-SnomedCT