Semantic analysis method and device, electronic equipment and storage medium

文档序号:8300 发布日期:2021-09-17 浏览:31次 中文

1. A semantic parsing method, comprising:

encoding the input questions and the corresponding database;

and generating a Structured Query Language (SQL) query statement according to the coding result, wherein the following processing is respectively carried out on any SQL clause:

determining a question segment corresponding to the SQL clause in the question;

and generating the SQL clause according to the question segment.

2. The method of claim 1, further comprising: segmenting the problem to obtain at least two problem segments;

the determining of the question fragment corresponding to the SQL clause in the question comprises: and selecting the question segment corresponding to the SQL clause from the at least two question segments.

3. The method of claim 1, wherein different SQL clauses correspond to different question fragments, respectively.

4. The method according to any of claims 1-3, wherein said generating the SQL clause from the question fragment comprises:

aiming at any SQL clause, taking a question segment corresponding to the SQL clause as a main reference object, taking other question segments in the question as auxiliary reference objects, and combining the main reference object and the auxiliary reference objects to generate the SQL clause.

5. The method according to claim 4, wherein the taking the question fragment corresponding to the SQL clause as a main reference object and the other question fragments in the question as auxiliary reference objects comprises:

and setting the weight of the question segment corresponding to the SQL clause to be higher than the weights of other question segments in the question.

6. A semantic parsing apparatus comprising: the device comprises an encoding module and a generating module;

the coding module is used for coding the input problems and the corresponding database;

the generating module is used for generating a Structured Query Language (SQL) query statement according to the coding result, wherein the following processing is respectively carried out on any SQL clause: determining a question segment corresponding to the SQL clause in the question; and generating the SQL clause according to the question segment.

7. The apparatus of claim 6, wherein,

the generating module is further used for segmenting the question to obtain at least two question segments, and selecting the question segment corresponding to the SQL clause from the at least two question segments aiming at any SQL clause.

8. The apparatus of claim 6, wherein different SQL clauses correspond to different question fragments, respectively.

9. The apparatus of any one of claims 6 to 8,

the generating module takes a question segment corresponding to any SQL clause as a main reference object, takes other question segments in the question as auxiliary reference objects, and combines the main reference object and the auxiliary reference objects to generate the SQL clause.

10. The apparatus of claim 9, wherein,

the generating module sets the weight of the question segment corresponding to the SQL clause to be higher than the weight of other question segments in the question.

11. An electronic device, comprising:

at least one processor; and

a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,

the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-5.

12. A non-transitory computer readable storage medium having stored thereon computer instructions for causing a computer to perform the method of any one of claims 1-5.

13. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-5.

Background

Semantic parsing (Text-to-SQL) is a core technology of Language understanding, aiming to automatically convert natural Language questions into Structured Query Language (SQL) Query statements that can interact with databases.

Wherein the executable SQL query statement may be generated based on the input question and the corresponding database. At present, when an SQL query statement is generated, information referenced by different SQL clauses is the same, so that elements with high matching degree with an input problem in a database are generally selected by multiple grammars, and elements which should be selected are not selected, thereby reducing accuracy of the generated SQL query statement.

Disclosure of Invention

The disclosure provides a semantic parsing method, a semantic parsing device, an electronic device and a storage medium.

A semantic parsing method, comprising:

encoding the input questions and the corresponding database;

and generating a Structured Query Language (SQL) query statement according to the coding result, wherein the following processing is respectively carried out on any SQL clause:

determining a question segment corresponding to the SQL clause in the question;

and generating the SQL clause according to the question segment.

A semantic parsing apparatus comprising: the device comprises an encoding module and a generating module;

the coding module is used for coding the input problems and the corresponding database;

the generating module is used for generating a Structured Query Language (SQL) query statement according to the coding result, wherein the following processing is respectively carried out on any SQL clause: determining a question segment corresponding to the SQL clause in the question; and generating the SQL clause according to the question segment.

