A fine-tuning corpus generation method, system and storage medium

By parsing the GQL code blocks and position information in the graph database manual, performing verification and serialization, a high-quality GQL fine-tuning corpus is formed, and incremental updates are performed when the version is updated, solving the syntax and syntax generated by GQL in the existing technology. It solves the problem of semantic errors, improves the quality of corpus and production efficiency, and reduces maintenance costs.

CN118377940BActive Publication Date: 2024-09-10HANGZHOU ZHITONGFU TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410828410.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-25
Publication Date
2024-09-10
Estimated Expiration
2044-06-25

AI Technical Summary

Technical Problem

It is difficult to directly generate a graph query language GQL that is both syntactically and semantically correct with existing technology, and traditional manual annotation of fine-tuned corpus is expensive and inefficient, which limits the application of Text-to-GQL.

Method used

By converting the graph database product manual into a preset format, extracting GQL code blocks and their location meta-information, performing correctness verification and serialization, a fine-tuned data set is formed, and incremental updates are performed when the version is updated, and automatic construction and maintenance are performed. High-quality GQL fine-tuning corpus.

Benefits of technology

It significantly improves the quality and production efficiency of GQL fine-tuning corpus, reduces the dependence on the private source code of graph database manufacturers and the maintenance costs caused by data source changes, and improves the iteration ability to adapt to versions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118377940B
    Figure CN118377940B
Patent Text Reader

Abstract

The present invention discloses a method, system and storage medium for generating fine-tuning corpus. The method uses the text paragraphs where each GQL code block in the graph database product manual is located as the seed text, constructs a first triple data set including GQL statements in various sub-texts, text explanations corresponding to the GQL statements, and position meta-information, performs a correctness check on the GQL statements in the first triple data set, and then serializes them in a format preset by a target language model to form a first fine-tuning data set. Finally, after the product manual version is updated, the position meta-information is compared to identify the changed text paragraphs, delete some triples corresponding to the changed text paragraphs from the first fine-tuning data set, parse the changed text paragraphs to obtain the modified triple update data, and perform a correctness check on the modified triple update data. Finally, newly added triple data is formed and added to the first fine-tuning data set to form a second fine-tuning data set, so as to complete the automatic generation of GQL fine-tuning corpus.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a fine-tuning corpus generation method, system and storage medium. Background Art

[0002] In recent years, large language models (LLMs) such as ChatGPT have demonstrated significant capabilities in human-computer interaction. For example, text-to-SQL technology greatly simplifies the process of building SQL queries for business analysts and data developers. Users only need to enter natural language descriptions, and Text-to-SQL can automatically generate corresponding SQL statements. On the standard test set SPIDER, the accuracy of Text-to-SQL has exceeded 90%, surpassing most non-professional engineers.

[0003] However, as a special NoSQL database, graph database uses a special query language GQL that is different from SQL. Because different graph database products have not yet completed the adaptation of GQL, the GQL voices used by various manufacturers are similar in style, but there are still significant differences in syntax. Even the latest models such as GPT-4 or Cluade3 are difficult to directly generate GQL that is correct in both semantics and syntax, which brings inconvenience to users and makes it impossible to achieve high-accuracy direct GQL generation. In addition, in many scenarios, users want to privately deploy tens of billions of LLMs while maintaining a small number of parameters and capabilities, which makes Text-to-GQL an urgent problem to be solved. Experiments show that tens of billions of open source LLMs have professional knowledge in the field of graph databases and can generate Cypher / GQL with roughly correct semantics. However, these Cypher / GQLs often have many defects in syntax, so fine-tuning is a feasible solution. Fine-tuning is a secondary training for specific tasks based on the pre-trained model. By introducing new training data, LLMs produce high-quality output in a specific format or field. However, the traditional method of manually annotating and fine-tuning corpus is costly and inefficient, which limits the application of fine-tuning in Text-to-GQL. Summary of the invention

[0004] In view of the deficiencies in the prior art, the present invention discloses a method for generating fine-tuning corpus, which is used to generate fine-tuning corpus of a graph query language GQL through a graph database product manual, comprising the following steps:

[0005] S1. Convert the graph database product manual into a manual document in a preset format and then parse it, obtain the text paragraph where each GQL code block in the manual document is located as the seed text, extract the GQL statements in various sub-texts, the text explanations corresponding to the GQL statements, and the position meta information to form a first triple data set, where the position meta information is the text position information of the seed text in the manual document;

[0006] S2, performing a correctness check on the GQL statements in the first triple data set to form a second triple data set, wherein the correctness check is configured to remove erroneous GQL statements that cannot be executed in the triple data set and the corresponding text explanations and position meta-information, and serialize the second triple data set according to a format preset by the target language model to form a first fine-tuning data set;

