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

CN118606352BActive Publication Date: 2026-10-30SHENZHEN LUMIUNITED TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

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

Smart Images

  • Figure CN118606352B_ABST
    Figure CN118606352B_ABST
Patent Text Reader

Abstract

The application 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: obtaining input natural language information, obtaining a corresponding query vector based on the natural language information; calculating the similarity of the query vector and each data vector in the constructed vector database, and if the similarity meets a set condition, obtaining the data vector in the vector database that meets the set condition as a target vector; obtaining the context background data of the target vector in the vector database, generating a corresponding initial structured sentence based on the context background data and the query vector, executing corresponding processing based on the initial structured sentence, and obtaining an execution result; and if the initial structured sentence is successfully executed, determining that the initial structured sentence is a target structured sentence. The application solves the problem of low accuracy of generated structured sentences in related technologies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and more specifically, to a natural language processing method, apparatus, electronic device, storage medium, and computer program product. Background Technology

[0002] With the rapid development of computer technology, structured languages ​​have been widely applied in various fields. Structured languages, derived from natural language processing, enable various data processing operations such as querying, inserting, updating, and deleting data. SQL (Structured Query Language) is a common type of structured query language, which also includes structured programming languages ​​(such as C and Java) and structured text markup languages ​​(such as HTML and XML). These structured languages ​​all have specific grammatical rules and structures to effectively organize and process data or information.

[0003] Traditional structured language generation methods typically require users to have a certain level of knowledge of structured languages ​​and an understanding of database structures, which poses a certain barrier for non-professional users. In practical applications, natural language generation of structured language technology still faces some problems and challenges, such as: lack of background knowledge, inability to fully understand the user's intent, resulting in the generated structured language not meeting the user's expectations; and inability to self-correct the generated structured language, which may lead to low accuracy of the generated structured statements.

[0004] As can be seen from the above, how to improve the accuracy of generated structured statements still needs to be addressed. Summary of the Invention

[0005] This application provides a natural language processing method, apparatus, 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 solutions are as follows:

[0006] According to one aspect of this application, a natural language processing method includes:

[0007] Obtain the input natural language information, and obtain the 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. If the similarity meets a set condition, then obtain the data vector in the vector database that meets the set condition as the target vector. The data vectors in the vector database include vectors obtained by transforming various data through an embedding model.

[0009] Obtain the contextual background data of the target vector in the 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 the execution result;

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

[0011] According to one aspect of this application, a natural language processing apparatus further includes:

[0012] The query vector acquisition module acquires the input natural language information and uses the natural language information to acquire the corresponding query vector.

[0013] 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 a set condition, it is used to acquire the data vector in the vector database that meets the set condition as the target vector. The data vectors in the vector database include vectors obtained by transforming various data through an embedding model.

[0014] The target structured statement determination module obtains the contextual background data of the target vector in the vector database, generates a corresponding initial structured statement based on the contextual background data and the query vector, performs corresponding processing based on the initial structured statement, and obtains the 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 one exemplary embodiment, the apparatus includes, but is not limited to:

[0016] The calculation module is 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] The target table structure determination module, based on the obtained similarity of each table structure, is used to determine the target table structure that meets the conditions.

[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 one exemplary embodiment, the apparatus for obtaining the contextual background data of the target vector in a vector database and generating a corresponding initial structured statement based on the contextual background data and the query vector includes, but is not limited to:

[0020] The target semantic acquisition module uses a trained language processing model to perform semantic understanding processing on the query vector based on the contextual background data, in order to obtain the target semantics corresponding to the natural language information.

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

[0022] In one 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 apparatus for performing semantic understanding processing on the query vector based on the contextual background data using the trained language processing model to obtain the target semantics corresponding to the natural language information includes, but is not limited to:

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

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

[0025] If the execution result indicates that the initial structured statement has failed to execute, the execution module modifies the initial structured statement and continues to execute the modified structured statement until the modified structured statement is executed successfully, and the successfully executed structured statement is identified as the target structured statement.

[0026] In one exemplary embodiment, the method 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 the target structured statement, includes, but is not limited to:

[0027] The transitional structured statement generation module inputs the initial structured statement into the language processing model, uses the language processing model to generate transitional structured statements, and continues to execute the transitional structured statements;

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

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

[0030] The error identifier acquisition module is used to acquire the error identifier in the initial structured statement after the initial structured statement fails to execute. The error identifier is information about an error that occurred during the execution of the initial structured statement.

[0031] The transitional structured statement determination module modifies the initial structured statement based on the initial structured statement and the error identifier, and uses this modification to determine the transitional structured statement.

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

[0033] The 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.

[0034] The extraction module, through a trained embedding model, is used to extract local and contextual features from the corpus data;

[0035] The data vector generation module is used to generate data vectors corresponding to the corpus data based on the local features and contextual features of the corpus data.

[0036] The vector database generation module generates a vector database based on the generated data vectors of various types.

[0037] According to one aspect of this application, an electronic device includes a memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the steps of the natural language processing methods of various embodiments of this application.

[0038] According to one aspect of this application, a storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in the natural language processing methods of various embodiments of this application.

[0039] According to one aspect of this application, a computer program product includes a computer program that, when executed by a processor, implements the steps in the natural language processing methods of various embodiments of this application.

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

[0041] In the above technical solution, by acquiring input natural language information, a corresponding query vector is obtained based on the natural language information. Then, the similarity between the query vector and each data vector in the constructed vector database is calculated. If the similarity meets a set condition, the data vector in the vector database that meets the set condition is obtained as the target vector. The data vectors in the vector database include vectors obtained by transforming various data through an embedding model. The contextual background data of the target vector in the vector database is obtained. Based on the contextual background data and the query vector, a corresponding initial structured statement is generated. Based on the initial structured statement, corresponding processing is performed to obtain the execution result. If the initial structured statement is executed successfully, the initial structured statement is finally determined as the target structured statement. Compared with existing methods of generating structured statements, this method... The method first converts natural language information into query vectors. Then, it calculates the similarity between the query vectors and a pre-built vector database. If the similarity meets certain conditions, the first step is achieved, which determines the accurate target vector. The target vector can then be used to retrieve corresponding contextual data from the vector database. Based on the contextual data and the query vector, an initial structured statement is generated and executed. If the initial structured statement executes successfully, it is determined to be the target structured statement. Iterative improvements can be made based on the results to further enhance the accuracy of the generated structured statement. This effectively solves the problem of low accuracy in generated structured statements in related technologies. Attached Figure Description

[0042] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0043] Figure 1 This is a schematic diagram of the implementation environment involved in a natural language processing method.

