commit 5f23abe66a1fa52fe93528214b0a0d43dc48f7e1 Author: ModelHub XC Date: Fri Jul 17 21:26:13 2026 +0800 初始化项目,由ModelHub XC社区提供模型 Model: DipaHealth/DipaMed-1 Source: Original Platform diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..52373fe --- /dev/null +++ b/.gitattributes @@ -0,0 +1,36 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.parquet filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +*.safetensors filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text +tokenizer.json filter=lfs diff=lfs merge=lfs -text diff --git a/README.md b/README.md new file mode 100644 index 0000000..e48698d --- /dev/null +++ b/README.md @@ -0,0 +1,104 @@ +--- +license: llama3.1 +base_model: meta-llama/Llama-3.1-8B +language: +- en +pipeline_tag: text-generation +tags: +- medical +- clinical +- nigeria +- healthcare +- africa +- llama +- global-health +--- + +# DipaMed-1 + +**A language model specialised on Nigerian clinical guidelines.** + +DipaMed-1 adapts Meta's Llama-3.1-8B to Nigerian medicine, grounded in Federal Ministry of Health (FMOH) and Nigeria Centre for Disease Control (NCDC) clinical guidelines. It is built to give locally-appropriate clinical guidance that reflects Nigerian disease priorities, the Nigerian Essential Medicines List, and national treatment protocols. + +- **Developed by:** Destiny Ebhodaghe Ibhate (DipaHealth) +- **Base model:** meta-llama/Llama-3.1-8B +- **Language:** English +- **License:** Llama 3.1 Community License + +> **Intended use:** clinical decision *support* for trained health workers. DipaMed-1 is **not** an autonomous diagnostic system and must not be used to make patient-care decisions without a qualified clinician. + +## Highlights - where DipaMed-1 leads + +On [NigeriaMedQA](https://huggingface.co/datasets/DipaHealth/NigeriaMedQA), DipaMed-1 **outperforms its base model on the Nigeria-specific clinical topics it was built for:** + +| Topic | DipaMed-1 | Base Llama-3.1-8B | Improvement | +|---|---|---|---| +| Mental health | **95.8%** | 87.5% | **+8.3** | +| Maternal emergencies | **90.6%** | 84.4% | **+6.2** | +| Drug availability | **72.8%** | 67.0% | **+5.8** | +| Hypertension | **68.5%** | 64.8% | **+3.7** | +| Tuberculosis-HIV | **82.4%** | 79.4% | **+3.0** | +| Lassa fever | **79.5%** | 76.9% | **+2.6** | +| Sickle cell disease | **81.8%** | 80.0% | **+1.8** | +| Outbreak diseases | **62.1%** | 60.3% | **+1.8** | + +These are the diseases and decisions that matter most in Nigerian practice. Across the full benchmark, DipaMed-1 performs comparably to the base model overall (76.3% vs 77.0%), while delivering these gains where Nigerian specialisation counts. + +## What makes it different + +General medical models are trained on North American and European data. DipaMed-1 is grounded in **Nigerian** guidelines, giving Nigeria-appropriate answers a general model cannot: correct local first-line treatments, Essential-Medicines-List-aware choices, and NCDC/FMOH-aligned protocols. + +## How it was built + +| Stage | Purpose | Data | +|---|---|---| +| **Continued pretraining** | Absorb Nigerian medical knowledge | 156 million words of Nigerian biomedical text (PubMed abstracts, open-access PMC full-text, clinical guidelines); approx. 254M tokens | +| **Instruction tuning** | Learn to answer clinical questions | Q&A generated from and independently verified against real Nigerian guidelines, plus cleaned expert-created sources (PubMedQA, MedQA-USMLE, WikiDoc) | + +Training used QLoRA (rank 16), a learning-rate sweep with model selection on a **held-out validation set**, and completion-only loss masking. The evaluation benchmark was kept fully uncontaminated and used only once for final scoring. The pretraining corpus is not released; its construction methodology is described in the accompanying paper. + +## Usage + +```python +import torch +from transformers import AutoModelForCausalLM, AutoTokenizer + +model_id = "DipaHealth/DipaMed-1" +model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto") +tok = AutoTokenizer.from_pretrained(model_id) + +messages = [ + {"role": "system", "content": "You are DipaMed-1, a clinical AI assistant grounded in Nigerian guidelines."}, + {"role": "user", "content": "First-line treatment for uncomplicated malaria in a non-pregnant adult in Nigeria?"}, +] +input_ids = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device) +out = model.generate(input_ids=input_ids, max_new_tokens=256, do_sample=False, pad_token_id=tok.eos_token_id) +print(tok.decode(out[0][input_ids.shape[1]:], skip_special_tokens=True)) +``` + +## Recommended deployment: retrieve, then answer (RAG) + +For production, wrap DipaMed-1 in a retrieval-augmented (RAG) pipeline over the Nigerian guidelines: retrieve the relevant passage, give it to the model, and have it answer **from that passage with a citation**. This substantially improves factual reliability, especially for exact drug doses where all language models are unreliable from memory, and lets the system cite its source. A dedicated DipaMed RAG service is planned as a separate release. + +## Limitations and responsible use + +- **Exact doses:** do not rely on DipaMed-1 for precise dosing without retrieval support; language models do not reliably memorise numeric dose tables. +- **Decision support only:** it assists clinicians and must not make autonomous clinical decisions. +- **Scale:** at 8B parameters it will not match frontier models on general medicine; its strength is Nigerian domain specialisation. +- **Errors and bias:** like all language models it can produce confident but incorrect answers; verify outputs against source guidelines. +- **Scope:** English, text-only in this version. Speech and Nigerian-language support are planned. + +## Citation + +```bibtex +@misc{dipamed2026, + title = {DipaMed-1: A Nigerian Guideline-Specialised Clinical Language Model}, + author = {Ibhate, Destiny Ebhodaghe}, + year = {2026}, + howpublished = {\url{https://huggingface.co/DipaHealth/DipaMed-1}} +} +``` + +## Acknowledgements + +Built on Meta Llama-3.1-8B. Evaluated with [NigeriaMedQA](https://huggingface.co/datasets/DipaHealth/NigeriaMedQA). Grounded in FMOH and NCDC clinical guidelines. diff --git a/chat_template.jinja b/chat_template.jinja new file mode 100644 index 0000000..33089ac --- /dev/null +++ b/chat_template.jinja @@ -0,0 +1,109 @@ +{{- bos_token }} +{%- if custom_tools is defined %} + {%- set tools = custom_tools %} +{%- endif %} +{%- if not tools_in_user_message is defined %} + {%- set tools_in_user_message = true %} +{%- endif %} +{%- if not date_string is defined %} + {%- set date_string = "26 Jul 2024" %} +{%- endif %} +{%- if not tools is defined %} + {%- set tools = none %} +{%- endif %} + +{#- This block extracts the system message, so we can slot it into the right place. #} +{%- if messages[0]['role'] == 'system' %} + {%- set system_message = messages[0]['content']|trim %} + {%- set messages = messages[1:] %} +{%- else %} + {%- set system_message = "" %} +{%- endif %} + +{#- System message + builtin tools #} +{{- "<|start_header_id|>system<|end_header_id|>\n\n" }} +{%- if builtin_tools is defined or tools is not none %} + {{- "Environment: ipython\n" }} +{%- endif %} +{%- if builtin_tools is defined %} + {{- "Tools: " + builtin_tools | reject('equalto', 'code_interpreter') | join(", ") + "\n\n"}} +{%- endif %} +{{- "Cutting Knowledge Date: December 2023\n" }} +{{- "Today Date: " + date_string + "\n\n" }} +{%- if tools is not none and not tools_in_user_message %} + {{- "You have access to the following functions. To call a function, please respond with JSON for a function call." }} + {{- 'Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.' }} + {{- "Do not use variables.\n\n" }} + {%- for t in tools %} + {{- t | tojson(indent=4) }} + {{- "\n\n" }} + {%- endfor %} +{%- endif %} +{{- system_message }} +{{- "<|eot_id|>" }} + +{#- Custom tools are passed in a user message with some extra guidance #} +{%- if tools_in_user_message and not tools is none %} + {#- Extract the first user message so we can plug it in here #} + {%- if messages | length != 0 %} + {%- set first_user_message = messages[0]['content']|trim %} + {%- set messages = messages[1:] %} + {%- else %} + {{- raise_exception("Cannot put tools in the first user message when there's no first user message!") }} +{%- endif %} + {{- '<|start_header_id|>user<|end_header_id|>\n\n' -}} + {{- "Given the following functions, please respond with a JSON for a function call " }} + {{- "with its proper arguments that best answers the given prompt.\n\n" }} + {{- 'Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.' }} + {{- "Do not use variables.\n\n" }} + {%- for t in tools %} + {{- t | tojson(indent=4) }} + {{- "\n\n" }} + {%- endfor %} + {{- first_user_message + "<|eot_id|>"}} +{%- endif %} + +{%- for message in messages %} + {%- if not (message.role == 'ipython' or message.role == 'tool' or 'tool_calls' in message) %} + {{- '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' }} + {%- elif 'tool_calls' in message %} + {%- if not message.tool_calls|length == 1 %} + {{- raise_exception("This model only supports single tool-calls at once!") }} + {%- endif %} + {%- set tool_call = message.tool_calls[0].function %} + {%- if builtin_tools is defined and tool_call.name in builtin_tools %} + {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}} + {{- "<|python_tag|>" + tool_call.name + ".call(" }} + {%- for arg_name, arg_val in tool_call.arguments | items %} + {{- arg_name + '="' + arg_val + '"' }} + {%- if not loop.last %} + {{- ", " }} + {%- endif %} + {%- endfor %} + {{- ")" }} + {%- else %} + {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}} + {{- '{"name": "' + tool_call.name + '", ' }} + {{- '"parameters": ' }} + {{- tool_call.arguments | tojson }} + {{- "}" }} + {%- endif %} + {%- if builtin_tools is defined %} + {#- This means we're in ipython mode #} + {{- "<|eom_id|>" }} + {%- else %} + {{- "<|eot_id|>" }} + {%- endif %} + {%- elif message.role == "tool" or message.role == "ipython" %} + {{- "<|start_header_id|>ipython<|end_header_id|>\n\n" }} + {%- if message.content is mapping or message.content is iterable %} + {{- message.content | tojson }} + {%- else %} + {{- message.content }} + {%- endif %} + {{- "<|eot_id|>" }} + {%- endif %} +{%- endfor %} +{%- if add_generation_prompt %} + {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' }} +{%- endif %} diff --git a/config.json b/config.json new file mode 100644 index 0000000..0f7dd6d --- /dev/null +++ b/config.json @@ -0,0 +1,36 @@ +{ + "architectures": [ + "LlamaForCausalLM" + ], + "attention_bias": false, + "attention_dropout": 0.0, + "bos_token_id": 128000, + "dtype": "bfloat16", + "eos_token_id": 128001, + "head_dim": 128, + "hidden_act": "silu", + "hidden_size": 4096, + "initializer_range": 0.02, + "intermediate_size": 14336, + "max_position_embeddings": 131072, + "mlp_bias": false, + "model_type": "llama", + "num_attention_heads": 32, + "num_hidden_layers": 32, + "num_key_value_heads": 8, + "pad_token_id": null, + "pretraining_tp": 1, + "rms_norm_eps": 1e-05, + "rope_parameters": { + "factor": 8.0, + "high_freq_factor": 4.0, + "low_freq_factor": 1.0, + "original_max_position_embeddings": 8192, + "rope_theta": 500000.0, + "rope_type": "llama3" + }, + "tie_word_embeddings": false, + "transformers_version": "5.13.0", + "use_cache": true, + "vocab_size": 128256 +} diff --git a/generation_config.json b/generation_config.json new file mode 100644 index 0000000..7063773 --- /dev/null +++ b/generation_config.json @@ -0,0 +1,9 @@ +{ + "_from_model_config": true, + "bos_token_id": 128000, + "do_sample": true, + "eos_token_id": 128001, + "temperature": 0.6, + "top_p": 0.9, + "transformers_version": "5.13.0" +} diff --git a/model.safetensors b/model.safetensors new file mode 100644 index 0000000..7a8951a --- /dev/null +++ b/model.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3638e75f62677b6314fee2316d8f3320f535f86896447c9ed060b69eb8cae2af +size 16060556616 diff --git a/tokenizer.json b/tokenizer.json new file mode 100644 index 0000000..1c1d8d5 --- /dev/null +++ b/tokenizer.json @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b9e4e7fb171f92fd137b777cc2714bf87d11576700a1dcd7a399e7bbe39537b +size 17209920 diff --git a/tokenizer_config.json b/tokenizer_config.json new file mode 100644 index 0000000..aadc141 --- /dev/null +++ b/tokenizer_config.json @@ -0,0 +1,14 @@ +{ + "backend": "tokenizers", + "bos_token": "<|begin_of_text|>", + "clean_up_tokenization_spaces": true, + "eos_token": "<|eot_id|>", + "is_local": false, + "local_files_only": false, + "model_input_names": [ + "input_ids", + "attention_mask" + ], + "model_max_length": 131072, + "tokenizer_class": "TokenizersBackend" +}