[0007] S3. After monitoring that the graph database product manual has been updated, compare the location metadata of the updated version with the base version that serves as the data source of the first fine-tuning dataset to identify the changed text paragraphs; delete some triples corresponding to the changed text paragraphs from the first fine-tuning dataset, parse the changed text paragraphs and obtain the modified triple update data, perform correctness verification on the GQL statements in the triple update data to form newly added triple data, and add the newly added triple data to the first fine-tuning dataset to form a second fine-tuning dataset as the updated fine-tuning corpus.

[0008] Preferably, the step S1 specifically includes: saving the acquired graph database product manual as a manual document in HTML format to be analyzed and parsing it, using regular expressions to match and extract each GQL code block in the manual document, extracting the document location meta-information where the GQL code block is located, the location meta-information including but not limited to the file name, chapter titles at various levels, or paragraph numbers; extracting contextual auxiliary text containing natural language interpretations that is adjacent to the GQL code block in the seed text as auxiliary information for obtaining the text interpretation corresponding to the GQL statement.

[0009] Preferably, extracting text interpretations corresponding to GQL statements in various sub-texts specifically includes: after assembling the GQL code, the corresponding position meta-information and the contextual auxiliary text into a prompt text, calling the first language model multiple times to obtain multiple text interpretations in response to the prompt text; performing text embedding on the text interpretation returned by each call, calculating the average value of the embedding vectors of all returned texts, and selecting the embedding vector closest to the average embedding vector and its corresponding text interpretation as the corresponding text interpretation of the GQL code.

[0010] Preferably, step S3 specifically includes: if some GQL statements in the basic version serving as the data source of the first fine-tuning dataset are deleted in the updated version, then the text paragraphs where the GQL code blocks in the manual document of the updated version are located are obtained as seed texts, and the GQL statements in various sub-texts, the text explanations corresponding to the GQL statements, and the position meta-information are extracted to form a third triple data set; the triple data corresponding to the deleted GQL statements are obtained and error syntax annotations are added to form discarded triple data; the GQL statements in the third triple data set are correctness-checked to form a fourth triple data set, and after adding the discarded triple data to the fourth triple data set, the discarded triple data are serialized according to the format preset by the target language model to form the second fine-tuning dataset.

[0011] Preferably, step S3 also includes: after monitoring that the graph database product manual has been updated, comparing the positional metadata of the updated version with the base version that serves as the data source of the first fine-tuning dataset; comparing the positional metadata of various sub-texts in the two versions of the manual documents, and obtaining the associated texts of the two seed texts currently being compared based on the reference relationship of the GQL statements contained therein; if the seed text or the corresponding associated text of this comparison has changed, deleting some triples of the corresponding changed seed text and associated text from the first fine-tuning dataset, parsing the changed seed text and associated text and obtaining modified triple update data, performing correctness verification on the GQL statements in the triple update data to form newly added triple data, and adding the newly added triple data to the first fine-tuning dataset to form a second fine-tuning dataset as the updated fine-tuning corpus.

[0012] The present invention also discloses a fine-tuning corpus generation system, which is used to generate fine-tuning corpus of graph query language GQL through graph database product manual, including information extraction module, sentence verification module and incremental generation module, wherein the information extraction module is used to convert the graph database product manual into a manual document of a preset format and then parse it, obtain the text paragraph where each GQL code block in the manual document is located as the seed text, extract the GQL statements in various sub-texts, the text explanations corresponding to the GQL statements, and the position meta-information to form a first triple data set, and the position meta-information is the text position information of the seed text in the manual document; the sentence verification module is used to form a second triple data set after performing correctness verification on the GQL statements in the first triple data set, and the correctness verification is configured to eliminate the triple data set The module detects the erroneous GQL statements that cannot be executed and the corresponding text explanations and positional meta-information in the graph database product manual, and serializes the second triple data set in the format preset by the target language model to form a first fine-tuning data set; an incremental generation module is used to compare the positional meta-information of the updated version with the basic version that is the data source of the first fine-tuning data set after monitoring that the graph database product manual has been updated, and identify the changed text paragraphs; delete some triples corresponding to the changed text paragraphs from the first fine-tuning data set, parse the changed text paragraphs and obtain the modified triple update data, and form newly added triple data after correctness verification of the GQL statements in the triple update data, and add the newly added triple data to the first fine-tuning data set to form a second fine-tuning data set as the updated fine-tuning corpus.

[0013] Preferably, the information extraction module specifically includes a meta-information extraction module and an auxiliary information extraction module, wherein the meta-information extraction module is used to save the acquired graph database product manual as a manual document in HTML format to be analyzed and parse it, use regular expressions to match and extract each GQL code block in the manual document, and extract the document location meta-information where the GQL code block is located, and the location meta-information includes but is not limited to the file name, chapter titles at all levels, or paragraph numbers; the auxiliary information extraction module is used to extract contextual auxiliary text containing natural language interpretations that is adjacent to the GQL code block in the seed text as auxiliary information for obtaining the text interpretation corresponding to the GQL statement.

