Query statement generation method and device and computing equipment

Through structured statement generation model and multi-task training, the problem of insufficient adaptability of query statement generation method to natural statement diversity is solved, and high accuracy and robust query statement generation is achieved, which improves the accuracy and efficiency of data query.

CN120256456APending Publication Date: 2025-07-04TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410026064.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-03
Publication Date
2025-07-04

AI Technical Summary

Technical Problem

The existing query statement generation methods are not adaptable to the diversity of natural statements, which leads to the low accuracy of the generated query statements and is difficult to meet the natural statement conversion requirements of different expression methods.

Method used

The structured statement generation model is adopted, and the deep learning model is trained, and structured statements are used as intermediate languages. After generating structured statements, they are converted into query statements according to the grammar of the query language, including multiple word classes and words, and a multi-task training method is designed to improve robustness and accuracy.

Benefits of technology

It improves the accuracy and robustness of query statement generation, ensures that the query statement complies with the syntax rules of the query language, reduces generation errors, and improves the accuracy and efficiency of data queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120256456A_ABST
    Figure CN120256456A_ABST
Patent Text Reader

Abstract

The invention discloses a query statement generation method and device. According to the method, firstly, a natural statement containing query information is obtained, and the natural statement describes the query information in a natural language; then, a structured statement corresponding to the natural statement is generated according to the natural statement by utilizing a structured statement generation model, the structured statement comprises a plurality of word classes and words corresponding to each word class, and the structured statement generation model is a trained deep learning model; finally, a query statement is determined based on the word classes in the structured statement and the corresponding words, and the query statement describes query information in a query language. Through the embodiment of the invention, query statement generation with higher accuracy and stronger robustness can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technologies, and particularly to a method and apparatus for generating query statements, a computing device, a computer-readable storage medium, and a computer program product. Background Art

[0002] When performing data queries, it is usually necessary to convert natural statements of people (i.e., statements described in natural language) into query statements that can be recognized by machines (e.g., statements described in query languages such as structured query language). Since natural statements do not have a fixed format and standard (e.g., the speaking habits and ways of different people are usually different), it has always been difficult to generate corresponding query statements according to natural statements. For example, existing methods for generating query statements are insufficient in adapting to the diversity of natural statements. When the expression of a natural statement changes slightly, it may be very difficult to accurately determine its corresponding query statement. Summary of the Invention

[0003] The applicant has found that there has always been a hope in this field to propose a method for generating query statements with high accuracy, strong robustness, and good adaptability. In view of this, this application provides a method and apparatus for generating query statements, a computing device, a computer-readable storage medium, and a computer program product, expecting to alleviate or overcome some or all of the above-mentioned defects and other possible defects.

[0004] According to one aspect of this application, a method for generating query statements is provided. The method for generating query statements includes: obtaining a natural statement containing query information, where the natural statement describes the query information in natural language; using a structured statement generation model to generate a structured statement corresponding to the natural statement according to the natural statement, the structured statement includes multiple word classes and the words corresponding to each word class, and the structured statement generation model is a trained deep learning model; determining a query statement based on the word classes and the corresponding words in the structured statement, where the query statement describes the query information in a query language.

[0005] According to another aspect of this application, a query statement generation apparatus is provided. The query statement generation apparatus includes: a first obtaining module configured to obtain a natural statement containing query information, where the natural statement describes the query information in natural language; a structured statement generation module configured to use a structured statement generation model to generate a structured statement corresponding to the natural statement according to the natural statement, the structured statement includes multiple word classes and the words corresponding to each word class, and the structured statement generation model is a trained deep learning model; a query statement generation module configured to determine a query statement based on the word classes and the corresponding words in the structured statement, where the query statement describes the query information in a query language.

[0006] In a query statement generation device according to some embodiments of the present application, the structured statement generation model is obtained by training a deep learning model using a training sample set; the training sample set includes a first training sample set, and the first training sample set includes a plurality of first-type training sample pairs, and each first-type training sample pair includes a natural statement and its corresponding structured statement.

[0007] In a query statement generation device according to some embodiments of the present application, the first-type training sample pairs are determined through the following steps: obtaining initial training sample pairs, where the initial training sample pairs include natural statements and their corresponding structured statements, and each part of speech and the corresponding words in the structured statements correspond to part of the content in the natural statements; taking the initial training sample pairs as the first current training sample pairs; performing a partial replication operation on the first current training sample pairs, and determining the first current training sample pairs after the partial replication operation as one first-type training sample pair; or taking the initial training sample pairs as the second current training sample pairs; performing a partial deletion operation on the second current training sample pairs, and determining the second current training sample pairs after the partial deletion operation as another first-type training sample pair; or taking the initial training sample pairs as the third current training sample pairs; performing a partial replacement operation on the third current training sample pairs, and determining the third current training sample pairs after the partial replacement operation as another first-type training sample pair. The partial replication operation includes: replicating the first part of the content in the natural statement of the first current training sample pair so that the replicated natural statement has repeated first part of the content, and determining the natural statement with the repeated first part of the content and the structured statement of the first current training sample pair as the first current training sample pair after the partial replication operation. The partial deletion operation includes: deleting the first part of the content in the natural statement of the second current training sample pair so that the natural statement after deletion no longer has the first part of the content; deleting the part of speech and the words corresponding to the first part of the content in the structured statement of the second current training sample pair so that the structured statement after deletion no longer has the part of speech and the words corresponding to the first part of the content; and determining the natural statement after deletion and the structured statement after deletion as the second current training sample pair after the partial deletion operation. The partial replacement operation includes: replacing the first part of the content in the natural statement of the third current training sample pair with a first phrase as the natural statement after the partial replacement operation, where the part of speech of the structured statement corresponding to the first phrase is the same as the part of speech of the structured statement corresponding to the first part of the content, but the words of the structured statement corresponding to the first phrase are different from the words of the structured statement corresponding to the first part of the content; replacing the words corresponding to the first part of the content in the structured statement of the third current training sample pair with the words of the structured statement corresponding to the first phrase as the structured statement after the partial replacement operation; and determining the natural statement after the partial replacement operation and the structured statement after the partial replacement operation as the third current training sample pair after the partial replacement operation.

[0008] In a query statement generation device according to some embodiments of the present application, the structured statement generation model is obtained by the deep learning model performing a first training step using a first training sample set. The first training step includes: inputting the natural statements of the first type of training sample pairs into the deep learning model to obtain the actual output of the deep learning model; using the structured statements of the first type of training sample pairs as the expected output of the deep learning model, determining the difference between the actual output and the expected output as the first difference of the first type of training sample pairs; determining the first difference of each first type of training sample pair in the first training sample set, accumulating the first differences corresponding to all the first type of training sample pairs in the first training sample set, and determining the accumulation result as the first loss; adjusting the model parameters of the deep learning model until the first loss is less than or equal to a first predetermined threshold; and determining the deep learning model with its model parameters adjusted as the structured statement generation model.

[0009] In a query statement generation device according to some embodiments of the present application, the training sample set further includes a second training sample set. The second training sample set includes a plurality of second type of training sample pairs, and each second type of training sample pair includes an initial natural statement and its corresponding canonical natural statement, and the canonical natural statement describes the query information included in the initial natural statement in a predetermined expression. The structured statement generation model is further obtained by the deep learning model performing a second training step using the second training sample set. The second training step includes: inputting the initial natural statements of the second type of training sample pairs into the deep learning model to obtain the actual output of the deep learning model; using the canonical natural statements of the second type of training sample pairs as the expected output of the deep learning model, determining the difference between the actual output and the expected output as the second difference of the second type of training sample pairs; determining the second difference of each second type of training sample pair in the second training sample set, accumulating the second differences corresponding to all the second type of training sample pairs in the second training sample set, and determining the accumulation result as the second loss; adjusting the model parameters of the deep learning model until the second loss is less than or equal to a second predetermined threshold; and determining the deep learning model with its model parameters adjusted as the structured statement generation model.

