Power grid emergency work special report generation method and system
By automatically generating documents and reading configuration files, combining masking strategies and unsupervised keyword extraction methods with comparison learning optimization, the problem of mismatched keyword extraction lengths, limited usage scenario scope, and cumbersome data content processing in the power grid emergency report generation tool is solved, and efficient and accurate report generation is achieved.
Patent Information
- Application Number
- CN202411504221.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2025-03-18
AI Technical Summary
The existing power grid emergency report generation tool has problems such as mismatch in keyword extraction lengths, limited use scenario scope, and cumbersome data content processing.
The method of automatically generating documents and reading configuration files is adopted, keyword extraction is performed through masking strategies and unsupervised methods of comparison learning optimization, the text format of the inserted content is adjusted, the content insertion points are located, and the content is packaged into an executable file.
It realizes automatic generation of Word reports without manual operations, which improves efficiency, avoids manual copy-paste errors, ensures the accuracy and consistency of reports, and flexibly adjusts the content and format of reports.
Smart Images

Figure CN119646120A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a method and system for generating a power grid emergency work special report. Background Art
[0002] In the field of automatic document and report generation, a variety of technologies and tools have been widely used, such as Python+pywin32. Special report generation involves multiple business domains such as production, marketing, scheduling, and operation monitoring. Its main function is to produce emergency special reports and obtain data reports captured by each RPA. The collected data is read by Python at regular intervals, and emergency special reports are output according to preset templates, providing a basis for emergency command decisions and improving emergency response efficiency. No human participation is required throughout the process.
[0003] The customized automatic power grid emergency work special report generation tool has the following particularities: 1. It can only be opened using WPS, and the customized tool is fixed to the WPS tool writing; 2. Data collection and comparison are cumbersome, consuming a lot of manpower and material resources, and the written content format is also customized to meet the content and format requirements of the document writing; 3. The similarity calculation at the phrase-text level is prone to cause the problem of mismatch in keyword extraction length. Summary of the invention
[0004] In view of the above-mentioned problems, the present invention is proposed.
[0005] Therefore, the technical problem solved by the present invention is: how to solve the technical problems of mismatched keyword extraction length, limited scope of usage scenarios, and cumbersome data content processing.
[0006] To solve the above technical problems, the present invention provides the following technical solutions: automatically generate documents and read and apply configuration files; extract keywords through an unsupervised method optimized by mask strategy and contrastive learning; adjust the text format of the inserted content according to the settings in the configuration file, locate the content insertion point, and package it into an executable file.
[0007] As a preferred solution of the method for generating a special report on power grid emergency work described in the present invention, the key phrase extraction includes absolute sampling and relative sampling, wherein the absolute sampling includes extracting a keyword set from each article, masking the original article with these keywords as positive examples, and then randomly extracting the remaining non-keyword candidate words as negative examples;
[0008] The relative sampling includes extracting a keyword set for each article, randomly extracting two keywords from the keyword set, calculating ranking scores, wherein the top-ranked one is used as a positive example and the other is used as a negative example, thereby constructing training data.
[0009] As a preferred solution of the method for generating a special report on power grid emergency work described in the present invention, the extraction of the keyword set includes comparing the document after the candidate word is masked with the original document for similarity. If the similarity score is high, it means that the masked word is not important and is a non-keyword. The loss function is expressed as:
[0010] L CL =max(d(e a ,e n )-d(e a ,e p )+m,0)+λ*L LML
[0011] Among them, d(e a ,e n ) represents the distance between the query document and the negative sample, d(e a ,e p ) represents the distance between the query document and the positive sample, m represents the boundary parameter, which controls the boundary of the triple loss, and L LML represents the mask model loss, and λ represents the loss given to L LML The weight of the assignment;
[0012] The ranking score calculation follows the formula:
[0013]
[0014] Among them, e m Represents the vector of the generated mask document after BERT embedding, e o Represents the vector of the original document after BERT embedding, i represents the i-th component of the vector, and n represents the vector dimension.
[0015] As a preferred solution of the method for generating a special report on power grid emergency work described in the present invention, the FocalLoss loss function is used to impose a greater penalty on difficult-to-classify samples for long-tail words or rare words, and the formula is expressed as follows:
[0016] L F =-(1-P(y|x)) γ log P(y|x)
[0017] Among them, P(y|x) represents the probability predicted by the model, and γ is an adjustment parameter used to control the weighting degree of difficult and easy samples.
[0018] As a preferred solution of the method for generating a special report on power grid emergency work described in the present invention, a self-supervised contrast loss is adopted to guide model learning by constructing positive and negative sample pairs, and the formula is expressed as follows:
[0019]
[0020] Among them, sim(e i ,e j ) means e i , e j , τ represents the temperature parameter used to adjust the softening degree, N represents the total number of samples in the batch, and exp represents the exponential function with the natural number e as the base.
[0021] As a preferred solution of the method for generating a special report on power grid emergency work described in the present invention, the final loss function obtained by combining the above formula is expressed as:
[0022] L total =λ cl *L CL +λ f *L F +λ cst *L contrast
[0023] Among them, L total represents the total loss function, λ cl , f , cst They represent the weights of controlling the triplet loss function, focal loss, and self-supervised contrast loss, respectively.
[0024] As a preferred solution of the method for generating a special report on power grid emergency work described in the present invention, the positioning content insertion point includes pre-setting a bookmark or placeholder in a Word template, locating the insertion position through the bookmark, reading the generated content in the configuration file in the specified Excel, cleaning and processing the content, organizing it into a specified format, and writing it to the position of the specified placeholder through positioning in the Word document.
[0025] In the second aspect, another object of the present invention is to provide a power grid emergency work special report generation system, including: a document generation module, a keyword extraction module and an adjustment and packaging module; the document generation module is used to automatically generate documents and read and apply configuration files; the keyword extraction module is used to extract keywords through an unsupervised method optimized by masking strategy and contrast learning; the adjustment and packaging module is used to adjust the text format of the inserted content, locate the content insertion point, and package it into an executable file.
[0026] In a third aspect, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method for generating a power grid emergency work special report as described above when executing the computer program.
[0027] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method for generating a power grid emergency work special report as described above are implemented.
[0028] Beneficial effects of the present invention: The power grid emergency work special report generation method and system provided by the present invention realize the automatic generation of Word reports through Python scripts and pywin32 libraries, without manual operation, greatly improving efficiency. The use of locators ensures that the content is inserted into the specified location, avoiding errors caused by manual copy and paste, and ensuring the accuracy and consistency of the report content. The format settings (such as font, font size, etc.) are defined through configuration files and automatically applied to the generated reports to ensure the uniformity of the document format. Using configuration files to manage content and format, the report content and style can be easily adjusted as needed without modifying the main code. A BERT masking strategy and an unsupervised key phrase extraction method optimized by contrastive learning are used. The original phrase-text level similarity calculation is converted to the text-text level through masking, thereby solving the problem of length mismatch.
[0029] Automatic report generation saves a lot of time and human resources, allowing employees to devote more time to higher-value work. Automated processes reduce errors caused by manual operations and improve the accuracy and reliability of reports. The format and content of reports are controlled through configuration files to ensure that each generated report has a consistent style and structure. Python scripts are packaged into executable files (exe), and users only need to run the file to automatically generate reports without programming knowledge. The report content and format can be flexibly adjusted through configuration files without modifying the code to adapt to different reporting needs. The use of open source Python language and libraries reduces the cost of technical implementation and eliminates the need to purchase expensive software tools. The modular code design facilitates maintenance and expansion, and new functions can be added or existing functions can be optimized according to business needs. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0031] Figure 1 An overall flow chart of a method for generating a power grid emergency work special report provided by an embodiment of the present invention;
[0032] Figure 2 A file configuration example diagram of a method for generating a network emergency work report provided by an embodiment of the present invention;
[0033] Figure 3 A special report generation example of a network emergency work special report generation method provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0034] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the drawings of the specification. Obviously, the described embodiments are part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary persons in the art without creative work should fall within the scope of protection of the present invention.
[0035] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0036] Example 1
[0037] Reference Figure 1 , as an embodiment of the present invention, provides a method for generating a power grid emergency work special report, comprising:
[0038] S1: Automatically generate documents and read and apply configuration files;
[0039] Furthermore, the pywin32 library is used to interact with the Word application. A word application object is created through win32, and the word file path is opened to perform word file operations; configuration files are read and applied in the code. An excel application object is created through win32, and the excel file path is opened to perform sheet reading operations corresponding to the excel file.
[0040] S2: Unsupervised keyword extraction via masking strategy and contrastive learning optimization;
[0041] Furthermore, a BERT masking strategy and contrastive learning optimized unsupervised keyword extraction method were used. The original phrase-text level similarity calculation was converted to the text-text level through masking, thus solving the length mismatch problem.
[0042] It should be noted that key phrase extraction includes absolute sampling and relative sampling. Absolute sampling includes extracting a set of keywords from each article, using these keywords as positive examples to mask the original article, and then randomly extracting the remaining non-keyword candidate words as negative examples.
[0043] Relative sampling involves extracting a keyword set for each article, randomly extracting two keywords from the keyword set, and calculating the ranking scores, with the top-ranked one being used as a positive example and the other as a negative example, thereby constructing training data.
[0044] Furthermore, the extraction of keyword sets includes a similarity comparison between the document after the candidate word is masked and the original document. If the similarity score is high, it means that the masked word is not important and is a non-keyword. The loss function is expressed as:
[0045] L CL =max(d(e a ,e n )-d(e a ,e p )+m,0)+λ*L LML
[0046] Among them, d(e a ,e n ) represents the distance between the query document and the negative sample, d(e a ,e p ) represents the distance between the query document and the positive sample, m represents the boundary parameter, which controls the boundary of the triple loss, and L LML represents the mask model loss, and λ represents the loss given to L LML The weights assigned mainly include: 1) triplet loss to force the BERT model to learn how to distinguish key phrases from non-key phrases, while setting the margin m; 2) MLM (Masked Language Model) loss to ensure that KPEBERT does not forget previous language knowledge;
[0047] The ranking score calculation follows the formula:
[0048]
[0049] Among them, e m Represents the vector of the generated mask document after BERT embedding, e o Represents the vector of the original document after BERT embedding, i represents the i-th component of the vector, and n represents the vector dimension.
[0050] It should be noted that the FocalLoss loss function is used to impose a greater penalty on difficult-to-classify samples for long-tail words or rare words. The formula is expressed as:
[0051] L F =-(1-P(y|x)) γ log P(y|x)
[0052] Among them, P(y|x) represents the probability predicted by the model, and γ is an adjustment parameter used to control the weighting degree of difficult and easy samples.
[0053] Furthermore, a self-supervised contrast loss is used to guide model learning by constructing positive and negative sample pairs. The formula is expressed as:
[0054]
[0055] Among them, sim(e i ,e j ) means e i , e j , τ represents the temperature parameter used to adjust the softening degree, N represents the total number of samples in the batch, and exp represents the exponential function with the natural number e as the base.
[0056] Combining the above formula, the final loss function is expressed as:
[0057] L total =λ cl *L CL +λ f *L F +λ cst *L contrast
[0058] Among them, L total represents the total loss function, λ cl , f , cst They represent the weights of controlling the triplet loss function, focal loss, and self-supervised contrast loss, respectively.
[0059] S3: Adjust the text format of the inserted content according to the settings in the configuration file, locate the content insertion point, and package it into an executable file.
[0060] Furthermore, use the interface provided by the pywin32 library to set the format of paragraphs and text in the document. After reading the configuration file, set the word format according to the read format through the interface function provided by pywin32. Pre-set bookmarks or placeholders in the Word template and locate the insertion position through bookmarks. After reading the generated content in the configuration file in the specified excel, clean and process the content. Arrange it into the specified format and write it to the specified placeholder position through positioning in the word document. Use the PyInstaller tool to package the script into an exe file.
[0061] Furthermore, add exception handling mechanisms (such as try-except blocks) to the code, record error logs, and provide friendly error prompts. Test the compatibility of the program in different environments to ensure that it runs normally on mainstream Windows and Office versions. Keep the template document concise and readable, check and update the template regularly, and ensure that the bookmarks and formatting in the template are set correctly.
[0062] Example 2
[0063] An embodiment of the present invention provides a power grid emergency work special report generation system, comprising:
[0064] Document generation module, keyword extraction module and adjustment packaging module;
[0065] The document generation module is used to automatically generate documents and read and apply configuration files;
[0066] The keyword extraction module is used to extract keywords through an unsupervised method optimized by masking strategy and contrastive learning;
[0067] The adjustment and packaging module is used to adjust the text format of the inserted content, locate the content insertion point, and package it into an executable file.
[0068] Example 3
[0069] An embodiment of the present invention is different from the first two embodiments in that:
[0070] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0071] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in conjunction with such instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in conjunction with such instruction execution systems, devices or apparatuses.
[0072] More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk case (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be a paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, deciphering or, if necessary, processing in another suitable manner, and then stored in a computer memory.
[0073] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0074] Example 4
[0075] As an embodiment of the present invention, a practical application example of a method for generating a power grid emergency work special report is provided.
[0076] See also Figure 2 , configure the file path and word format, and enter the format that can be set in word according to the example to modify the format of the generated special report content. Configure word content: modify the content of the special report to modify the content of the special report generated by word. Figure 3This is a special report generation result. The Python programming language is used in the process, and the win32 dependency package pywin32 library is referenced to control Word and other Office applications to achieve automated operations. The installation method is pipinstallpywin32. The special report generation process:
[0077] Initialize the Word application: Use pywin32 to open the Word application. Create or open a document: Create a new Word document or open an existing template document. Preset bookmarks or placeholders in the Word document. With these locators, you can accurately insert content at specific locations. Insert headers and article content: Use Python code to find the location of headers and content through locators. Insert data to the corresponding location to ensure the accuracy of the content.
[0078] The library reads the parameters in the configuration file. The configuration file usually includes document format settings (such as font, font size, paragraph style, etc.) and content data. Through the configuration file, you can flexibly adjust the format and content of the generated report. According to the settings in the configuration file, adjust the text format when inserting content. Use the interface provided by pywin32 to set the font, font size, color, paragraph style, etc.
[0079] Use the PyInstaller tool to package the Python script into a standalone executable file (exe). The user only needs to run the exe file, and the program will automatically execute and generate a Word report. By double-clicking the exe file, the program will automatically start and run the Python code. The program reads the configuration file, initializes Word, inserts content and sets the format, and finally saves the generated report.
[0080] The whole process does not require user intervention and is fully automated.
[0081] 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 preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
Claims
1. A method for generating a power grid emergency work report, characterized in that: include: Automatically generate documentation and read and apply configuration files; Keyword extraction by unsupervised method optimized by masking strategy and contrastive learning; Adjust the text format of the inserted content according to the settings in the configuration file, locate the content insertion point, and package it into an executable file.
2. The method for generating a power grid emergency work report according to claim 1, characterized in that: The key phrase extraction includes absolute sampling and relative sampling. The absolute sampling includes extracting a set of keywords from each article, masking the original article with these keywords as positive examples, and then randomly extracting the remaining non-keyword candidate words as negative examples. The relative sampling includes extracting a keyword set for each article, randomly extracting two keywords from the keyword set, calculating ranking scores, wherein the top-ranked one is used as a positive example and the other is used as a negative example, thereby constructing training data.
3. The method for generating a power grid emergency work report according to claim 2, characterized in that: The extraction of the keyword set includes comparing the similarity between the document after the candidate word is masked and the original document. If the similarity score is high, it means that the masked word is not important and is a non-keyword. The loss function is expressed as: L CL =max(d(e a ,e n )-d(e a ,e p )+m,0)+λ*L LML Among them, d(e a ,e n ) represents the distance between the query document and the negative sample, d(e a ,e p ) represents the distance between the query document and the positive sample, m represents the boundary parameter, which controls the boundary of the triple loss, and L LML represents the mask model loss, and λ represents the loss given to L LML The weight of the assignment; The ranking score calculation follows the formula: Among them, e m Represents the vector of the generated mask document after BERT embedding, e o Represents the vector of the original document after BERT embedding, i represents the i-th component of the vector, and n represents the vector dimension.
4. The method for generating a power grid emergency work report according to claim 3, characterized in that: The FocalLoss loss function is used for long-tail words or rare words to impose a greater penalty on difficult-to-classify samples. The formula is expressed as: L F =-(1-P(y∣x)) γ log P(y∣x) Among them, P(y|x) represents the probability predicted by the model, and γ is an adjustment parameter used to control the weighting degree of difficult and easy samples.
5. The method for generating a power grid emergency work report according to claim 4, characterized in that: Self-supervised contrast loss is used to guide model learning by constructing positive and negative sample pairs. The formula is expressed as: Among them, sim(e i ,e j ) means e i , e j , τ represents the temperature parameter used to adjust the softening degree, N represents the total number of samples in the batch, and exp represents the exponential function with the natural number e as the base.
6. The method for generating a power grid emergency work report according to claim 5, characterized in that: Combining the above formula, the final loss function is expressed as: L total =λ cl *L CL +λ f *L F +λ cst *L contrast Among them, L total represents the total loss function, λ cl , f , cst They represent the weights of controlling the triplet loss function, focal loss, and self-supervised contrast loss, respectively.
7. A method for generating a power grid emergency work report according to claim 6, characterized in that: The positioning content insertion point includes pre-setting a bookmark or placeholder in the Word template, positioning the insertion position through the bookmark, reading the generated content in the configuration file in the specified Excel, cleaning and processing the content, organizing it into a specified format, and writing it to the position of the specified placeholder through positioning in the Word document.
8. A system using the method for generating a power grid emergency work report according to any one of claims 1 to 7, characterized in that: include: Document generation module, keyword extraction module and adjustment packaging module; The document generation module is used to automatically generate documents and read and apply configuration files; The keyword extraction module is used to extract keywords through an unsupervised method optimized by masking strategy and contrastive learning; The adjustment and packaging module is used to adjust the text format of the inserted content, locate the content insertion point, and package it into an executable file.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of generating a power grid emergency work report according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of generating a power grid emergency work report according to any one of claims 1 to 7 are implemented.