An electronic device, comprising:

at least one processor; and

a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,

the memory stores instructions executable by the at least one processor to enable the at least one processor to perform a method as described above.

A non-transitory computer readable storage medium storing computer instructions for causing a computer to perform the method as described above.

A computer program product comprising a computer program which, when executed by a processor, implements a method as described above.

One embodiment in the above disclosure has the following advantages or benefits: when the SQL query statement is generated, the different SQL clauses respectively select the corresponding problem fragments for reference, so that the problems in the prior art are solved, and the accuracy of the generated SQL query statement is improved.

It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present disclosure, nor do they limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.

Drawings

The drawings are included to provide a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein:

FIG. 1 is a flow chart of an embodiment of a semantic parsing method according to the present disclosure;

FIG. 2 is a diagram illustrating a tree corresponding to a certain SQL query statement according to the present disclosure;

FIG. 3 is a schematic diagram of a database according to the present disclosure;

FIG. 4 is a schematic diagram of an overall implementation process of the semantic analysis method according to the present disclosure;

fig. 5 is a schematic diagram illustrating a structure of a semantic analysis apparatus 500 according to an embodiment of the disclosure;

FIG. 6 illustrates a schematic block diagram of an example electronic device 600 that can be used to implement embodiments of the present disclosure.

Detailed Description

Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, in which various details of the embodiments of the disclosure are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.

In addition, it should be understood that the term "and/or" herein is merely one type of association relationship that describes an associated object, meaning that three relationships may exist, e.g., a and/or B may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.

Fig. 1 is a flowchart of an embodiment of a semantic parsing method according to the present disclosure. As shown in fig. 1, the following detailed implementation is included.

In step 101, the input question is encoded with the corresponding database.

In step 102, an SQL query statement is generated from the encoding result, wherein any SQL clause is processed in the manner shown in steps 103-104.

In step 103, a question segment in the question corresponding to the SQL clause is determined.

In step 104, the SQL clause is generated according to the determined question segment.

It can be seen that, the above method embodiment provides a semantic parsing mode based on the concept of segment alignment, and when generating an SQL query statement, different SQL clauses may respectively select corresponding problem segments for reference, thereby overcoming the problems in the prior art, and improving the accuracy of the generated SQL query statement, etc.

The generated SQL query statement is usually a grammar sequence, which may be represented as a tree, and the sequence obtained by the depth-first traversal of the tree is the grammar sequence.

FIG. 2 illustrates an embodiment of the present disclosureAs shown in fig. 2, the diagram of the tree corresponding to the SQL query statement assumes that the SQL query statement is: population density of the sea of pearl (selection population/area (km)2) FROM T1 WHERE name ═ zhuhai'), WHERE T1 denotes table 1 in the database, i.e. a table about chinese Cities (China Cities).

FIG. 3 is a schematic diagram of a database according to the present disclosure. As shown in fig. 3, besides table 1, table 2(T2) and the like may be further included in the database, that is, a plurality of different tables may be included in the database.

For an input question, it may first be encoded with a corresponding database. For example, the input questions can be spliced with the corresponding database for encoding.

How to encode is not limited, and for example, the encoding may be performed using a Long Short-Term Memory network (LSTM) model or a model based on a transformer framework. The model based on the transform framework may be a fine-tuning (fine-tuning) model based on a pre-training model. The pre-training model may be any commonly used pre-training model.

Further, an SQL query statement may be generated from the encoded result. For any SQL clause, a question segment corresponding to the SQL clause in the input questions can be respectively determined, and the SQL clause can be generated according to the determined question segment.

To this end, in one embodiment of the present disclosure, the input question may be sliced, resulting in at least two question segments. Each question fragment typically has relatively complete semantics.

In addition, there may be some content duplication in different question fragments. For example, the input problem is: the wine name (given as the wine name of wine with its own taste and produced in 2006) for any wine produced at a price higher than 2006 may include the following question fragments: wine names (given the names of the wines), wines with prices higher than any wine (wines with prices above the wine) and wines produced in 2006 (wineproduced in 2006) are given.