[0010] In a query statement generation device according to some embodiments of the present application, the training sample set further includes a third training sample set. The third training sample set includes a plurality of third-type training sample pairs. Each third-type training sample pair includes a structured statement and its corresponding canonical natural statement. The canonical natural statement describes the query information included in the structured statement in natural language in a predetermined expression way. The structured statement generation model is further obtained by performing a third training step on the deep learning model using the third training sample set. The third training step includes: inputting the structured statement of the third-type training sample pair into the deep learning model to obtain the actual output of the deep learning model; using the canonical natural statement of the third-type training sample pair as the expected output of the deep learning model, and determining the difference between the actual output and the expected output as the third difference of the third-type training sample pair; determining the third difference of each third-type training sample pair in the third training sample set, accumulating the third differences of all third-type training sample pairs in the third training sample set, and determining the accumulated result as the third loss; adjusting the model parameters of the deep learning model until the third loss is less than or equal to a third predetermined threshold; and determining the deep learning model with its model parameters adjusted as the structured statement generation model.

[0011] In a query statement generation device according to some embodiments of the present application, the parts of speech of the structured statement include one or more of: the table to be queried, the dimension to be queried, the condition to be queried, the operation on the data, and the query mode.

[0012] In a query statement generation device according to some embodiments of the present application, determining the query statement based on the parts of speech and corresponding words in the structured statement includes: determining the composition rule of the words corresponding to the parts of speech in the query language; and organizing the words of each part of speech in the structured statement based on the composition rule to determine the query statement corresponding to the structured statement.

[0013] In a query statement generation device according to some embodiments of the present application, the query language includes a structured query language, and the structured statement organizes the multiple parts of speech and the corresponding words included therein in a domain-specific language.

[0014] According to another aspect of the present application, a data query method is provided. The data query method includes: obtaining a natural statement for querying data; determining the query statement corresponding to the natural statement by using the query statement generation method in any embodiment of the present application; and querying the corresponding data in the database by using the query statement.

[0015] According to another aspect of the present application, a data query device is provided. The data query device includes: a second acquisition module configured to acquire a natural statement for querying data; a query statement determination module configured to determine a query statement corresponding to the natural statement by using the query statement generation method of any one of the embodiments in the present application; and a data query module configured to query corresponding data in a database by using the query statement.

[0016] According to another aspect of the present application, a computing device is provided, including: a memory configured to store computer-executable instructions; and a processor configured to execute the steps of the query statement generation method according to some embodiments of the present application when the computer-executable instructions are executed by the processor.

[0017] According to another aspect of the present application, a computer-readable storage medium is provided, which stores computer-executable instructions, and the computer-executable instructions, when executed, implement the steps of the query statement generation method according to some embodiments of the present application.

[0018] According to another aspect of the present application, a computer program product is provided, including a computer program, and the computer program, when executed by a processor, implements the steps of the query statement generation method according to some embodiments of the present application.

[0019] In the query statement generation method and device according to some embodiments of the present application, a machine learning model (such as a deep learning model, a large language model, etc.) is used to receive a natural statement and generate a corresponding structured statement accordingly, and then the structured statement is converted into a corresponding query statement according to the grammar of the query language. The structured statement uses a structured intermediate language, which has multiple predefined word classes, that is, has certain limitations, which is beneficial to training the deep learning model to obtain better accuracy. In addition, because its word classes and words have the characteristics of simple structure and clear semantics, it can be automatically converted into a query statement according to the grammar of the query language, effectively avoiding errors in directly generating query statements. It can be seen that through the method proposed in the present application, the accuracy and robustness of query statement generation can be improved simultaneously, and further the accuracy and efficiency of data query can be improved.

[0020] According to the embodiments described below, these and other advantages of the present application will become clear, and these and other advantages of the present application are illustrated with reference to the embodiments described below. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Embodiments of the present application will now be described in more detail and with reference to the drawings, where:

[0022] Figure 1A A schematic diagram of a query statement generation method in related art solutions is shown;

[0023] Figure 1B A schematic diagram showing a query statement generation method according to some embodiments of the present application;

[0024] Figure 2 An exemplary application scenario of a query statement generation method according to some embodiments of the present application;

[0025] Figure 3 An exemplary flowchart showing a query statement generation method according to some embodiments of the present application;

[0026] Figure 4 A schematic diagram showing the determination of a first training sample set according to some embodiments of the present application;

[0027] Figure 5 A schematic diagram showing the determination of a structured statement generation model according to some embodiments of the present application;

[0028] Figure 6A and 6B A schematic diagram of an application scenario of a query statement generation method according to some embodiments of the present application;

[0029] Figure 7 A schematic diagram showing data query according to some embodiments of the present application;

[0030] Figure 8 An exemplary structural block diagram showing a query statement generation device according to some embodiments of the present application;

[0031] Figure 9 An exemplary structural block diagram showing a data query device according to some embodiments of the present application; and,

[0032] Figure 10 An example system is shown, which includes an example computing device representing one or more systems and / or devices that can implement the various methods described herein. Detailed implementation manners

[0033] Example embodiments will now be described more fully with reference to the accompanying drawings. However, the example embodiments can be implemented in various forms and should not be construed as limited to the embodiments set forth herein; rather, these embodiments are provided so that this application will be thorough and complete, and will fully convey the concept of the example embodiments to those skilled in the art. Like reference numerals in the figures denote like or similar parts, and thus their repeated description will be omitted.

[0034] In addition, the described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of the embodiments of the present application. However, those skilled in the art will recognize that the technical solutions of the present application may be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. may be employed. In other cases, well-known methods, devices, implementations, or operations are not shown or described in detail to avoid obscuring aspects of the present application.

[0035] The block diagrams shown in the drawings are only functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0036] The flowcharts shown in the drawings are only illustrative and do not necessarily include all the promotional information and operations / steps, nor are they necessarily executed in the order described. For example, some operations / steps may be decomposed, while some operations / steps may be combined or partially combined, so the actual execution order may change according to the actual situation.

[0037] It should be understood that although terms such as first, second, and third may be used herein to describe various components, these components should not be limited by these terms. These terms are used to distinguish one component from another. Thus, the first component discussed below may be referred to as the second component without departing from the teachings of the concept of the present application. As used herein, the term "and / or" and similar terms include any, multiple, and all combinations of the associated listed items.

[0038] Those skilled in the art can understand that the drawings are only schematic diagrams of exemplary embodiments, and the modules or processes in the drawings are not necessarily essential for implementing the present application, so they cannot be used to limit the protection scope of the present application.

[0039] Before introducing the embodiments of the present application in detail, some terms involved in the embodiments of the present application are first explained to facilitate the understanding of those skilled in the art.

[0040] Machine Learning (ML) is an interdisciplinary field that involves multiple disciplines such as probability theory, statistics, approximation theory, convex analysis, and algorithm complexity theory. It specifically studies how computers can simulate or implement human learning behaviors to acquire new knowledge or skills and reorganize the existing knowledge structure to continuously improve their own performance. Machine learning is the core of artificial intelligence and the fundamental way to endow computers with intelligence, and its applications cover all fields of artificial intelligence. Machine learning and deep learning usually include technologies such as artificial neural networks, belief networks, reinforcement learning, transfer learning, and inductive learning.

[0041] Deep Learning (DL): Deep learning is a new research direction in the field of Machine Learning (ML). It is introduced into machine learning to make it closer to the original goal - Artificial Intelligence (AI). Deep learning is about learning the internal laws and representation levels of sample data, and the information obtained during these learning processes is very helpful for the interpretation of data such as text, images, and sounds. Its ultimate goal is to enable machines to have the ability to analyze and learn like humans, and be able to recognize data such as text, images, and sounds. Deep learning is a complex machine learning algorithm, and the effects achieved in speech and image recognition far exceed those of previous related technologies. Deep learning has achieved many results in search technology, data mining, machine learning, machine translation, natural language processing, multimedia learning, speech, recommendation and personalization technologies, and other related fields.

[0042] Large Language Model (LLM): A large language model refers to a deep learning model trained with a large amount of text data that can generate natural language text or understand the meaning of language text. Large language models can handle various natural language tasks such as text classification, question answering, and dialogue, and are an important approach to artificial intelligence.

[0043] Natural language: Natural language usually refers to a language that naturally evolves with culture. Chinese and English are examples of natural languages. Sometimes all languages used by humans (including the languages that naturally evolve with culture mentioned above, as well as artificial languages) are regarded as "natural" languages, as opposed to "artificial" languages designed for computers such as programming languages. This usage can be seen in the term natural language processing. Natural language is the main tool for human communication and thinking.

[0044] Domain-Specific Language (DSL): A domain-specific language is a language designed for a context in a specific domain. Generally speaking, it includes word classes for that domain and words corresponding to each word class. Using these predefined word classes and the words corresponding to each word class, the intention of a certain part of the system can be communicated more clearly because it has restricted expressiveness.

