Electric quantity data analysis code self-generation method based on natural interaction

By transforming natural language commands into word segments through natural interaction, performing semantic mapping and semantic role labeling, generating a logic tree and executable query code, the problem of low efficiency in traditional power data analysis is solved, and automated and efficient power data analysis is achieved.

CN121523656APending Publication Date: 2026-02-13CHINA SOUTHERN POWER GRID DIGITAL GRID GRP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511701289.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-19
Publication Date
2026-02-13

AI Technical Summary

Technical Problem

Traditional electricity data analysis requires manual processing and SQL code writing by professional technicians, resulting in low efficiency and high communication costs.

Method used

By transforming natural language commands into word segments through natural interaction, semantic mapping and semantic role labeling are performed to generate a logic tree and executable query code, thereby achieving automated power data analysis.

Benefits of technology

It improves the processing efficiency of power data analysis, reduces the consumption of human resources and the requirements for technical understanding, and enhances the accuracy and efficiency of analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121523656A_ABST
    Figure CN121523656A_ABST
Patent Text Reader

Abstract

The invention relates to an electric quantity data analysis code self-generation method and device based on natural interaction, computer equipment, a computer readable storage medium and a computer program product. The method comprises the steps that a natural language instruction used for describing electric quantity data analysis processing is acquired, and the natural language instruction is converted into a word segmentation sequence; performing semantic mapping from the power data knowledge base according to the word segmentation sequence to obtain a structured semantic mapping object corresponding to the natural language instruction; performing semantic role label labeling on each segmented word in the segmented word sequence to obtain a labeling sequence corresponding to the segmented word sequence; generating a logic tree according to each segmented word, the respective attention weight of each segmented word and the respective semantic role label of each segmented word in the labeling sequence; based on the logic tree and the structured semantic mapping object, an executable query code is generated, and the executable query code is used for executing electric quantity data analysis processing. By adopting the method, the processing efficiency of electric quantity data analysis can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computers, and particularly relates to a power data analysis code self-generation method and device based on natural interaction, a computer device, a computer readable storage medium and a computer program product. BACKGROUND

[0002] With the upgrading and promotion of the digitalization of smart grids, the analysis of power data plays a crucial role in the efficient operation, energy management and decision-making of the power industry. Traditional power data analysis usually requires manual import and export processing of a large amount of data, consuming a large amount of human and time resources. If the data is queried and processed by professional technical personnel writing SQL (Structured Query Language) code, the technical personnel are required to have a deep understanding of the structure and business logic of the power data, greatly increasing the cumbersome process and communication cost of data analysis, resulting in a low processing efficiency of power data analysis. SUMMARY

[0003] Therefore, it is necessary to provide a power data analysis code self-generation method and device based on natural interaction, a computer device, a computer readable storage medium and a computer program product, which can improve the processing efficiency of power data analysis.

[0004] In a first aspect, the present application provides a power data analysis code self-generation method based on natural interaction, comprising: obtaining a natural language instruction for describing power data analysis processing, and converting the natural language instruction into a word segmentation sequence; performing semantic mapping from a power data knowledge base according to the word segmentation sequence to obtain a structured semantic mapping object corresponding to the natural language instruction; performing semantic role label annotation on each word in the word segmentation sequence to obtain an annotation sequence corresponding to the word segmentation sequence; generating a logic tree according to each word, the attention weight of each word and the semantic role label of each word in the annotation sequence; and generating an executable query code based on the logic tree and the structured semantic mapping object, the executable query code being used for executing power data analysis processing.

[0005] In a second aspect, the present application also provides a natural interaction-based power data analysis code self-generation device, comprising: a word segmentation sequence obtaining module, configured to obtain a natural language instruction for describing power data analysis processing, and convert the natural language instruction into a word segmentation sequence; a semantic mapping module, configured to perform semantic mapping from a power data knowledge base according to the word segmentation sequence, to obtain a structured semantic mapping object corresponding to the natural language instruction; a role labeling module, configured to perform semantic role label labeling on each word in the word segmentation sequence, to obtain a labeled sequence corresponding to the word segmentation sequence; a logic tree generation module, configured to generate a logic tree according to each word, an attention weight of each word, and a semantic role label of each word in the labeled sequence; and a code generation module, configured to generate an executable query code based on the logic tree and the structured semantic mapping object, the executable query code being used to execute the power data analysis processing.

[0006] In a third aspect, the present application also provides a computer device, comprising a memory and a processor, the memory storing a computer program, and the processor implementing the steps in the method provided in the first aspect above when executing the computer program.

[0007] In a fourth aspect, the present application also provides a computer-readable storage medium, storing a computer program, the computer program being executed by a processor to implement the steps in the method provided in the first aspect above.

[0008] In a fifth aspect, the present application also provides a computer program product, comprising a computer program, the computer program being executed by a processor to implement the steps in the method provided in the first aspect above.

[0009] The natural interaction-based power data analysis code self-generation method, device, computer device, computer-readable storage medium, and computer program product described above convert a natural language instruction for describing power data analysis processing into a word segmentation sequence, perform semantic mapping from a power data knowledge base according to the word segmentation sequence, to obtain a structured semantic mapping object corresponding to the natural language instruction, perform semantic role label labeling on each word in the word segmentation sequence, to obtain a labeled sequence corresponding to the word segmentation sequence, generate a logic tree according to each word, an attention weight of each word, and a semantic role label of each word in the labeled sequence, and generate an executable query code for executing power data analysis processing based on the logic tree and the structured semantic mapping object, so that the power data analysis elements mentioned in the natural language instruction can be accurately responded, automatic conversion from the natural language instruction to the executable query code is achieved, and the processing efficiency of the power data analysis is improved. BRIEF DESCRIPTION OF DRAWINGS

[0010] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related art, the drawings needed to be used in the description of the embodiments of the present application or the related art will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.

[0011] Figure 1 An application environment diagram of the natural interaction-based power data analysis code self-generation method in one embodiment;

[0012] Figure 2 A flowchart of the natural interaction-based power data analysis code self-generation method in one embodiment;

[0013] Figure 3 A flowchart of determining attention weight in one embodiment;

[0014] Figure 4 A flowchart of the natural interaction-based power data analysis code self-generation method in another embodiment;

[0015] Figure 5 A diagram of structured semantic mapping objects in one embodiment;

[0016] Figure 6 A structural diagram of a logic tree in one embodiment;

[0017] Figure 7 A diagram of a prompt word template in one embodiment;

[0018] Figure 8 A diagram of an SQL generation example in one embodiment;

[0019] Figure 9 A flowchart of an SQL verification closed loop in one embodiment;

[0020] Figure 10 A structural block diagram of the natural interaction-based power data analysis code self-generation device in one embodiment;

[0021] Figure 11 An internal structural diagram of a computer device in one embodiment. DETAILED DESCRIPTION

[0022] In order to make the purposes, technical solutions and advantages of the present application clearer, the present application is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and not to limit the present application. It should be noted that the terms "first", "second" and the like used in the present application can be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from the second element. The terms "include" and "have" and any variations thereof used in the present application are intended to cover non-exclusive inclusion. The term "multiple" used in the present application refers to two and more than two. The term "and / or" used in the present application refers to one of the options or any combination of multiple options.

