File size: 1,228 Bytes
2cdacf1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | """Step 2 of a prediction: a short explanation written from the cited sentences only.
The fine-tuned model (LoRA on) picks the label and sentence IDs; the same model with
LoRA off writes the explanation, seeing nothing but the criterion, the label and the
cited sentences. No cited sentences means nothing to explain from, so a template is used.
"""
SYSTEM = "You explain clinical trial screening decisions in one or two plain sentences, using only the evidence given."
def explanation_messages(criterion_type: str, criterion_text: str, label: str, cited: list[tuple[int, str]]):
evidence = "\n".join(f"{i}. {s}" for i, s in cited)
user = (f"Criterion ({criterion_type}): {criterion_text.strip()}\n"
f"Decision: {label}\n"
f"Patient sentences cited as evidence:\n{evidence}\n\n"
"Explain in one or two sentences why these sentences lead to the decision. "
"Refer to sentences by their number and do not add facts that are not in them.")
return [{"role": "system", "content": SYSTEM}, {"role": "user", "content": user}]
def template_explanation(label: str) -> str:
return f"No sentence in the patient note addresses this criterion, so it is marked '{label}'."
|