[0045] Structured Query Language (SQL): Structured Query Language is a special-purpose programming language, a database query and programming language used to access data and query, update, and manage relational database systems. Structured Query Language is a high-level non-procedural programming language that allows users to work on high-level data structures. It does not require users to specify the storage method of data, nor does it require users to understand the specific data storage method. Therefore, different database systems with completely different underlying structures can use the same Structured Query Language as the interface for data input and management. Structured Query Language statements can be nested, which gives it great flexibility and powerful functionality.

[0046] Figure 1A The figure shows a schematic diagram of a query statement generation method in related technical solutions. As Figure 1A shown, in related technical solutions, a machine learning model is trained so that the trained machine learning model generates corresponding query statements according to the input natural statements. However, in related technical solutions, the accuracy of generating query statements is usually not high. Even if the machine learning model is selected as a deep learning model with a very high complexity (such as a large language model, etc.), its test accuracy is generally less than 80%. The reason for this, the applicant believes, is that the expression of natural language varies from person to person, and the corpus of query language is too large and generalized. Therefore, both the input and output of the machine learning model have strong uncertainty. Therefore, the accuracy of the directly trained machine learning model for generating query statements is always not high. In addition, although the query language (such as SQL) has a large corpus and flexible content, because it needs to be recognized by machines, it also has certain grammar. Directly using a machine learning model to generate query statements, even if the generated query statements contain the query information in the natural statements, there are still certain challenges in whether the generated query statements conform to the grammar characteristics of the query language and can be recognized by the database.

[0047] Therefore, this application proposes a query statement generation method to overcome these problems in related technical solutions.

[0048] Figure 1B The figure shows a schematic diagram of a query statement generation method according to some embodiments of this application. As Figure 1BAs shown, a machine learning model (such as a deep learning model, a large language model, etc.) is used to receive a natural sentence and generate a corresponding structured sentence (such as DSL, etc.) accordingly. Then, the structured sentence is converted into a corresponding query sentence (such as SQL, etc.) through a converter. The structured sentence uses a structured intermediate language, which has multiple word classes and words, that is, it has a certain degree of limitation, which is beneficial to training the machine learning model. In addition, because its word classes and words have the characteristics of simple structure and clear semantics, it can be automatically converted into a query sentence according to the grammar of the query language, effectively avoiding errors in directly generating query sentences (such as SQL syntax errors, etc.), and improving both accuracy and robustness. In addition, in order to further improve robustness, in some embodiments of the present application, a multi-task training method for the structured sentence generation model is also proposed to achieve a more robust and accurate query sentence generation effect.

[0049] Figure 2 FIG. 200 shows an exemplary application scenario of a query sentence generation method according to some embodiments of the present application. The application scenario 200 may include a server 210, a terminal device 220, and a server 230. The server 210, the terminal device 220, and the server 230 are communicatively coupled together through a network 240. The network 240 may be, for example, a wide area network (WAN), a local area network (LAN), a wireless network, a public telephone network, an intranet, and any other type of network well known to those skilled in the art.

[0050] As an example, the query sentence generation method may mainly run on the server 210. On the server 210, first, a natural sentence containing query information is obtained, and the natural sentence describes the query information in natural language. For example, the server 210 may obtain the natural sentence from the terminal device 220 via the network 240. Then, a structured sentence generation model is used to generate a structured sentence corresponding to the natural sentence according to the natural sentence. The structured sentence includes multiple word classes and words corresponding to each word class, and the structured sentence generation model is a trained deep learning model. Finally, a query sentence is determined based on the word classes and corresponding words in the structured sentence, and the query sentence describes the query information in a query language.

[0051] As an example, the query statement generation method can also run mainly on the terminal device 220 or the server 230. It should be noted that the server 210, the terminal device 220, and the terminal device 230 can all include media and / or devices capable of persistently storing information, and / or tangible storage devices. Therefore, a computer-readable storage medium refers to a non-signal-bearing medium. Computer-readable storage media include hardware such as volatile and non-volatile, removable and non-removable media and / or storage devices implemented by methods or technologies suitable for storing information (such as computer-readable instructions, data structures, program modules, logic elements / circuits, or other data). As understood by those of ordinary skill in the art, an example of the server 210 can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal and the server can be directly or indirectly connected by wired or wireless communication methods, which are not limited in this application. The server 210 can present the data distribution strategy to be determined to the developer through the terminal device 220 and interact with the developer to visually determine the development strategy.

[0052] The terminal device 220 can be any type of mobile computing device, including mobile computers (such as personal digital assistants (PDAs), laptop computers, notebook computers, tablet computers, netbooks, etc.), mobile phones (such as cellular phones, smartphones, etc.), wearable computing devices (such as smart watches, head-mounted devices, including smart glasses, etc.), or other types of mobile devices. In some embodiments, the terminal device 220 and the terminal device 230 can also be fixed computing devices, such as desktop computers, gaming consoles, smart TVs, etc. In addition, in the case where the application scenario 200 includes multiple terminal devices 220, the multiple terminal devices 220 can be the same or different types of computing devices.

[0053] Such as Figure 2As shown, the terminal device 220 may include a display screen and a terminal application that can interact with the end user via the display screen. The terminal application may be a native application, a web application, or a mini program (LiteApp, such as a mobile mini program or a WeChat mini program) as a lightweight application. In the case where the terminal application is a native application that needs to be installed, the terminal application can be installed in the terminal device 220. In the case where the terminal application is a web application, the terminal application can be accessed through a browser. In the case where the terminal application is a mini program, the terminal application can be directly opened on the user terminal 220 by searching for relevant information of the terminal application (such as the name of the terminal application) or scanning a graphic code of the terminal application (such as a barcode or a QR code), etc., without installing the terminal application.

[0054] In some embodiments, the above application scenario 200 may be a distributed system composed of the server 230, and this distributed system may, for example, form a blockchain system. Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, and encryption algorithms. Essentially, blockchain is a decentralized database, a string of data blocks generated by using cryptographic methods, and each data block contains information about a batch of network transactions, which is used to verify the validity of the information (anti-counterfeiting) and generate the next block. Blockchain may include a blockchain underlying platform, a platform product service layer, and an application service layer.

[0055] The blockchain underlying platform may include processing modules such as user management, basic services, and smart contracts. Among them, the user management module is responsible for the identity information management of all blockchain participants, including maintaining public-private key generation (account management), key management, and maintaining the correspondence between the real identity of the user and the blockchain address (permission management), and under authorization, supervising and auditing the transaction situations of certain real identities, and providing rule configuration for risk control (risk control and auditing); the basic service module is deployed on all blockchain node devices to verify the validity of business requests, and after consensus on valid requests, record them on the storage. For a new business request, the basic service first performs interface adaptation parsing and authentication processing (interface adaptation), then encrypts the business information through a consensus algorithm (consensus management), transmits it to the shared ledger completely and consistently after encryption (network communication), and records and stores it; the smart contract module is responsible for the registration and issuance of contracts, contract triggering, and contract execution. Developers can define contract logic through a certain programming language, publish it to the blockchain (contract registration), trigger the execution according to the logic of the contract terms by calling keys or other events, complete the contract logic, and at the same time also provide functions such as contract upgrade and cancellation.

[0056] The platform product service layer provides the basic capabilities and implementation frameworks of typical applications. Developers can build on these basic capabilities and overlay the characteristics of the business to complete the blockchain implementation of the business logic. The application service layer provides application services based on the blockchain solution for business participants to use.

[0057] Figure 3 FIG. 300 is an exemplary flowchart of a query statement generation method according to some embodiments of the present application. As Figure 3 shown, method 300 includes step S310, step S320, and step S330.

[0058] In step S310, a natural statement containing query information is obtained. The natural statement describes the query information in natural language. For example, the natural statement can be "Obtain the weather conditions in the past month", "Determine the change trend of the number of visits in the past week", etc., which are query information described in natural language. The length, word usage habits, and word order of the natural statement are all affected by the user's preferences and habits, and natural statements issued by different users generally vary.

