Natural language processing method and device, electronic equipment and storage medium

By obtaining natural language information and calculating the similarity of vector databases, it generates and iteratively corrects structured statements, solving the problem of low accuracy in generating structured statements in the existing technology and improving accuracy and user experience.

CN118606352AActive Publication Date: 2024-09-06SHENZHEN LUMIUNITED TECH CO LTD

Patent Information

Application Number
CN202410771452.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-14
Publication Date
2024-09-06
Estimated Expiration
2044-06-14

AI Technical Summary

Technical Problem

In the existing technology, the accuracy of generating structured sentences from natural language is not high. Especially for non-professional users, it is difficult to understand the user's intention and modify the generated structured sentences by themselves, resulting in low accuracy of the generated structured sentences.

Method used

By obtaining the input natural language information, convert it into a query vector, and calculate the similarity with the pre-built vector database, obtain the target vector whose similarity meets the set conditions, generate an initial structured statement based on the contextual background data, and pass the language processing model Processing and iterative corrections are performed until a successful structured statement is generated.

Benefits of technology

It improves the accuracy of generating structured statements, reduces user burden, enhances query efficiency and experience for non-professional users, and ensures that the generated structured statements are consistent with user expectations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118606352A
    Figure CN118606352A
Patent Text Reader

Abstract

The invention provides a natural language processing method and device, electronic equipment and a storage medium, and relates to the technical field of computers. The method comprises the following steps: acquiring input natural language information, and acquiring a corresponding query vector based on the natural language information; calculating the similarity between the query vector and each data vector in the constructed vector database, and if the similarity meets a set condition, obtaining the data vector of which the similarity meets the set condition in the vector database as a target vector; obtaining context background data of the target vector in a vector database, generating a corresponding initial structured statement based on the context background data and the query vector, and executing corresponding processing based on the initial structured statement to obtain an execution result; and if the initial structured statement is successfully executed, determining that the initial structured statement is a target structured statement. According to the method and the device, the problem of low accuracy of the generated structured statement in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology. Specifically, the present application relates to a natural language processing method, device, electronic device, storage medium and computer program product. Background Art

[0002] With the rapid development of computer technology, structured languages ​​are widely used in various fields. By processing natural languages ​​to obtain structured languages, various data processing such as query, insert, update and delete can be realized. SQL (Structured Query Language) is a common structured query language, which also includes structured programming languages ​​(such as C, Java), structured text markup languages ​​(such as HTML, XML), etc. These structured languages ​​have certain grammatical rules and structures to effectively organize and process data or information.

[0003] Traditional structured generation methods usually require users to have certain knowledge of structured language and the ability to understand database structure. There is a certain threshold for non-professional users. In actual applications, natural language generation structured technology still has some problems and challenges, such as: lack of background knowledge and inability to fully understand the user's intentions, resulting in the generated structure may not meet the user's expectations; unable to correct the generated structure by itself. The above problems may result in the low accuracy of the generated structured sentences.

[0004] From the above, we can see that how to improve the accuracy of generated structured sentences still needs to be solved. Summary of the invention

[0005] The present application provides a natural language processing method, device, electronic device, storage medium and computer program product, which can solve the problem of low accuracy of generated structured sentences in related technologies. The technical solution is as follows:

[0006] According to one aspect of the present application, a natural language processing method comprises:

[0007] Obtain input natural language information, and obtain a corresponding query vector based on the natural language information;

[0008] Calculate the similarity between the query vector and each data vector in the constructed vector database, and if the similarity satisfies a set condition, obtain the data vector in the vector database whose similarity satisfies the set condition as the target vector; wherein the data vector in the vector database includes vectors obtained by converting various data through the embedding model;

[0009] Acquire context data of the target vector in a vector database, generate a corresponding initial structured statement based on the context data and the query vector, and perform corresponding processing based on the initial structured statement to obtain an execution result;

[0010] If the initial structured statement is executed successfully, the initial structured statement is determined to be a target structured statement.

[0011] According to one aspect of the present application, a natural language processing device further includes:

[0012] A query vector acquisition module, which acquires input natural language information and is used to acquire a corresponding query vector based on the natural language information;

[0013] A target vector acquisition module calculates the similarity between the query vector and each data vector in the constructed vector database, and if the similarity satisfies a set condition, is used to obtain a data vector in the vector database whose similarity satisfies the set condition as a target vector; wherein the data vector in the vector database includes vectors obtained by converting various data through an embedding model;

[0014] The target structured statement determination module obtains the context background data of the target vector in the vector database, generates a corresponding initial structured statement based on the context background data and the query vector, performs corresponding processing based on the initial structured statement, and obtains an execution result; if the initial structured statement is executed successfully, it is used to determine that the initial structured statement is the target structured statement.

[0015] In an exemplary embodiment, the apparatus includes, but is not limited to:

[0016] A calculation module, used to calculate the table structure similarity between the query vector and each table structure data in the vector database; wherein there are multiple table structure similarities;

[0017] A target table structure determination module is used to determine a target table structure that meets the conditions based on the obtained similarities of the table structures;

[0018] The context background data determination module uses the information corresponding to the target table structure to determine the context background data of the target vector.

[0019] In an exemplary embodiment, the acquiring context data of the target vector in the vector database and generating a corresponding initial structured statement based on the context data and the query vector includes but is not limited to:

[0020] A target semantics acquisition module, which performs semantic understanding processing on the query vector based on the contextual background data through a trained language processing model to obtain the target semantics corresponding to the natural language information;

[0021] The initial structured generation module is used to generate an initial structured sentence corresponding to the natural language information based on the target semantics.

[0022] In an exemplary embodiment, the language processing model includes a guide word template, and the guide word template includes at least one guide word for assisting in understanding the semantics of natural language information; the trained language processing model is used to perform semantic understanding processing on the query vector based on the context background data to obtain the target semantics corresponding to the natural language information, and the device includes but is not limited to:

[0023] The query vector is semantically understood by the trained language processing model based on the context background data and the guide word template to obtain the target semantics corresponding to the natural language information.

[0024] In an exemplary embodiment, the apparatus includes, but is not limited to:

[0025] The execution module modifies the initial structured statement if the execution result indicates that the initial structured statement fails to execute, and continues to execute the modified structured statement until the modified structured statement is successfully executed, and determines the successfully executed structured statement as the target structured statement.

[0026] In an exemplary embodiment, the initial structured statement is modified, and the modified structured statement is continuously executed until the modified structured statement is successfully executed, and the successfully executed structured statement is determined as a target structured statement, and the apparatus includes but is not limited to:

[0027] A transition structured statement generation module, inputting the initial structured statement into a language processing model, using the language processing model to generate a transition structured statement, and continuing to execute the transition structured statement;