[0014] Preferably, the information extraction module also includes a text acquisition module and a text selection module, wherein the text acquisition module is used to assemble the GQL code, the corresponding location meta-information and the context auxiliary text into a prompt text, and then call the first language model multiple times to obtain multiple text interpretations in response to the prompt text; the text selection module is used to perform text embedding on the text interpretation returned by each call, calculate the average value of the embedding vectors of all returned texts, and select the embedding vector closest to the average embedding vector and its corresponding text interpretation as the corresponding text interpretation of the GQL code.

[0015] The present invention also discloses a server, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of any of the above-mentioned methods for fine-tuning corpus generation are implemented.

[0016] The present invention also discloses a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any of the above-mentioned methods for fine-tuning corpus generation are performed.

[0017] The present invention discloses a method, system and storage medium for generating fine-tuning corpus. When constructing the fine-tuning corpus for the first time, the first triple data group is formed by parsing each GQL statement, the corresponding text interpretation and position meta-information in the graph database document, and a fine-tuning data set is generated after the correctness of the GQL statement is verified. Then, when receiving a new version of the graph database document, the triple data corresponding to the changed text paragraph is deleted and the new triple data is reconstructed and verified by comparing the position meta-information of different versions, and a new fine-tuning data set for updating the original fine-tuning corpus is generated, so as to realize automatic construction and maintenance of high-quality GOL fine-tuning corpus. Thus, public resources are fully utilized, the corpus quality and production efficiency of the GQL fine-tuning corpus are significantly improved, the dependence on the private source code of the graph database manufacturer and the maintenance cost caused by the change of the data source are reduced, and the iteration capability of the adaptive version is improved.

[0018] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0020] Figure 1 The figure is a schematic diagram of the steps of a method for generating fine-tuned corpus disclosed in an embodiment of the present invention.

[0021] Figure 2 This is a schematic diagram of specific steps of step S1 disclosed in one embodiment of the present invention.

[0022] Figure 3 This is another specific step diagram of step S1 disclosed in one embodiment of the present invention.

[0023] Figure 4 The figure is a schematic diagram of steps for handling a situation in which the GQL grammar is abandoned in a new version according to an embodiment of the present invention.

[0024] Figure 5 A schematic diagram of the steps for processing implicit dependency relationships disclosed in one embodiment of the present invention.

[0025] Figure 6 It is a structural block diagram of a fine-tuning corpus generation system disclosed in another embodiment of the present invention. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical solution and advantages of the embodiment of the present invention clearer, the technical solution of the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings of the embodiment of the present invention. Obviously, the described embodiment is a part of the embodiment of the present invention, not all of the embodiments. Based on the described embodiment of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0027] Unless otherwise defined, the technical or scientific terms used herein shall have the common meanings understood by persons with ordinary skills in the field to which the present invention belongs. The words "first", "second" and similar words used in the patent application specification and claims of the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, words such as "one" or "an" do not indicate quantity restrictions, but indicate the existence of at least one.

[0028] This embodiment discloses a method for generating fine-tuning corpus, which is used to generate fine-tuning corpus of graph query language GQL through graph database product manual, as shown in the attached Figure 1 As shown, the following steps are included.

[0029] Step S1, converting the graph database product manual into a manual document in a preset format and then parsing it, obtaining the text paragraph where each GQL code block in the manual document is located as the seed text, extracting the GQL statements in various sub-texts, the text explanations corresponding to the GQL statements, and the position meta-information to form a first triplet data set, wherein the position meta-information is the text position information of the seed text in the manual document.

[0030] This embodiment takes the query language nGQL of the graph database Nebula Graph as an example to illustrate the fine-tuning corpus generation method. nGQL is a dialect of Cypher / GQL, and the product manual is written in Markdown format, which has many incompatibilities with standard Cypher. This embodiment selects the official manual page of the most important Match statement in nGQL as the data source for corpus generation, and accurately extracts various sub-texts in the manual document according to Markdown syntax rules such as title levels and code block tags. The seed text contains GQL statements and the non-processed text interpretation and position meta-information corresponding to the GQL statements, as shown in the attached figure. Figure 2 As shown, the step S1 specifically includes the following contents.

[0031] Step S101, save the acquired graph database product manual as a manual document in HTML format to be analyzed and parse it, use regular expressions to match and extract each GQL code block in the manual document, and extract the document location meta information where the GQL code block is located, and the location meta information includes but is not limited to the file name, chapter titles at all levels, or paragraph numbers.

