{"id":13409401,"url":"https://github.com/llSourcell/Doctor-Dignity","last_synced_at":"2025-03-14T14:31:24.329Z","repository":{"id":187925459,"uuid":"675378348","full_name":"llSourcell/Doctor-Dignity","owner":"llSourcell","description":"Doctor Dignity is an LLM that can pass the US Medical Licensing Exam. It works offline, it's cross-platform, \u0026 your health data stays private.","archived":false,"fork":false,"pushed_at":"2023-09-21T01:07:13.000Z","size":13913,"stargazers_count":3807,"open_issues_count":23,"forks_count":397,"subscribers_count":54,"default_branch":"main","last_synced_at":"2024-05-17T03:15:14.358Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/llSourcell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-08-06T18:02:55.000Z","updated_at":"2024-05-16T00:25:22.000Z","dependencies_parsed_at":"2023-09-06T07:15:23.414Z","dependency_job_id":"3b1733b8-61e4-4997-af7c-216f6ac17577","html_url":"https://github.com/llSourcell/Doctor-Dignity","commit_stats":null,"previous_names":["llsourcell/doctorgpt","llsourcell/doctor-dignity"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llSourcell%2FDoctor-Dignity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llSourcell%2FDoctor-Dignity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llSourcell%2FDoctor-Dignity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llSourcell%2FDoctor-Dignity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/llSourcell","download_url":"https://codeload.github.com/llSourcell/Doctor-Dignity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243593393,"owners_count":20316177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:01:00.483Z","updated_at":"2025-03-14T14:31:19.312Z","avatar_url":"https://github.com/llSourcell.png","language":"Python","funding_links":[],"categories":["Models and Tools","Python","Specialized Medical LLMs","Medical LLMs \u0026 Foundation Models"],"sub_categories":["Use Cases"],"readme":"# Doctor Dignity\n\u003cp align=\"center\"\u003e\n\n\nDISCLAIMER - Do not take any advice from Doctor Dignity seriously yet. This is a work in progress and taking any advice seriously could result in serious injury or even death. \n\n\u003cimg src=\"https://i.imgur.com/18jVWiV.png\" width=\"400\" height=\"400\"\u003e\n\u003c/p\u003e\n\n## Overview\nDoctor Dignity is a Large Language Model that can pass the US Medical Licensing Exam. This is an open-source project with a mission to provide everyone their own private doctor. Doctor Dignity is a version of Meta's [Llama2](https://ai.meta.com/llama/) 7 billion parameter Large Language Model that was fine-tuned on a Medical Dialogue Dataset, then further improved using Reinforcement Learning \u0026 Constitutional AI. Since the model is only 3 Gigabytes in size, it fits on any local device, so there is no need to pay an API to use it. It's free, made for offline usage which preserves patient confidentiality, and it's available on iOS, Android, and Web. Pull requests for feature additions and improvements are encouraged.\n\n## Dependencies\n- [Numpy](https://numpy.org/install/)           (Use matrix math operations)\n- [PyTorch](https://pytorch.org/)         (Build Deep Learning models)\n- [Datasets](https://huggingface.co/docs/datasets/index)        (Access datasets from huggingface hub)\n- [Huggingface_hub](https://huggingface.co/docs/huggingface_hub/v0.5.1/en/package_reference/hf_api) (access huggingface data \u0026 models) \n- [Transformers](https://huggingface.co/docs/transformers/index)    (Access models from HuggingFace hub)\n- [Trl](https://huggingface.co/docs/trl/index)             (Transformer Reinforcement Learning. And fine-tuning.)\n- [Bitsandbytes](https://github.com/TimDettmers/bitsandbytes)    (makes models smaller, aka 'quantization')\n- [Sentencepiece](https://github.com/google/sentencepiece)       (Byte Pair Encoding scheme aka 'tokenization')\n- [OpenAI](https://openai.com)          (Create synthetic fine-tuning and reward model data)\n- [TVM](https://tvm.apache.org/)             (Tensor Virtual Machine, converts onnx model to efficient cross-platform use)\n- [Peft](https://huggingface.co/blog/peft)            (Parameter Efficient Fine Tuning, use low rank adaption (LoRa) to fine-tune)\n- [Onnx](https://onnx.ai/)            (Convert trained model to universal format)\n\n\n\n## Installation\n\nInstall all dependencies in one line using [pip](https://pip.pypa.io/en/stable/installation/)\n\n```bash\npip install numpy torch datasets huggingface_hub transformers trl bitsandbytes sentencepiece openai tvm peft onnx\n```\n\n## iOS QuickStart v2\n\n1. Clone this repository\n```bash\ngit clone https://github.com/llSourcell/Doctor-Dignity\n```\n2. Download the Weights\n```bash\nmkdir -p dist/prebuilt\ngit clone https://github.com/mlc-ai/binary-mlc-llm-libs.git dist/prebuilt/lib\ncd dist/prebuilt\ngit lfs install\nwget --no-check-certificate 'https://drive.google.com/file/d/1MLy8BDhuTTcXqagzLFMA07JDzqjQYUTB/view?pli=1'\ncd ../..\n```\n3. Build the Tensor Virtual Machine Runtime\n```bash\ngit submodule update --init --recursive\npip install apache-tvm\ncd ./ios\npip install --pre --force-reinstall mlc-ai-nightly mlc-chat-nightly -f https://mlc.ai/wheels \n./prepare_libs.sh\n```\n** Find the right version of MLC LLM for your system [here](https://mlc.ai/package/)\n4. Add Weights to Xcode\n```bash\ncd ./ios\nopen ./prepare_params.sh # make sure builtin_list only contains \"RedPajama-INCITE-Chat-3B-v1-q4f16_1\"\n./prepare_params.sh\n```\n5. Open Xcode Project and run! \n\n\n## DIY Training\n\nIn order to train the model, you can run the training.ipynb notebook locally or remotely via a cloud service like Google Colab Pro. The training process requires a GPU, and if you don't have one then the most accessible option i found was using Google Colab [Pro](https://colab.research.google.com/signup) which costs $10/month. The total training time for Doctor Dignity including supervised fine-tuning of the initial LLama model on custom medical data, as well as further improving it via Reinforcement Learning from Constitional AI Feedback took 24 hours on a paid instance of Google Colab. If you're interested in learning more about how this process works, details are in the training.ipynb notebook. \n\n#### Cloud Training\n\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/llSourcell/DoctorGPT/blob/main/llama2.ipynb)\nclick here: https://colab.research.google.com/github/llSourcell/Doctor-Dignity/blob/main/llama2.ipynb\n\n#### Local Training\n\n```bash\ngit clone https://github.com/llSourcell/Doctor-Dignity.git\njupyter training.ipynb\n```\nGet jupyter [here](https://jupyter.org/install)\n\n## Usage  https://huggingface.co/llSourcell/medllama2_7b\n\nThere are 2 huggingface repos, one which is quantized for mobile and one that is not.\n\n#### Old iOS app \n   \n- Step 1: [Download](https://github.com/mlc-ai/mlc-llm/tree/main/ios) the iOS Machine Learning Compilation Chat Repository\n- Step 2: Follow the [installation steps](https://mlc.ai/mlc-llm/docs/deploy/ios.html) \n- Step 3: Once the app is running on your iOS device or simulator, tap \"add model variant\"\n- Step 4: Enter the URL for the latest Doctor Dignity model to download it: [https://huggingface.co/llSourcell/doctorGPT_mini] (https://huggingface.co/llSourcell/doctorGPT_mini)\n- Step 5: Tap 'Add Model' and start chatting locally, inference runs on device. No internet connection needed!\n\n#### Android app (TODO)\n\n- Step 1: [Download](https://github.com/mlc-ai/mlc-llm/tree/main/android) the Android Machine Learning Compilation Chat Repository\n- Step 2: Follow the [installation steps]([https://mlc.ai/mlc-llm/docs/deploy/ios.html](https://mlc.ai/mlc-llm/docs/deploy/android.html)) \n- Step 3: Tap \"add model variant\"\n- Step 4: Enter the URL for the latest Doctor Dignity model to download it: [https://huggingface.co/llSourcell/doctorGPT_mini](https://huggingface.co/llSourcell/doctorGPT_mini)\n- Step 5: Tap 'Add Model' and start chatting locally! No internet needed. \n\n#### Web (TODO)\n\nAs an experiment in Online Learning using actual human feedback, i want to deploy the model as a Flask API with a React front-end. In this case, anyone can chat with the model at this URL. After each query, a human can rate the model's response. This rating is then used to further improve the model's performance through reinforcement learning. to run the app, download [flask](https://flask.palletsprojects.com/en/2.3.x/) and then you can run:\n\n```bash\nflask run\n```\n\nThen visit localhost:3000 to interact with it! You can also deploy to [vercel](https://vercel.com/templates/ai)\n\n## Credits\n\nMeta, MedAlpaca, Apache, MLC Chat \u0026 OctoML \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FllSourcell%2FDoctor-Dignity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FllSourcell%2FDoctor-Dignity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FllSourcell%2FDoctor-Dignity/lists"}