Correspondingly, for any SQL clause, when a question segment corresponding to the SQL clause in the input question needs to be determined, a question segment corresponding to the SQL clause can be selected from the at least two question segments.

How to segment the input question and how to select the question segment corresponding to the SQL clause are not limited. For example, as a possible implementation manner, training of the model may be performed in advance, so that the model learns how to segment the input question and how to select the question segment corresponding to the SQL clause. Therefore, after training is completed, aiming at any input problem, the model can be segmented according to the learned ability, and problem segments corresponding to different SQL clauses can be selected.

When the model is trained, the input problems can be manually segmented to obtain a plurality of problem fragments, or an automatic segmentation and manual correction mode can be adopted, or the model can be completely made to learn how to segment and the like.

For any SQL clause, the corresponding question segment is the question segment most aligned with the SQL clause.

Each SQL clause corresponds to a sub-tree, as shown in fig. 2, which includes SQL clauses such as Select (Select) and filter (Where), it can be seen that each SQL clause corresponds to a sub-tree.

In one embodiment of the present disclosure, different SQL clauses may correspond to different question fragments. Assuming that 3 question segments and 3 SQL clauses are included, which are respectively called question segment 1, question segment 2 and question segment 3, and SQL clause 1, SQL clause 2 and SQL clause 3 for convenience of expression, assuming that the question segment corresponding to SQL clause 1 is question segment 1, the question segment corresponding to SQL clause 2 will be question segment 2 or question segment 3, and assuming that it is question segment 3, the question segment corresponding to SQL clause 3 will be question segment 2.

That is to say, a problem fragment is selected and then cannot be selected again, so that each problem fragment in the input problem can be used, information in the problem is prevented from being lost, and the accuracy of subsequently generated SQL query statements is improved.

For any SQL clause, after the corresponding question segment is determined, the SQL clause can be generated according to the corresponding question segment.

In an embodiment of the present disclosure, for any SQL clause, a question segment corresponding to the SQL clause may be used as a main reference object, and other question segments in the input question may be used as auxiliary reference objects, and the SQL clause is generated by combining the main reference object and the auxiliary reference objects.

In an embodiment of the present disclosure, a specific manner of taking the question fragment corresponding to the SQL clause as a main reference object and taking other question fragments in the input question as auxiliary reference objects may be as follows: and setting the weight of the question segment corresponding to the SQL clause to be higher than the weights of other question segments in the input question.

Assuming that there are three problem segments, which are called problem segment 1, problem segment 2 and problem segment 3 for convenience of description, taking the SQL clause shown in fig. 2 as an example, after determining the corresponding problem segment, assuming that the problem segment 1 is the problem segment 1, the weight of the problem segment 1 may be set to be higher than the weights of the problem segment 2 and the problem segment 3, accordingly, when generating the SQL clause, the problem segment 1 may be mainly referred to, but the problem segment 2 and the problem segment 3 may be combined at the same time, so that not only the information in the problem segment 1 is focused, but also the problem segment 2 and the problem segment 3 are considered at the same time, thereby ensuring the accuracy of the generated SQL clause.

How to generate the SQL clause is not limited, and for example, a tree generation algorithm based on syntax decoding may be used. For any SQL clause, the generation of the SQL clause can be completed based on the corresponding question segment and the like, and the generation of the grammar and the database elements in the SQL clause is included.

Based on the above description, fig. 4 is a schematic diagram of an overall implementation process of the semantic analysis method according to the present disclosure.

As shown in fig. 4, the input question and the corresponding database may be encoded, for example, using an LSTM model or a transform framework-based model. Among them, it is assumed that the input problem is "How much more fertile people than the pearl sea (How much more fertile people live in the life of the pearl sea)" and the like.