[0032] Specifically, each GQL code block and position meta information in the seed text is extracted through regular expressions to ensure the correctness, completeness and executableness of the extracted GQL statements, avoiding the errors and uncertainties introduced when extracting through traditional large language models. At the same time, the extraction of position meta information can facilitate the subsequent tracing of the source of the GQL corpus. For example, locate the text paragraph corresponding to the GQL statement, and then extract the first-level, second-level, third-level, etc. title text starting with "#" above it as the title of each chapter. In other embodiments, common techniques such as lexical analysis can also be used to extract GQL code blocks and their position meta information.

[0033] In this embodiment, a preliminary judgment can also be made on the executableness of the extracted GQL code blocks, specifically including: sending each extracted GQL code block to the graph database and judging whether it is executable; if not, deleting the GQL code block and its corresponding location metadata and auxiliary information.

[0034] Step S102: extract contextual auxiliary text containing natural language explanations that is adjacent to the GQL code block in the seed text as auxiliary information for obtaining textual explanations corresponding to the GQL statement.

[0035] Extract the unprocessed text interpretation corresponding to the GQL statement in the seed text, and obtain the final text interpretation corresponding to the GQL statement. The unprocessed text interpretation is the natural language interpretation text of the adjacent context of the GQL code block, which can be used as auxiliary information for understanding the semantics of GQL and help better understand and use GQL statements.

[0036] In this embodiment, the text explanations corresponding to the GQL statements in various sub-texts are extracted as shown in the attached figure. Figure 3 As shown, the specific contents include the following.

[0037] Step S201, after assembling the GQL code, the corresponding location meta information and the context auxiliary text into a prompt text, the first language model is called multiple times to obtain multiple text interpretations for the prompt text reply.

[0038] Step S202, text embedding is performed for the text interpretation returned by each call, the average value of the embedding vectors of all returned texts is calculated, and the embedding vector closest to the average embedding vector and its corresponding text interpretation are selected as the corresponding text interpretation of the GQL code.

[0039] Specifically, the text interpretation corresponding to the GQL sentence is obtained through a large language model, which includes but is not limited to GPT-3.5, Qwen or GPT-4, etc., and the embedding technology includes but is not limited to BERT, BAAI or Hugging Face, etc. Among them, due to the low accuracy of the single return result of models such as Qwen and GPT-3.5, and the result of a single large language model call is not necessarily reliable, multiple calls are made to improve the credibility of the processing.

[0040] Among them, the few-shot learning paradigm is adopted to provide a small number of high-quality examples as part of the prompt text to the first language model to guide it to generate the desired results. According to experience and literature, selecting 5 typical examples written by experts can usually achieve good results. In practice, representative seed texts covering major grammars and key concepts can be selected from the original documents by combining heuristic rules and manual screening, and then transcribed into corresponding GQL fragments by experts to form a few-shot example set.

[0041] After obtaining the textual interpretation corresponding to the GQL code, the GQL code, its corresponding GQL textual interpretation and position meta-information are concatenated according to a preset triple structure to form a first triple data set.

[0042] Step S2: performing a correctness check on the GQL statements in the first triple data set to form a second triple data set, wherein the correctness check is configured to remove erroneous GQL statements that cannot be executed in the triple data set and the corresponding text explanations and position meta-information, and serialize the second triple data set in a format preset by the target language model to form a first fine-tuning data set.

[0043] In this embodiment, the correctness check includes the following contents.

[0044] Step S401: Input each triple data in the first triple data set into multiple second language models to determine whether the GQL text interpretation is correct to obtain multiple judgment results. The second language model generally adopts a large language model with strong capabilities such as GPT4 or Claude3Opus.

[0045] Step S402: Count and vote on the multiple judgment results, and take the result with the most votes as the final judgment result. Different results can be marked with different colors in the interactive interface to facilitate subsequent review and inspection.

[0046] Step S403, experts manually review the obtained discrimination results, and remove the triple data with incorrect review results from the first triple data set to form a second triple data set. Two or more experts are used to manually review the data with incorrect model discrimination results, and one expert is used to manually review the data with correct model discrimination results, so as to reduce the error rate of the data set.

[0047] The data in the second triple data group are sorted according to a preset format such as jsonl to obtain the initially constructed fine-tuning corpus, that is, the first fine-tuning data set.

[0048] Step S3, after monitoring that the graph database product manual has been updated, compare the location metadata of the updated version with the basic version that serves as the data source of the first fine-tuning dataset to identify the changed text paragraphs; delete some triples corresponding to the changed text paragraphs from the first fine-tuning dataset, parse the changed text paragraphs and obtain the modified triple update data, perform correctness verification on the GQL statements in the triple update data to form newly added triple data, and add the newly added triple data to the first fine-tuning dataset to form a second fine-tuning dataset as the updated fine-tuning corpus.