[0059] In step S320, a structured statement generation model is used to generate a structured statement corresponding to the natural statement according to the natural statement. The structured statement includes multiple word classes and the corresponding words for each word class. The structured statement generation model is a trained deep learning model. It can be seen that by pre-setting multiple word classes, the structured statement can extract key content (such as query content) from the semantics of the natural statement as planned. It should be noted that the words corresponding to the word classes extracted from the natural statement are not necessarily exactly the same as the words in the natural statement, because it pays more attention to the same semantics, which is also what deep learning models (such as large prediction models, etc.) focus on. In addition, since the structured statement does not have overly complex grammar but contains key information (such as query information), the model obtained by training the deep learning model with it as the output and the natural statement as the input has a higher accuracy. Because if the deep learning model directly learns the query language, the model will spend a large amount of cost learning the grammar of the query language, etc., and ignore the query information contained in the query statement. Moreover, at this time, even if a large amount of training cost is spent, the grammar of the query language of the generated query statement often makes mistakes, and the expected query information is often partially missing or distorted. Therefore, by designing this intermediate state of the structured statement, the learning efficiency and accuracy of the deep learning model can be effectively improved, and the training cost can be reduced. In addition, since the word classes of the structured statement are pre-set, they can be set specifically for the application scenario to be targeted, further achieving higher accuracy. For example, use the grammar rules of DSL to design the word classes of the structured statement, such as defining the conditions of the query, data column names, data statistical methods, etc. in a structured form.

[0060] In step S330, a query statement is determined based on the part of speech and the corresponding words in the structured statement, and the query statement describes the query information in a query language. Since the structured statement contains parts of speech and corresponding words, these words already fully contain the query information. The query statement describes the query information according to the grammar of the query language. Therefore, it is only necessary to organize the words in the structured statement according to the grammar of the query language. Corresponding rules can be designed according to the grammar of different query languages, and then the corresponding query statement can be automatically generated according to the words of each part of speech in the structured statement. For example, when the query statement uses SQL as the query language, the words in the structured statement are automatically organized according to the grammar of SQL.

[0061] Therefore, in method 300, a machine learning model (such as a deep learning model, a large language model, etc.) is used to receive a natural statement and generate a corresponding structured statement (such as DSL, etc.) accordingly, and then the structured statement is converted into a corresponding query statement (such as SQL, etc.) according to the grammar of the query language. The structured statement uses a structured intermediate language, which has multiple parts of speech and words, that is, it has a certain limitation, which is beneficial to training the deep learning model to obtain better accuracy. In addition, due to the characteristics of its parts of speech and words being concise in structure and clear in semantics, it can be automatically converted into a query statement according to the grammar of the query language, effectively avoiding errors in directly generating query statements (such as SQL syntax errors, etc.), and improving both accuracy and robustness.

[0062] In some embodiments, the structured statement generation model is obtained by training a deep learning model using a training sample set. The training sample set includes a first training sample set, and the first training sample set includes multiple first-class training sample pairs, and each first-class training sample pair includes a natural statement and its corresponding structured statement. As an example, the first training sample set can be used to perform supervised training on the deep learning model to obtain the structured statement generation model. For example, using the natural statement of the first-class training sample pair as the input to obtain the actual output of the model. Then, using the structured statement of the first-class training sample pair as the expected output, comparing it with the actual output, and calculating the loss corresponding to the first training sample set using the cross-entropy loss function. With the goal of minimizing this loss, the parameters of the deep learning model are adjusted, and finally the structured statement generation model is obtained.

[0063] Figure 4 shows a schematic diagram of determining the first training sample set according to some embodiments of the present application. As Figure 4As shown, first, obtain multiple initial training sample pairs. The initial training sample pairs include natural sentences and their corresponding structured sentences. Each part of speech and the corresponding words in the structured sentence correspond to part of the content in the natural sentence (i.e., they have the same semantic meaning). Then, perform a partial copy operation, a partial deletion operation, or a partial replacement operation on each initial training sample pair respectively to obtain three first-class training sample pairs corresponding to each initial training sample pair. It should be noted that in specific implementations, it is not necessarily required to perform all of the partial copy operation, the partial deletion operation, and the partial replacement operation. It is also possible to perform one or two of these operations to obtain one or two corresponding first-class training sample pairs. The operations for each initial training sample pair are described in detail below.

[0064] First, take the initial training sample pair as the first current training sample pair. Perform a partial copy operation on the first current training sample pair, and determine the first current training sample pair after the partial copy operation as a first-class training sample pair. The partial copy operation includes: copying the first part of the content in the natural sentence of the first current training sample pair so that the natural sentence after copying has repeated first part of the content; determining the natural sentence with the repeated first part of the content and the structured sentence of the first current training sample pair as the first current training sample pair after the partial copy operation.

[0065] Then, take the initial training sample pair as the second current training sample pair. Perform a partial deletion operation on the second current training sample pair, and determine the second current training sample pair after the partial deletion operation as another first-class training sample pair. The partial deletion operation includes: deleting the first part of the content in the natural sentence of the second current training sample pair so that the natural sentence after deletion no longer has the first part of the content; deleting the part of speech and the corresponding words in the structured sentence of the second current training sample pair that correspond to the first part of the content so that the structured sentence after deletion no longer has the part of speech and the corresponding words that correspond to the first part of the content; determining the natural sentence after deletion and the structured sentence after deletion as the second current training sample pair after the partial deletion operation.

[0066] Finally, take the initial training sample pair as the third current training sample pair. Perform a partial replacement operation on the third current training sample pair, and determine the third current training sample pair after the partial replacement operation as another first-class training sample pair. The partial replacement operation includes: replacing the first part of the natural sentence in the third current training sample pair with a first phrase to obtain the natural sentence after the partial replacement operation. The part-of-speech of the structured sentence corresponding to the first phrase is the same as that of the structured sentence corresponding to the first part of the content, but the words in the structured sentence corresponding to the first phrase are different from those in the structured sentence corresponding to the first part of the content; replacing the words in the structured sentence of the third current training sample pair corresponding to the first part of the content with the words in the structured sentence corresponding to the first phrase to obtain the structured sentence after the partial replacement operation; and determining the natural sentence after the partial replacement operation and the structured sentence after the partial replacement operation as the third current training sample pair after the partial replacement operation.

[0067] As an example, the input of the initial training sample pair is: "What is the trend of the number of visitors to the purchase page in Beijing City in the past 7 days?", which expresses the query information in natural language. The output of the initial training sample pair is "{table:demo,type:trend analysis,operator:count_all,dimensions:city,Index:purchase_visit,filters:{name:city,value:Beijing},time_range:in the past 7 days}", which expresses the query information in DSL. The part-of-speech categories include: table, type, operator, dimensions, Index, and filters.

[0068] First, perform a partial duplication operation on the input of the initial training sample pair. Optionally, duplicate "in the past seven days" to obtain "What is the trend of the number of visitors to the purchase page in Beijing City in the past 7 days in the past 7 days?". Take it and the output of the initial training sample pair as a first-class training sample pair. The input of this first-class training sample pair is: What is the trend of the number of visitors to the purchase page in Beijing City in the past 7 days in the past 7 days?. The output of this first-class training sample pair is: {table:demo,type:trend analysis,operator:count_all,dimensions:city,Index:purchase_visit,filters:{name:city,value:Beijing},time_range:in the past 7 days}.

[0069] Then, perform a partial deletion operation on the initial training sample pairs. Optionally, perform a deletion operation on "the past seven days" to obtain "What is the trend of the number of people visiting the purchase page in Beijing City?" as the new input. Then, perform a partial deletion operation on the output of the initial training sample pairs, that is, delete the part-of-speech and words of the structured statement corresponding to "the past seven days" to obtain "{table:demo,type:trend analysis,operator:count_all,dimensions:city,Index:purchase_visit,filters:{name:city,value:Beijing}}" as the new output. Then, determine them as another first-class training sample pair. The input of this first-class training sample pair is "What is the trend of the number of people visiting the purchase page in Beijing City?", and the corresponding output is "{table:demo,type:trend analysis,operator:count_all,dimensions:city,Index:purchase_visit,filters:{name:city,value:Beijing}}".

[0070] Finally, perform a partial replacement operation on the initial training sample pairs. Optionally, replace "Beijing" in the input natural statement with "Shanghai", and perform corresponding replacements on the words of the corresponding part-of-speech in the output structured statement. For example, the input of another first-class training sample pair is: "What is the trend of the number of people visiting the purchase page in Shanghai City in the past seven days?", and the output is "{table:demo,type:trend analysis,operator:count_all,dimensions:city,Index:purchase_visit,filters:{name:city,value:Shanghai},time_range:the past 7 days}".

