Views
No views yet

clinical-info-corrector-1Bunsloth/Llama-3.2-1B-InstructSFTTrainerÂ, broken bullets, etc.)clinical-info-corrector-1B is to explore whether even a small 1B parameter model, fine-tuned on a crude but realistic dataset, can:content – noisy / raw clinical text (e.g. original HISTORY, treatment, adviced, mdescript1)response – cleaned version of that text (grammar fixed, abbreviations expanded, structure improved, artefacts removed)1content:
2PATIENT ADMITTED WITH ABOVE SAID COMPLAINT FOR FURTHER EVALUATION AND MANAGEMENT. -H/O LAP CHOLECYSTECTOMY(12 YEAR BACK
3
4response:
5The patient was admitted with the above-mentioned complaints for further evaluation and management.
6The patient has a history of laparoscopic cholecystectomy performed 12 years ago.1[
2 {"role": "system", "content": "<system prompt (see below)>"},
3 {"role": "user", "content": "<content>"},
4 {"role": "assistant", "content": "<response>"}
5]llama-3.1 in Unsloth) was used to convert this into the final training text.train_on_responses_only, so only the assistant segment (response) contributed to the loss.1You are a medical AI assistant that rewrites noisy, telegraphic, or poorly formatted clinical text
2(eg, discharge summaries, admission notes, advice sections) into clear, grammatically correct,
3contextually rich prose.
4
5Given some raw 'content' from a clinician, you must:
6- preserve all medically relevant facts and timelines,
7- avoid inventing new clinical information,
8- expand or clarify abbreviations when appropriate,
9- fix spelling, grammar, punctuation, and formatting,
10- turn lists or fragments into coherent sentences and paragraphs.
11
12Your reply should be only the cleaned clinical text, nothing else.1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_name = "your-username/clinical-info-corrector-1B"
5
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 torch_dtype = torch.float16,
10 device_map = "auto",
11)
12
13SYSTEM_PROMPT = """
14You are a medical AI assistant that rewrites noisy, telegraphic, or poorly formatted clinical text
15into clear, grammatically correct, medically faithful prose. Preserve all medical facts and do not
16invent new information. Your reply should be only the cleaned clinical text.
17"""
18
19raw_content = "PATIENT ADMITTED WITH ABOVE SAID COMPLAINT FOR FURTHER EVALUATION AND MANAGEMENT. -H/O LAP CHOLECYSTECTOMY(12 YEAR BACK"
20
21messages = [
22 {"role": "system", "content": SYSTEM_PROMPT},
23 {"role": "user", "content": raw_content},
24]
25
26from unsloth.chat_templates import get_chat_template
27tokenizer = get_chat_template(tokenizer, chat_template = "llama-3.1")
28
29inputs = tokenizer.apply_chat_template(
30 messages,
31 tokenize = True,
32 add_generation_prompt = True,
33 return_tensors = "pt",
34).to(model.device)
35
36outputs = model.generate(
37 **inputs,
38 max_new_tokens = 256,
39 temperature = 0.7,
40 top_p = 0.9,
41)
42
43print(tokenizer.decode(outputs[0], skip_special_tokens = True))“Please clean and normalize the following clinical text. Preserve all clinical facts and do not add anything new:
”
“You are a clinical text cleaning assistant. Rewrite the input into clear, grammatically correct, medically faithful prose, preserving all facts.”
DAILY FLUID INTAKE 1.5LTR/DAY Check CBC, RFT,K+, RBS,CXR, ECG, in follow up Chest physiotherapy, wound hygiene & proper diet. Steam Inhalation three times a day. Syp Alex or TusQDx 2 spoons threee times a day if dry cough is present FBS AND PPBS AFTER 3DAYS IF BLOOD SUGAR IS <80 OR >200mg/dl THEN CONSULT to local physician. WHILE SPLEEPING MUST LIE SUPINE FOR ONE MONTH, CAN REMOVE BELT IN NIGHT ONLY. Maintain a daily fluid intake of about 1.5 L per day. At the follow-up visit, get a complete blood count (CBC), renal function tests (RFT), serum potassium (K+), random blood sugar (RBS), chest X-ray (CXR), and electrocardiogram (ECG) done. Continue chest physiotherapy, maintain good wound hygiene, and follow a nutritious diet. Do steam inhalation three times daily. If you have a dry cough, take syrup Alex or TusQDx 2 spoonfuls three times daily. Check fasting and post-meal blood sugar after 3 days; if it is less than 80 mg/dL or more than 200 mg/dL, consult your local physician. While sleeping for the next month, lie on your back (supine), and you may remove the belt only at night.
unsloth/Llama-3.2-1B-InstructSFTTrainertrain_on_responses_only (only assistant outputs)response given content (and system + user context)0.3 – 0.70.9256–5121.0–1.1)license: other field is a placeholder.