As shown in fig. 4, the input question may also be segmented to obtain at least two question segments, and the number of the obtained question segments depends on the actual situation.

As shown in fig. 4, when SQL query statements may be further generated, the following processes may be performed for each SQL clause: first, a question segment corresponding to the SQL clause is determined, that is, a question segment corresponding to the SQL clause is selected from the at least two question segments, and then the SQL clause may be generated according to the determined question segment. Different SQL clauses can respectively correspond to different question fragments.

Specifically, for each SQL clause, the question segment corresponding to the SQL clause may be used as a main reference object, and other question segments may be used as auxiliary reference objects, for example, the weight of the question segment corresponding to the SQL clause may be set to be higher than the weight of the other question segments, and the SQL clause may be generated by combining the main reference object and the auxiliary reference objects.

After the above processing, for the input problem "How many more match trees are heat of the heart in the Hefei of the in Zhuhai", the final SQL query statement can be obtained as follows:

SELECT a-b FROM

(SELECT population FROM T1 WHERE name=‘Hefei’)a,

(SELECT population FROM T1 WHERE name=‘Zhuhai’)b。

subsequently, the obtained SQL query statement may be executed, thereby obtaining an answer corresponding to the input question.

For a specific implementation of the process shown in fig. 4, reference is made to the foregoing related description, which is not repeated herein.

It is noted that while for simplicity of explanation, the foregoing method embodiments are described as a series of acts, those skilled in the art will appreciate that the present disclosure is not limited by the order of acts, as some steps may, in accordance with the present disclosure, occur in other orders and concurrently. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required for the disclosure.

The above is a description of embodiments of the method, and the embodiments of the apparatus are further described below.

Fig. 5 is a schematic structural diagram illustrating a semantic analysis apparatus 500 according to an embodiment of the present disclosure. As shown in fig. 5, includes: an encoding module 501 and a generating module 502.

And the encoding module 501 is used for encoding the input questions and the corresponding database.

A generating module 502, configured to generate an SQL query statement according to the encoding result, where, for any SQL clause, the following processing may be performed: determining a problem segment corresponding to the SQL clause in the problem; and generating the SQL clause according to the determined problem segment.

For the input question, the encoding module 501 may encode the input question with the corresponding database, for example, the input question may be spliced with the corresponding database for encoding.

Further, the generating module 502 may generate the SQL query statement according to the encoding result. For any SQL clause, a question segment corresponding to the SQL clause in the input questions can be respectively determined, and the SQL clause can be generated according to the determined question segment.

For this reason, the generating module 502 may further segment the input question to obtain at least two question segments, and accordingly, for any SQL clause, a question segment corresponding to the SQL clause may be selected from the at least two question segments.

For any SQL clause, the corresponding question segment is the question segment most aligned with the SQL clause.

Different SQL clauses can respectively correspond to different question fragments. That is, a question fragment is selected and will not be selected again.

For any SQL clause, after the corresponding question segment is determined, the SQL clause can be generated according to the corresponding question segment. Specifically, for any SQL clause, the question segment corresponding to the SQL clause may be used as a main reference object, and other question segments in the input question may be used as auxiliary reference objects, and the SQL clause may be generated by combining the main reference object and the auxiliary reference objects.

The specific way of taking the question fragment corresponding to the SQL clause as the main reference object and taking other question fragments in the input question as the auxiliary reference objects may be as follows: and setting the weight of the question segment corresponding to the SQL clause to be higher than the weights of other question segments in the input question.

How to generate the SQL clause is not limited, and for example, a tree generation algorithm based on syntax decoding may be used. For any SQL clause, the generation of the SQL clause can be completed based on the corresponding question segment and the like, and the generation of the grammar and the database elements in the SQL clause is included.

For a specific work flow of the apparatus embodiment shown in fig. 5, reference is made to the related description in the foregoing method embodiment, and details are not repeated.

