A method for generating content of standardization documents for characteristic agricultural products based on knowledge retrieval enhancement

By introducing knowledge retrieval enhancement mechanisms and vertical domain fine-tuning in the large language model, real-time information acquisition and accuracy problems when generating standardized files are solved, and efficient and accurate content generation is achieved.

CN118779407BActive Publication Date: 2025-03-21JIANGXI AGRICULTURAL UNIVERSITY +1

Patent Information

Application Number
CN202411262651.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-10
Publication Date
2025-03-21
Estimated Expiration
2044-09-10

AI Technical Summary

Technical Problem

When generating standardized files of characteristic agricultural products, existing large language models are difficult to obtain real-time information, knowledge updates are lagging, and factually wrong content is easily generated, resulting in the lack of timeliness and accuracy of the generated text.

Method used

Using a method based on knowledge retrieval enhancement, a hybrid mechanism of vector search, keyword search and knowledge graph search is used to inject external real-time knowledge into the large language model, improve the factual accuracy of generated content, and enhance the adaptability and efficiency of the model through vertical domain fine-tuning and structured pruning.

Benefits of technology

It significantly improves the accuracy and timeliness of the generation of standardized file content, reduces resource consumption, speeds up the reasoning process, and ensures the quality and consistency of the generated content.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118779407B_ABST
    Figure CN118779407B_ABST
Patent Text Reader

Abstract

The present invention belongs to the technical field of natural language processing, and specifically relates to a method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement, wherein the method collects standardized documents, extracts content and divides it into text blocks to form a data set; embeds the text blocks into vector form and stores them in a vector database, then extracts entities and relationships between entities from the text data and stores the entities and relationships in a graph database; optimizes a large language model, combines three methods of vector retrieval, keyword retrieval and knowledge graph retrieval to form a hybrid retrieval enhancement method, respectively retrieves content related to user input from a vector database and a graph database; screens the retrieval results, constructs prompt words of a large language model; inputs the prompt words into the optimized large language model to generate content related to the standardized document. The present invention can provide services such as general content generation of standardized documents and domain knowledge question and answer, thereby improving the efficiency of standard formulation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of natural language processing, and in particular relates to a method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement. Background Art

[0002] The standardization document of specialty agricultural products provides action rules and implementation guidelines for specific agricultural fields. It needs to be written in accordance with certain formats and structural specifications. The purpose of its writing is to ensure the consistency, reliability and comparability of the rules, so as to solve the problems of management ambiguity and non-traceability of product quality indicators in the specialty agricultural products industry. It provides a common framework that facilitates effective collaboration among agricultural enterprises, organizations and government departments to avoid misunderstandings and confusions. It also helps to ensure the quality and safety of specialty agricultural products, avoid industry chaos, and promote agricultural technology innovation and market development. With the rapid development of artificial intelligence and big model technology, big language models are increasingly used in many fields. Big language models deeply learn the expression patterns and contextual semantics of natural language in large-scale corpus data sets, and can generate high-quality texts with correct grammar and fluent expression, thereby improving the diversity and creativity of content in text generation tasks. However, although the big language model has excellent text generation capabilities, it is only based on past training data, cannot obtain real-time information, and lags behind in knowledge update, so it cannot generate timely texts. In addition, since the large language model uses a statistically based probabilistic method to generate text word by word, it completely relies on its internal parameterized knowledge, which makes it easy to generate content that seems logically rigorous but actually contains factual errors, resulting in the problem of large model hallucination. For knowledge-intensive tasks that need to process a large amount of professional information and rely on a wide range of domain backgrounds, it not only requires the model to understand the grammar and semantics of natural language, but also requires the model to be able to effectively use a large amount of background knowledge or external resources to understand and process problems. However, the general large language model lacks domain expertise, which leads to limitations in dealing with such problems. Summary of the invention

[0003] The purpose of the present invention is to propose a method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement. The method first injects external real-time knowledge into the large language model through a hybrid retrieval enhancement mechanism that integrates three methods: vector retrieval, keyword retrieval, and knowledge graph retrieval to improve the factual accuracy of the content generated by the large language model and combat the generation of hallucinations. Subsequently, the general large language model is fine-tuned in vertical fields to enable the model to have a deeper understanding of the professional terms in this field and adapt to actual application scenarios. Finally, the large language model is structurally pruned to reduce resource consumption and speed up the reasoning process.

[0004] The present invention is achieved through the following technical solutions.

[0005] The method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement is as follows:

[0006] Step 1: Collect standardized files in PDF format through crawlers, then use PDF parsing methods to extract the content of standardized files and split them into text blocks to form a data set;

[0007] Step 2: Embed the text block into vector form and store it in the vector database, then extract the entities and the relationships between entities from the text data and store the entities and relationships in the graph database;

[0008] Step 3: Fine-tune the large language model in the vertical field of the dataset and perform structured pruning to remove redundant parameters;

[0009] Step 4: Obtain the original user input and perform keyword decomposition and terminology standardization on the original user input to eliminate ambiguous input and form the final user input;

[0010] Step 5: Combine vector search, keyword search, and knowledge graph search to form a hybrid search enhancement method, which retrieves content related to user input from the vector database and graph database respectively;

[0011] Step 6: Filter the retrieval results of the hybrid retrieval enhancement method, remove the retrieval results with weak relevance, and then build the prompt words of the large language model based on the retrieval results;