[0028] If the transition structured sentence is executed successfully, the transition structured sentence is determined as the target structured sentence; wherein the transition structured sentence is a structured sentence regenerated by the language processing model based on the target vector.

[0029] In an exemplary embodiment, the inputting the initial structured sentence into a language processing model and generating a transitional structured sentence through the language processing model includes but is not limited to:

[0030] An error identification acquisition module, which is used to acquire an error identification in the initial structured statement after the initial structured statement fails to execute, wherein the error identification is information about an error that occurs during the execution of the initial structured statement;

[0031] The transition structured sentence determination module modifies the initial structured sentence based on the initial structured sentence and the error identifier, and uses the language processing model to determine the transition structured sentence.

[0032] In an exemplary embodiment, the apparatus includes, but is not limited to:

[0033] A corpus data acquisition module, used to acquire various types of corpus data; the corpus data includes at least one of table structure data, scenario data, and business knowledge data;

[0034] An extraction module, for extracting local features and context features of the corpus data through a trained embedding model;

[0035] A data vector generation module, for generating a data vector corresponding to the corpus data based on the local features and context features of the corpus data;

[0036] The vector database generation module is used to generate a vector database based on the generated data vectors of various types.

[0037] According to one aspect of the present application, an electronic device includes a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps in the natural language processing method of each embodiment of the present application when executing the computer program.

[0038] According to one aspect of the present application, a storage medium stores a computer program thereon, and when the computer program is executed by a processor, the steps in the natural language processing method of each embodiment of the present application are implemented.

[0039] According to one aspect of the present application, a computer program product includes a computer program, and when the computer program is executed by a processor, the steps in the natural language processing method of each embodiment of the present application are implemented.

[0040] The beneficial effects of the technical solution provided by this application are:

[0041] In the above technical scheme, by obtaining input natural language information, a corresponding query vector is obtained based on the natural language information, and then the similarity between the query vector and each data vector in the constructed vector database is calculated. If the similarity meets the set conditions, the data vector whose similarity meets the set conditions in the vector database is obtained as the target vector, wherein the data vector in the vector database includes vectors obtained by converting various data through an embedding model, the context background data of the target vector in the vector database is obtained, and a corresponding initial structured statement is generated based on the context background data and the query vector. Based on the initial structured statement, corresponding processing is performed to obtain an execution result. If the initial structured statement is successfully executed, the initial structured statement is finally determined to be the target structured statement. Compared with the existing method of generating structured statements, this method The scheme first converts natural language information into a query vector, and then calculates the similarity between the query vector and a vector database constructed in advance. When the similarity meets the set conditions, the first step is achieved, and an accurate target vector can be determined. Then, the corresponding context background data can be retrieved from the vector database through the target vector, and then a corresponding initial structured sentence is generated based on the context background data and the query vector, and the generated initial structured sentence is executed. If the initial structured sentence is executed successfully, the initial structured sentence is finally determined to be the target structured sentence. Iterative correction can be performed according to the result to improve the generated structured sentence, which can further improve the accuracy of the generated structured sentence; thereby, the problem of low accuracy of the generated structured sentence existing in the related art can be effectively solved. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are only some embodiments of the present application, and those skilled in the art can obtain other drawings based on these drawings without creative work.

[0043] Figure 1 A schematic diagram of an implementation environment involved in a natural language processing method;

[0044] Figure 2 is a flow chart of a natural language processing method according to an exemplary embodiment;

[0045] Figure 3 is a flowchart from S201 to S203 in a natural language processing method according to an exemplary embodiment;

[0046] Figure 4 is a flowchart from S221 to S223 in a natural language processing method according to an exemplary embodiment;

[0047] Figure 5 is a flowchart from S224 to S225 in a natural language processing method according to an exemplary embodiment;

[0048] Figure 6 is a flowchart from S2241 to S2242 in a natural language processing method according to an exemplary embodiment;

[0049] Figure 7 is a flowchart of constructing a vector database in S231 to S234 of a natural language processing method according to an exemplary embodiment;

[0050] Figure 8 is a schematic diagram of executing an initial structured sentence in a natural language processing method according to an exemplary embodiment;

[0051] Fig. 9 is a structural block diagram of a natural language processing device according to an exemplary embodiment;

[0052] Fig.10 The present invention is a structural block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0053] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present application.

[0054] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present disclosure refers to the presence of the features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be intermediate elements. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.

[0055] The following is an introduction and explanation of several terms involved in this application:

[0056] Language Processing Model (Large Language Model): Usually a natural language processing model with large-scale parameters and computing power, such as OpenAI's GPT-3.5 model. These models can be trained with a large amount of data and parameters to generate human-like text or answer natural language questions; if the initial structured sentence is executed successfully, the initial structured sentence is finally determined as the target structured sentence. It is widely used in natural language processing, text generation, and intelligent dialogue.

[0057] Embedding Model: Embedding model refers to the process of mapping high-dimensional data (such as text, pictures, audio) to low-dimensional space, among which word embedding is a technology that maps words or phrases to real vectors, such as Word2Vec, GloVe, etc. These embedding models can capture the semantic relationship between words, allowing machines to better understand natural language, and then apply them to natural language processing tasks.

[0058] Figure 1 Schematic diagram of an implementation environment involved in a natural language processing method. The implementation environment at least includes a user terminal 110, an intelligent device 130, a server 170, and a network device. Figure 1 In the embodiment, the network devices include a gateway 150 and a router 190, which is not specifically limited herein.

[0059] Among them, the user terminal 110, which can also be considered as a user end or terminal, can deploy (also understood as install) the client associated with the smart device 130. This user terminal 110 can be an electronic device such as a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart control panel, other devices with display and control functions, etc., which are not limited here.

[0060] Among them, the client is associated with the smart device 130, which essentially means that the user registers an account in the client and configures the smart device 130 in the client. For example, the configuration includes adding a device identifier to the smart device 130, so that when the client is run in the user terminal 110, it can provide the user with functions such as device display and device control of the smart device 130. This client can be in the form of an application or a web page. Accordingly, the interface for device display on the client can be in the form of a program window or a web page, which is not limited here.