[0023] The natural interaction-based power data analysis code self-generation method provided by the embodiments of the present application can be applied to, for example Figure 1The application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data required by the server 104 to process. The data storage system can be integrated on the server 104, or placed on the cloud or other network servers. The user can edit the natural language instruction through the terminal 102, and the natural language instruction can describe the required power data analysis processing. The terminal 102 can send the natural language instruction to the server 104, and the server 104 can convert the natural language instruction into a word segmentation sequence, and perform semantic mapping from the power data knowledge base according to the word segmentation sequence, to obtain a structured semantic mapping object corresponding to the natural language instruction. The server 104 can perform semantic role label annotation on each word in the word segmentation sequence to obtain an annotation sequence corresponding to the word segmentation sequence, and generate a logic tree according to each word, the attention weight of each word, and the semantic role label of each word in the annotation sequence. The server 104 can generate executable query code for executing power data analysis processing based on the logic tree and the structured semantic mapping object. In some embodiments, the server 104 can return the executable query code to the terminal 102, so that the user triggers the execution of the power data analysis processing based on the executable query code. In some embodiments, the natural interaction-based power data analysis code self-generation method can also be implemented by the terminal 102 or the server 104 alone. Among them, the terminal 102 can be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, unmanned aerial vehicles, low-altitude aircraft, Internet of Things devices and portable wearable devices. The Internet of Things device can be a smart speaker, a smart TV, a smart air conditioner, a smart vehicle device, a projection device, etc. The portable wearable device can be a smart watch, a smart bracelet, a head-mounted device, etc. The head-mounted device can be a virtual reality (VR) device, an augmented reality (AR) device, smart glasses, etc. The server 104 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.

[0024] In an exemplary embodiment, as Figure 2 shown, a natural interaction-based power data analysis code self-generation method is provided, which is executed by a computer device, specifically by a terminal or a server, etc. Computer device alone, or by a terminal and a server together, in the embodiments of the present application, taking the server in Figure 1 as an example for illustration, including the following steps 202 to 210. Among them:

[0025] Step 202, obtaining a natural language instruction for describing power data analysis processing, and converting the natural language instruction into a word segmentation sequence.

[0026] The natural language instruction can be provided by a user, e.g., the user can edit the natural language instruction, or the user can utter the natural language instruction. The natural language instruction can be used for an electric quantity data analysis processing, e.g., the natural language instruction can be “query the average power load of region A in the first quarter of 2025”. The token sequence can be obtained by splitting the natural language instruction, and the token sequence can include tokens that are sequentially arranged to form the natural language instruction, and each token can be used as a semantic unit of the natural language instruction.

[0027] Optionally, the server can obtain the natural language instruction, and the natural language instruction can be configured by a user according to an electric quantity data analysis processing requirement, e.g., the user can configure the natural language instruction based on the electric quantity data analysis processing requirement via a terminal, and the terminal can send the natural language instruction to the server. In some embodiments, the natural language instruction can include a text instruction directly edited by the user, or the natural language instruction can include a text instruction obtained by voice recognition based on a user voice. The server can convert the natural language instruction to obtain the token sequence. For example, the server can split the natural language instruction to obtain tokens, and arrange the tokens according to an order of the tokens in the natural language instruction, so as to obtain the token sequence. In some embodiments, the server can convert an unstructured natural language instruction to a structured semantic element that can be recognized by a machine, e.g., by tokenization, stop word removal, and format standardization, so as to obtain the token sequence.

[0028] In step 204, a structured semantic mapping object corresponding to the natural language instruction can be obtained by performing semantic mapping on the electric quantity data knowledge base based on the token sequence.

[0029] The structured semantic mapping object can be obtained by performing semantic mapping on the electric quantity data knowledge base based on the tokens included in the token sequence, and the structured semantic mapping object can include standardized semantics, e.g., “query action”, “data retrieval”, “field type”, “geographical division dimension”, and the like.

[0030] Exemplarily, the server can determine a pre-constructed power data knowledge base, which can include various power knowledge in the power business field. The power data knowledge base can be constructed based on historical work orders, power analysis reports, power metering terminology specifications, business rule manuals, and historical SQL logs, etc. The server can perform semantic mapping from the power data knowledge base according to the word segmentation sequence, for example, the server can perform semantic mapping of each word in the word segmentation sequence in the power data knowledge base to obtain the standardized semantics of each word, thereby obtaining a structured semantic mapping object corresponding to the natural language instruction. For example, a structured semantic mapping object in JSON (JavaScript Object Notation) format can be obtained.

[0031] Step 206, semantic role labeling is performed on each word in the word segmentation sequence to obtain an annotation sequence corresponding to the word segmentation sequence.

[0032] The semantic role label is used to represent the role of the word in the power data analysis processing task, for example, it can include the mapping role of business terminology and database fields. The annotation sequence can include the semantic role label of each word in the word segmentation sequence. Optionally, the server can perform semantic role labeling on each word in the word segmentation sequence to obtain an annotation sequence corresponding to the word segmentation sequence. For example, the server can perform semantic role labeling on each word in the word segmentation sequence through a pre-trained role labeling model, thereby obtaining an annotation sequence corresponding to the word segmentation sequence. Through semantic role labeling, the role of each word in the power data analysis task can be determined, and the importance of time, field, business scenario, etc. can be highlighted through weight allocation, so as to ensure the reliability of the power data analysis code generation.

[0033] Step 208, generating a logic tree according to each word, the attention weight of each word, and the semantic role label of each word in the annotation sequence.

[0034] The attention weight can be determined for each word based on the attention mechanism. The logic tree (Logic Tree) is a structured analysis tool that decomposes complex problems or concepts into smaller and more manageable components through tree-like graphs. Exemplarily, the server can determine the attention weight of each word, for example, the server can determine the attention weight of each word based on the attention mechanism. The server can build a logic tree according to each word, the attention weight of each word, and the semantic role label of each word in the annotation sequence, and each logic node in the logic tree can represent a word in the word segmentation sequence.

[0035] At step 210, based on the logical tree and the structured semantic mapping object, executable query code for performing the power data analysis processing is generated.

[0036] The executable query code can be used to perform the power data analysis processing, such as the executable query code can include SQL code. Alternatively, the server can generate executable query code for performing the power data analysis processing based on the logical tree and the structured semantic mapping object. In some embodiments, the server can execute the executable query code to perform the power data analysis processing in response to the natural language instruction and obtain a processing result, and the server can return the processing result to the terminal for presentation to the user through the terminal.

[0037] In the above natural interaction-based power data analysis code self-generation method, the natural language instruction for describing the power data analysis processing is converted into a word segmentation sequence, the structured semantic mapping object corresponding to the natural language instruction is obtained from the power data knowledge base according to the word segmentation sequence, the semantic role label annotation sequence corresponding to the word segmentation sequence is obtained by performing semantic role label annotation on each word in the word segmentation sequence, the logical tree is generated according to each word, the attention weight of each word, and the semantic role label of each word in the annotation sequence, and the executable query code for performing the power data analysis processing is generated based on the logical tree and the structured semantic mapping object. The power data analysis elements mentioned in the natural language instruction can be accurately responded to, automatic conversion from the natural language instruction to the executable query code is achieved, and the processing efficiency of the power data analysis is improved.

