Tree structure knowledge construction method and device based on large model and medium
By adopting the tree structure knowledge construction method based on large models in the text knowledge base construction, the problems of breakage and poor adaptability of text tilting methods in the existing technology are solved, and more efficient and accurate text parsing tree construction is achieved, which enhances semantic integrity and adaptability.
Patent Information
- Application Number
- CN202510070907.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2025-04-25
AI Technical Summary
In the construction of text knowledge bases, the text tiling method has the problem of "breaking" the sentence or semantics. The poor adaptability of the title tiling method can only work on some documents, and the clustering algorithm has poor interpretability and serious information loss.
Using the knowledge construction method of tree structure based on large models, we initialize the stack and create the root node, traverse the article line text, build the tree structure according to similarity and title type, and generate the parse tree of the target article.
It realizes a more efficient and accurate acquisition of the parse tree of the target article, retains document structure information, enhances the semantic integrity of text blocks, and improves the adaptability and interpretability of the method.
Smart Images

Figure CN119886307A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method, device and medium for constructing tree structure knowledge based on a large model. Background Art
[0002] RAG (Retrieval-Augmented Generation) is an artificial intelligence technology that combines information retrieval technology with language generation models. It retrieves relevant information from external knowledge bases and inputs it as prompts to large language models (LLMs) to enhance the model's ability to handle knowledge-intensive tasks such as question answering, text summarization, and content generation.
[0003] The core advantage of RAG is that it can dynamically utilize external knowledge, which outperforms the generative models that rely on static datasets. It consists of two core components: the retriever and the generator. The retriever uses techniques such as dense paragraph retrieval or the traditional BM25 algorithm to retrieve the most relevant documents from the corpus. The generator integrates the retrieved documents into coherent, context-related answers. The workflow of RAG usually includes four steps: First, the knowledge base is built. The RAG technology framework will extract text from the external knowledge base, split it into shorter text chunks, obtain a text knowledge base, and also perform text embedding to obtain a knowledge vector library. The second is question understanding. After the user asks a question, the RAG technology framework will perform text embedding on the question to obtain the embedding vector of the question text. Then there is knowledge retrieval. The RAG technology framework will perform similarity matching between the question text and the embedding vector and the knowledge base to match the relevant knowledge base original text. Finally, the answer is generated, the prompt word Prompt is constructed, and it is fed into LLMs to obtain the corresponding text answer.
[0004] The knowledge base construction phase mainly focuses on text segmentation. Currently, text segmentation technology mainly includes the following three aspects:
[0005] 1. Switch the text according to a fixed window size (number of words or sentences). The advantage is that it is simple and easy to implement, but the disadvantage is that it is easy to "break" sentences or semantics, which will cause certain difficulties for LLMs to understand knowledge.
[0006] 2. Split the text by title. The advantage is that you can get semantically complete text blocks, but the disadvantage is that the adaptability is relatively poor. This method can only work on certain documents because it presets the text title structure, and will fail beyond the scope of these documents.
[0007] 3. Convert text switching into a text clustering problem, and treat similar sentences as a text block. The advantage is that the algorithm has strong adaptability, but the disadvantage is that the clustering algorithm has poor interpretability. Once a problem occurs, it is difficult to optimize. At the same time, relying solely on the clustering algorithm will abandon the original information of the document, which will cause a certain degree of information loss. Summary of the invention
[0008] In view of the above technical problems, the technical solution adopted by the present invention is: a tree structure knowledge construction method based on a large model, the method comprising the following steps:
[0009] S100, initialize the stack and create the root node of the stack;
[0010] S200, obtaining the i-th line of text of the target article, where i is initialized to 1;
[0011] S300, judging the i-th line of text of the target article, if the i-th line of text is not a title, executing S400; if the i-th line of text is a title, executing S500;
[0012] S400, if the stack is empty, take the i-th line of text as the child node of the root node and execute S800;
[0013] If the stack is not empty, traverse the title nodes in order from the top of the stack to the bottom of the stack, obtain the similarity between the title node and the i-th line of text, and if the similarity between a title node and the i-th line of text is greater than a preset similarity threshold, take the i-th line of text as a child node of the title node, and execute S800; the title node is a child node composed of the text of the title;
[0014] S500, obtaining the title type of the i-th line of text of the target article;
[0015] S600, traverse the child nodes in the stack in order from the top of the stack to the bottom of the stack, if there is a child node with the same type as the title of the i-th line of text, mark the child node as a node of the same type, and pop all nodes from the top of the stack to the node of the same type, and execute S700; the node includes the title node and the child node;
[0016] S700, if the stack is empty, take the i-th line of text as a child node of the root node, and push the i-th line of text into the stack;
[0017] If the stack is not empty, get the top of the stack, take the i-th line of text as the child node of the top of the stack, and push the i-th line of text into the stack;
[0018] S800, if i<m, i=i+1, execute S200, otherwise, end the operation and obtain the parse tree of the target article; wherein m is the number of lines of the target article.
[0019] According to another aspect of the present invention, a non-transitory computer-readable storage medium is provided, in which at least one instruction or at least one program is stored, and the at least one instruction or the at least one program is loaded and executed by a processor to implement the aforementioned method.
[0020] According to yet another aspect of the present invention, an electronic device is provided, comprising a processor and the aforementioned non-transitory computer-readable storage medium.
[0021] The present invention has at least the following beneficial effects: In summary, the stack is initialized, and the root node of the stack is created, the i-th line of text of the target article is obtained, and the i-th line of text of the target article is judged. If the i-th line of text is not a title, if the stack is empty, the i-th line of text is used as a child node of the root node; if the stack is not empty, the title nodes are traversed in order from the top of the stack to the bottom of the stack, and the similarity between the title node and the i-th line of text is obtained. If the similarity between a title node and the i-th line of text is greater than a preset similarity threshold, the i-th line of text is used as a child node of the title node; if the i-th line of text is a title, the i-th line of text of the target article is obtained. The title type of the article is determined by traversing the child nodes in the stack from the top to the bottom. If there is a child node with the same title type as the i-th line of text, the child node is marked as a node of the same type, and all nodes from the top of the stack to the node of the same type are popped out of the stack. If the stack is empty, the i-th line of text is taken as the child node of the root node, and the i-th line of text is pushed into the stack; if the stack is not empty, the top of the stack is obtained, the i-th line of text is taken as the child node of the top of the stack, and the i-th line of text is pushed into the stack, until all lines of the target article are traversed and the parse tree of the target article is generated; thereby the parse tree of the target article can be obtained more efficiently and accurately. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0023] Figure 1 A flowchart of a method for constructing tree-structured knowledge based on a large model provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0024] 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 those skilled in the art without creative work are within the scope of protection of the present invention.
[0025] The embodiment of the present invention provides a tree structure knowledge construction method based on a large model, such as Figure 1 As shown, the method comprises the following steps:
[0026] S100, initialize the stack and create a root node of the stack. The root node is the root node.
[0027] S200, obtaining the i-th line of text of the target article, where i is initialized to 1. Specifically, if obtaining the i-th line of text of the target article fails, returning to the root node.
[0028] S300, judging the i-th line of text of the target article, if the i-th line of text is not a title, executing S400; if the i-th line of text is a title, executing S500.
[0029] Specifically, S300 further includes: inputting the i-th line of text of the target article into the target title binary classification model, and judging the i-th line of text of the target article. In one embodiment of the present invention, the target title binary classification model is a trained BERT-based binary classification module, which is used to answer whether the input text is a title.
[0030] S400, if the stack is empty, take the i-th line of text as the child node of the root node, and execute S800; if the stack is not empty, traverse the title nodes in the order from the top of the stack to the bottom of the stack, obtain the similarity between the title node and the i-th line of text, if the similarity between a title node and the i-th line of text is greater than the preset similarity threshold, take the i-th line of text as the child node of the title node, and execute S800; the title node is a child node composed of the text of the title. Among them, the top and bottom of the stack are both child nodes. It can be understood that the title nodes are traversed in the order from the top of the stack to the bottom of the stack, that is, in the order from near to far from the i-th line of text, the similarity between the title node and the i-th line of text is judged.
[0031] Optionally, the preset similarity threshold value ranges from 0.3 to 1; preferably, the preset similarity threshold value is 0.45.
[0032] Specifically, the similarity r between the title node and the i-th line of text i =[∑ n j=1 (A ij ×B j )] / [(∑ n j=1 (A ij 2 )) 1 / 2 ×(∑ n j=1 (B j 2 )) 1 / 2 ], where Aij is the jth preset dimension of the vector corresponding to the i-th row of text, B j is the jth preset dimension of the vector corresponding to the title node, the value range of j is 1 to n, and n is the number of preset dimensions of the vector. Specifically, those skilled in the art know that any method of obtaining the vector corresponding to the text in the prior art belongs to the protection scope of the present invention and will not be repeated here.
[0033] Specifically, S400 further includes: if the similarity between any title node and the i-th line of text is not greater than a preset similarity threshold, taking the i-th line of text as the child node at the top of the stack.
[0034] S500, obtaining the title type of the i-th line of text of the target article.
[0035] Specifically, S500 further includes: if obtaining the title type of the i-th line of text of the target article fails, executing S400.
[0036] S600, traverse the child nodes in the stack in order from the top of the stack to the bottom of the stack. If there is a child node with the same title type as the i-th line of text, mark the child node as the same type of node, and pop all nodes from the top of the stack to the same type of node, and execute S700; the node includes a title node and child nodes. Specifically, traverse the child nodes in the stack in order from the top of the stack to the bottom of the stack, that is, traverse the child nodes in the stack in order from near to far, so that the i-th line of text can find the closest title that meets the requirements. Popping all nodes from the top of the stack to the same type of node can be understood as there is a child node of the same type as the i-th line of text in the stack. At this time, it is necessary to find the top of the stack again and generate a branch to ensure that the child nodes of the same type are separate branches.
[0037] S700, if the stack is empty, take the i-th line of text as the child node of the root node and push the i-th line of text into the stack; if the stack is not empty, get the top of the stack, take the i-th line of text as the child node of the top of the stack, and push the i-th line of text into the stack.
[0038] S800, if i<m, i=i+1, execute S200, otherwise, end the operation and obtain the parse tree of the target article; wherein m is the number of lines of the target article.
[0039] In summary, initialize the stack and create the root node of the stack, get the i-th line of text of the target article, judge the i-th line of text of the target article, if the i-th line of text is not a title, if the stack is empty, take the i-th line of text as the child node of the root node; if the stack is not empty, traverse the title nodes in order from the top of the stack to the bottom of the stack, get the similarity between the title node and the i-th line of text, if the similarity between a title node and the i-th line of text is greater than the preset similarity threshold, take the i-th line of text as the child node of the title node; if the i-th line of text is a title, get the title type of the i-th line of text of the target article, traverse the child nodes in the stack in order from the top of the stack to the bottom of the stack, if there is a child node with the same title type as the i-th line of text, The child node is marked as a node of the same type, and all nodes from the top of the stack to the node of the same type are popped out of the stack. If the stack is empty, the i-th line of text is used as a child node of the root node, and the i-th line of text is pushed into the stack; if the stack is not empty, the top of the stack is obtained, the i-th line of text is used as a child node of the top of the stack, and the i-th line of text is pushed into the stack, until all lines of the target article are traversed, and a parse tree of the target article is generated; the present invention utilizes rules and deep learning solutions to construct a parse tree of the target article, which, on the one hand, retains the structural information of the document and makes the semantics of the text block more complete; on the other hand, the use of decoupled rules and deep learning methods ensures the adaptability of the method, thereby more efficiently and accurately obtaining the parse tree of the target article.
[0040] Furthermore, the text blocks constructed by this solution have complete semantics and store structural information in the tree, which can easily and accurately expand the text blocks during retrieval; and the text block construction method of this solution is consistent with the way humans write documents, so it is more interpretable. At the same time, this solution decouples the title from the overall style of the article, reducing the complexity of implementation. In addition, this solution uses a variety of deep learning algorithms to dig deeper into text information, making the algorithm more accurate and adaptable.
[0041] Furthermore, S500 also includes:
[0042] S510, obtaining the accuracy of the target title type recognition model. The target title type recognition model is a trained BERT-based single-label multi-classification module, which is used to answer what type the input title text belongs to.
[0043] S520: If the accuracy is greater than a preset accuracy threshold, the i-th line of text of the target article is input into the target title type recognition model to obtain the title type of the i-th line of text of the target article. The preset accuracy threshold can be set according to actual needs.
[0044] S530: If the accuracy is not greater than a preset accuracy threshold, a preset type list and a regular expression corresponding to each preset type are obtained, wherein the preset type list includes preset types of several text titles.
[0045] S540, matching the i-th line of text of the target article with a regular expression corresponding to a preset type to obtain the title type of the i-th line of text of the target article.
[0046] S550, inputting the title type of the j-th line of text and the i-th line of text of the target article into a target title type recognition model, and training the target title type recognition model.
[0047] In summary, the accuracy of the target title type recognition model is obtained. If the accuracy is greater than the preset accuracy threshold, the i-th line of text of the target article is input into the target title type recognition model to obtain the title type of the i-th line of text of the target article. If the accuracy is not greater than the preset accuracy threshold, a preset type list and a regular expression corresponding to each preset type are obtained, the i-th line of text of the target article is matched with the regular expression corresponding to the preset type to obtain the title type of the i-th line of text of the target article, the j-th line of text of the target article and the title type of the i-th line of text are input into the target title type recognition model, and the target title type recognition model is trained. When the accuracy of the target title type recognition model does not meet the requirements, the present invention uses rules to obtain the title type of the target article, and trains the target title type recognition model based on the title type determined by the rules, thereby improving the accuracy of the target title type recognition model.
[0048] Specifically, the preset title types are shown in Table 1. Here, only the style information of one content is specified, and the style of the multi-level title is not specified as a whole. The advantage of this is that it can reduce coupling and improve accuracy. If the style of the multi-level title is specified as a whole, it is necessary to define the number of levels and the style of each level of the title. The number of overall styles will increase factorially with the increase in the number of levels and styles, so the overall style information will become difficult to maintain, and a single move will affect the entire body. Compared with the recognition of multi-level style information, the recognition of a single style information is relatively simple, efficient and accurate. Among them, "other types" means other types besides known types. The reason for setting it is to make the model more complete, and it is also conducive to collecting "other types" of data for data analysis and data annotation, which helps to continuously optimize the model.
[0049] Table 1
[0050]
[0051] An embodiment of the present invention also provides a non-transitory computer-readable storage medium, which can be set in an electronic device to store at least one instruction or at least one program related to implementing a method in a method embodiment. The at least one instruction or the at least one program is loaded and executed by the processor to implement the method provided in the above embodiment.
[0052] An embodiment of the present invention further provides an electronic device, comprising a processor and the aforementioned non-transitory computer-readable storage medium.
[0053] Although some specific embodiments of the present invention have been described in detail by way of example, it should be understood by those skilled in the art that the above examples are only for illustration, not for limiting the scope of the present invention. It should also be understood by those skilled in the art that various modifications may be made to the embodiments without departing from the scope and spirit of the present invention.
Claims
1. A tree structure knowledge construction method based on a large model, characterized in that: The method comprises the following steps: S100, initialize the stack and create the root node of the stack; S200, obtaining the i-th line of text of the target article, where i is initialized to 1; S300, judging the i-th line of text of the target article, if the i-th line of text is not a title, executing S400; if the i-th line of text is a title, executing S500; S400, if the stack is empty, take the i-th line of text as the child node of the root node and execute S800; If the stack is not empty, traverse the title nodes in order from the top of the stack to the bottom of the stack, obtain the similarity between the title node and the i-th line of text, and if the similarity between a title node and the i-th line of text is greater than a preset similarity threshold, take the i-th line of text as a child node of the title node, and execute S800; the title node is a child node composed of the text of the title; S500, obtaining the title type of the i-th line of text of the target article; S600, traverse the child nodes in the stack in order from the top of the stack to the bottom of the stack, if there is a child node with the same type as the title of the i-th line of text, mark the child node as a node of the same type, and pop all nodes from the top of the stack to the node of the same type, and execute S700; the node includes the title node and the child node; S700, if the stack is empty, take the i-th line of text as a child node of the root node, and push the i-th line of text into the stack; If the stack is not empty, get the top of the stack, take the i-th line of text as the child node of the top of the stack, and push the i-th line of text into the stack; S800, if i<m, i=i+1, execute S200, otherwise, end the operation and obtain the parse tree of the target article; wherein m is the number of lines of the target article.
2. The tree structure knowledge construction method based on a large model according to claim 1 is characterized in that: S300 also includes: inputting the i-th line of text of the target article into the target title binary classification model, and judging the i-th line of text of the target article.
3. The method for constructing tree-structured knowledge based on a large model according to claim 1, characterized in that: The S500 also includes: S510, obtaining the accuracy of the target title type recognition model; S520, if the accuracy is greater than a preset accuracy threshold, inputting the i-th line of text of the target article into a target title type recognition model to obtain the title type of the i-th line of text of the target article; S530, if the accuracy is not greater than a preset accuracy threshold, obtaining a preset type list and a regular expression corresponding to each preset type, wherein the preset type list includes preset types of a plurality of text titles; S540, matching the i-th line of text of the target article with a regular expression corresponding to a preset type to obtain a title type of the i-th line of text of the target article; S550, inputting the title type of the j-th line of text and the i-th line of text of the target article into a target title type recognition model, and training the target title type recognition model.
4. The method for constructing tree-structured knowledge based on a large model according to claim 1, characterized in that: S500 also includes: if the title type of the i-th line of text of the target article fails to be obtained, executing S400.
5. The tree structure knowledge construction method based on a large model according to claim 1 is characterized in that: The preset similarity threshold value ranges from 0.3 to 1.
6. The method for constructing tree-structured knowledge based on a large model according to claim 5, characterized in that: The preset similarity threshold is 0.
45.
7. The method for constructing tree-structured knowledge based on a large model according to claim 1, characterized in that: In S400, the similarity r between the title node and the i-th line of text i =[∑ n j=1 (A ij ×B j )] / [(∑ n j=1 (A ij 2 )) 1 / 2 ×(∑ n j=1 (B j 2 )) 1 / 2 ], where A ij is the jth preset dimension of the vector corresponding to the i-th row of text, B j It is the j-th preset dimension of the vector corresponding to the title node. The value range of j is 1 to n, and n is the number of preset dimensions of the vector.
8. The method for constructing tree-structured knowledge based on a large model according to claim 1, characterized in that: S400 further includes: if the similarity between any title node and the i-th line of text is not greater than a preset similarity threshold, taking the i-th line of text as the child node at the top of the stack.
9. A non-transitory computer-readable storage medium, wherein at least one instruction or at least one program is stored in the storage medium, characterized in that: The at least one instruction or the at least one program is loaded and executed by the processor to implement the tree-structured knowledge construction method based on a large model as described in any one of claims 1-8.
10. An electronic device, characterized in that: The invention comprises a processor and the non-transitory computer-readable storage medium as claimed in claim 9.