A GQL corpus generation model training method, device and storage medium
By extracting GQL statements and natural language description texts from the graph database product manual, combining large language models and equivalent transformation rules to generate GQL variant statements, and constructing an expanded corpus data set, it solves the difficulty of balancing quality and diversity in the construction of GQL corpus. problem, realizing the automatic expansion and quality improvement of GQL corpus, and reducing the cost of manual annotation.
Patent Information
- Application Number
- CN202410865642.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-01
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2044-07-01
AI Technical Summary
It is difficult to balance the quality and diversity of the corpus during the construction of the existing GQL corpus, resulting in the inability of AI-assisted technology to be fully optimized, and there are errors and omissions in manual annotation, which affects the quality of the corpus and system reliability, making it difficult to apply it to the development and optimization of graph databases.
By extracting the original GQL statements and their natural language description texts in the graph database product manual, combined with the large language model and equivalent transformation rules to generate GQL variant statements, construct a positive and negative sample data set, integrate it into an expanded corpus data set, and input the target GQL The corpus generation model is fine-tuned so that the model can generate corresponding GQL statements based on natural language description text.
It realizes the automatic expansion of GQL corpus, improves the richness and quality of the corpus, avoids negligence and differences in human annotation, reduces costs, and enhances the model's generation capability and application value.
Smart Images