[0049] Specifically, after the first construction of the fine-tuning corpus dataset, the version of the graph database is monitored in real time. After the version is updated, the corpus is maintained and updated in a timely manner, the changed triples are deleted, and the triple data of the changed text paragraphs are reconstructed and the correctness is verified, so as to reduce the maintenance cost caused by the change of data source.

[0050] In this embodiment, it may be possible that a certain GQL syntax is abandoned in the new version, then step S3 is as shown in the attached Figure 4 As shown, it also includes the following contents.

[0051] Step S501: If some GQL statements in the basic version that serves as the data source of the first fine-tuning dataset are deleted in the updated version, the text paragraphs containing the GQL code blocks in the manual document of the updated version are obtained as seed texts, and the GQL statements in various sub-texts, the text explanations corresponding to the GQL statements, and the position metadata are extracted to form a third triplet dataset.

[0052] Step S502, obtaining triple data corresponding to the deleted GQL statement and adding an error syntax annotation to form discarded triple data.

[0053] Step S503, after correctness verification of the GQL statements in the third triple data set is performed to form a fourth triple data set, after discarded triple data is added to the fourth triple data set, serialization is performed according to a format preset by the target language model to form a second fine-tuning data set.

[0054] Specifically, when a certain GQL syntax is deprecated in a new version, since the large language model fine-tuning process usually does not support the deletion of learned knowledge, it is necessary to return to the full generation mode to rebuild the corpus and clearly mark the deprecated syntax as an error in the forecast to avoid participating in subsequent fine-tuning.

[0055] In this embodiment, the graph database product may also have implicit dependencies during the version evolution process, so step S3 is as shown in the attached Figure 5 As shown, the specific contents also include the following.

[0056] Step S601, after monitoring that the graph database product manual has been updated, compare the location metadata of the updated version with the basic version that is the data source of the first fine-tuning dataset.

[0057] Specifically, some implicit dependencies may appear in graph database products during the version evolution process. For example, a GQL statement uses a variable or function defined in the old version, and these definitions have changed in the new version. Simply comparing the GQL statements themselves cannot detect such changes, and it is necessary to analyze the context in which they are located. After comparing the meta information of the target paragraph itself, it is also necessary to trace the contextual meta information of the chapters, sub-chapter and other levels in which it is located.

[0058] Step S602 : compare the location meta information of various sub-texts in the two versions of the manual documents, and obtain the associated texts of the two sub-texts currently being compared according to the reference relationship of the GQL statements contained therein.

[0059] Specifically, the associated text is the paragraph text that forms a context with the target paragraph within the chapter, sub-chapter, etc. level where the target paragraph is located.

[0060] Step S603: If the seed text or the corresponding associated text for this comparison is changed, some triples of the corresponding changed seed text and associated text are deleted from the first fine-tuning dataset, and the changed seed text and associated text are parsed to obtain modified triple update data, and the GQL statements in the triple update data are corrected to form newly added triple data, and the newly added triple data are added to the first fine-tuning dataset to form a second fine-tuning dataset as the updated fine-tuning corpus.

[0061] Specifically, if the contextual meta-information is found to have changed, even if the target paragraph has not changed, it should be marked as a "potential change" and the triples corresponding to the changed paragraph and the "potential change" paragraph should be deleted to avoid legacy errors caused by implicit dependencies.

[0062] In this embodiment, during the iteration process of the graph database product, it is possible that the GQL statement text remains unchanged but its semantics changes. In this case, step S3 also includes the following content.

[0063] Step S701, after monitoring that the graph database product manual is updated, compare the location metadata of the updated version with the basic version that is the data source of the first fine-tuning dataset.

[0064] Step S702, obtain the target triplet corresponding to the changed text paragraph, input the GQL statement in the target triplet into the two versions of the graph database, and compare the two execution results.

[0065] Step S703: If the execution result is inconsistent, the target triple is deleted from the first fine-tuning data set, and the changed text paragraph is parsed to obtain the modified triple update data, and the GQL statement in the triple update data is corrected to form new triple data, and the new triple data is added to the first fine-tuning data set to form a second fine-tuning data set as the updated fine-tuning corpus.

[0066] Specifically, due to changes in the underlying storage, indexing, and algorithm mechanisms, the text of the GQL statement may remain unchanged, but its semantics may change during the iteration of the graph database product. For example, the return result of a certain aggregation function has added deduplication processing in the new version, or the default strategy of graph traversal has been changed from depth-first to breadth-first. Such changes will not be reflected in the GQL text representation, and it is difficult to detect simply by comparing the text. Therefore, the situation is judged by directly comparing the execution results of the GQL statements in the two versions of the graph database, while keeping the fine-tuning corpus consistent with the actual execution semantics.

