Views
No views yet
| Label (BIO) | Meaning |
|---|---|
medical-jargon-google-easy | Easily Google-able medical terms |
medical-jargon-google-hard | Complex, hard-to-Google medical terms |
medical-name-entity | Named diseases, drugs, procedures |
general-complex | Complex general vocabulary |
abbr-medical | Medical abbreviations (e.g., ECG, CBC) |
abbr-general | General abbreviations |
general-medical-multisense | Words with both lay and medical meanings |
pytorch_model.bin – model weightsconfig.json – hyper-parameters & label maptokenizer.json, vocab.json, merges.txt – RoBERTa tokenizer assetsmodeling_jargon.py – custom CRFTokenClassificationModel classrequirements.txt – runtime dependencies1from transformers import AutoTokenizer
2from modeling_jargon import CRFTokenClassificationModel
3import torch
4
5# 1. Load model and tokenizer
6model_name = "DNivalis/med-jargon-crf"
7tokenizer = AutoTokenizer.from_pretrained(model_name, add_prefix_space=True)
8model = CRFTokenClassificationModel.from_pretrained(model_name)
9model.eval()
10
11# 2. Prepare input text
12text = "The patient presented with elevated CRP and intermittent AF."
13inputs = tokenizer(text, return_tensors="pt")
14
15# 3. Run inference
16with torch.no_grad():
17 outputs = model(**inputs)
18 logits = outputs["logits"]
19 # Decode best sequence using CRF
20 predicted_tags = model.decode(logits, inputs["attention_mask"])[0]
21
22# 4. Extract spans from predictions
23spans = [(i, model.id2label[tag_id]) for i, tag_id in enumerate(predicted_tags) if tag_id != 0]
24tokens = tokenizer.convert_ids_to_tokens(inputs["input_ids"][0])
25
26# 5. Display results
27print("Detected medical jargon:")
28for token_idx, label in spans:
29 # Find continuous spans of the same entity
30 end_idx = token_idx + 1
31 while (end_idx < len(predicted_tags) and
32 predicted_tags[end_idx] == predicted_tags[token_idx]):
33 end_idx += 1
34
35 # Convert tokens back to text
36 detected_tokens = tokens[token_idx:end_idx]
37 detected_text = tokenizer.convert_tokens_to_string(detected_tokens)
38
39 print(f"{label}: '{detected_text.strip()}'")1@article{jiang2024medreadmesystematicstudyfinegrained,
2 title={MedReadMe: A Systematic Study for Fine-grained Sentence Readability in Medical Domain},
3 author={Chao Jiang and Wei Xu},
4 year={2024},
5 eprint={2405.02144},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2405.02144}
9}