Views
No views yet
answerdotai/ModernBERT-large] for sequence classification on pairs of (trial_boilerplate_text, patient_boilerplate_text). "Patient boilerplate text" represents a subsection of an overall patient summary that describes any history of such conditions.Important: This is a research prototype for model development, not a medical device or approved clinical decision support tool. It is not intended for clinical decision-making.
['patient_boilerplate_text', 'trial_boilerplate_text']text = "Patient history: " + patient_boilerplate_text + "\nTrial exclusions:" + trial_boilerplate_text
exclusion_result as the binary label (0/1)answerdotai/ModernBERT-largelearning_rate=2e-5, weight_decay=0.01per_device_train_batch_size=82epochAutoTokenizer.from_pretrained("answerdotai/ModernBERT-large")DataCollatorWithPadding1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
4device = "cuda" if torch.cuda.is_available() else "cpu"
5MODEL_REPO = "ksg-dfci/BoilerplateChecker-1225"
6
7tok = AutoTokenizer.from_pretrained(MODEL_REPO)
8model = AutoModelForSequenceClassification.from_pretrained(MODEL_REPO).to(device)
9model.eval()
10
11trial_boilerplate_text = (
12 "Patients with uncontrolled brain metastases are excluded."
13)
14
15patient_boilerplate_text = (
16 "New brain metastases identified 01/02/23, not yet treated."
17)
18
19text = "Patient history: " + patient_boilerplate_text + "\nTrial exclusions:" + trial_boilerplate_text
20
21# Raw Transformers model
22enc = tok(text, return_tensors="pt", truncation=True, max_length=4096).to(device)
23with torch.no_grad():
24 logits = model(**enc).logits
25probs = logits.softmax(-1).squeeze(0)
26
27# Label mapping was set in training: {0: "NEGATIVE", 1: "POSITIVE"}
28p_positive = float(probs[1])
29print(f"Exclusion probability: {p_positive:.3f}")
30
31# Or pipeline API to get similar outputs
32from trasnformers import pipeline
33pipe = pipeline('text-classification', 'ksg-dfci/BoilerplateChecker-1225')
34pipe([text])
351from typing import List
2import torch
3
4def score_pairs(spaces: List[str], summaries: List[str], tokenizer, model, max_length=4096, batch_size=8):
5 assert len(spaces) == len(summaries)
6 device = next(model.parameters()).device
7 scores = []
8
9 for i in range(0, len(spaces), batch_size):
10 batch_spaces = spaces[i:i+batch_size]
11 batch_summaries = summaries[i:i+batch_size]
12 texts = [s + "\nNow here is the patient summary:" + p for s, p in zip(batch_spaces, batch_summaries)]
13 enc = tokenizer(texts, return_tensors="pt", padding=True, truncation=True, max_length=max_length).to(device)
14 with torch.no_grad():
15 logits = model(**enc).logits
16 probs = logits.softmax(-1)[:, 1] # POSITIVE
17 scores.extend(probs.detach().cpu().tolist())
18 return scores
19
20# Example
21trial_exclusions = [trial_boilerplate_text] * 3
22paitne_boilerplate_texts = [patient_boilerplate_text, "Different patient comorbidities 1...", "Different patient comorbidities 2..."]
23scores = score_pairs(spaces, summaries, tok, model)
24print(scores)OncoReasoning-3B-1225 model for summarization and trial information extraction), but the classifier accepts any plain strings in the format shown above.1# 1) Load and merge three labeled sources
2# - space_specific_eligibility_checks.parquet
3# - top_ten_cohorts_checked_round{1,2,3}.csv
4# - top_twenty_patients_checked_round{1,2,3}.csv
5
6# 2) Deduplicate by ['patient_boilerplate_text','trial_boilerplate_text'] and keep:
7# - split, patient_boilerplate_text, trial_boilerplate_text, exclusion_result
8
9# 3) Compose input text and label:
10text = this_space + "\nNow here is the patient summary:" + patient_summary
11label = int(eligibility_result) # 0 or 1
12
13# 4) Tokenize with ModernBERT tokenizer (max_length=3192, truncation=True)
14# 5) Train AutoModelForSequenceClassification, which then produces probabilities for the "POSITIVE" class (patient may be excluded) and for the "NEGATIVE" class (patient not predicted to be excluded)