[0038] In an exemplary embodiment, converting the natural language instruction into a word segmentation sequence includes: splitting the natural language instruction into at least one semantic unit; filtering the at least one semantic unit to obtain a target semantic unit; performing format processing on the target semantic unit to obtain a formatted semantic unit; and obtaining the word segmentation sequence corresponding to the natural language instruction based on the formatted semantic unit.

[0039] The semantic unit is the smallest language unit in natural language processing (NLP) and a knowledge graph that carries independent and complete semantics, and can represent a complete concept, entity, attribute or relationship. The target semantic unit is a semantic unit reserved after filtering of the semantic unit. For example, the target semantic unit can be a core semantic word obtained after filtering of auxiliary words that have no actual business meaning. The formatted semantic unit can be a semantic unit with a uniform format. For example, the server can perform semantic unit splitting on the natural language instruction to split the natural language instruction into at least one semantic unit. The server can filter the split semantic unit to remove semantic units that have no actual business meaning, thereby obtaining a target semantic unit. The server can perform formatting processing on the target semantic unit to convert the target semantic unit into a formatted semantic unit with a standardized format. The server can obtain a word sequence corresponding to the natural language instruction according to the formatted semantic unit. For example, the server can arrange each word according to the order of the corresponding semantic unit in the natural language instruction to obtain a word sequence corresponding to the natural language instruction.

[0040] In some embodiments, converting the unstructured natural language instruction into a machine-recognizable structured semantic element to obtain a word sequence can include three stages: (1) instruction preprocessing stage: using a power field customized word segmentation tool to split the natural language instruction into the smallest semantic unit; (2) stop word removal: filtering auxiliary words that have no actual business meaning for each semantic unit, and retaining core semantic words to obtain target semantic units; (3) format standardization: performing preliminary format unification on special type words such as numbers and times, retaining number formats, and excluding text expression interference to obtain formatted semantic units. Arranging each formatted semantic unit in order can obtain a word sequence corresponding to the natural language instruction.

[0041] In this embodiment, the server can split the natural language instruction into semantic units, then perform filtering and formatting processing on the semantic units in turn, and obtain a word sequence based on the obtained formatted semantic units, which can accurately extract the power data analysis and processing elements mentioned in the natural language instruction, and is beneficial to improving the work efficiency of power data analysis and processing.

[0042] In an example embodiment, the semantic mapping from the power data knowledge base according to the word segmentation sequence obtains a structured semantic mapping object corresponding to the natural language instruction, including: determining a preset power data knowledge base, performing mixed retrieval in the power data knowledge base for each word in the word segmentation sequence according to at least two retrieval methods to obtain respective retrieval results of each word in the word segmentation sequence; and performing field mapping in the power data knowledge base according to the respective retrieval results of each word to obtain a structured semantic mapping object corresponding to the natural language instruction.

[0043] The mixed retrieval can be a retrieval process in the power data knowledge base for each word in the word segmentation sequence by multiple retrieval methods. For example, the retrieval methods can include, but are not limited to, at least two of vector retrieval, keyword retrieval, and rule matching. For example, the server can determine a pre-constructed power data knowledge base, which can be pre-constructed according to actual needs. For example, the server can obtain a power data field set from a smart meter and the like, synchronously collect historical work orders, power analysis reports, power metering terminology specifications, business rule manuals, and historical SQL logs, and construct a semantic knowledge base based on the above data sources, which can specifically include a metadata knowledge base, a business terminology library, and a historical SQL template library. The server can perform mixed retrieval in the power data knowledge base for each word in the word segmentation sequence by multiple retrieval methods, thereby obtaining respective retrieval results of each word. The server can perform field mapping in the power data knowledge base according to the respective retrieval results of each word to map each word into a standardized semantic, and the server can obtain a structured semantic mapping object corresponding to the natural language instruction according to the standardized semantic of each word.

[0044] In some embodiments, the mixed retrieval strategy can include: 1) vector retrieval (60%): calculating the semantic similarity between the user instruction and the knowledge base based on the Word2Vec word vector, suitable for fuzzy matching scenarios; 2) keyword retrieval (30%): performing accurate matching on the time, field, and business scenario keywords in the user instruction to ensure that the core information is not biased; 3) rule matching (10%): performing time format conversion, encoding mapping, and unifying data formats. The server can perform mixed retrieval for each word in the word segmentation sequence according to the vector retrieval, keyword retrieval, rule matching, and respective proportion weights of various retrieval methods, thereby obtaining respective retrieval results of each word in the word segmentation sequence.

[0045] The server can perform field mapping based on the respective retrieval results of each word in the word segmentation sequence. For example, the power data knowledge base can include a metadata knowledge base, a business terminology library, and a historical SQL template library, and the semantic knowledge base mapping process can include:

[0046] 1) Metadata repository: The main data sources are the power grid database table structure definition, field interpretation, information coding definition and database table field blood relationship, which provide basic metadata support for subsequent field mapping and table association.

[0047] 2) Business term library: Set user term set (k is the term index, K is the total number of terms), each term Correlation "user expression-standard term-database field" ternary mapping group, while binding business scenario label.

[0048] 3) Historical SQL template library: K-means clustering of historical SQL logs, extraction of high-frequency query patterns, formation of template library. Each template contains "scene description-SQL structure-field mapping-filter condition type" four parts.

[0049] Through the metadata repository, business term library and historical SQL template library, the field mapping of the retrieval results of various types of word segmentation can be performed respectively to obtain the standardized semantics of each word segmentation. The server can obtain the structured semantic mapping object corresponding to the natural language instruction according to the standardized semantics of each word segmentation.

[0050] In this embodiment, the server can perform mixed retrieval in the power data knowledge base for each word in the word segmentation sequence through various retrieval methods, and perform field mapping in the power data knowledge base according to the retrieval results of each word to obtain the structured semantic mapping object corresponding to the natural language instruction. Based on the structured semantic mapping object, the executable query code is generated, which is beneficial to ensure the accuracy and reliability of the executable query code, thereby improving the processing efficiency of the power data analysis.

[0051] In one exemplary embodiment, the semantic role label annotation is performed for each word in the word segmentation sequence to obtain the annotation sequence corresponding to the word segmentation sequence, including: performing vector mapping for each word in the word segmentation sequence through a pre-trained vector mapping model to obtain a word vector sequence, the word vector sequence including the word vector of each word; performing semantic role label annotation for the word vector of each word in the word vector sequence through a conditional random field model to obtain the annotation sequence corresponding to the word segmentation sequence.

[0052] The vector mapping model can be used to map the segmented words into word vectors. The vector mapping model can include a Word2Vec model. The sequence of word vectors can be obtained by arranging the word vectors of the segmented words in the order of their positions in the sequence of segmented words. The CRF model is a probabilistic graphical model used for sequence labeling tasks, and belongs to the discriminative model type. The CRF model can be used to predict a sequence of labels for an input sentence.