[0061] The smart device 130 is deployed in the gateway 150, and communicates with the gateway 150 through its own configured communication module, and is then controlled by the gateway 150. It should be understood that the smart device 130 generally refers to one of the multiple smart devices 130, and the embodiment of the present application only takes the smart device 130 as an example, that is, the embodiment of the present application does not limit the number and device type of smart devices deployed in the gateway 150. In an application scenario, the smart device 130 accesses the gateway 150 through a local area network, and is thus deployed in the gateway 150. The process of the smart device 130 accessing the gateway 150 through the local area network includes: the gateway 150 first establishes a local area network, and the smart device 130 joins the local area network established by the gateway 150 by connecting to the gateway 150. This local area network includes, but is not limited to: ZIGBEE or Bluetooth. Among them, the smart device 130 can be a smart printer, a smart fax machine, a smart camera, a smart air conditioner, a smart door lock, a smart light, or a human body sensor equipped with a communication module, a door and window sensor, a temperature and humidity sensor, a water immersion sensor, a natural gas alarm, a smoke alarm, a wall switch, a wall socket, a wireless switch, a wireless wall sticker switch, a magic cube controller, a curtain motor, a millimeter wave radar, etc.

[0062] The interaction between the user terminal 110 and the smart device 130 can be achieved through a local area network or a wide area network. In one application scenario, the user terminal 110 establishes a communication connection between the router 190 and the gateway 150 in a wired or wireless manner. For example, the wired or wireless manner includes but is not limited to WIFI, so that the user terminal 110 and the gateway 150 are deployed in the same local area network, so that the user terminal 110 can interact with the smart device 130 through the local area network path. In another application scenario, the user terminal 110 establishes a communication connection between the server 170 and the gateway 150 in a wired or wireless manner. For example, the wired or wireless manner includes but is not limited to 2G, 3G, 4G, 5G, WIFI, etc., so that the user terminal 110 and the gateway 150 are deployed in the same wide area network, so that the user terminal 110 can interact with the smart device 130 through the wide area network path.

[0063] The server end 170 may also be considered as a cloud, a cloud platform, a platform end, a service end, etc. The server end 170 may be a server, a server cluster consisting of multiple servers, or a cloud computing center consisting of multiple servers, so as to better provide background services to a large number of user terminals 110. For example, the background service includes a device control service.

[0064] In an application scenario, the user terminal 110 obtains a corresponding query vector based on the query information, and then calculates the similarity between the query vector and the vector in the constructed vector database. When the similarity satisfies the set conditions, a data vector in the vector database whose similarity satisfies the set conditions can be obtained as a target vector. At the same time, the context background data corresponding to the target vector in the vector database can be obtained, and a corresponding initial structured statement can be generated based on the context background data and the query vector. After the corresponding initial structured statement is generated, when the initial structured statement is successfully executed, the initial structured statement can be determined as the target structured statement, thereby providing users with more effective device control services.

[0065] As mentioned above, the related art still has the problem that the accuracy of the generated structured sentences is not high.

[0066] To this end, the natural language processing method provided in the present application can effectively improve the accuracy of natural language processing. Accordingly, the natural language processing method is applicable to a natural language processing device, which can be deployed in an electronic device. For example, the electronic device can be specifically Figure 1 Gateways, servers, user terminals, etc.

[0067] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0068] In one embodiment, Figure 2 As shown, a natural language processing method is provided, and the method is applied to an electronic device as an example for explanation. The electronic device may be Figure 1 The gateway, server, user terminal, etc. in the embodiment of the present invention may include the following steps:

[0069] S200, obtaining input natural language information, and obtaining a corresponding query vector based on the natural language information.

[0070] Among them, the natural language information is generally the query terms used by the user in the query interface, and then the query terms are converted into query vectors. Here, the natural language information can be converted into query vectors through an embedding model.

[0071] It should be pointed out here that natural language information can generally be obtained by user input: the most common way is to directly collect the query terms input by the user from the user query interface (such as search engines, question-answering systems, chat robots, etc.).

[0072] A query vector usually refers to converting a natural language text (such as a word, phrase, sentence, or paragraph) into a fixed-length data vector that captures the semantic information in the text.

[0073] In addition, for embedding models, you can choose Word2Vec, GloVe, BERT, RoBERTa, GPT, etc. For word embedding models such as Word2Vec and GloVe, you can directly obtain its embedding vector through the index of the query word of the natural language information in the model; and for sentence embedding models such as BERT and RoBERTa, you need to input the natural language information into the model as a complete sentence or paragraph, and then obtain the vector output by the model. This vector usually represents the semantics of the entire sentence or paragraph. For different types of natural language information, you can choose different embedding models to obtain the corresponding query vector.

[0074] S210, calculating the similarity between the query vector and each data vector in the constructed vector database, and if the similarity meets the set condition, obtaining the data vector in the vector database whose similarity meets the set condition as the target vector.

[0075] The vector database refers to a database used to store and query vectors. The vectors stored in the database come from the vectorization of text, speech, image, video and other data. Compared with traditional databases, vector databases can process more unstructured data. Vector databases can provide vector similarity search by providing indexes to provide fast query and matching of large-scale and multi-dimensional vector data.

[0076] It is understandable that the vector database can be constructed in advance through various types of corpus data. Specifically, the data vectors in the vector database may include vectors obtained by converting various data through the embedding model.

[0077] After the electronic device obtains the query vector corresponding to the natural language information, it further calculates the similarity between the query vector and each data vector in the constructed vector database. Specifically, the electronic device can use algorithms such as Euclidean distance, cosine similarity, and Euclidean distance to calculate the similarity between the query vector and each data vector.

[0078] If there is a data vector whose similarity satisfies the set condition, the data vector whose similarity satisfies the set condition in the vector database is used as the target vector corresponding to the query vector.

[0079] S220, obtain the context background data of the target vector in the vector database, generate a corresponding initial structured statement based on the context background data and the query vector, perform corresponding processing based on the initial structured statement, and obtain an execution result; if the initial structured statement is executed successfully, determine that the initial structured statement is the target structured statement.

[0080] It should be pointed out here that contextual background data is additional information or data associated with the target vector in the vector database, which provides detailed information about the environment or situation in which the target vector is located; for example: suppose we have a vector database for storing product information, and the target vector represents a specific product. The contextual background data may include the product description, price, manufacturer, user reviews, etc., and the contextual background data can facilitate understanding the meaning of the target vector and generating accurate initial structured sentences.

[0081] The initial structured statement is a statement with clear syntax and structure generated based on the query vector and context background data, which describes the operation or query to be performed; example: in the above product example, the initial structured statement may be "query for 'specific products' manufactured by 'XYZ Company' with a price less than 100 yuan"; and the initial structured statement is an operation instruction that can be understood and executed by a computer program, which is used to retrieve, modify or process data from a database or other data source.

[0082] The execution result is the result obtained after executing the initial structured statement. This result may be data, status information, or any other form of output; Example: In the above commodity example, the execution result may be a list of commodities that meet the conditions, including their detailed information (such as name, price, manufacturer, etc.); The execution result is used to verify the correctness of the initial structured statement and as a criterion for subsequent processing or operation.