[0044] Figure 2 This is a flowchart illustrating a natural language processing method according to an exemplary embodiment;

[0045] Figure 3 This is a flowchart illustrating steps S201 to S203 of a natural language processing method according to an exemplary embodiment;

[0046] Figure 4 This is a flowchart illustrating steps S221 to S223 of a natural language processing method according to an exemplary embodiment;

[0047] Figure 5 This is a flowchart illustrating steps S224 to S225 of a natural language processing method according to an exemplary embodiment;

[0048] Figure 6 This is a flowchart illustrating steps S2241 to S2242 of a natural language processing method according to an exemplary embodiment;

[0049] Figure 7 This is a flowchart illustrating the construction of a vector database in natural language processing methods S231 to S234 according to an exemplary embodiment;

[0050] Figure 8 This is a schematic diagram illustrating the execution of an initial structured statement in a natural language processing method according to an exemplary embodiment;

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

[0052] Figure 10 This is a structural block diagram of an electronic device according to an exemplary embodiment. Detailed Implementation

[0053] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application.

[0054] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this disclosure means the presence of the stated 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 say an element is “connected” or “coupled” to another element, it may be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein may include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any units and all combinations of one or more associated listed items.

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

[0056] Large Language Model: Typically, a natural language processing model with a large number of parameters and computational 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 statement is successfully executed, the initial structured statement is finally determined as the target structured statement. It has wide applications in natural language processing, text generation, and intelligent dialogue.

[0057] Embedding Models: Embedding models refer to the process of mapping high-dimensional data (such as text, images, and audio) to a low-dimensional space. Word embeddings are techniques that map words or phrases to real-valued vectors, such as Word2Vec and GloVe. These embedding models can capture the semantic relationships between words, enabling machines to better understand natural language and thus be applied to natural language processing tasks.

[0058] Figure 1 This is a schematic diagram of an implementation environment for a natural language processing method. The implementation environment includes at least a user terminal 110, a smart device 130, a server 170, and network equipment. Figure 1 In this context, network devices include gateway 150 and router 190, but this is not intended to be a specific limitation.

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

[0060] The client, associated with the smart device 130, is essentially where the user registers an account and configures the smart device 130. For example, the configuration includes adding a device identifier to the smart device 130, so that when the client runs on 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. Correspondingly, the interface for displaying the device on the client can be in the form of a program window or a web page, and there is no limitation here.

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

[0062] The interaction between user terminal 110 and smart device 130 can be achieved through a local area network (LAN) or a wide area network (WAN). In one application scenario, user terminal 110 establishes a wired or wireless communication connection with gateway 150 via router 190, such as Wi-Fi, allowing user terminal 110 and gateway 150 to be deployed on the same LAN, thus enabling user terminal 110 to interact with smart device 130 via the LAN path. In another application scenario, user terminal 110 establishes a wired or wireless communication connection with gateway 150 via server 170, such as 2G, 3G, 4G, 5G, or Wi-Fi, allowing user terminal 110 and gateway 150 to be deployed on the same WAN, thus enabling user terminal 110 to interact with smart device 130 via the WAN path.

