Views
No views yet
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_id = "sushvinmarimuthu/structured-radiology-intelligence"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 dtype=torch.bfloat16,
10 device_map="auto",
11)
12
13terminators = [
14 tokenizer.eos_token_id,
15 tokenizer.convert_tokens_to_ids("<|eot_id|>")
16]
17
18
19def all_question_getter(text):
20 system_prompt = f"""
21 You are an expert radiology information extraction model.
22 Return exactly what is specified in the instructions.
23 Respond ONLY in JSON.
24
25 INSTRUCTIONS:
26 Extract the following information from the radiology report:
27 For gender:
28 - If gender is explicitly mentioned → return that value ("Male" or "Female").
29 - If the report mentions prostate or seminal vesicles → return "Male".
30 - If the report mentions uterus, vagina, or ovaries → return "Female".
31 - If none of the above appear → return "Not Mentioned".
32 For age:
33 - Return the age as a number-only string (no units like "years" or "months").
34 - If age is not explicitly mentioned → return "Not Mentioned".
35 For current_length_of_tumour:
36 - Return the tumour length if tumour length is explicitly mentioned.
37 - Return the scar size if the report response is complete and mentions scar size.
38 - Return "Not Mentioned" if the tumour length is not mentioned explicitly.
39 For distance_from_anal_verge
40 - Return the distance if distance from the anal verge is explicitly mentioned.
41 - Return "Not Mentioned" if the distance from anal verge is not mentioned explicitly.
42 For distance_from_anorectal_junction
43 - Return the distance if distance from the anorectal junction is explicitly mentioned.
44 - Return "0 mm" if the lesion or tumour extends to or involves the anorectal junction"
45 - Return "Not Mentioned" if the distance from the anorectal junction is not mentioned explicitly.
46 For extramural_spread_size:
47 - Return the numeric size if extramural spread is explicitly mentioned.
48 - Return "0 mm" if the report explicitly states no extramural spread (e.g., "no extramural spread", "extramural spread: nil").
49 - Return "Not Mentioned" if the extramural spread size is not mentioned explicitly.
50 For mr_crm_distance:
51 - Return the distance if MR CRM distance is explicitly mentioned.
52 - Return "Not Mentioned" if the MR CRM distance is not explicitly mentioned.
53 For number_of_mesorectal_nodes
54 - Return a count if number of mesorectal nodes are explicitly mentioned.
55 - Return "Nil Significant" if the report mentions: "No significant mesorectal nodes", "mesorectal nodes: nil significant".
56 - Return "Not Applicable" if the report mentions: "small nodes not significant by size criteria".
57 - Return "Not Mentioned" if the number of mesorectal nodes is not explicitly mentioned.
58 For internal_iliac_nodes:
59 - Return a size if the significant internal iliac lymph nodes are explicitly mentioned.
60 - Return "Nil Significant" if the report mentions: "LYMPHADENOPATHY: Nil significant", "internal iliac: Nil significant".
61 - Return "Not Mentioned" if the internal iliac nodes are not explicitly mentioned.
62 For size_of_obturator_nodes:
63 - Return a size if Significant obturator nodes are explicitly mentioned.
64 - Return 'Nil Significant' if the report mentions "LYMPHADENOPATHY: Nil significant", "internal iliac: Nil significant"
65 - Return 'Not Applicable' if obturator nodes are mentioned but explicitly described as not significant by size criteria.
66 - Return 'Not Mentioned' if the obturator nodes are not explicitly mentioned.
67 For size_of_inguinal:
68 - Return a size if size of the inguinal lymph nodes are explicitly mentioned.
69 - Return 'Nil Significant' if the report mentions "LYMPHADENOPATHY: Nil significant", "inguinal: Nil significant"
70 - Return 'Not Mentioned' if the inguinal lymph nodes are not explicitly mentioned.
71 For size_of_external_iliac
72 - Return the size of the external iliac lymph nodes if explicitly mentioned.
73 - Return 'Nil Significant' if the report mentions "LYMPHADENOPATHY: Nil significant", "external iliac: Nil significant"
74 - Return 'Not Mentioned' if the external iliac nodes are not explicitly mentioned.
75 For size_of_common_iliac:
76 - Return the size of common iliac lymph nodes if explicitly mentioned.
77 - Return 'Nil Significant' if the report mentions "LYMPHADENOPATHY: Nil significant", "common iliac: Nil significant"
78 - Return 'Not Mentioned' if the common iliac nodes are not explicitly mentioned.
79 For size_of_para_aortic:
80 - Return the size of para-aortic iliac lymph nodes if explicitly mentioned.
81 - Return 'Nil Significant' if the report mentions "LYMPHADENOPATHY: Nil significant", "para-aortic iliac: Nil significant"
82 - Return "Not Applicable" if para-aortic iliac nodes are mentioned as "small para-aortic nodes not significant by size criteria".
83 - Return 'Not Mentioned' if the para-aortic iliac nodes are not explicitly mentioned.
84 for is_first_mri_report:
85 - if baseline / initial / first MRI OR explicitly states no prior MRI.
86 - No → comparison with prior MRI OR follow-up/restaging MRI
87 - Not Mentioned → no reference to baseline or prior MRI
88 - Note: comparison to CT/PET does NOT count as prior MRI
89 is_restaging_mri_report:
90 - Yes → explicitly states restaging, post-treatment, response assessment, or interval change clearly linked to treatment
91 - No → baseline / initial staging OR explicitly no prior imaging
92 - Not Mentioned → no restaging or treatment-response context
93 - Do NOT infer from tumour stage alone
94 is_mri_report_after_neoadjuvant:
95 - Yes → explicitly states MRI performed after neoadjuvant therapy (e.g., post-LCCRT, post-NACTRT, after chemoradiotherapy)
96 - No → explicitly states MRI performed before neoadjuvant therapy or no neoadjuvant therapy given
97 - Not Mentioned → neoadjuvant timing not stated
98 is_post_treatment_mri_report:
99 - Yes → explicitly states post-treatment or response assessment (tumour regression, response to therapy, interval decrease linked to treatment)
100 - No → clearly pre-treatment or baseline
101 - Not Mentioned → treatment timing unclear or not discussed
102 is_post_operative_mri:
103 - Yes → explicitly states post-operative or post-surgical status (post-op, post resection, status post surgery)
104 - No → explicitly states pre-operative or no surgery performed
105 - Not Mentioned → surgery not discussed or unclear
106 For location_of_tumour:
107 - Return "High" if the report explicitly mentions involvement of the upper rectum or high rectum.
108 - Return "Mid" if the report explicitly mentions involvement of the middle rectum or mid rectum.
109 - Return "Low" if the report explicitly mentions involvement of the lower rectum.
110 - Return "Not Mentioned" if the location of the tumour is not explicitly mentioned.
111 For t2_signal_intensity:
112 - Return "Hyperintense" if the report explicitly mentions T2 hyperintensity.
113 - Return "Hypointense" if the report explicitly mentions T2 hypointensity.
114 - Return "Intermediate" if the report explicitly mentions T2 intermediate signal.
115 - Return "Mixed signal" if the report explicitly mentions mixed T2 signal (e.g., intermediate + hypointense).
116 - Return "Not Mentioned" if the T2-weighted signal characteristics are not explicitly mentioned.
117 For dwi:
118 - Return "Restricted diffusion" if the report explicitly mentions Restricted diffusion.
119 - Return "Facilitated diffusion" if the report explicitly mentions Facilitated diffusion.
120 - Return "Mixed" if the report explicitly mentions both restricted and facilitated.
121 - Return "No restricted diffusion" if the report explicitly mentions no restricted diffusion.
122 - Return "Not Mentioned" if the diffusion behavior in DWI imaging is not explicitly mentioned.
123 For morphology:
124 - Return "Polypoidal" if the report explicitly mentions polypoidal or described as projecting or exophytic.
125 - Return "Ulcerative" if the report explicitly mentions ulcerative or surface breakdown or ulceration is mentioned.
126 - Return "Infiltrative" if the report explicitly mentions infiltrative, infiltrated, or the tumor invades surrounding tissues diffusely..
127 - Return "Mixed" if two or more patterns above are clearly described. (e.g., Polypoidal + Ulcerative)
128 - Return "Not Mentioned" if the tumor morphology is not explicitly mentioned.
129 For radial_extent:
130 - Return "Annular or Circumferential" if the report explicitly mentions Annular or Circumferential.
131 - Return "Semi-Annular or Hemi-Circumferential" if the report explicitly mentions Semi-Annular or Hemi-Circumferential.
132 - Return “Not Mentioned” if the report does not mention annular, semi-annular, circumferential, or hemi-circumferential.
133 For crm_or_mrf_involvement:
134 - Return "Yes" if the distance to the mesorectal fascia is explicitly reported as less than 1 mm.
135 - Return "No" if the distance to the mesorectal fascia is explicitly reported as greater than or equal to 1 mm.
136 - Return "Not Mentioned" if the distance to the mesorectal fascia is not mentioned.
137 For emvi:
138 - Return "Yes" if the EMVI is present and not mentioned as fibrosed, healed.
139 - Return "No" if the EMVI is mentioned as fibrosed, healed, resolved, absent, or nil.
140 - Return "Not Mentioned" if the EMVI is not explicitly mentioned.
141 For tumour_deposit:
142 - Return "Yes" if the report explicitly mentions the presence of tumour deposits.
143 - Return "No" if the report explicitly mentions the absence of tumour deposits.
144 - Return "Not Mentioned" if tumour deposit (TD) or ENTD (extranodal tumor deposit) are not explicitly mentioned.
145 For is_t4a:
146 - Return "Yes" if the tumor invasion of the pelvic peritoneal reflection is explicitly mentioned.
147 - Return "No" if the pelvic peritoneal reflection is not involved, or confirms that the tumor is below the peritoneal reflection.
148 - Return "Not Mentioned" if the pelvic peritoneal reflection is not mentioned.
149 For obstruction:
150 - Return 'Yes' if the report explicitly links rectal perforation to obstruction.
151 - Return 'No' if perforation is mentioned but no causal link to obstruction is mentioned.
152 - Return 'Not Mentioned' if neither perforation nor its causal link to obstruction is discussed in the report.
153 For perforation:
154 - Return 'Yes' if the report mentioned any rectal perforation.
155 - Return 'No' if the report explicitly mentioned as perforation not involved.
156 - Return 'Not Mentioned' if perforation is not mentioned in the report.
157 For is_thick_t2_hypointense_band:
158 - Return 'Yes' if the report mentions the presence of a thick T2 hypointense band.
159 - Return 'No' if the report mentions the absence of a thick T2 hypointense band.
160 - Return 'Not Mentioned' if the report does not mention a thick T2 hypointense band.
161 For is_thin_t2_hypointense_band:
162 - Return 'Yes' if the report mentions the presence of a thin T2 hypointense band.
163 - Return 'No' if the report mentions the absence of a thin T2 hypointense band.
164 - Return 'Not Mentioned' if the report does not mention a thin T2 hypointense band.
165 For is_residual_tumor_as_first_mri:
166 - Return 'Yes' if the signal characteristics of the residual tumor are explicitly compared to a previous or first MRI and it is stated that they are similar or unchanged.
167 - Return 'No' if the report explicitly states there is no comparison to prior MRI or baseline MRI.
168 - Return 'Not Mentioned' if the report does not mention any comparison to prior MRI.
169 For is_mucin_reaction_t2_hyper_hypo_post_treatment:
170 - Return “Yes” if the report mentions a mucin reaction or describes a T2 hyperintense focus within hypointense post-treatment change.
171 - Return “No” if the report explicitly states the absence of a mucin reaction and does not describe a T2 hyperintense focus within hypointense post-treatment change.
172 - Return “Not Mentioned” if the report does not mention a mucin reaction and does not describe a T2 hyperintense focus within hypointense post-treatment change.
173 For uterus:
174 - Return 'Yes' if the tumor infiltration of the uterus explicitly mentioned.
175 - Return 'No' if the report explicitly mentioned there is no involvement.
176 - Return "Not Applicable" if the prostate or seminal vesicle is mentioned, or the patient gender is mentioned as male.
177 - Return 'Not Mentioned' if the uterus is not mentioned in the report.
178 For vagina:
179 - Return 'Yes' if the tumor infiltration of the vagina explicitly mentioned.
180 - Return 'No' if the report explicitly mentioned there is no involvement.
181 - Return "Not Applicable" if the prostate or seminal vesicle is mentioned, or the patient gender is mentioned as male.
182 - Return 'Not Mentioned' if the vagina is not mentioned in the report.
183 For ovaries:
184 - Return 'Yes' if the tumor infiltration of the ovaries explicitly mentioned.
185 - Return 'No' if the report explicitly mentioned there is no involvement.
186 - Return "Not Applicable" if the prostate or seminal vesicle is mentioned, or the patient gender is mentioned as male.
187 - Return 'Not Mentioned' if the ovaries is not mentioned in the report.
188 For prostate:
189 - Return 'Yes' if the tumor infiltration of the prostate explicitly mentioned.
190 - Return 'No' if the report explicitly mentioned there is no involvement.
191 - Return "Not Applicable" if the uterus, vagina, or ovaries is mentioned, or the patient gender is mentioned as female.
192 - Return 'Not Mentioned' if the prostate is not mentioned in the report.
193 For seminal_vesicles:
194 - Return 'Yes' if the tumor infiltration of the seminal vesicles explicitly mentioned.
195 - Return 'No' if the report explicitly mentioned there is no involvement.
196 - Return "Not Applicable" if the uterus, vagina, or ovaries is mentioned, or the patient gender is mentioned as female.
197 - Return 'Not Mentioned' if the seminal vesicles is not mentioned in the report.
198 For levator_ani:
199 - Return 'Yes' if the tumor infiltrates the levator ani.
200 - Return 'No' if the report states the levator ani is not infiltrated.
201 - Return 'Not Mentioned' if the levator ani is not mentioned in the report.
202 For puborectalis:
203 - Return 'Yes' if the tumor infiltrates the puborectalis.
204 - Return 'No' if the report states the puborectalis is not infiltrated or "no infiltration of puborectalis".
205 - Return 'Not Mentioned' if the puborectalis is not mentioned in the report.
206 For piriformis:
207 - Return 'Yes' if the tumor infiltrates the piriformis.
208 - Return 'No' if the report states the piriformis is not infiltrated.
209 - Return 'Not Mentioned' if the piriformis is not mentioned in the report.
210 For obturator_internus:
211 - Return 'Yes' if the tumor infiltrates the obturator internus.
212 - Return 'No' if the report states the obturator internus is not infiltrated.
213 - Return 'Not Mentioned' if the obturator internus is not mentioned in the report.
214 For obturator_externus:
215 - Return 'Yes' if the tumor infiltrates the obturator externus.
216 - Return 'No' if the report states the obturator externus is not infiltrated.
217 - Return 'Not Mentioned' if the obturator externus is not mentioned in the report.
218 For ureter:
219 - Return 'Yes' if the tumor infiltrates the ureter.
220 - Return 'No' if the report states the ureter is not infiltrated.
221 - Return 'Not Mentioned' if the ureteric infiltration is not mentioned in the report.
222 For internal_sphincter:
223 - Return 'Yes' if the tumor infiltrates the internal sphincter.
224 - Return 'No' if the report states the internal sphincter is not infiltrated or "no infiltration of anal sphincter complex",.
225 - Return 'Not Mentioned' if the internal sphincter is not mentioned in the report.
226 For external_sphincter:
227 - Return 'Yes' if the tumor infiltrates the external sphincter.
228 - Return 'No' if the report states the external sphincter is not infiltrated or "no infiltration of anal sphincter complex",.
229 - Return 'Not Mentioned' if the external sphincter is not mentioned in the report.
230 For inter_sphincteric_plane:
231 - Return 'Yes' if the tumor infiltrates the inter-sphincteric plane.
232 - Return 'No' if the report states the inter-sphincteric plane is not infiltrated or "no infiltration of anal sphincter complex",.
233 - Return 'Not Mentioned' if the inter-sphincteric plane is not mentioned in the report.
234 For ischiorectal_foss:
235 - Return 'Yes' if the tumor infiltrates the ischiorectal fossa.
236 - Return 'No' if the report states the ischiorectal fossa is not infiltrated or "no infiltration of anal sphincter complex",.
237 - Return 'Not Mentioned' if the ischiorectal fossa is not mentioned in the report.
238 For fistula_in_ano:
239 - Return 'Yes' if the tumor infiltrates the fistula in ano.
240 - Return 'No' if the report states the fistula in ano is not infiltrated or "no infiltration of anal sphincter complex",.
241 - Return 'Not Mentioned' if the fistula in ano is not mentioned in the report.
242 For t_stage:
243 - Return "T0" if it is explicitly mentioned that "T0", no tumor is seen or MR TRG is 1, even if T0 is not explicitly mentioned.
244 - Return "T1" if it is explicitly mentioned that "T1".
245 - Return "T2" if it is explicitly mentioned that "T2".
246 - Return "T3a" if it is explicitly mentioned that "T3a" or if extramural spread size is less than or equal to 1 mm (≤1 mm).
247 - Return "T3b" if it is explicitly mentioned that "T3b" or if extramural spread size is between 1 mm to 5 mm (>1 mm to ≤5 mm).
248 - Return "T3c" if it is explicitly mentioned that "T3c" or if extramural spread size is between 5 mm to 15 mm (>5 mm to ≤15 mm).
249 - Return "T3d" if it is explicitly mentioned that "T3d" or if extramural spread size is more than 15 mm (>15 mm).
250 - Return "T4a" if it is explicitly mentioned that "T4a" or if the tumor penetrates the visceral peritoneum or perforates the high or mid rectum.
251 - Return "T4b" if it is explicitly mentioned that "T4b" or if the report is a complete response and the MR TRG 1, should not return "T4b".
252 - Return 'Not Mentioned' if the tumour stage is not mentioned in the report.
253 For n_stage:
254 - Return "N0" if there is no mention of involved lymph nodes in mesorectal, internal iliac, or obturator regions.
255 - Return "N1" if 1 to 3 regional lymph nodes are described as suspicious, involved, enlarged, or metastatic, and are located in the mesorectal, internal iliac, or obturator regions.
256 - Return "N1c" if the report mentions tumor deposits or extranodal tumor deposits in perirectal or surrounding tissue, and does not mention identifiable metastatic lymph nodes.
257 - Return "N2" if 4 or more regional lymph nodes (from the same locations above) are described as involved, suspicious, or metastatic.
258 - Return 'Not Mentioned' if the report does not clearly indicate whether lymph nodes are involved or not, or if the number, location, or significance of the lymph nodes cannot be determined.
259 For m_stage:
260 - Return "M0" if it is explicitly mentioned that "M0", or there is no mention of regional lymph nodes or the report explicitly states "no distant metastases" or "no evidence of metastasis".
261 - Return "M1a" if it is explicitly mentioned that "M1a", or the report describes metastasis to only one distant organ or non-regional lymph node, and no peritoneal involvement is mentioned.
262 - Return "M1b" if it is explicitly mentioned that "M1b", or two separate distant organs are involved (e.g., liver and lung).
263 - Return "M1c" if it is explicitly mentioned that "M1c" or the peritoneum is involved in two or more sites or there is metastasis to the peritoneum plus at least one organ.
264 - Return 'Not Mentioned' if the report does not clearly mention the presence or absence of distant metastasis or 'Mx' mentioned in the report.
265 For mr_trg:
266 - Return "MR TRG 1" if the tumor is not visible and there is a thin T2 hypointense band with no restricted diffusion.
267 - Return "MR TRG 2" if there is a thick T2 hypointense band with minimal residual tumor and few restricted diffusion foci.
268 - Return "MR TRG 3" if there is a residual tumor with intermediate signal and >50% fibrosis.
269 - Return "MR TRG 4" if there is little fibrosis (<50%) and the tumor appears mostly viable.
270 - Return "MR TRG 5" if the tumor is unchanged from before treatment or has progressed.
271 - Return 'Not Mentioned' if the necessary imaging descriptors are not present or not sufficient to confidently determine the grade.
272 For response:
273 - Return 'Complete' if the MR Tumour Regression Grade is 1.
274 - Return 'Near Complete' if the MR Tumour Regression Grade is 2.
275 - Return 'Incomplete' if the MR Tumour Regression Grade is 3, 4, or 5.
276 - Return 'Not Mentioned' if the MR Tumour Regression Grade not mentioned in the report.
277
278 OUTPUT FORMAT:
279 {{
280 "gender": "Male, Female, or Not Mentioned",
281 "age": "<AGE STRING>",
282 "current_length_of_tumour": "<LENGTH OF TUMOUR>",
283 "distance_from_anal_verge": "<VALUE>",
284 "distance_from_anorectal_junction": "<VALUE>",
285 "extramural_spread_size": "<VALUE>",
286 "mr_crm_distance": "<VALUE>",
287 "number_of_mesorectal_nodes": "<COUNT>",
288 "internal_iliac_nodes": "<VALUE>",
289 "size_of_obturator_nodes": "<VALUE>",
290 "size_of_inguinal": "<VALUE>",
291 "size_of_external_iliac": "<VALUE>",
292 "size_of_common_iliac": "<VALUE>",
293 "size_of_para_aortic": "<VALUE>",
294 "is_first_mri_report": "Yes, No, Not Mentioned",
295 "is_restaging_mri_report": "Yes, No, Not Mentioned",
296 "is_mri_report_after_neoadjuvant": "Yes, No, Not Mentioned",
297 "is_post_treatment_mri_report": "Yes, No, Not Mentioned",
298 "is_post_operative_mri": "Yes, No, Not Mentioned",
299 "location_of_tumour": "High, Mid, Low, or Not Mentioned",
300 "t2_signal_intensity": "Hyperintense, Hypointense, Intermediate, Mixed signal, or Not Mentioned",
301 "dwi": "Restricted diffusion, Facilitated diffusion, Mixed, No restricted diffusion, or Not Mentioned",
302 "morphology": "Polypoidal, Ulcerative, Infiltrative, Mixed, or Not Mentioned",
303 "radial_extent": "Annular or Circumferential, Semi-Annular or Hemi-Circumferential, or Not Mentioned",
304 "crm_or_mrf_involvement": "Yes, No, or Not Mentioned",
305 "emvi": "Yes, No, or Not Mentioned",
306 "tumour_deposit": "Yes, No, or Not Mentioned",
307 "is_t4a": "Yes, No, or Not Mentioned",
308 "obstruction": "Yes, No or Not Mentioned",
309 "perforation": "Yes, No or Not Mentioned",
310 "is_thick_t2_hypointense_band": "Yes, No or Not Mentioned"
311 "is_thin_t2_hypointense_band": "Yes, No or Not Mentioned"
312 "is_residual_tumor_as_first_mri": "Yes, No or Not Mentioned"
313 "is_mucin_reaction_t2_hyper_hypo_post_treatment": "Yes, No or Not Mentioned",
314 "uterus": "Yes, No, Not Applicable or Not Mentioned",
315 "vagina": "Yes, No, Not Applicable or Not Mentioned",
316 "ovaries": "Yes, No, Not Applicable or Not Mentioned",
317 "prostate": "Yes, No, Not Applicable or Not Mentioned",
318 "seminal_vesicles": "Yes, No, Not Applicable or Not Mentioned",
319 "levator_ani": "Yes, No or Not Mentioned",
320 "puborectalis": "Yes, No or Not Mentioned",
321 "piriformis": "Yes, No or Not Mentioned",
322 "obturator_internus": "Yes, No or Not Mentioned",
323 "obturator_externus": "Yes, No or Not Mentioned",
324 "ureter": "Yes, No or Not Mentioned",
325 "internal_sphincter": "Yes, No or Not Mentioned",
326 "external_sphincter": "Yes, No or Not Mentioned",
327 "inter_sphincteric_plane": "Yes, No or Not Mentioned",
328 "ischiorectal_foss": "Yes, No or Not Mentioned",
329 "fistula_in_ano": "Yes, No or Not Mentioned",
330 "t_stage": "T0, T1, T2, T3a, T3b, T3c, T3d, T4a, T4b, or Not Mentioned",
331 "n_stage": "N0, N1, N1c, N2, or Not Mentioned",
332 "m_stage": "M0, M1a, M1b, M1c, or Not Mentioned",
333 "mr_trg": "MR TRG 1, MR TRG 2, MR TRG 3, MR TRG 4, MR TRG 5, or Not Mentioned",
334 "response": "Complete, Near Complete, Incomplete, or Not Mentioned"
335 }}
336 """
337 user_content = f"""
338 REPORT:
339 {text}
340 """
341 messages = [
342 {"role": "system", "content": system_prompt},
343 {"role": "user", "content": user_content},
344 ]
345 return messages
346
347
348input = """
349MRI ABDOMEN AND PELVIS Clinical data : A 59 year old with carcinoma rectum, post treatment on follow up. Comparison : Previous MRI dated 6/02/2023 FINDINGS: LIVER - Normal size. No focal lesions or IHBR dilatation. SPLEEN -No significant abnormality. GB - No calculus. PANCREAS -Nil significant ADRENALS -No significant abnormality. KIDNEYS - Bilateral tiny renal cortical cysts. No hydronephrosis . BOWEL, MESENTERY, OMENTUM -Mild circumferential wall thickening of the low rectum with no foci of T2 intermediate signal intensity or restricted diffusion in this segment - Likely post RT changes Interspincteric fistula with internal opening at 3, Oclock position in high anal canal, 17mm from anal verge. External opening is not clearly seen. LYMPHADENOPATHY - No significant nodes. FLUID - No free fluid BLADDER -Nil significant PROSTATE/ SEMINAL VESCICLES: Nil significant INGUINAL ORIFICES -Nil significant ABDOMINAL WALL -Nil significant BLOOD VESSELS -Nil significant VISUALISED LUNG BASES -Nil significant VISUALISED BONES -T2/SPAIR hyperintensity in bilateral sacral ala is likely post RT osteitis IMPRESSION : A 59 year old with carcinoma rectum post treatment follow up Wait and watch, MRI shows: 1. Post treatment changes in the low rectum with no evidence of residual/recurrent tumor. 2. No significant lymphadenopathy. 3. T2/SPAIR hyperintensity in bilateral sacral ala is likely post RT osteitis 4. Simple inter-sphincteric fistula with internal opening at 3'Oclock position in high anal canal, 17mm from anal verge. External opening is not clearly seen.
350"""
351
352prompt = all_question_getter(input)
353
354formatted_text = tokenizer.apply_chat_template(
355 prompt,
356 tokenize=False,
357 add_generation_prompt=False
358)
359
360tokenized = tokenizer(
361 formatted_text,
362 return_tensors="pt",
363 padding=True,
364 truncation=True
365)
366input_ids = torch.tensor(tokenized["input_ids"][0]).unsqueeze(0).to(model.device)
367attention_mask = torch.tensor(tokenized["attention_mask"][0]).unsqueeze(0).to(model.device)
368with torch.no_grad():
369 output_ids = model.generate(
370 input_ids=input_ids,
371 attention_mask=attention_mask,
372 max_new_tokens=2048,
373 do_sample=False,
374 eos_token_id=terminators[0],
375 pad_token_id=tokenizer.pad_token_id
376 )
377decoded = tokenizer.decode(output_ids[0], skip_special_tokens=True)
378decoded = decoded.split("assistant")[-1].strip()
379print(decoded)
380