Personalized traditional Chinese medicine inquiry system based on traditional Chinese medicine large model and multiple knowledge bases

Through the combination of traditional Chinese medicine pre-trained embedded model and multi-knowledge base, the dataset construction problems and information retrieval correlation problems of traditional Chinese medicine large models in RLHF training are solved, the accuracy and knowledge coverage of the traditional Chinese medicine consultation system are improved, and individualization is achieved Translated Chinese medicine Q&A logic and information selection.

CN119274754APending Publication Date: 2025-01-07SHANGHAI BAYES HEALTH TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411169662.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-24
Publication Date
2025-01-07

AI Technical Summary

Technical Problem

The existing TCM large models are difficult to build user preference data sets during the RLHF training stage. The TCM text segmentation standards are not determined, information integrity is missing, vector search is not relevant enough, and traditional Chinese medicine knowledge is missing.

Method used

Using traditional Chinese medicine pre-trained embedding model, Text2Cyper module, sorting model, traditional Chinese medicine vector database and traditional Chinese medicine graph database, text segmentation and vector representation are carried out through traditional Chinese medicine pre-trained embedding model, and a personalized vector and graph database is constructed, combining the sorting model and graph database. Carry out information retrieval and logic introduction to improve the accuracy and knowledge coverage of the traditional Chinese medicine consultation system.

Benefits of technology

Reduces the difficulty of building a preferred database for the Chinese medicine big model in RLHF training, improves the adaptation accuracy of the pre-trained embedded model, increases the data source of the Chinese medicine knowledge graph, and realizes the personalized Q&A logic and information for each famous Chinese medicine doctor. Accurate choice.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119274754A_ABST
    Figure CN119274754A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of traditional Chinese medicine, and particularly relates to a personalized traditional Chinese medicine inquiry system based on a traditional Chinese medicine large model and multiple knowledge bases, which comprises the traditional Chinese medicine large model, a traditional Chinese medicine pre-training embedding model, a sorting model, a traditional Chinese medicine vector database and a traditional Chinese medicine graph database, the output end of the traditional Chinese medicine pre-training embedded model is connected with the traditional Chinese medicine vector database, and the output end of the traditional Chinese medicine pre-training embedded model is connected with the traditional Chinese medicine graph database. And the construction difficulty of the preference database of the traditional Chinese medicine large model in RLHF training is reduced. The adaptation of the pre-trained semantic embedding model to the vectorization of the traditional Chinese medicine text is improved, and the accuracy of vector matching is improved. And a traditional Chinese medicine knowledge graph data source is increased. A traditional Chinese medicine large model is trained, and a sorting model is trained and introduced, so that context selection is more accurate. Vector data and a graph database are constructed for each famous traditional Chinese medicine, and personalized question and answer logic for each famous traditional Chinese medicine is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of traditional Chinese medicine, and in particular to a personalized traditional Chinese medicine consultation system based on a large traditional Chinese medicine model and multiple knowledge bases. Background Art

[0002] With the development of natural language processing (NLP) and big model technology, using big models to learn the medical records, prescriptions and other knowledge of famous Chinese medicine doctors, and then simulating famous Chinese medicine doctors to conduct automatic consultations has become a new alternative solution.

[0003] Some disadvantages of existing technologies:

[0004] (1) During the RLHF training stage of the TCM big model, it is difficult to build a user preference dataset because different famous TCM doctors have different diagnosis and prescription logics. At this stage, it is impossible to complete the accuracy training of multiple rounds of question and answering.

[0005] (2) When constructing the vector knowledge base of RAG, the TCM text needs to be segmented into smaller paragraphs or sentences. The criteria for segmentation and the length of the paragraphs are still under study and there is no final conclusion. This stage may cause a loss of information integrity.