[0063] The server-side 170 can also be considered as the cloud, cloud platform, platform side, server side, etc. This server-side 170 can be a single server, a server cluster consisting of multiple servers, or a cloud computing center consisting of multiple servers, in order to better provide backend services to a massive number of user terminals 110. For example, backend services include device control services.

[0064] In one application scenario, user terminal 110 obtains the corresponding query vector based on query information. Then, by calculating the similarity between the query vector and the vectors in the pre-built vector database, if the similarity meets the set conditions, the data vector in the vector database that meets the set similarity conditions can be obtained as the target vector. At the same time, the contextual background data corresponding to the target vector in the vector database can be obtained, and the corresponding initial structured statement can be generated based on the contextual background data and the query vector. After the corresponding initial structured statement is generated, if the initial structured statement is executed successfully, it can be determined that the initial structured statement is the target structured statement, thereby providing users with more effective device control services.

[0065] As mentioned earlier, the accuracy of the generated structured statements still exists in the relevant technologies.

[0066] Therefore, the natural language processing method provided in this application can effectively improve the accuracy of natural language processing. Accordingly, this 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 may specifically be... Figure 1 Gateways, servers, and user terminals in the system.

[0067] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0068] In one embodiment, such as Figure 2 As shown, a natural language processing method is provided. Taking the application of this method to an electronic device as an example, the electronic device can specifically be... Figure 1 The method may include the following steps: (The text then lists various network components, such as gateways, servers, and user terminals.)

[0069] S200: Obtain the input natural language information and obtain the corresponding query vector based on the natural language information.

[0070] Natural language information typically refers to the query terms used by users on the query interface. These query terms are then converted into query vectors, which can be achieved through an embedding model.

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

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

[0073] Additionally, for embedding models, options include Word2Vec, GloVe, BERT, RoBERTa, and GPT. For word embedding models like Word2Vec and GloVe, the embedding vector can be obtained directly by using the index of the query word in the natural language information within the model. However, for sentence embedding models like BERT and RoBERTa, the natural language information needs to be input as a complete sentence or paragraph into the model, and then the output vector is obtained. This vector typically represents the semantics of the entire sentence or paragraph. Different embedding models can be selected to obtain the corresponding query vector for different types of natural language information.

[0074] S210, calculate the similarity between the query vector and each data vector in the constructed vector database. If the similarity meets the set conditions, then obtain the data vector in the vector database that meets the set conditions as the target vector.

[0075] Vector databases, in particular, refer to databases used to store and query vectors. The vectors they store are derived from the vectorization of data such as text, speech, images, and video. Compared to traditional databases, vector databases can handle more unstructured data. Vector databases can provide vector similarity searches through indexes, enabling fast querying and matching of large-scale and multi-dimensional vector data.

[0076] It is understandable that vector databases can be pre-constructed using various types of corpus data. Specifically, the data vectors in a vector database can include vectors obtained by transforming various data through embedding models.

[0077] After obtaining the query vector corresponding to the natural language information, the electronic device 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 a data vector exists that meets the set similarity criteria, then the data vector in the vector database that meets the set similarity criteria will be used as the target vector corresponding to the query vector.

[0079] S220: Obtain the contextual background data of the target vector in the vector database; generate the corresponding initial structured statement based on the contextual background data and the query vector; perform corresponding processing based on the initial structured statement to obtain the execution result; if the initial structured statement is executed successfully, then the initial structured statement is determined to be the target structured statement.

[0080] It is important to note that contextual background data refers to the additional information or data associated with the target vector in the vector database. This data provides detailed information about the environment or context in which the target vector exists. For example, suppose we have a vector database for storing product information. The target vector represents a specific product. The contextual background data may include the product description, price, manufacturer, user reviews, etc. Furthermore, the contextual background data can facilitate understanding the meaning of the target vector and generating accurate initial structured statements.