[0083] In the above scheme, by introducing the vector database and context background data, and passing the context background data to the language processing model, the generated structured sentences can more accurately meet the user's query needs, which helps the language processing model to better understand the user's intentions. In addition, during the user's query process, the user no longer needs to manually write structured sentences, but after entering the query requirements through natural language, the language processing model automatically generates structured sentences, which can greatly reduce the user's burden and improve the efficiency of data query.

[0084] Among them, after the user inputs the corresponding natural language information, the natural language information input by the user is first recognized, and the key information therein (such as location name, equipment type, etc.) is identified, so that the natural language information input by the user can be recognized at the first time.

[0085] like Figure 3 As shown, the specific identification process includes:

[0086] S201, performing data cleaning on natural language information;

[0087] It should be noted here that cleaning data involves two aspects. One is to remove any irrelevant or redundant information, such as deleting spaces, special characters, punctuation marks, etc. The other is to standardize the data to ensure a unified format. For example, convert all text to lowercase or use a certain encoding format uniformly.

[0088] During the cleaning process, first, special symbols and punctuation marks are removed from the text. This step is to remove various special symbols and punctuation marks that may be contained in the original text, such as commas, periods, exclamation marks, question marks, quotation marks, etc. These symbols often have no practical significance for model training and may interfere with the performance of the model. Subsequently, text tokenization is performed. Tokenization is the process of splitting text into individual words and is a basic step in NLP tasks. Then, stop word filtering is carried out. Stop words refer to words that frequently appear in the text but have no practical meaning for text expression, such as "de", "shi", "zai", etc. These words usually do not contribute to NLP tasks and therefore need to be filtered out. Then, lemmatization is performed. Lemmatization is the process of reducing words in the text to their basic form (or root form).

[0089] For example, "running" is reduced to "run", "better" is reduced to "good", etc. And lemmatization helps to reduce the diversity of vocabulary and improve the performance of the model. Then, text standardization is carried out to ensure the unified format and consistency of text data, which can include converting text to lowercase, removing numbers, removing HTML tags, removing URL links, etc. Standardization processing helps to reduce the complexity of the data and improve the accuracy of subsequent NLP tasks. Then, white spaces and redundant characters are removed. This step is to remove redundant white space characters such as spaces, tabs, line breaks, etc. in the text, as well as non-printable characters (such as control characters) that may exist. Finally, special characters and encoding issues are processed. If the text contains special characters (such as Unicode characters) or encoding issues (such as garbled characters), corresponding processing is required. Through the above process, the cleaning of natural language information is achieved.

[0090] S202, calculate the similarity between the cleaned natural language information and the data in the database;

[0091] It should be noted here that the data in the database includes table structure data, data samples, and business knowledge. During the process of calculating similarity, the electronic device needs to convert the cleaned natural language information and the data in the database into numerical feature representations, convert the text into vector form, the text is represented as a vector, and the similarity is measured by calculating the distance between these vectors.

[0092] In the process of similarity calculation, if it is a vector-based similarity calculation: if the natural language information and the data in the database are both represented as vectors, then the similarity measure between the vectors can be used to calculate their similarity. Common vector similarity measures include cosine similarity, Euclidean distance, etc.; if it is a model-based similarity calculation: in some cases, a pre-trained model (such as a deep learning model) can be used to calculate the similarity between natural language information and database data. For example, a text classification model or a question-answering model can be used to determine whether the natural language information is similar to an entry in the database.

[0093] S203, if the calculated similarity meets the threshold, the natural language information recognition is normal, which means that relevant information can be queried in the database and the corresponding query vector can be obtained; otherwise, the natural language information recognition is abnormal.

[0094] This indicates that no information related to the natural language information input by the user can be found in the database, and then a prompt message will be generated on the interface to remind the user to re-enter the query information, and the user can re-enter the information to be queried.

[0095] By executing steps S201 to S203, when a user performs a data query, feedback can be given to the user immediately, and incorrect names or terms in the natural language information input by the user can be identified to ensure the validity and correctness of the subsequently generated structured sentences.

[0096] In one embodiment, in the process of obtaining the contextual background data of the target vector in the vector database, such as Figure 4 As shown, the specific process includes:

[0097] S221, calculating the table structure similarities between the query vector and each table structure data in the vector database; wherein there are multiple table structure similarities.

[0098] It should be pointed out here that table structure data refers to the framework and rules that constitute the database table. It defines what types of data can be stored in the table and how the data is organized. Specifically, table structure data usually includes the following aspects: table name, column, data type, etc.

[0099] When obtaining the table structure similarity, you need to first extract the table structure features, such as table name, column, data type, etc., and then convert the table structure features into vectors. For text features such as table name and column name, you can use pre-trained word embedding models (such as Word2Vec, GloVe or FastText) to convert them into vectors. For classification features such as data types and constraints, you can use One-Hot Encoding, Label Encoding or Embedding Layer for encoding, and combine vectors from different features into a single vector representation. This can be achieved through simple concatenation, weighted sum or more complex neural network models. The calculation method of similarity has been mentioned above and will not be repeated here.

[0100] S222: Determine a target table structure that meets the conditions based on the obtained similarities of the table structures.

[0101] The process of determining the target table structure includes: the electronic device retrieves all table structure similarities, and then sorts all the table structure similarities. Before sorting, some table structure similarities may be screened out.

[0102] For example, after calculating the table structure similarity between the query vector and the table structure, the table structure similarity can be compared with a set threshold, and the table structure similarities greater than the threshold are placed in a set, defined as satisfying the set, and the other table structure similarities are placed in a set, defined as not satisfying the set. In the sorting stage, only the table structure similarities that satisfy the set need to be sorted; the table structure corresponding to the highest table structure similarity is determined as the target table structure.

[0103] Through the above-mentioned execution steps of determining the target table structure, the table structure that best matches the given query can be quickly found, so as to perform subsequent data processing or operations, thereby improving the efficiency of data retrieval and processing, and being able to select the most accurate table structure as the target table structure to improve the accuracy of subsequent generation of structured statements.

[0104] S223, determining the information corresponding to the target table structure as context background data of the target vector;

[0105] It should be pointed out here that the context background data includes not only the data itself, that is, the corresponding information in the determined target table structure as the context background data, but also various information and knowledge related to the data.

[0106] When determining contextual background data, it is necessary to clarify the specific goals of the analysis or application, such as prediction, classification, association analysis, etc. The contextual background data should directly support the realization of these goals; then understand what information is critical to making business decisions, and this information should be part of the contextual background data.

