Text Generation
Transformers
Safetensors
English
Chinese
Malay
qwen2
redflag
medical
extraction
qwen2.5
LoRA-merged
conversational
text-generation-inference
Instructions to use ningpy/redflag-detection-V4.1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ningpy/redflag-detection-V4.1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ningpy/redflag-detection-V4.1") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ningpy/redflag-detection-V4.1") model = AutoModelForCausalLM.from_pretrained("ningpy/redflag-detection-V4.1", 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ningpy/redflag-detection-V4.1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ningpy/redflag-detection-V4.1" # 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-detection-V4.1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ningpy/redflag-detection-V4.1
- SGLang
How to use ningpy/redflag-detection-V4.1 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-detection-V4.1" \ --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-detection-V4.1", "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-detection-V4.1" \ --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-detection-V4.1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use ningpy/redflag-detection-V4.1 with Docker Model Runner:
docker model run hf.co/ningpy/redflag-detection-V4.1
Redflag Detection V4.1 (V20d, 65 rules)
Fine-tuned from Qwen2.5-7B-Instruct for medical red-flag extraction. Aligned with 2026-08 "Red Flad_New" spec, extended with 6 additional critical rules missing from the original spec.
What's new in V4.1 vs V4.0
- Fixed
is_malehallucination (0/269 val cases; V4.0 had schema gap wheresexwas in prompt but 0 training samples used it) - 6 new critical rules covering previously uncovered surgical/OB
emergencies:
- V20-60 testicular_torsion (sex=male defensive gate)
- V20-61 pyelonephritis (painful_urination + fever + severe)
- V20-62 severe_pid (foul_discharge + fever + severe)
- V20-63 eye_emergency (angle-closure glaucoma / sudden vision loss; any age)
- V20-64 cauda_equina (new_incontinence + severe_weakness; any adult age)
- V20-65 postpartum_hemorrhage (sex=female defensive gate)
- Defensive sex gates on Row 34-39 (pregnancy) — blocks conflict only, not required
- Pediatric age fallback — Row 40-46 accept
is_child/is_babyboolean whenage_bandabsent - 50 new training samples covering sex extraction from "Patient Info: Age X, Male/Female" blocks (EN/中文/BM)
Performance (val 269, strict)
| V4.0 (V20c) | V4.1 (V20d) | |
|---|---|---|
| Exact Match | 89.2% | 87.0% |
| Precision | 0.918 | 0.901 |
| Recall | 0.749 | 0.786 |
| F1 | 0.825 | 0.839 |
Performance (clinical-fair, SUSPECTED = TP for recall)
- Precision: 0.753
- Recall: 0.853
- F1: 0.800
Usage
python3 -m vllm.entrypoints.openai.api_server \
--model ningpy/redflag-detection-V4.1 \
--served-model-name redflag \
--dtype float16
Requires V20e rule engine (65 compiled rules with sex_gate + age fallback).
Training
- 3816 samples (V20c 3766 + patch20d 50 sex-field samples)
- LoRA r=32 alpha=64, 7 target projections
- 3 epochs @ 2e-5, seq len 1900, 8×V100 DDP
- Downloads last month
- -