[0067] In another embodiment, taking the graph database product Neo4j as an example, the process of automatically generating a fine-tuning corpus of the Cypher query language based on its official manual is demonstrated, which specifically includes the following contents.

[0068] Obtain all versions of product manuals from the Neo4j official website and save them as HTML documents. This example selects the Neo4j 5.x manual as the data source.

[0069] Use Python's BeautifulSoup library to parse HTML documents and extract paragraphs in plain text and their meta-location information, including document title, URL, etc. Specifically, filter out irrelevant text such as navigation menus and copyright statements, and only keep the main text.

[0070] Heuristic rules are used to preliminarily screen paragraphs, extract paragraphs containing Cypher keywords as candidates, and use a lightweight binary classification model to score and sort the candidate paragraphs, and select the top K high-scoring paragraphs as seed texts. In this embodiment, K=1000.

[0071] Use OpenAI's text-davinci-003 model to infer each seed text and use Anthropic's Claude3 model to preliminarily screen the triple data. Serialize the triple data that pass the correctness check in jsonl format. Each line of the formatted triple data represents a sample. The text-davinci-003 model is close to GPT-3.5 performance, and the Claude3 model is comparable to GPT-4 performance.

[0072] So far, a high-quality Cypher fine-tuning dataset has been automatically generated from the Neo4j official manual, which contains Cypher examples that fully cover syntax and semantics, and the natural language expressions that accurately correspond to them. This dataset can be directly used to fine-tune LLMs such as GPT-3.5, thereby obtaining an efficient and accurate end-to-end text2Cypher system. By regularly crawling the official manual and incrementally updating the dataset, the system's adaptability to new versions of Cypher can be continuously improved.

[0073] Finally, the intelligent question-answering system is deployed on the enterprise intranet for business personnel to use. This embodiment introduces in detail the process of using the graph database product manual to build a comprehensive, accurate, and up-to-date GQL fine-tuning corpus, which not only avoids the dependence on commercial source code, but also overcomes the inefficiency and high cost of manual corpus construction, achieving a truly out-of-the-box, plug-and-play text2GQL solution.

[0074] The present invention is not strongly coupled with specific LLM and fine-tuning algorithms. During implementation, appropriate LLM and fine-tuning frameworks can be selected according to actual conditions to achieve an optimal balance between effect and cost.

[0075] In addition, the corpus generation method of the present invention is not only applicable to graph database product manuals, but also to the GQL knowledge base accumulated within the enterprise. The knowledge base usually contains GQL logic unique to business scenarios, which is another very valuable source of corpus. Applying this method to the knowledge base can quickly build a customized text2GQL model for a specific business field, greatly improving the development efficiency in practical applications.

[0076] The present invention discloses a method, system and storage medium for generating fine-tuning corpus. When constructing the fine-tuning corpus for the first time, a first triple data group is formed by parsing each GQL statement, the corresponding text interpretation and position metadata in a graph database document, and a fine-tuning data set is generated after the correctness of the GQL statement is verified. Then, when a new version of the graph database document is received, the triple data corresponding to the changed text paragraph is deleted and the new triple data is reconstructed and verified by comparing the position metadata of different versions, so as to generate an incremental fine-tuning data set, so as to automatically construct and maintain high-quality GOL fine-tuning corpus, significantly improve the production efficiency of GQL fine-tuning corpus, reduce the dependence on the graph database source code and the maintenance cost caused by the change of data source, and improve the iteration capability of adapting to versions.

[0077] In another embodiment, as shown in the attached Figure 6As shown, the present invention also discloses a fine-tuning corpus generation system, which is used to generate fine-tuning corpus of graph query language GQL through graph database product manual, including information extraction module 1, statement verification module 2 and incremental generation module 3. The information extraction module 1 is used to convert the graph database product manual into a manual document in a preset format and then parse it, obtain the text paragraph where each GQL code block in the manual document is located as the seed text, extract the GQL statements in various sub-texts, the text interpretation corresponding to the GQL statements, and the position meta-information to form a first triple data set, and the position meta-information is the text position information of the seed text in the manual document. The statement verification module 2 is used to perform a correctness check on the GQL statements in the first triple data set to form a second triple data set, and the correctness check is configured to remove the erroneous GQL statements and the corresponding text interpretation and position meta-information that cannot be executed in the triple data set, and the second triple data set is serialized according to the preset format of the target language model to form the first fine-tuning data set. The incremental generation module 3 is used to compare the position metadata of the updated version with the basic version that serves as the data source of the first fine-tuning dataset after monitoring that the graph database product manual has been updated, and identify the changed text paragraphs; delete some triples corresponding to the changed text paragraphs from the first fine-tuning dataset, parse the changed text paragraphs and obtain the modified triple update data, perform correctness verification on the GQL statements in the triple update data to form newly added triple data, and add the newly added triple data to the first fine-tuning dataset to form a second fine-tuning dataset as the updated fine-tuning corpus.