[0107] First, carefully review the structure of the target table, including column names, data types, constraints, etc., and then understand the meaning of each field and its application in the business; then, based on business needs, identify the key fields that are directly related to the target vector. These fields should contain information that has a significant impact on the target vector; then extract the data of these key fields from the target table and organize the extracted data into a format suitable as the context background data of the target vector.

[0108] By executing the above steps S221 to S223, the context background data is determined based on the target table structure, which can ensure that the acquired context background data in the database is most consistent with the natural language information input by the user. The context background data helps the language processing model to better understand the user's intentions.

[0109] In some embodiments, the process of generating a corresponding initial structured sentence based on the context background data and the query vector specifically includes:

[0110] Through the trained language processing model, the query vector is semantically understood based on the contextual background data to obtain the target semantics corresponding to the natural language information; based on the target semantics, an initial structured sentence corresponding to the natural language information is generated.

[0111] It can be understood that the trained language processing model has the ability to recognize the target semantics of natural language information. The language processing model can be obtained by training a large number of natural languages ​​of various types.

[0112] Among them, the target semantics is to determine the true intention of the user's query and the specific information or knowledge sought by analyzing and understanding the input natural language query and contextual background data.

[0113] In order to generate target semantics, the language processing model may also include a guide word template, which includes at least one guide word to assist in understanding the semantics of natural language information.

[0114] After the electronic device obtains the contextual background data of the target vector in the vector database, it can use the trained language processing model to perform semantic understanding processing on the query vector based on the contextual background data and the guide word template, and thus obtain the target semantics corresponding to the natural language information; through the guide word template, the accuracy of the target semantics can be further mentioned.

[0115] Then, based on the target semantics, an initial structured sentence corresponding to the natural language information is generated; through the generated target semantics, in the process of generating the initial structured sentence corresponding to the natural language information, the quality and accuracy of the initial structured sentence generated by the natural language can be improved.

[0116] After generating the initial structured statement, the electronic device needs to execute the generated initial structured statement to obtain the corresponding execution result; if the initial structured statement is executed successfully, the initial structured statement can be determined as the target structured statement, and then the target structured statement is displayed to the user on the display page.

[0117] Through the above process, when inputting and generating accurate structured sentences through natural language, users do not need to learn cumbersome structured sentence grammar and structure, and can query the database in a more intuitive and natural way. It can also identify and correct incorrect names or terms in user input, and improve the accuracy of the generated structured sentences. This can improve the query efficiency and experience of non-professional users and lower the usage threshold. Users no longer need to write structured sentences manually. Instead, after inputting query requirements through natural language, the large language model automatically generates structured sentences, which greatly reduces the user burden and improves the efficiency of data query. Contextual background data helps the large model better understand the user's intentions. By passing the contextual background to the large model, the generated structured sentences can more accurately meet the user's query needs.

[0118] In some embodiments, the language processing model includes a guide word template, the guide word template includes at least one guide word, and is used to assist in understanding the semantics of natural language information; the query vector is subjected to semantic understanding processing based on contextual background data through the trained language processing model to obtain the target semantics corresponding to the natural language information, including:

[0119] The query vector is semantically understood by the trained language processing model based on the context background data and the guide word template to obtain the target semantics corresponding to the natural language information.

[0120] In addition, the specific process of obtaining the target semantics can be achieved by using a trained language processing model to encode the preprocessed query vector and context background data. The language processing model converts the input data into a high-dimensional semantic vector representation. In this process, the model learns the structure and pattern of the language, so that it can capture the semantic information in the query. The language processing model analyzes the encoded semantic vector and identifies the user's query intention. Classification or clustering algorithms can be used to classify queries into different intent categories.

[0121] Based on the recognition of intent, the language processing model further analyzes the specific content of the query and extracts the specific information or knowledge the user is seeking. According to the results of intent recognition and semantic analysis, the language processing model generates the target semantics corresponding to the natural language information, and the target semantics is an accurate description of the user's query intent and the information sought.

[0122] In some embodiments, after performing corresponding processing based on the initial structured sentence and obtaining the execution result, the natural language processing method further includes:

[0123] If the execution result indicates that the initial structured statement fails to execute, the initial structured statement is modified, and the modified structured statement is continued to be executed until the modified structured statement is successfully executed, and the successfully executed structured statement is determined as the target structured statement.

[0124] Among them, the execution failure means that the execution result corresponding to the generated initial structured statement is not the result corresponding to the user, which means that the generated initial structured statement is not accurate enough.

[0125] Specifically, after the electronic device obtains the execution result, it can input the execution result, the initial structured statement and the natural language information into the trained language processing model, and determine whether the execution is successful or failed through the language processing model.

[0126] In other embodiments, the system can also automatically determine whether the initial structured statement is executed successfully. For example, the execution result can be compared with the initial structured statement to determine whether the execution is successful. If the matching degree reaches a preset threshold, it means that the execution is successful. For another example, the system identifies whether the execution result is successfully executed. If so, it means that the execution is successful. If the execution error is fed back, it means that the execution failed. For another example, after the execution result is obtained, it can be fed back to the user. If the user feeds back that the execution result is wrong, it means that the execution failed.

[0127] If the execution result indicates that the initial structured statement fails to execute, the electronic device further modifies the initial structured statement, for example, the initial structured statement can be adjusted and optimized based on the execution result and natural language information. Then the electronic device continues to execute the modified structured statement until the modified structured statement is successfully executed, and determines the successfully executed structured statement as the target structured statement.

[0128] In this embodiment, when the initial structured statement fails to execute, the initial structured statement is iteratively corrected by feeding back the running result of the initial structured language to improve the generated initial structured statement, thereby further improving the accuracy of the generated structured statement.

[0129] In some embodiments, Figure 5As shown, the modification process of the initial structured statement based on the running failure specifically includes:

[0130] S224, input the initial structured statement into the language processing model, generate a transitional structured statement through the language processing model, and continue to execute the transitional structured statement.

[0131] The transition structured sentence is generated after the language processing model modifies the initial structured sentence. Specifically, the language processing model modifies the initial structured sentence based on the location where the execution fails and the target vector.

[0132] S225: If the transition structured statement is executed successfully, the transition structured statement is determined as the target structured statement.

[0133] After modifying the initial structured statement, the language processing model outputs a transitional structured statement, which is a correction to the initial structured statement and is intended to solve the problem of execution failure. The transitional structured statement is submitted to the system for execution to verify whether the modification has successfully solved the original problem. If the execution is successful, the transitional structured statement is accepted as the final valid statement. If the execution still fails, it may be necessary to return to the step and restart the error detection and analysis process, and it may be necessary to adjust the parameters or strategies of the language processing model.