[0071] It can be seen that the partial copying operation, partial deletion operation, and partial replacement operation can all increase the diversity of the samples in the first training sample set, thereby enhancing the understanding ability and adaptability of the trained structured statement generation model to natural language, and thus achieving the accuracy and robustness in extracting structured statements from natural statements. It should be noted that in actual operation, one or more of the partial copying operation, partial deletion operation, and partial replacement operation can be performed to generate the corresponding one or more first-class training sample pairs.

[0072] In some embodiments, the structured statement generation model is obtained by performing a first training step on a deep learning model using a first training sample set. The first training step includes: inputting the natural statements of the first type of training sample pairs into the deep learning model to obtain the actual output of the deep learning model; using the structured statements of the first type of training sample pairs as the expected output of the deep learning model, and determining the difference between the actual output and the expected output as the first difference of the first type of training sample pairs; determining the first difference of each first type of training sample pair in the first training sample set, accumulating the first differences corresponding to all the first type of training sample pairs in the first training sample set, and determining the accumulated result as the first loss; adjusting the model parameters of the deep learning model until the first loss is less than or equal to a first predetermined threshold; and determining the deep learning model with its model parameters adjusted as the structured statement generation model. As an example, the difference between the actual output and the expected output, and the first loss can be calculated using the cross-entropy loss function. For example, using the cross-entropy loss function as the supervision function, the deep learning model is supervised trained until the output value of the cross-entropy loss function is minimized, and the deep learning model at this time is determined as the structured statement generation model.

[0073] In some embodiments, the training sample set further includes a second training sample set. The second training sample set includes multiple second type of training sample pairs, and each second type of training sample pair includes an initial natural statement and its corresponding canonical natural statement. The canonical natural statement describes the query information included in the initial natural statement in a predetermined expression way. The role of the second training sample set is to enhance the deep learning model's understanding of different expression ways of natural statements, so that the trained deep learning model can understand diverse expressions. The structured statement generation model is further obtained by performing a second training step on the deep learning model using the second training sample set. The second training step includes: inputting the initial natural statements of the second type of training sample pairs into the deep learning model to obtain the actual output of the deep learning model; using the canonical natural statements of the second type of training sample pairs as the expected output of the deep learning model, and determining the difference between the actual output and the expected output as the second difference of the second type of training sample pairs; determining the second difference of each second type of training sample pair in the second training sample set, accumulating the second differences of all the second type of training sample pairs in the second training sample set, and determining the accumulated result as the second loss; adjusting the model parameters of the deep learning model until the second loss is less than or equal to a second predetermined threshold; and determining the deep learning model with its model parameters adjusted as the structured statement generation model.

[0074] As an example, the natural sentences "What is the trend of the number of visitors to the purchase page in Beijing City in the past 7 days?" and "The change in the number of visitors to the purchase page in Beijing City in the past 7 days" express the same meaning (i.e., contain the same query information), but the expressions are different. Therefore, a second training sample set (which contains multiple second-class training sample pairs) can be established, and then the deep learning model can be trained using the second training step to obtain a structured sentence generation model. The second-class training samples include initial natural sentences and canonical natural sentences. The initial natural sentences are, for example, "What is the trend of the number of visitors to the purchase page in Beijing City in the past 7 days?", "The change in the number of visitors to the purchase page in Beijing City in the past 7 days", etc. Describe the query information contained in the initial natural sentence in a predetermined expression, such as "[In the past 7 days] [The city is Beijing] [The number of visitors to the purchase page] of [Trend analysis]", or "Trend analysis of the number of visitors to the purchase page in Beijing City in the past 7 days". In the second training step, use the initial natural sentence as the input, the canonical natural sentence as the expected output, and the cross-entropy loss function as the supervision function to supervise the difference between the expected output and the actual output. Adjust the parameters of the deep learning model until the value of the cross-entropy loss function is minimized, and determine the deep learning model at this time as the structured sentence generation model. It can be seen that by constructing the second training sample set and using the second training step, the trained model can better understand the query information contained in diverse natural sentences.

[0075] In some embodiments, the training sample set further includes a third training sample set. The third training sample set includes a plurality of third-class training sample pairs, and each third-class training sample pair includes a structured statement and its corresponding canonical natural statement. The canonical natural statement describes the query information included in the structured statement in natural language in a predetermined expression manner. The structured statement generation model is further obtained by performing a third training step on the deep learning model using the third training sample set. The role of the third training sample set is to train the deep learning model so that the model can understand the meaning of the structured statement. To this end, the third training step can be used to train the deep learning model so that the deep learning model can predict the corresponding canonical natural statement according to the structured statement. The third training step includes: inputting the structured statement of the third-class training sample pair into the deep learning model to obtain the actual output of the deep learning model; using the canonical natural statement of the third-class training sample pair as the expected output of the deep learning model, and determining the difference between the actual output and the expected output as the third difference of the third-class training sample pair; determining the third difference of each third-class training sample pair in the third training sample set, accumulating the third differences of all third-class training sample pairs in the third training sample set, and determining the accumulated result as the third loss; adjusting the model parameters of the deep learning model until the third loss is less than or equal to a third predetermined threshold; and determining the deep learning model with its model parameters adjusted as the structured statement generation model. For example, in the third training step, the input of the deep learning model is determined as "{table:demo,type:trend analysis,operator:count_all,dimensions:city,Index:purchase_visit,filters:{name:city,value:Shanghai},time_range:last 7 days}", and the expected output of the deep learning model is determined as "Trend analysis of the number of visits to the purchase page in the city of Beijing in the last 7 days". As an example, the cross-entropy loss function can be used as the supervision function to supervise the difference between the expected output and the actual output. Adjust the parameters of the deep learning model until the value of the cross-entropy loss function is minimized, and determine the deep learning model at this time as the structured statement generation model. It can be seen that by constructing the third training sample set and using the third training step, the trained model can better understand the query information included in the structured statement.

[0076] It should be noted that one or more of the first training step, the second training step, and the third training step can be performed simultaneously, so as to perform multi-task training on the deep learning model and further improve the accuracy and robustness of the obtained structured statement generation model.

[0077] Figure 5Shows a schematic diagram of determining a structured statement generation model according to some embodiments of the present application. In Figure 5 the first training step, the second training step, and the third training step are carried out jointly. In Figure 5 the illustrated embodiment, the first training step uses the first training sample set to train the deep learning model, the second training step uses the second training sample set to train the deep learning model, and the third training step uses the third training sample set to train the deep learning model. Finally, through this multi-task training, a structured statement generation model is obtained. In some other embodiments, one or more of the first training step, the second training step, and the third training step can also be used, and one or more of the corresponding first training sample set, the second training sample set, and the third training sample set are used to train the deep learning model to obtain the corresponding structured statement generation model. For example, the deep learning model can be selected as a large language model, and at this time, multi-task training can be used to perform multiple training steps simultaneously. For example, the first task is set as: Input: Given a natural language query, "Trend of the number of visitors to the purchase page in the last 7 days"; Output the corresponding json, Output: {}. The second task is set as: Input: Given diverse expressions, "How about the trend of the number of visitors to the purchase page in the last 7 days"; Output the corresponding standardized expression, "Trend of the number of visitors to the purchase page in the last 7 days". The third task is set as: Input: Given the corresponding json, {}; Output the corresponding sentence, "Trend of the number of visitors to the purchase page in the last 7 days". Through the above three tasks, the large language model can perform the first training step, the second training step, and the third training step simultaneously.

[0078] In some embodiments, the parts of speech of the structured statement include one or more of: the table of the query, the dimension of the query, the condition of the query, the operation of the data, and the query mode. As an example, these parts of speech can be identified or distinguished using identifiers, data structure languages, programming languages, etc. For example, using the DSL language, the table of the query, the dimension of the query, the condition of the query, the operation of the data, and the query mode can be expressed as: table, dimensions, type, operator, Index, filters, etc.

[0079] In some embodiments, determining a query statement based on the word classes and corresponding words in the structured statement includes: determining the composition rules of the words corresponding to the word classes in the query language; organizing the words of each word class in the structured statement based on the composition rules to determine the query statement corresponding to the structured statement. As an example, the structured statement contains "{table:demo,type:trend analysis,operator:count_all,dimensions:city,Index:purchase_visit,filters:{name:city,value:Beijing},time_range:last 7 days}". If the query statement is described in SQL, according to the syntax of SQL, the structured statement will be automatically converted to "select count(purchase_visit) from demo group by days where city = Beijing and dates = last 7 days". As an example, the query language may include SQL, and the query statement can use the structured query language to describe the query information. The structured statement organizes the multiple word classes and the corresponding words included therein in a domain-specific language.