[0006] (3) When RAG performs information search, it searches the vector database for the text (TCM text fragment) that is closest to the input text (the patient's question) based on the similarity of the vector. Since the vector is generated based on the pre-trained semantic embedding model, the searched text is closely related to the pre-trained semantic embedding model. The vector similarity alone is not enough to guarantee that the searched TCM text fragment must have a strong correlation with the patient's question. It is possible that the text is irrelevant or even contradictory.

[0007] (4) In RAG, only one type of data source, the vector database of TCM texts, is used, and the logic, rules and other knowledge summarized and refined by TCM are not added in an appropriate way. This will also lead to the loss of TCM knowledge. Summary of the invention

[0008] The purpose of the present invention is to provide a personalized TCM consultation system based on a TCM big model and multiple knowledge bases to solve the problems raised in the above background technology.

[0009] To achieve the above object, the present invention provides the following technical solution: a personalized TCM consultation system based on a TCM big model and multiple knowledge bases, comprising:

[0010] TCM big model, TCM pre-trained embedding model, Text2Cyper module, sorting model, TCM vector database, TCM graph database;

[0011] The output end of the TCM pre-trained embedding model is connected to the TCM vector database, and the output end of the Text2Cyper module is connected to the TCM graph database;

[0012] The output ends of the sorting model, TCM vector database, and TCM graph data are output to a TCM big model (TCM-LLM big model), and an answer statement is output based on the TCM big model.

[0013] Preferably, the TCM pre-trained embedding model uses BERT as the base model of the embedding model;

[0014] The BERT model consists of two parts: Embeddings and Encoder. The Encoder of the BERT model is composed of multiple identical Transformer Encoders stacked together;

[0015] Use TCM data to continue pre-training on the basic parameters of the general BERT model. TCM data includes TCM textbooks, TCM medical records, and TCM medical records.

[0016] Continue pre-training consists of two self-supervised learning tasks:

[0017] Masked Language Model: In this task, some words in the TCM text are randomly masked, and the model's task is to predict these masked words, which enables the TCM pre-trained embedding model to learn bidirectional contextual information;

[0018] Next Sentence Prediction: In this task, the TCM pre-trained embedding model receives two sentences in the TCM text as input, where sometimes the two sentences are two related sentences from the same document, and sometimes they are randomly paired. The TCM pre-trained embedding model needs to predict whether the second sentence is the next sentence of the first sentence, which enables the TCM pre-trained embedding model to learn the relationship between sentences;

[0019] The input format of the TCM pre-trained embedding model is: a token CLS is added at the beginning of the input text to indicate the start of a sentence, and a token SEP is added between sentences to distinguish different sentences;

[0020] Input a sentence into the TCM pre-trained embedding model, and use the input vector labeled CLS to represent the vector representation of the entire sentence.

[0021] Preferably, the sorting model is based on a reward model of a TCM pre-trained embedding model, and multiple texts can be sorted according to the size of the reward value;

[0022] Based on the already trained TCM pre-trained embedding model, add another linear layer to the CLS output, and the scalar output is the reward;

[0023] The training set is a preference data set: for a TCM sentence and its K related contexts, the K contexts are sorted according to their relevance to the TCM sentence;

[0024] The input of the reward model is , and the output is a scalar value representing the reward. For each TCM sentence, the K contexts associated with it are combined to produce Preference comparison data pairs;

[0025] The reward model loss function is calculated as follows:

[0026]

[0027] Among them, r θ (x, y) is the reward value of the reward model when the TCM sentence and the context sentence are input, y w is the preferred context sentence in the preference pair, y l is the unpreferred context sentence in the preference pair, and σ is the sigmoid function.

[0028] Preferably, the TCM vector database: each famous TCM doctor has a separate vector data sub-database, and the construction process is as follows:

[0029] 1) Segment the TCM text into smaller paragraphs or sentences;

[0030] 2) Each segmented text block is converted into a vector representation through a TCM pre-trained embedding model;

[0031] 3) The generated vectors are then stored in a vector database, which is specially designed for efficient storage and retrieval of high-dimensional vectors;

[0032] Preferably, the TCM graph database: each famous TCM doctor has a separate TCM graph database sub-library for knowledge graph expression, and the construction process is as follows:

[0033] 1) Segment the TCM text into smaller paragraphs or sentences;

[0034] 2) Use the TCM big model to extract entities and relations from the segmented text to obtain triples;

[0035] 3) Store TCM triples in a graph database, which is specifically used for efficient retrieval and query of structured data.

[0036] Preferably, the specific steps of the consultation of the personalized TCM consultation system based on the TCM big model and multiple knowledge bases are as follows:

[0037] 1) Use the TCM pre-trained embedding model to convert the patient’s question into a vector;

[0038] 2) Input the question vector into the TCM vector database, retrieve multiple context text vectors with the highest vector similarity, and then return the original texts corresponding to these vectors;

[0039] 3) Use the Text2Cyper module to extract relevant TCM entities and relationships from the question and convert them into Cyp query statements for the graph database;

[0040] 4) Use Cyper query statements to query the TCM graph database and obtain multiple triples related to the question;

[0041] 5) Merge the triplets into text fragments using the Triple2Text module;

[0042] 6) Using the sorting model, the multiple texts returned in step 2) and the multiple texts returned in step 5) are further sorted, and the top-K number of texts are returned;

[0043] 7) Input the patient’s question, top-K context, and previous rounds of conversation history data into the TCM-LLM model and output the answer sentence;

[0044] Continue to the next round of questions and answers.

[0045] Preferably, the TCM big model continues pre-training, SFT training and RLHF training on the basic parameters of the general big model:

[0046] In the pre-training stage, the training data sets of TCM include TCM textbooks, TCM research literature, TCM medical records, and TCM medical history. The training method adopts autoregressive training and full parameter fine-tuning training;

[0047] In the SFT training phase, the training TCM datasets include: manually constructed TCM multi-round dialogue datasets, manually constructed TCM text-to-Cypher sentence datasets, manually constructed TCM knowledge graph triple-to-text datasets, and manually constructed TCM text-to-knowledge graph triple-to-text datasets. The training method of Lora fine-tuning is adopted.

[0048] In the RLHF training phase, the training data set is an artificially constructed TCM preference data set. The purpose of constructing this data set is security, and it does not include the personalized preferences of each famous TCM doctor. The PPO training method is used.

[0049] Compared with the prior art, the present invention has the following beneficial effects:

[0050] The difficulty of building a preference database for the TCM big model in RLHF training has been reduced. The pre-trained semantic embedding model has been improved to adapt to the vectorization of TCM texts, and the accuracy of vector matching has been improved. The TCM knowledge graph data source has been added. The TCM big model has been trained, and the sorting model has been introduced to make the context selection more accurate. A vector data and graph database have been built for each famous TCM doctor, and personalized question-and-answer logic has been implemented for each famous TCM doctor. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1 A system flow chart for a round of dialogue in a multi-round dialogue;

[0052] Figure 2 This is a schematic diagram of the structure of the llama3 large model;

[0053] Figure 3 This is a schematic diagram of the structure of TCM-BERT;

[0054] Figure 4 Schematic diagram of the TCM-BERT-REWARD reward model structure. DETAILED DESCRIPTION

[0055] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0056] In the description of the present invention, it is necessary to understand that the terms "upper", "lower", "front", "back", "left", "right", "top", "bottom", "inside", "outside", etc., indicating the orientation or position relationship are based on the orientation or position relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention.

[0057] Embodiment 1:

[0058] See also Figure 1-4 , the present invention provides a technical solution:

[0059] System overall architecture and process:

[0060] The process of this system completing one round of dialogue in multiple rounds of dialogue is as follows Figure 1 shown.

[0061] The specific steps are as follows:

[0062] 1) Use the TCM pre-trained embedding model (TCM-BERT) to convert the patient’s question into a vector;

[0063] 2) Input the question vector into the TCM vector database, retrieve multiple context text vectors with the highest vector similarity, and then return the original texts corresponding to these vectors;

[0064] 3) Use the Text2Cyper module (based on TCM-LLM) to extract relevant TCM entities (diseases, symptoms, etc.) and relationships (is-a, attributes, etc.) from the question and convert them into Cyper query statements for the graph database;