Figure CN118410060B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular to a GQL corpus generation model training method, device and storage medium. Background Art
[0002] With the continuous development of big data and artificial intelligence technology, people are increasingly demanding the construction of GQL corpus, thanks to the excellent processing ability and high scalability of graph query language GQL (graph query language) for complex relationships in the process of graph database query. At present, most GQL corpus is obtained through manual design and annotation. Due to the scarcity of experts who master the principles of GQL and graph databases, as well as the rich expression ability of GQL, it is difficult to take into account the quality, diversity and scale of the corpus during the construction process. As a result, various AI-assisted technologies for GQL cannot be fully optimized and trained, which greatly reduces their effectiveness in practical applications and makes it difficult to truly provide valuable assistance to users.
[0003] At the same time, in the manual annotation process, errors and omissions caused by the annotator's negligence, annotation differences caused by the annotator's misunderstanding, omission of test cases due to the annotator's lack of understanding of certain grammatical boundary conditions, and incomplete coverage of certain implicit dependencies in artificial corpora will also cause the corpus quality to be unstable, affecting the reliability of GQL-related systems in subsequent training and testing, making it difficult to directly apply the current GQL corpus to actual graph database application development and optimization. Summary of the invention
[0004] In view of the deficiencies in the prior art, the present invention discloses a GQL corpus generation model training method, comprising the following steps:
[0005] S1, extract the matching pairs of each GQL original sentence and its corresponding natural language description text in the graph database product manual to build the initial corpus dataset;
[0006] S2, performing equivalent transformation on each GQL original sentence in the initial corpus dataset according to a preset equivalent transformation rule and in combination with a large language model, generating corresponding GQL variant sentences and constructing a variant corpus dataset;
[0007] S3, combining the initial corpus dataset and the variant corpus dataset to construct a positive and negative sample dataset including a plurality of positive and negative sample pairs, wherein the positive and negative sample pairs include positive sample pairs of matched GQL sentences and corresponding natural language description texts, and negative sample pairs of unmatched or randomly combined GQL sentences and corresponding natural language description texts;
[0008] S4, integrating the initial corpus dataset, the variant corpus dataset, and the constructed positive and negative sample datasets into an extended corpus dataset, and inputting the extended corpus dataset into the target GQL corpus generation model to fine-tune the model so that the target GQL corpus generation model can generate corresponding GQL sentences according to the input natural language description text.
[0009] Preferably, the equivalent transformation rules include but are not limited to connection condition rewriting rules, predicate reordering rules, synonym replacement rules, and variable renaming rules.
[0010] Preferably, the step S2 comprises:
[0011] S21, identifying transformable units of each GQL original sentence in the initial corpus data set, and generating equivalent transformation sentence groups corresponding to each GQL original sentence according to a preset equivalent transformation rule, wherein the transformable units include but are not limited to predicates and WHERE clauses;
[0012] S22, input each GQL original sentence and the corresponding equivalent transformation sentence group into the trained first language model, and score each equivalent transformation sentence in combination with a preset scoring function, and use the equivalent transformation sentence corresponding to the highest scoring result as the corresponding GQL transformation sentence.
[0013] Preferably, the loss function of the target GQL language model is configured as:
[0014] ;
[0015] in, For contrastive learning loss based on graph isomorphism:
[0016] ;
[0017] For the contrastive learning loss based on relational paths:
[0018] ;
[0019] For contrastive learning loss based on semantic parsing:
[0020] ;
[0021] It is the traditional supervised learning Loss function; Respectively represent the weights of the above loss functions, Represents a GQL original statement or a GQL variant statement. represents the positive sample GQL, represents the negative sample GQL, D is the positive and negative sample data set, , The natural language description texts representing positive samples and negative samples respectively Parse represents the semantic parsing model. is the similarity measurement function of the query graph, is the measurement function of relationship path similarity, represents the similarity function defined on the semantic parsing result, is a weight function based on whether the query graph is isomorphic:
[0022] , Indicates whether the query graph is isomorphic. and is a hyperparameter and > .
[0023] Preferably, the method further comprises:
[0024] S51, extracting matching pairs of GQL statements and their corresponding natural language description texts in the required target domain graph data, and constructing a new domain corpus dataset;
[0025] S52, preprocessing the new domain corpus dataset, performing equivalent transformation and constructing positive and negative samples on the GQL statements in the preprocessed dataset, and generating a new domain expanded corpus dataset;
[0026] S53, perform quality assessment on the new domain expanded corpus dataset, select part of the corpus whose quality is higher than a preset value, mix it with the expanded corpus dataset to generate a secondary fine-tuning corpus dataset, and input it into the target GQL corpus expansion model to fine-tune the model.
[0027] The present invention also discloses a GQL corpus generation model training device, including a data extraction module, an equivalent transformation module, a sample generation module and a model fine-tuning module, wherein the data extraction module is used to extract the matching pairs of each GQL original sentence and its corresponding natural language description text in the graph database product manual to construct an initial corpus data set; the equivalent transformation module is used to perform equivalent transformation on each GQL original sentence in the initial corpus data set according to a preset equivalent transformation rule and in combination with a large language model to generate corresponding GQL variant sentences and construct a variant corpus data set; the sample generation module is used to combine the initial corpus data set with the variant language A corpus dataset is constructed to construct a positive and negative sample dataset including multiple positive and negative sample pairs, wherein the positive and negative sample pairs include positive sample pairs of matched GQL sentences and corresponding natural language description texts, and negative sample pairs of unmatched or randomly combined GQL sentences and corresponding natural language description texts; a model fine-tuning module is used to integrate the initial corpus dataset, the variant corpus dataset, and the constructed positive and negative sample datasets into an expanded corpus dataset, and input the expanded corpus dataset into the target GQL corpus generation model to fine-tune the model, so that the target GQL corpus generation model can generate corresponding GQL sentences according to the input natural language description text.
[0028] Preferably, the equivalent transformation rules include but are not limited to connection condition rewriting rules, predicate reordering rules, synonym replacement rules, and variable renaming rules.
[0029] Preferably, the equivalent transformation module includes a sentence generation module and a sentence screening module, wherein the sentence generation module is used to identify the transformable units of each GQL original sentence in the initial corpus data set, and generate each equivalent transformation statement group corresponding to each GQL original sentence according to a preset equivalent transformation rule, and the transformable units include but are not limited to predicates and WHERE clauses; the sentence screening module is used to input each GQL original sentence and the corresponding equivalent transformation statement group into the trained first language model and score each equivalent transformation statement in combination with a preset scoring function, and use the equivalent transformation statement corresponding to the highest scoring result as the corresponding GQL transformation statement.
[0030] 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 the GQL corpus generation model training method as described above are implemented.
[0031] 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 GQL corpus generation model training methods are performed.
[0032] The GQL corpus generation model training method, device and storage medium disclosed in the present invention, after preliminarily building a high-quality small-sample corpus set based on a graph data product user manual, generates GQL variant sentences in combination with equivalent transformation rules, a large language model, etc. to achieve automatic expansion of GQL sentences in the GQL corpus, increase the richness of the corpus, and simultaneously generate positive and negative sample pairs and input them together with all the generated good corpora into the target GQL corpus generation model to fine-tune the model, so that the model can automatically generate corresponding GQL expansion sentences according to the input natural language description text, so as to achieve automatic expansion of the GQL corpus under low-cost conditions while ensuring quality, avoid human negligence, omissions, and annotation differences in the manual annotation process, and reduce the manpower and material costs spent on manual annotation.
[0033] 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
[0034] 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:
[0035] Figure 1 The figure is a schematic diagram of the steps of a GQL corpus generation model training method disclosed in one embodiment of the present invention.
[0036] Figure 2 This is a schematic diagram of specific steps of step S2 disclosed in one embodiment of the present invention.
[0037] Figure 3 This is a schematic diagram of specific steps of step S5 disclosed in one embodiment of the present invention.
[0038] Figure 4 It is a structural block diagram of a GQL corpus generation model training device disclosed in another embodiment of the present invention. DETAILED DESCRIPTION
[0039] 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.
[0040] 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 "a" do not indicate a quantity limitation, but indicate the existence of at least one.
[0041] With the continuous development of big data and artificial intelligence technology, people are increasingly demanding the construction of GQL corpus, thanks to the excellent processing ability and high scalability of graph query language GQL (graph query language) for complex relationships in the process of graph database query. At present, most GQL corpus is obtained through manual design and annotation. Due to the scarcity of experts who master the principles of GQL and graph databases, as well as the rich expression ability of GQL, it is difficult to take into account the quality, diversity and scale of the corpus during the construction process. As a result, various AI-assisted technologies for GQL cannot be fully optimized and trained, which greatly reduces their effectiveness in practical applications and makes it difficult to truly provide valuable assistance to users.
[0042] At the same time, in the manual annotation process, errors and omissions caused by the annotator's negligence, annotation differences caused by the annotator's misunderstanding, omission of test cases due to the annotator's lack of understanding of certain grammatical boundary conditions, and incomplete coverage of certain implicit dependencies in artificial corpora will also cause the corpus quality to be unstable, affecting the reliability of GQL-related systems in subsequent training and testing, making it difficult to directly apply the current GQL corpus to actual graph database application development and optimization.
[0043] Therefore, this embodiment discloses a GQL corpus generation model training method, as shown in the attached Figure 1 As shown, the following steps are included.
[0044] Step S1, extract the matching pairs of each GQL original sentence and its corresponding natural language description text in the graph database product manual to construct an initial corpus dataset.
[0045] Specifically, we first build a small amount of high-quality seed corpus according to the graph database product manual to form an initial corpus dataset to solve the cold start problem. The initial corpus dataset stores multiple matching pairs of GQL statements and natural language description texts in the form of a (GQL statement, natural language description text) structure. Each matching pair includes a GQL statement and a natural language description text statement, for example:
[0046] GQL statement:
[0047] "MATCH (p:Person)-[:FOLLOWS]->(f:Person)
[0048] WHERE p.age>18 AND f.city = 'Beijing'
[0049] RETURN p.name AS name"
[0050] The corresponding natural language description text:
[0051] “Find all usernames over 18 who are following people living in Beijing.”
[0052] Among them, extracting the matching pairs of each GQL original sentence and its corresponding natural language description text in the graph database product manual and constructing the initial corpus dataset specifically includes the following contents.
[0053] Step S101, 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 natural language description text 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.
[0054] Specifically, the location meta-information is the chapter information where the GQL statement is located, such as the first-level, second-level, and third-level titles corresponding to the GQL statement, which ensures the traceability of the source of the GQL corpus and facilitates better understanding and use of GQL statements as well as subsequent updates.
[0055] Step S102, forming a second triple data set after correctness verification of the GQL statements in the first triple data set, wherein the correctness verification is configured to eliminate erroneous GQL statements that cannot be executed in the triple data set and the corresponding natural language description text and position meta-information, serialize the second triple data set according to the format preset by the target GQL corpus generation model to form a first fine-tuning data set, and extract the GQL statements and the corresponding natural language description text in the serialized second triple data set to form an initial corpus data set.
[0056] Furthermore, the initial corpus dataset can also be updated, which also includes step S103. After monitoring that the graph database product manual has been updated, the location metadata of the updated version is compared with the basic version serving as the data source of the first fine-tuning dataset to identify the changed text paragraphs; some triples corresponding to the changed text paragraphs are deleted from the first fine-tuning dataset, and the changed text paragraphs 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 is added to the first fine-tuning dataset to form a second fine-tuning dataset serving as the updated fine-tuning corpus, and the GQL statements and corresponding natural language description texts in the second fine-tuning corpus dataset are extracted to replace the original initial corpus dataset.
[0057] By comparing the position metadata, deleting the triple data corresponding to the changed text paragraphs, and reconstructing and verifying the new triples, automatic maintenance of the constructed initial GQL corpus dataset is achieved, reducing the tediousness of data reconstruction when updating the graph database product manual.
[0058] Step S2, according to preset equivalent transformation rules, combined with the large language model, each GQL original sentence in the initial corpus data set is equivalently transformed to generate corresponding GQL variant sentences and construct a variant corpus data set. The equivalent transformation rules include but are not limited to connection condition rewriting rules, predicate reordering rules, synonym replacement rules, and variable renaming rules.
[0059] Specifically, we introduce rule-based equivalent transformations and utilize the powerful semantic understanding and generation capabilities of large language models. Under the condition of a small number of samples in the initial corpus dataset, we expand the initial corpus dataset and generate GQL sentence variants in various forms as much as possible while maintaining semantics. This increases the diversity of GQL sentence expression and the richness of the corpus, improves the quality of corpus generation and the generalization ability of the AI model that uses the corpus for optimized training.
[0060] Among them, the large language model preferably uses a generative language model with Few-Shot capability, such as GPT-3, GPT-4, and BLOOM. The connection condition rewriting rule is, for example: (a) -[r]->(b) is equivalent to (b)<-[r]- (a);
[0061] The predicate reordering rule is as follows: WHERE a>1 AND b<2 is equivalent to WHERE b<2 AND a>1;
[0062] For example, the synonym replacement rule is: COUNT is equivalent to SIZE, DISTINCT is equivalent to UNIQUE;
[0063] The variable renaming rule, for example: MATCH (a) RETURN a is equivalent to MATCH (b) RETURN b.
[0064] In this embodiment, as shown in the attached Figure 2 As shown, obtaining the GQL transformation statement using the equivalent transformation rule specifically includes the following contents.
[0065] Step S21, identifying transformable units of each GQL original sentence in the initial corpus data set, and generating each equivalent transformation statement group corresponding to each GQL original sentence according to a preset equivalent transformation rule, wherein the transformable units include but are not limited to predicates and WHERE clauses.
[0066] Specifically, through algorithms such as tree traversal or pattern matching, the parts of each GQL original sentence in the initial corpus data set to which the transformation rules can be applied are identified and obtained, and multiple GQL equivalent sentences are generated for each GQL original sentence.
[0067] For example: For the GQL original statement Q in the initial corpus dataset: MATCH (a:Person) -[r:FOLLOW]->(b:Person) WHERE r.date>2022 RETURN DISTINCT a,
[0068] Using the join condition rewrite rule, an equivalent statement 1 can be generated: MATCH (b:Person)<-[r:FOLLOW]- (a:Person) WHERE r.date>2022 RETURN DISTINCT a;
[0069] Using predicate reordering + synonym replacement rules, we can generate equivalent statement 2: MATCH (a:Person) -[r:FOLLOW]->(b:Person) WHERE 2022 <r.date RETURN UNIQUE a;
[0070] Using the variable renaming rule, an equivalent statement 3 can be generated: MATCH (p:Person) -[f:FOLLOW]->(q:Person) WHERE f.date>2022 RETURN DISTINCT.
[0071] Equivalent statements 1, 2, and 3 together constitute the equivalent transformation statement group corresponding to the GQL original statement Q.
[0072] Step S22, input each GQL original sentence and the corresponding equivalent transformation sentence group into the trained first language model, and score each equivalent transformation sentence in combination with a preset scoring function, and use the equivalent transformation sentence corresponding to the highest scoring result as the corresponding GQL transformation sentence.
[0073] Specifically, the equivalent transformation statements generated by simple equivalent transformation may not be natural enough or may not conform to actual usage habits. To this end, this embodiment uses the language understanding and generation capabilities of the large language model to select the most natural and customary equivalent transformation statements from the multiple equivalent transformation statements obtained. Among them, the degree of equivalence of each statement in the equivalent transformation statement group with the GQL original statement and the naturalness of each equivalent transformation statement are evaluated by a preset scoring function. In this embodiment, the scoring function is implemented by the Few-shot Prompt method.
[0074] Furthermore, when the scoring result is lower than the preset score, the large language model can be used to directly generate GQL equivalent transformation statements to avoid the pollution of the data set by redundant statements.
[0075] In another embodiment, for complex GQL with nested subqueries, complex predicate conditions, smear-style matching recursion, etc., since it is often difficult for a rule-based parser to be completely accurate when processing such complex structures, the generated parse tree does not completely match the actual semantics of GQL. Therefore, each GQL original sentence in the initial corpus data set and the equivalent transformation rule can be input into the second language model as prompt information to generate GQL variant sentences.
[0076] Specifically, in the training phase, the model is trained with a few sample examples to describe GQL in a structured way, and the second language model is inspired to think about the semantic structure of GQL by inputting prompt information, further enhancing the large language model's ability to understand complex GQL. In the reasoning phase, the original GQL sentences in the initial corpus dataset are filled into the prompt information template, and the second language model automatically extracts the keywords and generates a structured representation that conforms to the predefined format. The structured representation includes but is not limited to JSON and XML.
[0077] Furthermore, since the GQL transformation statements generated entirely by the large language model have low reliability, a manual review process can be introduced to perform manual sampling checks on the transformation results selected or generated by the large language model. When the review results show that there are problems with the generated GQL transformation statements, the transformation statements are deleted and the reasons are summarized, so as to improve the transformation rules or optimize the LLM scoring function to form a closed-loop feedback. After multiple rounds of iterative optimization, reliable equivalent transformation of GQL statements can be achieved.
[0078] In addition, in this embodiment, the graph database can be directly used to review different transformation results of the same GQL original statement, further improving the accuracy of the obtained GQL transformation statement. In this way, specific data can be directly called for execution, or only verified through the logical plan layer.
[0079] Step S3, combining the initial corpus dataset and the variant corpus dataset to construct a positive and negative sample dataset including multiple positive and negative sample pairs, wherein the positive and negative sample pairs include positive sample pairs of matched GQL sentences and corresponding natural language description texts, and negative sample pairs of unmatched or randomly combined GQL sentences and corresponding natural language description texts.
[0080] Specifically, the positive and negative sample datasets include multiple positive sample pairs and negative sample pairs, each of which includes a GQL matching pair in the initial corpus dataset or the variant corpus dataset and a generated GQL statement positive sample or GQL statement negative sample corresponding to the natural language description text of the GQL matching pair.
[0081] Among them, the positive samples include but are not limited to: matching pairs of each GQL original sentence in the initial corpus data set and its corresponding natural language description text; matching pairs of each GQL variant sentence and its corresponding natural language description text; matching pairs of each fragment in the natural language description text extracted by the sentence compression model and its corresponding GQL sentence fragment; matching pairs of similar natural language description texts obtained by the sentence similarity model and their corresponding GQLs that are matched in series.
[0082] The negative samples include but are not limited to: matching pairs that are randomly combined with GQL statements and natural language description texts using random number seeds; matching pairs that are randomly shuffled and spliced with fragments of GQL statements and natural language description texts using the Shuffle algorithm; matching pairs of GQL statements and natural language description texts with opposite semantics that are manually defined; and matching pairs composed of GQL statements with grammatical errors and original natural language description texts that are randomly introduced using syntax analysis tools.
[0083] The parser of the parsing tool is used to parse each GQL original statement and GQL variant statement, generate the corresponding abstract syntax tree, and introduce a random perturbation mechanism to generate GQL statements with syntax errors. The abstract syntax tree (AST) represents the grammatical composition of the GQL statement in a tree structure, where each node corresponds to a grammatical component, such as a Match clause, a Where condition, etc.
[0084] In this embodiment, the semantic similarity can also be used to select and construct negative sample matching pairs corresponding to the natural language description text, which specifically includes the following contents:
[0085] Step S201, calculating the semantic similarity between each GQL statement and each natural language description text matching pair by a word vector calculation method.
[0086] Step S202, select matching pairs whose similarity is within a preset numerical range to construct a GQL statement candidate matching group corresponding to each natural language description text. In this embodiment, the preset numerical range is 0.6-0.8.
[0087] Step S203: randomly select a GQL sentence from the GQL sentence candidate matching group as a negative sample, and form a negative sample pair with the corresponding natural language description text.
[0088] In addition, the appropriate introduction of some noise data, such as randomly replacing individual words in NL or randomly deleting individual tokens in GQL, can improve the robustness of the model.
[0089] Specifically, for example, for a natural language description text: find all usernames over 18 years old who follow people living in Beijing, and their corresponding GQL original statements:
[0090] MATCH (p:Person)-[:FOLLOWS]->(f:Person)
[0091] WHERE p.age>18 AND f.city = 'Beijing'
[0092] RETURN p.name AS name;
[0093] GQL negative sample statement 1 can be generated:
[0094] MATCH (p:Person)-[:FOLLOWS]->(f:Person)
[0095] WHERE p.age<18 AND f.city = 'Beijing'
[0096] RETURN p.name AS name;
[0097] At this point, the predicate condition p.age<18 in the GQL statement contradicts "over 18 years old" in the natural language description text. This sample can help the training model identify predicate errors.
[0098] GQL negative sample statement 2:
[0099] MATCH (p:Person)-[:FOLLOWS]->(f:Person)
[0100] WHERE p.age>18 AND f.city = 'Beijing'
[0101] RETURN f.name AS name;
[0102] At this time, the name f.name of the person being followed returned by the GQL statement does not match the username p that should be found in the natural language description text. This sample can help the training model identify semantic understanding errors.
[0103] GQL negative sample statement 3:
[0104] MATCH (p:Person)-[:LIVES_IN]->(c:City)
[0105] WHERE c.name = 'Shanghai'
[0106] RETURN p.name AS name;
[0107] At this point, the GQL statement is completely unrelated to the natural language description text and is generated by random patchwork. The introduction of obvious errors in this sample can help the model increase robustness.
[0108] The GQL original sentence and its corresponding natural language description text form different negative sample pairs with GQL negative sample sentences 1, 2, and 3. Through the above-mentioned random combination, alignment and shuffling, the positive and negative sample pairs of GQL sentences and natural language description texts are automatically constructed, and then the constructed positive and negative sample pairs are fine-tuned in the target GQL corpus generation model, so as to prompt the model to learn the consistency and difference characteristics of positive and negative samples, further increase the model's understanding of the mapping relationship between positive and negative samples, improve the model's discrimination ability, and reduce the possibility of model misjudgment.
[0109] Step S4, integrating the initial corpus dataset, the variant corpus dataset, and the constructed positive and negative sample datasets into an extended corpus dataset, and inputting the extended corpus dataset into the target GQL corpus generation model to fine-tune the model so that the target GQL language model can generate corresponding GQL sentences according to the input natural language description text.
[0110] Specifically, the input of positive and negative sample data sets into the target GQL corpus generation model helps the model summarize the key features of positive and negative samples and improve the ability to distinguish between positive and negative samples. At the same time, when the user inputs a natural language description text, the target GQL corpus generation model can automatically determine whether the corresponding GQL sentence is a negative sample pair with the input GQL sentence after it is generated, and provide timely feedback when a negative sample pair is formed, and continue to generate until a positive sample pair is generated, thereby improving the model's discrimination ability and the accuracy of the generated expanded corpus. Its training steps can minimize the similarity between the embedding vectors of positive and negative samples through comparative learning to prompt the model to make judgments, and can also train the model to perform binary classification of positive and negative samples through classification learning.
[0111] In this embodiment, the loss function of the target GQL language model is configured as:
[0112] ;
[0113] in, For contrastive learning loss based on graph isomorphism:
[0114] ;
[0115] For the contrastive learning loss based on relational paths:
[0116] ;
[0117] For contrastive learning loss based on semantic parsing:
[0118] ;
[0119] It is the traditional supervised learning Loss function; Respectively represent the weights of the above loss functions, Represents a GQL original statement or a GQL variant statement. represents the positive sample GQL, represents the negative sample GQL, D is the positive and negative sample data set, , The natural language description texts representing positive samples and negative samples respectively Parse represents the semantic parsing model. is the similarity measurement function of the query graph, is the measurement function of relationship path similarity, represents the similarity function defined on the semantic parsing result, is a weight function based on whether the query graph is isomorphic:
[0120] , Indicates whether the query graph is isomorphic. and is a hyperparameter and > .
[0121] Specifically, this embodiment comprehensively improves the ability of the target GQL language model to learn mapping relationships by integrating various types of contrastive learning and traditional supervised learning loss functions, so that in specific implementation, the weight ratio of each loss function can be adjusted according to task characteristics and model architecture.
[0122] Among them, the contrastive learning loss function based on graph isomorphism By parsing GQL statements into query graphs, the isomorphism of the query graphs of the positive and negative sample pairs in each positive and negative sample pair is determined, so as to determine the discrimination between different positive and negative sample pairs, thereby adjusting the weights and encouraging the model to learn the subtle structural differences between different GQL statement expressions. Each GQL corresponds to a query graph, which reflects the pattern matching semantics of the GQL statement. When two GQL statements have syntactic differences but the query graphs are isomorphic, they are semantically equivalent. For example, the weight function expression As shown in the figure, when the query graphs of the positive sample pair are isomorphic and the query graphs of the negative sample pair are not, the model believes that the positive and negative samples have a higher degree of discrimination and gives them a larger weight.
[0123] Contrastive learning loss function based on relational paths By extracting all relationship paths from GQL statements, converting them into a multiset representation of a relationship path, and calculating the relationship path similarity between GQL statements in positive and negative sample pairs as supervisory information for comparative learning, the model is prompted to focus on the implicit semantic associations in GQL statements, model the long-distance dependencies between nodes and relationships, and learn deeper semantic representations. The complex path relationships contained in GQL statements reflect the semantics of data flow on the graph. The more similar the relationship between two GQL statements, the closer the semantics. The measurement function PathSim of relationship path similarity can be constructed based on indicators such as Jaccard similarity or edit distance of two relationship path sets.
[0124] Contrastive Learning Loss Function Based on Semantic Parsing Make full use of the rich semantic information contained in the natural language description text corresponding to the GQL sentence, introduce the pre-trained semantic parsing model to parse both the GQL sentence and the natural language description text into a more abstract and standardized semantic representation, and use the semantic representation as the object of comparative learning, forcing the model to explore the deep semantics behind the surface syntax of GQL and learn the alignment of GQL sentence and natural language description text at the semantic level. For example, use the semantic parsing model AMR Parser to parse GQL sentence and natural language description text into AMR graph.
[0125] By combining the above-mentioned contrastive learning loss functions and performing a weighted combination with the traditional supervised learning loss function, the weights of each loss function are reasonably adjusted. While inheriting the advantages of contrastive learning in learning universal representations, a customized contrast mechanism is designed for the unique properties of GQL, which makes up for the limitations of traditional supervised learning and prompts the model to consider the structural semantics, relational semantics, contextual semantics, and alignment with natural language description text of GQL, thereby improving the robustness and accuracy of the model-generated GQL representation. In specific implementation, the weight coefficient can be used as a hyperparameter for grid search, or a weight generator can be designed to adaptively generate the weights of each loss function based on the characteristics of GQL length, nesting depth, number of relationships, etc.
[0126] In this embodiment, the gain effect of contrastive learning can also be evaluated. The model is trained on the training set of traditional supervised learning only and the training set of supervised learning and contrastive learning at the same time. The model is tuned with the same validation set and the performance of the model is evaluated with the same test machine. The performance of the two models in terms of BLEU, ROUGE, Precision, Recall and other indicators is compared to observe the gain effect of contrastive learning, and a significance test is performed to ensure that the gain effect is statistically significant. In this practice, it can be observed that the model using contrastive learning is significantly better than the model of pure supervised learning.
[0127] Furthermore, in real scenarios, graph databases are often used in new fields and scenarios. However, the generated corpus and the corresponding target GQL corpus generation model in this embodiment, after fine-tuning through the above-mentioned expanded corpus dataset, cover a relatively single scenario and lack comprehensive consideration of different industries, different data scales, and different access modes. In this case, the method can also be expanded by bootstrapping the adjacent new domain datasets, as shown in the attached figure. Figure 3 As shown, the specific contents include the following.
[0128] Step S51, extracting matching pairs of GQL statements and their corresponding natural language description texts in the required target domain graph data, and constructing a new domain corpus dataset.
[0129] Specifically, the generated corpus and the corresponding target GQL corpus generation model still lack the knowledge of other fields. To this end, this embodiment constructs a corpus dataset of a new field by extracting and expanding the GQL sentences and the corresponding natural language description texts in the relevant new field graph data.
[0130] Step S52, preprocessing the new domain corpus dataset, performing equivalent transformation and constructing positive and negative samples on the GQL sentences in the preprocessed dataset, and generating a new domain expanded corpus dataset.
[0131] Specifically, the preprocessing process includes but is not limited to data cleaning, data formatting, data desensitization, and data sampling. Among them, data cleaning improves data quality by removing obvious data errors, incomplete data, and duplicate data; data formatting converts unstructured or semi-structured text data into a preset structured format to ensure the consistency of corpus information and improve the utilization of information; data desensitization desensitizes sensitive information that is designed to protect privacy to ensure the legality and compliance of corpus data; data sampling reduces the computational overhead in the corpus update process by randomly extracting from massive data. The preprocessing process improves the standardization and neatness of the new domain corpus data set to a certain extent, ensuring the efficiency and accuracy of the subsequent generation of the new domain expansion corpus.
[0132] The equivalent transformation and positive and negative sample construction process remain the same as steps S2-S3 to simplify data processing and calculation, and further improve the scale and diversity of the GQL corpus in the new domain.
[0133] Step S53, perform quality assessment on the new domain expanded corpus dataset, select part of the corpus whose quality is higher than a preset value, mix it with the expanded corpus dataset to generate a secondary fine-tuning corpus dataset, and input it into the target GQL corpus expansion model to fine-tune the model.
[0134] Specifically, the quality of the expanded new domain corpus obtained after expansion can be evaluated using unsupervised indicators such as language model perplexity and sequence edit distance, or the quality of the generated natural language description text can be judged by manual annotation. The target GQL corpus generation model is fine-tuned twice by integrating the obtained new domain expanded corpus dataset with the previously acquired expanded corpus dataset, so that the model can remember the original knowledge while learning the new domain knowledge.
[0135] Furthermore, the model can be iterated multiple times according to the above method until the iteration stop condition is reached, so as to help continuously improve the scale and quality of the new domain corpus and enhance the model's understanding and generation capabilities for related new domains. The target GQL corpus expansion model after multiple fine-tuning can support a variety of applications such as GQL intelligent portability, semantic retrieval, and data annotation for new domains. Among them, the iteration stop condition can be configured to be multiple, for example: the scale of the new domain corpus reaches the expected scale, the performance indicators of the model on the new domain verification set tend to be stable, or the quality of manual evaluation generation is difficult to further improve.
[0136] In this embodiment, due to the continuous development of graph data technology and changes in related business needs, the new domain dataset itself may also change, such as the emergence of new GQL grammatical features or new domain concepts. In order to improve the adaptability of the target GQL corpus expansion model to such changes, a continuous optimization and update mechanism can also be established for the target GQL corpus expansion model, specifically including the following contents.
[0137] Step S301: regularly extract matching pairs of GQL statements and their corresponding natural language description texts in the relevant domain graph data at preset time intervals to construct a first corpus dataset.
[0138] Step S302, preprocessing, equivalent transformation and positive and negative sample pair generation are performed on the data in the first corpus data set to construct a second corpus data set.
[0139] Step S303: The second corpus data set is merged with the data of according to a preset weighted average strategy to generate a third corpus data set.
[0140] Step S304: input the third corpus data set into the target GQL corpus expansion model to fine-tune the model.
[0141] Through continuous optimization and updating, the target GQL corpus expansion model can regularly learn new grammar in the field and improve the applicability of the generated corpus.
[0142] In this embodiment, the GQL corpus expansion model is integrated into an end-to-end GQL corpus generation model training system after training. The system implements various data enhancement algorithms in a configurable manner, has a built-in syntax parser and execution engine adapter for the mainstream GQL dialect, and provides a flexible human-computer interaction interface, which can dynamically adjust the transformation rules and LLM parameters according to user feedback. In addition, the system provides seamless integration with mainstream GQL modeling tools (such as Neo4j Bloom), and users can directly use natural language to describe text GQL logic in the modeling interface, which significantly reduces the threshold for GQL learning and improves development efficiency.
[0143] The GQL corpus generation model training method, device and storage medium disclosed in the present invention, after preliminarily building a high-quality small-sample corpus set based on a graph data product user manual, generates GQL variant sentences in combination with equivalent transformation rules, a large language model, etc. to achieve automatic expansion of GQL sentences in the GQL corpus, increase the richness of the corpus, and simultaneously generate positive and negative sample pairs and input them together with all the generated good corpora into the target GQL corpus generation model to fine-tune the model, so that the model can automatically generate a natural language description text corresponding to the GQL expansion sentence according to the input GQL sentence, so as to achieve automatic expansion of the GQL corpus under low-cost conditions while ensuring quality, avoid human negligence, omissions, and annotation differences in the manual annotation process, and reduce the manpower and material costs spent on manual annotation.
[0144] In another embodiment, as shown in the attached Figure 4 As shown, a GQL corpus generation model training device is also disclosed, including a data extraction module 1, an equivalent transformation module 2, a sample generation module 3 and a model fine-tuning module 4. The data extraction module 1 is used to extract matching pairs of each GQL original sentence and its corresponding natural language description text in the graph database product manual to construct an initial corpus data set. The equivalent transformation module 2 is used to perform equivalent transformation on each GQL original sentence in the initial corpus data set according to a preset equivalent transformation rule and in combination with a large language model, generate corresponding GQL variant sentences, and construct a variant corpus data set. The sample generation module 3 is used to combine the initial corpus data set with the variant corpus data set to automatically construct a positive and negative sample data set including multiple positive and negative sample pairs, wherein the positive and negative sample pairs include positive sample pairs of matched GQL sentences and natural language description texts, and negative sample pairs of unmatched or randomly combined GQL sentences and natural language description texts. The model fine-tuning module 4 is used to integrate the initial corpus dataset, the variant corpus dataset, and the constructed positive and negative sample datasets into an expanded corpus dataset, and input it into the target GQL corpus generation model to fine-tune the model so that the target GQL corpus generation model can generate corresponding GQL sentences according to the input natural language description text.
[0145] In this embodiment, the equivalent transformation rules include but are not limited to connection condition rewriting rules, predicate reordering rules, synonym replacement rules, and variable renaming rules.
[0146] In this embodiment, the equivalent transformation module includes a sentence generation module and a sentence screening module, wherein the sentence generation module is used to identify the transformable units of each GQL original sentence in the initial corpus data set, and generate each equivalent transformation statement group corresponding to each GQL original sentence according to the preset equivalent transformation rule, and the transformable unit includes but is not limited to the predicate and WHERE clause statement screening module, which is used to input each GQL original sentence and the corresponding equivalent transformation statement group into the trained first language model and score each equivalent transformation statement in combination with the preset scoring function, and use the equivalent transformation statement corresponding to the highest scoring result as the corresponding GQL transformation statement.
[0147] 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. Similar parts between the various embodiments can be referenced to each other. For the GQL corpus generation model training device disclosed in the embodiment, since it corresponds to the GQL corpus generation model training method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the aforementioned method part description.
[0148] 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 GQL corpus generation model training 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 a combination of certain components, or different components.
[0149] If the GQL corpus generation model training 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 various GQL corpus generation model training 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 capable of carrying 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.
[0150] 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.
[0151] 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 GQL corpus generation model training method, characterized in that: The steps include: S1, extract the matching pairs of each GQL original sentence and the corresponding natural language description text in the graph database product manual to build the initial corpus dataset; S2, according to the preset equivalent transformation rules, combined with the large language model, each GQL original sentence in the initial corpus data set is equivalently transformed to generate a corresponding GQL variant sentence and construct a variant corpus data set, specifically including: S21, identifying transformable units of each GQL original sentence in the initial corpus data set, and generating equivalent transformation sentence groups corresponding to each GQL original sentence according to a preset equivalent transformation rule, wherein the transformable units include a predicate and a WHERE clause; S22, inputting each GQL original sentence and the corresponding equivalent transformation sentence group into the trained first language model, scoring each equivalent transformation sentence in combination with a preset scoring function, and taking the equivalent transformation sentence corresponding to the highest scoring result as the corresponding GQL transformation sentence; S3, combining the initial corpus dataset and the variant corpus dataset to construct a positive and negative sample dataset including a plurality of positive and negative sample pairs, wherein the positive and negative sample pairs include positive sample pairs of matched GQL sentences and corresponding natural language description texts, and negative sample pairs of unmatched or randomly combined GQL sentences and corresponding natural language description texts; S4, integrating the initial corpus dataset, the variant corpus dataset, and the constructed positive and negative sample datasets into an extended corpus dataset, and inputting the extended corpus dataset into the target GQL corpus generation model to fine-tune the model so that the target GQL corpus generation model can generate corresponding GQL sentences according to the input natural language description text.
2. The GQL corpus generation model training method according to claim 1, characterized in that: The equivalent transformation rules include connection condition rewriting rules, predicate reordering rules, synonym replacement rules, and variable renaming rules.
3. The GQL corpus generation model training method according to claim 2, characterized in that: The loss function of the target GQL language model is configured as: ; in, For contrastive learning loss based on graph isomorphism: ; For the contrastive learning loss based on relational paths: ; For contrastive learning loss based on semantic parsing: ; It is the traditional supervised learning Loss function; Respectively represent the weights of the above loss functions, Represents a GQL original statement or a GQL variant statement. represents the positive sample GQL, represents the negative sample GQL, D is the positive and negative sample dataset, , The natural language description texts representing positive samples and negative samples respectively Parse represents the semantic parsing model. is the similarity measurement function of the query graph, is the measurement function of relationship path similarity, represents the similarity function defined on the semantic parsing result, is a weight function based on whether the query graph is isomorphic: , Indicates whether the query graph is isomorphic, and is a hyperparameter and > .
4. The GQL corpus generation model training method according to claim 3, characterized in that: Also includes: S51, extracting matching pairs of GQL statements and their corresponding natural language description texts in the required target domain graph data, and constructing a new domain corpus dataset; S52, preprocessing the new domain corpus dataset, performing equivalent transformation and constructing positive and negative samples on the GQL statements in the preprocessed dataset, and generating a new domain expanded corpus dataset; S53, perform quality assessment on the new domain expanded corpus dataset, select part of the corpus whose quality is higher than a preset value, mix it with the expanded corpus dataset to generate a secondary fine-tuning corpus dataset, and input it into the target GQL corpus expansion model to fine-tune the model.
5. A GQL corpus generation model training device, characterized in that: include: The data extraction module is used to extract the matching pairs of each GQL original statement and its corresponding natural language description text in the graph database product manual to construct the initial corpus dataset; An equivalent transformation module, used to perform equivalent transformation on each GQL original sentence in the initial corpus data set according to a preset equivalent transformation rule and in combination with a large language model, generate corresponding GQL variant sentences, and construct a variant corpus data set; wherein the equivalent transformation module includes: a sentence generation module, used to identify the transformable units of each GQL original sentence in the initial corpus data set, and generate each equivalent transformation sentence group corresponding to each GQL original sentence according to the preset equivalent transformation rule, wherein the transformable unit includes a predicate and a WHERE clause; a sentence screening module, used to input each GQL original sentence and the corresponding equivalent transformation sentence group into the trained first language model, and score each equivalent transformation sentence in combination with a preset scoring function, and use the equivalent transformation sentence corresponding to the highest scoring result as the corresponding GQL transformation sentence; A sample generation module, used to combine the initial corpus dataset and the variant corpus dataset to construct a positive and negative sample dataset including a plurality of positive and negative sample pairs, wherein the positive and negative sample pairs include positive sample pairs of matched GQL sentences and corresponding natural language description texts, and negative sample pairs of unmatched or randomly combined GQL sentences and corresponding natural language description texts; The model fine-tuning module is used to integrate the initial corpus dataset, the variant corpus dataset, and the constructed positive and negative sample datasets into an extended corpus dataset, and input the extended corpus dataset into the target GQL corpus generation model to fine-tune the model so that the target GQL corpus generation model can generate corresponding GQL sentences according to the input natural language description text.
6. The GQL corpus generation model training device according to claim 5, characterized in that: The equivalent transformation rules include connection condition rewriting rules, predicate reordering rules, synonym replacement rules, and variable renaming rules.
7. A server comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