[0053] The server can determine a pre-trained vector mapping model, and use the vector mapping model to map each segmented word in the sequence of segmented words into a word vector. The server can combine the word vectors of the segmented words to obtain a sequence of word vectors. The server can determine a CRF model, and use the CRF model to label each word vector in the sequence of word vectors with a semantic role label, thereby obtaining a sequence of labels corresponding to the sequence of segmented words. The sequence of labels can include semantic role labels for each segmented word.

[0054] In some embodiments, the server can pre-build a Word2Vec-CRF word vector sequence labeling model, which can include a vector mapping model and a CRF model. The input of the Word2Vec-CRF word vector sequence labeling model can be a sequence of segmented words obtained based on a natural language instruction wherein is the i-th segmented word in the instruction; and the output of the Word2Vec-CRF word vector sequence labeling model is a sequence of labels corresponding to the sequence of segmented words wherein is a semantic role label of the i-th segmented word, and the labels cover four categories of “query action, field type, business scenario, and filter condition”. In some embodiments, the Word2Vec pre-training process can include:

[0055] The word vector learning is achieved by maximizing the log probability, and the formula is as follows:

[0056] The word vector learning is achieved by maximizing the log probability, and the formula is as follows:

[0057]

[0058] wherein, is an optimization objective function in the training process, is a target word, , ​The window size of the target word segmentation is set as According to the complexity of the power field corpus, c is set to 3-5, The power field corpus (including business documents, historical instructions, SQL comments, etc.). P(·) is the probability.

[0059] Objective function The optimization process directly determines the parameter update of the word vector matrix Specifically:

[0060]

[0061] Through the back propagation algorithm, the gradient guides the iterative update of the word vector matrix :

[0062]

[0063] Where is the learning rate. After pre-training, the word vector matrix is obtained, where is the vocabulary (covering the core terms of the power field), is the word vector dimension. This matrix can convert natural language words into computer-understandable vectors and capture semantic associations.

[0064] For CRF sequence labeling processing, it can include:

[0065] The conditional random field (CRF) is used to label the word vector sequence. The core is to define the feature function to capture the sequence dependency relationship, and the formula is as follows:

[0066]

[0067] Where, is the label of the current word, is the label of the previous word, is the input natural language instruction sequence, is the position index of the current word in the sequence, is the learnable weight of the feature function, which is iteratively optimized through training data, is the feature function. is the global scoring function of the labeled sequence, which reflects the rationality of the "overall sequence label combination with respect to the observed sequence". The labeled sequence corresponding to the maximum global scoring function can be determined as the word segmentation sequence corresponding to the labeled sequence. Through the Word2Vec-CRF word vector sequence labeling model, the natural language instructions input by the user through natural interaction can be converted into computer-understandable labeled sequences with semantic role labels.

[0068] In this embodiment, the server maps the word segmentation sequence into a word vector sequence through a vector mapping model, and respectively performs semantic role label annotation on the word vectors of each word segmentation in the word vector sequence through a conditional random field model, so as to obtain an annotation sequence, which can ensure the accuracy of semantic role label annotation and is beneficial to improving the processing efficiency of power data analysis.

[0069] In one exemplary embodiment, a logical tree is generated according to each word segmentation, the attention weight of each word segmentation, and the semantic role label of each word segmentation in the annotation sequence, including: determining the attention weight of each word segmentation based on each word segmentation and the semantic role label of each word segmentation in the annotation sequence; mapping each word segmentation into a logical node according to the attention weight and the semantic role label of each word segmentation; generating an initial logical tree according to the attention weight and the logical node of each word segmentation; and injecting a verification rule into each logical node in the initial logical tree to obtain the logical tree.

[0070] The logical node can be mapped according to the attention weight and the semantic role label of each word segmentation, and each logical node is used to represent the corresponding word segmentation. The initial logical tree can be generated according to the attention weight and the logical node of each word segmentation. The verification rule can be a verification rule for the data corresponding to the word segmentation, and the verification rule can be determined from the power data knowledge base.

[0071] Alternatively, the server can determine the semantic role label of each word segmentation based on the annotation sequence, and determine the attention weight of each word segmentation in combination with each word segmentation. For example, the server can obtain the attention weight of each word segmentation according to each word segmentation and the semantic role label of each word segmentation in the annotation sequence based on an attention mechanism. The server can map each word segmentation according to the attention weight and the semantic role label of each word segmentation to obtain the logical node of each word segmentation. The server can generate an initial logical tree according to the attention weight of each word segmentation and the logical node of each word segmentation, for example, can generate the initial logical tree based on the logical node of each word segmentation in a depth-first search (DFS) mode according to the priority of the attention weight. The server can inject a verification rule into each logical node in the initial logical tree, for example, can inject the verification rule corresponding to the logical node, so as to obtain the logical tree.

[0072] In some embodiments, the server can generate a logical tree through attention weight, carry out node framework construction and injection of verification rules, such as the server can generate a logical tree according to the annotation sequence output by the Word2Vec-CRF model as input, in combination with attention weight mapping, the logical tree needs to include core nodes such as "query target, filter condition, calculation rule, output field", and provide a structured template for SQL code generation, in the process of building the logical tree, verification rules such as field legality and time format correctness need to be injected into each logical node.

[0073] When building the logical tree, the server can map the annotation type and the logical node to form a clear corresponding relationship. The node type set corresponds to the query target, the filter condition, the calculation rule and the output field respectively; according to the label and the attention weight , the word is converted into a logical node through a mapping function :

[0074]

[0075] The server can adopt depth-first search (DFS) according to the priority of attention weight to build the logical tree structure, as follows:

[0076]

[0077] Wherein, T is an initial logical tree, is the maximum depth of the logical tree, and the node with high weight is given priority to be a parent node.

[0078] Verification rules can be injected into the initial logical tree, which can include:

[0079] For each logical node of the logical tree, the corresponding term in the semantic knowledge base is associated, and the verification rule of the term is injected, as follows:

[0080]

[0081] By injecting verification rules for each logical node in the initial logical tree, the logical tree can be obtained.

[0082] In this embodiment, the server maps each wordpiece to each logical node according to the attention weight and the semantic role label of each wordpiece, generates an initial logical tree according to the attention weight and the logical node of each wordpiece, and injects a verification rule for each logical node in the initial logical tree to obtain a logical tree. The logical tree can be constructed based on the attention weight and the semantic role label, and the executable query code can be generated through the logical tree. The power data analysis element mentioned in the natural language instruction can be accurately determined, thereby improving the processing efficiency of the power data analysis.

[0083] In one exemplary embodiment, as shown in Figure 3 The process of determining the attention weight, i.e., determining the attention weight of each wordpiece based on the semantic role label of each wordpiece in the wordpiece and the annotation sequence, includes steps 302 to 306. Among them:

[0084] Step 302, respectively mapping the semantic role label of each wordpiece in the annotation sequence into an embedding vector.

[0085] Among them, the embedding vector can be obtained by mapping the semantic role label. Optionally, the server can determine the semantic role label of each wordpiece from the annotation sequence, and respectively map the semantic role label of each wordpiece to obtain the embedding vector of each wordpiece.

[0086] Step 304, fusing the word vector and the embedding vector of each wordpiece to obtain the fusion vector of each wordpiece.