[0065] 4) Use the Cyp query statement to query the TCM graph database (knowledge graph) and obtain multiple triples related to the question (TCM entity 1, relationship, TCM entity 2);

[0066] 5) Merge triples into text fragments using the Triple2Text module (based on TCM-LLM);

[0067] 6) Using the sorting model, the multiple texts returned in step 2) and the multiple texts returned in step 5) are further sorted, and the top-K number of texts are returned;

[0068] 7) Input the patient’s question, top-K context, and previous rounds of conversation history data into the TCM-LLM large model and output the answer sentence.

[0069] Continue to the next round of questions and answers.

[0070] The specific structure and training process of each module are described below.

[0071] Traditional Chinese Medicine Large Model (TCM-LLM)

[0072] Here we use the same structure as llama3 ( Figure 2 )Similar general large models.

[0073] Continue pre-training, SFT training and RLHF training on the basic parameters of the general large model.

[0074] In the pre-training stage, the training data sets of TCM include TCM textbooks, TCM research literature, TCM medical records, TCM medical history, etc. The training method of autoregression and full parameter fine-tuning is adopted.

[0075] In the SFT training phase, the training TCM datasets include: manually constructed TCM multi-round dialogue datasets, manually constructed TCM text-to-Cypher sentence datasets, manually constructed TCM knowledge graph triple-to-text datasets, and manually constructed TCM text-to-knowledge graph triple-to-text datasets. The training method of Lora fine-tuning is adopted.

[0076] In the RLHF training phase, the training data set is an artificially constructed TCM preference data set. The purpose of constructing this data set is security, and it does not include the personalized preferences of each famous TCM doctor. The PPO training method is used.

[0077] In this way, the TCM-LLM model has the ability of multi-round dialogue in TCM (output answer sentences), the ability to convert TCM text into Cypher (Text2Cyper module), the ability to convert knowledge graph triples into text (Triple2Text module), and the ability to automatically extract triples from TCM text, while retaining the capabilities of the LLM base model.

[0078] Traditional Chinese Medicine Pre-trained Embedding Model (TCM-BERT)

[0079] BERT (Bidirectional Encoder Representations from Transformers) is used as the base model of the embedding model. The basic structure of BERT is as follows Figure 3 shown.

[0080] The BERT model mainly consists of two parts: Embeddings and Encoder. The BERT Encoder is composed of multiple identical Transformer Encoders stacked together.

[0081] Use TCM data to continue pre-training on the basic parameters of the general BERT model. TCM data includes TCM textbooks, TCM medical records, TCM medical records, etc.

[0082] Continue pre-training consists of two self-supervised learning tasks:

[0083] Masked Language Model (MLM): In this task, some words in the TCM text are randomly masked (marked with [MASK]), and the model's task is to predict these masked words. This enables TCM-BERT to learn bidirectional contextual information.

[0084] Next Sentence Prediction (NSP): In this task, the model receives two sentences from TCM text as input, where sometimes the two sentences are from the same document and are related (positive examples, labeled 0), and sometimes they are randomly paired (negative examples, labeled 1). The model needs to predict whether the second sentence is the next sentence of the first sentence. This allows TCM-BERT to learn the relationship between sentences.

[0085] The input format of TCM-BERT is: a special token [CLS] is added at the beginning of the input text to indicate the start of a sentence, and a special token [SEP] is added between sentences to distinguish different sentences.

[0086] Input a sentence to TCM-BERT, and the input vector with a special token [CLS] represents the vector representation of the entire sentence.

[0087] Sorting Model

[0088] The sorting model is actually a TCM-BERT-REWARD-based reward model, which can sort multiple texts according to the reward value. Its structure is as follows: Figure 4 .

[0089] Based on the trained TCM-BERT, a linear layer is added to the [CLS] output, and the output scalar is the reward.

[0090] The training set is a preference data set: for a TCM sentence and its K related contexts, the K contexts are ranked according to their relevance to the TCM sentence.

