Pregnancy nutrition mapping knowledge domain construction and application method based on large language model
By constructing a knowledge graph of pregnancy nutrition using a large language model, the problem of converting unstructured pregnancy nutrition data into structured knowledge in existing technologies has been solved, enabling precise recommendations for pregnancy nutrition plans and improving the effectiveness of pregnancy nutrition management.
Patent Information
- Application Number
- CN202511169987.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-20
- Publication Date
- 2025-10-31
AI Technical Summary
Existing technologies cannot directly apply large language models to pregnancy nutrition data, transform unstructured text into structured knowledge graphs, or accurately recommend personalized pregnancy nutrition knowledge.
This study employs a knowledge graph construction method for pregnancy nutrition based on a large language model. By collecting unstructured medical data, target triple entities and relationships are identified. Triples are extracted using the Prompt dialog, and the data is constructed into a visualized knowledge graph. Nutritional plans are then recommended in conjunction with personalized information for pregnant women.
It has enabled the construction of a pregnancy nutrition knowledge graph under zero-sample or low-sample conditions, which improves the accuracy and personalization of nutrition knowledge recommendations and enhances the pertinence and accuracy of pregnancy nutrition management.
Smart Images

Figure CN120873207A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of knowledge graph technology, and in particular relates to a method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model. Background Technology
[0002] Currently, with the increasing awareness of public health, the demand for precision medicine services is growing. During pregnancy, which involves both the mother and fetus, precision medicine is especially crucial for early screening and intervention. It also facilitates pregnancy management, such as nutritional guidance and exercise recommendations, by developing tailored plans based on the pregnant woman's specific situation, providing more targeted monitoring and treatment.
[0003] To develop personalized treatment plans, it is necessary to delve into multi-dimensional data such as patients' medical history, clinical manifestations, and lifestyles. With the development of medical data informatization, a large amount of medical data in various forms, including Electronic Health Records (EHRs), medical literature, and clinical trial reports, is generated during the medical process. However, most of this medical data exists in the form of unstructured text, making it difficult to use directly for computer analysis or decision support. How to extract effective information from this vast ocean of unstructured data and transform it into structured knowledge that can be understood and utilized by machines is an urgent problem.
[0004] Based on current domain knowledge, computers struggle to understand unstructured text information. Therefore, to enable computers to receive and process information, unstructured text needs to be transformed into a structured knowledge graph (KG). This process primarily involves two basic Natural Language Processing (NLP) tasks: Named Entity Recognition (NER) and Relation Extraction (RE).
[0005] Against this backdrop, deep learning-based pre-trained language models (such as BERT and GPT1) are widely used in NER and RE tasks due to their powerful context modeling capabilities. These models are pre-trained on large-scale corpora and can achieve good performance in various downstream tasks. However, despite this, existing technologies still have the following drawbacks: due to the small number of model parameters, in practical applications, it is usually necessary to rely on the training data of specific tasks to update the parameters in the model. This limits the application of models such as BERT and GPT1 in low-sample or even zero-sample scenarios, especially in pregnancy medical data where labeled data is scarce.
[0006] Large Language Models (LLMs), which have matured in recent years, have demonstrated powerful application capabilities in zero-shot or few-shot tasks due to their large number of parameters, compensating for the shortcomings of pre-trained models. However, they cannot be directly applied to NLP processing tasks because the task structures of the two are incompatible. NER belongs to sequence labeling tasks, while RE belongs to classification tasks. These differ significantly in input-output structure from generative QA (question-answer pair) tasks, which LLM excels at, making direct transfer and application difficult.
[0007] In view of the shortcomings of existing technologies, this invention proposes a method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model. The aim is to use the Prompt dialogue with the large language model to extract triples from unstructured medical information and transform the data into a visualized knowledge graph. Based on this knowledge graph, machine understanding can be performed to help with pregnancy nutrition management. Summary of the Invention
[0008] The purpose of this invention is to provide a method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model, in order to solve the problems mentioned in the background art, such as the inability of large language models to be directly applied to pregnancy nutrition data, the inability to transform unstructured text into a structured knowledge graph, and the inability to accurately recommend personalized pregnancy nutrition knowledge.
[0009] To achieve the above objectives, the present invention employs the following technical solution:
[0010] In its first aspect, this invention proposes a method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model, comprising the following steps:
[0011] S1. Collect unstructured medical data to obtain identifiable knowledge text;
[0012] S2. Determine the target triplet entity and the relationships between entities within the triplet;
[0013] S3. Filter identifiable knowledge texts through a large language model to obtain a set of triplet instances that match the target triplet type;
[0014] S4. Construct a knowledge graph of pregnancy nutrition based on the set of triplet instances;
[0015] S5. Construct a personalized knowledge graph for pregnant women based on their individual information;
[0016] S6. Based on the pregnancy nutrition knowledge map, recommend a personalized pregnancy nutrition plan for pregnant women.
[0017] Furthermore, S2 is specifically as follows:
[0018] Key information is selected from identifiable knowledge text, and semantic expansion is performed on the key information and the relationships between them. All key information is then classified and summarized using a large language model to obtain target triples, specifically including the following six main triples:
[0019] <Nutritional entity, suitable for, pregnancy entity>;
[0020] <Food entity, suitable for, pregnancy entity>;
[0021] <Food entities that are harmful to pregnant women>;
[0022] <Nutrient entities, prevention, disease entities>;
[0023] <Food entity, trigger, disease entity>;
[0024] <Food entities, including nutrient entities>.
[0025] Furthermore, S3 is specifically as follows:
[0026] Multiple large language models can be selected to obtain triple instances that match the target triple from identifiable knowledge text, resulting in a set of triple instances that match the target triple type.
[0027] Multiple different Prompt statements can be designed for large language models. These Prompt statements apply commands to the large language models, filtering recognizable text within them to obtain a set of triple instances that match the target triple type. Each Prompt statement includes the target triple knowledge pair type and a connecting statement. One template is shown below:
[0028] "Please extract triple instances from the following text: <entity1a, relation1, entity1b>, <entity2a, relation2, entity2b>... <entityna, relationn, entitynb>. Output the triple instances you find, and return "none" if none are found."
[0029] Furthermore, the Precision, Recall, and F1 scores of triplet data obtained through different large language models and corresponding Prompt statements;
[0030] Recall refers to the proportion of samples that were actually positive but were predicted as positive. This metric measures the model's ability to identify all actually positive samples, i.e., the model's comprehensiveness.
[0031] The F1 score is the harmonic mean of precision and recall, used to comprehensively reflect the model's precision and recall; a higher F1 score indicates better model performance.
[0032] We select the most accurate large language model to obtain triple data from identifiable knowledge texts, and improve the Prompt statement based on the most accurate large language model to improve the F1 score.
[0033] Furthermore, S4 is specifically as follows:
[0034] Using Python statements, all the triplet instance sets obtained in step three are stored in neo4j, forming a knowledge graph from the triplet instance sets.
[0035] Furthermore, S5 is specifically as follows:
[0036] We obtain structured or unstructured information about pregnant women from relevant hospital systems. Similarly, we use a large language model to extract unstructured information into triplet information. The corresponding prompt is: "Please extract triplet knowledge pairs from the following text: <Pregnant woman's name entity, suffers from, disease entity>, <Pregnant woman's name entity, is in, pregnancy entity>, <Pregnant woman's name entity, dietary restrictions, food entity>, <Pregnant woman's name entity, needs, nutrient entity>, <Pregnant woman's name entity, recommended intake, food entity>. Output the knowledge pairs you find; if none are found, return 'None'."
[0037] The integrated structured triplet data is stored in neo4j to construct an individual knowledge graph of pregnant women.
[0038] Furthermore, S6 recommends a personalized prenatal nutrition plan for pregnant women, with the following specific steps:
[0039] S61. Identify the types of nutritional knowledge you want to obtain from the individual knowledge graph of pregnant women;
[0040] S62. To find the required information, the knowledge graph of the pregnancy diet guide can be embedded using the TransH (Translation in Hyperplane) algorithm, mapping each entity (node) and relation (edge) in the knowledge graph to a continuous vector space.
[0041] Furthermore, the original structure of the triple in step S62 is (h, r, t); where h is the head entity, r is the relation, and t is the tail entity. The implementation process is as follows:
[0042] S621. Define the hyperplane corresponding to the relation. For each relation r, define its normal vector w. r ∈R d And relation vector r∈R d ;
[0043] S622. Project the entities onto the hyperplane, projecting the head entity h and the tail entity t onto the hyperplane:
[0044]
[0045] Here, h′ and t′ are the projections of the entities onto the hyperplane corresponding to relation r;
[0046] S623. Training objective: Using open-source libraries such as OpenKE or PyTorch-Geometric, train the model using the following function. The objective is to learn the vector representations of all entities and relations such that the correct triples satisfy h′+r=h′.
[0047]
[0048] Where S is the set of correct triples; (h f ,r,t f ) is a negative sample (erroneous triple); γ is the margin; [·]+=max(0,·);
[0049] Then, using Python, we calculate the cosine similarity between each entity and all other entities:
[0050]
[0051] Store the cosine similarity of all entities into the prenatal dietary guidelines already stored in neo4j; finally, use Cypher's apoc.algo.cosineSimilarity to create a graph database query API; in this way, when searching for a target entity, the database will not only output entities related to it, but also entities with close cosine similarity to it.
[0052] In its second aspect, this invention proposes a system for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model, comprising:
[0053] The module for collecting unstructured medical data collects unstructured medical data to obtain identifiable knowledge text.
[0054] The relationship determination module is used to determine the target triple entity and the relationships between entities within the triple;
[0055] The triplet instance set filtering module is used to filter identifiable knowledge text through a large language model to obtain triplet instance sets that match the target triplet type.
[0056] A knowledge graph module was constructed, including a knowledge graph of pregnancy nutrition and an individual knowledge graph of pregnant women.
[0057] The module for personalized prenatal nutrition recommendations for pregnant women is used to recommend personalized prenatal nutrition plans based on a prenatal nutrition knowledge map.
[0058] As can be seen from the above technical solution, the present invention provides a method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model. Compared with the prior art, the present invention has the following advantages:
[0059] 1. This invention aims to utilize a large language model to construct prompts, enabling zero-sample extraction of pregnancy nutrition triple knowledge pairs from unstructured text, and constructing a knowledge graph from the extracted triple knowledge pairs, storing it in the graph database Neo4j, thereby achieving visualization of the knowledge graph and supporting subsequent reasoning and analysis.
[0060] 2. This invention utilizes three metrics for data analysis: Precision, Recall, and F1 score. Precision refers to the proportion of samples predicted as positive that are actually positive. This metric measures the accuracy of the model's predictions. Recall refers to the proportion of samples actually positive that were predicted as positive. This metric measures the model's ability to identify all actual positive samples, i.e., the model's comprehensiveness. The F1 score is the harmonic mean of precision and recall, used to comprehensively reflect the model's precision and recall. A higher F1 score indicates better model performance. By specifically modifying the Prompt statement, the F1 score can be improved. This invention improves the F1 score by adjusting the Prompt language and increasing the knowledge pairs extracted by the Prompt.
[0061] 3. The method in this invention combines the pregnant woman's personalized information, and through knowledge graphs and calculation of the cosine similarity between each entity and all other entities, it achieves accurate and personalized nutritional knowledge recommendations for pregnant women, improves the relevance and accuracy of the recommended knowledge, and can better meet the nutritional knowledge needs of pregnant women at different stages of pregnancy.
[0062] 4. The method in this invention employs a large language model. Compared to the earlier pre-trained models frequently used in existing technologies, the number of parameters used in simulated training by the pre-trained models is far less than that of the large language model. This allows the large language model to learn more complex patterns and perform better on a wider range of tasks, enabling this invention to achieve more accurate and reasonable outputs compared to previous technologies.
[0063] It should be understood that the descriptions in this section are not intended to identify key or essential features of embodiments of the invention, nor are they intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Of course, implementing any product of the invention does not necessarily require achieving all of the advantages described above simultaneously. Attached Figure Description
[0064] The accompanying drawings, which form part of this application, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an undue limitation of the invention. In the drawings:
[0065] Figure 1 This is a flowchart of the method for constructing and applying a pregnancy nutrition knowledge graph based on a large language model in this invention.
[0066] Figure 2 This is a schematic diagram of the triplet knowledge pairs in this invention;
[0067] Figure 3 This is a schematic diagram illustrating the principle of extracting triples from a large language model in this invention.
[0068] Figure 4 This is a schematic diagram of the knowledge graph obtained in this invention. Detailed Implementation
[0069] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Unless otherwise specified, the embodiments and features in the embodiments of this application can be combined with each other. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0070] Example 1:
[0071] like Figure 1 As shown, the method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model includes the following steps:
[0072] Step 1: Collect unstructured medical data to obtain identifiable knowledge text.
[0073] In this embodiment, the pregnancy nutrition data comes from the PDF version of "Dietary Guidelines for Chinese Women". The PDF version of "Dietary Guidelines for Chinese Women" is input into the large language model, and a prompt similar to "convert this file into a TXT text and output it to me" is given to the large language model. The corresponding recognizable target unstructured text is generated. The format of the converted text in the target instruction is not limited to TXT text. Any text format that the computer can recognize is acceptable.
[0074] It can also generate recognizable target unstructured text by applying a Prompt to a large language model from other forms of medical data collected related to women's pregnancy, such as electronic health records, medical literature, and clinical trial reports.
[0075] Step 2: Determine the target triple entity and the relationships between entities within the triple.
[0076] This invention, based on target unstructured text, selects key information, semantically expands the key information and the relationships between them, and classifies and summarizes all key information using a large language model. The summarized key information is used as entities, and the relationships between them are summarized accordingly. An example of entity relationship terminology extraction can be found in [link to example]. Figure 2 This generates multiple sets of primary triples.
[0077] In this embodiment, six main triples are obtained from the target unstructured text, as follows:
[0078] <Nutritional entity, suitable for, pregnancy entity>;
[0079] <Food entities, including nutrient entities>;
[0080] <Food entity, suitable for, pregnancy entity>;
[0081] <Food entities that are harmful to pregnant women>;
[0082] <Nutrient entities, prevention, disease entities>;
[0083] <Food entity, trigger, disease entity>.
[0084] A triple is a basic data unit in knowledge representation (such as knowledge graphs, semantic web, and RDF), used to describe the relationship between two entities (or an entity and an attribute value). Its standard form is: G = {(h,r,t) | h,t ∈ E, r ∈ R}
[0085] Where E is the set of entities (such as disease entities, drug entities), and R is the set of relations (such as "cause" and "contraindicated").
[0086] like Figure 2 As shown, in Example 1, "Milk is the best food source of calcium," where "milk" and "calcium" are the food entity and nutrient entity, respectively, and there is an inclusion relationship between them, hence "inclusion" is the relation. Therefore, the unstructured text can be described as a triple instance: (milk, inclusion, calcium).
[0087] Step 3: Filter the recognizable unstructured knowledge text using a large language model to obtain a set of triplet instances that match the target triplet type.
[0088] This invention combines computer language to formalize requirements into Prompt statements. The following is the Prompt statement generated by this invention:
[0089] "Please extract the following triplet knowledge pairs from the text below: <nutrient entity, suitable for, pregnancy entity>, <food entity, contains, nutrient entity>, <food entity, suitable for, pregnancy entity>, <food entity, harmful to, pregnancy entity>, <nutrient entity, prevent, disease entity>, <food entity, cause, disease entity>. Output the knowledge pairs you find, and return "none" if none are found. For example, if the text is: Protein is beneficial during pregnancy, you should be able to find the triplet <protein, suitable for, pregnancy>. The following is the text you want to detect:"
[0090] In addition, to verify the effectiveness and feasibility of this method, the present invention conducted manual text reading and summarized 172 triplet data, which were then verified using a large language model.
[0091] The steps for obtaining the internal workings of triples from a large language model are as follows: Figure 3 As shown. Entity recognition is performed directly based on named entity recognition and semi-pointer / semi-labeling or BIO architecture for entity identification in triples. Relationship classification is performed using pipelined methods and joint learning methods.
[0092] This invention improves the accuracy of target triple extraction by adjusting the Prompt statement of the large language model when extracting target triples. The Prompt statement further requests other textual knowledge to output knowledge pairs with similar relationships to the triples.
[0093] Step 4: Construct a knowledge graph of pregnancy nutrition based on the target triplet.
[0094] Using Python statements, all the triplet instance sets obtained in step three are stored in Neo4j. These triplet instance sets form a knowledge graph. The result of running the graph shows the triplet instance sets displayed in Neo4j as follows. Figure 4 As shown.
[0095] exist Figure 4 As can be seen, the "Dietary Guidelines for Chinese Women," under the premise of extracting the target tripartite as: <nutrient entity, suitable for, pregnancy entity>, <food entity, contains, nutrient entity>, <food entity, suitable for, pregnancy entity>, <food entity, harmful to, pregnancy entity>, <nutrient entity, prevent, disease entity>, <food entity, cause, disease entity>, it can extract 114 nodes and 172 relations (one node can be connected by multiple relations). Among them, the node part includes 59 food nodes, 37 disease nodes, 5 pregnancy nodes, and 13 nutrient nodes. The relation part includes 9 "suitable" relations, 56 "contains" relations, 40 "suitable" relations, 2 "harmful to", 49 "prevent" relations, and 15 "cause" relations.
[0096] Step 5: Integrate the pregnant woman's personalized information to construct an individual knowledge graph for the pregnant woman.
[0097] Obtain structured or unstructured information about pregnant women from relevant hospital systems. Similarly, use a large language model to extract unstructured information into triples. The corresponding prompt is: "Please extract triple knowledge pairs from the following text: <Pregnant woman's name entity, suffers from, disease entity>, <Pregnant woman's name entity, in, pregnancy entity>, <Pregnant woman's name entity, dietary restrictions, food entity>, <Pregnant woman's name entity, needs, nutrient entity>, <Pregnant woman's name entity, recommended intake, food entity>. Output the knowledge pairs you find; if none are found, return "None". For example, if the text is: "Zhang San is deficient in vitamins and should consume more of the corresponding foods, such as apples and oranges," then you should be able to find the triple <Zhang San, needs, vitamins>, <Zhang San, recommended intake, apples>, <Zhang San, recommended intake, oranges>. If you find triples similar to the target triples, please convert them to the required format. The following is the text you want to detect:", successfully obtaining triple data pairs. Integrate these with structured information (such as the pregnant woman's name, age, height, and weight).
[0098] Following the process in step four, the integrated structured triplet data will be stored in neo4j to construct an individual knowledge graph for pregnant women.
[0099] Step Six: Based on the pregnancy nutrition knowledge map, recommend a personalized pregnancy nutrition plan for the pregnant woman;
[0100] First, the desired type of nutritional knowledge is identified from the individual knowledge graph of the pregnant woman. For example, if the knowledge graph contains "<Zhang San, needs, carbohydrates>", then the desired nutritional knowledge type is carbohydrates. Next, a search is performed. This invention provides two search methods: First, directly use Cypher to search for the target node (e.g., carbohydrates) in the pregnancy dietary guidelines knowledge graph to obtain information related to the target node. Second, use the TransH (Translation in Hyperplane) algorithm to embed entities into the pregnancy dietary guidelines knowledge graph, mapping each entity (node) and relation (edge) in the knowledge graph to a continuous vector space. The process is as follows:
[0101] The original structure of a triple is: (h, r, t); where h is the head entity, r is the relation, and t is the tail entity. The first step is to define the hyperplane corresponding to each relation. For each relation r, define its normal vector w. r ∈R d And relation vector r∈R d The second step is to project the entities onto the hyperplane, specifically the head entity h and the tail entity t:
[0102]
[0103] Here, h′ and t′ are the projections of the entity onto the hyperplane corresponding to relation r.
[0104] The third step is to train the model using open-source libraries such as OpenKE or PyTorch-Geometric through the following function. The goal is to learn the vector representations of all entities and relations so that the correct triples satisfy h′+r=h′.
[0105]
[0106] Where: S is the set of correct triples; (h f ,r,t f ) represents a negative sample (erroneous triple); γ is the margin; [·]+=max(0,·)
[0107] After training, you will obtain a vector representation of each entity, for example:
[0108] entity Vector (example) spinach [0.12,-0.34,0.78...] iron [0.15,-0.36,0.79...] Gestational diabetes [-0.45,0.23,0.81...]
[0109] Next, the cosine similarity between each entity and all other entities is calculated using Python:
[0110]
[0111] The cosine similarity of all entities is stored in the pre-existing pregnancy dietary guidelines in neo4j. Finally, a graph database query API is created using Cypher's apoc.algo.cosineSimilarity. This way, when searching for a target node, the database will output not only related nodes but also nodes with similar cosine similarity.
[0112] For example: Suppose your knowledge graph contains <spinach, contains, iron>, <animal liver, contains, iron>, <folic acid, suitable for, second trimester>, <iron, suitable for, second trimester>. After TransH embedding: when you input spinach, the system will return animal liver (because both contain iron); input second trimester, it will return folic acid, iron, spinach, animal liver, etc. The returned data is the recommended personalized pregnancy nutrition plan for pregnant women.
[0113] Experiments have shown that F1 scores can be improved.
[0114] This invention validates the use of large language models to extract entities and entity relationships to construct knowledge graphs.
[0115] To ensure the generalizability of the experiment and to leverage the characteristics of large language models, five commonly used large language models were selected for questioning: ChatGLM4, QWEN, V4.0 Turbo, ERNIE Bot, and Kimi. The obtained triplet dataset was organized and analyzed. This invention utilizes Precision, Recall, and F1 scores for data analysis.
[0116] Precision refers to the proportion of truly positive samples out of all samples predicted as positive. This metric measures the proportion of truly positive samples among the model's predicted positive examples, i.e., the accuracy of the model's prediction. The formula for calculating precision is: Where TP represents a true positive and FP represents a false positive.
[0117] Recall refers to the proportion of samples that were predicted to be positive out of all actual positive samples. This metric measures the model's ability to identify all actual positive samples, i.e., the model's comprehensiveness. The formula for calculating recall is... Where TP represents a true example and FN represents a false counterexample.
[0118] The F1 score is the harmonic mean of precision and recall, used to comprehensively reflect the model's precision and recall. The calculation formula is: The higher this value, the better the model's performance.
[0119] When processing the data, manually extracted triples are considered actual triples, and triples extracted by the large language model are considered predicted triples. Triples that overlap are considered positive examples. Taking the Wenxin Yiyan 3.5 (ERNIE Bot) model as an example: manually extracted triples are considered actual, those extracted by the Wenxin model are considered predicted, and overlaps are considered positive examples. Therefore, there are 172 actual triples, of which 115 overlap with the Wenxin model and 57 do not. There are 128 predicted triples, of which 115 overlap with the manually extracted triples and 13 do not.
[0120] That is, the number of true positives is 115 (115 correct triples are output); the number of false positives is 13 (13 triples that are not true are output); and the number of false negatives is 58 (58 true triples that are not output).
[0121] So:
[0122]
[0123] Following the above processing flow, the present invention processed the data of the five major language models respectively, and the results are shown in Table 1 below.
[0124] Table 1: Calculation Results of Indicators for Large Language Model Data Processing
[0125]
[0126] As shown in the table above, QWEN is the model with the best output performance. Its application effect is the best, with an F1 score as high as 0.85.
[0127] The F1 scores obtained by interacting with a fixed Prompt statement in this invention are shown in Table 1. This invention investigates further improvements to the F1 score. Specifically, based on triples that were not correctly output by the large language model, the Prompt statement is modified in a targeted manner to improve the F1 score. This invention improves the F1 score by adjusting the Prompt language and increasing the knowledge pair extraction range of the Prompt.
[0128] This invention utilizes the QWEN model to attempt to modify the prompt for the 22 triples that it did not output correctly:
[0129] During the experiment, it was found that LLM was not sensitive to words like "e.g." and "for example" when detecting triples. To address this issue, the Prompt was modified as follows: "Please extract triple knowledge pairs from the following text: <food entity, suitable, pregnancy>. Output the knowledge pairs you find; otherwise, return 'none'. For example, if the text is: Animal foods are beneficial during pregnancy, such as fish and poultry; then you should be able to find the triples <fish, suitable, pregnancy> and <poultry, suitable, pregnancy>. The following is the text you want to detect:." The results showed that some previously unoutput triples were successfully output.
[0130] Furthermore, during the experiment, some subtle triplet relationships were discovered. Although the large language model recognized their existence, it doubted the correctness of the triplet due to its lack of explicitness and therefore did not output it. Therefore, the following was added to the original Prompt statement: "When you encounter a knowledge pair that you cannot definitively determine, please contact other textual knowledge in the network for a definitive judgment. And if you find a triplet relationship similar to the target, please convert it to the required format yourself."
[0131] In summary, the advanced Prompt version can be modified as follows: "Please extract triplet knowledge pairs from the following text: <food entity, suitable, pregnancy>. Output the knowledge pairs you find; if none are found, return 'None'. For example, if the text is: 'Animal foods are beneficial during pregnancy, such as fish and poultry,' then you should be able to find the triplets <fish, suitable, pregnancy> and <poultry, suitable, pregnancy>. Furthermore, when you encounter knowledge pairs that you cannot definitively identify, please contact other text knowledge sources online for a more accurate assessment. If you find triplets with similar relationships to the target triplets, please convert them to the required format. The following is the text you want to detect:'." After extracting the triplet type <food entity, suitable, pregnancy>, then replace the remaining triplets one by one to achieve the desired result.
[0132] Based on the above findings, and by re-enacting the interactive output with the same text content, after several attempts, it was found that Tongyi's F1 score increased from 0.85 to 0.91. This proves that modifying the Prompt statement can further improve the F1 score.
[0133] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
[0134] Furthermore, it should be noted that if any directional indication (such as up, down, left, right, front, back, etc.) is involved in the embodiments of the present invention, the directional indication is only used to explain the relative positional relationship and movement of each component in a specific posture. If the specific posture changes, the directional indication will also change accordingly.
[0135] Furthermore, if the embodiments of this invention involve descriptions such as "first" or "second," these descriptions are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first" or "second" may explicitly or implicitly include at least one of those features. Additionally, the meaning of "and / or" throughout the text includes three parallel solutions; for example, "A and / or B" includes solution A, solution B, or a solution where both A and B are satisfied simultaneously. Furthermore, in the embodiments of this invention, "multiple" refers to two or more. Moreover, the technical solutions of the various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed by this invention.
Claims
1. A method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model, characterized in that, Includes the following steps: S1. Collect unstructured medical data to obtain identifiable knowledge text; S2. Determine the target triplet entity and the relationships between entities within the triplet; S3. Filter identifiable knowledge texts through a large language model to obtain a set of triplet instances that match the target triplet type; S4. Construct a knowledge graph of pregnancy nutrition based on the set of triplet instances; S5. Construct a personalized knowledge graph for pregnant women based on their individual information; S6. Based on the pregnancy nutrition knowledge map, recommend a personalized pregnancy nutrition plan for pregnant women.
2. The method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model according to claim 1, characterized in that, S2 is specifically as follows: Key information is selected from identifiable knowledge text, and semantic expansion is performed on the key information and the relationships between them. All key information is then classified and summarized using a large language model to obtain target triples, specifically including the following six sets of triples: <Nutritional entity, suitable for, pregnancy entity>; <Food entity, suitable for, pregnancy entity>; <Food entities that are harmful to pregnant women>; <Nutrient entities, prevention, disease entities>; <Food entity, trigger, disease entity>; <Food entities, including nutrient entities>.
3. The method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model according to claim 1, characterized in that, S3 is specifically as follows: Multiple large language models are selected to obtain triple instances that match the target triple in identifiable knowledge text, resulting in a set of triple instances that match the target triple type. Design multiple different Prompt statements for large language models. The Prompt statements apply commands to the large language models to filter the recognizable text in the large language models to a set of triple instances that match the target triple type. The Prompt statements include the target triple knowledge pair type and the connection statement.
4. The method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model according to claim 3, characterized in that, The template for the Prompt statement is shown below: Please extract triple instances from the following text: <entity 1a, relation 1, entity 1b>, <entity 2a, relation 2, entity 2b>... <entity na, relation n, entity nb>. Output the triple instances you find, and return "none" if none are found.
5. The method for constructing and applying a pregnancy nutrition knowledge graph based on a large language model according to claim 3, characterized in that, Calculate the precision, recall, and F1 score of triplet data obtained from different large language models and corresponding Prompt statements; The F1 score is the harmonic mean of precision and recall, used to comprehensively reflect the model's precision and recall; the higher the F1 score, the better the model's performance. We select the most accurate large language model to obtain triple data from identifiable knowledge texts, and improve the Prompt statement based on the most accurate large language model to improve the F1 score.
6. The method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model according to claim 1, characterized in that, S4 is specifically as follows: Using Python statements, all triple instance sets obtained from S3 are stored in neo4j, forming a knowledge graph from the triple instance sets.
7. The method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model according to claim 1, characterized in that, S5 is specifically as follows: Obtain structured or unstructured information about pregnant women from relevant hospital systems. Use a large language model to extract unstructured information into triplet information. The corresponding prompt is: "Please extract triplet knowledge pairs from the following text: <Pregnant woman's name entity, suffers from, disease entity>, <Pregnant woman's name entity, is in, pregnancy entity>, <Pregnant woman's name entity, dietary restrictions, food entity>, <Pregnant woman's name entity, needs, nutrient entity>, <Pregnant woman's name entity, recommended intake, food entity>. Output the knowledge pairs you find. If you find none, return "None". The integrated structured triplet data is stored in neo4j to construct an individual knowledge graph of pregnant women.
8. The method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model according to claim 1, characterized in that, The S6 section recommends a personalized prenatal nutrition plan for pregnant women, with the following specific steps: S61. Identify the types of nutritional knowledge you want to obtain from the individual knowledge graph of pregnant women; S62. Find the required information and use the TransH algorithm to embed entities into the pregnancy nutrition knowledge graph of the pregnancy diet guide, mapping each entity and relation in the knowledge graph to a continuous vector space.
9. The method for constructing and applying a knowledge graph of pregnancy nutrition based on a large language model according to claim 8, characterized in that, S62 is specifically as follows: S621. Original structure of a triple: (h, r, t); where h is the head entity, r is the relation, and t is the tail entity; define the hyperplane corresponding to each relation, and for each relation r, define its normal vector w. r ∈R d And relation vector r∈R d ; S622. Project the entities onto the hyperplane, projecting the head entity h and the tail entity t onto the hyperplane: Where h′,t′ are the projections of the entity onto the hyperplane corresponding to relation r; S623. Training objective: Use the open-source library OpenKE or PyTorch-Geometric to train the model using the following function. The objective is to learn the vector representations of all entities and relations such that the correct triples satisfy h′+r=h′. Where S is the set of correct triples; (h f ,r,t f ) is an incorrect triple; γ is the margin; [·]+=max(0,·); Then, using Python, we calculate the cosine similarity between each entity and all other entities: Store the cosine similarity of all entities into the existing pregnancy nutrition knowledge graph in neo4j; finally, use Cypher's apoc.algo.cosineSimilarity to create a graph database query API; when searching for a target entity, the database will not only output entities related to it, but also entities with close cosine similarity to it.
10. A prenatal nutrition knowledge graph construction system based on a large language model, applied to the method described in any one of claims 1-9, characterized in that, include: The module for collecting unstructured medical data collects unstructured medical data to obtain identifiable knowledge text. The relationship determination module is used to determine the target triple entity and the relationships between entities within the triple; The triplet instance set filtering module is used to filter identifiable knowledge text through a large language model to obtain triplet instance sets that match the target triplet type. A knowledge graph module was constructed, including a knowledge graph of pregnancy nutrition and an individual knowledge graph of pregnant women. The module for personalized prenatal nutrition recommendations for pregnant women is used to recommend personalized prenatal nutrition plans based on a prenatal nutrition knowledge map.