[0080] Table I shows the accuracy of the structured statement generation model trained with different training sample sets. The accuracy in Table I refers to the ratio between the number of correct structured statements generated by the structured statement generation model and the total number of output statements. Among them, the initial training sample pair refers to training the deep learning model with a training set composed of the initial training sample pair to obtain the structured statement generation model. "First training sample set + second training sample set" refers to the structured statement generation model obtained by performing multi-task training using the first training sample set for the first training step and the second training sample set for the second training step. "First training sample set + second training sample set + third training sample set" refers to the structured statement generation model obtained by performing multi-task training using the first training sample set for the first training step, the second training sample set for the second training step, and the third training sample set for the third training step.

[0081] Table I Accuracy of the Structured Statement Generation Model Trained with Different Training Sample Sets

[0082]

[0083] The present application further discloses a data query method. The data query method includes: obtaining a natural statement for querying data; determining a query statement corresponding to the natural statement by using the query statement generation method in any of the foregoing embodiments; and querying corresponding data in a database by using the query statement. For example, first obtain the natural statement "What is the trend of the number of people accessing the purchase page in Beijing in the past 7 days?". Then, use the query statement generation method in the foregoing embodiment to determine its corresponding SQL query statement "select count(purchase_visit) from demo group by days where city = Beijing and dates = in the past 7 days". Finally, query the target data in the database according to the query statement. Therefore, by using the data query method disclosed in the present application, the query statement can be determined quickly and accurately according to the natural statement, and then the target data can be queried by using the query statement. Since the determination of the query statement is highly accurate and robust, the accuracy and efficiency of data query are also improved.

[0084] Figure 6A , 6B FIG. shows a schematic diagram of an application scenario of a query statement generation method according to some embodiments of the present application. As Figure 6A shown, first enter the question you want to ask in natural language on the "Intelligent Analysis Engine" page. For example, enter "The change trend of the number of visitors in the past week". Then, the background of the intelligent analysis engine will generate a corresponding query statement by using the query statement generation method in any of the foregoing embodiments, and then query the target data (i.e., the number of visitors in a week) from the database by using the query statement. Finally, the change trend is presented in the form of text or a chart, as Figure 6B shown.

[0085] As an example, the background of the intelligent analysis engine can be as Figure 7 shown. Figure 7 FIG. shows a schematic diagram of data query according to some embodiments of the present application. As Figure 7 shown, the user first inputs a natural statement to the computer, and then the computer inputs the natural statement and the information of the query table into a structured statement generation model. The structured statement generation model randomly generates a structured statement and outputs it to a converter. The converter then converts the structured statement (described in DSL, for example) into a query statement (described in SQL, for example), and inputs it to the computer for the computer to query corresponding data in the database.

[0086] As an example, structured statements can be organized using a DSL. The DSL is mainly targeted at a preset specific domain, and it can have different preset definitions in different application scenarios (such as part of speech). For example, in this application scenario, the part of speech corresponding to the table to be queried, the dimension to be queried, the query condition, the simple operation of data (sum or average), and the query mode (comparison mode, trend mode, etc.) can be mainly defined.

[0087] Figure 8 FIG. 4 shows an exemplary structural block diagram of a query statement generation device 800 according to some embodiments of the present application. As Figure 8 shown, the query statement generation device 800 includes a first acquisition module 810, a structured statement generation module 820, and a query statement generation module 830, which will be described in detail below.

[0088] The first acquisition module 810 is configured to acquire a natural statement containing query information. The natural statement describes the query information in natural language. For example, the natural statement can be "Obtain the weather conditions in the past month", "Determine the change trend of the number of visits in the past week", etc., which are query information described in natural language. The length, word usage habits, word order, etc. of the natural statement are all affected by the user's preferences and habits, and the natural statements issued by different users generally vary.

[0089] The structured statement generation module 820 is configured to generate a structured statement corresponding to the natural statement according to the natural statement by using a structured statement generation model. The structured statement includes multiple word classes and words corresponding to each word class. The structured statement generation model is a trained deep learning model. It can be seen that by presetting multiple word classes, key content (such as query content) can be extracted from the semantics of the natural statement according to the plan. It should be noted that the words corresponding to the word classes extracted from the natural statement are not necessarily exactly the same as the words in the natural statement, because it pays more attention to the same semantics, which is also what deep learning models (such as large prediction models, etc.) focus on. In addition, since the structured statement does not have overly complex grammar but contains key information (such as query information), using it as the output and the natural statement as the input to train the deep learning model can obtain a higher model accuracy. Because if the deep learning model directly learns the query language, the model will spend a large amount of cost learning the grammar of the query language and ignore the query information contained in the query statement. Moreover, at this time, even if a large amount of training cost is spent, the grammar of the query language of the generated query statement often makes mistakes, and the expected query information is often partially missing or distorted. Therefore, by designing this intermediate state of the structured statement, the learning efficiency and accuracy of the deep learning model can be effectively improved, and the training cost can be reduced. In addition, since the word classes of the structured statement are preset, they can be set specifically for the application scenario, further achieving higher accuracy. For example, use the grammar rules of DSL to design the word classes of the structured statement, such as defining the query conditions, data column names, data statistical methods, etc. in a structured form.

[0090] The query statement generation module 830 is configured to determine a query statement based on the word classes and corresponding words in the structured statement. The query statement describes the query information in a query language. Since the structured statement includes word classes and corresponding words, these words already fully contain the query information. And the query statement describes the query information in the grammar of the query language, so only need to organize the words in the structured statement according to the grammar of the query language. Corresponding rules can be designed according to the grammar of different query languages, and then the corresponding query statement can be automatically converted according to the words of each word class in the structured statement. For example, when the query statement uses SQL as the query language, organize the words in the structured statement automatically according to the grammar of SQL.

[0091] As can be seen, the query statement generation device 800 first uses a machine learning model (such as a deep learning model, a large language model, etc.) to receive a natural statement and generate a corresponding structured statement (such as DSL, etc.) accordingly, and then converts the structured statement into a corresponding query statement (such as SQL, etc.) according to the syntax of the query language. Since the structured statement uses a structured intermediate language, which has multiple word classes and words, that is, it has a certain degree of limitation, it is beneficial to train the deep learning model to obtain better accuracy. In addition, since the word classes and words of the structured statement have the characteristics of simple structure and clear semantics, they can be automatically converted into query statements according to the syntax of the query language, effectively avoiding errors in directly generating query statements (such as SQL syntax errors, etc.), and improving both accuracy and robustness.

[0092] Figure 9 FIG. shows an exemplary structural block diagram of a data query device 900 according to some embodiments of the present application. As Figure 9 shown, the data query device 900 includes a second acquisition module 910, a query statement determination module 920, and a data query module 930, which will be introduced in detail below.

[0093] The second acquisition module 910 is configured to acquire a natural statement for querying data. As an example, a method of acquiring a natural statement using an interface as shown in the embodiments in Figure 6A can be adopted.

[0094] The query statement determination module 920 is configured to determine the query statement corresponding to the natural statement by using the query statement generation method in any of the foregoing embodiments.

[0095] The data query module 930 is configured to query the corresponding data in the database by using the query statement. For example, the second acquisition module 910 first acquires the natural statement "What is the trend of the number of purchase page visits in Beijing City in the past 7 days?". Then, the query statement determination module 920 determines its corresponding SQL query statement "select count(purchase_visit) from demo group by days where city = Beijing and dates = in the past 7 days" by using the query statement generation method in the foregoing embodiment. Finally, the data query module 930 queries the target data in the database according to the query statement.

[0096] As can be seen, by using the data query device 900, the query statement can be quickly and accurately determined according to the natural statement, and then the target data can be queried by using the query statement. Since the determination of the query statement is highly accurate and robust, the accuracy and efficiency of data query are also improved.

[0097] Figure 10FIG. illustrates an example system 1000, which includes an example computing device 1010 representative of one or more systems and / or devices that may implement the various methods described herein. The computing device 1010 may be, for example, a server of a service provider, a device associated with the server, a system-on-chip, and / or any other suitable computing device or computing system. Referenced above with respect to Figure 8 the query statement generation device 800 described and Figure 9 the data query device 900 described may take the form of the computing device 1010. Alternatively, the query statement generation device 800 and the data query device 900 may be implemented as a computer program in the form of an application 1016.