[0091] The input of the reward model is (TCM sentence, context sentence), and the output is a scalar value representing the reward. For each TCM sentence, the K contexts associated with it are combined to produce Preference comparison data pairs.

[0092] The reward model loss function is calculated as follows:

[0093]

[0094] Among them, r θ (x, y) is the reward value of the reward model when the TCM sentence and the context sentence are input, y w is the preferred context sentence in the preference pair, y l is the unpreferred context sentence in the preference pair, and σ is the sigmoid function.

[0095] Traditional Chinese Medicine Vector Database

[0096] Each famous Chinese medicine practitioner has a separate vector data sub-library. The construction process is as follows:

[0097] (1) Divide TCM texts (general TCM textbooks, medical records of famous TCM doctors themselves, medical records of patients treated by famous TCM doctors, etc.) into smaller paragraphs or sentences.

[0098] (2) Each segmented text block is converted into a vector representation through the TCM pre-trained embedding model (TCM-BERT).

[0099] (3) The generated vectors are then stored in a vector database (Faiss, Milvus, etc.). Vector databases are specifically designed for efficient storage and retrieval of high-dimensional vectors.

[0100] Traditional Chinese Medicine Graph Database

[0101] Each famous Chinese medicine practitioner has a separate Chinese medicine graph database sub-database for knowledge graph expression. The construction process is as follows:

[0102] (1) Divide TCM texts (general TCM textbooks, medical records of famous TCM doctors themselves, medical records of patients treated by famous TCM doctors, etc.) into smaller paragraphs or sentences.

[0103] (2) Use the TCM-LLM model to extract entities and relations from the segmented text and obtain triples

[0104] (3) Store TCM triples in a graph database (such as NebulaGraph). Graph databases are specifically designed for efficient retrieval and query of structured data.

[0105] The above shows and describes the basic principles and main features of the present invention and the advantages of the present invention. For those skilled in the art, it is obvious that the present invention is not limited to the details of the above exemplary embodiments, and the present invention can be implemented in other specific forms without departing from the spirit or basic features of the present invention; therefore, no matter from which point of view, the embodiments should be regarded as exemplary and non-restrictive. The scope of the present invention is limited by the attached claims rather than the above description. Therefore, it is intended to include all changes within the meaning and scope of the equivalent elements of the claims in the present invention, and any figure marks in the claims should not be regarded as limiting the claims involved.

[0106] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A personalized TCM consultation system based on a TCM big model and multiple knowledge bases, characterized by: include: TCM big model, TCM pre-trained embedding model, Text2Cyper module, sorting model, TCM vector database, TCM graph database; The output end of the TCM pre-trained embedding model is connected to the TCM vector database, and the output end of the Text2Cyper module is connected to the TCM graph database; The output ends of the sorting model, TCM vector database, and TCM graph data are output to the TCM big model, and an answer statement is output based on the TCM big model.

2. According to claim 1, a personalized TCM consultation system based on a TCM big model and multiple knowledge bases is characterized by: The TCM pre-trained embedding model uses BERT as the base model of the embedding model; The BERT model consists of two parts: Embeddings and Encoder. The Encoder of the BERT model is composed of multiple identical Transformer Encoders stacked together; Use TCM data to continue pre-training on the basic parameters of the general BERT model. TCM data includes TCM textbooks, TCM medical records, and TCM medical records. Continue pre-training consists of two self-supervised learning tasks: Masked Language Model: In this task, some words in the TCM text are randomly masked, and the model's task is to predict these masked words, which enables the TCM pre-trained embedding model to learn bidirectional contextual information; Next Sentence Prediction: In this task, the TCM pre-trained embedding model receives two sentences in the TCM text as input, where sometimes the two sentences are two related sentences from the same document, and sometimes they are randomly paired. The TCM pre-trained embedding model needs to predict whether the second sentence is the next sentence of the first sentence, which enables the TCM pre-trained embedding model to learn the relationship between sentences; The input format of the TCM pre-trained embedding model is: a token CLS is added at the beginning of the input text to indicate the start of a sentence, and a token SEP is added between sentences to distinguish different sentences; Input a sentence into the TCM pre-trained embedding model, and use the input vector labeled CLS to represent the vector representation of the entire sentence.