[0134] After the initial structured statement is executed, the failed initial structured statement is input into the language processing model for modification, and iterative correction is performed based on the result to improve the generated transition structured statement. By feeding back the running result of the initial structured language, the language processing model can iteratively correct the running result to improve the generated initial structured statement. The accuracy and quality of the generated structured statement can be further improved through its own self-correction mechanism.

[0135] In one embodiment, the initial structured sentence is input into the language processing model, and the language processing model generates a transitional structured sentence, such as Figure 6 As shown in the figure, the specific modification process includes:

[0136] S2241, after the initial structured statement fails to execute, obtain an error identifier in the initial structured statement.

[0137] The error indicator is information indicating an error occurred during the execution of the initial structured statement.

[0138] S2242, based on the initial structured sentence and the error identification, the language processing model modifies the initial structured sentence and determines a transitional structured sentence.

[0139] Among them, after the language processing model receives the initial structured sentence and the error mark, it is necessary to call the target vector again. The language processing model determines the error position in the initial structured sentence based on the error mark, and modifies the initial structured sentence based on the determined error position and the target vector, so as to obtain a more accurate transition structured sentence.

[0140] The specific process includes: when the initial structured statement fails to execute, the error information is first captured and the specific location of the execution failure is located. This location may be a grammatical error, logical error, missing data or other types of errors. Then the error location is analyzed in detail to understand why the error occurs. It is necessary to view the context background data, the target vector and the complete content of the initial structured statement. The initial structured statement, the location information of the execution failure and the context background data (if applicable) are input into the trained language processing model. The language processing model understands and analyzes the initial structured statement based on this information. The language processing model attempts to modify the statement according to the error location and context information of the initial structured statement. The modification may include correcting grammatical errors, adjusting the logical structure, supplementing missing data or replacing inappropriate vocabulary. After the modification, the language processing model outputs a transitional structured statement.

[0141] In the process of modifying the initial structured statement from S2241 to S2242, the initial structured statement that fails to execute can be accurately modified to generate a more accurate target structured statement.

[0142] In one embodiment, Figure 7 As shown in the figure, the construction process of the vector database is as follows:

[0143] S231, obtaining various types of corpus data.

[0144] Among them, the corpus data includes at least one of table structure data, scenario data, and business knowledge data, and the table structure data includes column names, data types, constraints, etc. The data samples are a small number of representative data samples selected according to business needs, and the business knowledge includes business rules, entity relationships, etc.

[0145] When acquiring various types of corpus data, we first need to clarify business needs and collect various data sources including table structure data (such as column names, data types, constraints, etc.), scenario data, and business knowledge data (such as business rules and entity relationships). Next, we need to verify and integrate the collected data to ensure data accuracy and consistency. During the data processing process, we need to select representative data samples and store them through appropriate storage solutions. Finally, we need to develop a data management system to ensure data security and availability, and continuously update and maintain data as the business develops to maintain its timeliness and accuracy.

[0146] S232, extracting local features and context features of the corpus data through the trained embedding model.

[0147] First, the corpus data is preprocessed to meet the input requirements of the embedding model; then, the trained embedding model is loaded; then, the local features of each word in the corpus are extracted through word embedding, and the contextual features of the words are captured in combination with the words in the context window; thus, the local features and contextual features can be extracted.

[0148] S233: Generate a data vector corresponding to the corpus data based on the local features and context features of the corpus data.

[0149] Among them, taking table structure data as an example, information such as column name, data type and constraint conditions can be extracted as the corresponding data vector. The column name is important text information that describes the data attributes. The data type (such as integer, floating point number, string, etc.) reflects the nature of the data and possible operations. Constraints: such as primary key, foreign key, uniqueness constraint, etc., provide information on data integrity and consistency.

[0150] Specifically, the electronic device can pre-process the corpus data to ensure the quality and consistency of the data. Then, the trained embedding model is used to extract local features and context features in the corpus. Local features are usually obtained through word embedding, that is, each word is converted into a real number vector, which contains the semantic information of the word, and context features are obtained by considering the context information of the word in the sentence or paragraph, which can be achieved by inputting the word into the embedding model together with the surrounding words.

[0151] After the features are extracted, they are combined into a feature set. Next, according to the requirements of the task and the characteristics of the data, a suitable encoding strategy is selected to encode the feature set. For text sequence data, models such as recurrent neural networks (RNN), long short-term memory networks (LSTM) or Transformer can be used to encode sequence information to capture the temporal dependencies and contextual relationships in the sequence. These models can convert each word or phrase in the sequence into a fixed-length vector representation. If the corpus data contains multiple sentences or paragraphs and they need to be combined into a whole data vector, feature aggregation is required. This can be achieved by averaging, summing or max pooling the embedding vectors of all sentences or paragraphs to obtain a single, fixed-length data vector, which represents the semantic information of the entire corpus data.

[0152] S234, generating a vector database based on the generated data vectors of various types.

[0153] Among them, the data vector maintains a corresponding relationship with the original data in the database; it should also be pointed out that it is necessary to select the vector database in advance. When converting the feature information into a data vector, it is necessary to ensure that the data vector conforms to the format of the selected vector database and can indeed be saved in the selected vector database.

[0154] The constructed vector database can quickly perform approximate nearest neighbor searches in large data sets. This capability gives the vector database a significant speed advantage in processing complex queries and performing recognition. In the process of applying structured sentence generation, the rate of structured sentence generation can be accurately improved.

[0155] The present application also provides an application scenario, which applies the above-mentioned natural language processing method. Specifically, Figure 8 As shown, the system includes a system, a large language model (LLM) and a database. The application of the natural language processing method in the application scenario is as follows:

[0156] The user enters natural language information on the query page of the system. For example, the natural language information may be "show the names and prices of all products", "show the products with the highest sales volume", and so on.

[0157] Then, the natural language information is converted into corresponding query information through the embedding model, and then the similarity between the query vector corresponding to the query information and each data vector in the vector database is calculated. For example, the embedding model (such as the CosENT model) can be used to calculate the similarity between the query vector and the data vectors corresponding to each table structure in the vector database, identify the table structure information that the user may want to query, and extract information related to the table structure information as context.

[0158] Specifically, the table structure similarities between the query vector and each table structure data in the vector database may be calculated, and all the table structure similarities may be retrieved.

[0159] Then, all the table structure similarities are sorted, and the table structure corresponding to the highest table structure similarity is determined as the target table structure. At the same time, the data vector corresponding to the target table structure is used as the target vector, and the information corresponding to the target table structure is determined as the context background data of the target vector.

[0160] After determining the contextual background data corresponding to the target vector, the query vector and the contextual background data are input into the guide word template, and then the guide word template outputs the target semantics corresponding to the natural language information. Then the language processing model inputs the corresponding initial structured sentence based on the guiding role of the target semantics.

