dogoodson commited on
Commit
95f98b6
·
1 Parent(s): c4d8e9b

Initialize project 1

Browse files
Files changed (3) hide show
  1. Project1.ipynb +0 -1
  2. Project1Demo.ipynb +0 -0
  3. requirements.txt +2 -2
Project1.ipynb DELETED
@@ -1 +0,0 @@
1
- {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyOgOHaJj1Rz/PtcwjNbfMyX"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"},"widgets":{"application/vnd.jupyter.widget-state+json":{"8abe534570f446de88127cfefbb0b34b":{"model_module":"@jupyter-widgets/controls","model_name":"HBoxModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_fd980ea7952740b7a5018226f969a9a9","IPY_MODEL_2ed8bd4773024328baba879d6b9119af","IPY_MODEL_7a2635bd4d284d03a80297bac1987796"],"layout":"IPY_MODEL_956376c3f9684d1498a8b80c51d61ca1"}},"fd980ea7952740b7a5018226f969a9a9":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_010995bf495a4e5c86b2035933bea864","placeholder":"​","style":"IPY_MODEL_cf0154a9839d4522a2699d38f8c62b09","value":"Loading weights: 100%"}},"2ed8bd4773024328baba879d6b9119af":{"model_module":"@jupyter-widgets/controls","model_name":"FloatProgressModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"ProgressView","bar_style":"success","description":"","description_tooltip":null,"layout":"IPY_MODEL_7983d5fb6231494d9970deb9b2fedbdd","max":131,"min":0,"orientation":"horizontal","style":"IPY_MODEL_b6b96afe02064dd280c113cb099e461c","value":131}},"7a2635bd4d284d03a80297bac1987796":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_335fc6548abb4cc8ad321fafb89e1cb9","placeholder":"​","style":"IPY_MODEL_6c7024bdab3044a6a030d9b113ddbd89","value":" 131/131 [00:00&lt;00:00, 287.16it/s, Materializing param=shared.weight]"}},"956376c3f9684d1498a8b80c51d61ca1":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"010995bf495a4e5c86b2035933bea864":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"cf0154a9839d4522a2699d38f8c62b09":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"7983d5fb6231494d9970deb9b2fedbdd":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"b6b96afe02064dd280c113cb099e461c":{"model_module":"@jupyter-widgets/controls","model_name":"ProgressStyleModel","model_module_version":"1.5.0","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"335fc6548abb4cc8ad321fafb89e1cb9":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"6c7024bdab3044a6a030d9b113ddbd89":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}}}}},"cells":[{"cell_type":"markdown","source":["Install and Import Transformers & Gradio\n"],"metadata":{"id":"qHg18TkYvg_Z"}},{"cell_type":"code","execution_count":134,"metadata":{"id":"wFTaipZ6u3-K","executionInfo":{"status":"ok","timestamp":1775581944259,"user_tz":240,"elapsed":6063,"user":{"displayName":"Donnie G","userId":"08794454185807289257"}}},"outputs":[],"source":["# Install and import\n","!pip install -q gradio datasets transformers\n","from datasets import load_dataset\n","from transformers import pipeline\n","import gradio as gr\n"]},{"cell_type":"markdown","source":["Load clinical note data"],"metadata":{"id":"t01ciTyuye1x"}},{"cell_type":"code","source":["# Print the columns in this dataset and a sample entry.\n","from datasets import load_dataset\n","ds = load_dataset(\"AGBonnet/augmented-clinical-notes\")\n"],"metadata":{"id":"9TAqXmpuyydg","executionInfo":{"status":"ok","timestamp":1775587739138,"user_tz":240,"elapsed":589,"user":{"displayName":"Donnie G","userId":"08794454185807289257"}}},"execution_count":169,"outputs":[]},{"cell_type":"markdown","source":["(Optional) View the Columns in the loaded dataset"],"metadata":{"id":"i8mXndc6Hyng"}},{"cell_type":"code","source":["print(\"Columns:\", ds['train'].column_names)\n","# Print truncated example to inspect content\n","for k in ds['train'].column_names:\n"," print(k, \":\", str(ds['train'][0][k])[:400], \"\\n---\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"IIXuf4YyHxRr","executionInfo":{"status":"ok","timestamp":1775589217734,"user_tz":240,"elapsed":10,"user":{"displayName":"Donnie G","userId":"08794454185807289257"}},"outputId":"31079bde-51a9-41e7-a038-481f18e2d458"},"execution_count":194,"outputs":[{"output_type":"stream","name":"stdout","text":["Columns: ['idx', 'note', 'full_note', 'conversation', 'summary']\n","idx : 155216 \n","---\n","note : A a sixteen year-old girl, presented to our Outpatient department with the complaints of discomfort in the neck and lower back as well as restriction of body movements. She was not able to maintain an erect posture and would tend to fall on either side while standing up from a sitting position. She would keep her head turned to the right and upwards due to the sustained contraction of the neck mus \n","---\n","full_note : A a sixteen year-old girl, presented to our Outpatient department with the complaints of discomfort in the neck and lower back as well as restriction of body movements. She was not able to maintain an erect posture and would tend to fall on either side while standing up from a sitting position. She would keep her head turned to the right and upwards due to the sustained contraction of the neck mus \n","---\n","conversation : Doctor: Good morning, what brings you to the Outpatient department today?\n","Patient: Good morning doctor, I have some discomfort in my neck and lower back, and I'm not able to maintain an erect posture.\n","Doctor: Hmm, okay. Can you tell me more about the discomfort?\n","Patient: Yes, I tend to fall on either side when I stand up from a sitting position, and my head is always turned to the right and upward \n","---\n","summary : {\n","\"visit motivation\": \"Discomfort in the neck and lower back, restriction of body movements, inability to maintain an erect posture, and requiring assistance in standing and walking.\",\n","\"admission\": [\n","{\n","\"reason\": \"None\",\n","\"date\": \"None\",\n","\"duration\": \"None\",\n","\"care center details\": \"None\"\n","}\n","],\n","\"patient information\": {\n","\"age\": \"Sixteen years old\",\n","\"sex\": \"Female\",\n","\"ethnicity\": \"None\",\n","\"weight\": \"None\",\n"," \n","---\n"]}]},{"cell_type":"code","source":["def load_json_with_status(raw):\n"," import json\n"," try:\n"," parsed = json.loads(raw)\n"," return True, parsed\n"," except:\n"," return False, raw\n"],"metadata":{"id":"-GT68a4LqhkY","executionInfo":{"status":"ok","timestamp":1775577776884,"user_tz":240,"elapsed":10,"user":{"displayName":"Donnie G","userId":"08794454185807289257"}}},"execution_count":65,"outputs":[]},{"cell_type":"markdown","source":["View samples of Clinical Notes"],"metadata":{"id":"mIBTAy9TYc0Y"}},{"cell_type":"code","source":["train = ds[\"train\"]\n","sampleLengthTrain = min(5, len(ds['train']))\n","print(\"length=\",sampleLengthTrain)\n","patientSample = {} # Dictionary keyed by patient ID\n","\n","for i in range(sampleLengthTrain):\n"," ##print(\"full_note:\", repr(str(ds['train'][i]['full_note'])))\n"," # A JSON summary contains multiple sections describing the patient's problem and the prescribed tests.\n","\n"," patientJsonSummaryStr = ds['train'][i]['summary']\n"," patientIdx = ds['train'][i]['idx']\n"," patientNote = ds['train'][i]['note']\n"," success, parsedJsonSummary = load_json_with_status(patientJsonSummaryStr);\n"," if success:\n"," motivation = parsedJsonSummary['visit motivation']\n"," patientSample[patientIdx] = {'note': patientNote, 'visit motivation': motivation, 'summary': parsedJsonSummary}\n"," print(\"idx:\", ds['train'][i]['idx'], \"summary:\", repr(str(patientJsonSummaryStr)))\n"," # otherwise, skip the record with invalid JSON.\n","print(\"Done. patientSample=\", len(patientSample))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"hYGVUApvxp6q","executionInfo":{"status":"ok","timestamp":1775589544915,"user_tz":240,"elapsed":45,"user":{"displayName":"Donnie G","userId":"08794454185807289257"}},"outputId":"f24f94d2-193b-44af-bbf5-0587c4957a5b"},"execution_count":199,"outputs":[{"output_type":"stream","name":"stdout","text":["length= 5\n","idx: 155216 summary: '{\\n\"visit motivation\": \"Discomfort in the neck and lower back, restriction of body movements, inability to maintain an erect posture, and requiring assistance in standing and walking.\",\\n\"admission\": [\\n{\\n\"reason\": \"None\",\\n\"date\": \"None\",\\n\"duration\": \"None\",\\n\"care center details\": \"None\"\\n}\\n],\\n\"patient information\": {\\n\"age\": \"Sixteen years old\",\\n\"sex\": \"Female\",\\n\"ethnicity\": \"None\",\\n\"weight\": \"None\",\\n\"height\": \"None\",\\n\"family medical history\": \"None\",\\n\"recent travels\": \"None\",\\n\"socio economic context\": \"None\",\\n\"occupation\": \"None\"\\n},\\n\"patient medical history\": {\\n\"physiological context\": \"None\",\\n\"psychological context\": \"Diagnosed with bipolar affective disorder at the age of eleven, first episode was that of mania.\",\\n\"vaccination history\": \"None\",\\n\"allergies\": \"None\",\\n\"exercise frequency\": \"None\",\\n\"nutrition\": \"None\",\\n\"sexual history\": \"None\",\\n\"alcohol consumption\": \"None\",\\n\"drug usage\": \"None\",\\n\"smoking status\": \"None\"\\n},\\n\"surgeries\": [\\n{\\n\"reason\": \"None\",\\n\"Type\": \"None\",\\n\"time\": \"None\",\\n\"outcome\": \"None\",\\n\"details\": \"None\"\\n}\\n],\\n\"symptoms\": [\\n{\\n\"name of symptom\": \"Discomfort in the neck and lower back, restriction of body movements, inability to maintain an erect posture\",\\n\"intensity of symptom\": \"None\",\\n\"location\": \"Neck and lower back\",\\n\"time\": \"Past four months\",\\n\"temporalisation\": \"None\",\\n\"behaviours affecting the symptom\": \"Standing up from a sitting position\",\\n\"details\": \"Head turned to the right and upwards due to sustained contraction of neck muscles, sideways bending of the back in the lumbar region, limbs positioned to support body weight.\"\\n}\\n],\\n\"medical examinations\": [\\n{\\n\"name\": \"None\",\\n\"result\": \"None\",\\n\"details\": \"None\"\\n}\\n],\\n\"diagnosis tests\": [\\n{\\n\"test\": \"None\",\\n\"severity\": \"None\",\\n\"result\": \"None\",\\n\"condition\": \"None\",\\n\"time\": \"None\",\\n\"details\": \"None\"\\n}\\n],\\n\"treatments\": [\\n{\\n\"name\": \"Olanzapine tablets\",\\n\"related condition\": \"Bipolar affective disorder\",\\n\"dosage\": \"5 mg per day\",\\n\"time\": \"Past four months\",\\n\"frequency\": \"Daily\",\\n\"duration\": \"None\",\\n\"reason for taking\": \"Control of exacerbated mental illness\",\\n\"reaction to treatment\": \"Pain and discomfort in neck, sustained and abnormal contraction of neck muscles, requiring assistance in daily chores\",\\n\"details\": \"Previously managed with olanzapine tablets in 2.5–10 mg doses per day at different times over the past seven years.\"\\n},\\n{\\n\"name\": \"Trihexyphenidyl\",\\n\"related condition\": \"Rigidity in upper limbs\",\\n\"dosage\": \"4 mg per day\",\\n\"time\": \"Brief period of around three weeks\",\\n\"frequency\": \"Daily\",\\n\"duration\": \"None\",\\n\"reason for taking\": \"Rigidity in upper limbs\",\\n\"reaction to treatment\": \"Good response\",\\n\"details\": \"None\"\\n}\\n],\\n\"discharge\": {\\n\"reason\": \"None\",\\n\"referral\": \"None\",\\n\"follow up\": \"None\",\\n\"discharge summary\": \"None\"\\n}\\n}'\n","idx: 133948 summary: '{\\n\"visit motivation\": \"Pain and restricted range of motion in the left hip joint\",\\n\"admission\": [\\n{\\n\"reason\": \"Idiopathic osteonecrosis of the femoral head\",\\n\"date\": \"None\",\\n\"duration\": \"Three weeks\",\\n\"care center details\": \"None\"\\n},\\n{\\n\"reason\": \"Pain and limited ROM in the contralateral hip joint and gait disturbance\",\\n\"date\": \"One year after the initial surgery\",\\n\"duration\": \"None\",\\n\"care center details\": \"None\"\\n}\\n],\\n\"patient information\": {\\n\"age\": \"36 years old\",\\n\"sex\": \"Female\",\\n\"ethnicity\": \"None\",\\n\"weight\": \"7 kg heavier than at the time of the first procedure\",\\n\"height\": \"None\",\\n\"family medical history\": \"None\",\\n\"recent travels\": \"None\",\\n\"socio economic context\": \"None\",\\n\"occupation\": \"None\"\\n},\\n\"patient medical history\": {\\n\"physiological context\": \"None\",\\n\"psychological context\": \"Intensifying feelings of helplessness\",\\n\"vaccination history\": \"None\",\\n\"allergies\": \"None\",\\n\"exercise frequency\": \"None\",\\n\"nutrition\": \"None\",\\n\"sexual history\": \"None\",\\n\"alcohol consumption\": \"None\",\\n\"drug usage\": \"None\",\\n\"smoking status\": \"None\"\\n},\\n\"surgeries\": [\\n{\\n\"reason\": \"Idiopathic osteonecrosis of the femoral head\",\\n\"Type\": \"Total Hip Arthroplasty (THA)\",\\n\"time\": \"After diagnosis\",\\n\"outcome\": \"Discharged in good condition without specific complications\",\\n\"details\": \"First THA on the left hip\"\\n},\\n{\\n\"reason\": \"Pain and limited ROM in the contralateral hip joint\",\\n\"Type\": \"Total Hip Arthroplasty (THA)\",\\n\"time\": \"One year after the first THA\",\\n\"outcome\": \"Discharged in good condition without specific complications\",\\n\"details\": \"Second THA on the contralateral hip\"\\n}\\n],\\n\"symptoms\": [\\n{\\n\"name of symptom\": \"Pain\",\\n\"intensity of symptom\": \"Severe\",\\n\"location\": \"Left hip joint\",\\n\"time\": \"Persisting for two months\",\\n\"temporalisation\": \"Increased over the following three weeks\",\\n\"behaviours affecting the symptom\": \"Aggravated by hip joint flexion or rotation\",\\n\"details\": \"Also complained of pain and limited ROM in the contralateral hip joint one year after initial surgery\"\\n},\\n{\\n\"name of symptom\": \"Restricted range of motion\",\\n\"intensity of symptom\": \"None\",\\n\"location\": \"Left hip joint\",\\n\"time\": \"Persisting for two months\",\\n\"temporalisation\": \"None\",\\n\"behaviours affecting the symptom\": \"None\",\\n\"details\": \"None\"\\n},\\n{\\n\"name of symptom\": \"Gait disturbance\",\\n\"intensity of symptom\": \"Severe\",\\n\"location\": \"None\",\\n\"time\": \"None\",\\n\"temporalisation\": \"None\",\\n\"behaviours affecting the symptom\": \"Secondary to hip pain\",\\n\"details\": \"Continued for two months and increased over the following three weeks\"\\n},\\n{\\n\"name of symptom\": \"Moderate moon face\",\\n\"intensity of symptom\": \"Moderate\",\\n\"location\": \"Face\",\\n\"time\": \"At the time of the second surgery\",\\n\"temporalisation\": \"None\",\\n\"behaviours affecting the symptom\": \"None\",\\n\"details\": \"Initially overlooked as weight gain\"\\n},\\n{\\n\"name of symptom\": \"Central obesity\",\\n\"intensity of symptom\": \"None\",\\n\"location\": \"Central body\",\\n\"time\": \"Aggravated over a three-month period of outpatient follow-up after the second surgery\",\\n\"temporalisation\": \"None\",\\n\"behaviours affecting the symptom\": \"None\",\\n\"details\": \"None\"\\n},\\n{\\n\"name of symptom\": \"Muscle mass reduction\",\\n\"intensity of symptom\": \"None\",\\n\"location\": \"Both the upper and lower limbs\",\\n\"time\": \"Aggravated over a three-month period of outpatient follow-up after the second surgery\",\\n\"temporalisation\": \"None\",\\n\"behaviours affecting the symptom\": \"None\",\\n\"details\": \"None\"\\n}\\n],\\n\"medical examinations\": [\\n{\\n\"name\": \"Physical examination\",\\n\"result\": \"Severe gait disturbance secondary to hip pain\",\\n\"details\": \"Aggravated by hip joint flexion or rotation\"\\n},\\n{\\n\"name\": \"Anteroposterior view of the left hip\",\\n\"result\": \"Sclerosis and collapse of the femoral head and dysplasia of the hip\",\\n\"details\": \"None\"\\n}\\n],\\n\"diagnosis tests\": [\\n{\\n\"test\": \"Magnetic resonance imaging (MRI) scan\",\\n\"severity\": \"None\",\\n\"result\": \"Increased amount of joint fluid and bone marrow edema in the left hip, and femoral head necrosis on the contralateral side\",\\n\"condition\": \"Idiopathic osteonecrosis of the femoral head\",\\n\"time\": \"None\",\\n\"details\": \"Patient did not complain of any pain on the contralateral side at the time of the first MRI\"\\n},\\n{\\n\"test\": \"Repeat MRI\",\\n\"severity\": \"None\",\\n\"result\": \"Similar findings to those noted previously in the left hip\",\\n\"condition\": \"None\",\\n\"time\": \"One year after the initial surgery and symptoms continued for two months and increased over the following three weeks\",\\n\"details\": \"None\"\\n}\\n],\\n\"treatments\": \"None\",\\n\"discharge\": {\\n\"reason\": \"Good condition post-surgery\",\\n\"referral\": \"Referred to the Department of Cardiology due to a progressive worsening of central\",\\n\"follow up\": \"Regular outpatient visits\",\\n\"discharge summary\": \"Discharged in good condition after both surgeries without specific complications\"\\n}\\n}'\n","idx: 80176 summary: '{\\n\"visit motivation\": \"Pain in the left proximal forearm after a fall\",\\n\"admission\": [\\n{\\n\"reason\": \"None\",\\n\"date\": \"None\",\\n\"duration\": \"None\",\\n\"care center details\": \"None\"\\n}\\n],\\n\"patient information\": {\\n\"age\": \"49\",\\n\"sex\": \"male\",\\n\"ethnicity\": \"None\",\\n\"weight\": \"None\",\\n\"height\": \"None\",\\n\"family medical history\": \"None\",\\n\"recent travels\": \"None\",\\n\"socio economic context\": \"None\",\\n\"occupation\": \"None\"\\n},\\n\"patient medical history\": {\\n\"physiological context\": \"History of left elbow arthrodesis performed for posttraumatic arthritis at the age of 18\",\\n\"psychological context\": \"None\",\\n\"vaccination history\": \"None\",\\n\"allergies\": \"None\",\\n\"exercise frequency\": \"None\",\\n\"nutrition\": \"None\",\\n\"sexual history\": \"None\",\\n\"alcohol consumption\": \"None\",\\n\"drug usage\": \"None\",\\n\"smoking status\": \"None\"\\n},\\n\"surgeries\": [\\n{\\n\"reason\": \"Posttraumatic arthritis\",\\n\"Type\": \"Left elbow arthrodesis\",\\n\"time\": \"At the age of 18\",\\n\"outcome\": \"None\",\\n\"details\": \"Elbow was fused at 90 degrees\"\\n},\\n{\\n\"reason\": \"Hypertrophic nonunion of ulnar shaft fracture and functional limitations of elbow arthrodesis\",\\n\"Type\": \"Repair of nonunion and conversion of elbow arthrodesis to arthroplasty\",\\n\"time\": \"Three months after the fall and subsequent conservative treatment period\",\\n\"outcome\": \"None\",\\n\"details\": \"The stem of the ulnar component would act as an intramedullary device\"\\n}\\n],\\n\"symptoms\": [\\n{\\n\"name of symptom\": \"Pain\",\\n\"intensity of symptom\": \"None\",\\n\"location\": \"Left proximal forearm\",\\n\"time\": \"After a fall\",\\n\"temporalisation\": \"None\",\\n\"behaviours affecting the symptom\": \"None\",\\n\"details\": \"Patient was tender at the proximal ulna\"\\n}\\n],\\n\"medical examinations\": [\\n{\\n\"name\": \"Physical examination\",\\n\"result\": \"No active flexion or extension at elbow, 40 degrees of pronation, 60 degrees of supination, normal motor and sensory exam at the hand\",\\n\"details\": \"Elbow was fused at 90 degrees\"\\n}\\n],\\n\"diagnosis tests\": [\\n{\\n\"test\": \"Radiographs\",\\n\"severity\": \"Minimally displaced\",\\n\"result\": \"Proximal ulnar shaft fracture\",\\n\"condition\": \"Proximal ulnar shaft fracture, hypertrophic nonunion\",\\n\"time\": \"None\",\\n\"details\": \"Elbow arthrodesis at 90 degrees with retained hardware was also noted\"\\n}\\n],\\n\"treatments\": [\\n{\\n\"name\": \"Closed treatment in a cast\",\\n\"related condition\": \"Proximal ulnar shaft fracture\",\\n\"dosage\": \"None\",\\n\"time\": \"Initially after the fall\",\\n\"frequency\": \"None\",\\n\"duration\": \"None\",\\n\"reason for taking\": \"To treat the ulnar shaft fracture\",\\n\"reaction to treatment\": \"Developed a hypertrophic nonunion\",\\n\"details\": \"None\"\\n},\\n{\\n\"name\": \"Conservative treatment\",\\n\"related condition\": \"Ulna nonunion\",\\n\"dosage\": \"None\",\\n\"time\": \"Three months after the fall\",\\n\"frequency\": \"None\",\\n\"duration\": \"An additional three months\",\\n\"reason for taking\": \"To treat the ulna nonunion\",\\n\"reaction to treatment\": \"Worsening motion through the nonunion site\",\\n\"details\": \"None\"\\n}\\n],\\n\"discharge\": {\\n\"reason\": \"None\",\\n\"referral\": \"None\",\\n\"follow up\": \"None\",\\n\"discharge summary\": \"None\"\\n}\\n}'\n","idx: 72232 summary: '{\\n\"visit motivation\": \"Recurrent attacks of pain in both knees over 1 year\",\\n\"admission\": [\\n{\\n\"reason\": \"None\",\\n\"date\": \"None\",\\n\"duration\": \"None\",\\n\"care center details\": \"Rheumatology clinic\"\\n}\\n],\\n\"patient information\": {\\n\"age\": \"47\",\\n\"sex\": \"Male\",\\n\"ethnicity\": \"None\",\\n\"weight\": \"None\",\\n\"height\": \"None\",\\n\"family medical history\": \"None\",\\n\"recent travels\": \"None\",\\n\"socio economic context\": \"None\",\\n\"occupation\": \"None\"\\n},\\n\"patient medical history\": {\\n\"physiological context\": \"None\",\\n\"psychological context\": \"None\",\\n\"vaccination history\": \"None\",\\n\"allergies\": \"None\",\\n\"exercise frequency\": \"None\",\\n\"nutrition\": \"None\",\\n\"sexual history\": \"None\",\\n\"alcohol consumption\": \"None\",\\n\"drug usage\": \"None\",\\n\"smoking status\": \"None\"\\n},\\n\"surgeries\": [\\n{\\n\"reason\": \"None\",\\n\"Type\": \"None\",\\n\"time\": \"None\",\\n\"outcome\": \"None\",\\n\"details\": \"None\"\\n}\\n],\\n\"symptoms\": [\\n{\\n\"name of symptom\": \"Pain\",\\n\"intensity of symptom\": \"Severe\",\\n\"location\": \"Medial aspect of the left knee, lateral aspect of the left knee, medial side of the right knee\",\\n\"time\": \"Over 1 year\",\\n\"temporalisation\": \"Recurrent attacks\",\\n\"behaviours affecting the symptom\": \"Increased with weight-bearing physical activity\",\\n\"details\": \"Prevented ambulation, no history of trauma, mild effusion, moderate limitation of range of motion, no erythema or increased warmth\"\\n}\\n],\\n\"medical examinations\": [\\n{\\n\"name\": \"Examination\",\\n\"result\": \"Severe tenderness over the medial side of the knee with mild effusion and moderate limitation of range of motion\",\\n\"details\": \"No erythema or increased warmth of the knee\"\\n}\\n],\\n\"diagnosis tests\": [\\n{\\n\"test\": \"MRI\",\\n\"severity\": \"Moderate-sized\",\\n\"result\": \"Focal area of marrow edema/contusion involving the medial femoral condyle, bone marrow edema involving the lateral femoral condyle, extensive marrow edema involving the medial femoral condyle\",\\n\"condition\": \"Bone marrow edema\",\\n\"time\": \"September 2016, three months later, April 2017, four months later\",\\n\"details\": \"Involvement of medial femoral condyle in mid and anterior parts predominantly along the articular surface, complete resolution of the bone marrow edema of the medial femoral condyle, involvement of the medial tibial plateau medially and anteriorly, complete recovery of the medial tibial plateau bone marrow edema\"\\n}\\n],\\n\"treatments\": [\\n{\\n\"name\": \"Diclofenac sodium\",\\n\"related condition\": \"Bone marrow edema\",\\n\"dosage\": \"50 mg\",\\n\"time\": \"September 2016\",\\n\"frequency\": \"Twice daily\",\\n\"duration\": \"None\",\\n\"reason for taking\": \"To treat knee pain\",\\n\"reaction to treatment\": \"Pain subsided and resolved\",\\n\"details\": \"Advised to avoid prolonged weight-bearing activities\"\\n},\\n{\\n\"name\": \"NSAIDs and physiotherapy\",\\n\"related condition\": \"Bone marrow edema\",\\n\"dosage\": \"None\",\\n\"time\": \"Three months after September 2016\",\\n\"frequency\": \"None\",\\n\"duration\": \"None\",\\n\"reason for taking\": \"Treatment for new onset of pain involving the lateral aspect of the left knee\",\\n\"reaction to treatment\": \"None\",\\n\"details\": \"Advised to use cane to minimize weight bearing on the diseased knee\"\\n},\\n{\\n\"name\": \"Conservative treatment\",\\n\"related condition\": \"Bone marrow edema\",\\n\"dosage\": \"None\",\\n\"time\": \"April 2017\",\\n\"frequency\": \"None\",\\n\"duration\": \"None\",\\n\"reason for taking\": \"Treatment for gradual pain over the medial side of the right knee\",\\n\"reaction to treatment\": \"None\",\\n\"details\": \"None\"\\n}\\n],\\n\"discharge\": {\\n\"reason\": \"None\",\\n\"referral\": \"None\",\\n\"follow up\": \"None\",\\n\"discharge summary\": \"None\"\\n}\\n}'\n","Done. patientSample= 4\n"]}]},{"cell_type":"code","source":["# See the dictionary values.\n","for key, value in patientSample.items():\n"," print(f\"Key: {key}\")\n"," print(f\"Value: {value}\")\n"," print(\"---\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"9QQzEnx2VbAZ","executionInfo":{"status":"ok","timestamp":1775589554641,"user_tz":240,"elapsed":19,"user":{"displayName":"Donnie G","userId":"08794454185807289257"}},"outputId":"9be51a36-8f36-47fd-f314-ba32da48596a"},"execution_count":200,"outputs":[{"output_type":"stream","name":"stdout","text":["Key: 155216\n","Value: {'note': 'A a sixteen year-old girl, presented to our Outpatient department with the complaints of discomfort in the neck and lower back as well as restriction of body movements. She was not able to maintain an erect posture and would tend to fall on either side while standing up from a sitting position. She would keep her head turned to the right and upwards due to the sustained contraction of the neck muscles. There was a sideways bending of the back in the lumbar region. To counter the abnormal positioning of the back and neck, she would keep her limbs in a specific position to allow her body weight to be supported. Due to the restrictions with the body movements at the neck and in the lumbar region, she would require assistance in standing and walking. She would require her parents to help her with daily chores, including all activities of self-care.\\nShe had been experiencing these difficulties for the past four months since when she was introduced to olanzapine tablets for the control of her exacerbated mental illness. This was not her first experience with this drug over the past seven years since she had been diagnosed with bipolar affective disorder. Her first episode of the affective disorder was that of mania at the age of eleven which was managed with the use of olanzapine tablets in 2.5–10 mg doses per day at different times. The patient developed pain and discomfort in her neck within the second week of being put on tablet olanzapine at a dose of 5 mg per day. This was associated with a sustained and abnormal contraction of the neck muscles that would pull her head to the right in an upward direction. These features had persisted for the first three years of her illness with a varying intensity, distress, and dysfunction which would tend to correlate with the dose of olanzapine. Apart from a brief period of around three weeks when she was given tablet trihexyphenidyl 4 mg per day for rigidity in her upper limbs, she was not prescribed any other psychotropic medication. The rigidity showed good response to this medication which was subsequently', 'visit motivation': 'Discomfort in the neck and lower back, restriction of body movements, inability to maintain an erect posture, and requiring assistance in standing and walking.', 'summary': {'visit motivation': 'Discomfort in the neck and lower back, restriction of body movements, inability to maintain an erect posture, and requiring assistance in standing and walking.', 'admission': [{'reason': 'None', 'date': 'None', 'duration': 'None', 'care center details': 'None'}], 'patient information': {'age': 'Sixteen years old', 'sex': 'Female', 'ethnicity': 'None', 'weight': 'None', 'height': 'None', 'family medical history': 'None', 'recent travels': 'None', 'socio economic context': 'None', 'occupation': 'None'}, 'patient medical history': {'physiological context': 'None', 'psychological context': 'Diagnosed with bipolar affective disorder at the age of eleven, first episode was that of mania.', 'vaccination history': 'None', 'allergies': 'None', 'exercise frequency': 'None', 'nutrition': 'None', 'sexual history': 'None', 'alcohol consumption': 'None', 'drug usage': 'None', 'smoking status': 'None'}, 'surgeries': [{'reason': 'None', 'Type': 'None', 'time': 'None', 'outcome': 'None', 'details': 'None'}], 'symptoms': [{'name of symptom': 'Discomfort in the neck and lower back, restriction of body movements, inability to maintain an erect posture', 'intensity of symptom': 'None', 'location': 'Neck and lower back', 'time': 'Past four months', 'temporalisation': 'None', 'behaviours affecting the symptom': 'Standing up from a sitting position', 'details': 'Head turned to the right and upwards due to sustained contraction of neck muscles, sideways bending of the back in the lumbar region, limbs positioned to support body weight.'}], 'medical examinations': [{'name': 'None', 'result': 'None', 'details': 'None'}], 'diagnosis tests': [{'test': 'None', 'severity': 'None', 'result': 'None', 'condition': 'None', 'time': 'None', 'details': 'None'}], 'treatments': [{'name': 'Olanzapine tablets', 'related condition': 'Bipolar affective disorder', 'dosage': '5 mg per day', 'time': 'Past four months', 'frequency': 'Daily', 'duration': 'None', 'reason for taking': 'Control of exacerbated mental illness', 'reaction to treatment': 'Pain and discomfort in neck, sustained and abnormal contraction of neck muscles, requiring assistance in daily chores', 'details': 'Previously managed with olanzapine tablets in 2.5–10 mg doses per day at different times over the past seven years.'}, {'name': 'Trihexyphenidyl', 'related condition': 'Rigidity in upper limbs', 'dosage': '4 mg per day', 'time': 'Brief period of around three weeks', 'frequency': 'Daily', 'duration': 'None', 'reason for taking': 'Rigidity in upper limbs', 'reaction to treatment': 'Good response', 'details': 'None'}], 'discharge': {'reason': 'None', 'referral': 'None', 'follow up': 'None', 'discharge summary': 'None'}}}\n","---\n","Key: 133948\n","Value: {'note': 'A 36-year old female patient visited our hospital with a chief complaint of pain and restricted range of motion (ROM) in the left hip joint persisting for two months. Physical examination of the patient revealed severe gait disturbance secondary to hip pain aggravated by hip joint flexion or rotation. The patient had no lifestyle habits or specific comorbidities thought to cause femoral head AVN. An anteroposterior view of the left hip revealed sclerosis and collapse of the femoral head and dysplasia of the hip (). The magnetic resonance imaging (MRI) scan revealed an increased amount of joint fluid and bone marrow edema in the left hip, and femoral head necrosis was detected on the contralateral side; however, the patient did not complain of any pain (). The patient underwent THA after being diagnosed with idiopathic osteonecrosis of the femoral head, was discharged in good condition three weeks after the surgery without specific complications, and followed up via regular outpatient visits. The patient complained of pain and limited ROM in the contralateral hip joint and gait disturbance one year after the initial surgery. Her symptoms continued for two months and increased over the following three weeks. Repeat MRI revealed similar findings to those noted previously in the left hip (). A second THA was performed (one year after the first THA of the left hip); the patient was discharged in good condition after the surgery without specific complications and followed up via regular outpatient visits (). At the time of the second surgery, the patient was 7 kg heavier than she was at the time of the first procedure and developed a moderate moon face, signs that were initially overlooked as weight gain. Subsequently, the patient complained of intensifying feelings of helplessness and central obesity and muscle mass reduction in both the upper and lower limbs aggravated over a three-month period of outpatient follow-up after the second surgery. However, these signs were not significant enough to warrant further investigation. One year after the second surgery, the patient was referred to the Department of Cardiology in our hospital due to a progressive worsening of central', 'visit motivation': 'Pain and restricted range of motion in the left hip joint', 'summary': {'visit motivation': 'Pain and restricted range of motion in the left hip joint', 'admission': [{'reason': 'Idiopathic osteonecrosis of the femoral head', 'date': 'None', 'duration': 'Three weeks', 'care center details': 'None'}, {'reason': 'Pain and limited ROM in the contralateral hip joint and gait disturbance', 'date': 'One year after the initial surgery', 'duration': 'None', 'care center details': 'None'}], 'patient information': {'age': '36 years old', 'sex': 'Female', 'ethnicity': 'None', 'weight': '7 kg heavier than at the time of the first procedure', 'height': 'None', 'family medical history': 'None', 'recent travels': 'None', 'socio economic context': 'None', 'occupation': 'None'}, 'patient medical history': {'physiological context': 'None', 'psychological context': 'Intensifying feelings of helplessness', 'vaccination history': 'None', 'allergies': 'None', 'exercise frequency': 'None', 'nutrition': 'None', 'sexual history': 'None', 'alcohol consumption': 'None', 'drug usage': 'None', 'smoking status': 'None'}, 'surgeries': [{'reason': 'Idiopathic osteonecrosis of the femoral head', 'Type': 'Total Hip Arthroplasty (THA)', 'time': 'After diagnosis', 'outcome': 'Discharged in good condition without specific complications', 'details': 'First THA on the left hip'}, {'reason': 'Pain and limited ROM in the contralateral hip joint', 'Type': 'Total Hip Arthroplasty (THA)', 'time': 'One year after the first THA', 'outcome': 'Discharged in good condition without specific complications', 'details': 'Second THA on the contralateral hip'}], 'symptoms': [{'name of symptom': 'Pain', 'intensity of symptom': 'Severe', 'location': 'Left hip joint', 'time': 'Persisting for two months', 'temporalisation': 'Increased over the following three weeks', 'behaviours affecting the symptom': 'Aggravated by hip joint flexion or rotation', 'details': 'Also complained of pain and limited ROM in the contralateral hip joint one year after initial surgery'}, {'name of symptom': 'Restricted range of motion', 'intensity of symptom': 'None', 'location': 'Left hip joint', 'time': 'Persisting for two months', 'temporalisation': 'None', 'behaviours affecting the symptom': 'None', 'details': 'None'}, {'name of symptom': 'Gait disturbance', 'intensity of symptom': 'Severe', 'location': 'None', 'time': 'None', 'temporalisation': 'None', 'behaviours affecting the symptom': 'Secondary to hip pain', 'details': 'Continued for two months and increased over the following three weeks'}, {'name of symptom': 'Moderate moon face', 'intensity of symptom': 'Moderate', 'location': 'Face', 'time': 'At the time of the second surgery', 'temporalisation': 'None', 'behaviours affecting the symptom': 'None', 'details': 'Initially overlooked as weight gain'}, {'name of symptom': 'Central obesity', 'intensity of symptom': 'None', 'location': 'Central body', 'time': 'Aggravated over a three-month period of outpatient follow-up after the second surgery', 'temporalisation': 'None', 'behaviours affecting the symptom': 'None', 'details': 'None'}, {'name of symptom': 'Muscle mass reduction', 'intensity of symptom': 'None', 'location': 'Both the upper and lower limbs', 'time': 'Aggravated over a three-month period of outpatient follow-up after the second surgery', 'temporalisation': 'None', 'behaviours affecting the symptom': 'None', 'details': 'None'}], 'medical examinations': [{'name': 'Physical examination', 'result': 'Severe gait disturbance secondary to hip pain', 'details': 'Aggravated by hip joint flexion or rotation'}, {'name': 'Anteroposterior view of the left hip', 'result': 'Sclerosis and collapse of the femoral head and dysplasia of the hip', 'details': 'None'}], 'diagnosis tests': [{'test': 'Magnetic resonance imaging (MRI) scan', 'severity': 'None', 'result': 'Increased amount of joint fluid and bone marrow edema in the left hip, and femoral head necrosis on the contralateral side', 'condition': 'Idiopathic osteonecrosis of the femoral head', 'time': 'None', 'details': 'Patient did not complain of any pain on the contralateral side at the time of the first MRI'}, {'test': 'Repeat MRI', 'severity': 'None', 'result': 'Similar findings to those noted previously in the left hip', 'condition': 'None', 'time': 'One year after the initial surgery and symptoms continued for two months and increased over the following three weeks', 'details': 'None'}], 'treatments': 'None', 'discharge': {'reason': 'Good condition post-surgery', 'referral': 'Referred to the Department of Cardiology due to a progressive worsening of central', 'follow up': 'Regular outpatient visits', 'discharge summary': 'Discharged in good condition after both surgeries without specific complications'}}}\n","---\n","Key: 80176\n","Value: {'note': \"A 49-year-old male presented with a complaint of pain in the left proximal forearm after a fall. The patient had a history of left elbow arthrodesis performed for posttraumatic arthritis at the age of 18. On physical examination he was tender at the proximal ulna. He had no active flexion or extension at his elbow, which was fused at 90 degrees but achieved 40 degrees of pronation and 60 degrees of supination. His motor and sensory exam was normal at the hand. Radiographs of the forearm and the elbow revealed an elbow arthrodesis at 90 degrees with retained hardware and a minimally displaced proximal ulnar shaft fracture (). A decision was made to treat his ulnar shaft fracture closed in a cast, and he subsequently developed a hypertrophic nonunion. At his clinic visit three months after the fall, surgical options for the ulna nonunion were discussed with the patient. We proceeded with conservative treatment for an additional three months, with worsening motion through the nonunion site. He revealed that he was unhappy with the functional limitations of his elbow arthrodesis and inquired about the possibility of converting it to an arthroplasty. The risks of elbow arthroplasty were discussed with the patient at length. Increasing the functional capacity of his arm was his ultimate goal, and understanding that he faced a likely operation for the ulna nonunion, the patient wished to proceed. Due to the patient's prior surgery and history of trauma, as well as risk of infection, we chose to avoid multiple surgeries and combine the repair of nonunion and the conversion of elbow arthrodesis to arthroplasty into one procedure. The stem of the ulnar component would thus act as an intramedullary device.\\nIn the operating room the patient was placed in a supine position and a posterior incision centered over the elbow was performed. A prior muscle flap that was used for soft tissue coverage at his index procedure had to be elevated. The ulnar nerve was encased in scar tissue and required a meticulous neuroplasty. A triceps splitting approach to the elbow joint was then performed and multiple buried pins\", 'visit motivation': 'Pain in the left proximal forearm after a fall', 'summary': {'visit motivation': 'Pain in the left proximal forearm after a fall', 'admission': [{'reason': 'None', 'date': 'None', 'duration': 'None', 'care center details': 'None'}], 'patient information': {'age': '49', 'sex': 'male', 'ethnicity': 'None', 'weight': 'None', 'height': 'None', 'family medical history': 'None', 'recent travels': 'None', 'socio economic context': 'None', 'occupation': 'None'}, 'patient medical history': {'physiological context': 'History of left elbow arthrodesis performed for posttraumatic arthritis at the age of 18', 'psychological context': 'None', 'vaccination history': 'None', 'allergies': 'None', 'exercise frequency': 'None', 'nutrition': 'None', 'sexual history': 'None', 'alcohol consumption': 'None', 'drug usage': 'None', 'smoking status': 'None'}, 'surgeries': [{'reason': 'Posttraumatic arthritis', 'Type': 'Left elbow arthrodesis', 'time': 'At the age of 18', 'outcome': 'None', 'details': 'Elbow was fused at 90 degrees'}, {'reason': 'Hypertrophic nonunion of ulnar shaft fracture and functional limitations of elbow arthrodesis', 'Type': 'Repair of nonunion and conversion of elbow arthrodesis to arthroplasty', 'time': 'Three months after the fall and subsequent conservative treatment period', 'outcome': 'None', 'details': 'The stem of the ulnar component would act as an intramedullary device'}], 'symptoms': [{'name of symptom': 'Pain', 'intensity of symptom': 'None', 'location': 'Left proximal forearm', 'time': 'After a fall', 'temporalisation': 'None', 'behaviours affecting the symptom': 'None', 'details': 'Patient was tender at the proximal ulna'}], 'medical examinations': [{'name': 'Physical examination', 'result': 'No active flexion or extension at elbow, 40 degrees of pronation, 60 degrees of supination, normal motor and sensory exam at the hand', 'details': 'Elbow was fused at 90 degrees'}], 'diagnosis tests': [{'test': 'Radiographs', 'severity': 'Minimally displaced', 'result': 'Proximal ulnar shaft fracture', 'condition': 'Proximal ulnar shaft fracture, hypertrophic nonunion', 'time': 'None', 'details': 'Elbow arthrodesis at 90 degrees with retained hardware was also noted'}], 'treatments': [{'name': 'Closed treatment in a cast', 'related condition': 'Proximal ulnar shaft fracture', 'dosage': 'None', 'time': 'Initially after the fall', 'frequency': 'None', 'duration': 'None', 'reason for taking': 'To treat the ulnar shaft fracture', 'reaction to treatment': 'Developed a hypertrophic nonunion', 'details': 'None'}, {'name': 'Conservative treatment', 'related condition': 'Ulna nonunion', 'dosage': 'None', 'time': 'Three months after the fall', 'frequency': 'None', 'duration': 'An additional three months', 'reason for taking': 'To treat the ulna nonunion', 'reaction to treatment': 'Worsening motion through the nonunion site', 'details': 'None'}], 'discharge': {'reason': 'None', 'referral': 'None', 'follow up': 'None', 'discharge summary': 'None'}}}\n","---\n","Key: 72232\n","Value: {'note': 'A 47-year-old male patient was referred to the rheumatology clinic because of recurrent attacks of pain in both knees over 1 year.\\nIn September 2016, the patient presented with severe pain over the medial aspect of the left knee for a two-week duration which prevented him from ambulation. The pain increased with weight-bearing physical activity. The patient reported no history of trauma before the onset of the knee pain. Examination showed severe tenderness over the medial side of the knee with mild effusion and moderate limitation of range of motion. There was no erythema or increased warmth of the knee. MRI of the left knee showed a moderate-sized focal area of marrow edema/contusion involving the medial femoral condyle in mid and anterior parts predominantly along the articular surface. The patient was prescribed diclofenac sodium 50 mg twice daily and was advised to avoid prolonged weight-bearing activities. Over the next few weeks, the pain subsided and resolved. Three months later, the patient developed spontaneous new onset of pain involving the lateral aspect of the same knee. MRI showed bone marrow edema involving the lateral femoral condyle with complete resolution of the bone marrow edema of the medial femoral condyle. He was treated conservatively with NSAIDs and physiotherapy and advised to use cane to minimize weight bearing on the diseased knee. demonstrates MRI of the left knee in September 2016 and three months later.\\nIn April 2017, the patient developed gradual pain over the medial side of the right knee with no obvious swelling. MRI of the right knee showed a moderate-sized focal area of marrow edema involving the medial tibial plateau medially and anteriorly. The patient was treated conservatively in a similar fashion to the previous episode. Four months later, the pain got more severe for which he underwent another MRI of the right knee which showed extensive marrow edema involving the medial femoral condyle with complete recovery of the medial tibial plateau bone marrow edema noted in the previous MRI (). The patient also recalled a similar pain happened in 2011 to the left knee but did not do MRI at', 'visit motivation': 'Recurrent attacks of pain in both knees over 1 year', 'summary': {'visit motivation': 'Recurrent attacks of pain in both knees over 1 year', 'admission': [{'reason': 'None', 'date': 'None', 'duration': 'None', 'care center details': 'Rheumatology clinic'}], 'patient information': {'age': '47', 'sex': 'Male', 'ethnicity': 'None', 'weight': 'None', 'height': 'None', 'family medical history': 'None', 'recent travels': 'None', 'socio economic context': 'None', 'occupation': 'None'}, 'patient medical history': {'physiological context': 'None', 'psychological context': 'None', 'vaccination history': 'None', 'allergies': 'None', 'exercise frequency': 'None', 'nutrition': 'None', 'sexual history': 'None', 'alcohol consumption': 'None', 'drug usage': 'None', 'smoking status': 'None'}, 'surgeries': [{'reason': 'None', 'Type': 'None', 'time': 'None', 'outcome': 'None', 'details': 'None'}], 'symptoms': [{'name of symptom': 'Pain', 'intensity of symptom': 'Severe', 'location': 'Medial aspect of the left knee, lateral aspect of the left knee, medial side of the right knee', 'time': 'Over 1 year', 'temporalisation': 'Recurrent attacks', 'behaviours affecting the symptom': 'Increased with weight-bearing physical activity', 'details': 'Prevented ambulation, no history of trauma, mild effusion, moderate limitation of range of motion, no erythema or increased warmth'}], 'medical examinations': [{'name': 'Examination', 'result': 'Severe tenderness over the medial side of the knee with mild effusion and moderate limitation of range of motion', 'details': 'No erythema or increased warmth of the knee'}], 'diagnosis tests': [{'test': 'MRI', 'severity': 'Moderate-sized', 'result': 'Focal area of marrow edema/contusion involving the medial femoral condyle, bone marrow edema involving the lateral femoral condyle, extensive marrow edema involving the medial femoral condyle', 'condition': 'Bone marrow edema', 'time': 'September 2016, three months later, April 2017, four months later', 'details': 'Involvement of medial femoral condyle in mid and anterior parts predominantly along the articular surface, complete resolution of the bone marrow edema of the medial femoral condyle, involvement of the medial tibial plateau medially and anteriorly, complete recovery of the medial tibial plateau bone marrow edema'}], 'treatments': [{'name': 'Diclofenac sodium', 'related condition': 'Bone marrow edema', 'dosage': '50 mg', 'time': 'September 2016', 'frequency': 'Twice daily', 'duration': 'None', 'reason for taking': 'To treat knee pain', 'reaction to treatment': 'Pain subsided and resolved', 'details': 'Advised to avoid prolonged weight-bearing activities'}, {'name': 'NSAIDs and physiotherapy', 'related condition': 'Bone marrow edema', 'dosage': 'None', 'time': 'Three months after September 2016', 'frequency': 'None', 'duration': 'None', 'reason for taking': 'Treatment for new onset of pain involving the lateral aspect of the left knee', 'reaction to treatment': 'None', 'details': 'Advised to use cane to minimize weight bearing on the diseased knee'}, {'name': 'Conservative treatment', 'related condition': 'Bone marrow edema', 'dosage': 'None', 'time': 'April 2017', 'frequency': 'None', 'duration': 'None', 'reason for taking': 'Treatment for gradual pain over the medial side of the right knee', 'reaction to treatment': 'None', 'details': 'None'}], 'discharge': {'reason': 'None', 'referral': 'None', 'follow up': 'None', 'discharge summary': 'None'}}}\n","---\n"]}]},{"cell_type":"code","source":["def get_motivation_from_patient_id(patientId):\n"," return patientSample.get(patientId)['visit motivation'] # Simple lookup\n","\n","def get_note_from_patient_id(patientId):\n"," return patientSample.get(patientId)['note'] # Simple lookup\n","\n","def json_section_to_text(json_obj):\n"," parts = []\n","\n"," # Simple mapping that includes only non-empty fields.\n"," if json_obj.get(\"visit motivation\"):\n"," motiviation = \"Visit motivation: \" + json_obj[\"visit motivation\"]\n"," parts.append(motiviation)\n"," print(motiviation)\n"," if json_obj.get(\"patient information\"):\n"," patientInfo = \"Patient information: \" + json_obj[\"patient information\"]\n"," parts.append(patientInfo)\n"," print(patientInfo)\n","\n"," return \"\\n\\n\".join(parts)"],"metadata":{"id":"eAbmn96Sjarq","executionInfo":{"status":"ok","timestamp":1775589572389,"user_tz":240,"elapsed":54,"user":{"displayName":"Donnie G","userId":"08794454185807289257"}}},"execution_count":201,"outputs":[]},{"cell_type":"code","source":["import gradio as gr\n","\n","#choices = [patient[0] for patient in patientSample]\n","choices = list(patientSample.keys()) # Get list of patient IDs\n","\n","with gr.Blocks(title=\"Patient Instructions generated from Clinical Notes\",theme=\"soft\") as demo:\n"," gr.Markdown(\"# Choose a patient to view their summary, and then generate concise patient instructions.\")\n","\n"," patientDropdown = gr.Dropdown(choices, label=\"Choose a Patient ID\")\n"," motivationTextbox = gr.Textbox(lines=4, label=\"Visit Motivation\")\n"," summaryTextbox = gr.Textbox(lines=4, label=\"Clinical summary\")\n"," patientDropdown.change(get_motivation_from_patient_id, inputs=patientDropdown, outputs=motivationTextbox)\n"," patientDropdown.change(get_note_from_patient_id, inputs=patientDropdown, outputs=summaryTextbox)\n"," patientInstructions = gr.Textbox(lines=5, label=\"Patient Instructions\"),\n","\n","demo.launch(debug=True)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":695},"id":"UZB1GQA1E3dq","executionInfo":{"status":"ok","timestamp":1775591125363,"user_tz":240,"elapsed":1551386,"user":{"displayName":"Donnie G","userId":"08794454185807289257"}},"outputId":"9e4d6cc4-89b8-4590-b408-e06640221689"},"execution_count":202,"outputs":[{"output_type":"stream","name":"stderr","text":["/tmp/ipykernel_2891/2536891410.py:6: DeprecationWarning: The 'theme' parameter in the Blocks constructor will be removed in Gradio 6.0. You will need to pass 'theme' to Blocks.launch() instead.\n"," with gr.Blocks(title=\"Patient Instructions generated from Clinical Notes\",theme=\"soft\") as demo:\n"]},{"output_type":"stream","name":"stdout","text":["It looks like you are running Gradio on a hosted Jupyter notebook, which requires `share=True`. Automatically setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n","\n","Colab notebook detected. This cell will run indefinitely so that you can see errors and logs. To turn off, set debug=False in launch().\n","* Running on public URL: https://5c4480bdbd84901e3f.gradio.live\n","\n","This share link expires in 1 week. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)\n"]},{"output_type":"display_data","data":{"text/plain":["<IPython.core.display.HTML object>"],"text/html":["<div><iframe src=\"https://5c4480bdbd84901e3f.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"]},"metadata":{}},{"output_type":"stream","name":"stdout","text":["Keyboard interruption in main thread... closing server.\n","Killing tunnel 127.0.0.1:7867 <> https://5c4480bdbd84901e3f.gradio.live\n"]},{"output_type":"execute_result","data":{"text/plain":[]},"metadata":{},"execution_count":202}]},{"cell_type":"code","source":["from transformers import pipeline, AutoTokenizer\n","\n","model_name = \"Falconsai/medical_summarization\"\n","tok = AutoTokenizer.from_pretrained(model_name)\n","generator = pipeline(\n"," \"summarization\",\n"," model=model_name,\n"," tokenizer=tok,\n"," device_map=\"auto\",\n"," dtype=\"auto\",\n"," return_full_text=False)\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":408},"executionInfo":{"status":"error","timestamp":1775581706764,"user_tz":240,"elapsed":2158,"user":{"displayName":"Donnie G","userId":"08794454185807289257"}},"outputId":"a0821948-e428-4e9f-c2f2-3877b86384f9","id":"d7DL_KBD6nw2"},"execution_count":129,"outputs":[{"output_type":"error","ename":"KeyError","evalue":"\"Unknown task summarization, available tasks are ['any-to-any', 'audio-classification', 'automatic-speech-recognition', 'depth-estimation', 'document-question-answering', 'feature-extraction', 'fill-mask', 'image-classification', 'image-feature-extraction', 'image-segmentation', 'image-text-to-text', 'image-to-image', 'keypoint-matching', 'mask-generation', 'ner', 'object-detection', 'question-answering', 'sentiment-analysis', 'table-question-answering', 'text-classification', 'text-generation', 'text-to-audio', 'text-to-speech', 'token-classification', 'video-classification', 'visual-question-answering', 'vqa', 'zero-shot-audio-classification', 'zero-shot-classification', 'zero-shot-image-classification', 'zero-shot-object-detection', 'translation_XX_to_YY']\"","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)","\u001b[0;32m/tmp/ipykernel_2891/46504198.py\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mmodel_name\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"Falconsai/medical_summarization\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mtok\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mAutoTokenizer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_pretrained\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m generator = pipeline(\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0;34m\"summarization\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmodel_name\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/pipelines/__init__.py\u001b[0m in \u001b[0;36mpipeline\u001b[0;34m(task, model, config, tokenizer, feature_extractor, image_processor, processor, revision, use_fast, token, device, device_map, dtype, trust_remote_code, model_kwargs, pipeline_class, **kwargs)\u001b[0m\n\u001b[1;32m 775\u001b[0m )\n\u001b[1;32m 776\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 777\u001b[0;31m \u001b[0mnormalized_task\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtargeted_task\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtask_options\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcheck_task\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtask\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 778\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mpipeline_class\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 779\u001b[0m \u001b[0mpipeline_class\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtargeted_task\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"impl\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/pipelines/__init__.py\u001b[0m in \u001b[0;36mcheck_task\u001b[0;34m(task)\u001b[0m\n\u001b[1;32m 379\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 380\u001b[0m \"\"\"\n\u001b[0;32m--> 381\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mPIPELINE_REGISTRY\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcheck_task\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtask\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 382\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 383\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/pipelines/base.py\u001b[0m in \u001b[0;36mcheck_task\u001b[0;34m(self, task)\u001b[0m\n\u001b[1;32m 1354\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"Invalid translation task {task}, use 'translation_XX_to_YY' format\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1355\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1356\u001b[0;31m raise KeyError(\n\u001b[0m\u001b[1;32m 1357\u001b[0m \u001b[0;34mf\"Unknown task {task}, available tasks are {self.get_supported_tasks() + ['translation_XX_to_YY']}\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1358\u001b[0m )\n","\u001b[0;31mKeyError\u001b[0m: \"Unknown task summarization, available tasks are ['any-to-any', 'audio-classification', 'automatic-speech-recognition', 'depth-estimation', 'document-question-answering', 'feature-extraction', 'fill-mask', 'image-classification', 'image-feature-extraction', 'image-segmentation', 'image-text-to-text', 'image-to-image', 'keypoint-matching', 'mask-generation', 'ner', 'object-detection', 'question-answering', 'sentiment-analysis', 'table-question-answering', 'text-classification', 'text-generation', 'text-to-audio', 'text-to-speech', 'token-classification', 'video-classification', 'visual-question-answering', 'vqa', 'zero-shot-audio-classification', 'zero-shot-classification', 'zero-shot-image-classification', 'zero-shot-object-detection', 'translation_XX_to_YY']\""]}]},{"cell_type":"code","source":["from transformers import pipeline, AutoTokenizer\n","\n","model_name = \"Falconsai/medical_summarization\"\n","tok = AutoTokenizer.from_pretrained(model_name)\n","generator = pipeline(\n"," \"text-generation\",\n"," model=model_name,\n"," tokenizer=tok,\n"," device_map=\"auto\",\n"," dtype=\"auto\",\n"," return_full_text=False)\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":86,"referenced_widgets":["8abe534570f446de88127cfefbb0b34b","fd980ea7952740b7a5018226f969a9a9","2ed8bd4773024328baba879d6b9119af","7a2635bd4d284d03a80297bac1987796","956376c3f9684d1498a8b80c51d61ca1","010995bf495a4e5c86b2035933bea864","cf0154a9839d4522a2699d38f8c62b09","7983d5fb6231494d9970deb9b2fedbdd","b6b96afe02064dd280c113cb099e461c","335fc6548abb4cc8ad321fafb89e1cb9","6c7024bdab3044a6a030d9b113ddbd89"]},"id":"qxwzH-khvudW","executionInfo":{"status":"ok","timestamp":1775580508467,"user_tz":240,"elapsed":3088,"user":{"displayName":"Donnie G","userId":"08794454185807289257"}},"outputId":"b84a26a3-1f73-463e-9e56-f92d6edc73cb"},"execution_count":115,"outputs":[{"output_type":"display_data","data":{"text/plain":["Loading weights: 0%| | 0/131 [00:00<?, ?it/s]"],"application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"8abe534570f446de88127cfefbb0b34b"}},"metadata":{}},{"output_type":"stream","name":"stderr","text":["The model 'T5ForConditionalGeneration' is not supported for text-generation. Supported models are ['PeftModelForCausalLM', 'AfmoeForCausalLM', 'ApertusForCausalLM', 'ArceeForCausalLM', 'AriaTextForCausalLM', 'BambaForCausalLM', 'BartForCausalLM', 'BertLMHeadModel', 'BertGenerationDecoder', 'BigBirdForCausalLM', 'BigBirdPegasusForCausalLM', 'BioGptForCausalLM', 'BitNetForCausalLM', 'BlenderbotForCausalLM', 'BlenderbotSmallForCausalLM', 'BloomForCausalLM', 'BltForCausalLM', 'CamembertForCausalLM', 'LlamaForCausalLM', 'CodeGenForCausalLM', 'CohereForCausalLM', 'Cohere2ForCausalLM', 'CpmAntForCausalLM', 'CTRLLMHeadModel', 'CwmForCausalLM', 'Data2VecTextForCausalLM', 'DbrxForCausalLM', 'DeepseekV2ForCausalLM', 'DeepseekV3ForCausalLM', 'DiffLlamaForCausalLM', 'DogeForCausalLM', 'Dots1ForCausalLM', 'ElectraForCausalLM', 'Emu3ForCausalLM', 'ErnieForCausalLM', 'Ernie4_5ForCausalLM', 'Ernie4_5_MoeForCausalLM', 'Exaone4ForCausalLM', 'FalconForCausalLM', 'FalconH1ForCausalLM', 'FalconMambaForCausalLM', 'FlexOlmoForCausalLM', 'FuyuForCausalLM', 'GemmaForCausalLM', 'Gemma2ForCausalLM', 'Gemma3ForConditionalGeneration', 'Gemma3ForCausalLM', 'Gemma3nForConditionalGeneration', 'Gemma3nForCausalLM', 'GitForCausalLM', 'GlmForCausalLM', 'Glm4ForCausalLM', 'Glm4MoeForCausalLM', 'Glm4MoeLiteForCausalLM', 'GotOcr2ForConditionalGeneration', 'GPT2LMHeadModel', 'GPT2LMHeadModel', 'GPTBigCodeForCausalLM', 'GPTNeoForCausalLM', 'GPTNeoXForCausalLM', 'GPTNeoXJapaneseForCausalLM', 'GptOssForCausalLM', 'GPTJForCausalLM', 'GraniteForCausalLM', 'GraniteMoeForCausalLM', 'GraniteMoeHybridForCausalLM', 'GraniteMoeSharedForCausalLM', 'HeliumForCausalLM', 'HunYuanDenseV1ForCausalLM', 'HunYuanMoEV1ForCausalLM', 'Jais2ForCausalLM', 'JambaForCausalLM', 'JetMoeForCausalLM', 'Lfm2ForCausalLM', 'Lfm2MoeForCausalLM', 'LlamaForCausalLM', 'Llama4ForCausalLM', 'Llama4ForCausalLM', 'LongcatFlashForCausalLM', 'MambaForCausalLM', 'Mamba2ForCausalLM', 'MarianForCausalLM', 'MBartForCausalLM', 'MegatronBertForCausalLM', 'MiniMaxForCausalLM', 'MiniMaxM2ForCausalLM', 'MinistralForCausalLM', 'Ministral3ForCausalLM', 'MistralForCausalLM', 'MixtralForCausalLM', 'MllamaForCausalLM', 'ModernBertDecoderForCausalLM', 'MoshiForCausalLM', 'MptForCausalLM', 'MusicgenForCausalLM', 'MusicgenMelodyForCausalLM', 'MvpForCausalLM', 'NanoChatForCausalLM', 'NemotronForCausalLM', 'OlmoForCausalLM', 'Olmo2ForCausalLM', 'Olmo3ForCausalLM', 'OlmoeForCausalLM', 'OpenAIGPTLMHeadModel', 'OPTForCausalLM', 'PegasusForCausalLM', 'PersimmonForCausalLM', 'PhiForCausalLM', 'Phi3ForCausalLM', 'Phi4MultimodalForCausalLM', 'PhimoeForCausalLM', 'PLBartForCausalLM', 'ProphetNetForCausalLM', 'Qwen2ForCausalLM', 'Qwen2MoeForCausalLM', 'Qwen3ForCausalLM', 'Qwen3MoeForCausalLM', 'Qwen3NextForCausalLM', 'RecurrentGemmaForCausalLM', 'ReformerModelWithLMHead', 'RemBertForCausalLM', 'RobertaForCausalLM', 'RobertaPreLayerNormForCausalLM', 'RoCBertForCausalLM', 'RoFormerForCausalLM', 'RwkvForCausalLM', 'SeedOssForCausalLM', 'SmolLM3ForCausalLM', 'SolarOpenForCausalLM', 'StableLmForCausalLM', 'Starcoder2ForCausalLM', 'TrOCRForCausalLM', 'VaultGemmaForCausalLM', 'WhisperForCausalLM', 'XGLMForCausalLM', 'XLMWithLMHeadModel', 'XLMRobertaForCausalLM', 'XLMRobertaXLForCausalLM', 'XLNetLMHeadModel', 'xLSTMForCausalLM', 'XmodForCausalLM', 'ZambaForCausalLM', 'Zamba2ForCausalLM'].\n"]}]},{"cell_type":"code","source":["# 1) Inspect model config and tokenizer\n","print(\"is_encoder_decoder:\", generator.model.config.is_encoder_decoder)\n","print(\"model_type:\", generator.model.config.model_type)\n","print(\"tokenizer.eos_token:\", tok.eos_token)\n","print(\"tokenizer.pad_token:\", tok.pad_token)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"KwYSu16uz_iJ","executionInfo":{"status":"ok","timestamp":1775579955544,"user_tz":240,"elapsed":12,"user":{"displayName":"Donnie G","userId":"08794454185807289257"}},"outputId":"3590109d-b8de-4dff-f482-a5d2efa71c5a"},"execution_count":112,"outputs":[{"output_type":"stream","name":"stdout","text":["is_encoder_decoder: True\n","model_type: t5\n","tokenizer.eos_token: </s>\n","tokenizer.pad_token: <pad>\n"]}]},{"cell_type":"code","source":["def summarize_note(jsonSummary):\n"," import json\n"," jsonAsString = json.dumps(jsonSummary['treatments'], ensure_ascii=False, separators=(\",\", \":\"))\n","\n"," prompt = (\"Summarize the following clinical JSON with notes and summary into 2-3 concise sentences focusing on the most critical information for the patient:\"\n"," f\"JSON: \\n{jsonAsString}\")\n"," responseGenerator = generator(prompt, max_new_tokens=256, do_sample=False)\n"," print(responseGenerator)\n"," print(\"PROMPT:\", prompt)\n"," out = responseGenerator[0][\"generated_text\"]\n"," return out\n","\n","def todo_from_summary(summary):\n"," prompt = \"Rewrite the following summary as 4 simple patient-friendly bullet points and a short TODO list. Use plain language and do not invent anything outside of this medical summary including instructions or medications:\\n\\n\" + summary\n"," out = generator(prompt, max_new_tokens=256, do_sample=False)[0][\"generated_text\"]\n"," return out\n"],"metadata":{"id":"UmwZt-HOxo7Q","executionInfo":{"status":"ok","timestamp":1775580684950,"user_tz":240,"elapsed":55,"user":{"displayName":"Donnie G","userId":"08794454185807289257"}}},"execution_count":125,"outputs":[]},{"cell_type":"code","source":["for i in range(len(patientSample)):\n"," #print(\"full_note:\", repr(str(patientFullNote)))\n"," #patientJsonSummary = patientSample[i]\n"," outputSummary = summarize_note(patientJsonSummary)\n"," print(\"Summary:\", outputSummary)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":463},"id":"gGo227f7ZN1A","executionInfo":{"status":"error","timestamp":1775580694666,"user_tz":240,"elapsed":8034,"user":{"displayName":"Donnie G","userId":"08794454185807289257"}},"outputId":"a532f329-b819-4900-ab60-0db7ca1b3608"},"execution_count":126,"outputs":[{"output_type":"stream","name":"stderr","text":["Both `max_new_tokens` (=256) and `max_length`(=20) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)\n"]},{"output_type":"stream","name":"stdout","text":["[{'generated_text': ''}]\n","PROMPT: Summarize the following clinical JSON with notes and summary into 2-3 concise sentences focusing on the most critical information for the patient:JSON: \n","[{\"name\":\"Diclofenac sodium\",\"related condition\":\"Bone marrow edema\",\"dosage\":\"50 mg\",\"time\":\"September 2016\",\"frequency\":\"Twice daily\",\"duration\":\"None\",\"reason for taking\":\"To treat knee pain\",\"reaction to treatment\":\"Pain subsided and resolved\",\"details\":\"Advised to avoid prolonged weight-bearing activities\"},{\"name\":\"NSAIDs and physiotherapy\",\"related condition\":\"Bone marrow edema\",\"dosage\":\"None\",\"time\":\"Three months after September 2016\",\"frequency\":\"None\",\"duration\":\"None\",\"reason for taking\":\"Treatment for new onset of pain involving the lateral aspect of the left knee\",\"reaction to treatment\":\"None\",\"details\":\"Advised to use cane to minimize weight bearing on the diseased knee\"},{\"name\":\"Conservative treatment\",\"related condition\":\"Bone marrow edema\",\"dosage\":\"None\",\"time\":\"April 2017\",\"frequency\":\"None\",\"duration\":\"None\",\"reason for taking\":\"Treatment for gradual pain over the medial side of the right knee\",\"reaction to treatment\":\"None\",\"details\":\"None\"}]\n","Summary: \n"]},{"output_type":"stream","name":"stderr","text":["Both `max_new_tokens` (=256) and `max_length`(=20) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)\n"]},{"output_type":"error","ename":"KeyboardInterrupt","evalue":"","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)","\u001b[0;32m/tmp/ipykernel_2891/621555168.py\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;31m#print(\"full_note:\", repr(str(patientFullNote)))\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;31m#patientJsonSummary = patientSample[i]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0moutputSummary\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msummarize_note\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpatientJsonSummary\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Summary:\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutputSummary\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/tmp/ipykernel_2891/1057638751.py\u001b[0m in \u001b[0;36msummarize_note\u001b[0;34m(jsonSummary)\u001b[0m\n\u001b[1;32m 5\u001b[0m prompt = (\"Summarize the following clinical JSON with notes and summary into 2-3 concise sentences focusing on the most critical information for the patient:\"\n\u001b[1;32m 6\u001b[0m f\"JSON: \\n{jsonAsString}\")\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mresponseGenerator\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgenerator\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprompt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmax_new_tokens\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m256\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdo_sample\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresponseGenerator\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"PROMPT:\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mprompt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/pipelines/text_generation.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, text_inputs, **kwargs)\u001b[0m\n\u001b[1;32m 291\u001b[0m \u001b[0mids\u001b[0m \u001b[0mof\u001b[0m \u001b[0mthe\u001b[0m \u001b[0mgenerated\u001b[0m \u001b[0mtext\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 292\u001b[0m \"\"\"\n\u001b[0;32m--> 293\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__call__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtext_inputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 294\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 295\u001b[0m def preprocess(\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/pipelines/base.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs, num_workers, batch_size, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1272\u001b[0m )\n\u001b[1;32m 1273\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1274\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_single\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpreprocess_params\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mforward_params\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpostprocess_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1275\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1276\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mrun_multi\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpreprocess_params\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mforward_params\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpostprocess_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/pipelines/base.py\u001b[0m in \u001b[0;36mrun_single\u001b[0;34m(self, inputs, preprocess_params, forward_params, postprocess_params)\u001b[0m\n\u001b[1;32m 1279\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mrun_single\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpreprocess_params\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mforward_params\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpostprocess_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1280\u001b[0m \u001b[0mmodel_inputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpreprocess\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mpreprocess_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1281\u001b[0;31m \u001b[0mmodel_outputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mforward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel_inputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mforward_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1282\u001b[0m \u001b[0moutputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpostprocess\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel_outputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mpostprocess_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1283\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0moutputs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/pipelines/base.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, model_inputs, **forward_params)\u001b[0m\n\u001b[1;32m 1171\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0minference_context\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1172\u001b[0m \u001b[0mmodel_inputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_ensure_tensor_on_device\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel_inputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdevice\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdevice\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1173\u001b[0;31m \u001b[0mmodel_outputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_forward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel_inputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mforward_params\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1174\u001b[0m \u001b[0mmodel_outputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_ensure_tensor_on_device\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel_outputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdevice\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdevice\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"cpu\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1175\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mmodel_outputs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/pipelines/text_generation.py\u001b[0m in \u001b[0;36m_forward\u001b[0;34m(self, model_inputs, **generate_kwargs)\u001b[0m\n\u001b[1;32m 395\u001b[0m \u001b[0mgenerate_kwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"generation_config\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgeneration_config\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 396\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 397\u001b[0;31m \u001b[0moutput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgenerate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput_ids\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0minput_ids\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mattention_mask\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mattention_mask\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mgenerate_kwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 398\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 399\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mModelOutput\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/torch/utils/_contextlib.py\u001b[0m in \u001b[0;36mdecorate_context\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 122\u001b[0m \u001b[0;31m# pyrefly: ignore [bad-context-manager]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 123\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mctx_factory\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 124\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 125\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 126\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mdecorate_context\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/generation/utils.py\u001b[0m in \u001b[0;36mgenerate\u001b[0;34m(self, inputs, generation_config, logits_processor, stopping_criteria, prefix_allowed_tokens_fn, synced_gpus, assistant_model, streamer, negative_prompt_ids, negative_prompt_attention_mask, custom_generate, **kwargs)\u001b[0m\n\u001b[1;32m 2667\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2668\u001b[0m \u001b[0;31m# 9. Call generation mode\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2669\u001b[0;31m result = decoding_method(\n\u001b[0m\u001b[1;32m 2670\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2671\u001b[0m \u001b[0minput_ids\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/generation/utils.py\u001b[0m in \u001b[0;36m_sample\u001b[0;34m(self, input_ids, logits_processor, stopping_criteria, generation_config, synced_gpus, streamer, **model_kwargs)\u001b[0m\n\u001b[1;32m 2872\u001b[0m \u001b[0mmodel_inputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprepare_inputs_for_generation\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput_ids\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mmodel_kwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2873\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_optimize_model_for_decode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2874\u001b[0;31m \u001b[0moutputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodel_forward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mmodel_inputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreturn_dict\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2875\u001b[0m \u001b[0mprefill_consumed\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2876\u001b[0m model_kwargs = self._update_model_kwargs_for_generation(\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_wrapped_call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1774\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_compiled_call_impl\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# type: ignore[misc]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1775\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1776\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_impl\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1777\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1778\u001b[0m \u001b[0;31m# torchrec tests the code consistency with the following code\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1785\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0m_global_backward_pre_hooks\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0m_global_backward_hooks\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1786\u001b[0m or _global_forward_hooks or _global_forward_pre_hooks):\n\u001b[0;32m-> 1787\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mforward_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1788\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1789\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/transformers/models/t5/modeling_t5.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, input_ids, attention_mask, decoder_input_ids, decoder_attention_mask, encoder_outputs, past_key_values, inputs_embeds, decoder_inputs_embeds, labels, use_cache, output_attentions, output_hidden_states, return_dict, cache_position, **kwargs)\u001b[0m\n\u001b[1;32m 1140\u001b[0m \u001b[0msequence_output\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msequence_output\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodel_dim\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m0.5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1141\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1142\u001b[0;31m \u001b[0mlm_logits\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlm_head\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msequence_output\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1143\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1144\u001b[0m \u001b[0mloss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_wrapped_call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1774\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_compiled_call_impl\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# type: ignore[misc]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1775\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1776\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call_impl\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1777\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1778\u001b[0m \u001b[0;31m# torchrec tests the code consistency with the following code\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/torch/nn/modules/module.py\u001b[0m in \u001b[0;36m_call_impl\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 1785\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0m_global_backward_pre_hooks\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0m_global_backward_hooks\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1786\u001b[0m or _global_forward_hooks or _global_forward_pre_hooks):\n\u001b[0;32m-> 1787\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mforward_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1788\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1789\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/usr/local/lib/python3.12/dist-packages/torch/nn/modules/linear.py\u001b[0m in \u001b[0;36mforward\u001b[0;34m(self, input)\u001b[0m\n\u001b[1;32m 132\u001b[0m \u001b[0mRuns\u001b[0m \u001b[0mthe\u001b[0m \u001b[0mforward\u001b[0m \u001b[0;32mpass\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 133\u001b[0m \"\"\"\n\u001b[0;32m--> 134\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mF\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlinear\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mweight\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbias\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 135\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 136\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mextra_repr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mKeyboardInterrupt\u001b[0m: "]}]},{"cell_type":"code","source":[],"metadata":{"id":"m_MPLEYWUhED"},"execution_count":null,"outputs":[]}]}
 
 
Project1Demo.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- transformers
2
  gradio
3
- torch
 
1
+ datasets
2
  gradio
3
+ transformers