3. According to claim 1, a personalized TCM consultation system based on a TCM big model and multiple knowledge bases is characterized by: The sorting model is based on a reward model of a TCM pre-trained embedding model, and multiple texts can be sorted according to the size of the reward value; Based on the already trained TCM pre-trained embedding model, add another linear layer to the CLS output, and the scalar output is the reward; The training set is a preference data set: for a TCM sentence and its K related contexts, the K contexts are sorted according to their relevance to the TCM sentence; The input of the reward model is , and the output is a scalar value representing the reward. For each TCM sentence, the K contexts associated with it are combined to produce Preference comparison data pairs; The reward model loss function is calculated as follows: Among them, r θ (x, y) is the reward value of the reward model when the TCM sentence and the context sentence are input, y w is the preferred context sentence in the preference pair, y l is the unpreferred context sentence in the preference pair, and σ is the sigmoid function.

4. According to claim 1, a personalized TCM consultation system based on a TCM big model and multiple knowledge bases is characterized by: The TCM vector database: Each famous TCM doctor has a separate vector data sub-database, and the construction process is as follows: 1) Segment the TCM text into smaller paragraphs or sentences; 2) Each segmented text block is converted into a vector representation through a TCM pre-trained embedding model; 3) The generated vectors are then stored in a vector database, which is specially designed for efficient storage and retrieval of high-dimensional vectors.

5. According to claim 1, a personalized TCM consultation system based on a TCM big model and multiple knowledge bases is characterized by: The TCM graph database: Each famous TCM doctor has a separate TCM graph database sub-database for knowledge graph expression, and its construction process is as follows: 1) Segment the TCM text into smaller paragraphs or sentences; 2) Use the TCM big model to extract entities and relations from the segmented text to obtain triples; 3) Store TCM triples in a graph database, which is specifically used for efficient retrieval and query of structured data.

6. According to claim 1, a personalized TCM consultation system based on a TCM big model and multiple knowledge bases is characterized by: The specific steps of the personalized TCM consultation system based on the TCM big model and multiple knowledge bases are as follows: 1) Use the TCM pre-trained embedding model to convert the patient’s question into a vector; 2) Input the question vector into the TCM vector database, retrieve multiple context text vectors with the highest vector similarity, and then return the original texts corresponding to these vectors; 3) Use the Text2Cyper module to extract relevant TCM entities and relationships from the question and convert them into Cyp query statements for the graph database; 4) Use Cyper query statements to query the TCM graph database and obtain multiple triples related to the question; 5) Merge the triplets into text fragments using the Triple2Text module; 6) Using the sorting model, the multiple texts returned in step 2) and the multiple texts returned in step 5) are further sorted, and the top-K number of texts are returned; 7) Input the patient’s question, top-K context, and previous rounds of conversation history data into the TCM-LLM model and output the answer sentence; Continue to the next round of questions and answers.

7. According to claim 1, a personalized TCM consultation system based on a TCM big model and multiple knowledge bases is characterized by: The TCM large model continues pre-training, SFT training and RLHF training on the basic parameters of the general large model: In the pre-training stage, the training data sets of TCM include TCM textbooks, TCM research literature, TCM medical records, and TCM medical history. The training method adopts autoregressive training and full parameter fine-tuning training; In the SFT training phase, the training TCM datasets include: manually constructed TCM multi-round dialogue datasets, manually constructed TCM text-to-Cypher sentence datasets, manually constructed TCM knowledge graph triple-to-text datasets, and manually constructed TCM text-to-knowledge graph triple-to-text datasets. The training method of Lora fine-tuning is adopted. During the RLHF training phase, the training dataset is an artificially constructed TCM preference dataset. The dataset is constructed for security and does not include the personalized preferences of each famous TCM doctor. The PPO training method is used.