Building a Vertical LLM for Traditional Chinese Medicine: Technical Architecture and Deployment Practices
This article walks through the technical construction and real-world deployment of a domain-specific large language model for Traditional Chinese Medicine (TCM). It explains why general-purpose LLMs break down in TCM scenarios, how to build a six-source data foundation with deduplication, de-identification, and quality tiering, how to convert a clinical knowledge graph into trainable corpus with semantic diversity, and how a four-layer training stack (domain pre-training, SFT, reward modeling, RLHF) is combined with an expert evaluation loop. Deployment forms, engineering prerequisites, and common pitfalls such as evaluation-set leakage and missing abstention are also covered.
1. Why TCM Needs a Vertical LLM
General-purpose LLMs perform well on open-domain question answering, but the moment they enter a TCM setting, three structural problems surface:
- Semantic drift. Terms such as “epigastric fullness,” “poor appetite,” and “fatigue” have a statistical distribution in general corpora that differs completely from their meaning in a TCM context.
- Broken reasoning chains. TCM diagnosis and treatment is a multi-hop chain of symptoms → pattern → treatment principle → formula. General models usually learn only surface-level word co-occurrence.
- Blurred safety boundaries. Medical settings tolerate almost no hallucination. The model must explicitly abstain or hand off to a human when it is uncertain.
So the goal of a TCM vertical is not “a model that can chat.” It is a clinically assistive decision system with traceable knowledge, explainable reasoning, and constrained output. That decision dictates the technical route: knowledge engineering as the skeleton, data engineering as the flesh, and expert evaluation as the closed loop.
2. The Data Foundation: The Real Moat
The performance ceiling of a vertical model is set by its data. A usable TCM data system typically draws on six complementary sources:
- Natural-language data converted from a knowledge graph. Entities and relation triples are rewritten back into natural language, reaching tens of millions of records. This solves the problem that structured knowledge cannot be consumed directly by a language model.
- Classical texts and literature. On the order of a thousand classic and modern works, providing terminology lineage and theoretical grounding. These require traditional/simplified normalization, variant-character merging, and edition collation first.
- Real expert case records. On the order of a hundred thousand cases. This is the scarcest supervision signal for pattern-differentiation reasoning chains.
- Objective four-examination data. Normalized descriptions of pulse, tongue, meridians, and acupoints, on the order of a hundred thousand entries, used to turn invisible information into text.
- Real clinical records. From a million to tens of millions of entries, covering long-tail patterns and regional prescribing habits.
- A terminology normalization dictionary. A standard vocabulary for symptoms and signs, serving as the shared baseline for both data cleaning and evaluation.
Engineering requires three gates: deduplication (a dual check using approximate hashing plus semantic similarity), de-identification (bidirectional scanning of structured fields and free text to remove direct and quasi identifiers), and quality tiering (tagging by source trustworthiness and expert annotation density so that training can apply weighted sampling).
# Illustrative: weighted sampling across quality tiersdef sample_weight(record):w = 1.0w *= SOURCE_TRUST[record.source] # different weights for literature/case records/clinical recordsw *= 1.0 + 0.5 * record.expert_richness # expert annotation densityif record.quality_tier == "low":w *= 0.2return w
3. The Knowledge Graph: From Triples to Trainable Corpus
The pivotal step is to first build a diagnosis-and-treatment knowledge graph from clinical data of senior TCM physicians and from literature, then “translate” it into a form the model can learn. The ontology generally covers six node types — patterns, symptoms, treatment principles, formulas, Chinese medicinals, and acupoints — with relations such as symptom–pattern, pattern–treatment principle, treatment principle–formula, and formula–composition.
The conversion is not template concatenation. It requires semantic diversification: expressing the same relation in multiple sentence patterns and at multiple levels of detail, while preserving intermediate reasoning steps, so the model learns the chain rather than the answer.
Triple: (spleen deficiency with dampness excess, treatment principle, strengthen spleen and resolve dampness)Sample A: The patient presents with poor appetite, abdominal distension, and loose stools; this is differentiated as spleen deficiency with dampness excess, to be treated by strengthening the spleen and resolving dampness.Sample B: In spleen deficiency with dampness excess, transportation and transformation fail, so strengthening the spleen and resolving dampness is the appropriate principle.Sample C: A thick white tongue coating with a slow pulse usually indicates spleen deficiency with dampness excess, for which strengthening the spleen and resolving dampness may be considered.
The accompanying terminology normalization dictionary serves two purposes: aligning free text to standard terms before training, and acting as the ground-truth basis for answer correctness during evaluation, which avoids the noise of marking a correct answer wrong simply because the wording differs.
4. Four-Layer Progressive Training: Pre-training, SFT, Reward Modeling, RL
The mature industry practice is to decouple the layers, with each layer solving one class of problem:
- Domain pre-training. Inject the terminology distribution and classical-expression habits. Goal: “understand the input.”
- Supervised fine-tuning (SFT). Use case records and graph-converted samples to teach “how to answer.” Goal: “answer like a clinician.”
- Reward model (RM). Convert expert preferences into an optimizable scalar. Goal: “know what good looks like.”
- Reinforcement learning (RLHF / preference optimization). Align for safety and consistency. Goal: “be good reliably.”
The first two layers are usually completed up front; the latter two are the main arena for long-term iteration. The engineering crux of reward modeling is annotation consistency: multiple annotators, disagreement arbitration, and inter-annotator agreement monitoring are required. Otherwise the reward signal amplifies annotation noise into policy degradation.
# Illustrative: minimal structure of a preference recordpreference = {"prompt": "Thick white tongue coating, slow pulse, poor appetite and loose stools — how is this differentiated?","chosen": "Most likely spleen deficiency with dampness excess, treated by strengthening the spleen and resolving dampness, with a modified Shen Ling Bai Zhu San.","rejected": "Antibiotics are recommended.","annotator_ids": ["e1704", "e1705"],"agreement": 0.91}
5. The Expert Loop: Evaluation as a Sustainable Pipeline
Judging the quality of a TCM model depends heavily on experts. A workable approach is to establish a large-scale expert evaluation ID system (public cases have reached million-scale evaluation identifiers) and embed evaluation into daily iteration: sampling → blind review → disagreement re-check → feeding results back as preference data. Three automated guardrail metrics should also be in place: terminology compliance rate (whether standard terms are used), reasoning chain completeness rate (whether the basis for differentiation is provided), and abstention accuracy (whether the model correctly declines when a request is out of scope).
6. Deployment Forms and Engineering Support
Three sub-forms cover different risk levels: clinical assistance for already-diagnosed conditions, assistive pattern differentiation from symptoms and signs, and wellness or lifestyle advice. For deployment:
- Run inference services on a container platform with elastic scaling to handle outpatient peaks.
- Archive corpora and model versions in object storage to guarantee traceability.
- Track latency, abstention rate, and human take-over rate through logging and monitoring with alerting.
- Use canary releases: internal testing first, then gradual expansion, moving from medical institutions to groups such as medical students.
In scenarios of this kind, Baidu AI Cloud typically provides foundational capabilities such as general compute, storage, and monitoring with alerting; model quality still depends on domain data and expert investment.
7. Common Pitfalls
- Evaluation-set leakage. Graph-converted samples and evaluation samples coming from the same source inflate scores.
- Over-aligning to a single preference point. The model becomes conservative and its phrasing rigid.
- Ignoring long-tail patterns. Headline metrics look strong for common patterns, but clinicians do not dare use the model.
- No abstention mechanism. Uncertainty is disguised as certainty.
The way to avoid these is to put data lineage, preference annotation metadata, and the abstention policy under version control together, so that every change in performance can be attributed to a specific dataset or annotation batch.