[0012] Step 7: Input the prompt words into the large language model after vertical field fine-tuning and structural pruning, and the large language model generates standardized document-related content.

[0013] Further preferably, a multi-stage cascade structure is adopted, which consists of seven stages: query decomposition, route selection, hybrid search enhancement, result screening, composition prompt words, input of large language model, and content generation;

[0014] In the query decomposition stage, the original user input undergoes entity extraction, input decomposition, and terminology normalization;

[0015] In the routing selection phase, the knowledge database will be selected based on the type of content generated by the user in the decomposition query phase;

[0016] The hybrid search enhancement stage uses three different search methods in parallel: vector search, keyword search, and knowledge graph search. The knowledge graph search branch retrieves the substructure of the multimodal knowledge graph from the graph database. The vector search branch searches in the vector database based on the cosine similarity of word vectors. The keyword search branch also searches in the vector database, but unlike vector search, it uses keyword matching to search.

[0017] In the result screening stage, the text blocks obtained by vector retrieval and keyword retrieval will be combined through the inverse sorting algorithm to determine the unique result set; the knowledge graph substructure retrieved by the knowledge graph retrieval branch also needs to be filtered, and then the filtered subgraph is converted into the form of entity triples, which are used as the context in the prompt word together with the text blocks retrieved and screened from the vector database;

[0018] In the stage of forming prompt words, a quality inspection module is set for the prompt words. If the prompt words fail to pass the quality inspection on relevance, the route selection will be changed, and the hybrid retrieval enhancement stage and the result screening stage will be re-executed. Only if the prompt words pass the quality inspection will they be sent to the large language model to provide external knowledge for them.

[0019] In the content generation stage, the large language model combines the prompt words to generate corresponding content and feeds it back to the user.

[0020] Further preferably, the process of constructing the vector database is: firstly, the standardized files of the featured agricultural products in PDF format and related information are collected from relevant websites by crawlers, and then the contents of the unstructured files are extracted by PDF parsing, and divided into text blocks to form a data set. The text blocks are converted into vector form by a pre-trained word embedding model and stored in the vector database.

[0021] It is further preferred that a tree index with 4 levels is constructed for the text blocks stored in the vector database by recursive clustering. The leaf nodes in level 4 represent the numbers of specific text blocks, reflecting the association of texts at a fine-grained level; level 3 is a clustering node, reflecting the similarity of texts in semantic and content features, which is an association at a medium-grained level; level 2 is a super clustering node, reflecting the similarity of texts in topics, which is an association at a coarse-grained level, and level 1 is the root node of the tree.

[0022] Further preferably, entities and relationships between entities are extracted from text data and the entities and relationships are stored in a graph database, including: extracting content from an unstructured corpus obtained by parsing standardized documents, including text, tables, and pictures, and constructing a multimodal knowledge graph for a vertical field. The multimodal knowledge graph contains three types of nodes: text nodes, table nodes, and picture nodes. There are two types of edges between nodes: semantic relationships and structural relationships.

[0023] Further optimization, the multimodal knowledge graph is represented by a directed graph G={ℰ,ℛ,𝒜,𝒱,𝒯 ℛ , 𝒯 𝒜}, where ℰ is the set of entities, ℛ is the set of relations, 𝒜 is the set of entity attributes, and 𝒱 is the set of attribute values; 𝒯 𝒜 It is a set of attribute triples, which is used to describe various attribute information of an entity; Represents a set of entity triples, expressed as:

[0024] ;

[0025] Among them, ℛ is the set of all relations in the multimodal knowledge graph, Represents a collection of text entities, It is a collection of two modal data: tables and pictures.

[0026] For further optimization, vector search uses a breadth-first mode to search for relevant text blocks in a tree structure; keyword search requires first establishing an inverted index of the text blocks, and then using the BM25 (Best Matching 25) algorithm to filter; for text blocks obtained by vector search and keyword search, a unique result set is obtained from two result sets with different relevance indicators through a reciprocal sort fusion algorithm (RRF).

[0027] Further preferably, in step three, a low-rank adaptive fine-tuning method with dynamically adjustable rank size is used to fine-tune the parameters of the general large language model: first, the weight matrix of the original large language model is kept unchanged, and then a parallel bypass module with fine-tunable parameters is set for the module inside the large language model. The bypass module is decomposed into the product of two low-rank matrices, one of which is used for down-projection and the other for up-projection; a trainable gating unit is added between the up-projection matrix and the down-projection matrix. At this time, the bypass module is expressed as:

[0028] ;

[0029] in, represents the input of the bypass module, z represents the output of the bypass module, is the lower projection matrix, is the upper projection matrix, g is the gating unit;

[0030] In the process of vertical domain fine-tuning, the parameters of the gating unit are adjusted through the proximal gradient descent optimization algorithm; then a soft threshold function is set to set the values ​​of the gating unit matrix that are less than the threshold to 0, and only retain the values ​​that are greater than the threshold, thereby obtaining a sparse representation of the matrix.

[0031] Further optimization, the process of vertical field fine-tuning is expressed by the following formula:

[0032] ;

[0033] where g t represents the value of the gate control unit matrix at the tth iteration, g t+1 is the value of the door unit matrix at the next iteration; is the loss function of the bypass module, represents the gradient of the loss function at the tth iteration of g; η t is the learning rate at the tth iteration, λ is a hyperparameter of the regularization strength, which is used to control the sparsity of the gated unit matrix; Represents the soft threshold function, and the function expression is:

[0034] ;