[0078] In this embodiment, the information extraction module 1 specifically includes a meta-information extraction module and an auxiliary information extraction module, wherein the meta-information extraction module is used to save the acquired graph database product manual as a manual document in HTML format to be analyzed and parse it, use regular expressions to match and extract each GQL code block in the manual document, and extract the document location meta-information where the GQL code block is located, and the location meta-information includes but is not limited to the file name, chapter titles at all levels, or paragraph numbers; the auxiliary information extraction module is used to extract contextual auxiliary text containing natural language interpretations that is adjacent to the GQL code block in the seed text as auxiliary information for obtaining the text interpretation corresponding to the GQL statement.

[0079] In this embodiment, text interpretations corresponding to GQL statements in various sub-texts are extracted, specifically including a text acquisition module and a text selection module, wherein the text acquisition module is used to assemble the GQL code, the corresponding position meta-information and the context auxiliary text into a prompt text, and then call the first language model multiple times to obtain multiple text interpretations for the prompt text reply; the text selection module is used to perform text embedding on the text interpretation returned by each call, calculate the average value of the embedding vectors of all returned texts, and select the embedding vector closest to the average embedding vector and its corresponding text interpretation as the corresponding text interpretation of the GQL code.

[0080] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and similar parts between the various embodiments can be referred to each other. For the fine-tuning corpus generation device disclosed in the embodiment, since it corresponds to the fine-tuning corpus generation method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the aforementioned method part.

[0081] In other embodiments, a server is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the various steps of the fine-tuning corpus generation method described in the above embodiments when executing the computer program. The server may include, but is not limited to, a processor and a memory. It will be understood by those skilled in the art that the schematic diagram is merely an example of a server and does not constitute a limitation on the server, and may include more or fewer components than shown in the figure, or combine certain components, or different components.

[0082] If the fine-tuning corpus generation device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned fine-tuning corpus generation method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device that can carry the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory, random access memory, electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0083] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

[0084] In conclusion, the above is only a preferred embodiment of the present invention, and all equivalent changes and modifications made according to the scope of the patent application of the present invention should fall within the scope of the patent of the present invention.

Claims

1. A fine-tuning corpus generation method for generating fine-tuning corpus of graph query language GQL through graph database product manuals, It is characterized in that The steps include: S1. Convert the graph database product manual into a manual document in a preset format and then parse it, obtain the text paragraph where each GQL code block in the manual document is located as the seed text, extract the GQL statements in various sub-texts, the text explanations corresponding to the GQL statements, and the position meta-information to form a first triple data set, where the position meta-information is the text position information of the seed text in the manual document; extract the context auxiliary text containing the natural language explanation adjacent to the GQL code block in the seed text as the auxiliary information for obtaining the text explanation corresponding to the GQL statement; The extracting of text explanations corresponding to GQL statements in various sub-texts specifically includes: after assembling the GQL code, the corresponding position meta-information and the context auxiliary text into a prompt text, calling the first language model multiple times to obtain multiple text explanations for the prompt text response; performing text embedding on the text explanation returned by each call, calculating the average value of the embedding vectors of all returned texts, and selecting the embedding vector closest to the average embedding vector and its corresponding text explanation as the corresponding text explanation of the GQL code; S2, performing a correctness check on the GQL statements in the first triple data set to form a second triple data set, wherein the correctness check is configured to remove erroneous GQL statements that cannot be executed in the triple data set and the corresponding text explanations and position meta-information, and serialize the second triple data set according to a format preset by the target language model to form a first fine-tuning data set; S3. After monitoring that the graph database product manual has been updated, compare the location metadata of the updated version with the base version that is the data source of the first fine-tuning dataset to identify the changed text paragraphs; delete some triples corresponding to the changed text paragraphs from the first fine-tuning dataset, parse the changed text paragraphs and obtain the modified triple update data, perform a correctness check on the GQL statements in the triple update data to form newly added triple data, and add the newly added triple data to the first fine-tuning dataset to form a second fine-tuning dataset as the updated fine-tuning corpus; if the data of the first fine-tuning dataset is deleted in the updated version, For some GQL statements in the basic version of the source, the text paragraphs where the GQL code blocks in the manual document of the updated version are located are obtained as seed texts, and the GQL statements in various sub-texts, the text explanations corresponding to the GQL statements, and the position meta-information are extracted to form a third triple data set; the triple data corresponding to the deleted GQL statements are obtained and error syntax annotations are added to form discarded triple data; the GQL statements in the third triple data set are correctness-verified to form a fourth triple data set, and the discarded triple data are added to the fourth triple data set, and then serialized according to the format preset by the target language model to form a second fine-tuning data set.