[0087] Among them, the fusion vector can be obtained by fusing the word vector and the embedding vector of each wordpiece, such as splicing the word vector and the embedding vector to obtain the fusion vector of each wordpiece. Exemplarily, the server can determine the word vector of each wordpiece, and the word vector can be obtained by mapping the wordpiece. The server can fuse the word vector and the embedding vector of each wordpiece to obtain the fusion vector of each wordpiece.

[0088] Step 306, determining the attention weight of each wordpiece based on the attention mechanism and the fusion vector of each wordpiece.

[0089] Among them, the attention mechanism is an artificial intelligence technology that allows the model to dynamically "focus" on the most relevant parts of the input sequence when processing input data, rather than uniformly processing all parts. Attention mechanism can give different "attention scores" to different elements of the input by calculating attention weights, thereby improving the accuracy and efficiency of the model in a specific task. Optionally, the server can assign weights to each segmented word based on the attention mechanism according to the fusion vector of each segmented word to obtain the attention weight of each segmented word.

[0090] In some embodiments, in determining the attention weight of each segmented word, the server can map the obtained semantic role label to an embedding vector , and concatenate the corresponding word vector to a fusion vector . The server can process the fusion vector through an encoder to generate a hidden state , formula:

[0091]

[0092] The server can calculate the attention weight of each hidden state , the higher the weight, the greater the impact of the word on SQL generation, formula:

[0093]

[0094] wherein , is a learnable parameter matrix, is a query vector representing the SQL generation requirement, is a bias term.

[0095] In this embodiment, the server can fuse the word vector and embedding vector of each segmented word, and determine the attention weight based on the attention mechanism according to the fusion vector of each segmented word, which can fuse the segmented word features and semantic role label features to ensure the accuracy of the attention weight.

[0096] In an exemplary embodiment, based on the logical tree and the structured semantic mapping object, an executable query code is generated, including: based on the structured semantic mapping object, obtaining auxiliary resources from the power data knowledge base; generating a candidate query code according to the logical tree, the auxiliary resources and the prompt word template; when the candidate query code passes the legality check, obtaining the executable query code according to the candidate query code.

[0097] The auxiliary resource can include, but is not limited to, at least one of a data table structure, a table relationship, a field dictionary, and a historical SQL template. The auxiliary resource can be obtained from the power data knowledge base based on the structured semantic mapping object. The candidate query code is a query code generated based on the logical tree, the auxiliary resource, and the prompt word template. After the candidate query code passes the legality check, an executable query code for performing power data analysis and processing can be obtained based on the candidate query code.

[0098] Exemplarily, the server can query the power data knowledge base based on the structured semantic mapping object to obtain the auxiliary resource from the power data knowledge base, such as at least one of a data table structure, a table relationship, a field dictionary, and a historical SQL template. The server can determine the prompt word template, which can include a query code template, such as an SQL template. The server can generate the candidate query code based on the logical tree, the auxiliary resource, and the prompt word template, such as filling the prompt word template based on the logical tree and the auxiliary resource to obtain a target prompt word, and generating the candidate query code based on the target prompt word. The server can perform the legality check on the candidate query code to obtain a check result. When the check result is a pass, the server can obtain the executable query code based on the candidate query code, such as determining the candidate query code as the executable query code.

[0099] In some embodiments, the server can generate executable SQL code based on the semantic logic through the prompt word engineering, and convert the user's analysis requirement into an actual operable database query statement, such as taking the logical tree structured information as the core, fusing the table structure definition, the table relationship, the field dictionary, and the historical SQL template example in the knowledge base, constructing a "instruction-context-example-output format" four-element prompt word template, dynamically generating an executable query statement conforming to the SQL syntax specification and the power business rule through the template, and finally converting the user's natural language analysis requirement into an actual operable database query code.

[0100] In some embodiments, for the prompt word engineering template construction process, the logical tree T and the semantic knowledge base output can be taken as the input, and the prompt word engineering template can be designed as follows:

[0101] The instruction is to generate an accurate SQL query statement based on the user's question and the provided database mode, the relationship, and the historical SQL example, and needs to meet the power business rule;

[0102] The context includes a filtered table structure (filtered_table.json), a table relationship (relation.json), a field dictionary (dict.json), and a historical SQL example (sql_shot.txt).

[0103] For dynamic SQL generation rules, the hint word template can be filled and SQL clauses can be generated according to the logical tree node type:

[0104] The SELECT clause: the output fields are extracted from the Output node, including the fields explicitly required by the user and the core associated fields, and Chinese aliases are added to the fields;

[0105] The FROM / JOIN clause: the table information associated with the Query node is combined with the inter-table relations (relation.json) in the knowledge base to determine the main table and the associated table, and the correct connection method is used;

[0106] The WHERE clause: the filter conditions are extracted from the “Filter” node, and the default business rule conditions are injected;

[0107] The aggregation and sorting clause: if the Compute node contains aggregation requirements, the “GROUP BY” clause is added; if the user has sorting requirements, the ORDER BY clause is added; and the LIMIT clause is added as needed to limit the number of returned rows.

[0108] After obtaining the candidate query code, the candidate query code can be verified for legality. For example, the generated SQL needs to be verified for legality by a verification function, as follows:

[0109]

[0110] wherein, is the SQL syntax verification, is the SQL field extraction function is the set of valid fields in the semantic knowledge base, is an indication function (if the conditions in the parentheses are all met, return 1, representing that the SQL is legal; otherwise, return 0, and the SQL needs to be regenerated).

[0111] In this embodiment, the server can obtain auxiliary resources from the power data knowledge base according to the structured semantic mapping object, and generate a candidate query code in combination with the logical tree, the auxiliary resources and the hint word template. When the candidate query code passes the legality verification, an executable query code is obtained according to the candidate query code, which can ensure that the executable query code can accurately cover the power data analysis elements mentioned in the natural language instruction, and is beneficial to improving the processing efficiency of power data analysis.

[0112] The application also provides an application scenario applying the above-mentioned natural interaction-based power data analysis code self-generation method. Specifically, the natural interaction-based power data analysis code self-generation method is applied in the application scenario as follows:

[0113] With the upgrading and promotion of the digitalization of smart grid, the analysis of electricity consumption data plays a crucial role in the efficient operation, energy management and decision-making of the power industry. Traditional electricity consumption data analysis usually requires manual import and export processing of a large amount of data, consuming a lot of human and time resources. If the data is queried and processed by professional technical personnel through SQL code, it requires technical personnel to have a deep understanding of the structure and business logic of electricity consumption data, greatly increasing the cumbersome process and communication cost of data analysis. In the actual process of electricity consumption data analysis, there is a long time for manual processing, lack of intelligent analysis method of electricity consumption data, resulting in too cumbersome and inefficient electricity consumption data analysis process. In the existing research methods, there is still a lack of integration of intelligent analysis technology in the research of electricity consumption data; for natural interaction, it cannot accurately respond to the electricity consumption analysis elements mentioned in the user's natural language instruction.

[0114] Based on this, the application provides a natural interaction-based electricity consumption data analysis code self-generation method, which realizes the automatic conversion from user natural language instruction to executable SQL code by using Word2Vec-CRF model and prompt word engineering, accurately responds to the electricity consumption analysis elements mentioned in the user's natural language instruction, and improves the work efficiency of electricity consumption data analysis. The natural interaction-based electricity consumption data analysis code self-generation method provided by the application solves the problems of complicated data analysis process, high communication cost and low work efficiency, realizes the automatic conversion from user natural language instruction to executable SQL code by using Word2Vec-CRF model and prompt word engineering, accurately responds to the electricity consumption analysis elements mentioned in the user's natural language instruction, and improves the work efficiency of electricity consumption data analysis.