[0035] Threshold Corresponding to the previous formula ; Then filter out the element i with a value of 0 in the gate control unit matrix and form a set , this process is expressed as:

[0036] ;

[0037] Where m is the number of the bypass module, r max is the maximum rank initially set, Represents the value of the i-th column of the gated unit matrix numbered m; finally, according to the set The two projection matrices are clipped and the lower projection matrix W of the mth bypass module is d (m) No. The row is removed, and the upper projection matrix W of the mth bypass module is u (m) No. The columns are removed to obtain two new projection matrices with smaller ranks, and the elements with zero are also removed for the gating unit.

[0038] Further preferably, in step three, the weights and gradients of the LoRA module are used as approximate values ​​of the weights and gradients of the pre-training module to evaluate the importance of the pre-training module and perform structured pruning.

[0039] The present invention designs three different retrieval strategies for multi-way recall of key contents of external knowledge base, which has the following advantages:

[0040] 1. The present invention creates a large language model specifically for the generation and question-answering of standardized documents for specialty agricultural products. This allows the developers of standardized documents to be freed from the tedious information collection, text writing and format adjustment, and focus on the acquisition of physical and chemical data. Under the premise of ensuring the quality of standardized documents, the writing efficiency is improved and the developers' time and energy are saved.

[0041] 2. An external knowledge database was constructed using knowledge engineering, and a hybrid retrieval enhancement method that integrates vector retrieval, keyword retrieval, and knowledge graph retrieval was designed to accurately recall important information from the external knowledge base and then inject it into the large language model, significantly enhancing the model's information understanding and generation capabilities.

[0042] 3. Combine vertical field fine-tuning with large language model pruning to make the large language model more suitable for tasks in the field of specialty agricultural product standardization, avoid conflicts between external knowledge and internal parameterized knowledge of the large language model, streamline the model structure, and improve reasoning speed. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 It is a flow chart of a method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement provided by the present invention.

[0044] Figure 2 It is a schematic diagram of the framework structure of the method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement.

[0045] Figure 3 It is a schematic diagram of the process of building a vector database.

[0046] Figure 4 Constructing a schematic for a multimodal knowledge graph.

[0047] Figure 5 This is a schematic diagram of the retrieval and fusion process of the two methods: vector and keyword.

[0048] Figure 6 This is a diagram of the framework for fine-tuning a large language model in a vertical field on a dataset.

[0049] Figure 7 This is a curve chart of the mean recall rate changes for 8 types of retrieval under different retrieval numbers.

[0050] Figure 8 It is the confusion matrix diagram of the RRF fusion retrieval method on the term retrieval type. DETAILED DESCRIPTION

[0051] The present invention is further described in detail below with reference to the accompanying drawings and embodiments.

[0052] Reference Figure 1 ,A method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement, the steps are as follows:

[0053] Step 1: Collect standardized files in PDF format through crawlers, then use PDF parsing methods to extract the content of standardized files and split them into text blocks to form a data set;

[0054] Step 2: Embed the text block into vector form and store it in the vector database, then extract the entities and the relationships between entities from the text data and store the entities and relationships in the graph database;

[0055] Step 3: Fine-tune the large language model in the vertical field of the dataset and perform structured pruning to remove redundant parameters;

[0056] Step 4: Obtain the original user input and perform keyword decomposition and terminology standardization on the original user input to eliminate ambiguous input and form the final user input;

[0057] Step 5: Combine vector search, keyword search, and knowledge graph search to form a hybrid search enhancement method, which retrieves content related to user input from the vector database and graph database respectively;

[0058] Step 6: Filter the retrieval results of the hybrid retrieval enhancement method, remove the retrieval results with weak relevance, and then build the prompt words of the large language model based on the retrieval results;

[0059] Step 7: Input the prompt words into the large language model after vertical field fine-tuning and structural pruning, and the large language model generates standardized document-related content.

[0060] Figure 2 The basic framework of the present invention is demonstrated. The framework adopts a multi-stage cascade structure, which consists of seven stages: query decomposition, route selection, hybrid retrieval enhancement, result screening, composition prompt words, input of large language model, and content generation.

[0061] During the query decomposition stage, the original user input will undergo entity extraction, input decomposition, and terminology normalization to eliminate possible ambiguous input by the user and more accurately locate user needs.

[0062] In the routing selection phase, the knowledge database will be selected based on the content types generated by the user needs obtained in the decomposition query phase. There are two types of content types: technical specifications and product standards. The former is further divided into six types: breeding and seedling raising, cultivation, sales, storage, pest and disease control, and processing.

[0063] The hybrid search enhancement phase uses three different search methods in parallel: vector search, keyword search, and knowledge graph search. The knowledge graph search branch retrieves the substructure of the multimodal knowledge graph from the graph database, the vector search branch searches in the vector database based on the cosine similarity of word vectors, and the keyword search branch also searches in the vector database, but unlike vector search, it uses keyword matching to search.

[0064] In the result screening stage, the text blocks obtained by vector retrieval and keyword retrieval will be combined through a reciprocal sorting fusion algorithm to determine a unique result set. This algorithm will "reorder" the retrieved text blocks and take only the first k text blocks to filter out low-quality text blocks and enhance the relevance of text blocks in the result set. The knowledge graph substructure retrieved by the knowledge graph retrieval branch also needs to be filtered to remove some less relevant nodes and edges, and then the filtered subgraph is converted into the form of entity triples, which are used as the context in the prompt word together with the text blocks retrieved and screened from the vector database.