[0161] It can be understood that the guide word template includes prompt words and / or prompt sentences. The use of prompt words and / or prompt sentences can help the model understand the context and direction of the question to obtain more accurate and useful answers, that is, structured sentences.

[0162] The initial structured statement is then input into the system, and the system executes it based on the data in the database. If the system successfully executes the initial structured statement, the initial structured statement for displaying the product name and price can be output as the target structured statement, and the target structured statement can be displayed to the user.

[0163] If the execution result indicates that the initial structured statement failed to execute, the system may have executed the information about a product in the initial structured statement incorrectly during the execution of the initial structured statement. At this time, while outputting the execution failure, the corresponding error identifier will also be output. The error identifier corresponds to one or more product information where the execution error occurred.

[0164] Then the initial structured sentence with execution error and the error mark are transmitted to the language processing model, and the language processing model is modified based on the error mark, the context background data corresponding to the target vector, and the initial structured sentence. The language processing model is modified based on the error mark and the context background data corresponding to the target vector on the basis of the initial structured sentence. Then the initial structured sentence modified by the language processing model is output as a transition structured sentence, and the transition structured sentence is continued to be executed.

[0165] If the transition structured statement is executed successfully, the transition structured statement is determined as the target structured statement. If the transition structured statement fails to execute, the modified transition structured statement is continued until the modified transition structured statement is executed successfully, and the successfully executed structured statement is determined as the target structured statement.

[0166] Compared with related technologies, firstly, through natural language input and generation of accurate structured sentences, users do not need to learn cumbersome structured sentence grammar and structure, and can query the database in a more intuitive and natural way. In addition, the system can identify and correct incorrect names or terms in user input, and improve the accuracy of generated structured sentences, which can improve the query efficiency and experience of non-professional users and lower the usage threshold. Users no longer need to write structured sentences manually, but can input query requirements through natural language, and then the large language model will automatically generate structured sentences, which greatly reduces the user burden and improves the efficiency of data query. Contextual background data helps the large model better understand the user's intentions. By passing the contextual background to the large model, the generated structured sentences can more accurately meet the user's query needs. Finally, the generated structured sentences can be self-corrected. By feeding back the structured execution results, the large language model can iteratively correct according to the results and improve the generated initial structured sentences, thereby further improving the accuracy and quality of the generated structured sentences to ensure consistency with user expectations.

[0167] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0168] The following is an embodiment of the device of the present application, which can be used to execute the natural language processing method involved in the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the method embodiment of the natural language processing method involved in the present application.

[0169] See also Fig. 9 In an embodiment of the present application, a natural language processing device is provided, and the device further includes:

[0170] A query vector acquisition module, which acquires input natural language information and is used to acquire a corresponding query vector based on the natural language information;

[0171] The target vector acquisition module calculates the similarity between the query vector and each data vector in the constructed vector database. If the similarity meets the set conditions, it is used to obtain the data vector in the vector database whose similarity meets the set conditions as the target vector; wherein the data vector in the vector database includes vectors obtained by converting various data through the embedding model;

[0172] The target structured statement determination module obtains the context background data of the target vector in the vector database, generates a corresponding initial structured statement based on the context background data and the query vector, performs corresponding processing based on the initial structured statement, and obtains an execution result; if the initial structured statement is executed successfully, it is used to determine that the initial structured statement is the target structured statement.

[0173] In an exemplary embodiment, the apparatus includes, but is not limited to:

[0174] A calculation module, used to calculate the table structure similarity between the query vector and each table structure data in the vector database; wherein there are multiple table structure similarities;

[0175] A target table structure determination module is used to determine a target table structure that meets the conditions based on the obtained similarities of the table structures;

[0176] The context background data determination module uses the information corresponding to the target table structure to determine the context background data of the target vector.

[0177] In an exemplary embodiment, context data of a target vector in a vector database is obtained, and a corresponding initial structured statement is generated based on the context data and the query vector. The apparatus includes but is not limited to:

[0178] The target semantics acquisition module uses the trained language processing model to perform semantic understanding processing on the query vector based on the contextual background data to obtain the target semantics corresponding to the natural language information;

[0179] The initial structured generation module is used to generate initial structured sentences corresponding to natural language information based on target semantics.

[0180] In an exemplary embodiment, the language processing model includes a guide word template, which includes at least one guide word for assisting in understanding the semantics of natural language information; the query vector is semantically understood based on contextual background data through the trained language processing model to obtain target semantics corresponding to the natural language information, and the device includes but is not limited to:

[0181] Through the trained language processing model, based on the contextual background data and guide word template, the query vector is semantically understood and processed to obtain the target semantics corresponding to the natural language information.

[0182] In an exemplary embodiment, the apparatus includes, but is not limited to:

[0183] The execution module modifies the initial structured statement if the execution result indicates that the initial structured statement fails to execute, and continues to execute the modified structured statement until the modified structured statement is successfully executed, and determines the successfully executed structured statement as the target structured statement.

[0184] In an exemplary embodiment, the initial structured statement is modified, and the modified structured statement is continuously executed until the modified structured statement is successfully executed, and the successfully executed structured statement is determined as the target structured statement, and the apparatus includes but is not limited to:

[0185] A transition structured statement generation module inputs the initial structured statement into the language processing model, generates a transition structured statement through the language processing model, and continues to execute the transition structured statement;

[0186] If the transition structured sentence is executed successfully, the transition structured sentence is determined as the target structured sentence; wherein the transition structured sentence is a structured sentence generated again by the language processing model based on the target vector.

[0187] In an exemplary embodiment, the initial structured sentence is input into a language processing model, and a transitional structured sentence is generated by the language processing model, and the apparatus includes but is not limited to:

[0188] An error identification acquisition module is used to acquire an error identification in the initial structured statement after the initial structured statement fails to execute, wherein the error identification is information about an error that occurs during the execution of the initial structured statement;

[0189] The transition structured sentence determination module modifies the initial structured sentence based on the initial structured sentence and the error identification, and uses the language processing model to determine the transition structured sentence.

[0190] In an exemplary embodiment, the apparatus includes, but is not limited to:

[0191] A corpus data acquisition module is used to acquire various types of corpus data; the corpus data includes at least one of table structure data, scenario data, and business knowledge data;

[0192] The extraction module is used to extract local features and contextual features of the corpus data through the trained embedding model;

[0193] A data vector generation module, which is used to generate data vectors corresponding to the corpus data based on local features and context features of the corpus data;

[0194] The vector database generation module is used to generate a vector database based on the generated data vectors of various types.

