Text-to-SQL generation method for reservoir data monitoring and early warning
Through the text-to-SQL generation method based on refined syntax information and graph neural network, the problem of untimely data collection and low warning accuracy in traditional reservoir monitoring systems is solved, efficient and accurate reservoir data monitoring and early warning are achieved, and the system is improved ease of use and intelligence.
Patent Information
- Application Number
- CN202411440408.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-15
- Publication Date
- 2025-01-14
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Traditional reservoir monitoring and early warning systems have problems such as untimely data collection, limited monitoring range and low warning accuracy, which cannot meet the needs of reservoir safety management.
Using text-to-SQL generation method based on refined syntax information and graph neural network, efficient and accurate SQL query statements are generated to realize reservoir data through syntax dependency tree and relational graph attention network, dynamic edge attention pooling and RAT layer. Monitoring and early warning.
It improves the ease of use, efficiency and accuracy of the system, expands the user group, realizes the intelligence and informatization of reservoir safety management, and can quickly generate personalized data results that meet user needs.
Smart Images

Figure SMS_3 
Figure SMS_5 
Figure SMS_7
Abstract
Description
Technical Field
[0001] The present invention is directed to the technical field of reservoir data monitoring and early warning, and in particular relates to a text-to-SQL generation method based on refined grammatical information and graph neural network, belonging to the technical field of code generation in natural language processing. Background Art
[0002] Reservoirs play a vital role in water resource management. They are not only important sources of water for water supply, irrigation and power generation, but also have multiple functions such as flood control, water flow regulation and ecological environment protection. However, with the intensification of climate change, population growth and urbanization, reservoir management is facing increasing challenges. Reservoirs may face multiple risks such as floods, droughts and water pollution, which have serious impacts on the safety and sustainable development of reservoirs.
[0003] Traditional reservoir monitoring and early warning systems mainly rely on sensors and monitoring equipment to predict the status of reservoirs and possible disasters by real-time monitoring of water level, flow and other data. However, traditional systems have problems such as untimely data collection, limited monitoring range, and low early warning accuracy, which cannot meet the needs of reservoir safety management.
[0004] With the development of natural language processing and artificial intelligence technology, text-to-SQL methods are widely used in various data query and analysis tasks. By converting natural language commands into SQL query statements, text-to-SQL methods can provide users with a more intuitive and convenient way to access data, enabling non-professionals to use databases for data analysis and query.
[0005] In this context, a text-to-SQL generation method for reservoir data monitoring and early warning has emerged. This method uses natural language commands to enable reservoir managers and related personnel to obtain real-time monitoring data, forecast information and disaster warnings of reservoirs through simple language instructions, so as to take timely measures to deal with possible disasters. This text-to-SQL generation method for reservoir data monitoring and early warning can not only improve the efficiency and accuracy of reservoir management, but also expand the user group and realize the intelligent and information-based management of reservoir safety. Summary of the invention
[0006] Purpose of the invention: Through the analysis of the above prior art, it can be seen that the present invention provides a text-to-SQL generation method for reservoir data monitoring and early warning, which enables reservoir managers and related personnel to obtain real-time monitoring data, forecast information and disaster warnings of reservoirs through simple language instructions, so as to take timely measures to deal with possible disasters. In order to enable the model to achieve a better recognition effect, the present invention provides a text-to-SQL generation method based on refined grammatical information and graph neural network in the technical field of reservoir data monitoring and early warning, so that the generation effect is better.
[0007] Technical solution: Text-to-SQL generation method for reservoir data monitoring and early warning. A text-to-SQL generation model is designed for reservoir data monitoring and early warning. The model incorporates detailed grammatical information in the question and limits the complexity of edge embedding by reducing coupling. Using the grammatical dependency tree, the model can better capture the structure and grammatical rules of the question. The detailed grammatical information can provide additional context and semantic clues for the model, thereby improving its generalization and interpretability. We also dynamically capture the importance of different edges according to the structure of the graph to reduce edge embedding coupling, which can further improve the performance of the model.
[0008] The specific steps include:
[0009] Step 1: Data cleaning and dataset creation: Data processing of the data contained in the reservoir database and commonly used natural language commands mainly involves two steps: data cleaning and preprocessing, and natural language command processing and conversion. The processed dataset contains the tables and columns contained in the reservoir database, as well as commonly used natural language commands and corresponding SQL queries.
[0010] Step 2: Use the grammatical dependency tree to obtain the grammatical information contained in the question, and then convert the information contained in the database and the entities mentioned in the natural language question and the relationship between the two into an interaction graph.
[0011] Step 3: Convert the interaction graph into edge embedding and node embedding: Take the labels of the entire input sequence as vertices and the relationships between sequence labels as edges, so as to incorporate various types of relationships into the model.
[0012] Step 4: Applying the Relational Graph Attention Network: The model uses the Relational Graph Attention Network, which mainly consists of two modules, a node-centric graph module and an edge-centric graph module. By combining and then superimposing the two graphs, the nodes and the relationships between them can be captured during training, while updating the node and relationship embeddings.
[0013] Step 5: Reduce the over-coupling of edge embeddings by using the dynamic edge attention pooling method, which uses the attention mechanism to dynamically calculate the importance of different edges in the graph, and then performs graph pooling operations based on the edge weights. The importance of different edges can be captured dynamically based on the structure of the graph, thereby improving the representation ability and performance of the graph neural network.
[0014] Step 6: Use the RAT layer to unify the two types of embeddings: Link the node embedding and the relationship embedding into a longer sequence representation, which is the initial input of the RAT. After passing through the RAT module, the final result is a unified representation of the two embeddings.
[0015] Step 7: Decode using a decoder based on grammar generation: In order to eliminate the mismatch between the intention of natural language expression and the implementation details of SQL, a domain-specific language called SemQL is used as an intermediate representation between NL problems and SQL, which is essentially an abstract syntax tree. SemQL can represent SQL statements in the form of a tree, first generating the most important part of the SQL query, and then filling it in, so that when synthesizing the final SQL statement, the grammatical constraints are added, and finally the correct SQL query statement is generated.
[0016] The specific steps of the text-to-SQL generation method for reservoir data monitoring and early warning are as follows:
[0017] In step 1, the text-to-SQL generation method for reservoir data monitoring and early warning is characterized in that the specific steps of data cleaning and preprocessing and natural language command processing and conversion are as follows:
[0018] For the reservoir database, data cleaning is first performed, including deleting duplicate data, processing missing values, and correcting erroneous data. Then data preprocessing is performed, including data formatting, data normalization, outlier processing, and data integration. Natural language commands are processed, first semantic understanding is performed, including syntactic analysis and semantic parsing. Then query generation is performed, including query construction and parameter mapping.
[0019] The toolkit Stanza is used to preprocess the questions, table names, and column names contained in the dataset so that the natural language can be tokenized and lemmatized.
[0020] In step 2, the text-to-SQL generation method for reservoir data monitoring and early warning is characterized in that the grammatical information contained in the question is obtained by using a grammatical dependency tree, and then the information contained in the database and the entities mentioned in the natural language question and the relationship between the two are converted into an interaction diagram. The specific steps are as follows:
[0021] First, the distance between the two question words in the natural language question is calculated. If the distance between the question words is less than the set maximum relationship distance, then the distance between the question words is set to the calculated first-order distance. If it exceeds the maximum relationship distance, then the relationship is set to no distance relationship between the question words. Secondly, based on the first-order distance relationship, the dependency relationship between the question words is obtained using the grammatical dependency tree. The dependency relationship is generally divided into three types. From the relative position of the two question words, the dependency relationship from the previous word to the next word is recorded as the backward relationship, and the dependency relationship from the next word to the previous word is recorded as the forward relationship. There is no dependency relationship between the question words and is recorded as empty. Finally, the dependency relationship is refined, and the four types of relationships about the main components of the sentence in the dependency relationship are marked. They are distinguished from the three major types of dependency relationships mentioned above to specially mark the dependency relationships of the main components in the sentence. The purpose is to make the relationship in the natural language question more refined. The refined grammatical information can provide additional context and semantic clues for the model, thereby improving its generalization and interpretability. Then the nodes and the relationships between nodes are represented in the form of a graph.
[0022] In step 3, the input sequence is converted into an interaction graph and then into edge embedding and node embedding. First, the input sequence is represented as an interaction graph, and then the graph is converted into the corresponding node embedding X and relation embedding R and initialized. This paper uses a pre-trained language model to obtain their representations.
[0023] Specifically, we flatten all questions and pattern items into a sequence, where columns belonging to the same table are grouped together: Type information t is also inserted before each pattern item i0 or Since each word is tokenized into subwords in PLM, an autonomous attention pooling layer is attached after PLM to obtain subword representations.
[0024] In step 4, the text-to-SQL generation method for reservoir data monitoring and early warning uses a relational graph attention network, and the specific steps are as follows:
[0025] (1) The attention mechanism is used to dynamically calculate the weights between a node and its neighboring nodes to better aggregate the information of neighboring nodes. In each layer, GAT calculates an attention coefficient for each node, which represents the importance between the node and its neighboring nodes. Then, these attention coefficients are used to perform a weighted summation of the features of the neighboring nodes to obtain a new representation of the node. The formula of GAT is as follows:
[0026]
[0027] in is the feature representation of node i in layer l, W (l) is the weight parameter of the lth layer, is the attention coefficient of node i to node j, and σ is the activation function, usually ReLU or LeakyReLU. The attention coefficient is calculated as follows:
[0028]
[0029] Where a is the self-learned attention parameter, represents the set of neighbor nodes of node i, and || represents the link operation.
[0030] (2) The relationship graph is composed of a set of nodes and the edges between them. Each node represents an entity and can be linked to other nodes, while the edges represent the relationships between nodes. By combining the features of the node and its adjacent nodes, the relationship score between each node and its adjacent nodes is calculated while maintaining the relative position information. By re-weighting and accumulating the scores, the information of adjacent nodes is aggregated, and the self-attention mechanism is used to enhance the expressiveness of node features, thereby achieving better results.
[0031] The relationship graph attention network used here mainly includes two modules, namely the node-centric graph module and the edge-centric graph module. The node-centric graph module represents entities in the form of nodes, and the edges represent the relationship between nodes. The edge-centric graph module represents the relationship between two entities in the form of nodes, and the entities are represented as the edges of a directed graph. Combining and superimposing the two graphs can capture the nodes and the relationship between nodes during training, and update the node and relationship embeddings at the same time.
[0032] In step 5, the text-to-SQL generation method for reservoir data monitoring and early warning adopts a dynamic edge attention pooling method to reduce excessive coupling of edge embedding, and the specific steps are as follows:
[0033] In order to avoid the situation where edge embeddings are over-coupled, a dynamic edge attention pooling method is used. This method uses the attention mechanism to dynamically calculate the importance of different edges in the graph, and then performs graph pooling operations based on the edge weights. The importance of different edges can be dynamically captured according to the structure of the graph, thereby improving the representation ability and performance of the graph neural network.
[0034] Before describing dynamic edge attention pooling, let's first give the notation of directed graphs. We use G = (V, E) to represent a directed graph, where V represents the set of nodes and E represents the set of edges. For each edge, we can define a corresponding attention weight to represent the importance of the relationship between node i and node j. The importance of the relationship here is dynamically calculated based on the features between the nodes, rather than being predefined. The edge attention score calculation formula can be described as follows:
[0035] e ij =LeakyReLU(w T [h i ||h j ])
[0036] where h i represents the feature representation of node i, || represents the link operation, W is the learned weight matrix, and LeakyReLU is the activation function used to enhance the nonlinear fitting ability of the model. According to the calculated edge attention score e ij , the edge attention weight can be calculated:
[0037]
[0038] Where N i Represents the set of neighboring nodes of node i. After obtaining the edge attention weight, the corresponding edges can be feature aggregated:
[0039]
[0040] Where W and b are the learned parameters, σ represents the activation function, and finally graph-level pooling is performed to obtain the final pooled graph representation:
[0041]
[0042] Where AGG represents the aggregation function. Through such dynamic edge attention pooling operations, we can effectively aggregate the information of different edges in the graph and weight them according to their importance, reducing the over-coupling of edge embeddings and thus obtaining a better graph representation.
[0043] In step 6, the text-to-SQL generation method for reservoir data monitoring and early warning uses the RAT layer to unify the two types of embeddings, and the specific steps are as follows:
[0044] First, the input is divided into NL questions, database patterns, and link relations. The model builds global reasoning about patterns and questions through a relation-aware self-attention mechanism to encode relational structures in given questions and database patterns. This mechanism enables the model to effectively encode the relational structure of database patterns and questions, thereby capturing the complex interactions between them. RATSQL defines the relationship between different inputs, and uses the RAT(·) function to obtain a unified representation of questions and patterns. The three inputs are represented by a directed graph, and a pre-trained language model, such as BERT, is used to obtain the embeddings of nodes and relationships in the input, and a relational graph neural network is used to update them. Then, RAT is used to unify the updated embeddings. The node embedding and the relationship embedding are linked into a longer sequence representation, which is the initial input of RAT. After passing through the RAT module, the unified representation of the two embeddings is obtained as follows:
[0045] P (M) =RAT(concat(X (N) , R (N) ))
[0046] A computer device, characterized in that: the computer device includes a memory, a processor and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the text-to-SQL generation method for reservoir data monitoring and early warning as described above is implemented.
[0047] A computer-readable storage medium, characterized in that: the computer-readable storage medium stores a computer program for executing the text-to-SQL generation method for reservoir data monitoring and early warning as described above.
[0048] Beneficial effects: Compared with the prior art, the present invention has the following advantages:
[0049] (1) User-friendliness: The text-to-SQL method allows users to query and instruct through natural language without having to understand complex database query languages or professional knowledge. This improves the ease of use of the system and enables more people to conveniently use the reservoir data monitoring and early warning system.
[0050] (2) Efficiency: The text-to-SQL method can quickly convert natural language commands into SQL query statements, thereby achieving rapid retrieval and analysis of reservoir data. Compared with traditional manual queries or operations using a graphical user interface, the text-to-SQL method is more efficient.
[0051] (3) Personalization: The reservoir data monitoring and early warning system based on the text-to-SQL method can flexibly generate corresponding SQL query statements based on the natural language commands input by the user, and return personalized data results that meet the user's needs. This allows users to perform customized queries and analyses according to their own needs.
[0052] (4) Generalization: The text-to-SQL method can better capture the structure and grammatical rules of the question by utilizing structured information such as the grammatical dependency tree, thus improving the generalization ability of the model. This means that the system can more accurately understand the user's intention when faced with different types of natural language commands and generate corresponding SQL query statements.
[0053] (4) Intelligence: The reservoir data monitoring and early warning system based on the text-to-SQL method can be combined with artificial intelligence technology to achieve intelligent data analysis and prediction. The system can analyze and train models based on historical data and real-time monitoring data, thereby achieving intelligent monitoring and early warning of reservoir status, improving prediction accuracy and reliability. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 A flow chart of preprocessing reservoir data according to the present invention;
[0055] Figure 2 Schematic diagram of (a) grammatical restriction and (b) grammatical dependency tree of natural language problem in the present invention;
[0056] Figure 3 A flowchart of the process of generating a SQL query from a natural language question in the present invention;
[0057] Figure 4 A schematic diagram of coupling for reducing edge embedding in an example implementation of the present invention. DETAILED DESCRIPTION
[0058] The present invention is further explained below in conjunction with specific embodiments. It should be understood that these embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention. After reading the present invention, various equivalent forms of modifications to the present invention by those skilled in the art all fall within the scope defined by the claims attached to this application.
[0059] like Figure 1 As shown in the figure, the text-to-SQL generation method for reservoir data monitoring and early warning includes the following steps:
[0060] Step 1: Figure 1As shown, data processing of the data contained in the reservoir database and commonly used natural language commands mainly involves two steps: data cleaning and preprocessing, and natural language command processing and conversion. The processed data set contains the tables and columns contained in the reservoir database, as well as commonly used natural language commands and corresponding SQL queries.
[0061] First, data cleaning and preprocessing are performed. Deleting duplicate data means identifying and deleting duplicate records in the database. For example, if there are two records with the same date and water level in the database, one of the records is deleted. Processing missing values means filling, deleting or interpolating missing data. For example, for missing water level data, it can be filled by interpolation method based on water level data at adjacent time points. Correcting erroneous data means identifying and correcting erroneous data in the database. For example, if there are obviously erroneous water level data in the database, such as negative values or values beyond a reasonable range, it is corrected to the correct value. Data formatting means converting data in different formats into a unified format. For example, date data is unified into the format of YYYY-MM-DD, and water level data is unified into the format of floating point numbers. Data normalization means normalizing or standardizing data to eliminate differences between different dimensions. For example, water level data is normalized to a range between 0 and 1. Outlier processing means detecting and processing outliers to prevent them from affecting data analysis results. For example, water level data that deviates abnormally from the normal range can be processed by smoothing or deleting outliers. Data integration is the integration of data from different data sources into a unified database. For example, water level data from different monitoring sites can be integrated into the same database table.
[0062] Secondly, natural language command processing and conversion are performed. Semantic understanding is to identify keywords and phrases in commands to understand the user's intentions and needs. For example: for the command "query today's water level data", syntactic analysis identifies the keywords as "query" and "water level data", and semantic parsing understands that the user needs to query today's water level data. Query generation is to generate the corresponding SQL query statement, mapping the information entered by the user to the parameter position in the SQL query statement. For example: Generate an SQL query statement based on the results of semantic parsing, such as "SELECT * FROM water level data WHERE date = '2022-04-10'".
[0063] Step 2: Use the grammatical dependency tree to obtain the grammatical information contained in the question, and then convert the information contained in the database and the entities mentioned in the natural language question and the relationship between the two into an interaction graph. The grammatical dependency tree structure of the question is as follows: Figure 2 shown.
[0064] First, the distance between the two question words in the natural language question is calculated. If the distance between the question words is less than the set maximum relationship distance, then the distance between the question words is set to the calculated first-order distance. If it exceeds the maximum relationship distance, then the relationship is set to no distance relationship between the question words. Secondly, based on the first-order distance relationship, the dependency relationship between the question words is obtained using the grammatical dependency tree. The dependency relationship is generally divided into three types. From the relative position of the two question words, the dependency relationship from the previous word to the next word is recorded as the backward relationship, and the dependency relationship from the next word to the previous word is recorded as the forward relationship. There is no dependency relationship between the question words and it is recorded as empty. Finally, the dependency relationship is refined, and the four types of relationships about the main components of the sentence in the dependency relationship are annotated. They are distinguished from the three major types of dependency relationships mentioned above to specially mark the dependency relationships of the main components in the sentence. The purpose is to make the relationship in the natural language question more refined. The refined grammatical information can provide additional context and semantic clues for the model, thereby improving its generalization and interpretability.
[0065] Step 3: Convert the input sequence into an interaction graph and convert it into edge embedding and node embedding. First, the input sequence is represented as an interaction graph, and then the graph is converted into the corresponding node embedding X and relationship embedding R and initialized. This paper uses the pre-trained language model to obtain their representation.
[0066] Specifically, if Figure 3 As shown in the input module in , all questions and pattern items are flattened into a sequence, where columns belonging to the same table are together: Type information t is also inserted before each pattern item i0 or Since each word is tokenized into subwords in PLM, an autonomous attention pooling layer is attached after PLM to obtain subword representations.
[0067] Step 4: The text-to-SQL generation method for reservoir data monitoring and early warning uses a graph attention network. The dual graph attention network is used as the basic architecture of the model, and the obtained node embedding and edge embedding are input into the network, which can effectively capture the relationship and semantic information between words in the sentence. Figure 3As shown in the figure, the dual relational graph attention network representation and query generation algorithm are combined to achieve intelligent query generation. In the process of generating SQL query statements, the context and contextual information of the natural language commands entered by the user are taken into account, so as to generate more accurate and reasonable query statements. Dynamic weight adjustment of the graph can better capture the importance of different words and improve the accuracy and efficiency of query generation. The network combines the advantages of graph neural networks and attention mechanisms, can learn rich semantic representations in text data, and better consider the correlation between different words in the sentence when generating SQL query statements.
[0068] Step 5: Reduce the over-coupling of edge embeddings by using dynamic edge attention pooling, such as Figure 4 As shown in the figure, in the process of generating SQL query statements, dynamic edge attention pooling is applied to the representation of edge embeddings to dynamically adjust the importance of different edges. By learning the attention weight of each edge, the model can dynamically adjust the importance of the edge according to the specific task and input data, thereby reducing unnecessary edge embeddings and reducing the complexity and overfitting risk of the model. Before describing dynamic edge attention pooling, the notation of the directed graph is first given. The directed graph is represented by G = (V, E), where V represents the node set and E represents the edge set. For each edge, a corresponding attention weight can be defined to represent the importance of the relationship between node i and node j. The relationship importance here is dynamically calculated based on the features between the nodes, rather than being predefined. The edge attention score calculation formula can be described as follows:
[0069] e ij =LeakyReLU(w T [h i ||h j ])
[0070] where h i represents the feature representation of node i, || represents the link operation, W is the learned weight matrix, and LeakyReLU is the activation function used to enhance the nonlinear fitting ability of the model. According to the calculated edge attention score e ij , the edge attention weight can be calculated:
[0071]
[0072] Where N i Represents the set of neighboring nodes of node i. After obtaining the edge attention weight, the corresponding edges can be feature aggregated:
[0073]
[0074] Where W and b are the learned parameters, σ represents the activation function, and finally graph-level pooling is performed to obtain the final pooled graph representation:
[0075]
[0076] Where AGG represents the aggregation function. Through such a dynamic edge attention pooling operation, the information of different edges in the graph can be effectively aggregated and weighted according to their importance, reducing the over-coupling of edge embeddings, thereby obtaining a better graph representation. For example, for the sentence "Query today's water level data", when generating SQL query statements, the dynamic edge attention pooling method can dynamically adjust the importance of the edge according to the relationship between each word in the sentence. If the relationship between the keywords "today" and "water level data" is very important for the goal of generating SQL query statements, then the dynamic edge attention pooling method will give this edge a higher weight, thereby better capturing the user's intentions and needs.
[0077] Step 6: Use the RAT layer to unify the two types of embeddings to better integrate the relationship and semantic information between nodes, thereby improving the performance and generalization ability of the model. RAT is an improvement on the traditional Transformer model. It uses relation-aware self-attention to enhance ordinary self-attention by introducing relational embeddings in key and value entries. The formula for calculating the attention score is as follows:
[0078]
[0079] Where W is the trainable parameter matrix, h is the number of heads, It is the calculated attention score, from element x i to element x j The edge of r ij,K and r ij,V The final output is The calculation is as follows:
[0080]
[0081] where r ij,K and r ij,V Shared among different attention heads, for each layer of RAT, the update process can be simply expressed as:
[0082]
[0083] in is the relationship matrix between tokens, R ij Represents the relationship between the i-th token and the j-th token.
[0084] The node embedding and edge embedding are uniformly represented through the RAT layer. The RAT layer can take into account the relationship between nodes and the relationship between edges at the same time, thereby generating a unified representation vector. For example, the RAT layer can capture the relationship between monitoring points.
Claims
1. A text-to-SQL generation method for reservoir data monitoring and early warning, characterized in that: Based on the information contained in the reservoir database and some commonly used natural language commands, the model is trained to complete the generation of text to SQL. The steps include: Step 1: Data cleaning and dataset creation: Data processing of the data contained in the reservoir database and commonly used natural language commands mainly involves two steps: data cleaning and preprocessing, and natural language command processing and conversion. The processed dataset contains the tables and columns contained in the reservoir database, as well as commonly used natural language commands and corresponding SQL queries. Step 2: Use the grammatical dependency tree to obtain the grammatical information contained in the question, and then convert the information contained in the database and the entities mentioned in the natural language question and the relationship between the two into an interaction graph. Step 3: Convert the interaction graph into edge embedding and node embedding: Take the labels of the entire input sequence as vertices and the relationships between sequence labels as edges, so as to incorporate various types of relationships into the model. Step 4: Applying the Relational Graph Attention Network: The model uses the Relational Graph Attention Network, which mainly consists of two modules, a node-centric graph module and an edge-centric graph module. By combining and then superimposing the two graphs, the nodes and the relationships between them can be captured during training, while updating the node and relationship embeddings. Step 5: Reduce the over-coupling of edge embeddings by using the dynamic edge attention pooling method, which uses the attention mechanism to dynamically calculate the importance of different edges in the graph, and then performs graph pooling operations based on the edge weights. The importance of different edges can be captured dynamically based on the structure of the graph, thereby improving the representation ability and performance of the graph neural network. Step 6: Use the RAT layer to unify the two types of embeddings: Link the node embedding and the relationship embedding into a longer sequence representation, which is the initial input of the RAT. After passing through the RAT module, the final result is a unified representation of the two embeddings. Step 7: Decode using a decoder based on grammar generation: In order to eliminate the mismatch between the intention of natural language expression and the implementation details of SQL, a domain-specific language called SemQL is used as an intermediate representation between NL problems and SQL, which is essentially an abstract syntax tree. SemQL can represent SQL statements in the form of a tree, first generating the most important part of the SQL query, and then filling it in, so that when synthesizing the final SQL statement, the grammatical constraints are added, and finally the correct SQL query statement is generated.
2. The text-to-SQL generation method for reservoir data monitoring and early warning according to claim 1 is characterized in that: The specific steps for data cleaning and preprocessing as well as natural language command processing and conversion are as follows: For the reservoir database, data cleaning is first performed, including deleting duplicate data, processing missing values, and correcting erroneous data. Then data preprocessing is performed, including data formatting, data normalization, outlier processing, and data integration. Natural language commands are processed, first semantic understanding is performed, including syntactic analysis and semantic parsing. Then query generation is performed, including query construction and parameter mapping. The toolkit Stanza is used to preprocess the questions, table names, and column names contained in the dataset so that the natural language can be tokenized and lemmatized.
3. The text-to-SQL generation method for reservoir data monitoring and early warning according to claim 1 is characterized in that: The specific steps of using the grammatical dependency tree to obtain the grammatical information contained in the question and then converting the information contained in the database and the entities mentioned in the natural language question and the relationship between the two into an interaction graph are as follows: First, the distance between the two question words in the natural language question is calculated. If the distance between the question words is less than the set maximum relationship distance, then the distance between the question words is set to the calculated first-order distance. If it exceeds the maximum relationship distance, then the relationship is set to no distance relationship between the question words. Secondly, based on the first-order distance relationship, the dependency relationship between the question words is obtained using the grammatical dependency tree. The dependency relationship is generally divided into three types. From the relative position of the two question words, the dependency relationship from the previous word to the next word is recorded as the backward relationship, and the dependency relationship from the next word to the previous word is recorded as the forward relationship. There is no dependency relationship between the question words and is recorded as empty. Finally, the dependency relationship is refined, and the four types of relationships about the main components of the sentence in the dependency relationship are marked. They are distinguished from the three major types of dependency relationships mentioned above to specially mark the dependency relationships of the main components in the sentence. The purpose is to make the relationship in the natural language question more refined. The refined grammatical information can provide additional context and semantic clues for the model, thereby improving its generalization and interpretability. Then the nodes and the relationships between nodes are represented in the form of a graph.
4. The text-to-SQL generation method for reservoir data monitoring and early warning according to claim 1 is characterized in that: Convert the input sequence into an interaction graph and convert it into edge embedding and node embedding. Convert the graph obtained above into the corresponding node embedding X and relationship embedding R and initialize them. Use the pre-trained language model to obtain their representation. Specifically, all questions and pattern items are flattened into a sequence, with columns belonging to the same table together: Type information t is also inserted before each pattern item i0 or Since each word is tokenized into subwords in PLM, an autonomous attention pooling layer is attached after PLM to obtain subword representations.
5. The text-to-SQL generation method for reservoir data monitoring and early warning according to claim 1 is characterized in that: Apply the graph attention network. The specific steps are as follows: Step 1: Use the attention mechanism to dynamically calculate the weights between a node and its neighboring nodes to better aggregate the information of neighboring nodes. In each layer, GAT calculates an attention coefficient for each node, which indicates the importance between the node and its neighboring nodes. Then, these attention coefficients are used to perform a weighted summation of the features of the neighboring nodes to obtain a new representation of the node. The formula of GAT is as follows: in is the feature representation of node i in the ,th layer, W (l) is the weight parameter of the lth layer, is the attention coefficient of node i to node j, and σ is the activation function, usually ReLU or LeakyReLU. The attention coefficient is calculated as follows: Where a is the self-learned attention parameter, represents the set of neighbor nodes of node i, and || represents the link operation. Step 2: The relationship graph is composed of a set of nodes and the edges between them. Each node represents an entity and can be linked to other nodes, while the edges represent the relationship between nodes. By combining the features of the node and its adjacent nodes, the relationship score between each node and its adjacent nodes is calculated while maintaining the relative position information. By re-weighting and accumulating the scores, the information of adjacent nodes is aggregated, and the self-attention mechanism is used to enhance the expressiveness of node features, thereby achieving better results. The relationship graph attention network used here mainly includes two modules, namely the node-centric graph module and the edge-centric graph module. The node-centric graph module represents entities in the form of nodes, and the edges represent the relationship between nodes. The edge-centric graph module represents the relationship between two entities in the form of nodes, and the entities are represented as the edges of a directed graph. Combining and superimposing the two graphs can capture the nodes and the relationship between nodes during training, and update the node and relationship embeddings at the same time.
6. The text-to-SQL generation method for reservoir data monitoring and early warning according to claim 1 is characterized in that: To reduce the over-coupling of edge embeddings, a dynamic edge attention pooling method is used. The specific steps are as follows: In order to avoid the situation where edge embeddings are over-coupled, a dynamic edge attention pooling method is used. This method uses the attention mechanism to dynamically calculate the importance of different edges in the graph, and then performs graph pooling operations based on the edge weights. The importance of different edges can be dynamically captured according to the structure of the graph, thereby improving the representation ability and performance of the graph neural network. Before describing dynamic edge attention pooling, we first give the notation of directed graphs. We use G = (V, E) to represent a directed graph, where V represents the set of nodes and E represents the set of edges. For each edge, we can define a corresponding attention weight to represent the importance of the relationship between node i and node j. The importance of the relationship here is dynamically calculated based on the features between the nodes, rather than being predefined. The edge attention score calculation formula can be described as follows: and ij =LeakyReLU(in T [h i ||h j ]) where h i represents the feature representation of node i, || represents the link operation, w is the learned weight matrix, and LeakyReLU is the activation function used to enhance the nonlinear fitting ability of the model. According to the calculated edge attention score e ij , the edge attention weight can be calculated: Where N i Represents the set of neighboring nodes of node i. After obtaining the edge attention weight, the corresponding edges can be feature aggregated: Where W and b are the learned parameters, σ represents the activation function, and finally graph-level pooling is performed to obtain the final pooled graph representation: Where AGG represents the aggregation function. Through such dynamic edge attention pooling operations, we can effectively aggregate the information of different edges in the graph and weight them according to their importance, reducing the over-coupling of edge embeddings and thus obtaining a better graph representation.
7. The text-to-SQL generation method for reservoir data monitoring and early warning according to claim 1 is characterized in that: The RAT layer is used to unify the two types of embeddings. The specific steps are as follows: First, the input is divided into NL questions, database patterns, and link relations. The model builds global reasoning about patterns and questions through a relation-aware self-attention mechanism to encode relational structures in given questions and database patterns. This mechanism enables the model to effectively encode the relational structure of database patterns and questions, thereby capturing the complex interactions between them. RATSQL defines the relationship between different inputs, and uses the RAT(·) function to obtain a unified representation of questions and patterns. The three inputs are represented by a directed graph, and a pre-trained language model, such as BERT, is used to obtain the embeddings of nodes and relationships in the input, and a relational graph neural network is used to update them. Then, RAT is used to unify the updated embeddings. The node embedding and the relationship embedding are linked into a longer sequence representation, which is the initial input of RAT. After passing through the RAT module, the unified representation of the two embeddings is obtained as follows: P (M) =RAT(concat(X (N) ,R (N) ))。 8. A computer device, characterized in that: The computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the text-to-SQL generation method for reservoir data monitoring and early warning as described in any one of claims 1 to 8 is implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the text-to-SQL generation method for reservoir data monitoring and early warning as described in any one of claims 1-8.
Citation Information
Patent Citations
Real domain three-dimensional point cloud object recognition algorithm based on hierarchical attention sampling strategy
CN113688700A
Construction method and application of SQL statement generation model of natural Chinese language
CN114020768A
Database query method and system based on self-attention syntactic perception
CN116910086A
SQL (Structured Query Language) generation method for injecting optimal mode item and historical interaction information
CN117033423A
SQL statement generation method and device based on relation perception
CN117493372A