Lingdan-4B-R1

Lingdan-V2 logo

Lingdan-V2: Large Language Models for Clinically Grounded Reasoning in Traditional Chinese Medicine

Open the Lingdan-V2 online demo

Lingdan-V2 paper on arXiv Hugging Face models ModelScope models LingLan benchmark Model scales: 4B, 8B, and 14B Apache License 2.0

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
Safetensors
Model size
4B params
Tensor type
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for TCMLLM/Lingdan-4B-R1

Finetuned
(1)
this model
Quantizations
1 model

Collection including TCMLLM/Lingdan-4B-R1

Paper for TCMLLM/Lingdan-4B-R1