2. The fine-tuning corpus generation method according to claim 1, It is characterized in that The step S1 specifically includes: The obtained graph database product manual is saved as a manual document in HTML format to be analyzed and parsed, and each GQL code block in the manual document is matched and extracted using regular expressions, and the document location meta information where the GQL code block is located is extracted, and the location meta information includes but is not limited to the file name, chapter titles at various levels, or paragraph numbers.

3. The fine-tuning corpus generation method according to claim 2, It is characterized in that The step S3 further comprises: After monitoring that the graph database product manual has been updated, the location metadata of the updated version is compared with the base version that is the data source of the first fine-tuning dataset; Compare the location meta information of various sub-texts in the two versions of the manual documents, and obtain the associated text of the two sub-texts currently being compared according to the reference relationship of the GQL statements contained therein; If the seed text or the corresponding associated text for this comparison changes, some triples of the corresponding changed seed text and associated text are deleted from the first fine-tuning dataset, and the changed seed text and associated text are parsed to obtain the modified triple update data, and the GQL statements in the triple update data are corrected to form new triple data, and the new triple data are added to the first fine-tuning dataset to form a second fine-tuning dataset as the updated fine-tuning corpus.

4. A fine-tuning corpus generation system for generating fine-tuning corpus of the graph query language GQL through the graph database product manual, It is characterized in that include: An information extraction module is used to convert the graph database product manual into a manual document in a preset format and then parse it, obtain the text paragraph where each GQL code block in the manual document is located as the seed text, extract the GQL statements in various sub-texts, the text explanations corresponding to the GQL statements, and the position meta information to form a first triple data set, where the position meta information is the text position information of the seed text in the manual document; The information extraction module specifically includes: an auxiliary information extraction module, which is used to extract contextual auxiliary text containing natural language interpretations that are adjacent to the GQL code block in the seed text as auxiliary information for obtaining the text interpretation corresponding to the GQL statement; a text acquisition module, which is used to assemble the GQL code, the corresponding position meta-information and the contextual auxiliary text into a prompt text, and then call the first language model multiple times to obtain multiple text interpretations for the prompt text reply; a text selection module, which is used to perform text embedding on the text interpretation returned by each call, calculate the average value of the embedding vectors of all returned texts, and select the embedding vector closest to the average embedding vector and its corresponding text interpretation as the corresponding text interpretation of the GQL code; a sentence verification module, configured to perform correctness verification on the GQL sentences in the first triple dataset to form a second triple dataset, wherein the correctness verification is configured to remove erroneous GQL sentences and corresponding text explanations and position meta-information that cannot be executed in the triple dataset, and to serialize the second triple dataset in a format preset by the target language model to form a first fine-tuning dataset; The incremental generation module is used to compare the location metadata of the updated version with the basic version as the data source of the first fine-tuning dataset after monitoring that the graph database product manual has been updated, and identify the changed text paragraphs; delete some triples corresponding to the changed text paragraphs from the first fine-tuning dataset, parse the changed text paragraphs and obtain the modified triple update data, and form new triple data after correctness verification of the GQL statements in the triple update data, and add the new triple data to the first fine-tuning dataset to form a second fine-tuning dataset as the updated fine-tuning corpus; if the triples used as the first fine-tuning data are deleted in the updated version, The method comprises the following steps: based on the method of claim 1, wherein the method comprises the following steps: first, obtaining some GQL statements in the basic version of the data source, obtaining the text paragraphs where the GQL code blocks in the manual document of the updated version are located as seed texts, extracting the GQL statements in various sub-texts, the text explanations corresponding to the GQL statements, and the position meta-information to form a third triple data set; obtaining the triple data corresponding to the deleted GQL statements and adding error grammar annotations to form discarded triple data; performing correctness verification on the GQL statements in the third triple data set to form a fourth triple data set, and adding the discarded triple data to the fourth triple data set to serialize the data in the format preset by the target language model to form a second fine-tuning data set.

5. The fine-tuning corpus generation system according to claim 4, It is characterized in that The information extraction module specifically includes: The metadata extraction module is used to save the acquired graph database product manual as a manual document in HTML format to be analyzed and parse it, use regular expressions to match and extract each GQL code block in the manual document, and extract the document location metadata where the GQL code block is located. The location metadata includes but is not limited to the file name, chapter titles at all levels, or paragraph numbers.

6. A server comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, Features: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 3 are implemented.

7. A computer-readable storage medium storing a computer program, Features: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 3 are implemented.