[0065] In the stage of composing prompt words, a quality inspection module is set up for the prompt words. If the quality inspection on relevance fails, the routing selection will be changed, and the hybrid retrieval enhancement stage and result screening stage will be re-executed. Only if the quality inspection is passed will the prompt words be sent to the large language model to provide it with external knowledge.

[0066] The large language model will undergo fine-tuning and structured pruning on vertical domain datasets to improve its performance and efficiency in specific domains and tasks. Finally, in the content generation stage, the large language model combines prompt words to generate corresponding content and provide feedback to users.

[0067] Hybrid retrieval enhancement is the core stage of the present invention, which is divided into two processes: database construction and text retrieval.

[0068] like Figure 3 As shown in the figure, the process of constructing the vector database is as follows: first, we collect standardized PDF files of featured agricultural products and related information from relevant websites through crawlers, then extract the content of unstructured files through PDF parsing, and divide them into text blocks to form a data set. The text blocks are converted into vector form (text block vector) through the pre-trained word embedding model and stored in the vector database.

[0069] In the absence of index support, when retrieving text blocks, it is necessary to traverse the entire vector database to find the search target, so that each search requires global comparison and calculation. The computing resources and computing time consumed by the search will increase significantly with the increase of the vector database, which greatly reduces the search efficiency and affects the overall performance and user experience. Therefore, this embodiment constructs a tree index with 4 levels for the text blocks stored in the vector database through recursive clustering. This hierarchical structure can reflect the connection between texts at different abstract levels and the association at different granularities. The leaf node in level 4 represents the number of the specific text block, which is the smallest clustering unit and reflects the association of the text at a fine granularity; level 3 is a clustering node, which reflects the similarity of the text in semantics and content features, and is an association at a medium granularity; level 2 is a super clustering node, which reflects the similarity of the text in subject matter, and is an association at a coarse granularity, and level 1 is the root node of the tree.

[0070] like Figure 4 As shown in the figure, after the vector database is built, the content is extracted from the unstructured corpus obtained by parsing standardized files, including text, tables, and pictures, and a multimodal knowledge graph for vertical fields is constructed. The multimodal knowledge graph contains three types of nodes: text nodes, table nodes, and picture nodes. There are two types of edges between nodes: semantic relationships and structural relationships. The multimodal knowledge graph stores accurate, updateable, and interpretable factual knowledge. The nodes represent specific entities rather than a large number of strings, providing more fine-grained external knowledge for large language models. The multimodal knowledge graph can be represented by a directed graph G={ℰ, ℛ, 𝒜, 𝒱, 𝒯 ℛ , 𝒯 𝒜}, where ℰ is the set of entities, ℛ is the set of relations, 𝒜 is the set of entity attributes, and 𝒱 is the set of attribute values. 𝒜 It is a collection of attribute triples, which is used to describe various attribute information of an entity. Represents a set of entity triples, which can be expressed as:

[0071] ;

[0072] Among them, ℛ is the set of all relations in the multimodal knowledge graph, Represents a collection of text entities, It is a collection of two modal data, tables and pictures, which are considered as new entities and added to the knowledge graph. When performing graph-based knowledge graph retrieval, the text-based nodes are the core. According to the keywords in the user input, the related nodes and their direct neighbor nodes and secondary neighbor nodes are returned.

[0073] Figure 5The retrieval and fusion processes of the two methods, vector retrieval and keyword retrieval, are specifically demonstrated. Vector retrieval is based on semantics and can identify synonyms, near-synonyms, and sentences with different wording. Keyword retrieval can lock in specific important words. It treats both user input and the text to be retrieved as unordered bags of words, and only considers them as a collection of words. When searching, it only considers whether the words match, and does not care about the order and semantic information of the words. The two retrieval methods are combined to perform double recall on text blocks, ensuring that the semantics can be accurately understood and the key words in the user input can be captured during the retrieval process. Figure 5 In the , vector search uses breadth-first mode to search for relevant text blocks in the tree index. The tree index has 4 levels, where level 1 is the root node of the tree; level 2 is the super cluster node, which can be represented by letters A and B; level 3 is the cluster node, which can be represented by letters C, D, E, F, G, and H respectively; level 4 is the leaf node of the tree, which stores the number of the text vector block. The user input determines the super cluster node A and cluster node D of the relevant text block it needs through the tree index, and then searches in the child nodes corresponding to cluster node D through the approximate nearest neighbor method. This retrieval process is Figure 5 The two-dimensional space vector is used to show that in the two-dimensional vector space, leaf nodes, i.e., text block vectors, are represented by "dots", "squares" represent super cluster nodes or cluster nodes, and "hexagrams" represent the corresponding positions of the vectors of the user input content in the two-dimensional vector space. The approximate nearest neighbor method will take the several text block vectors closest to the vector of the user input content in the vector space as related text blocks, and use them as the search results. For keyword retrieval, it is necessary to first establish an inverted index of the text block. When establishing an inverted index, the text in the data set will first be segmented to build a term table. Each word in the term table will point to a text block number list, indicating that the word has appeared in the text block. For example, for user input, three keywords are extracted. These three keywords correspond to "word 2", "word 3", and "word 4" in the term table respectively. Through the inverted index, the text blocks where these three keywords appear can be found as: block O, block P, block M, block S, block L, block K, block J, and block T. Then, the BM25 (Best Matching 25) algorithm is used to find the top k text blocks with the highest relevance from the above text blocks, that is, to take the text block of Tok k. This algorithm avoids the deficiency of the IF-IDF algorithm that only considers the word frequency, because the word frequency will be affected by the length of the text block. The BM25 algorithm introduces the text block length factor, so that long text blocks will not be misjudged as having higher relevance due to the high overall word frequency. The algorithm can be expressed as:

[0074] ;

[0075] Among them, Q represents user input, d represents text block, n represents the number of keywords extracted from user input, and qi represents the i-th keyword in the user input, IDF(q i ) represents the inverse document frequency of the keyword, f(q i , d) represents the number of times the i-th keyword appears in text block d, len(d) represents the length of text block d, avg_len is the average length of all text blocks, and k1 and b are adjustment parameters.

[0076] For the text blocks obtained by the two retrieval methods, a unique result set is obtained from two result sets with different relevance indicators through the reciprocal ranking fusion algorithm (RRF), which can be expressed as:

[0077] ;

[0078] in, is the RRF score, D is the set of relevant text blocks retrieved, S is the set of retrieval systems, r(d) is the ranking of text block d in retrieval system r, k a is a constant used to scale the RRF score. Figure 5 It can be seen that the text blocks obtained by vector retrieval are: block J, block K, block L, block M, and the text blocks obtained by keyword retrieval are: block M, block J, block L, block K. Then the text blocks obtained by the two retrieval methods are screened and reordered by the inverse sorting fusion algorithm. First, it is necessary to calculate the reverse ranking of the text blocks obtained by the two retrieval methods. The rankings of blocks J, block K, block L, and block M obtained by vector retrieval are: 1, 2, 3, and 4, respectively, so the corresponding reverse rankings are: 1, 1 / 2, 1 / 3, and 1 / 4. Similarly, the reverse rankings of blocks M, block J, block L, and block K obtained by keyword retrieval are also 1, 1 / 2, 1 / 3, and 1 / 4. The reverse rankings corresponding to each block are added together, and the values ​​of blocks J, block K, block L, and block M are obtained as 1.5, 0.75, 0.66, and 1.25, respectively. This is used as the RRF score to reorder the text blocks according to the size of the relevance, and finally blocks J, block K, block L, and block M are obtained as the final retrieval results.

[0079] When searching the knowledge graph, the text-type nodes are mainly used as the core. According to the keywords in the user input, the relevant nodes and their direct neighboring nodes and secondary neighboring nodes are returned. Then, the returned sub-knowledge graph is filtered according to the user input and finally converted into triple form.

[0080] Vertical domain fine-tuning methods for large language models such as Figure 6As shown in the figure. The number of parameters of a large language model exceeds 100 million. The computational cost of adjusting the entire model parameters using the full fine-tuning method is too high. Therefore, the present invention adopts an efficient parameter fine-tuning method to freeze most of the model's parameters, retaining the general knowledge it has learned in large-scale pre-training tasks, and at the same time trains on domain datasets to adjust a small part of the model's variable parameters to make the model more suitable for downstream tasks, thereby reducing computational overhead and improving fine-tuning efficiency.

[0081] Specifically, the present invention uses a low-rank adaptive fine-tuning method that can dynamically adjust the rank size to efficiently fine-tune the parameters of a general large language model. For a large language model composed of a linear transformation layer, a self-attention mechanism layer, a residual connection, a layer normalization layer, and a forward propagation layer, first keep all the weight matrices of the original large language model unchanged, and then set a parallel parameter fine-tuning bypass module for a linear transformation layer inside the large language model. The bypass module can be decomposed into the product of two low-rank matrices, one of which is used for down-projection and is called the down-projection matrix, and the other is used for up-projection and is called the up-projection matrix, wherein the linear transformation layer is a matrix of d rows and d columns, the down-projection matrix maps the d-dimensional input into an r-dimensional intermediate result, and the up-projection matrix restores the r-dimensional intermediate result to a d-dimensional output. Rank is an important hyperparameter of the bypass module. Different modules have different structures and complexities, and require ranks of different sizes to maximize the performance of the model. Fixed ranks cannot adapt to such diversity requirements, so the size of the rank in the variable matrix should be dynamically adjustable. In order to realize this function, the present invention adds a trainable gating unit between the upper projection matrix and the lower projection matrix. At this time, the bypass module can be expressed as:

[0082] ;

[0083] in, represents the input of the bypass module, z represents the output of the bypass module, is the lower projection matrix, is the upper projection matrix, g is the gating unit, which is a matrix with r rows and r columns. In the process of vertical field fine-tuning, the gating unit is parameterized by the proximal gradient descent optimization algorithm. Then a soft threshold function is set to set the values ​​of the gating unit matrix that are less than the threshold to 0, and only the values ​​that are greater than the threshold are retained, thereby obtaining a sparse representation of the matrix - a sparse gating matrix. This process can be expressed by the following formula:

[0084] ;

[0085] where g t represents the value of the gate control unit matrix at the tth iteration, g t+1 It is the value of the door unit matrix at the next iteration. is the loss function of the bypass module, Represents the gradient of the loss function obtained by g at the tth iteration. η t is the learning rate at the tth iteration, and λ is a hyperparameter of the regularization strength, which is used to control the sparsity of the gated unit matrix. Represents the soft threshold function, and the function expression is:

[0086] ;

[0087] The threshold value for this formula Corresponding to the previous formula Then filter out the element i with a value of 0 in the gate control unit matrix and form it into a set of 0 elements , this process can be expressed as:

[0088] ;

[0089] Where m is the number of the bypass module, r max is the maximum rank initially set, Represents the value of the i-th column of the gated unit matrix numbered m. Finally, according to the set The two projection matrices are clipped and the lower projection matrix W of the mth bypass module is d (m) No. The row is removed, and the upper projection matrix W of the mth bypass module is u (m) No. The columns are removed to obtain two new projection matrices with smaller ranks. For the gating unit, the elements with zero are also removed to make its structure more compact.

[0090] The pre-trained large language model has redundant structures and parameters. Pruning the large language model can reduce computing costs, improve efficiency, and better balance the performance and deployment complexity of the model. The present invention uses the weights and gradients of the LoRA module as approximate values ​​of the weights and gradients of the pre-trained modules to evaluate the importance of the pre-trained modules and perform structured pruning. Since there are associations between different modules of the pre-trained large language model, it is necessary to prune other modules associated with it while pruning a certain module to avoid destroying the model structure due to local pruning and causing global performance degradation. The present invention regards interdependent modules as a group and prunes at the group granularity. First, use the lower projection matrix W d , the projection matrix W u The importance of each parameter in the pre-training module is calculated by the gradient of , and then the importance of all parameters in the same group is accumulated as the importance level of the group, and finally the group with the lowest importance is deleted. The process of evaluating parameter importance can be expressed as:

[0091] ;

[0092] ;

[0093] ;

[0094] Among them, W v represents the weight in the pre-training module, W d , W u are the upper projection matrix and the lower projection matrix, respectively, and W is the output of the large language model after fine-tuning, which is the sum of the output of the pre-training module and the output of the bypass module. ij Indicates the importance of the weights with subscripts i and j in the pre-training module. Its value is equal to the change in the loss value compared to the original value after the weight is set to 0. represents the loss function, x and y represent the input and output of the pre-training module respectively, Indicates the loss value of the pre-training module. Indicates (W d W u ) ij +W ji =0, that is, the loss value when Wv=0, due to I ij The computational cost of is high, so the importance is approximated by first-order Taylor expansion , represents the weights of all columns in the i-th row of the projection matrix, Represents the weights of all rows in the j-th column of the upper projection matrix.

[0095] Obtaining high-quality standardized documents and related information is the basis for building an external knowledge base and fine-tuning a general large model. The present invention collects standardized documents and other contents such as basic information of characteristic agricultural products to form a data set. First, the standardized documents and related data are obtained from websites such as local standard information service platforms around thirty kinds of fruit, vegetable and tea through incremental crawler technology. These data are stored in different formats such as PDF and HTML. Subsequently, the multi-source heterogeneous unstructured files are extracted and integrated according to three basic types: text, table and picture. Then the text content is cleaned, and the headers, page numbers and other useless information retained by the PDF file converted to text are removed, so that it can focus on the substantive content in the file. Among the thirty kinds of fruit, vegetable and tea, 15 kinds of fruits are fruits, namely: grapefruit, navel orange, kiwi, plum, strawberry, banana, watermelon, grape, pineapple, mango, pear, peach, blueberry, lemon and citrus. Twelve kinds of vegetables are vegetables, namely: pepper, tomato, cucumber, potato, eggplant, spinach, onion, ginger, garlic, pumpkin, sweet potato and pea. Three kinds of tea are tea, namely: black tea, green tea and white tea.

[0096] The search results are evaluated using four indicators: precision (Precision@k), recall (Recall@k), F1-score (F1-score@k), and normalized discounted cumulative gain (NDCG@k). The first three indicators focus on the number of relevant items in the first k results retrieved, without considering the ranking of the relevant items. NDCG is a ranking-aware evaluation indicator. Under the premise that the number of relevant items retrieved is the same, the higher the ranking of the relevant items, the larger the value of this indicator.

[0097] During retrieval, only the first k retrieval results with the highest relevance values ​​are taken. The setting of the k value has a great influence on the retrieval results. The larger the k value, the more samples with relevant labels are included in the retrieval result list, and the higher the recall rate. However, in the process of hybrid retrieval enhancement, too many retrieval results will cause the context input into the large language model to be too long, which will interfere with the model locking the most needed external knowledge, thereby reducing performance. Therefore, it is necessary to balance the retrieval performance and the number of retrieval results when performing retrieval enhancement. In order to find a suitable k value, this study fixed the range of k between 0 and 36, and designed 8 different retrieval types, and then observed the changes in the recall rate indicator when different numbers of retrieval results were taken. The results of the average recall rate on the 8 retrieval types under different k values ​​are shown below. Figure 7 As shown in the figure, it can be seen that the recall rate curve rises sharply between 0 and 15, and gradually rises gently between 15 and 36. The slope of the former is 0.03301, and the latter is 0.01024. The former is greater than the latter. Therefore, this study takes the first 15 search results.

[0098] Then, the present invention tests the retrieval capabilities of three retrieval methods, namely, vector retrieval, keyword retrieval, and reciprocal fusion retrieval (RRF) of vectors and keywords, on 8 different retrieval types. The k value of all evaluation indicators is set to 15. The experimental results are shown in Table 1, from which it can be seen that the performance of RRF fusion retrieval in different retrieval types is better than that of single retrieval.

[0099] Table 1

[0100]

