File size: 2,440 Bytes
c7a6fe6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | {
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "eef90c68",
"metadata": {},
"outputs": [],
"source": [
"from openmed.core import ModelLoader\n",
"from openmed.processing import format_predictions\n",
"\n",
"loader = ModelLoader() # uses the default configuration\n",
"ner = loader.create_pipeline(\n",
" \"disease_detection_superclinical\", # registry key or full model ID\n",
" aggregation_strategy=\"simple\", # group sub-token predictions for quick wins\n",
")\n",
"\n",
"text = \"Patient diagnosed with acute lymphoblastic leukemia and started on imatinib.\"\n",
"raw_predictions = ner(text)\n",
"\n",
"result = format_predictions(raw_predictions, text, model_name=\"Disease Detection\")\n",
"for entity in result.entities:\n",
" print(f\"{entity.label:<12} -> {entity.text} (confidence={entity.confidence:.2f})\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a14de1a5",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import json\n",
"\n",
"data_dir = \"/home/mshahidul/readctrl/data/kyw_def_raw\"\n",
"json_list = []\n",
"\n",
"for filename in os.listdir(data_dir):\n",
" print(f\"Processing file: {filename}\")\n",
" if filename.endswith(\".json\"):\n",
" file_path = os.path.join(data_dir, filename)\n",
" with open(file_path, \"r\") as f:\n",
" json_file=json.load(f)\n",
" if \"chatgpt_answer\" in json_file:\n",
" json_file=json_file[\"chatgpt_answer\"]\n",
" json_list.append(json_file)\n",
"\n",
"# Save the combined list to a new file\n",
"save_dir = \"/home/mshahidul/readctrl/data/kyw_def_train\"\n",
"os.makedirs(save_dir, exist_ok=True)\n",
"with open(os.path.join(save_dir, \"kyw_gen_gpt5.json\"), \"w\") as out_f:\n",
" json.dump(json_list, out_f, indent=4)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "unsloth",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|