[0081] An initial structured statement is a statement with a clear syntax and structure generated based on a query vector and contextual background data. This statement describes the operation or query to be performed. Example: In the product example above, the initial structured statement might be "Query for 'specific products' manufactured by 'XYZ Company' with a price less than 100 yuan". Furthermore, the initial structured statement is an operation instruction that a computer program can understand and execute 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; for example, in the product example above, the execution result may be a list of products that meet the conditions, including their details (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 operations.

[0083] In the above approach, by introducing a vector database and contextual background data, and by passing the contextual background data to the language processing model, the generated structured statements can more accurately meet the user's query needs and help the language processing model better understand the user's intent. Furthermore, during the query process, users no longer need to manually write structured statements; instead, they input their query requirements in natural language, and the language processing model automatically generates structured statements. This significantly reduces the user's burden and improves the efficiency of data retrieval.

[0084] After the user inputs the corresponding natural language information, the system first identifies the natural language information input by the user, and identifies key information (such as location name, device type, etc.) so that the natural language information input by the user can be identified as soon as possible.

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

[0086] S201, Data cleaning of natural language information;

[0087] It should be noted that data cleaning includes two aspects: first, removing any irrelevant or redundant information, for example, deleting spaces, special characters, punctuation marks, etc.; second, performing standardization processing on the data to ensure uniform formats, for example, converting all texts to lowercase or uniformly using a certain encoding format.

[0088] In the cleaning process, special symbols and punctuation marks are first 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 usually have no practical significance for model training and may interfere with the performance of the model; then text word segmentation is performed. Word segmentation is the process of dividing text into individual words, which is a basic step of NLP tasks; then stop word filtering is performed. Stop words refer to words that appear frequently in the text but have no practical significance for text expression, such as "de", "shi", "zai", etc. These words usually contribute nothing to NLP tasks, so they need to be filtered out; then lemmatization is performed. Lemmatization is the process of restoring words in the text to their base form (or root form).

[0089] For example, restoring "running" to "run", restoring "better" to "good", etc., and lemmatization helps reduce the diversity of vocabulary and improve the performance of the model; then text standardization is performed to ensure the format uniformity and consistency of text data, which may include converting text to lowercase, removing numbers, removing HTML tags, removing URL links, etc. The standardization process helps reduce the complexity of data and improve the accuracy of subsequent NLP tasks; then blanks and redundant characters are removed. This step is to remove redundant spaces, tabs, line breaks and other blank characters in the text, as well as possible non-printable characters (such as control characters); finally, special characters and encoding issues are handled. 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 realized.

[0090] S202: Perform similarity calculation between the cleaned natural language information and the data in the database;

[0091] It should be noted that the data in the database includes table structure data, data samples and business knowledge. In the process of performing similarity calculation, 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 a 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 vector-based similarity calculation: if both natural language information and data in the database are represented as vectors, then the similarity between vectors can be used to calculate their similarity. Common vector similarity measures include cosine similarity, Euclidean distance, etc. If it is model-based similarity calculation: in some cases, pre-trained models (such as deep learning models) can be used to calculate the similarity between natural language information and database data. For example, text classification models or question answering models can be used to determine whether natural language information is similar to a certain entry in the database.

[0093] S203. If the calculated similarity meets the threshold, then the natural language information recognition is normal, indicating that relevant information can be found in the database and the corresponding query vector can be obtained; otherwise, the natural language information recognition is abnormal.

[0094] If the database does not contain information related to the natural language input by the user, a prompt message will be generated on the interface to remind the user to re-enter the query information. The user can then re-enter the information they need to query.

[0095] Through the execution steps S201 to S203, feedback can be provided to the user immediately when the user performs a data query. It can identify incorrect names or terms in the user's input natural language information to ensure the validity and correctness of the subsequently generated structured statements.

[0096] In one embodiment, during 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, calculate the table structure similarity between the query vector and each table structure data in the vector database; where there are multiple table structure similarities.

[0098] It should be noted that table structure data refers to the framework and rules that make up a 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, columns, data types, etc.

[0099] When obtaining table structure similarity, it is necessary to first extract table structure features, such as table name, columns, and data types. Then, the table structure features are converted into vectors. For text features such as table name and column name, pre-trained word embedding models (such as Word2Vec, GloVe, or FastText) can be used to convert them into vectors. For classification features such as data types and constraints, one-hot encoding, label encoding, or embedding layers can be used to encode them, combining vectors from different features into a single vector representation. This can be achieved through simple concatenation, weighted summation, or more complex neural network models. The method for calculating similarity has been mentioned above and will not be repeated here.

[0100] S222, Based on the obtained similarity of the table structures, determine the target table structure that meets the conditions.

[0101] The process of determining the target table structure includes: the electronic device retrieves all table structure similarities, sorts all table structure similarities, and filters out some table structure similarities before sorting.

[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. Table structure similarities greater than the threshold are placed in one set, defined as satisfying the set, while other table structure similarities are placed in another set, defined as not satisfying the set. During the sorting stage, it is only necessary to sort the table structure similarities that satisfy the set; the table structure with the highest table structure similarity is determined as the target table structure.

[0103] By following the steps described above to determine the target table structure, the table structure that best matches a given query can be found quickly, enabling subsequent data processing or operations. This improves the efficiency of data retrieval and processing, and allows the selection of the most accurate table structure as the target table structure, thereby enhancing the accuracy of subsequent structured statement generation.

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

[0105] It should be noted that contextual background data includes not only the data itself, that is, the information corresponding to the defined target table structure, but also various information and knowledge related to the data.

[0106] To determine the contextual background data, it is necessary to clarify the specific objectives of the analysis or application, such as prediction, classification, and correlation analysis, and the contextual background data should directly support the achievement of these objectives; then, it is necessary to understand which information is critical for making business decisions, and this information should be included as part of the contextual background data.

[0107] First, carefully examine 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 requirements, identify the key fields that are directly related to the target vector. These fields should contain information that has an important impact on the target vector. Next, extract the data of these key fields from the target table and organize the extracted data into a format suitable for use as background data for the target vector.

[0108] By executing steps S221 to S223 above, the contextual background data is determined based on the target table structure. This ensures that the acquired contextual background data in the database best matches the natural language information input by the user. The contextual background data helps the language processing model better understand the user's intent.

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

[0110] Using a trained language processing model, semantic understanding processing is performed on the query vector based on 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 is understandable that a trained language processing model has the ability to recognize the target semantics of natural language information. Specifically, a language processing model can be obtained by training on a large number of natural languages ​​of various types.

[0112] Among them, target semantics is to determine the user's true intent 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 can also include a guide word template, which includes at least one guide word to help understand the semantics of natural language information.

[0114] After obtaining the contextual background data of the target vector in the vector database, the electronic device can use a trained language processing model to perform semantic understanding processing on the query vector based on the contextual background data and the guide word template, thereby obtaining the target semantics corresponding to the natural language information; the accuracy of the target semantics can be further improved by using the guide word template.

[0115] Then, based on the target semantics, an initial structured statement corresponding to the natural language information is generated. Through the generated target semantics, the quality and accuracy of the initial structured statement generated from the natural language information 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, it can be determined that the initial structured statement is the target structured statement, and then the target structured statement is displayed to the user on the display page.

[0117] Through the above process, by inputting and generating accurate structured statements using natural language, users no longer need to learn cumbersome structured statement syntax and structure. They can query the database in a more intuitive and natural way, and the system can identify and correct incorrect names or terms in the user's input, improving the accuracy of the generated structured statements. This enhances the query efficiency and experience for non-professional users and lowers the barrier to entry. Users no longer need to manually write structured statements; instead, they input their query requirements in natural language, and the large language model automatically generates structured statements. This significantly reduces the user's burden and improves the efficiency of data querying. Contextual background data helps the large model better understand the user's intent. By passing the contextual background to the large model, the generated structured statements can more accurately meet the user's query needs.

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

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

[0120] In addition, the specific process of obtaining target semantics can be achieved by using a trained language processing model to encode the preprocessed query vector and contextual 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 patterns of the language, thereby capturing the semantic information in the query. By analyzing the encoded semantic vector, the language processing model can identify the user's query intent. Classification or clustering algorithms can be used to classify the query into different intent categories.

[0121] Based on the identified intent, the language processing model further analyzes the specific content of the query, extracts the specific information or knowledge sought by the user, and generates the target semantics corresponding to the natural language information based on the results of intent identification and semantic analysis. The target semantics is a precise description of the user's query intent and the information sought.

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

[0123] If the execution result indicates that the initial structured statement failed to execute, the initial structured statement is modified, and the modified structured statement continues to be executed until the modified structured statement is executed successfully. The successfully executed structured statement is then identified as the target structured statement.

[0124] Execution failure indicates that the execution result corresponding to the generated initial structured statement is not the same as the user's expected result, which means that the generated initial structured statement is not accurate enough.

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

[0126] In other embodiments, the system can automatically determine whether the initial structured statement was executed successfully. For example, it can determine whether the execution was successful by comparing the execution result with the initial structured statement. If the matching degree reaches a preset threshold, the execution is considered successful. Alternatively, the system can identify whether the execution result was successfully obtained; if so, the execution is considered successful. If an execution error is reported, the execution is considered failed. Furthermore, after obtaining the execution result, it can be fed back to the user; if the user reports an error in the execution result, the execution is considered failed.

[0127] If the execution result indicates that the initial structured statement failed, the electronic device further modifies the initial structured statement, for example, by adjusting and optimizing it based on the execution result and natural language information. The electronic device then continues to execute the modified structured statement until it is executed successfully, and identifies the successfully executed structured statement as the target structured statement.

[0128] In this embodiment, if the initial structured statement fails to execute, the execution result of the initial structured language is fed back to iteratively revise the initial structured statement, thereby improving the generated initial structured statement and further enhancing the accuracy of the generated structured statement.

[0129] In some embodiments, such as Figure 5As shown, the modification process for the initial structured statement based on runtime 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 transitional structured statement is generated by the language processing model after modifying the initial structured statement. Specifically, the language processing model modifies the initial structured statement based on the location of execution failure and the target vector.

[0132] S225. If the transitional structured statement is executed successfully, then the transitional structured statement will be identified as the target structured statement.

[0133] After modifying the initial structured statement, the language processing model outputs a transitional structured statement. This statement is a correction to the initial structured statement, designed to resolve execution failures. The transitional structured statement is submitted to the system for execution to verify whether the modification has successfully resolved 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 previous step, restart the error detection and analysis process, and 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. Based on the results, iterative correction is performed to improve the generated transitional structured statement. By feeding back the execution results of the initial structured language, the language processing model can iteratively correct and improve the generated initial structured statement. Through its own self-correction mechanism, the accuracy and quality of the generated structured statement can be further improved.

[0135] In one embodiment, an initial structured statement is input into a language processing model, which then generates a transitional structured statement, such as... Figure 6 As shown, the specific modification process includes:

[0136] S2241: After the initial structured statement fails to execute, retrieve the error flag from the initial structured statement.

[0137] Among them, the error identifier is information indicating that an error occurred during the execution of the initial structured statement.

[0138] S2242, based on the initial structured statement and error flags, the language processing model modifies the initial structured statement and determines the transitional structured statement.

[0139] After the language processing model receives the initial structured statement and error flags, it needs to retrieve the target vector again. The language processing model determines the error location in the initial structured statement based on the error flags, and modifies the initial structured statement based on the determined error location and the target vector, thereby obtaining a more accurate transitional structured statement.

[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 failure is located. This location may be a syntax error, a logical error, missing data, or other types of error. Then, the error location is analyzed in detail to understand why the error occurred. This requires examining the contextual 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 contextual background data (if applicable) are input into the trained language processing model. Based on this information, the language processing model understands and analyzes the initial structured statement. According to the error location and contextual information of the initial structured statement, the language processing model attempts to modify the statement. Modifications may include correcting syntax errors, adjusting the logical structure, supplementing missing data, or replacing inappropriate words. After modification, the language processing model outputs a transitional structured statement.

[0141] By modifying the initial structured statement through S2241 to S2242, it is possible to precisely modify the initial structured statement that fails to execute, so as to generate a more accurate target structured statement.

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

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

[0144] The corpus data includes at least one of the following: table structure data, scenario data, and business knowledge data. 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. The business knowledge includes business rules, entity relationships, etc.

[0145] When acquiring various types of corpus data, the first step is to clarify business requirements and collect data from multiple sources, including table structure data (such as column names, data types, and constraints), scenario data, and business knowledge data (such as business rules and entity relationships). Next, the collected data is validated and integrated to ensure accuracy and consistency. During data processing, representative data samples are selected and stored using appropriate storage solutions. Finally, a data management system is established to ensure data security and availability, and the data is continuously updated and maintained as business evolves to ensure its timeliness and accuracy.

[0146] S232 extracts local and contextual features from the corpus data using a 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 context features of the words are captured by combining the words in the context window; thus, the local features and context features can be extracted.

[0148] S233, Based on the local features and contextual features of the corpus data, generate the data vector corresponding to the corpus data.

[0149] Taking table structure data as an example, information such as column names, data types, and constraints can be extracted as corresponding data vectors. Column names are important textual information describing data attributes. Data types (such as integers, floating-point numbers, strings, etc.) reflect the nature of the data and possible operations. Constraints, such as primary keys, foreign keys, and uniqueness constraints, provide information on data integrity and consistency.

[0150] Specifically, electronic devices can first preprocess the corpus data to ensure data quality and consistency. Then, a trained embedding model is used to extract local and contextual features from the corpus. Local features are typically obtained through word embedding, where each word is converted into a real-valued vector containing its semantic information. Contextual features are obtained by considering the contextual information of words in sentences or paragraphs, which can be achieved by inputting the word along with its surrounding words into the embedding model.

[0151] After extracting features, they are combined into a feature set. Next, based on the task requirements and data characteristics, an appropriate encoding strategy is selected to encode the feature set. For text sequence data, models such as Recurrent Neural Networks (RNNs), Long Short-Term Memory Networks (LSTMs), or Transformers can be used to encode sequence information to capture temporal dependencies and contextual relationships within 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 needs to be combined into a single data vector, feature aggregation is required. This can be achieved by averaging, summing, or max-pooling the embedding vectors of all sentences or paragraphs, resulting in a single, fixed-length data vector that represents the semantic information of the entire corpus data.

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

[0153] The data vectors maintain a correspondence with the original data in the database. It should also be noted that a vector database needs to be selected in advance. When converting feature information into data vectors, it is necessary to ensure that the data vectors conform to the format of the selected vector database and can indeed be stored in the selected vector database.

[0154] The constructed vector database enables rapid near-nearest neighbor search on massive datasets. This capability gives the vector database a significant speed advantage when processing complex queries and performing recognition. Furthermore, it can precisely improve the generation rate of structured statements during the application of structured statement generation.

[0155] This application also provides an application scenario in which the above-described natural language processing method is applied. Specifically, as... Figure 8 As shown, the system includes a Large Language Model (LLM) and a database. The application of this natural language processing method in this scenario is as follows:

[0156] Users enter natural language information on the system's query page. For example, this natural language information could be "Show the names and prices of all products" or "Show the products with the highest sales volume," etc.

[0157] Then, the natural language information is converted into corresponding query information through an embedding model, and the similarity between the query vector corresponding to the query information and each data vector in the vector database is calculated. For example, an 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 similarity between the query vector and each table structure data in the vector database can be calculated, and all table structure similarities can be retrieved.

[0159] Then, all table structure similarities are sorted, and the table structure with the highest 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 contextual background data of the target vector.

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

[0161] It is understandable that the prompt word template includes prompt words and / or prompt sentences. Using prompt words and / or prompt sentences can help the model understand the context and direction of the question in order to obtain more accurate and useful answers, that is, structured statements.

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

[0163] If the execution result indicates that the initial structured statement failed to execute, it means that during the execution of the initial structured statement, there may have been an error in the execution of information about a certain product in the initial structured statement. In this case, while outputting the execution failure, the system will also output a corresponding error flag, which corresponds to one or more product information that have an execution error.

[0164] The initial structured statement that resulted in the error, along with the error flag, is then transmitted to the language processing model. The language processing model modifies the initial structured statement based on the error flag, the contextual data corresponding to the target vector, and the initial structured statement. The modified initial structured statement is then output as a transitional structured statement, and execution of the transitional structured statement continues.

[0165] If the transitional structured statement is executed successfully, it will be designated as the target structured statement. If the transitional structured statement fails to execute, the modified transitional structured statement will continue to be executed until it is executed successfully, and the successfully executed structured statement will be designated as the target structured statement.

[0166] Compared to related technologies, firstly, by inputting and generating accurate structured statements through natural language, users do not need to learn cumbersome structured statement syntax and structure. They can query the database in a more intuitive and natural way, and the system can identify and correct incorrect names or terms in the user's input, improving the accuracy of the generated structured statements. This improves the query efficiency and experience for non-professional users and lowers the barrier to entry. Secondly, users no longer need to manually write structured statements. Instead, they input their query requirements through natural language, and the large language model automatically generates structured statements. This greatly reduces the user's burden and improves the efficiency of data querying. Contextual background data helps the large model better understand the user's intent. By passing the contextual background to the large model, the generated structured statements can more accurately meet the user's query needs. Finally, the generated structured statements can be self-correcting. By providing feedback on the structured execution results, the large language model can iteratively correct the generated structured statements, further improving the accuracy and quality of the generated structured statements and ensuring consistency with user expectations.

[0167] It should be understood that although the steps in the flowcharts of the accompanying figures are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the accompanying figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.

[0168] The following are embodiments of the apparatus described in this application, which can be used to execute the natural language processing method involved in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the method embodiments of the natural language processing method involved in this application.

[0169] Please see Figure 9 This application provides a natural language processing device, which further includes:

[0170] The query vector acquisition module acquires the input natural language information and uses this information to obtain the corresponding query vector.

[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 acquire the data vectors in the vector database that meet the set conditions as the target vector. The data vectors in the vector database include vectors obtained by transforming various data through an embedding model.

[0172] The target structured statement determination module obtains the contextual background data of the target vector in the vector database, generates the corresponding initial structured statement based on the contextual background data and the query vector, performs corresponding processing based on the initial structured statement, and obtains the 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 one exemplary embodiment, the apparatus includes, but is not limited to:

[0174] The calculation module is used to calculate the table structure similarity between the query vector and the table structure data in the vector database; there are multiple table structure similarities.

[0175] The target table structure determination module, based on the obtained similarity of each table structure, is used to determine the target table structure that meets the conditions.

[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 one exemplary embodiment, the contextual background data of the target vector in a vector database is obtained, and an initial structured statement is generated based on the contextual background data and the query vector. The apparatus includes, but is not limited to:

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

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

[0180] In one 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 trained language processing model performs semantic understanding processing on the query vector based on contextual background data to obtain the target semantics corresponding to the natural language information, and the apparatus includes, but is not limited to:

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

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

[0183] If the execution result indicates that the initial structured statement failed to execute, the execution module modifies the initial structured statement and continues to execute the modified structured statement until the modified structured statement is executed successfully. The successfully executed structured statement is then identified as the target structured statement.

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

[0185] The transitional structured statement generation module takes the initial structured statement as input to the language processing model, uses the language processing model to generate transitional structured statements, and then continues to execute the transitional structured statements.

[0186] If the transitional structured statement is executed successfully, it will be identified as the target structured statement; the transitional structured statement is a structured statement regenerated by the language processing model based on the target vector.

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

[0188] The error flag acquisition module is used to acquire the error flags in the initial structured statement after the initial structured statement fails to execute. The error flags are information about errors that occurred during the execution of the initial structured statement.

[0189] The transitional structured statement determination module modifies the initial structured statement based on the initial structured statement and error flags, and uses this modification to determine the transitional structured statement.

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

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

[0192] The extraction module, through a trained embedding model, is used to extract local and contextual features from the corpus data.

[0193] The data vector generation module, based on the local and contextual features of the corpus data, is used to generate data vectors corresponding to the corpus data.

[0194] The vector database generation module generates 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 embodiments is only illustrated by the division of the above functional modules when performing natural language processing. In actual applications, the above 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] Furthermore, the natural language processing apparatus and the natural language processing method embodiments provided in the above embodiments belong to the same concept, and the specific way in which each module performs operations has been described in detail in the method embodiments, and will not be repeated here.

[0197] Please see Figure 10 This application provides an electronic device 4000, which may include: a desktop computer, a laptop computer, a server, etc.

[0198] exist Figure 10 In this context, 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 achieved through at least one communication bus 4002. This 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, Figure 10 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0200] Optionally, the electronic device 4000 may further include a transceiver 4004, which can be used for data interaction between the electronic device and other electronic devices, such as sending and / or receiving data. It should be noted that in practical applications, the transceiver 4004 is not limited to one type, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of this 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 can implement or execute the 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 computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.

[0202] The memory 4003 may be a ROM (Read Only Memory) or other type of static storage device capable of storing static information and instructions, RAM (Random Access Memory) or other type of dynamic storage device capable of storing information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program instructions or code in the form of instructions or data structures and accessible by the electronic device 400, but not limited thereto.

[0203] The memory 4003 stores computer-readable instructions, 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 methods in the above embodiments.

[0205] Furthermore, this application provides a storage medium storing computer-readable instructions that are executed by one or more processors to implement the natural language processing method described above.

[0206] This application provides a computer program product including computer-readable instructions 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, thereby enabling the electronic device to implement the natural language processing method as described above.

[0207] The above description is only a partial embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.

Claims

1. A natural language processing method, characterized in that, The method includes: Obtain the input natural language information, and obtain the 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. If the similarity meets a set condition, then obtain the data vector in the vector database that meets the set condition as the target vector. The data vectors in the vector database include vectors obtained by transforming various data through an embedding model. Obtain the contextual background data of the target vector in a vector database; wherein, the process of obtaining the contextual 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 table structure similarities, determining the target table structure that meets the conditions; and determining the information corresponding to the target table structure as the contextual background data of the target vector; Based on the contextual background data and the query vector, a corresponding initial structured statement is generated. Based on the initial structured statement, corresponding processing is performed to obtain the execution result. If the initial structured statement is executed successfully, then the initial structured statement is determined to be the target structured statement.

2. The method as described in claim 1, characterized in that, The step of obtaining the contextual background data of the target vector in the vector database, and generating a corresponding initial structured statement based on the contextual background data and the query vector, includes: Using a trained language processing model, semantic understanding processing is performed on the query vector 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 statement corresponding to the natural language information is generated.

3. The method as described in claim 2, characterized in that, The language processing model includes a guide word template, which includes at least one guide word to aid 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 using a trained language processing model to obtain the target semantics corresponding to the natural language information includes: Using a trained language processing model, based on the contextual background data and the guide word template, the query vector is semantically understood to obtain the target semantics corresponding to the natural language information.

4. The method as described in claim 1, characterized in that, The method further includes: If the execution result indicates that the initial structured statement failed to execute, the initial structured statement is modified, and the modified structured statement continues to be executed until the modified structured statement is executed successfully. The successfully executed structured statement is then identified as the target structured statement.

5. The method as described in claim 4, 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 executed successfully, and determining the successfully executed structured statement as the target structured statement, includes: The initial structured statement is input into the language processing model, which generates a transitional structured statement, and the transitional structured statement is then executed. If the transitional structured statement is executed successfully, then the transitional structured statement is determined as the target structured statement; wherein, the transitional structured statement is a structured statement regenerated by the language processing model based on the target vector.

6. The method as described in claim 5, characterized in that, The method further includes: After the initial structured statement fails to execute, the error flag in the initial structured statement is obtained; wherein, the error flag is information indicating that an error occurred during the execution of the initial structured statement; Based on the initial structured statement 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 statements and determine transitional structured statements.

7. The method according to any one of claims 1 to 6, characterized in that, The method further includes: Acquire multiple types of corpus data; the corpus data includes at least one of table structure data, scenario data, and business knowledge data. The local and contextual features of the corpus data are extracted using a trained embedding model. Based on the local and contextual features of the corpus data, a data vector corresponding to the corpus data is generated; A vector database is generated based on the various types of data vectors produced.

8. A natural language processing device, characterized in that, The device further includes: The query vector acquisition module acquires the input natural language information and uses the natural language information to acquire the corresponding query vector. 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 a set condition, it is used to acquire the data vector in the vector database that meets the set condition as the target vector. The data vectors in the vector database include vectors obtained by transforming various data through an embedding model. The target structured statement determination module acquires the contextual background data of the target vector in a vector database, generates a corresponding initial structured statement based on the contextual 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. The process of acquiring the contextual background data of the target vector in the vector database includes: calculating the table structure similarity between the query vector and the structure data of each table in the vector database; wherein there are multiple table structure similarities; determining the target table structure that meets the conditions based on the obtained table structure similarities; and determining the information corresponding to the target table structure as the contextual background data of the target vector.

9. An electronic device comprising at least one processor and at least one memory, wherein the memory stores a computer program, characterized in that, The memory stores a computer program, characterized in that the processor executes the computer program to implement the steps of the method according to any one of claims 1 to 7.

10. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 7.

11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.

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