[0101] The regularized confusion matrix of the RRF fusion retrieval results of the term retrieval type is as follows Figure 8As shown in the figure, the matrix has two rows and two columns. The horizontal axis represents the retrieval status of the text block, whether it is retrieved or not, and the vertical axis represents the relevance of the label of the text block, whether it is relevant or not. 0.3077 represents the value after the regularization of the number of text blocks whose labels are relevant and retrieved; 0.6923 represents the value after the regularization of the number of text blocks whose labels are relevant and not retrieved; 0.0039 represents the value after the regularization of the number of text blocks whose labels are irrelevant but retrieved; 0.9961 represents the value after the regularization of the number of text blocks whose labels are irrelevant and not retrieved.

[0102] In order to verify the effectiveness of the method proposed in this study in the generation of standardized documents, an ablation experiment was designed and 8 ablation schemes were formulated. The evaluation indicators used are ROUGE-2, chrF, BLEU-2, BERT score, and Gscore. Among them, ROUGE-2, chrF, and BLEU-2 are all evaluation indicators based on the N-gram method. ROUGE-2 mainly focuses on the degree of overlap between the generated text and the real text, that is, this indicator is more inclined to the recall rate of words in the generated text, while ChrF focuses on the degree of text overlap at the character level. They can reflect the content coverage of the generated text. In contrast, BLEU pays more attention to the precision rate of words, which can reflect the accuracy of the words used in the generated text. The BERTScore evaluation indicator is based on the pre-trained language model BERT. It characterizes the quality level of the generated text by calculating the cosine similarity between the generated text and the real text in the hidden layer representation of the BERT model. The BERTScore indicator can capture semantic information rather than being limited to the words themselves. Gscore is a comprehensive indicator for evaluating the text generation ability of Chinese language models, which can reflect the overall expression quality of generated texts. It is obtained by weighting four indicators: ROUGE-2, chrF, BLEU-2, and BERT score, with the weights of the four indicators being 25%, 20%, 25%, and 30%, respectively. Scheme 1 only uses a general large language model for text generation; Scheme 2 adds a vector-based retrieval enhancement module on this basis; Scheme 3 adds a keyword-based retrieval enhancement module on the basis of Scheme 1; Scheme 4 introduces two retrieval enhancement methods, vector and keyword; Scheme 5 performs external knowledge retrieval through knowledge graph; Scheme 6 adds a vector retrieval enhancement module on the basis of Scheme 5; Scheme 7 adds a keyword retrieval enhancement module on the basis of Scheme 5; Scheme 8 uses three retrieval enhancement methods, vector, keyword, and knowledge graph, at the same time; Scheme 9 fine-tunes the general large language model in a vertical field; Scheme 10 is the method of the present invention, which combines three retrieval enhancement methods with field fine-tuning. The ablation experiment results are shown in Table 2, from which it can be seen that the various indicators of the method of the present invention are better than the other 9 ablation schemes, reflecting the effectiveness of the method of this paper and the rationality of the module combination.

[0103] Table 2

[0104]

[0105] This embodiment provides a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implements the method for generating content of standardized files of specialty agricultural products based on knowledge retrieval enhancement.

[0106] This embodiment also provides an electronic device, including: one or more processors; a memory for storing one or more programs; when the one or more programs are executed by the one or more processors, the one or more processors implement the method for generating standardized file content of specialty agricultural products based on knowledge retrieval enhancement.

[0107] The invention described above only expresses the implementation methods of the embodiments of the present invention, and cannot be understood as limiting the scope of the invention patent, nor does it impose any form of limitation on the structure of the embodiments of the present invention. It should be pointed out that for ordinary technicians in this field, several changes and improvements can be made without departing from the concept of the embodiments of the present invention, which all belong to the protection scope of the embodiments of the present invention.

Claims

1. A method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement, characterized in that: Here are the steps: Step 1: Collect standardized files in PDF format through crawlers, then use PDF parsing methods to extract the content of standardized files and split them into text blocks to form a data set; Step 2: Embed the text block into vector form and store it in the vector database, then extract the entities and the relationships between entities from the text data and store the entities and relationships in the graph database; Step 3: Fine-tune the large language model in the vertical field of the dataset and perform structured pruning to remove redundant parameters; Step 4: Obtain the original user input and perform keyword decomposition and terminology standardization on the original user input to eliminate ambiguous input and form the final user input; Step 5: Combine vector search, keyword search, and knowledge graph search to form a hybrid search enhancement method, which retrieves content related to user input from the vector database and graph database respectively; Step 6: Filter the retrieval results of the hybrid retrieval enhancement method, remove the retrieval results with weak relevance, and then build the prompt words of the large language model based on the retrieval results; Step 7: Input the prompt words into the large language model after vertical field fine-tuning and structural pruning, and the large language model generates standardized document-related content; In step 3, a low-rank adaptive fine-tuning method with dynamically adjustable rank size is used to fine-tune the parameters of the general large language model: first, the weight matrix of the original large language model is kept unchanged, and then a parallel bypass module with fine-tunable parameters is set for the module inside the large language model. The bypass module is decomposed into the product of two low-rank matrices, one for down-projection and the other for up-projection; a trainable gating unit is added between the up-projection matrix and the down-projection matrix. At this time, the bypass module is expressed as: ; in, Represents the input of the bypass module, z Represents the output of the bypass module, is the lower projection matrix, is the upper projection matrix, g It is a gate control unit; In the process of vertical domain fine-tuning, the parameters of the gating unit are adjusted through the proximal gradient descent optimization algorithm; then a soft threshold function is set to set the values ​​of the gating unit matrix that are less than the threshold to 0, and only retain the values ​​that are greater than the threshold, thereby obtaining a sparse representation of the matrix.