[0115] As shown in Figure 4 , it is a flowchart of the natural interaction-based electricity consumption data analysis code self-generation method in some embodiments, which includes:

[0116] Step 401, pre-processing of user natural language instruction;

[0117] Step 402, semantic analysis and mapping by using knowledge base;

[0118] Step 403, establishing Word2Vec-CRF word vector sequence labeling model to process and train data;

[0119] Step 404, generating logical tree through attention weight, building node framework and injecting verification rules;

[0120] Step 405, generating executable SQL code based on prompt word engineering, converting user's analysis demand into actual operable database query statement.

[0121] Exemplarily, taking the input information as a user natural language instruction: "Query the maximum load of each region in 2023" as an example:

[0122] Step 401 can include: first, performing basic preprocessing on the user natural language instruction, splitting the instruction query the maximum load of each region in 2023 into the smallest semantic units ["query", "2023", "year", "each", "region", "maximum", "load"], then filtering auxiliary words without actual business meaning such as "of", "year", etc., and retaining the core semantic words: ["query", "2023", "region", "maximum", "load"]. Perform preliminary format unification on special type words such as numbers and times, "retain 2023" number format, and exclude text expression interference such as "2023".

[0123] Step 402 can include:

[0124] (1) Mixed retrieval phase

[0125] Vector retrieval (core weight 60%): Based on the pre-trained word vector model of the power field in the semantic knowledge base, the cosine similarity of the core words and the standard business terms is calculated to realize "fuzzy semantic matching". Here, "load" has high similarity with the "electric power load measurement value" term in the knowledge base, which is determined as the core business index; "region" has high similarity with the "geographical division dimension" term, which is determined as the data grouping dimension; "maximum" has high similarity with the semantic of "aggregation calculation mode-MAX", which is determined as the index calculation mode.

[0126] Keyword retrieval (auxiliary weight 30%): Through regular expressions and keyword dictionaries, "precise element extraction" is realized to supplement the details of vector retrieval. Extract the time keyword "2023" to match the "time filtering dimension" label in the knowledge base; extract the "each" in "each region" to trigger the "full grouping" business scenario, excluding "specific region" filtering conditions; extract the action keyword "query" to lock the "data retrieval" operation type, excluding other operations such as "data insertion / modification").

[0127] Rule matching (verification weight 10%): Apply predefined business rules to normalize and correct the retrieval results to ensure semantic consistency. Time rule, supplement "2023" to "annual dimension-2023" to avoid confusion with "monthly / daily-2023"; calculation rule, verify the rationality of "maximum + load" combination, exclude ambiguous expressions such as "minimum load", "average load"; dimension rule: confirm "region" as a one-level grouping dimension, without nested grouping "region + time" requirement.

[0128] (2) Knowledge base mapping phase

[0129] Business Term Library Mapping: According to the search results, match the standard business definitions corresponding to the core words from the knowledge base:

[0130] "Load" → "Electricity Load Measurement" (Core Indicator, Max Value Calculation Required);

[0131] "Region" → "Geographical Division Dimension" (Grouping Basis, Full Coverage Required);

[0132] "2023" → "Time Filter Dimension - Year" (Filter Condition, Exact Match Required).

[0133] Historical SQL Template Library Mapping: Based on the combination of "Regional Grouping + Maximum Indicator Calculation + Time Filtering", recall high-frequency matching templates in the knowledge base:

[0134] Template Scenario: "Grouping by Geographical Dimension, Calculating Maximum Value of Core Indicator in Specified Year";

[0135] Template Structure: SELECT [Grouping Dimension], MAX ([Core Indicator]) FROM [Data Table] WHERE [Time Dimension] = [Specified Value] GROUP BY [Grouping Dimension].

[0136] The output of this step is a structured semantic mapping object (JSON format) containing all the core elements required for the query. As shown in Figure 5 , the structured semantic mapping object output by the knowledge base semantic analysis and mapping.

[0137] Step 403 can include:

[0138] Preprocessed Token Sequence: ["Query", "2023", "Year", "Each", "Region", "Maximum", "Load"] Through "Word Vector Encoding + Sequence Labeling", achieve "Semantic Role Localization" for each token, clearly defining its function in the query process, which is divided into two stages:

[0139] (1) Word2Vec Word Vector Mapping Stage:

[0140] Use a pre-trained Word2Vec model based on power domain corpus, with vector dimension set to 256, window size 5, to ensure industry semantic accuracy. Input each token into the model to generate high-dimensional word vectors "Load" → , "Region" → ;

[0141] Through the objective function ( For the current word (where context is the context), make the vector distance between semantically similar words "load" and "burden" ≤ 0.1, and the vector distance between the unrelated word "load" and the time vector ≥ 0.8, ultimately obtaining a more precise semantic matching for the model.

[0142] (2)CRF sequence labeling stage

[0143] The Conditional Random Field (CRF) captures the "contextual dependencies" of the word segmentation sequence by constructing feature functions, avoiding ambiguities caused by isolated labeling. Here, "each" needs to be combined with "region" to be determined as "scope modification".

[0144] 1) Feature function design:

[0145] Local features: —— Based on the word vector of the current word determine its basic role, that is, the numerical feature of "2023" → candidate "time condition";

[0146] Transition features: —— Based on the role of the previous word optimize the role of the current word That is, if "year" is preceded by "2023", then it is corrected from "ordinary modification" to "time modification";

[0147] Global features: —— Based on the semantics of the entire sequence, adjust the role consistency. That is, if "maximum" is followed by "load", then "maximum" is corrected from "ordinary adjective" to "aggregation operation".

[0148] 2) Labeling execution:

[0149] Input the word vector sequence, calculate the role probability distribution of each word segment through the CRF model; select the role label with the highest probability to generate the final labeled sequence. That is, the "scope modification" probability of "each" is relatively high, far exceeding other roles.

[0150] The output result of this step is a semantic role labeled sequence corresponding one-to-one to the word segmentation sequence. The function definitions of each role in [query action, time condition, time modification, scope modification, grouping field, aggregation operation, calculation field] are as follows:

[0151] "Query action": Define the operation type, that is, data retrieval;

[0152] "Time condition + time modification": Combine to form time filtering elements, that is, 2023;

[0153] "Scope modification + grouping field": Combine to form full-scale grouping elements, that is, each region;

[0154] "Aggregation operation + calculated field": This combination constitutes the core indicator calculation element, namely the maximum load.

[0155] Step 404 may include:

[0156] (1) Attention weight calculation stage

[0157] The output semantic role-labeled sequence Y: [query action, time condition, time modifier, range modifier, grouping field, aggregation operation, calculated field] corresponds to the Word2Vec word vector on the word segmentation, i.e. , , Wait, then perform feature fusion generation:

[0158] Each semantic role tag [query action, time condition, time modifier, range modifier, grouping field, aggregation operation, calculated field] is converted into a tag embedding vector. The dimension is 256; it is then compared with the word vectors of the corresponding word segments. Concatenate to form a fused feature vector It has 512 dimensions and retains both semantic information of roles and words.

[0159] Encoder processing: A two-layer Transformer encoder is used to perform context encoding on the fused feature vector sequence to generate hidden states containing global information. The encoder captures the correlation between different feature vectors through a self-attention mechanism, such as the correlation weight values ​​between "aggregation operations" and "computational fields".

[0160] Weight Calculation: Define a query vector q (randomly initialized and optimized through training), and calculate the attention weights for each hidden state using the Softmax function. :

[0161]

[0162] The weighting results are shown in Table 1 below.

[0163] Table 1

[0164]

[0165] (2) Logic tree construction stage

[0166] Node mapping rules are defined, pre-setting the mapping relationship between semantic roles and logical tree nodes. The higher the weight of a role, the more core the node it corresponds to.

[0167] "Query Action" → Root Node (Query): Defines the query entry point, with no specific parameters;

[0168] "Time condition + time modifier" → Filter node: responsible for data filtering, parameter is "time dimension = 2023";

[0169] "Grouping field + range modifier" → Output node: responsible for data grouping and display, parameter is "grouping dimension = region";

[0170] "Aggregation operation + calculated field" → Compute node: Responsible for metric calculation, with the parameter "Calculation method = MAX (load)".

[0171] Tree structure generation:

[0172] The "depth-first traversal" strategy is adopted, starting from the root node and expanding the child nodes from high to low according to the attention weight (Compute→Output→Filter).

[0173] Building a hierarchical relationship: The root node (Query) contains three child nodes (Compute, Output, Filter), and the child nodes are related through "data flow" (data filtered by Filter → Compute calculation → Output output).

[0174] (3) Verification rule injection stage

[0175] Rule retrieval: Based on business terms associated with logical tree nodes, match corresponding rules from the "validation rule base" of the semantic knowledge base.

[0176] Filter node (time dimension): Injects "time validity check", meaning that 2023 must be within the database time coverage range;

[0177] Output node (region dimension): Injects "dimensional value validation", that is, the region must be a valid geographical division defined in the knowledge base, and invalid values ​​are excluded;

[0178] Compute node (load metric): Injects "numerical reasonableness verification", that is, the load value must be within a reasonable range to exclude abnormal data;

[0179] Global rule: Inject "data status verification", that is, only filter "valid status" data and exclude "invalid / test" data.

[0180] Rule binding: Bind the validation rules to the corresponding nodes as "attributes" to ensure that validation is automatically triggered when subsequent SQL is generated.

[0181] The output of this step is a logic tree T (JSON format) with validation rules. For example... Figure 6 The diagram shown is a schematic representation of the logic tree T for injecting verification rules.

[0182] Step 405 may include:

[0183] In practical applications, based on prompt word engineering, semantic logic is generated into executable SQL code, transforming user analysis requirements into practical and operable database query statements.

[0184] The output logic tree T and auxiliary resources retrieved in real time from the semantic knowledge base are taken as input. The auxiliary resources mainly include:

[0185] Data table structure: The core data table is mapped by "table name - field type", that is, the "geographic dimension field", "time dimension field", "load index field" and "data status field" included in the power load table;

[0186] Field dictionary: The correspondence between standard terms and database fields, i.e., "geographic division dimension" → the corresponding region field name in the database;

[0187] Historical SQL example: Historical query statements that match the current logical tree, i.e., the SQL for "maximum load query for each region in 2023").

[0188] Business constraints: The default filter condition is "data status field = valid".

[0189] This step mainly transforms the logic tree into executable standard SQL through "prompt word construction + model inference + SQL verification", which is divided into three stages:

[0190] (1) Prompt word template filling and construction stage

[0191] Template Design: A four-element template structure of "instruction-context-example-format" is used to ensure that the large language model understands the query requirements and output specifications. For example... Figure 7 The image shown is a schematic diagram of a prompt word template.

[0192] (2) Dynamic SQL generation rules

[0193] Based on dynamic SQL generation rules, the corresponding forced SQL output format is implemented to ensure automated parsing in subsequent validation stages: keywords are capitalized (SELECT / FROM / WHERE); multiple clauses are broken into separate lines (SELECT, FROM, WHERE, and GROUP BY each occupy a separate line). For example... Figure 8 The image shows an example of SQL generation.

[0194] (3) SQL output validation: After generating SQL, its legality needs to be verified using a validation function. The validation function is as follows:

[0195]

[0196] The meanings of each dimension are shown in Table 2 below:

[0197] Table 2

[0198]

[0199] Based on the validation failure type (syntax, field), different correction processes are automatically triggered, forming a closed loop of error location, prompt word adjustment, and model regeneration. For example... Figure 9 The diagram shown is a schematic of the closed-loop process of SQL verification.

[0200] The method for generating electricity data analysis code based on natural interaction provided in this application utilizes the Word2Vec-CRF model and prompt word engineering to automatically convert user natural language commands into executable SQL code. It accurately responds to the electricity analysis elements mentioned in the user's natural language commands, improves the efficiency of electricity data analysis, and enhances the timeliness of the knowledge base and the interpretability and maintainability of the generated SQL.

[0201] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to 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 embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps. It is understood that the steps in different embodiments can be freely combined as needed, and all non-contradictory solutions formed by such combinations are within the scope of protection of this application.

[0202] Based on the same inventive concept, this application also provides a device for generating power data analysis code based on natural interaction, which implements the above-mentioned method for generating power data analysis code based on natural interaction. The solution provided by this device is similar to the solution described in the above method. Therefore, the specific limitations of one or more embodiments of the device for generating power data analysis code based on natural interaction provided below can be found in the limitations of the method for generating power data analysis code based on natural interaction described above, and will not be repeated here.

[0203] In one exemplary embodiment, such as Figure 10As shown, a code self-generation device 1000 for power data analysis based on natural interaction is provided, including: a word segmentation sequence acquisition module 1002, a semantic mapping module 1004, a role labeling module 1006, a logic tree generation module 1008, and a code generation module 1010, wherein:

[0204] The word segmentation sequence acquisition module 1002 is used to acquire natural language instructions for describing power data analysis and processing, and convert the natural language instructions into word segmentation sequences;

[0205] The semantic mapping module 1004 is used to perform semantic mapping from the power data knowledge base according to the word segmentation sequence to obtain a structured semantic mapping object corresponding to the natural language command;

[0206] The role labeling module 1006 is used to label each word in the word segmentation sequence with semantic role tags to obtain the labeling sequence corresponding to the word segmentation sequence.

[0207] The logic tree generation module 1008 is used to generate a logic tree based on each word segment, the attention weight of each word segment, and the semantic role label of each word segment in the annotation sequence.

[0208] The code generation module 1010 is used to generate executable query code based on the logic tree and structured semantic mapping object. The executable query code is used to perform power data analysis and processing.

[0209] In some embodiments, the word segmentation sequence obtaining module 1002 is further configured to split the natural language instruction into at least one semantic unit; filter the at least one semantic unit to obtain a target semantic unit; perform formatting processing on the target semantic unit to obtain a formatted semantic unit; and obtain the word segmentation sequence corresponding to the natural language instruction based on the formatted semantic unit.

