Instructions to use TCMLLM/Lingdan-4B-R1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TCMLLM/Lingdan-4B-R1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="TCMLLM/Lingdan-4B-R1") 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("TCMLLM/Lingdan-4B-R1") model = AutoModelForCausalLM.from_pretrained("TCMLLM/Lingdan-4B-R1", 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 TCMLLM/Lingdan-4B-R1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "TCMLLM/Lingdan-4B-R1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TCMLLM/Lingdan-4B-R1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/TCMLLM/Lingdan-4B-R1
- SGLang
How to use TCMLLM/Lingdan-4B-R1 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 "TCMLLM/Lingdan-4B-R1" \ --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": "TCMLLM/Lingdan-4B-R1", "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 "TCMLLM/Lingdan-4B-R1" \ --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": "TCMLLM/Lingdan-4B-R1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use TCMLLM/Lingdan-4B-R1 with Docker Model Runner:
docker model run hf.co/TCMLLM/Lingdan-4B-R1
Lingdan-4B-R1
Lingdan-V2: Large Language Models for Clinically Grounded Reasoning in Traditional Chinese Medicine
Paper ยท Model ยท Results ยท Quickstart ยท vLLM ยท Prompts ยท Citation
Model Details
Lingdan-4B-R1 is a Qwen3-based TCM model in the Lingdan-V2 family.
| Field | Value |
|---|---|
| Parameter scale | 4B |
| Architecture family | Qwen3 causal language model |
| Training stage | Reinforcement learning (RL; prescription-centered GRPO) |
| Starting checkpoint / backbone | Lingdan-4B-SFT |
| Intended use | Structured TCM clinical reasoning and prescription-generation research |
| Platform model ID | TCMLLM/Lingdan-4B-R1 |
Training History
This checkpoint includes the following training stages, in order:
| Stage | Objective | Training data |
|---|---|---|
| CPT โ continued pretraining | TCM-domain knowledge acquisition | 16.62B tokens |
| SFT โ supervised fine-tuning | Reasoning-oriented instruction following | 7,729,982 samples / 2.08B tokens |
| RL โ prescription-centered GRPO | Prescription composition alignment | 24,212 samples |
Checkpoint Evaluation
Results for Lingdan-4B-R1 reported in Lingdan-V2 (arXiv:2610.14705v1). Full: LingLan (25,620 items); Hard: LingLan-Hard (5,200 items). Overall Score averages 16 primary metrics, excluding dose MAE. All scores use a 0โ100 scale except MAE (lower is better). The paper uses zero-shot Chinese prompts, temperature 0.6, and at most 8,192 generated tokens; reproduction also requires the same data and scoring pipeline.
| Metric | LingLan Full | LingLan-Hard |
|---|---|---|
| Overall Score โ | 63.4 | 40.4 |
| Prescription generation F1 โ | 36.2 | 24.8 |
| Clinical-record entity extraction F1 โ | 70.5 | 58.4 |
| Classical-text entity extraction F1 โ | 58.5 | 42.5 |
| Syndrome generation F1 โ | 9.5 | 1.6 |
| Treatment-principle generation F1 โ | 13.9 | 2.4 |
| Prescription dose cosine โ | 34.2 | 23.4 |
| Prescription dose MAE โ | 4.6 | 4.7 |
Task-level scores follow the appendixโs primary DTR metrics, not the character-level DTR-F1 variant.
| Private prescription evaluation (4,348 cases) | Score |
|---|---|
| Herb F1 โ | 52.7 |
| Herb precision โ | 52.5 |
| Herb recall โ | 54.1 |
| Dose cosine โ | 49.5 |
| Dose MAE โ | 5.062 |
The private set contains 4,348 de-identified spleen/stomach disorder cases. See the full comparison for other checkpoints.
Quickstart
Use Transformers โฅ4.51.0; see the Qwen3 quickstart.
pip install -U torch transformers accelerate
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "TCMLLM/Lingdan-4B-R1"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto",
).eval()
messages = [{"role": "user", "content": "่ฏท็ฎ่ฆไป็ปไธญๅป่พจ่ฏ่ฎบๆฒป็ๅบๆฌๆฆๅฟตใ"}]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
enable_thinking=True,
)
inputs = tokenizer([text], return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=8192,
eos_token_id=[151645, 151643], # <|im_end|> and <|endoftext|>
do_sample=True,
temperature=0.6,
top_p=0.95,
top_k=20,
)
new_tokens = outputs[0, inputs.input_ids.shape[1]:]
print(tokenizer.decode(new_tokens, skip_special_tokens=True))
The explicit EOS IDs stop generation at either the chat-turn or text terminator.
Thinking Mode
The quickstart enables thinking with enable_thinking=True. Set it to False for direct answers. The released chat templates support this switch.
| Mode | enable_thinking |
Temperature | Top-p | Top-k |
|---|---|---|---|---|
| Thinking | True |
0.6 | 0.95 | 20 |
| Non-thinking | False |
0.7 | 0.8 | 20 |
These are Qwen3 inference starting settings; behavior after fine-tuning may vary. Prefer the explicit switch over the unverified /think and /no_think soft instructions. Separate direct-generation output as follows:
raw_output = tokenizer.decode(new_tokens, skip_special_tokens=True)
reasoning_part, delimiter, final_answer = raw_output.partition("</think>")
if delimiter:
thinking_content = reasoning_part.removeprefix("<think>").strip()
final_answer = final_answer.strip()
else:
thinking_content = ""
final_answer = raw_output.strip()
print("Thinking:", thinking_content)
print("Answer:", final_answer)
If generation hits the token limit before the thinking block closes, increase the budget and retry; the answer is incomplete.
vLLM Deployment
Install vLLM in a GPU environment with compatible CUDA/PyTorch; see the Qwen3 vLLM guide.
pip install -U "vllm>=0.9.0" openai
Start the Server
Hugging Face:
export VLLM_USE_MODELSCOPE=false
vllm serve TCMLLM/Lingdan-4B-R1 \
--served-model-name Lingdan-4B-R1 \
--host 127.0.0.1 \
--port 8000 \
--max-model-len 16384 \
--reasoning-parser qwen3
Replace the repository ID with a local model directory to reuse downloaded files. For two GPUs, append --tensor-parallel-size 2. Adjust the 16,384-token context limit (input + output) to available GPU memory.
Chat Client
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="EMPTY")
response = client.chat.completions.create(
model="Lingdan-4B-R1",
messages=[{"role": "user", "content": "่ฏท็ฎ่ฆไป็ปไธญๅป่พจ่ฏ่ฎบๆฒป็ๅบๆฌๆฆๅฟตใ"}],
temperature=0.6,
top_p=0.95,
max_tokens=8192,
extra_body={
"top_k": 20,
"chat_template_kwargs": {"enable_thinking": True},
"stop_token_ids": [151645, 151643],
},
)
message = response.choices[0].message
thinking_content = (
getattr(message, "reasoning", None)
or getattr(message, "reasoning_content", None)
or ""
)
print("Thinking:", thinking_content)
print("Answer:", message.content)
print("Finish reason:", response.choices[0].finish_reason)
chat_template_kwargs selects thinking mode; --reasoning-parser qwen3 separates its output. To disable thinking, use the non-thinking settings above. The client supports both reasoning and the older reasoning_content field (vLLM reference). Parse task JSON from message.content; finish_reason="length" indicates truncation.
EMPTY is a placeholder for the local server started without API-key authentication.
Task Prompts
For SFT/R1 models, fill the placeholders in these LingLan evaluation templates and pass the text as the user message.
Clinical-record Entity Extraction
Source: LingLan ner_clinic.py.
่ฏทไปไปฅไธ็
ๅๆๆฌไธญๆฝๅๆๅฎ็ฑปๅ็ๅฎไฝใ
ๆณจๆ๏ผ
1. ่ฏทๅ
ไป็ปๅๆๆๆฌๅ
ๅฎน๏ผๆ่ๆฏไธชๅฎไฝ็ฑปๅ็่ฏๅซ่ฆ็น๏ผ็ถๅๅ่พๅบ็ปๆ
2. ๅฆๆๆไธชๅฎไฝ็ฑปๅๅจๆๆฌไธญๆฒกๆๅฏนๅบๅฎไฝ๏ผ่ฏท่ฟๅ็ฉบๅ่กจ[]
3. ๅฆๆๅไธไธชๅฎไฝๅจๆๆฌไธญๅบ็ฐๅคๆฌก๏ผ่ฏทๅจๅ่กจไธญๆ้กบๅบ้ๅคๅบ็ฐ
ๆๆฌ๏ผ
{text}
้่ฆๆฝๅ็ๅฎไฝ็ฑปๅ๏ผ
{entity_types}
่ฏทๆ็
งไปฅไธJSONๆ ผๅผ่พๅบ็ปๆ๏ผๆฏไธชๅฎไฝ็ฑปๅๅฏนๅบไธไธชๅ่กจ๏ผๅฆๆๆๆฌไธญๆไธชๅฎไฝๅบ็ฐๅคๆฌก๏ผ่ฏทๅจๅ่กจไธญ้ๅคๅบ็ฐ๏ผ
```json
{
"ๅฎไฝ็ฑปๅ1": ["ๅฎไฝ1", "ๅฎไฝ2", ...],
"ๅฎไฝ็ฑปๅ2": ["ๅฎไฝ1", "ๅฎไฝ2", ...],
...
}
```
Classical-text Entity Extraction
Source: LingLan ner_ancient.py.
่ฏทไปไปฅไธๅค็ฑๆๆฌไธญๆฝๅๆๅฎ็ฑปๅ็ๅฎไฝใ
ๆณจๆ๏ผ
1. ่ฏทๅ
ไป็ปๅๆๅค็ฑๆๆฌๅ
ๅฎน๏ผๆ่ๅคๆ่ฏญ่จ็น็นๅๅๅฎไฝ็ฑปๅ็่ฏๅซ่ฆ็น๏ผ็ถๅๅ่พๅบ็ปๆ
2. ๅฆๆๆไธชๅฎไฝ็ฑปๅๅจๆๆฌไธญๆฒกๆๅฏนๅบๅฎไฝ๏ผ่ฏท่ฟๅ็ฉบๅ่กจ[]
3. ๅฆๆๅไธไธชๅฎไฝๅจๆๆฌไธญๅบ็ฐๅคๆฌก๏ผ่ฏทๅจๅ่กจไธญๆ้กบๅบ้ๅคๅบ็ฐ
ๆๆฌ๏ผ
{text}
้่ฆๆฝๅ็ๅฎไฝ็ฑปๅ๏ผ
{entity_types}
่ฏทๆ็
งไปฅไธJSONๆ ผๅผ่พๅบ็ปๆ๏ผๆฏไธชๅฎไฝ็ฑปๅๅฏนๅบไธไธชๅ่กจ๏ผๅฆๆๆๆฌไธญๆไธชๅฎไฝๅบ็ฐๅคๆฌก๏ผ่ฏทๅจๅ่กจไธญ้ๅคๅบ็ฐ๏ผ
```json
{
"ๅฎไฝ็ฑปๅ1": ["ๅฎไฝ1", "ๅฎไฝ2", ...],
"ๅฎไฝ็ฑปๅ2": ["ๅฎไฝ1", "ๅฎไฝ2", ...],
...
}
```
Joint Syndrome, Treatment, and Prescription Generation
Source: LingLan pres_diag_eval.py.
่ฏทๆ นๆฎไปฅไธ็
ๅๆๆฌ๏ผ่ฟ่กๅฎๆด็ไธญๅป่ฏ็ๅๆ๏ผๅ
ๆฌ่พจ่ฏใๆฒปๆณๅๅคๆนใ
ๆณจๆ๏ผ
1. ่ฏทไป็ปๅๆๆฃ่
็็็ถ่กจ็ฐใ่่่ฑก็ญไฟกๆฏ
2. ่พจ่ฏ๏ผ็ปๅบๅ็กฎ็ไธญๅป่ฏๅๅคๆญ๏ผๅฆๆๅคไธช๏ผ็จ้ๅทๅ้๏ผ
3. ๆฒปๆณ๏ผๆ นๆฎ่พจ่ฏ็ปๆ็กฎๅฎ็ธๅบ็ๆฒป็ๆนๆณ๏ผๅฆๆๅคไธช๏ผ็จ้ๅทๅ้๏ผ
4. ๅคๆน๏ผๅผๅ
ทๅ
ทไฝ็ไธญ่ฏๅคๆน๏ผๆ ผๅผไธบ"่ฏๅ: ๅ้, ่ฏๅ: ๅ้"
็
ๅๆๆฌ๏ผ
{medical_record}
่ฏทๆ็
งไปฅไธJSONๆ ผๅผ่พๅบ็ปๆ๏ผ
```json
{
"่พจ่ฏ": "่ฏๅ1, ่ฏๅ2, ...",
"ๆฒปๆณ": "ๆฒปๆณ1, ๆฒปๆณ2, ...",
"ๅคๆน": "่ฏๅ1: ๅ้1, ่ฏๅ2: ๅ้2, ่ฏๅ3: ๅ้3, ..."
}
```
Use the datasetโs exact entity labels. JSON examples contain illustrative ellipses; actual output must be valid JSON. In joint generation, ่พจ่ฏ, ๆฒปๆณ, and ๅคๆน are strings; format prescription items as ่ฏๅ: ๆฐๅผg. Extract task JSON from the final answer using the output handling above.
Data Privacy and Responsible Use
Lingdan-V2 is for research and does not replace qualified clinical judgment. Private clinical data are not released. Retrospective prescription agreement is not evidence of clinical safety or effectiveness; use de-identified inputs and professional review for any clinical application.
License
Lingdan-V2 model weights and project-owned documentation and images are released under the Apache License 2.0. See NOTICE for attribution notices. Third-party data and materials remain subject to their original terms.
Citation
Please cite Lingdan-V2 and the earlier Lingdan work:
@misc{hua2026lingdanv2,
title = {{Lingdan-V2}: Large language models for clinically grounded reasoning in traditional Chinese medicine},
author = {Hua, Rui and Wei, Yu and Jin, Ziri and Sun, Zhuo and Chang, Kai and Xia, Jianan and Shu, Zixin and Li, Xiaodong and Jia, Dongmei and Dong, Fei and Zhang, Runshun and Yu, Jian and Xu, Hao and Yu, Haibin and Li, Jiansheng and Liu, Baoyan and Wang, Wenjia and Zhou, Xuezhong},
year = {2026},
eprint = {2610.14705},
archivePrefix = {arXiv},
primaryClass = {cs.CL},
url = {https://arxiv.org/abs/2610.14705}
}
@article{hua2024lingdan,
title={Lingdan: enhancing encoding of traditional Chinese medicine knowledge for clinical reasoning tasks with large language models},
author={Hua, Rui and Dong, Xin and Wei, Yu and Shu, Zixin and Yang, Pengcheng and Hu, Yunhui and Zhou, Shuiping and Sun, He and Yan, Kaijing and Yan, Xijun and others},
journal={Journal of the American Medical Informatics Association},
volume={31},
number={9},
pages={2019--2029},
year={2024},
publisher={Oxford University Press}
}
Related Links
Paper ยท GitHub ยท Hugging Face collection ยท ModelScope collection ยท LingLan benchmark
- Downloads last month
- 93