2. The method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement according to claim 1 is characterized in that: It adopts a multi-stage cascade structure, which consists of seven stages: query decomposition, routing selection, hybrid retrieval enhancement, result screening, composition of prompt words, input of large language model, and content generation; In the query decomposition stage, the original user input undergoes entity extraction, input decomposition, and terminology normalization; In the routing selection phase, the knowledge database will be selected based on the type of content generated by the user in the decomposition query phase; The hybrid search enhancement stage uses three different search methods in parallel: vector search, keyword search, and knowledge graph search. The knowledge graph search branch retrieves the substructure of the multimodal knowledge graph from the graph database. The vector search branch searches in the vector database based on the cosine similarity of word vectors. The keyword search branch also searches in the vector database, but unlike vector search, it uses keyword matching to search. In the result screening stage, the text blocks obtained by vector retrieval and the text blocks obtained by keyword retrieval will be combined through the inverse sorting algorithm to determine the unique result set; The knowledge graph substructure retrieved by the knowledge graph retrieval branch also needs to be filtered, and then the filtered subgraph is converted into the form of entity triples, which are used as the context in the prompt word together with the text block retrieved and filtered from the vector database; In the stage of forming prompt words, a quality inspection module is set for the prompt words. If the prompt words fail to pass the quality inspection on relevance, the route selection will be changed, and the hybrid retrieval enhancement stage and the result screening stage will be re-executed. Only if the prompt words pass the quality inspection will they be sent to the large language model to provide external knowledge for them. In the content generation stage, the large language model combines the prompt words to generate corresponding content and feeds it back to the user.

3. The method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement according to claim 1 is characterized in that: The process of building a vector database is as follows: first, standard files in PDF format of specialty agricultural products and related information are collected from relevant websites through crawlers; then, the content of unstructured files is extracted through PDF parsing and divided into text blocks to form a data set; the text blocks are converted into vector form through a pre-trained word embedding model and stored in the vector database.

4. The method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement according to claim 3 is characterized in that: The leaf nodes in level 4 represent the numbers of specific text blocks, reflecting the fine-grained association of texts; level 3 is the clustering node, reflecting the similarity of texts in semantic and content features, which is the medium-grained association; level 2 is the super-clustering node, reflecting the similarity of texts in topics, which is the coarse-grained association, and level 1 is the root node of the tree.

5. The method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement according to claim 1 is characterized in that: Extract entities and relationships between entities from text data and store the entities and relationships in a graph database, including: extracting content from an unstructured corpus obtained by parsing standardized documents, including text, tables, and pictures, and building a multimodal knowledge graph for a vertical field. The multimodal knowledge graph contains three types of nodes: text nodes, table nodes, and picture nodes. There are two types of edges between nodes: semantic relationships and structural relationships.

6. The method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement according to claim 5 is characterized in that: Multimodal Knowledge Graph Using Directed Graphs Indicates that is a collection of entities, is a collection of relations, is a collection of entity attributes, is a collection of attribute values; It is a set of attribute triples, which is used to describe various attribute information of an entity; Represents a set of entity triples, expressed as: ; in, is the set of all relations in the multimodal knowledge graph, Represents a collection of text entities, It is a collection of two modal data: tables and pictures.

7. The method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement according to claim 1 is characterized in that: Vector search searches for relevant text blocks in a tree structure in a breadth-first manner; Keyword search requires first establishing an inverted index of the text block, and then using the BM25 algorithm to filter; for the text blocks obtained by vector search and keyword search, a unique result set is obtained from two result sets with different relevance indicators through a reciprocal sorting fusion algorithm.

8. The method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement according to claim 1 is characterized in that: The process of vertical field fine-tuning is expressed by the following formula: ; in Indicates t The value of the gating unit matrix at the iteration, is the value of the door unit matrix at the next iteration; is the loss function of the bypass module, express g In the t The gradient of the loss function at the iteration; It is t The learning rate at the iteration, is a hyperparameter of the regularization strength, which is used to control the sparsity of the gate unit matrix; Represents the soft threshold function, and the function expression is: ; Threshold Corresponding to the previous formula ; Then filter out the elements with a value of 0 in the gate control unit matrix i And form a collection , this process is expressed as: ; in m is the bypass module number, is the maximum rank initially set, Indicates the number m The gate control unit matrix i The value of the column; finally, according to the collection The two projection matrices are clipped and the lower projection matrix of the mth bypass module is No. The row is removed, and the upper projection matrix of the mth bypass module is No. The columns are removed to obtain two new projection matrices with smaller ranks, and the elements with zero are also removed for the gating unit.

9. The method for generating content of standardized documents of characteristic agricultural products based on knowledge retrieval enhancement according to claim 1 is characterized in that: In step three, the weights and gradients of the LoRA module are used as approximate values ​​of the weights and gradients of the pre-trained module to evaluate the importance of the pre-trained module and perform structured pruning.

Citation Information

Patent Citations

  • NLP knowledge graph construction method combining information amount and BERT-BiLSTM-CRF

    CN114817454A

  • Knowledge graph-based fuzzy matching method and apparatus, computer device, and storage medium

    WO2022142027A1

Cited By

  • Unmanned production field planting harvesting consistency adjusting and optimizing system based on hybrid large language model and quantitative model

    CN121581274A