Text Generation
Transformers
Safetensors
English
Chinese
Malay
qwen2
medical
red-flag
extraction
qwen2.5
multi-lingual
brunei-english
conversational
text-generation-inference
Instructions to use ningpy/redflag-modifier-3b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ningpy/redflag-modifier-3b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ningpy/redflag-modifier-3b") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ningpy/redflag-modifier-3b") model = AutoModelForCausalLM.from_pretrained("ningpy/redflag-modifier-3b", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ningpy/redflag-modifier-3b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ningpy/redflag-modifier-3b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ningpy/redflag-modifier-3b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ningpy/redflag-modifier-3b
- SGLang
How to use ningpy/redflag-modifier-3b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "ningpy/redflag-modifier-3b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ningpy/redflag-modifier-3b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "ningpy/redflag-modifier-3b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ningpy/redflag-modifier-3b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use ningpy/redflag-modifier-3b with Docker Model Runner:
docker model run hf.co/ningpy/redflag-modifier-3b
|
Download README.md from ningpy/redflag-modifier-3b: direct link, hf CLI and curl.
- Browser
- Download file 5.1 kB
-
https://huggingface.co/ningpy/redflag-modifier-3b/resolve/main/README.md
- Command line
-
hf download hf://ningpy/redflag-modifier-3b/README.md
-
curl -L -o README.md https://huggingface.co/ningpy/redflag-modifier-3b/resolve/main/README.md
5.1 kB
| license: apache-2.0 | |
| base_model: Qwen/Qwen2.5-3B-Instruct | |
| library_name: transformers | |
| tags: | |
| - medical | |
| - red-flag | |
| - extraction | |
| - qwen2.5 | |
| - multi-lingual | |
| - brunei-english | |
| language: | |
| - en | |
| - zh | |
| - ms | |
| # Red Flag Detection: `modifier` module (Qwen2.5-3B-Instruct + LoRA merged) | |
| Part of a **5-module medical red flag detection system** for Brunei English (Manglish), | |
| Chinese, and Bahasa Melayu clinical notes / patient messages. | |
| This model is the **`modifier` extraction module** โ one of 5 specialized modules used | |
| together with a Python rule engine (V20 spec, 59 rules). | |
| ## Sister modules | |
| - `peiyan-ning/redflag-symptom-3b` โ 83-symptom multi-label extraction | |
| - `peiyan-ning/redflag-context-3b` โ 12 context flags (post_trauma, drowning, etc.) | |
| - `peiyan-ning/redflag-modifier-3b` โ onset / fever_celsius / consciousness / etc. | |
| - `peiyan-ning/redflag-denied-3b` โ denied symptoms (multi-turn negation) | |
| - `peiyan-ning/redflag-gate-3b` โ 8 population gates (is_pregnant, is_child, ...) | |
| ## Performance (2246-case independent test set) | |
| Full 5-module pipeline + rule engine V46: | |
| | Metric | P | R | F1 | Acc | | |
| |---|---|---|---|---| | |
| | PRIMARY (any_matched ร labeled_matched) | **0.902** | **0.911** | **0.906** | 91.9% | | |
| | STRICT matched-only | 0.893 | 0.828 | 0.859 | 91.8% | | |
| | STRICT m+s | 0.844 | 0.905 | 0.873 | 92.1% | | |
| ## System prompt used at inference | |
| ``` | |
| Extract quantitative modifiers from text. | |
| ===== EXTRACT onset ===== | |
| Set onset:"acute" when text describes SUDDEN event: | |
| - "suddenly", "just", "out of nowhere", "in an instant", "็ช็ถ", "tiba-tiba" | |
| - Trauma events: "fell", "crash", "hit" | |
| - Symptom onset described as fast: "just started" | |
| Set onset:"chronic" when described as long-standing/gradual. | |
| ===== EXTRACT temperature ===== | |
| When text has actual number: "39.5ยฐC" / "38 degrees" / "40ๅบฆ" โ fever_celsius | |
| ===== EXTRACT other modifiers ===== | |
| - seizure duration in minutes โ seizure_duration_min | |
| - inhaler used / worked โ inhaler_used / inhaler_effective | |
| - bleeding amount described "heavy" / "uncontrolled" โ bleeding_severity | |
| - burn size โ burn_severity | |
| - burn location โ burn_location | |
| - consciousness: alert / confused / drowsy / unresponsive | |
| ===== EXAMPLES ===== | |
| "Suddenly severe chest pain" โ {"modifiers": {"onset": "acute"}} | |
| "Fell down and hit head" โ {"modifiers": {"onset": "acute"}} | |
| "Fever 39.5 for 3 days" โ {"modifiers": {"onset": "chronic", "fever_celsius": 39.5, "fever_days": 3}} | |
| "Seizure lasted 7 minutes" โ {"modifiers": {"seizure_duration_min": 7}} | |
| "Uncontrolled bleeding" โ {"modifiers": {"bleeding_severity": "uncontrolled"}} | |
| "Not sure about symptoms" โ {"modifiers": {}} | |
| Output: {"modifiers": {...}} | |
| ===== MULTILINGUAL / MANGLISH GUIDANCE ===== | |
| Text may be in Brunei/Manglish English or mixed with Malay/Chinese. | |
| Ignore these colloquial particles when extracting: "lah", "kah", "meh", "ah", "leh", "lor", "sia", "one". | |
| Common Manglish/Malay/Chinese mappings: | |
| - "kena panic attack" / "feel like dying" / "jantung deg-deg" โ severe_panic | |
| - "sesak nafas" (Malay) / "ๅไธ่ฟๆฐ" โ breathlessness | |
| - "sakit dada" (Malay) / "่ธๅฃ็ผ" โ chest_pain | |
| - "sakit kepala teruk" / "ๅง็ๅคด็" / "worst headache" โ thunderclap_headache | |
| - "pengsan" (Malay) / "ๆๅ" โ fainting | |
| - "sawan" (Malay) / "ๆฝๆ" โ seizure | |
| - "anak saya" (Malay: my child) โ is_child | |
| - "bayi saya" (Malay: my baby) โ is_baby | |
| - "warga emas" / "่ไบบๅฎถ" โ is_elderly | |
| - "hamil" / "ๆๅญ" โ is_pregnant | |
| - "kencing manis" (Malay: diabetes) โ has_diabetes | |
| - "asma" (Malay: asthma) โ has_asthma | |
| - "kena patuk ular" (Malay: snake bit) โ context_flags: venomous_bite | |
| Auntie/uncle in Manglish family reference: usually elderly family member โ is_elderly. | |
| ``` | |
| ## Usage | |
| ```python | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| import torch, json | |
| tok = AutoTokenizer.from_pretrained('peiyan-ning/redflag-modifier-3b') | |
| model = AutoModelForCausalLM.from_pretrained( | |
| 'peiyan-ning/redflag-modifier-3b', | |
| torch_dtype=torch.float16, | |
| device_map='auto' | |
| ) | |
| SYSTEM_PROMPT = tok.chat_template # or use the prompt above | |
| messages = [ | |
| {'role': 'system', 'content': SYSTEM_PROMPT}, | |
| {'role': 'user', 'content': 'My 3-year-old child has severe fever and vomiting lah'}, | |
| ] | |
| inputs = tok.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors='pt').to(model.device) | |
| out = model.generate(inputs, max_new_tokens=200, do_sample=False) | |
| text = tok.decode(out[0][inputs.shape[1]:], skip_special_tokens=True) | |
| result = json.loads(text) | |
| print(result) | |
| ``` | |
| ## Full pipeline | |
| See [git.evyd.tech/ai/redflag-detection-2.0](https://git.evyd.tech/ai/redflag-detection-2.0) for: | |
| - Rule engine (59 V20 rules) | |
| - Post-processing (gate_detector, severity_extractor, numeric_extractor) | |
| - End-to-end sample inference code | |
| ## Training | |
| - Base: Qwen/Qwen2.5-3B-Instruct | |
| - LoRA: r=32, ฮฑ=64, dropout=0.05 | |
| - Target modules: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj | |
| - 2 epochs, LR 2e-4, cosine, warmup 5%, effective batch 32 | |
| - Multi-lingual: EN/ZH/MS with Manglish particles (lah/kah/meh) | |