[0098] The example computing device 1010 illustrated in the figure includes a processing system 1011, one or more computer-readable media 1012, and one or more I / O interfaces 1013 that are communicatively coupled to each other. Although not shown, the computing device 1010 may also include a system bus or other data and command transfer system that couples the various components to each other. The system bus may include any one or combination of different bus structures, such as a memory bus or memory controller, a peripheral bus, a universal serial bus, and / or a processor or local bus utilizing any one of a variety of bus architectures. Also contemplated are various other examples, such as control and data lines.

[0099] The processing system 1011 represents the functionality to perform one or more operations using hardware. Accordingly, the processing system 1011 is illustrated as including hardware elements 1014 that may be configured as a processor, functional blocks, etc. This may include being implemented in hardware as an application specific integrated circuit or other logic device formed using one or more semiconductors. The hardware elements 1014 are not limited by the materials from which they are formed or the processing mechanism employed therein. For example, a processor may be composed of (multiple) semiconductors and / or transistors (e.g., an electronic integrated circuit (IC)). In such a context, the executable instructions of the processor may be electronically executable instructions.

[0100] The computer-readable media 1012 is illustrated as including a memory / storage device 1016. The memory / storage device 1016 represents the memory / storage capacity associated with one or more computer-readable media. The memory / storage device 1016 may include volatile media (such as random access memory (RAM)) and / or non-volatile media (such as read-only memory (ROM), flash memory, optical disks, magnetic disks, etc.). The memory / storage device 1016 may include fixed media (e.g., RAM, ROM, fixed hard disk drive, etc.) and removable media (e.g., flash memory, removable hard disk drive, optical disk, etc.). The computer-readable media 1012 may be configured in a variety of other ways as described further below.

[0101] One or more I / O interfaces 1013 represent functionality that allows a user to input commands and information to the computing device 1010 using various input devices and optionally also allows information to be presented to the user and / or other components or devices using various output devices. Examples of input devices include keyboards, cursor control devices (e.g., mice), microphones (e.g., for voice input), scanners, touch capabilities (e.g., capacitive or other sensors configured to detect physical touch), cameras (e.g., that can detect motion not involving touch as gestures using visible or non-visible wavelengths such as infrared frequencies), and the like. Examples of output devices include display devices, speakers, printers, network cards, haptic response devices, and the like. Thus, the computing device 1010 can be configured in various ways, as further described below, to support user interaction.

[0102] The computing device 1010 also includes an application 1016. The application 1016 can be, for example, a software instance for query statement generation device 800 or data query device 900, and implements the techniques described herein in combination with other elements in the computing device 1010.

[0103] This application provides a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of the computing device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computing device executes the query statement generation method provided in the above various optional implementation manners.

[0104] Various techniques may be described herein in the general context of software, hardware elements, or program modules. Generally, these modules include routines, programs, objects, elements, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The terms "module", "function", and "component" as used herein generally represent software, firmware, hardware, or a combination thereof. The features of the techniques described herein are platform-independent, meaning that these techniques can be implemented on various computing platforms having various processors. Also, in the embodiments of this application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, which works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, one processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of an overall module or unit that includes the function of that module or unit.

[0105] Implementations of the described modules and techniques may be stored on or transmitted across some form of computer-readable medium. Computer-readable media can include a variety of media accessible by computing device 1010. By way of example and not limitation, computer-readable media may include "computer-readable storage media" and "computer-readable signal media".

[0106] Contrary to mere signal transmission, carrier waves, or signals themselves, "computer-readable storage media" refers to media and / or devices that are capable of storing information persistently, and / or tangible storage devices. Thus, computer-readable storage media refers to non-signal-bearing media. Computer-readable storage media includes hardware such as volatile and non-volatile, removable and non-removable media and / or storage devices implemented in a method or technology suitable for storing information such as computer-readable instructions, data structures, program modules, logic elements / circuits, or other data. Examples of computer-readable storage media may include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disks (DVDs) or other optical storage devices, hard disks, magnetic cassettes, magnetic tape, magnetic disk storage devices or other magnetic storage devices, or other storage devices, tangible media, or articles of manufacture suitable for storing the desired information and accessible by a computer.

[0107] "Computer-readable signal media" refers to a signal-bearing media configured to send instructions to computing device 1010, such as via a network. Signal media typically may embody computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave, data signal, or other transmission mechanism. Signal media also includes any information delivery media. The term "modulated data signal" refers to a signal in which one or more of the characteristics are set or changed in such a manner as to encode information in the signal. By way of example and not limitation, communication media includes wired media such as a wired network or direct-wired connection, and wireless media such as acoustic, RF, infrared, and other wireless media.

[0108] As noted previously, hardware element 1014 and computer-readable medium 1012 represent instructions, modules, programmable device logic, and / or fixed device logic implemented in hardware, which in some embodiments may be used to implement at least some aspects of the techniques described herein. Hardware elements may include integrated circuits or system-on-a-chip, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), complex programmable logic devices (CPLDs), and components of other hardware devices implemented in silicon or other hardware. In this context, hardware elements may serve as processing devices that execute program tasks defined by the instructions, modules, and / or logic embodied by the hardware elements, as well as hardware devices that store instructions for execution, e.g., the previously described computer-readable storage media.

[0109] The foregoing combinations can also be used to implement the various techniques and modules herein. Accordingly, software, hardware, or program modules and other program modules can be implemented as one or more instructions and / or logic on a computer-readable storage medium of some form and / or embodied by one or more hardware elements 1014. The computing device 1010 can be configured to implement specific instructions and / or functions corresponding to the software and / or hardware modules. Thus, for example, by using the computer-readable storage medium of the processing system and / or the hardware element 1014, the implementation of the module as a module executable by the computing device 1010 as software can be at least partially implemented in hardware. The instructions and / or functions can be executable / operable by one or more articles of manufacture (e.g., one or more computing devices 1010 and / or processing systems 1011) to implement the techniques, modules, and examples described herein.

[0110] In various embodiments, the computing device 1010 can be configured in a variety of different ways. For example, the computing device 1010 can be implemented as a computer-like device including a personal computer, a desktop computer, a multi-screen computer, a laptop computer, a netbook, etc. The computing device 1010 can also be implemented as a mobile device-like device including mobile devices such as mobile phones, portable music players, portable gaming devices, tablet computers, multi-screen computers, etc. The computing device 1010 can also be implemented as a television-like device, which includes a device having or connected to a generally larger screen in a leisure viewing environment. These devices include televisions, set-top boxes, gaming consoles, etc.

[0111] The techniques described herein can be supported by these various configurations of the computing device 1010 and are not limited to the specific examples of the techniques described herein. The functionality can also be implemented in whole or in part on the "cloud" 1020 by using a distributed system, such as through the platform 1022 described below.

[0112] The cloud 1020 includes and / or represents a platform 1022 for resources 1024. The platform 1022 abstracts the underlying functionality of the hardware (e.g., servers) and software resources of the cloud 1020. The resources 1024 can include applications and / or data that can be used when performing computer processing on servers remote from the computing device 1010. The resources 1024 can also include services provided over the Internet and / or over a subscriber network such as a cellular or Wi-Fi network.

[0113] Platform 1022 may abstract resources and functions to connect computing device 1010 with other computing devices. Platform 1022 may also be used to abstract a hierarchy of resources to provide a corresponding level of hierarchy for the requirements encountered for resources 1024 implemented via platform 1022. Thus, in an interconnected device embodiment, the implementation of the functions described herein may be distributed throughout system 1000. For example, the functions may be implemented partially on computing device 1010 and via platform 1022 that abstracts the functions of cloud 1020.

[0114] It should be understood that, for clarity, embodiments of the present application have been described with reference to different functional units. However, it will be apparent that, without departing from the present application, the functionality of each functional unit may be implemented in a single unit, implemented in multiple units, or implemented as part of other functional units. For example, functionality illustrated as being performed by a single unit may be performed by multiple different units. Thus, reference to a particular functional unit is only considered a reference to an appropriate unit for providing the described functionality, rather than indicating a strict logical or physical structure or organization. Thus, the present application may be implemented in a single unit, or may be physically and functionally distributed between different units and circuits.

[0115] Although the present application has been described in connection with some embodiments, it is not intended to be limited to the specific forms set forth herein. Rather, the scope of the present application is limited only by the appended claims. Additionally, although individual features may be included in different claims, these may possibly be advantageously combined, and including in different claims does not imply that a combination of features is not practicable and / or advantageous. The order of features in the claims does not imply that the features must be in any particular order in which they work. Further, in the claims, the word "comprising" does not exclude other elements, and the terms "a" or "an" do not exclude a plurality. The reference numerals in the claims are provided only as illustrative examples and should not be construed as limiting the scope of the claims in any way.