In summary, according to the scheme of the embodiment of the present disclosure, a semantic parsing manner based on a segment alignment concept is provided, and when generating an SQL query statement, different SQL clauses may respectively select corresponding problem segments for reference, thereby overcoming the problems in the prior art, and improving the accuracy of the generated SQL query statement.

The scheme disclosed by the disclosure can be applied to the field of artificial intelligence, in particular to the fields of natural language processing, deep learning and the like.

Artificial intelligence is a subject for studying a computer to simulate some thinking processes and intelligent behaviors (such as learning, reasoning, thinking, planning and the like) of a human, and has a hardware technology and a software technology, the artificial intelligence hardware technology generally comprises technologies such as a sensor, a special artificial intelligence chip, cloud computing, distributed storage, big data processing and the like, and the artificial intelligence software technology mainly comprises a computer vision technology, a voice recognition technology, a natural language processing technology, machine learning/deep learning, a big data processing technology, a knowledge graph technology and the like.

The present disclosure also provides an electronic device, a readable storage medium, and a computer program product according to embodiments of the present disclosure.

FIG. 6 illustrates a schematic block diagram of an example electronic device 600 that can be used to implement embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital assistants, cellular telephones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the disclosure described and/or claimed herein.

As shown in fig. 6, the apparatus 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a Read Only Memory (ROM)602 or a computer program loaded from a storage unit 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the device 600 can also be stored. The calculation unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.

A number of components in the device 600 are connected to the I/O interface 605, including: an input unit 606 such as a keyboard, a mouse, or the like; an output unit 607 such as various types of displays, speakers, and the like; a storage unit 608, such as a magnetic disk, optical disk, or the like; and a communication unit 609 such as a network card, modem, wireless communication transceiver, etc. The communication unit 609 allows the device 600 to exchange information/data with other devices via a computer network such as the internet and/or various telecommunication networks.

The computing unit 601 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various dedicated Artificial Intelligence (AI) computing chips, various computing units running machine learning model algorithms, a Digital Signal Processor (DSP), and any suitable processor, controller, microcontroller, and so forth. The computing unit 601 performs the various methods and processes described above, such as the methods described in this disclosure. For example, in some embodiments, the methods described in this disclosure may be implemented as a computer software program tangibly embodied in a machine-readable medium, such as storage unit 608. In some embodiments, part or all of the computer program may be loaded and/or installed onto the device 600 via the ROM 602 and/or the communication unit 609. When the computer program is loaded into RAM 603 and executed by the computing unit 601, one or more steps of the methods described in the present disclosure may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured by any other suitable means (e.g., by means of firmware) to perform the methods described in the present disclosure.

Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, Field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), system on a chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.

Program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions/operations specified in the flowchart and/or block diagram to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.

In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic, speech, or tactile input.

The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), Wide Area Networks (WANs), and the Internet.

The computer system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also called a cloud computing server or a cloud host, and is a host product in a cloud computing service system, so as to solve the defects of high management difficulty and weak service expansibility in the traditional physical host and Virtual Private Server (VPS). The server may also be a server of a distributed system, or a server incorporating a blockchain. Cloud computing refers to accessing an elastically extensible shared physical or virtual resource pool through a network, resources can include servers, operating systems, networks, software, applications, storage devices and the like, a technical system for deploying and managing the resources in a self-service mode as required can be achieved, and efficient and powerful data processing capacity can be provided for technical applications and model training of artificial intelligence, block chains and the like through a cloud computing technology.

It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present disclosure may be executed in parallel, sequentially, or in different orders, as long as the desired results of the technical solutions disclosed in the present disclosure can be achieved, and the present disclosure is not limited herein.

The above detailed description should not be construed as limiting the scope of the disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made in accordance with design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present disclosure should be included in the scope of protection of the present disclosure.

完整详细技术资料下载
上一篇:石墨接头机器人自动装卡簧、装栓机
下一篇:语义表示模型的训练方法、装置、设备和存储介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!