Large language model-based power time series anomaly detection method and system
Through the power time series anomaly detection method based on the large language model, the scaling quantization processing and sliding window segmentation technology are used to solve the problems of high cost and complexity in the existing technology, and efficient power time series anomaly detection is achieved.
Patent Information
- Application Number
- CN202411779416.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-03-28
AI Technical Summary
The existing power time series anomaly detection methods require complex model design and training processes, which are costly and difficult to effectively reduce development complexity.
The power time series anomaly detection method based on the large language model is adopted, and the power time series data is processed by acquiring and scaling quantization, and the sliding window segmentation and preset prompt templates are used to perform abnormal detection with the large language model.
This method can effectively reduce development costs and system complexity, while ensuring the effectiveness of the model, providing an effective solution for the power time series anomaly detection task under the condition of sample scarcity.
Smart Images

Figure CN119720021A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of time series anomaly detection, and in particular relates to a method and system for detecting anomaly in power time series based on a large language model. Background Art
[0002] The power time series is the user power consumption data and various electrical equipment signal data arranged in chronological order. The distribution loss in the operation of the power grid has received more and more attention. The distribution loss can be divided into two categories: technical loss and non-technical loss. Among them, the most serious non-technical loss is the user's stealing of electricity, which has caused serious property losses to the power grid. At the same time, if various power equipment failures are not handled in time, they will cause social problems such as large-scale power outages, which will have a serious impact on the production and life of residents and enterprises. Therefore, how to quickly and effectively find abnormal power consumption behaviors from the historical power consumption data of a large number of users and provide them to decision makers for review can effectively reduce non-technical losses in the power distribution process and promote the development of the power grid. It has important research significance. Similarly, timely detection of abnormal information in the power equipment signal data can quickly handle equipment failures and reduce the impact caused by equipment failures.
[0003] In recent years, large language models have developed rapidly, and they have shown excellent capabilities in the field of natural language tasks, including reading comprehension, conversation, and translation. In addition, in addition to code generation and text output tasks, large language models also show great prospects in generating images and videos based on natural language descriptions. More and more researchers are trying to apply large language models to new tasks and data patterns, which has promoted the development of large language models and discovered their value in different task areas. Pre-trained large language models are trained on a large number of public data sets, so that they should have a wider range of uses in essence. Using the prompt engineering method, plug-and-play, and applying them to power time series anomaly detection tasks can avoid the huge training overhead required for specially designed deep learning models, effectively reduce development costs, and ensure the effectiveness of the model. However, existing anomaly detection methods require complex model design and training processes before deployment, which is costly. Summary of the invention
[0004] In order to solve the deficiencies in the prior art, the present invention provides a method and system for detecting anomalies in power time series based on a large language model to solve the technical problem of enabling the large language model to understand input data information and correctly perform anomaly detection tasks.
[0005] In order to solve the above technical problems, the present invention adopts the following technical solutions.
[0006] The present invention first discloses a method for detecting anomalies in power time series based on a large language model, the method comprising the following steps:
[0007] Get the input power time series training data X = (x1, x2, ..., x N ), where x n The power consumption data at the time step of n is used to scale and quantize the time series data using the scaling mapping function and the quantization mapping function to obtain the labeled power time series data.
[0008] The tokenized power time series data is segmented using a sliding window with predefined window length and step size features Get Collection
[0009] The power time series data set obtained by segmenting based on the preset prompt template and the sliding window A large language model is used to detect anomalies and output the detection results.
[0010] The present invention further includes the following preferred embodiments:
[0011] The scaling mapping function is used to subtract the minimum value from the power time series training data to obtain a new time series: st =x t -min(x1,x2,...,x N ).
[0012] The quantization mapping function is used to round each value to a predefined number of decimal places and then scale it to an integer format.
[0013] After the scaling and quantization processing, the method further includes:
[0014] According to the type of large language model, the power time series data is tokenized in a corresponding manner.
[0015] When the large language model is LLAMA-2, space segmentation is used to tokenize the data, and the number sequence is divided into single numbers by adding spaces.
[0016] The sliding window with predefined window length and step size features is used to segment the tokenized power time series data. Get Collection Further including:
[0017] Set the sliding window length w and step size t;
[0018] According to the sliding window length, the first time series segment is divided into X1 = (x1, x2, ..., x w );
[0019] According to the step length t, the second time series segment is X2=(x w+1 ,x w=2 ,...,x 2w );
[0020] Continue with the above steps and convert the time series X q Split into sets
[0021] The power time series data set obtained by segmenting based on the preset prompt template and the sliding window Use a large language model to detect anomalies and output the detection results, further including:
[0022] The set obtained by segmenting the preset prompt template with the sliding window Merge into Where k is the total length of the input data in each round. Loop input into the large language model and output the result text u k+1 .
[0023] The present invention also discloses a large language model-based power time series anomaly detection system using the aforementioned large language model-based power time series anomaly detection method, comprising:
[0024] Scaling quantization module, used to obtain the input power time series training data X = (x1, x2, ..., x N ), where x n The power consumption data at the time step of n is used to scale and quantize the time series data using the scaling mapping function and the quantization mapping function to obtain the labeled power time series data.
[0025]
[0026] A sliding window segmentation module for segmenting the tokenized power time series data using a sliding window with predefined window length and step size characteristics Get Collection
[0027] A large model prediction module is used to obtain a power time series data set based on a preset prompt template and the sliding window segmentation. A large language model is used to detect anomalies and output the detection results.
[0028] Accordingly, the present application also discloses a terminal, including a processor and a storage medium;
[0029] The storage medium is used to store instructions;
[0030] The processor is used to operate according to the instructions to execute the steps of the aforementioned power time series anomaly detection method based on a large language model.
[0031] Accordingly, the present application also discloses a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the aforementioned method for detecting anomalies in power time series based on a large language model.
[0032] The beneficial effect of the present invention is that, compared with the prior art, the present invention provides a method and system for detecting anomalies in electric power time series based on a large language model, utilizes a public large language model to perform time series anomaly detection in the electric power field, combines a pre-designed prompt template with an electric power time series data set, and provides an effective solution for the task of detecting anomalies in electric power time series under conditions of sample scarcity, thereby avoiding the complex training process of traditional deep learning algorithms and reducing training costs and the complexity of system development. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 This is the architecture of the large language model based on prompt engineering of the present invention. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical solution and advantages of the present invention more clear, the technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0035] The embodiments described in this application are only some embodiments of the present invention, not all embodiments. Based on the spirit of the present invention, other embodiments obtained by ordinary technicians in this field without creative work are all within the protection scope of the present invention.
[0036] In view of the shortcomings of the prior art, the present invention proposes a method and system for detecting anomalies in power time series based on a large language model. Figure 1 As shown, the power time series anomaly detection method based on a large language model disclosed in the present invention includes the following steps:
[0037] Step 1: Get the input power time series training data X = (x1, x2, ..., x N ), where x n The power consumption data at the time step of n is used to scale and quantize the time series data using the scaling mapping function and the quantization mapping function to obtain the labeled power time series data.
[0038] Time series data includes values of different sizes, which may include positive and negative values, covering a large range of values. In order to speed up the operation efficiency and reduce the impact of too large or too small values on the large language model, the scaling mapping function is used to subtract the minimum value from the power time series training data to obtain a new time series. The scaled time series eliminates negative numbers, that is, the mapping function ε is introduced: R → R ≥0 ;
[0039] Unlike the limited vocabulary used for large language model training, time series data contains decimals, negative numbers and other data of different sizes. Even after scaling, its vocabulary is still infinite, which is difficult for large language models to process directly. Therefore, it is necessary to quantize the sequence data. The quantization mapping function is used to round each value to a predefined number of decimal places and then scale it to an integer format to avoid wasting marks on decimal points. Therefore, the time series becomes The quantization example is as follows:
[0040] 0.3565,0.0031,0.2742,0.514→"357,3,274,514"
[0041] Different tokenization schemes have different data processing methods. Several different open source large language models, such as LLAMA-2, use space segmentation to tokenize data, splitting the number sequence into individual numbers by adding spaces. However, different large language models have different acceptance levels of this method of marking. For example, llama3-8b-instruct cannot accurately process data after space segmentation. Therefore, the present invention uses different tokenization schemes for different large language models. Example of tokenizing data by space segmentation:
[0042] "357,3,274,514"→"3 5 7,3,2 7 4,5 14"
[0043] Step 2: Segment the tokenized power time series data using a sliding window with predefined window length and step size features Get Collection
[0044] The sliding window segments the power time series data, and the specific contents include:
[0045] Step 2.1: Set the sliding window length w and step length t;
[0046] Step 2.2: According to the sliding window length, divide the first time series segment into X1 = (x1, x2, ..., x w );
[0047] Step 2.3: According to the step length t, the second time series segment is obtained as X2 = (x w+1 ,x w=2 ,...,x 2w );
[0048] Step 2.4: Continue with the above steps and convert the time series X q Split into sets
[0049] Step 3: The power time series data set obtained by segmenting based on the preset prompt template and the sliding window A large language model is used to detect anomalies and output the detection results.
[0050] Specifically, the set obtained by segmenting the preset prompt template with the sliding window Merge into Where k is the total length of the input data in each round, that is, the sum of the input text length and the sliding window length is k. Loop input into the large language model and output the result text u k+1 .
[0051] The beneficial effect of the present invention is that, compared with the prior art, the present invention provides a method and system for detecting anomalies in electric power time series based on a large language model, utilizes a public large language model to perform time series anomaly detection in the electric power field, combines a pre-designed prompt template with an electric power time series data set, and provides an effective solution for the task of detecting anomalies in electric power time series under conditions of sample scarcity, thereby avoiding the complex training process of traditional deep learning algorithms and reducing training costs and the complexity of system development.
[0052] The present invention may be a system, a method and / or a computer program product. The present invention also discloses a large language model-based power time series anomaly detection system based on the aforementioned large language model-based power time series anomaly detection method, comprising:
[0053] Scaling quantization module, used to obtain the input power time series training data X = (x1, x2, ..., x N ), where x n The power consumption data at the time step of n is used to scale and quantize the time series data using the scaling mapping function and the quantization mapping function to obtain the labeled power time series data.
[0054]
[0055] A sliding window segmentation module for segmenting the tokenized power time series data using a sliding window with predefined window length and step size characteristics Get Collection
[0056] A large model prediction module is used to use a preset prompt template and the set obtained by segmenting the sliding window. Merge into Where k is the total length of the input data in each round. Loop input into the large language model and output the result text u k+1 .
[0057] Based on the spirit of the present invention, those skilled in the art can easily think that a computer program product can be obtained based on the aforementioned large language model-based power time series anomaly detection method. The computer program product may include a computer-readable storage medium, which carries computer-readable program instructions for enabling a processor to implement various aspects of the present disclosure. That is, the present application also includes a terminal, including a processor and a storage medium; the storage medium is used to store instructions; the processor is used to operate according to the instructions to execute the steps of the aforementioned large language model-based power time series anomaly detection method.
[0058] Computer readable storage medium can be a tangible device that can keep and store the instructions used by the instruction execution device. Computer readable storage medium can be, for example, - but not limited to - electrical storage device, magnetic storage device, optical storage device, electromagnetic storage device, semiconductor storage device or any suitable combination of the above. More specific examples (non-exhaustive list) of computer readable storage medium include: portable computer disk, hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disk read-only memory (CD-ROM), digital versatile disk (DVD), memory stick, floppy disk, mechanical encoding device, for example, punch card or groove protrusion structure with instructions stored thereon and any suitable combination of the above. Computer readable storage medium used here is not interpreted as instantaneous signal itself, such as radio wave or other free propagating electromagnetic wave, electromagnetic wave propagated by waveguide or other transmission medium (for example, light pulse by optical fiber cable) or electrical signal transmitted by wire.
[0059] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0060] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages-such as Smalltalk, C++, etc., and conventional procedural programming languages-such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network-including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA) may be personalized by utilizing the state information of a computer-readable program instruction, and the electronic circuit may execute a computer-readable program instruction, thereby realizing various aspects of the present disclosure.
[0061] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that the specific implementation methods of the present invention can still be modified or replaced by equivalents, and any modifications or equivalent replacements that do not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A method for detecting anomalies in power time series based on a large language model, characterized in that: The following steps are involved: Get the input power time series training data X = (x1, x2, ..., x N ), where x n The power consumption data at the time step of n is used to scale and quantize the time series data using the scaling mapping function and the quantization mapping function to obtain the labeled power time series data. The tokenized power time series data is segmented using a sliding window with predefined window length and step size features Get the power time series data set The power time series data set obtained by segmenting based on the preset prompt template and the sliding window A large language model is used to detect anomalies and output the detection results.
2. The power time series anomaly detection method based on a large language model according to claim 1 is characterized in that: The scaling mapping function is used to subtract the minimum value from the power time series training data to obtain a new time series:
3. The power time series anomaly detection method based on a large language model according to claim 2 is characterized in that: The quantization mapping function is used to round each value to a predefined number of decimal places and then scale it to an integer format.
4. The method for detecting anomalies in power time series based on a large language model according to claim 3 is characterized in that: After the scaling and quantization processing, the method further includes: According to the type of large language model, the power time series data is tokenized in a corresponding manner.
5. The method for detecting anomalies in power time series based on a large language model according to claim 4, characterized in that: When the large language model is LLAMA-2, space segmentation is used to tokenize the data, and the number sequence is divided into single numbers by adding spaces.
6. The power time series anomaly detection system based on a large language model according to claim 5 is characterized in that: The sliding window with predefined window length and step size features is used to segment the tokenized power time series data. Get Collection Further including: Set the sliding window length w and step size t; According to the sliding window length, the first time series segment is divided into X1 = (x1, x2, ..., x w ); According to the step length t, the second time series segment is X2=(x w+1 ,x w=2 ,...,x 2w ); Continue with the above steps and convert the time series X q Split into sets 7. The power time series anomaly detection system based on a large language model according to claim 6 is characterized in that: The power time series data set obtained by segmenting based on the preset prompt template and the sliding window Use a large language model to detect anomalies and output the detection results, further including: The set obtained by segmenting the preset prompt template with the sliding window Merge into Where k is the total length of the input data in each round. Loop input into the large language model and output the result text u k+1 .
8. A power time series anomaly detection system based on a large language model, characterized in that: include: Scaling quantization module, used to obtain the input power time series training data X = (x1, x2, ..., x N ), where x n The power consumption data at the time step of n is used to scale and quantize the time series data using the scaling mapping function and the quantization mapping function to obtain the labeled power time series data. A sliding window segmentation module for segmenting the tokenized power time series data using a sliding window with predefined window length and step size characteristics Get Collection A large model prediction module is used to obtain a power time series data set based on a preset prompt template and the sliding window segmentation. A large language model is used to detect anomalies and output the detection results.
9. A terminal comprising a processor and a storage medium; characterized in that: The storage medium is used to store instructions; The processor is used to operate according to the instructions to execute the steps of the power time series anomaly detection method based on a large language model according to any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the power time series anomaly detection method based on a large language model described in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Power system fault prediction method based on large language model
CN121936551A