[0116] It can be understood that, in the specific implementation of the present application, relevant data such as software test cases are involved. When the above embodiments of the present application are applied to specific products or technologies, user permission or consent is required, and the collection, use, and processing of relevant data need to comply with relevant laws, regulations, and standards of relevant countries and regions.

Claims

1. A method for generating a query statement, characterized in that, The method includes: Obtaining a natural statement containing query information, where the natural statement describes the query information in natural language; Using a structured statement generation model to generate a structured statement corresponding to the natural statement according to the natural statement, the structured statement includes multiple word classes and words corresponding to each word class, and the structured statement generation model is a trained deep learning model; Determining a query statement based on the word classes and corresponding words in the structured statement, where the query statement describes the query information in a query language.

2. The method according to claim 1, wherein The structured statement generation model is obtained by training a deep learning model using a training sample set; the training sample set includes a first training sample set, and the first training sample set includes multiple first-class training sample pairs, and each first-class training sample pair includes a natural statement and its corresponding structured statement.

3. The method according to claim 2, characterized in that, The first-class training sample pairs are determined through the following steps: Obtaining an initial training sample pair, where the initial training sample pair includes a natural statement and its corresponding structured statement, and each word class and corresponding word in the structured statement correspond to a part of the content in the natural statement; Taking the initial training sample pair as the first current training sample pair; Performing a partial replication operation on the first current training sample pair, and determining the first current training sample pair after the partial replication operation as a first-class training sample pair; Or Taking the initial training sample pair as the second current training sample pair; Performing a partial deletion operation on the second current training sample pair, and determining the second current training sample pair after the partial deletion operation as another first-class training sample pair; Or Taking the initial training sample pair as the third current training sample pair; Performing a partial replacement operation on the third current training sample pair, and determining the third current training sample pair after the partial replacement operation as another first-class training sample pair; Wherein, the partial replication operation includes: copying a first part of the content in the natural statement of the first current training sample pair, so that the natural statement after copying has repeated first part of the content, and determining the natural statement with repeated first part of the content and the structured statement of the first current training sample pair as the first current training sample pair after the partial replication operation; The partial deletion operation includes: Deleting a first part of the content in the natural statement of the second current training sample pair, so that the natural statement after deletion no longer has the first part of the content, Deleting the word classes and words corresponding to the first part of the content in the structured statement of the second current training sample pair, so that the structured statement after deletion no longer has the word classes and words corresponding to the first part of the content, Determining the natural statement after deletion and the structured statement after deletion as the second current training sample pair after the partial deletion operation; The partial replacement operation includes: Replace the first part of the content of the natural sentence in the third current training sample pair with the first phrase to obtain a natural sentence after the partial replacement operation. The part-of-speech of the structured sentence corresponding to the first phrase is the same as that of the structured sentence corresponding to the first part of the content, but the words of the structured sentence corresponding to the first phrase are different from those of the structured sentence corresponding to the first part of the content. Replace the words corresponding to the first part of the content in the structured sentence of the third current training sample pair with the words of the structured sentence corresponding to the first phrase to obtain a structured sentence after the partial replacement operation. Determine the natural sentence after the partial replacement operation and the structured sentence after the partial replacement operation as the third current training sample pair after the partial replacement operation.

4. The method according to claim 2, wherein The structured sentence generation model is obtained by the deep learning model performing the first training step using the first training sample set. The first training step includes: Input the natural sentence of the first type of training sample pair into the deep learning model to obtain the actual output of the deep learning model. Use the structured sentence of the first type of training sample pair as the expected output of the deep learning model, and determine the difference between the actual output and the expected output as the first difference of the first type of training sample pair. Determine the first difference of each first type of training sample pair in the first training sample set, accumulate the first differences corresponding to all first type of training sample pairs in the first training sample set, and determine the accumulated result as the first loss. Adjust the model parameters of the deep learning model until the first loss is less than or equal to the first predetermined threshold; and Determine the deep learning model with its model parameters adjusted as the structured sentence generation model.

5. The method according to claim 2, wherein The training sample set further includes a second training sample set. The second training sample set includes multiple second type of training sample pairs. Each second type of training sample pair includes an initial natural sentence and its corresponding canonical natural sentence. The canonical natural sentence describes the query information included in the initial natural sentence in a predetermined expression. The structured sentence generation model is further obtained by the deep learning model performing the second training step using the second training sample set. The second training step includes: Input the initial natural sentence of the second type of training sample pair into the deep learning model to obtain the actual output of the deep learning model. Use the canonical natural sentence of the second type of training sample pair as the expected output of the deep learning model, and determine the difference between the actual output and the expected output as the second difference of the second type of training sample pair. Determine the second difference of each second type of training sample pair in the second training sample set, accumulate the second differences of all second type of training sample pairs in the second training sample set, and determine the accumulated result as the second loss. Adjust the model parameters of the deep learning model until the second loss is less than or equal to the second predetermined threshold; and Determine the deep learning model with its model parameters adjusted as the structured sentence generation model.

6. The method according to claim 2, wherein The training sample set further includes a third training sample set, which includes a plurality of third-class training sample pairs. Each third-class training sample pair includes a structured statement and its corresponding canonical natural statement. The canonical natural statement describes the query information included in the structured statement in natural language in a predetermined expression; The structured statement generation model is further obtained by performing a third training step on the deep learning model using the third training sample set. The third training step includes: Inputting the structured statement of the third-class training sample pair into the deep learning model to obtain the actual output of the deep learning model; Taking the canonical natural statement of the third-class training sample pair as the expected output of the deep learning model, and determining the difference between the actual output and the expected output as the third difference of the third-class training sample pair; Determining the third difference of each third-class training sample pair in the third training sample set, accumulating the third differences of all third-class training sample pairs in the third training sample set, and determining the accumulated result as the third loss; Adjusting the model parameters of the deep learning model until the third loss is less than or equal to a third predetermined threshold; and, Determining the deep learning model with its model parameters adjusted as the structured statement generation model.

7. The method according to claim 1, characterized in that, The parts of speech of the structured statement include one or more of: the table to be queried, the dimension to be queried, the condition of the query, the operation on the data, and the query mode.

8. The method according to claim 7, wherein Determining the query statement based on the parts of speech and the corresponding words in the structured statement includes: Determining the composition rules of the words corresponding to the parts of speech in the query language; Organizing the words of each part of speech in the structured statement based on the composition rules to determine the query statement corresponding to the structured statement.

9. The method according to claim 8, characterized in that The query language includes Structured Query Language (SQL), and the structured statement organizes the multiple parts of speech and the corresponding words included therein in a domain-specific language.

10. A data query method, characterized in that, It includes: Obtaining a natural statement for querying data; Determining the query statement corresponding to the natural statement by using the query statement generation method according to any one of claims 1-9; And, Querying the corresponding data in the database by using the query statement.

11. A query statement generation device, characterized in that, The query statement generation device includes: A first acquisition module configured to acquire a natural statement containing query information, where the natural statement describes the query information in natural language; A structured statement generation module configured to use a structured statement generation model to generate a structured statement corresponding to the natural statement according to the natural statement. The structured statement includes multiple parts of speech and the corresponding words for each part of speech, and the structured statement generation model is a trained deep learning model; A query statement generation module configured to determine a query statement based on the parts of speech and the corresponding words in the structured statement, where the query statement describes the query information in a query language.

12. A data query device, characterized in that, The data query device includes: A second acquisition module configured to acquire a natural statement for querying data; A query statement determination module configured to determine a query statement corresponding to the natural statement by using the query statement generation method according to any one of claims 1-9; and, A data query module configured to query corresponding data in a database by using the query statement.

13. A computing device, comprising: A memory configured to store computer-executable instructions; And A processor configured to execute the method according to any one of claims 1-10 when the computer-executable instructions are executed by the processor.

14. A computer-readable storage medium storing computer-executable instructions that, when executed, implement the method according to any one of claims 1-10.

15. A computer program product comprising a computer program that, when executed by a processor, implements the steps of the method according to any one of claims 1 to 10.

Citation Information

Cited By

  • Query statement generation method and device based on large model, medium and equipment

    CN120541191A

  • A method, apparatus, medium, and device for generating query statements based on a large model.

    CN120541191B