[0210] In some embodiments, the semantic mapping module 1004 is further configured to determine a preset power data knowledge base, perform mixed retrieval of each word in the word segmentation sequence in the power data knowledge base according to at least two retrieval methods, obtain the retrieval results of each word in the word segmentation sequence, and perform field mapping in the power data knowledge base according to the retrieval results of each word to obtain a structured semantic mapping object corresponding to the natural language instruction.

[0211] In some embodiments, the role labeling module 1006 is further configured to perform vector mapping on each word in the word segmentation sequence using a pre-trained vector mapping model to obtain a word vector sequence, wherein the word vector sequence includes the word vector of each word; and to perform semantic role labeling on the word vector of each word in the word vector sequence using a conditional random field model to obtain a labeling sequence corresponding to the word segmentation sequence.

[0212] In some embodiments, the logic tree generation module 1008 is further configured to determine the attention weight of each word based on the semantic role label of each word in each word segmentation and annotation sequence; map each word to a logic node according to the attention weight and semantic role label of each word; generate an initial logic tree according to the attention weight and logic node of each word; and inject verification rules into each logic node in the initial logic tree to obtain the logic tree.

[0213] In some embodiments, the logic tree generation module 1008 is further configured to map the semantic role labels of each word in the labeled sequence to embedding vectors respectively; fuse the word vectors and embedding vectors of each word to obtain the fusion vector of each word; and determine the attention weight of each word based on the attention mechanism and the fusion vector of each word.

[0214] In some embodiments, the code generation module 1010 is further configured to obtain auxiliary resources from the power data knowledge base based on the structured semantic mapping object; generate candidate query codes based on the logic tree, auxiliary resources, and prompt word templates; and obtain executable query codes based on the candidate query codes when the candidate query codes pass the legality verification.

[0215] The modules in the aforementioned self-generating device for power data analysis based on natural interaction can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.

[0216] In one exemplary embodiment, a computer device is provided, which may be a server or a terminal, and its internal structure diagram may be as follows. Figure 11As shown, the computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores various data involved in the self-generation method of power data analysis code based on natural interaction. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communication with external terminals via a network connection. When the computer program is executed by the processor, it implements a self-generation method of power data analysis code based on natural interaction.

[0217] Those skilled in the art will understand that Figure 11 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0218] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.

[0219] In one embodiment, a computer-readable storage medium is provided storing a computer program that, when executed by a processor, implements the steps in the above method embodiments.

[0220] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.

[0221] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.

[0222] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.

[0223] The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as the combination of these technical features does not contradict each other, it should be considered within the scope of this application. The above embodiments only illustrate several implementation methods of this application, and their descriptions are relatively specific and detailed, but they should not be construed as limiting the scope of this application. It should be noted that for those skilled in the art, several modifications and improvements can be made without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.

Claims

1. A method for self-generating electricity data analysis code based on natural interaction, characterized in that, The method includes: Obtain natural language instructions for describing power data analysis and processing, and convert the natural language instructions into word segmentation sequences; Based on the word segmentation sequence, semantic mapping is performed from the power data knowledge base to obtain a structured semantic mapping object corresponding to the natural language instruction; Semantic role labels are applied to each word segment in the word segmentation sequence to obtain the labeled sequence corresponding to the word segmentation sequence. A logic tree is generated based on each of the word segments, the attention weight of each word segment, and the semantic role label of each word segment in the annotation sequence. Based on the logic tree and the structured semantic mapping object, executable query code is generated, which is used to perform the power data analysis and processing.

2. The method according to claim 1, characterized in that, The process of converting the natural language instruction into a word segmentation sequence includes: The natural language instruction is broken down into at least one semantic unit; Filter the at least one semantic unit to obtain the target semantic unit; The target semantic unit is formatted to obtain a formatted semantic unit; The word segmentation sequence corresponding to the natural language instruction is obtained based on the formatted semantic unit.

3. The method according to claim 1, characterized in that, The step of performing semantic mapping from the power data knowledge base based on the word segmentation sequence to obtain a structured semantic mapping object corresponding to the natural language instruction includes: A preset power data knowledge base is determined, and a mixed search is performed on each word in the word segmentation sequence in the power data knowledge base according to at least two search methods to obtain the search results for each word in the word segmentation sequence. Based on the retrieval results of each of the aforementioned word segments, field mapping is performed in the power data knowledge base to obtain a structured semantic mapping object corresponding to the natural language instruction.

4. The method according to claim 1, characterized in that, The step of semantic role labeling for each word in the word segmentation sequence to obtain the labeling sequence corresponding to the word segmentation sequence includes: By using a pre-trained vector mapping model, vector mapping is performed on each word in the word segmentation sequence to obtain a word vector sequence, which includes the word vector of each word. Using a conditional random field model, semantic role labels are applied to the word vectors of each segmented word in the word vector sequence to obtain the labeled sequence corresponding to the word segmentation sequence.

5. The method according to claim 1, characterized in that, The step of generating a logic tree based on each of the word segments, the attention weight of each word segment, and the semantic role label of each word segment in the annotation sequence includes: Based on the semantic role labels of each of the aforementioned word segments and the labeled sequence, the attention weight of each of the aforementioned word segments is determined. Based on the attention weight and semantic role label of each of the aforementioned word segments, each word segment is mapped to a logical node; An initial logic tree is generated based on the attention weights and logical nodes of each segmentation word. Verification rules are injected into each logical node in the initial logical tree to obtain the logical tree.

6. The method according to claim 5, characterized in that, The step of determining the attention weight of each word segment based on its semantic role label in the labeled sequence includes: Map the semantic role labels of each word segment in the labeled sequence into embedding vectors; The word vectors and embedding vectors of each of the word segments are fused to obtain the fused vector of each of the word segments. Based on the attention mechanism, the attention weight of each segment is determined according to the fusion vector of each segment.

7. The method according to any one of claims 1 to 6, characterized in that, The step of generating executable query code based on the logic tree and the structured semantic mapping object includes: Based on the structured semantic mapping object, auxiliary resources are obtained from the power data knowledge base; Candidate query codes are generated based on the logic tree, the auxiliary resources, and the prompt word template; Once the candidate query code passes the validity check, an executable query code is obtained based on the candidate query code.

8. A device for self-generating power data analysis code based on natural interaction, characterized in that, The device includes: The word segmentation sequence acquisition module is used to acquire natural language instructions for describing power data analysis and processing, and to convert the natural language instructions into word segmentation sequences; The semantic mapping module is used to perform semantic mapping from the power data knowledge base according to the word segmentation sequence to obtain a structured semantic mapping object corresponding to the natural language instruction; The role labeling module is used to label each word in the word segmentation sequence with semantic role tags to obtain the labeling sequence corresponding to the word segmentation sequence. The logic tree generation module is used to generate a logic tree based on each of the word segments, the attention weight of each word segment, and the semantic role label of each word segment in the annotation sequence. The code generation module is used to generate executable query code based on the logic tree and the structured semantic mapping object. The executable query code is used to perform the power data analysis and processing.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 7.

10. A computer-readable 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 according to any one of claims 1 to 7.