[0195] It should be noted that the natural language processing device provided in the above embodiment only uses the division of the above-mentioned functional modules as an example when performing natural language processing. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the natural language processing device will be divided into different functional modules to complete all or part of the functions described above.

[0196] In addition, the natural language processing device and the natural language processing method provided in the above embodiments belong to the same concept, and the specific manner in which each module performs operations has been described in detail in the method embodiments and will not be repeated here.

[0197] See also Fig.10 In an embodiment of the present application, an electronic device 4000 is provided, and the electronic device 400 may include: a desktop computer, a laptop computer, a server, etc.

[0198] exist Fig.10 In the embodiment, the electronic device 4000 includes at least one processor 4001 and at least one memory 4003.

[0199] The data interaction between the processor 4001 and the memory 4003 can be realized through at least one communication bus 4002. The communication bus 4002 may include a path for transmitting data between the processor 4001 and the memory 4003. The communication bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus 4002 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.10 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0200] Optionally, the electronic device 4000 may further include a transceiver 4004, which may be used for data interaction between the electronic device and other electronic devices, such as data transmission and / or data reception. It should be noted that in actual applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present application.

[0201] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. Processor 4001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0202] The memory 4003 can be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program instructions or codes in the form of instructions or data structures and can be accessed by the electronic device 400, but is not limited to this.

[0203] Computer-readable instructions are stored in the memory 4003 , and the processor 4001 can read the computer-readable instructions stored in the memory 4003 through the communication bus 4002 .

[0204] The computer-readable instructions are executed by one or more processors 4001 to implement the natural language processing method in the above-mentioned embodiments.

[0205] In addition, an embodiment of the present application provides a storage medium on which computer-readable instructions are stored. The computer-readable instructions are executed by one or more processors to implement the natural language processing method as described above.

[0206] A computer program product is provided in an embodiment of the present application. The computer program product includes computer-readable instructions. The computer-readable instructions are stored in a storage medium. One or more processors of an electronic device read the computer-readable instructions from the storage medium, load and execute the computer-readable instructions, so that the electronic device implements the natural language processing method as described above.

[0207] The above description is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A natural language processing method, characterized in that: The method comprises: Obtain input natural language information, and obtain a corresponding query vector based on the natural language information; Calculate the similarity between the query vector and each data vector in the constructed vector database, and if the similarity satisfies a set condition, obtain the data vector in the vector database whose similarity satisfies the set condition as the target vector; wherein the data vector in the vector database includes vectors obtained by converting various data through the embedding model; Obtain contextual background data of the target vector in a vector database, generate a corresponding initial structured statement based on the contextual background data and the query vector, perform corresponding processing based on the initial structured statement, and obtain an execution result; if the initial structured statement is executed successfully, determine that the initial structured statement is the target structured statement.

2. The method according to claim 1, characterized in that The process of obtaining the context background data of the target vector in the vector database includes: Calculating the table structure similarity between the query vector and each table structure data in the vector database; wherein there are multiple table structure similarities; Based on the obtained similarities of the table structures, determine the target table structure that meets the conditions; The information corresponding to the target table structure is determined as context background data of the target vector.

3. The method according to claim 1, characterized in that The acquiring context background data of the target vector in the vector database, and generating a corresponding initial structured statement based on the context background data and the query vector, includes: Using a trained language processing model, the query vector is semantically understood based on the contextual background data to obtain target semantics corresponding to the natural language information; Based on the target semantics, an initial structured sentence corresponding to the natural language information is generated.

4. The method according to claim 3, characterized in that The language processing model includes a guide word template, wherein the guide word template includes at least one guide word for assisting in understanding the semantics of natural language information; The step of performing semantic understanding processing on the query vector based on the contextual background data by using the trained language processing model to obtain target semantics corresponding to the natural language information includes: The query vector is semantically understood by the trained language processing model based on the context background data and the guide word template to obtain the target semantics corresponding to the natural language information.

5. The method according to claim 1, characterized in that The method further comprises: If the execution result indicates that the initial structured statement fails to execute, the initial structured statement is modified, and the modified structured statement is continued to be executed until the modified structured statement is successfully executed, and the successfully executed structured statement is determined as the target structured statement.

6. The method according to claim 5, characterized in that The step of modifying the initial structured statement and continuing to execute the modified structured statement until the modified structured statement is successfully executed, and determining the successfully executed structured statement as a target structured statement, includes: Inputting the initial structured sentence into a language processing model, generating a transitional structured sentence through the language processing model, and continuing to execute the transitional structured sentence; If the transition structured sentence is executed successfully, the transition structured sentence is determined as the target structured sentence; wherein the transition structured sentence is a structured sentence regenerated by the language processing model based on the target vector.

7. The method according to claim 6, characterized in that The method further comprises: After the execution of the initial structured statement fails, an error mark in the initial structured statement is obtained; wherein the error mark is information about an error that occurs during the execution of the initial structured statement; Based on the initial structured sentence and the error identifier, the language processing model is iteratively trained to obtain an updated language processing model; the updated language processing model is used to modify subsequent initial structured sentences and determine transitional structured sentences.

8. The method according to any one of claims 1 to 7, characterized in that The method further comprises: Acquire multiple types of corpus data; the corpus data includes at least one of table structure data, scenario data, and business knowledge data; Extracting local features and context features of the corpus data through the trained embedding model; Based on the local features and context features of the corpus data, generating a data vector corresponding to the corpus data; Based on the generated data vectors of various types, a vector database is generated.

9. A natural language processing device, characterized in that: The device also includes: A query vector acquisition module, which acquires input natural language information and is used to acquire a corresponding query vector based on the natural language information; A target vector acquisition module calculates the similarity between the query vector and each data vector in the constructed vector database, and if the similarity satisfies a set condition, is used to obtain a data vector in the vector database whose similarity satisfies the set condition as a target vector; wherein the data vector in the vector database includes vectors obtained by converting various data through an embedding model; The target structured statement determination module obtains the context background data of the target vector in the vector database, generates a corresponding initial structured statement based on the context background data and the query vector, performs corresponding processing based on the initial structured statement, and obtains an execution result; if the initial structured statement is executed successfully, it is used to determine that the initial structured statement is the target structured statement.

10. An electronic device comprising at least one processor and at least one memory, wherein a computer program is stored in the memory, wherein: The memory stores a computer program, wherein the processor implements the steps of the method according to any one of claims 1 to 8 when executing the computer program.

11. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.

12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Database natural language query method and device, electronic equipment and storage medium

    CN114328823A

  • Data query method and device, computer equipment and storage medium

    CN116842036A

  • Natural language querying of data in a structured context

    US20190079978A1

Cited By

  • Structured query language generation method and device based on large model, equipment and medium

    CN120104637A