Query statement generation method, device and equipment
By extracting the problem information input by the user and determining the subtype of the problem type, adjusting the entity weights and generating query statements, the problem that the existing technology is difficult to flexibly adapt to the diverse needs of users, and efficient and flexible query statement generation is achieved.
Patent Information
- Application Number
- CN202411958532.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-04-25
AI Technical Summary
The existing technology is difficult to flexibly adapt to the diverse needs of users, and it is impossible to quickly generate structured and dynamic query statements consistent with the semantics of user problems.
By obtaining the input problem information, performing feature extraction to obtain the problem vector, determining the problem category as the analysis class, identifying the entity set and adjusting the entity weight according to the subtype of the analysis class problem, generating the target entity set and query statement.
It realizes automatic generation of query statements consistent with the semantics of the problem, which has strong versatility and flexibility, and can accurately identify the specific intentions of analytical problems and prioritize the entities of core concern.
Smart Images

Figure CN119884284A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology and provides a query statement generating method, a query statement generating device and an electronic device. Background Art
[0002] With the rapid development of big data and artificial intelligence, being able to quickly analyze user questions and generate structured and dynamic query statements has become an important requirement for enterprises and institutions to improve efficiency and optimize decision-making. However, existing methods usually rely on manual input or preset fixed templates, which is difficult to flexibly adapt to the diverse needs of users. Summary of the invention
[0003] The purpose of the present application is to provide a query statement generation method, a query statement generation device, an electronic device and a computer-readable storage medium, which can automatically generate a query statement consistent with the question semantics by accurately expressing the user's actual problem, and have strong versatility and flexibility.
[0004] The present application proposes a query statement generation method, which includes: obtaining input question information, and performing feature extraction on the question information to obtain a question vector; if the question category of the question information is determined to be an analysis type according to the question vector, then determining the subtype of the analysis type question according to the question vector; identifying an entity set in the question information, and adjusting the weight of each entity in the entity set according to the subtype of the analysis type question to obtain a target weight of each entity; sorting each entity in the entity set according to the target weight of each entity to obtain a target entity set, and generating a query statement corresponding to the question information according to the target entity set, the question information and the subtype of the analysis type question.
[0005] Furthermore, the analysis of the operational behavior data, if it is determined according to the problem vector that the problem classification of the problem information is an analysis class, then the subtype of the analysis class problem is determined according to the problem vector, including: performing a first-level coarse-grained classification on the problem vector to obtain the probability distribution of each problem category, and determining the problem category of the problem information according to the probability distribution of each problem category; if the problem category of the problem information is an analysis class, then performing a second fine-grained classification on the problem vector to obtain the subtype of the analysis class problem.
[0006] Furthermore, the weight of each entity in the entity set is adjusted according to the subtype of the analysis type question to obtain the target weight of each entity, including: performing word segmentation processing on the question information to obtain a word sequence, and performing feature extraction on the word sequence to obtain a context-related representation for describing each word in the question information; calculating an attention score between each entity in the entity set and the context-related representation; obtaining the initial weight of each entity in the entity set, and adjusting the initial weight of each entity according to the subtype of the analysis type question and the attention score to obtain the target weight of each entity.
[0007] Furthermore, the initial weight is adjusted according to the subtype of the analysis question and the attention score to obtain the target weight of each entity, including: determining a static weight adjustment factor for each entity according to the subtype of the analysis question; adjusting the initial weight according to the static weight adjustment factor to obtain the preliminary importance of each entity; obtaining the importance adjustment coefficient of each entity in the context of the question information, and adjusting the attention score according to the importance adjustment coefficient to obtain the context-related importance of each entity; generating the target weight of each entity according to the preliminary importance of each entity and the context-related importance of each entity.
[0008] Furthermore, obtaining the importance adjustment coefficient of each entity in the question context includes: analyzing the context of the question information to evaluate the relevance of each entity in the question information; determining the importance adjustment coefficient based on the relevance, wherein the relevance is positively correlated with the importance adjustment coefficient.
[0009] Furthermore, the target weight of each entity is generated according to the preliminary importance of each entity and the context-related importance of each entity, including: generating a basic weight of each entity according to the preliminary importance of each entity and the context-related importance of each entity; obtaining the sum weight of the basic weights of all entities, and normalizing the basic weights of each entity according to the sum weight to obtain the target weight of each entity.
[0010] Furthermore, the generating of a query statement corresponding to the question information according to the target entity set, the question information and the subtype of the analysis type question includes: generating a comprehensive vector according to the target entity set, the question information and the subtype of the analysis type question; mapping the entities in the question information to corresponding fields of a database; inputting the comprehensive vector and the corresponding fields of the database into a pre-trained query generation model to obtain the query statement, wherein the query generation model is used to generate the query statement with reference to different types of query templates constructed according to different subtypes.
[0011] Furthermore, after generating a query statement corresponding to the question information according to the target entity set, the question information and the subtype of the analysis type question, the method also includes: retrieving structured data corresponding to the query statement from a database according to the query statement; generating prompt words according to the structured data, the target entity set, the question information and the subtype of the analysis type question; inputting the prompt words into a large language model to obtain analysis content of the query statement; generating a structured analysis report according to the analysis content, and displaying the structured analysis report.
[0012] The present application also proposes a query statement generating device, which includes: an acquisition module, used to acquire input question information, and perform feature extraction on the question information to obtain a question vector; a determination module, used to determine the subtype of the analysis type question according to the question vector if the question category of the question information is determined to be an analysis type according to the question vector; an adjustment module, used to identify an entity set in the question information, and adjust the weights of each entity in the entity set according to the subtype of the analysis type question to obtain a target weight of each entity; a generation module, used to sort each entity in the entity set according to the target weight of each entity to obtain a target entity set, and generate a query statement corresponding to the question information according to the target entity set, the question information and the subtype of the analysis type question.
[0013] The present application also proposes an electronic device, which includes: one or more processors; a storage device for storing one or more programs, which, when executed by the one or more processors, enables the electronic device to implement the method described above.
[0014] The present application also proposes a computer-readable storage medium on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer executes the method as described above.
[0015] An embodiment of the present application provides a computer program product, including a computer program, wherein the computer program is stored in a computer-readable storage medium, and a processor of an electronic device reads and executes the computer program from the computer-readable storage medium, so that the electronic device executes the method described above.
[0016] Compared with the prior art, this application has the following beneficial effects:
[0017] In the technical solution provided by the present application, input question information is obtained, and feature extraction is performed on the question information to obtain a question vector, which can capture the contextual semantic information of the question to better understand the deep meaning of the question; when the question category of the question information is determined to be an analysis type according to the question vector, the subtype of the analysis type question is determined according to the question vector, and the subtype is further extracted after coarse-grained classification, so as to accurately identify the specific intention of the analysis type question; by identifying the entity set in the question information, and adjusting the weight of each entity in the entity set according to the subtype of the analysis type question to obtain the target weight of each entity, so as to highlight the entities related to the analysis, and then sorting each entity in the entity set according to the target weight of each entity to obtain the target entity set, so as to focus on the entities of core concern and give priority to them, and then generate a query statement corresponding to the question information according to the target entity set, the question information and the subtype of the analysis type question, and by accurately expressing the user's actual problem, it is possible to automatically generate a query statement consistent with the question semantics, which has strong versatility and flexibility. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 A schematic diagram showing an implementation environment involved in the present application is shown;
[0019] Figure 2 A flowchart of a query statement generation method shown in an embodiment of the present application is shown;
[0020] Figure 3 Shows Figure 2 A flowchart of step S230 in the illustrated embodiment in an exemplary embodiment;
[0021] Figure 4 Shows Figure 3 A flowchart of step S233 in the illustrated embodiment in an exemplary embodiment;
[0022] Figure 5 Shows Figure 2 A flowchart of step S240 in the illustrated embodiment in an exemplary embodiment;
[0023] Figure 6 Shows Figure 2 A flow chart in an exemplary embodiment after step S240 in the illustrated embodiment;
[0024] Figure 7 A schematic diagram of the structure of an implementation system involved in the present application is shown;
[0025] Figure 8 A schematic diagram of a query statement generation method application process involved in the present application is shown;
[0026] Fig. 9 A schematic diagram of the structure of a query statement generating device shown in an exemplary embodiment of the present application is shown;
[0027] Fig.10 A schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present application is shown. DETAILED DESCRIPTION
[0028] Here, exemplary embodiments will be described in detail, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0029] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0030] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0031] It should also be noted that the "multiple" mentioned in this application refers to two or more than two. "And / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship.
[0032] See also Figure 1 , Figure 11 is a schematic diagram of an implementation environment involved in the present application. The implementation environment includes a client 10 and a server 20. The client 10 and the server 20 can be connected via a network 30. The network 30 can be a wired network or a wireless network, which is not limited here.
[0033] The client 10 is used to receive question information input by the user and send the question information to the server.
[0034] The server 20 is used to extract features from the question information to obtain a question vector; if the question category of the question information is determined to be an analysis type based on the question vector, then the subtype of the analysis type question is determined based on the question vector; an entity set in the question information is identified, and the weight of each entity in the entity set is adjusted based on the subtype of the analysis type question to obtain a target weight of each entity; each entity in the entity set is sorted based on the target weight of each entity to obtain a target entity set, and a query statement corresponding to the question information is generated based on the target entity set, the question information, and the subtype of the analysis type question.
[0035] In some embodiments, the query statement generation method can also be implemented by the client alone, that is, after the client receives the question information input by the user, it extracts features of the question information to obtain a question vector, and then determines the subtype of the analysis type of question, adjusts the weight of each entity in the entity set in the question information, and then generates a query statement corresponding to the question information based on the target entity set, the question information and the subtype of the analysis type of question.
[0036] Among them, the server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network) and big data and artificial intelligence platforms. This section does not impose any restrictions on this.
[0037] Clients include but are not limited to smartphones, tablets, laptops, computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft, etc.
[0038] The following is based on Figure 1 The implementation environment shown describes the query statement generation method in detail:
[0039] See also Figure 2 , Figure 2 is a flowchart of a query statement generation method shown in an exemplary embodiment of the present application. The query statement generation method is based on Figure 1Taking the server execution shown in FIG. 1 as an example, the query statement generation method includes steps S210 to S240, which are described in detail as follows:
[0040] S210: Obtain input question information, and perform feature extraction on the question information to obtain a question vector.
[0041] In an embodiment of the present application, a user inputs question information in a terminal based on his or her own needs. The question information may be text information, voice information, image information, etc. It is necessary to accurately identify the question intent of the question information input by the user.
[0042] The server needs to extract features from the question information to obtain a context-related question vector, which captures the semantic information of the entire question. Different forms of question information require different feature extraction methods. For example, for text-based question information, the question information can be input into a language model to obtain a question vector. Before inputting the question information into the language model, the question information can be cleaned, such as removing extra spaces, punctuation marks, HTML tags or other noise, and then standardized, such as converting the question text to lowercase or restoring the word form according to language characteristics (such as English stem extraction). Language models include BERT (Bidirectional Encoder Representation from Transformers) models, Word2Vec, etc. For voice-based question information, feature extraction can be performed using models such as ResNet-34. For image-based question information, feature extraction can be performed using models such as CNN (Convolutional Neural Networks).
[0043] In one example, question information in the form of voice or image can be first converted into text information, and then the question vector is obtained through the BERT model.
[0044] S220: If the question category of the question information is determined to be an analysis category according to the question vector, a subtype of the analysis category question is determined according to the question vector.
[0045] In an embodiment of the present application, the question vector may be input into a classifier, and the classifier may be used to determine the question category of the question information, such as knowledge category, analysis category, operation category, etc.
[0046] It should be noted that the processing method of this application is different for different question categories. If the question category is a chat question, the question information is directly passed to the large language model to enable the LLM (large language model) to interact with the user; if the question category is a knowledge question, an external knowledge base is provided to directly retrieve relevant knowledge based on the question information, and the retrieved relevant knowledge is passed to the LLM for data analysis.
[0047] If the problem category is analysis type, it is necessary to deeply analyze the structure of the analysis type problem and extract potential subtypes, such as trend analysis, root cause analysis, anomaly detection, etc. Therefore, in the embodiment of the present application, the problem vector is further classified in fine grains to determine the subtype of the analysis class.
[0048] In one example, step S220 includes: performing a first-level coarse-grained classification on the question vector to obtain the probability distribution of each question category, and determining the question category of the question information based on the probability distribution of each question category; if the question category of the question information is an analysis category, performing a second fine-grained classification on the question vector to obtain a subtype of the analysis category question.
[0049] In an embodiment of the present application, the question vector is coarse-grainedly classified to identify the category of the question, wherein the question vector can be input into a classifier, and the probability distribution of each question category is input, which represents the possibility of the question belonging to different categories, such as the output probability distribution: knowledge category: 0.2; analysis category: 0.7; operation category: 0.1.
[0050] Determine the coarse-grained category of the problem based on the probability distribution value, that is, which category the problem is more likely to belong to. The category with the highest probability can be directly selected as the problem category. If the probabilities are close, a threshold can be set or a multi-category decision strategy can be adopted (such as considering the Top-K category).
[0051] For example, according to the probability distribution, the question category is determined to be an analysis category, and for the "analysis category" questions, further fine-grained classification is performed to identify specific subtypes. In one example, the question vector can be input into a fine-grained classifier to obtain the probability distribution of each subtype, and the final subtype is determined according to the probability distribution of each subtype, wherein the fine-grained classifier is obtained by learning the relationship between the sample question vector and the sample subtype.
[0052] S230: Identify an entity set in the question information, and adjust the weight of each entity in the entity set according to the subtype of the analysis question to obtain a target weight of each entity.
[0053] In the embodiment of the present application, it is necessary to extract key information from the analysis-type question information, and then identify entities in the question information, such as time entities, location entities, indicator entities, etc., and then entity sets.
[0054] In the traditional entity recognition and information extraction module, all entities are considered to have equal weights. However, in actual business scenarios, different entities have different importance in different types of problems. For example, in the subtype of trend analysis, the time entity usually has a higher priority, while in root cause analysis, certain specific indicator entities (such as sales, revenue, etc.) are more important. Therefore, in the embodiment of the present application, the weight of the entity is dynamically adjusted according to the subtype of the analysis problem to obtain the target weight of each entity, and important entities can be dynamically highlighted according to the semantic focus of the problem or the user's intention (such as focusing on the cause entity in the causal relationship or the key indicator in the trend).
[0055] S240 , sorting the entities in the entity set according to the target weight of each entity to obtain a target entity set, and generating a query statement corresponding to the question information according to the target entity set, the question information, and the subtype of the analysis question.
[0056] After adjusting the weights of each entity in the entity set, each entity is sorted according to the target weight, where the weight is sorted from large to small, and then a target entity set is generated. By weight sorting, it is possible to more intuitively determine which entities are the core focus of question answering, so as to give priority to entities with high weights when computing resources are limited.
[0057] In an embodiment of the present application, the target entity set reflects the importance of different entities. Combined with the question information and the subtypes of analytical questions, it can accurately express the user's actual problem, avoid too broad or too narrow a query scope, and then generate a query statement corresponding to the question information.
[0058] In the technical solution provided by the present application, input question information is obtained, and feature extraction is performed on the question information to obtain a question vector, which can capture the contextual semantic information of the question to better understand the deep meaning of the question; when the question category of the question information is determined to be an analysis type according to the question vector, the subtype of the analysis type question is determined according to the question vector, and the subtype is further extracted after coarse-grained classification, so as to accurately identify the specific intention of the analysis type question; by identifying the entity set in the question information, and adjusting the weight of each entity in the entity set according to the subtype of the analysis type question to obtain the target weight of each entity, so as to highlight the entities related to the analysis, and then sorting each entity in the entity set according to the target weight of each entity to obtain the target entity set, so as to focus on the entities of core concern and give priority to them, and then generate a query statement corresponding to the question information according to the target entity set, the question information and the subtype of the analysis type question, and by accurately expressing the user's actual problem, it is possible to automatically generate a query statement consistent with the question semantics, which has strong versatility and flexibility.
[0059] In some embodiments, Figure 3 As shown, Figure 3 Shows Figure 2 In the illustrated embodiment, step S230 is a flowchart of adjusting the weight of the entity to obtain the target weight of each entity. The process of adjusting to obtain the target weight includes:
[0060] S231. Perform word segmentation on the question information to obtain a word sequence, and perform feature extraction on the word sequence to obtain a context-related representation for describing each word in the question information.
[0061] In an embodiment of the present application, word segmentation is performed on the question information to obtain a word sequence including multiple words. For languages without obvious separators such as Chinese, word segmentation can be performed based on a dictionary or statistical word segmentation technology.
[0062] Feature extraction is performed on each word in the word sequence to obtain a context-related embedding vector, which can capture the specific semantic meaning of the word in the question, and then the set of embedding vectors of each word in the question information is represented in a context-related manner.
[0063] In one example, a word sequence can be input into a BERT model to obtain a context-sensitive representation.
[0064] S232. Calculate the attention score between each entity in the entity set and the context-related representation.
[0065] In an embodiment of the present application, an attention score between each entity in the entity set and the context-related representation is calculated, and the attention score represents the relevance of the entity in the question context.
[0066] In one example, the similarity between an entity and a context-related representation is calculated, and an attention score is obtained by the similarity. For example, the dot product between an entity and a context-related representation is calculated, and Softmax is used for normalization to obtain an attention score (the sum of the scores is 1); for another example, the cosine similarity between a target entity and a context-related representation is calculated, the sum of the cosine similarities between other entities and the context-related representation is calculated, and the cosine similarity corresponding to the target entity is normalized according to the sum of the cosine similarities to obtain the attention score between the target entity and the context-related representation, where the target entity can be any entity.
[0067] S233. Obtain the initial weight of each entity in the entity set, and adjust the initial weight of each entity according to the subtype and attention score of the analysis question to obtain the target weight of each entity.
[0068] In one example, the initial weight of an entity may be determined based on the frequency of the entity appearing in question information. The higher the frequency of appearance, the higher the initial weight of the entity. The initial weight of an entity may also be set based on the general importance of the entity in a field.
[0069] In another example, entities in a text are identified by a pre-trained NER model, and all entities are considered to be equally weighted, that is, the same initial weight is given to the identified entities.
[0070] After obtaining the initial weight of the entity, the subtype and attention score are combined to increase the weight of the entity that is more in line with the semantic goal of the question, and weaken the weight of irrelevant or minor entities. For example, in trend analysis, the weight of the time entity will be significantly increased; in root cause analysis, the indicator entity has a higher weight than other entities. Assuming that the indicator entities include sales entity and revenue entity, and the attention score corresponding to the sales entity is higher than the attention score corresponding to the revenue, then the sales entity has a higher weight than the revenue entity.
[0071] In an embodiment of the present application, a context-related representation is obtained through feature extraction, and then the attention score between the entity and the context-related representation is calculated. The subtypes of the analysis questions are combined to have a more comprehensive understanding of the semantics of the question, and then the weight of the entity is dynamically adjusted to flexibly adapt to the problem scenario, so that the final generated query statement is more in line with user needs.
[0072] In one example, if Figure 4 As shown, Figure 4 Shows Figure 3 In the flowchart of step S233 in the illustrated embodiment, the process of obtaining the target weight includes:
[0073] S2331. Determine the static weight adjustment factor for each entity based on the subtype of the analysis question.
[0074] In an embodiment of the present application, a set of static weight adjustment factors are defined in advance according to different subtypes. These factors are based on experience or domain knowledge of the importance of different entities under these subtypes, and represent the preliminary importance of the entities under the subtypes. Each entity is mapped to the corresponding static weight adjustment factor according to the subtype of the analysis question as shown in Table 1 below.
[0075] Trend Analysis Root Cause Analysis Time Entity 0.7 0.2 Indicator Entity 0.1 0.6 Place Entity 0.2 0.2
[0076] Table 1
[0077] Based on Table 1, if the current subtype of the question information is trend analysis, and the question information includes a time entity and a location entity, the corresponding static weight adjustment factors are 0.7 and 0.2 respectively.
[0078] S2332. Adjust the initial weight according to the static weight adjustment factor to obtain the preliminary importance of each entity.
[0079] In an embodiment of the present application, the static weight adjustment factor and the initial weight may be dot-producted to obtain the preliminary importance of the entity under the current subtype, which reflects the initial weight adjustment of the entity under a specific task.
[0080] S2333. Obtain the importance adjustment coefficient of each entity in the context of the question information, and adjust the attention score according to the importance adjustment coefficient to obtain the context-related importance of each entity.
[0081] Get the importance adjustment coefficient of the entity in the context of question information, which reflects the relative importance of the entity in the current question context.
[0082] In one example, obtaining an importance adjustment coefficient of an entity in a question context includes: analyzing the context of question information to evaluate the relevance of each entity in the question information; and determining the importance adjustment coefficient based on the relevance, wherein the relevance is positively correlated with the importance adjustment coefficient.
[0083] For example, the attention mechanism is used to calculate the correlation between the entity and the question context to evaluate the relevance of each entity in the question information; for example, the question information is segmented to obtain a word sequence, and the word sequence is feature extracted to obtain a context-related representation for describing each word in the question information, and the context relevance score of the entity is calculated:
[0084] AttentionScore(e i )=Softmax(W a ·V Q +W b ·e i )
[0085] Among them, W a and W b is the weight matrix, V Q is the context-dependent representation, e i is the vector representation of the i-th entity.
[0086] The higher the relevance, the higher the importance adjustment coefficient; for example, a mapping relationship of importance adjustment coefficients corresponding to different relevances is pre-constructed, and the final importance adjustment coefficients of each entity in the context of the question information can be obtained through the mapping relationship.
[0087] The dot product of the importance adjustment coefficient and the attention score is used to obtain the context-related importance of the entity in the current question information context, which reflects the actual importance of the entity in the specific question.
[0088] S2334. Generate a target weight for each entity based on the preliminary importance of each entity and the context-related importance of each entity.
[0089] In one example, the preliminary importance and the context-related importance are added together to obtain the target weight of the entity, illustratively:
[0090] μ′ i =μ i α i (s)+β i ·ATT(e i ,V Q )
[0091] Among them, μ′ i For entity e i Target weight, μ i is the initial weight, α i (s) is the static weight adjustment factor; β i is the importance adjustment factor, ATT(e i ,V Q ) is entity e i With V Q The attention score, V Q It is a context-dependent representation.
[0092] In another example, the preliminary importance and the context-related importance are added to obtain the adjusted weight of the entity, the sum of the adjusted weights of all entities is calculated, and the adjusted weights of the entity are normalized by the sum of the adjusted weights of all entities to obtain the target weight of the entity, exemplarily:
[0093]
[0094] The numerator part represents the entity e i The denominator is the sum of the weights of all entities, which is used for normalization.
[0095] In the embodiment of the present application, generating the target weight of the entity includes:
[0096] Generate a basic weight for each entity according to the preliminary importance of each entity and the context-related importance of each entity; obtain the sum weight of the basic weights of all entities, and standardize the basic weight of each entity according to the sum weight to obtain the target weight of each entity.
[0097] Among them, the basic weight of the generated entity can be obtained by adding the preliminary importance and the context-related importance, or by adding the preliminary importance and the context-related importance to obtain the adjusted weight of the entity, calculating the sum of the adjusted weights of all entities, and normalizing the adjusted weight of the entity by the sum of the adjusted weights of all entities.
[0098] Similarly, the basic weight of each entity in the entity set is calculated, and then the sum of the basic weights of all entities is obtained. The weights of all entities need to be standardized to ensure the consistency of weight distribution, that is, the ratio of the basic weight of each entity to the sum of the basic weights of all entities is calculated to obtain the target weight of each entity; exemplary:
[0099]
[0100] in, For entity e i The target weight, μ″ i For entity e i The basic weight of i The calculation process is the same.
[0101] In the embodiment of the present application, by further combining the static weight adjustment factor and the importance adjustment system, the weight of each entity can be dynamically adjusted to ensure that the importance of each entity in the current problem is reasonably reflected.
[0102] like Figure 5 As shown, Figure 5 Shows Figure 2 In the flowchart of step S240 in the illustrated embodiment, the process of generating a query statement includes:
[0103] S241. Generate a comprehensive vector according to the target entity set, question information, and subtypes of the analysis questions.
[0104] In an embodiment of the present application, question information is segmented to obtain a word sequence, and feature extraction is performed on the word sequence to obtain a context-related representation, and the context-related representation, target entity set and subtype are concatenated to obtain a comprehensive vector.
[0105] S242. Map the entities in the question to the corresponding fields in the database.
[0106] For example, the "time entity" is mapped to the "date" field of the database, and the "place entity" is mapped to the "location" field of the database. The purpose of mapping is to accurately locate the corresponding data field in the database when generating SQL (Structured Query Language) query statements.
[0107] S243. Input the comprehensive vector and the corresponding field of the database into a pre-trained query generation model to obtain a query statement, wherein the query generation model is used to generate a query statement by referring to different types of query templates constructed according to different subtypes.
[0108] In an embodiment of the present application, different types of query templates, i.e., SQL templates, are pre-built. The SQL template is a set of pre-defined SQL statement frameworks for processing specific types of analysis tasks. Different subtypes have different SQL templates. For example, trend analysis may require aggregate queries, and root cause analysis may require multi-table joins and complex condition screening; these templates are usually trained and optimized to adapt to different data structures and query requirements.
[0109] The query generation model is a neural network architecture that is commonly used in natural language processing tasks such as machine translation and text generation. The query generation model is a Seq2Seq model. In the embodiment of the present application, the function of the query generation model is to generate corresponding SQL query statements based on the user's question information, subtypes and entity sets.
[0110] It should be noted that the SQL template provides basic structure and format guidance for the query generation model. When generating SQL queries, the query generation model will refer to these templates to ensure that the generated query statements conform to the expected syntax and logic.
[0111] Therefore, the database corresponding fields and the comprehensive vector are input into the query generation model, and the query generation model generates the restriction conditions of the statement according to the database corresponding fields, and generates the query statement corresponding to the SQL template corresponding to the subtype according to the comprehensive vector under the restriction conditions.
[0112] In other embodiments, the SQL query generated by the query generation model can continuously optimize and correct the SQL template, thereby improving the design and adaptability of the template.
[0113] In an embodiment of the present application, a comprehensive vector is generated based on the target entity set, question information, and subtypes of analysis questions. The mapping process is a key step in converting natural language into a machine-understandable database query language, so that the model can answer user questions more intelligently, and then generate query statements through the query generation model to generate more targeted query statements.
[0114] Among them, Figure 6 As shown, Figure 6 Shows Figure 2 The process of generating a structured analysis report after step S240 in the illustrated embodiment includes:
[0115] S250: Retrieve structured data corresponding to the query statement from a database according to the query statement.
[0116] In the embodiment of the present application, the SQL query statement corresponding to the generated question information is executed, and the target data corresponding to the SQL query statement is retrieved from the database, and the target data includes all data records that meet the query conditions, and then the target data is subjected to index calculation and data encapsulation to be converted into structured data (such as JSON, XML, etc.). For example, if the query statement is a statement for querying the sales trend of each month in the past year, the structured data is the total sales data of each month in the past year.
[0117] S260: Generate prompt words according to the structured data, the target entity set, the question information, and the subtype of the analysis question.
[0118] In an embodiment of the present application, the prompt words provide contextual information to the large language model so that it can understand the data and user intent, thereby generating more accurate analysis content, wherein the prompt words should be combined with structured data to embed the retrieved data into the prompt words in an easy-to-understand manner, and emphasize key entities related to the question, combined with question information to ensure that the prompt words fully convey the user's question, and combined with subtypes to clarify the purpose of the prompt words.
[0119] In one example, structured data, target entity set, question information, and subtypes may be used to generate prompt words.
[0120] In another example, generating prompt words includes: generating analysis goals based on the target entity set and the subtype of the analysis type problem; obtaining a contextual analysis description for describing the analysis background and analysis requirements; and splicing the analysis goals, contextual analysis description, structured data and problem information to generate prompt words.
[0121] Among them, the target entity set and the subtypes of analysis questions can be spliced together to generate analysis goals, which are used to clearly tell the big model the core task of generating content; the context analysis description is used to provide the big language model with analysis background and analysis requirements, such as the specific scenarios, business fields and related contexts of user questions, which helps the big model understand the background and meaning of the questions and generate more relevant content; the analysis requirements include model roles and guidance formats. The model role is to clarify the role played by the big model in the analysis process, for example, whether it is a data analyst, market researcher, or technical consultant, etc. This role will guide the model to generate answers that are consistent with the role identity and background; according to specific task requirements, provide format guidance for the model to generate answers, for example, whether it is necessary to generate a report, data visualization chart, or simple text description, etc.
[0122] S270: Input the prompt word into the large language model to obtain the analysis content of the query sentence.
[0123] S280. Generate a structured analysis report based on the analysis content, and display the structured analysis report.
[0124] In an embodiment of the present application, the prompt word is input into a large language model, and the large language model uses its natural language understanding and generation capabilities to obtain the analysis content of the query statement; the analysis content is organized into a document or data format with a fixed structure, such as a table, segmented text, or a chart, to obtain a structured analysis report; the structured analysis report includes the following elements: Problem description: a brief review of the original problem or query statement; Data analysis: the core conclusions and key points of the analysis content; Visualization: using charts (such as line charts, bar charts) to present data trends; Suggestions and predictions: providing specific suggestions or prediction results for subtypes, and then displaying a structured analysis report, presenting the analysis results in a clear and concise manner, which is convenient for users to understand and operate.
[0125] In the embodiment of the present application, structured data is retrieved from the database to ensure that the basic data for analysis is true and accurate, and prompt words are generated in combination with the target entity set and the analysis target, so that the analysis results of the model are more in line with user needs. A large language model is used to generate in-depth analysis content, quickly respond to complex queries, and generate structured analysis reports in various forms, providing efficient support for user decision-making.
[0126] For ease of understanding, this embodiment uses a more specific example to illustrate the query statement generation method. The query statement generation method is applicable to intelligent data analysis and report generation systems, especially in the following scenarios:
[0127] Enterprise data analysis: Automatically generate SQL queries based on internal enterprise data and business needs, and provide analysis reports such as trends, root causes, and anomalies.
[0128] BI system and report generation tools: support automated report generation for complex analytical tasks, and improve report efficiency through natural language input and SQL automatic generation.
[0129] Data-driven decision support: Support rapid decision-making and data-driven business adjustments through automated analysis processes.
[0130] like Figure 7As shown, it shows an architecture diagram of a system, including a data layer, a system function layer, a gateway layer and an interaction layer, wherein the query statement generation method of the present application mainly involves the system function layer, wherein the intent classification module under the intent recognition function in the system function layer: the goal of this module is to accurately identify the question intention input by the user and provide effective support for the subsequent analysis module. The core of this module lies in the multi-level intent classification algorithm, which can distinguish different types of questions (such as analysis, knowledge, chat, etc.), and deeply analyze the structure of analysis questions, and extract potential analysis targets (such as trend analysis, root cause analysis, anomaly detection, etc.).
[0131] Based on this, this application adopts a hierarchical intent classification algorithm (HIC) and uses the BERT model to convert the natural language question Q into a context-related vector representation V q , and realizes problem classification and analysis target extraction through multi-layer neural network.
[0132] First, extract the text features of the user question Q to obtain the context-related vector representation
[0133] V q =BERT(Q)
[0134] Among them, V q It is a high-dimensional vector that captures the semantic information of the question.
[0135] Secondly, a classifier is designed based on the traditional softmax function. The preprocessed embedding vector is processed by a multi-layer neural network to output the probability distribution of each category. q The first level of coarse-grained classification is performed to determine the problem classification (such as analysis, knowledge, chat, etc.).
[0136] c=arg max Softmax(W1·V q +b1)
[0137] Where cvC={c1,c2...c n},c i Indicates a problem classification (such as analysis, knowledge, and chat), W1 is the weight of the classifier, and b1 is the bias of the classifier. For chat questions, the questions are directly passed to LLM for user interaction. For knowledge questions, an external knowledge base is provided to directly retrieve relevant knowledge and pass it to LLM for data analysis. For analysis questions, a second-level fine-grained classification is performed to determine the specific subtypes of analysis questions (such as trend analysis, root cause analysis, etc.).
[0138] s=arg max Softmax(W2·V q +b2)
[0139] Among them, s∈S={s1,s2...s n},s i represents a specific subtype, W2 is the weight of the classifier, and b2 is the bias of the classifier.
[0140] Information extraction module under the intent recognition function: This module is mainly used to accurately extract key information from analytical questions, such as time entities, spatial entities, etc.; process fuzzy information and synonym problems in the questions, and standardize them into structured data to facilitate subsequent SQL generation.
[0141] In traditional entity recognition and information extraction, entity extraction is usually based on a fixed model, and all entities are considered to have equal weights. However, in actual business scenarios, different entities have different importance in different types of problems. For example, in trend analysis, time entities usually have a higher priority, while in root cause analysis, some specific indicator entities (such as sales, revenue, etc.) may be more important. Therefore, this application introduces the aforementioned fine-grained classification to dynamically adjust the weight of the entity.
[0142] Assume that the entity set to be identified is E = {e1, e2..., e n}, where each e i Corresponds to an entity type (such as e1 time entity, e2 indicator entity, e3 location entity, e4 dimension entity).
[0143] First, the fuzzy information and synonym problems in question Q are processed, and then the processed question Q is split into word sequences {ω1,ω2...,ω k}, use the BERT model to convert the word sequence after segmentation into a context-dependent embedding vector V Q =BERT({ω1,ω2...,ω k}), where V Q It is a context-dependent representation of each word in the question, which is a vector matrix with a shape of [n, d], where n is the number of words in question Q and d is the word vector dimension output by BERT.
[0144] Next, we need to standardize the weights of all entities to ensure that the weights of each entity are more reasonable under the guidance of the analysis goal. i For entity e i The initial weights (which can be obtained through a pre-trained NER model or rule-based) define each entity e i The dynamic adjustment weight formula is:
[0145]
[0146] Among them, α i (s) is a static weight adjustment factor for the entity based on the fine-grained classification s, which indicates the initial importance of the entity under the current analysis goal. The factor is dynamically adjusted according to the type of problem (such as trend analysis, root cause analysis, anomaly detection, etc.).
[0147] β i It is entity e i The importance adjustment coefficient in the question context, which reflects the relative importance of the entity in the current question context.
[0148] ATT(e i ,V Q ) is entity e i With V Q The attention score of , which indicates the relevance of the entity in the context of the question. This value is calculated by the following formula:
[0149]
[0150] Among them, V ei It is entity e i The vector representation of sim(V ei ,V Q ) is V ei and V Q The similarity of is calculated using cosine similarity
[0151] After the entity weights are updated, the weights of all entities need to be standardized to ensure the consistency of weight distribution and ultimately determine the priority of the entity in subsequent modules. The standardized weights are calculated using the following formula:
[0152]
[0153] Finally, all entities are classified according to their final weights Sort and generate the final standardized entity set E, arranged from high to low in importance.
[0154] Data retrieval module in the system functional layer: This module builds the data query statement sql=SQL(E,s) that best suits question Q based on the fine-grained classification s and the extracted standardized entity set E. Specifically:
[0155] Entity mapping: Map the entities in the question to the corresponding fields in the database to ensure that the query can accurately find the data related to the question.
[0156] Template construction: Build and train specific types of SQL templates. For example, for trend analysis, you need to build aggregate queries; for root cause analysis, you need to join multiple tables and perform complex condition screening; for anomaly detection, you need to calculate data deviations, etc.
[0157] SQL generation: concatenate question Q, fine-grained s, and entity set E into a comprehensive vector (V Q ,V s ,V E ) Input the trained Seq2Seq model and generate SQL. The SQL template provides the basic structure and format guidance for the Seq2Seq model. When generating SQL queries, the Seq2Seq model will refer to these templates and the corresponding database fields of the entity mapping to ensure that the generated query statements conform to the expected syntax and logic and accurately locate the corresponding data fields in the database. Then execute the generated SQL query statement and retrieve the structured data corresponding to the SQL query statement from the database. data (such as json), which can be searched by province, date, profession, etc.
[0158] Prompt word construction: combined with data D data , question Q, fine-grained s and entity set E, generate prompt words prompt=[C content ,Q,T analysis ,D data ]. Among them, C content It is a context description, which is used to define the model role, describe the character background, and provide a guidance format; the user question Q is used as a direct input to help the model associate context and semantics; the analysis goal T analysis Derived from the fine-grained classification s and the entity set E, it is used to clearly tell the core task of the large model to generate content; D data Provides key data required for large model analysis.
[0159] Analysis and visualization: The constructed prompt is passed to the big model to generate analysis content, including in-depth interpretation of trends, root causes, anomalies, etc., generate a structured analysis report and present it visually.
[0160] like Figure 8 As shown in the figure, the user asks questions on the front-end service provided by the terminal. The front-end service can provide atomic page display, query index recommendation and query question recommendation for inputting question information. After that, the back-end can classify the question information input by the user. If it is a knowledge-related question, the big model scheduling module directly retrieves the relevant knowledge through the question retrieval knowledge base, and transmits the retrieved relevant knowledge to the big model solution generation module. If it is a non-analysis or non-knowledge-related question, the question is directly transmitted to the big model solution generation module.
[0161] If it is an analysis question, the entity set is extracted through the information extraction module, and the entity weights are adjusted. Then, SQL is generated through the Seq2Seq model provided by the text2sql module, and the query parameters of the SQL statement are interpreted. Data is retrieved from the database provided by the data storage module, and the retrieved original search data is processed to obtain structured data. Then, the structured data and the question, fine-grained and entity set are combined to generate prompt words, which are input into the large language model to generate an analysis report, and then the analysis report is flexibly componentized to generate answers to the questions and returned to the user.
[0162] By introducing a multi-level attention mechanism and an adaptive weighting algorithm, the weight of the entity is adjusted more finely. This method can dynamically adjust the weight of the entity according to different analysis objectives and problem contexts, ensuring that the most relevant entities are given priority in the subsequent SQL generation, analysis target extraction, etc., thereby improving the overall analysis quality and system accuracy. This innovative method of dynamically adjusting entity priorities provides stronger intelligence and adaptability for entity recognition and information extraction; through fine-grained classification, the task type (trend analysis, root cause analysis, etc.) is identified, and a suitable SQL template is selected and a query is generated. Avoid the limitations of simple template matching and improve the accuracy and flexibility of generated SQL; extract key entities from natural language questions, map them to database fields, and fill in SQL queries; automatically generate SQL queries dynamically according to user needs to reduce manual intervention.
[0163] In addition, the whole process is automated: by integrating the functions of data collection, preprocessing, analysis and report generation, an end-to-end intelligent analysis system is established to reduce manual labor. Dynamically adapt to user needs: natural language processing and intent recognition technology are used to accurately understand user questions, and the content and format of the report are dynamically adjusted to meet the needs of different scenarios. Enhance data credibility and transparency: design a data traceability module to record the data source and analysis logic of each report, and provide users with explainable analysis results. Lower the user operation threshold: through Text2SQL and natural language interaction, users can obtain analysis results without mastering complex programming or database query skills. Improve the real-time performance of report generation: use reinforcement learning to optimize the generation algorithm, achieve rapid response based on the large language model, and provide efficient support for decision-making.
[0164] Through the method of this application, enterprises and users can complete data analysis and decision support in a low-cost and high-efficiency manner, which can be widely used in communications, finance, medical and other industries.
[0165] The following describes an apparatus embodiment of the present application, which can be used to execute the query statement generation method in the above embodiment of the present application. For details not disclosed in the apparatus embodiment of the present application, please refer to the above embodiment of the query statement generation method of the present application.
[0166] like Fig. 9 As shown, Fig. 9 : is a structural diagram of a query statement generating device shown in an exemplary embodiment of the present application. The device is deployed on a server or a terminal, and the device includes:
[0167] The acquisition module 910 is used to acquire input question information and perform feature extraction on the question information to obtain a question vector;
[0168] A determination module 920, configured to determine a subtype of the analysis type question according to the question vector if the question type of the question information is determined to be an analysis type according to the question vector;
[0169] An adjustment module 930 is used to identify an entity set in the question information, and adjust the weight of each entity in the entity set according to the subtype of the analysis question to obtain a target weight of each entity;
[0170] The generation module 940 is used to sort the entities in the entity set according to the target weights of the entities to obtain a target entity set, and to generate a query statement corresponding to the question information according to the target entity set, the question information and the subtype of the analysis question.
[0171] In some embodiments of the present application, based on the aforementioned scheme, the determination module is further used to perform a first-level coarse-grained classification on the problem vector to obtain the probability distribution of each problem category, and determine the problem category of the problem information based on the probability distribution of each problem category; if the problem category of the problem information is an analysis category, the problem vector is subjected to a second fine-grained classification to obtain a subtype of the analysis category problem.
[0172] In some embodiments of the present application, based on the aforementioned scheme, the adjustment module is further used to perform word segmentation on the question information to obtain a word sequence, and perform feature extraction on the word sequence to obtain a context-related representation for describing each word in the question information; calculate the attention score between each entity in the entity set and the context-related representation; obtain the initial weight of each entity in the entity set, and adjust the initial weight of each entity according to the subtype of the analysis type question and the attention score to obtain the target weight of each entity.
[0173] In some embodiments of the present application, based on the aforementioned scheme, the adjustment module further determines a static weight adjustment factor for each entity according to the subtype of the analysis type question; adjusts the initial weight according to the static weight adjustment factor to obtain the preliminary importance of each entity; obtains the importance adjustment coefficient of each entity in the context of the question information, and adjusts the attention score according to the importance adjustment coefficient to obtain the context-related importance of each entity; generates the target weight of each entity according to the preliminary importance of each entity and the context-related importance of each entity.
[0174] In some embodiments of the present application, based on the aforementioned scheme, the adjustment module is further used to analyze the context of the question information to evaluate the relevance of each entity in the question information; determine the importance adjustment coefficient based on the relevance, wherein the relevance is positively correlated with the importance adjustment coefficient.
[0175] In some embodiments of the present application, based on the aforementioned scheme, the adjustment module is further used to generate a basic weight for each entity according to the preliminary importance of each entity and the context-related importance of each entity; obtain the sum weight of the basic weights of all entities, and standardize the basic weights of each entity according to the sum weight to obtain the target weight of each entity.
[0176] In some embodiments of the present application, based on the aforementioned scheme, the generation module is further used to generate a comprehensive vector according to the target entity set, the question information and the subtypes of the analysis type questions; map the entities in the question information to corresponding fields of the database; input the comprehensive vector and the corresponding fields of the database into the pre-trained query generation model to obtain the query statement, wherein the query generation model is used to generate the query statement with reference to different types of query templates constructed according to different subtypes.
[0177] In some embodiments of the present application, based on the aforementioned scheme, the generation module is also used to retrieve structured data corresponding to the query statement from the database according to the query statement; generate prompt words according to the structured data, the target entity set, the question information and the subtype of the analysis type question; input the prompt words into the large language model to obtain the analysis content of the query statement; generate a structured analysis report according to the analysis content, and display the structured analysis report.
[0178] It should be noted that the device provided in the above embodiment and the method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment and will not be repeated here.
[0179] In an exemplary embodiment, an electronic device includes one or more processors; a storage device for storing one or more programs, which, when executed by the one or more processors, enable the electronic device to implement the method described above. It is understood that the electronic device can be deployed in a server.
[0180] Fig.10 The diagram is a schematic structural diagram of an electronic device according to an exemplary embodiment.
[0181] It should be noted that the electronic device is only an example adapted to the present application and cannot be considered to provide any limitation on the scope of use of the present application. The electronic device cannot be interpreted as requiring dependence on or having Fig.10 One or more components of an exemplary electronic device shown in FIG.
[0182] like Fig.10 As shown, in an exemplary embodiment, the electronic device includes a processing component 1001, a memory 1002, a power component 1003, a multimedia component 1004, an audio component 1005, a processor 1006, a sensor component 1007 and a communication component 1008. Among them, the above components are not all necessary, and the electronic device can add other components or reduce certain components according to its own functional requirements, which is not limited in this embodiment.
[0183] The processing component 1001 generally controls the overall operation of the electronic device, such as operations associated with display, data communication, and log data synchronization. The processing component 1001 may include one or more processors 1006 to execute instructions to complete all or part of the steps of the above operations. In addition, the processing component 1001 may include one or more modules to facilitate the interaction between the processing component 1001 and other components. For example, the processing component 1001 may include a multimedia module to facilitate the interaction between the multimedia component 1004 and the processing component 1001.
[0184] The memory 1002 is configured to store various types of data to support operations on the electronic device, examples of which include instructions for any application or method used to operate on the electronic device. The memory 1002 stores one or more modules, which are configured to be executed by the one or more processors 1006 to complete all or part of the steps in the method described in the above embodiment.
[0185] The power supply component 1003 provides power to various components of the electronic device. The power supply component 1003 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device.
[0186] The multimedia component 1004 includes a screen that provides an output interface between the electronic device and the user. In some embodiments, the screen may include a TP (Touch Panel) and an LCD (Liquid Crystal Display). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
[0187] The audio component 1005 is configured to output and / or input audio signals. For example, the audio component 1005 includes a microphone, and when the electronic device is in an operation mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. In some embodiments, the audio component 1005 also includes a speaker for outputting audio signals.
[0188] The sensor component 1007 includes one or more sensors for providing status evaluation of various aspects for the electronic device. For example, the sensor component 1007 can detect the on / off status of the electronic device and can also detect the temperature change of the electronic device.
[0189] The communication component 1008 is configured to facilitate wired or wireless communication between the electronic device and other devices. The electronic device can access a wireless network based on a communication standard, such as Wi-Fi (Wireless-Fidelity).
[0190] Understandably, Fig.10 The structure shown is for illustration only, and the electronic device may include Fig.10 More or fewer components as shown, or with Fig.10 The different components are shown. Fig.10 Each component shown in the figure can be implemented by hardware, software or a combination thereof.
[0191] In an exemplary embodiment, a computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described above is implemented. The computer-readable storage medium may be included in the electronic device described in the above embodiment, or may exist independently without being assembled into the electronic device.
[0192] It should be noted that the computer-readable storage medium shown in the embodiment of the present application can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0193] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the embodiments disclosed herein. The present application is intended to cover any variations, uses or adaptations of the present application, which follow the general principles of the present application and include common knowledge or customary technical means in the art that are not disclosed in the present application.
[0194] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. A person skilled in the art can easily make corresponding changes or modifications based on the main concept and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.
Claims
1. A query statement generation method, characterized in that: include: Obtain input question information, and perform feature extraction on the question information to obtain a question vector; If it is determined according to the question vector that the question category of the question information is an analysis category, then determining a subtype of the analysis category question according to the question vector; Identify an entity set in the question information, and adjust the weight of each entity in the entity set according to the subtype of the analysis question to obtain a target weight of each entity; The entities in the entity set are sorted according to the target weights of the entities to obtain a target entity set, and a query statement corresponding to the question information is generated according to the target entity set, the question information and the subtype of the analysis question.
2. The method according to claim 1, characterized in that If it is determined according to the question vector that the question information is classified as an analysis type, then determining a subtype of the analysis type question according to the question vector includes: Performing a first-layer coarse-grained classification on the question vector to obtain a probability distribution of each question category, and determining the question category of the question information according to the probability distribution of each question category; If the question category of the question information is analysis type, a second fine-grained classification is performed on the question vector to obtain a subtype of the analysis type question.
3. The method according to claim 1, characterized in that The step of adjusting the weight of each entity in the entity set according to the subtype of the analysis problem to obtain the target weight of each entity includes: Performing word segmentation processing on the question information to obtain a word sequence, and performing feature extraction on the word sequence to obtain a context-related representation for describing each word in the question information; Calculating an attention score between each entity in the entity set and the context-related representation; The initial weight of each entity in the entity set is obtained, and the initial weight of each entity is adjusted according to the subtype of the analysis question and the attention score to obtain the target weight of each entity.
4. The method according to claim 3, characterized in that The initial weight is adjusted according to the subtype of the analysis question and the attention score to obtain the target weight of each entity, including: Determining a static weight adjustment factor for each entity according to the subtype of the analytical problem; Adjusting the initial weight according to the static weight adjustment factor to obtain the preliminary importance of each entity; Obtaining an importance adjustment coefficient of each entity in the context of the question information, and adjusting the attention score according to the importance adjustment coefficient to obtain the context-related importance of each entity; A target weight for each entity is generated according to the preliminary importance of each entity and the context-related importance of each entity.
5. The method according to claim 4, characterized in that The obtaining of the importance adjustment coefficient of each entity in the context of the question includes: Analyzing the context of the question information to evaluate the relevance of each entity in the question information; The importance adjustment coefficient is determined according to the correlation, wherein the correlation is positively correlated with the importance adjustment coefficient.
6. The method according to claim 4, characterized in that Generating the target weight of each entity according to the preliminary importance of each entity and the context-related importance of each entity includes: generating a basic weight of each entity according to the preliminary importance of each entity and the context-related importance of each entity; The sum weight of the basic weights of all entities is obtained, and the basic weights of the respective entities are normalized according to the sum weight to obtain the target weights of the respective entities.
7. The method according to claim 1, characterized in that The step of generating a query statement corresponding to the question information according to the target entity set, the question information and the subtype of the analysis question includes: Generate a comprehensive vector according to the target entity set, the question information and the subtype of the analysis question; Mapping entities in the question information to corresponding fields in the database; The comprehensive vector and the corresponding field of the database are input into a pre-trained query generation model to obtain the query statement, wherein the query generation model is used to generate the query statement with reference to different types of query templates constructed according to different subtypes.
8. The method according to any one of claims 1 to 7, characterized in that: After generating a query statement corresponding to the question information according to the target entity set, the question information and the subtype of the analysis question, the method further includes: Retrieving structured data corresponding to the query statement from a database according to the query statement; Generate prompt words according to the structured data, the target entity set, the question information and the subtype of the analysis question; Inputting the prompt word into a large language model to obtain the analysis content of the query sentence; A structured analysis report is generated according to the analysis content, and the structured analysis report is displayed.
9. A query statement generating device, characterized in that: include: An acquisition module is used to acquire input question information and perform feature extraction on the question information to obtain a question vector; A determination module, configured to determine a subtype of the analysis type question according to the question vector if the question type of the question information is determined to be an analysis type according to the question vector; An adjustment module, used for identifying an entity set in the question information, and adjusting the weight of each entity in the entity set according to the subtype of the analysis question to obtain a target weight of each entity; A generation module is used to sort the entities in the entity set according to the target weights of the entities to obtain a target entity set, and to generate a query statement corresponding to the question information according to the target entity set, the question information and the subtype of the analysis question.
10. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, enables the electronic device to execute the method according to any one of claims 1 to 8.
Citation Information
Cited By
Method for realizing semantic chain retrieval enhanced generation processing aiming at knowledge questions and answers of long document
CN121029966A