Model training method, template file generation method, equipment and medium

By conducting adversarial training on the generator model and discriminator model, the problem of insufficient flexibility of template files in the existing template generation technology is solved, and a diverse and highly adaptable template files are generated.

CN119398022APending Publication Date: 2025-02-07CHENGDU NEW HOPE FINANCIAL INFORMATION CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411443766.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-16
Publication Date
2025-02-07

AI Technical Summary

Technical Problem

Existing template generation technology relies on fixed template structure and content format, and lacks dynamic adaptability, resulting in poor flexibility in generating template files.

Method used

By adversarial training of the generator model and the discriminator model, a generator model that can generate diverse template files is obtained. The method includes inputting random noise and real template file features into the generator model, performing anti-loss calculations and model parameters updates, and improving the adaptability and quality of the generator model.

Benefits of technology

It realizes the diversity and flexibility of generating template files, can adapt to different types of document needs, and improves the adaptability and quality of template files.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119398022A_ABST
    Figure CN119398022A_ABST
Patent Text Reader

Abstract

The invention provides a model training method, a template file generation method, equipment and a medium, and the model training method comprises the steps: inputting random noise and real template file features into a generator model, and obtaining a generated template file generated by the generator model; inputting the real template file and the generated template file into a discriminator model to obtain a true and false discrimination result of the template file; calculating adversarial loss based on a template file authenticity discrimination result and a template authenticity label, and updating model parameters of the generator model and the discriminator model according to the adversarial loss; and repeatedly iterating the steps, and performing adversarial training on the generator model and the discriminator model to obtain the trained generator model and discriminator model. According to the scheme, on one hand, different types of document requirements can be met, so that the adaptability of the template file is improved; and on the other hand, through confrontation training between the generator model and the discriminator model, the quality of the template file generated by the generator model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a model training method, a template file generation method, a device and a medium. Background Art

[0002] With the rapid development of information technology, office automation has become an important means to improve work efficiency and reduce costs. Template file generation technology is a new document generation method developed based on traditional document processing and combined with artificial intelligence technology.

[0003] However, the template generation technology in the related art mainly relies on fixed template structure and content format, the generation process lacks dynamic adaptability, and the flexibility of generating template files is poor. Summary of the invention

[0004] The purpose of the embodiments of the present application is to provide a model training method, a template file generation method, a device and a medium to improve the flexibility of template file generation.

[0005] In a first aspect, an embodiment of the present application provides a model training method, the method comprising:

[0006] Inputting random noise and real template file features into a generator model to obtain a generated template file generated by the generator model; wherein the real template file features are extracted based on a real template file, the real template file has a template category label, and the template category label is used to guide the generator model to generate a template file of a corresponding category;

[0007] Input the real template file and the generated template file into the discriminator model to obtain the template file authenticity discrimination result; wherein the real template file and the generated template file both have template authenticity labels;

[0008] Based on the true and false discrimination result of the template file and the true and false label of the template, the adversarial loss is calculated, and the model parameters of the generator model and the discriminator model are updated according to the adversarial loss;

[0009] The above steps are iterated repeatedly to perform adversarial training on the generator model and the discriminator model to obtain the trained generator model and the discriminator model.

[0010] In the implementation process of the above scheme, the generator model and the discriminator model are adversarially trained to obtain a generator model that can be used to generate template files. The trained generator model is used to automatically generate diversified template files. On the one hand, it is helpful to adapt to different types of document requirements, thereby improving the adaptability of template files; on the other hand, the adversarial training between the generator model and the discriminator model is helpful to improve the quality of the template files generated by the generator model.

[0011] In an implementation of the first aspect, the method further includes: obtaining a real template file; extracting real template intermediate features from the real template file; wherein the real template intermediate features include at least one of real template text features, real template structural features and real template semantic features; based on the real template intermediate features, obtaining the real template file features.

[0012] In the implementation process of the above scheme, the real template file features may include at least one of the real template text features, real template structural features and real template semantic features. On the one hand, the real template file features may include at least one of the content information, structural information and semantic information of the real template file. Using the real template file features to train the generator model is conducive to improving the quality and diversity of the generated template files generated by the generator model; on the other hand, the information contained in the real template file features can be adaptively set for different application scenarios, so that the generator model can be applied to more application scenarios, which is conducive to improving the applicability of the generator model.

[0013] In an implementation of the first aspect, extracting the real template text features from the real template file includes: extracting template keywords from the real template file; subject-classifying the real template file to obtain template subject words; and concatenating the template keywords and the template subject words to obtain the real template text features.

[0014] In the implementation process of the above scheme, the real template file features are obtained by extracting template keywords and template subject words in the real template file, and the generator model is trained using the real template file features containing the real template file features. This helps the generator model to learn the theme and core content of the template file more accurately, thereby helping to improve the quality of the generated template file generated by the generator model.

[0015] In an implementation of the first aspect, the real template structural features are extracted from the real template file, including: performing paragraph recognition on the real template file to obtain the number of template paragraphs and the length of template paragraphs; performing title hierarchy analysis on the real template file to obtain template titles and their hierarchical structures; performing list item extraction on the real template file to obtain list items and their hierarchical structures; and concatenating the number of template paragraphs, the template paragraph length, the template title and its hierarchical structure, and the list items and their hierarchical structures to obtain the real template structural features.

[0016] In the process of implementing the above scheme, the real template structure features are obtained by integrating the number of paragraphs, paragraph length, template title and its hierarchical structure, and list items and their hierarchical structure of the real template file, so that the real template structure features contain rich template file structured information. The generator model is trained using the real template file features containing the real template structure features, which helps the generator model to learn the structured information of the template file more accurately, thereby helping to improve the quality of the generated template file generated by the generator model.

[0017] In an implementation of the first aspect, the real template semantic features are extracted from the real template file, including: converting the text in the real template file into a word vector; based on the word vector, extracting the semantic vector of each sentence in the real template file; aggregating the semantic vectors of all sentences to obtain the real template semantic features.

[0018] In the implementation process of the above solution, the template file is converted into high-dimensional semantic features to capture the semantic relationship between words and sentences in the template file, which helps the generator model to understand the template file context information more deeply, thereby generating a more logical and semantically coherent generated template file, which is conducive to improving the quality of the generated template file generated by the generator model.

[0019] In an implementation manner of the first aspect, calculating the adversarial loss and updating the model parameters of the generator model and the discriminator model according to the adversarial loss includes:

[0020] Calculating a first loss, and updating a model parameter of the discriminator model based on the first loss; wherein the first loss is used to characterize the ability of the discriminator model to distinguish between real data and generated data;

[0021] A second loss is calculated, and model parameters of the generator model are updated based on the second loss; wherein the second loss is used to characterize the ability of the generator model to generate real data.

[0022] In the implementation process of the above scheme, the first loss and the second loss are used to update the model parameters of the discriminator model and the generator model respectively, which is conducive to improving the training effect of the generative adversarial network, thereby improving the quality of the generated template file generated by the generator model.

[0023] In a second aspect, an embodiment of the present application provides a template file generation method, the method comprising: obtaining requirement information of a template file to be generated; aggregating the requirement information into requirement features; inputting the requirement features into a generator model to obtain a first template file generated by the generator model; wherein the generator model is a trained generator model obtained using the first aspect or any possible implementation method of the first aspect.

[0024] In an implementation of the second aspect, the method further includes:

[0025] The first template file generated by the generator model is input into the discriminator model to obtain a file authenticity discrimination result of the discriminator model; wherein the discriminator model is a trained discriminator model obtained by using the first aspect or any possible implementation method of the first aspect; based on the file authenticity discrimination result, a second template file is obtained; wherein the second template file is the first template file whose file authenticity discrimination result is true.

[0026] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a memory, and a communication bus, wherein the processor and the memory communicate with each other through the communication bus; the memory stores computer program instructions that can be executed by the processor, and when the computer program instructions are read and run by the processor, the method provided by the first aspect or any possible implementation of the first aspect or the second aspect or any possible implementation of the second aspect is executed.

[0027] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which computer program instructions are stored. When the computer program instructions are read and executed by a processor, the method provided by the first aspect or any possible implementation of the first aspect or the second aspect or any possible implementation of the second aspect is executed.

[0028] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the embodiments of the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0030] Figure 1 A flowchart of a model training method provided in an embodiment of the present application;

[0031] Figure 2 A schematic diagram of a flow chart of a template file generation method provided in an embodiment of the present application;

[0032] Figure 3 A schematic diagram of the structure of a model training device provided in an embodiment of the present application;

[0033] Figure 4 A schematic diagram of the structure of a template file generating device provided in an embodiment of the present application;

[0034] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0035] The following will describe the technical solutions in the embodiments of the present application in conjunction with the accompanying drawings in the embodiments of the present application. The following embodiments are only used to more clearly illustrate the technical solutions of the present application, and are therefore only used as examples, and cannot be used to limit the scope of protection of the present application.

[0036] The template generation technology in the related art parses the existing template file to obtain the fixed structure and content format of the template file, and then generates a new template file based on the fixed structure and content format. The generated new template file is limited by the fixed template structure and content format, and cannot dynamically adjust the generation strategy when the document format or content changes, which results in the applicability of the template being limited in a diverse and changing environment, and the flexibility of the template file is poor.

[0037] Based on this, an embodiment of the present application provides a model training method, which obtains a generator model that can be used to generate template files by performing adversarial training on a generator model and a discriminator model, and uses the trained generator model to automatically generate a variety of template files. On the one hand, it is conducive to adapting to different types of document requirements, thereby improving the adaptability of template files; on the other hand, through adversarial training between the generator model and the discriminator model, the generator model is able to generate a generated template file that is close to the real template file, which is conducive to improving the quality of the template file generated by the generator model.

[0038] The following is a detailed description of the above model training method. Figure 1 , the embodiment of the present application provides a model training method, the method comprising:

[0039] Step S110: inputting random noise and real template file features into the generator model to obtain a generated template file generated by the generator model;

[0040] Among them, the real template file features are extracted based on the real template file, and the real template file has a template category label, and the template category label is used to guide the generator model to generate a template file of the corresponding category;

[0041] Step S120: inputting the real template file and the generated template file into the discriminator model to obtain the result of distinguishing the authenticity of the template file;

[0042] Among them, both the real template file and the generated template file have template true or false labels;

[0043] Step S130: Calculate the adversarial loss based on the template file true or false discrimination result and the template true or false label, and update the model parameters of the generator model and the discriminator model according to the adversarial loss;

[0044] Repeat the above steps S110 to S130 to perform adversarial training on the generator model and the discriminator model to obtain trained generator model and discriminator model.

[0045] It is understandable that when the iteration end condition is met, the repeated iterations of the above steps S110 to S130 may be ended. The iteration end condition may be: the model index meets the preset requirement, or reaches the preset number of iterations.

[0046] It is understandable that the template category labels carried by the real template files include, for example, labor contracts, loan contracts, sales contracts, and the like.

[0047] The above-mentioned generator model and discriminator model can form a generative adversarial network, in which the generator model is used to generate a new template file, and the discriminator model is used to judge the authenticity of the template file input into the discriminator model. If the template file is true, it means that the template file is a real template file, and if the template file is false, it means that the template file is a generated template file generated by the discriminator model.

[0048] It is understandable that the generator model and the discriminator model in the generative adversarial network GAN influence and improve each other through repeated adversarial training, and the random noise in the above step S110 enables the generator model to continuously try new generation methods, thereby continuously improving in the confrontation with the discriminator model. On the other hand, since data in the real world often has randomness and diversity, by introducing random noise, the generator model can simulate the randomness and diversity of real data, thereby generating a generated template file that is closer to the real template file, while improving the anti-interference ability of the generator model.

[0049] The following is an introduction to the solution for calculating the adversarial loss in step S130:

[0050] As an optional implementation of the above-mentioned model training method, the above-mentioned step S130 includes: calculating a first loss, and updating the model parameters of the discriminator model based on the first loss; wherein the first loss is used to characterize the discriminator model's ability to distinguish between real data and generated data; calculating a second loss, and updating the model parameters of the generator model based on the second loss; wherein the second loss is used to characterize the generator model's ability to generate real data.

[0051] The goal of the above generator model is to generate a template file that is as close to the real template file as possible to deceive the discriminator model, so the generator model can use the second loss to minimize the probability that the discriminator model will discriminate the generated template file as "fake". The second loss can be implemented using the cross entropy loss function.

[0052] The goal of the above discriminator model is to accurately distinguish between the real template file and the generated template file, so the discriminator model can use the first loss to minimize the probability of mistaking the real template file for "fake" and the probability of mistaking the generated template file for "true". The first loss can also be implemented using a cross entropy loss function.

[0053] The above scheme uses the first loss and the second loss to update the model parameters of the discriminator model and the generator model respectively, which is conducive to improving the training effect of the generative adversarial network, thereby improving the quality of the generated template file generated by the generator model.

[0054] The following is an introduction to the solution of extracting the features of the real template file based on the real template file:

[0055] As an optional implementation of the above-mentioned model training method, the above-mentioned method also includes: obtaining a real template file; extracting real template intermediate features from the real template file; wherein the real template intermediate features include at least one of real template text features, real template structural features and real template semantic features; based on the real template intermediate features, obtaining real template file features.

[0056] The above-mentioned real template text features can be used to characterize the content information of the real template file, the real template structure features can be used to characterize the format and structure information of the real template file, and the real template semantic features can be used to characterize the semantic information of the real template file.

[0057] It is understandable that when the real template intermediate feature includes one of the real template text feature, the real template structure feature and the real template semantic feature, this feature can be directly used as the real template file feature. When the real template intermediate feature includes at least two of the real template text feature, the real template structure feature and the real template semantic feature, the at least two features can be aggregated into the real template file feature by splicing, weighted fusion and the like.

[0058] The real template file features in the above scheme may include at least one of the real template text features, real template structural features and real template semantic features. On the one hand, the real template file features may include at least one of the content information, structural information and semantic information of the real template file. Using the real template file features to train the generator model is conducive to improving the quality and diversity of the generated template files generated by the generator model; on the other hand, the information contained in the real template file features can be adaptively set for different application scenarios, so that the generator model can be applied to more application scenarios, which is conducive to improving the applicability of the generator model.

[0059] The following is an introduction to the extraction scheme of the above-mentioned real template text features:

[0060] As an optional implementation of the above model training method, extracting real template text features from real template files includes: extracting template keywords from real template files; subject-classifying real template files to obtain template subject words; and concatenating template keywords and template subject words to obtain real template text features. This implementation is for example:

[0061] First, the TF-IDF method is used to extract template keywords from the real template file; then the LDA model is applied to the real template file for topic classification to obtain template subject words; finally, the template keywords and template subject words are concatenated to obtain the real template text features;

[0062] The real template text features of multiple real template files may constitute a text feature matrix, in which each column represents a template keyword or a template subject word, and each row represents a real template text feature of a real template file.

[0063] The above scheme obtains the real template file features by extracting template keywords and template subject words in the real template file, and trains the generator model using the real template file features containing the real template file features, which helps the generator model to learn the theme and core content of the template file more accurately, thereby helping to improve the quality of the generated template file generated by the generator model.

[0064] The following is an introduction to the extraction scheme of the above-mentioned real template structure features:

[0065] As an optional implementation of the above-mentioned model training method, extracting real template structural features from real template files includes: performing paragraph recognition on real template files to obtain the number of template paragraphs and the length of template paragraphs; performing title hierarchy analysis on real template files to obtain template titles and their hierarchical structures; performing list item extraction on real template files to obtain list items and their hierarchical structures; and concatenating the number of template paragraphs, the length of template paragraphs, the template titles and their hierarchical structures, and the list items and their hierarchical structures to obtain real template structural features. This implementation is, for example:

[0066] First, identify the paragraphs in the template file and count the number and length of paragraphs in order to understand the structure and logic of the template file; secondly, identify the titles and their hierarchical structure in the template file in order to understand the hierarchical framework of the template file; then identify the list items and their hierarchical structure in the template file; finally, concatenate the above paragraph numbers, paragraph lengths, template titles and their hierarchical structures, and list items and their hierarchical structures to obtain the real template structure features and provide structured template file information for the model.

[0067] The above scheme obtains the real template structure features by integrating the number of paragraphs, paragraph length, template title and its hierarchical structure, and list items and their hierarchical structure of the real template file, so that the real template structure features contain rich template file structured information. Using the real template file features containing the real template structure features to train the generator model helps the generator model to learn the structured information of the template file more accurately, thereby helping to improve the quality of the generated template file generated by the generator model.

[0068] The following is an introduction to the extraction scheme of the semantic features of the above-mentioned real template:

[0069] As an optional implementation of the above model training method, extracting the semantic features of the real template in the real template file includes: converting the text in the real template file into a word vector; extracting the semantic vector of each sentence in the real template file based on the word vector; aggregating the semantic vectors of all sentences to obtain the semantic features of the real template. This implementation is for example:

[0070] First, the template file is converted into a single word vector representation using the Word2Vec pre-trained word embedding model. Word2Vec generates a high-dimensional vector by capturing the semantic relationship between words to represent the semantic information of the document. The word vector is then used to extract the semantic vector of each sentence in the document through the pre-trained Bert. Finally, the vectors of all sentences are aggregated into the true template semantic features.

[0071] The above scheme converts the template file into high-dimensional semantic features to capture the semantic relationship between words and sentences in the template file, which helps the generator model to understand the context information of the template file more deeply, thereby generating a more logical and semantically coherent generated template file, which is conducive to improving the quality of the generated template file generated by the generator model.

[0072] The following are the specific implementation steps of the above model training method in a certain application scenario:

[0073] Step 1: Collecting real template files. The real template file collection step aims to provide rich and high-quality data resources for subsequent model training and template generation. This step mainly obtains document data through two channels: enterprise document management system and online document resource library, including:

[0074] (1) Extract document data from enterprise document management systems. Specifically, you can use the Microsoft Graph API to batch extract Word and PDF files from enterprise platforms such as SharePoint, and then store the files and metadata such as file name, author, creation date, and version number in a local database;

[0075] (2) Obtaining public documents from online document repositories through web crawler technology. In this process, you can use Python's Scrapy library to build a crawler script and set specific crawling rules and target website URLs to ensure that the required documents are accurately obtained. In addition, you can also use deduplication algorithms to prevent the occurrence of duplicate data.

[0076] Documents obtained through crawler technology, including PDF and Word formats, will be stored in the local database and full-text indexed using Elasticsearch.

[0077] Step 2: Data preprocessing, mainly including:

[0078] (1) Format conversion:

[0079] Convert the original files obtained in step 1 into text format. Specifically, for PDF files, you can use the PyPDF2 library function to extract text content and convert it into plain text format. For Word files, you can use the Python library python-docx to convert paragraphs and content in the document into text.

[0080] (2) Denoising:

[0081] Clean up irrelevant characters, format errors, redundant information, etc. to ensure data accuracy and consistency;

[0082] For example, you can use regular expressions to perform the following three operations for denoising:

[0083] Step 1: Remove irrelevant special characters in the document, such as ASCII characters, HTML tags, special marks, etc.

[0084] Operation 2: Remove extra spaces and blank lines;

[0085] Step 3: Use the spellchecker library to identify and fix typos and grammatical errors in the text;

[0086] Operation 4: Remove headers, footers and other redundant information from the document to make the text content more focused.

[0087] (3) Structural analysis:

[0088] Identify and extract hierarchical structure information of documents including titles, paragraphs, lists, tables, etc.

[0089] Step 3: Extract features, mainly including:

[0090] (1) Extracting the features of the real template text, including: first using the TF-IDF method to extract important keywords in the document, then applying the LDA model to perform topic modeling, identifying potential topics in the document, and obtaining subject words. Finally, concatenating a set of keywords and subject words of a document to form a text feature matrix, where each column represents a keyword or subject word, and each row represents the features of a document.

[0091] (2) Extracting the structural features of the real template, including: first identifying the paragraphs in the document, counting the number and length of paragraphs, so as to understand the structure and logic of the document, then identifying the titles in the document and their hierarchical structure to help build the hierarchical framework of the document, and finally identifying the list items in the document and their hierarchical structure to analyze the list content. The above structural features are integrated into a unified structural feature matrix to provide structured document information for the model.

[0092] (3) Extracting the semantic features of the real template, including: first, using the pre-trained word embedding model of Word2Vec to convert the document text into a single word vector representation. Word2Vec generates a high-dimensional vector by capturing the semantic relationship between words to represent the semantic information of the document. Then, the word vector is extracted through the pre-trained Bert to extract the semantic vector of each sentence in the document. Finally, the vectors of all sentences are aggregated to form the semantic features of the complete document.

[0093] Step 4: Dataset construction, mainly including:

[0094] (1) Data integration: The real template text features, real template structural features, and real template semantic features extracted in step 3 are integrated to form a complete feature matrix, where each row corresponds to a document and each column corresponds to a feature dimension.

[0095] (2) Data labeling: Attach the correct template category label to each document in the dataset so that the model can learn the relationship between the document and the template.

[0096] Specifically: two-level classification can be carried out according to the subject and characteristics of the document content. The first-level categories can include three major categories: contracts, reports, and plans. The second-level categories can include subcategories in the three major categories. For example, the contract category can have subcategories such as labor contracts, sales contracts, service contracts, confidentiality contracts, loan note contracts, and loan limit contracts.

[0097] (3) Data standardization: Standardize feature data to improve the stability and effectiveness of model training;

[0098] Specifically, the Z-score normalization method can be used to make the numerical features have the same dimension and distribution, and then the text and category labels can be converted into one-hot numerical form.

[0099] (4) Data segmentation: The dataset is divided into training set, validation set, and test set in a ratio of 80%, 10%, and 10% to facilitate model training, validation, and evaluation.

[0100] Step 5: Model training;

[0101] Use a generative adversarial network to generate a template file. The architecture of the generator model and the discriminator model in the generative adversarial network can be:

[0102] 1. The model input of the generator model can include:

[0103] Noise vector: size is 128;

[0104] Input features: In the training phase, the real template file features of the real template file can be input, and in the application phase, the demand features that can characterize the demand information of the template file to be generated can be input;

[0105] Hidden layers can include:

[0106] Dense Layer: used for feature fusion, with 256 neurons;

[0107] Convolutional Layer: used to extract local features, the convolution kernel size is 3×3, and the number is 128;

[0108] Batch Normalization: used to speed up training and stabilize the model.

[0109] Model output may include: generating template files.

[0110] 2. Discriminator model;

[0111] Model input can include: real template files and generated template files;

[0112] Hidden layers can include:

[0113] Convolution layer: The convolution kernel size is 3×3 and the number is 128;

[0114] Pooling Layer: Use Max Pooling with a size of 2×2;

[0115] Fully connected layer: The number of neurons is 128, and the ReLU activation function is used.

[0116] The model output layer may use a Sigmoid activation function, and the output content may include a result of distinguishing true from false of the template file.

[0117] The hyperparameters of the model can be set as shown in Table 1:

[0118] Table 1 Model hyperparameters

[0119] Optimizer Adam Learning Rate 0.0002 Batch Size 64 Epochs 100 Decay rate 0.95 Evaluation Metrics BLEU, ROUGE

[0120] Model training steps may include:

[0121] (1) Extract a batch of real template files from the training set;

[0122] (2) extracting the real template file features from the real template file;

[0123] (3) Generate random noise, input the random noise and the real template file features into the generator model, and generate a batch of generated template files;

[0124] (4) Inputting the real template file and the generated template file into the discriminator model to obtain the true and false discrimination result of the template file;

[0125] (5) Calculate the adversarial loss and update the model parameters of the generator model and the discriminator model according to the adversarial loss;

[0126] (6) Repeat the above steps until the iteration stop condition is met;

[0127] (7) Evaluate the model on the validation set.

[0128] See also Figure 2 Based on the same inventive concept, the present application also provides a template file generation method, which includes:

[0129] Step S210: Obtaining requirement information of the template file to be generated;

[0130] Step S220: Aggregate demand information into demand features;

[0131] Step S230: input the demand characteristics into the generator model, and obtain the first template file generated by the generator model; wherein the generator model is a trained generator model obtained by using any of the above-mentioned model training methods.

[0132] It can be understood that the requirement information of the template file to be generated may include the text content to be included in the contract to be generated, the type of contract to be generated, and other requirements.

[0133] The above step S220 can extract relevant information of the user on the text, structure and semantics of the template file to be generated according to the requirement information of the template file to be generated, and aggregate it into requirement features, so that the generator model can generate a template file that meets the user's needs according to the requirement features.

[0134] It is understandable that the "first" in the above-mentioned first template file does not limit the number of template files. The first template file may include one or more template files, that is, the generator model may output one or more generated template files according to the input demand characteristics. When the generator model outputs multiple generated template files, the user can further select a target template file from the multiple generated template files.

[0135] Of course, the discriminator model can also be used to screen the first template file. The specific scheme is as follows:

[0136] As an optional implementation of the above template file generation method, the above template file generation method also includes:

[0137] The first template file generated by the generator model is input into the discriminator model to obtain the file authenticity discrimination result of the discriminator model; wherein the discriminator model is a trained discriminator model obtained by using any of the above-mentioned model training methods; based on the file authenticity discrimination result, a second template file is obtained; wherein the second template file is the first template file whose file authenticity discrimination result is true.

[0138] It is understandable that the second template file obtained after verification by the discriminator model may also include multiple template files. At this time, the user can filter the target template file from the multiple template files included in the second template file.

[0139] See also Figure 3 Based on the same inventive concept, the embodiment of the present application also relates to a model training device 300, which includes:

[0140] A generated template file acquisition module 310 is used to input random noise and real template file features into a generator model to obtain a generated template file generated by the generator model; wherein the real template file features are extracted based on a real template file, the real template file has a template category label, and the template category label is used to guide the generator model to generate a template file of a corresponding category;

[0141] The template file authenticity discrimination result acquisition module 320 is used to input the real template file and the generated template file into the discriminator model to obtain the template file authenticity discrimination result; wherein the real template file and the generated template file both have template authenticity labels;

[0142] A model parameter updating module 330, configured to calculate the adversarial loss based on the true or false discrimination result of the template file and the true or false label of the template, and to update the model parameters of the generator model and the discriminator model according to the adversarial loss;

[0143] The adversarial training module 340 is used to repeatedly call the above-mentioned template file generation acquisition module 310, the template file true and false judgment result acquisition module 320 and the model parameter update module 330 to perform adversarial training on the generator model and the discriminator model to obtain the trained generator model and the discriminator model.

[0144] As an optional implementation of the above-mentioned model training device, the above-mentioned model training device 300 also includes:

[0145] A real template file feature extraction module is used to obtain a real template file; extract real template intermediate features from the real template file; wherein the real template intermediate features include at least one of real template text features, real template structural features and real template semantic features; based on the real template intermediate features, obtain the real template file features.

[0146] As an optional implementation of the above-mentioned model training device, the above-mentioned real template file feature extraction module extracts the real template text features from the real template file, including: extracting template keywords from the real template file; subject-classifying the real template file to obtain template subject words; splicing the template keywords and the template subject words to obtain the real template text features.

[0147] As an optional implementation of the above-mentioned model training device, the above-mentioned real template file feature extraction module extracts the real template structural features from the real template file, including: performing paragraph recognition on the real template file to obtain the number of template paragraphs and the length of template paragraphs; performing title hierarchy analysis on the real template file to obtain template titles and their hierarchical structures; performing list item extraction on the real template file to obtain list items and their hierarchical structures; splicing the number of template paragraphs, the template paragraph length, the template title and its hierarchical structure, and the list items and their hierarchical structures to obtain the real template structural features.

[0148] As an optional implementation of the above-mentioned model training device, the above-mentioned real template file feature extraction module extracts the real template semantic features from the real template file, including: converting the text in the real template file into a word vector; based on the word vector, extracting the semantic vector of each sentence in the real template file; aggregating the semantic vectors of all sentences to obtain the real template semantic features.

[0149] As an optional implementation of the above-mentioned model training device, the above-mentioned model parameter updating module 330 calculates the adversarial loss and updates the model parameters of the generator model and the discriminator model according to the adversarial loss, including: calculating a first loss, and updating the model parameters of the discriminator model based on the first loss; wherein the first loss is used to characterize the ability of the discriminator model to distinguish between real data and generated data; calculating a second loss, and updating the model parameters of the generator model based on the second loss; wherein the second loss is used to characterize the ability of the generator model to generate real data.

[0150] See also Figure 4 Based on the same inventive concept, the embodiment of the present application further provides a template file generating device 400, which includes:

[0151] The requirement information acquisition module 410 is used to acquire the requirement information of the template file to be generated;

[0152] A demand feature aggregation module 420 is used to aggregate the demand information into demand features;

[0153] The first template file acquisition module 430 is used to input the demand characteristics into the generator model to obtain the first template file generated by the generator model; wherein the generator model is a trained generator model obtained using any of the above-mentioned model training methods.

[0154] As an optional implementation of the template file generating device, the template file generating device 400 further includes:

[0155] A file authenticity discrimination result acquisition module, used for inputting the first template file generated by the generator model into the discriminator model to obtain the file authenticity discrimination result of the discriminator model; wherein the discriminator model is a trained discriminator model obtained by using any of the above-mentioned model training methods;

[0156] The second template file acquisition module is used to acquire a second template file based on the authenticity judgment result of the file; wherein the second template file is the first template file whose authenticity judgment result is true.

[0157] Figure 5 A schematic diagram of an electronic device provided in an embodiment of the present application. Figure 5 The electronic device 500 includes: a processor 510, a memory 520 and a communication interface 530. These components are interconnected and communicate with each other through a communication bus 540 and / or other forms of connection mechanisms (not shown).

[0158] The memory 520 includes one or more (only one is shown in the figure), which may be, but not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc. The processor 510 and other possible components may access the memory 520 and read and / or write data therein.

[0159] The processor 510 includes one or more (only one is shown in the figure), which can be an integrated circuit chip with signal processing capabilities. The above-mentioned processor 510 can be a general-purpose processor, including a central processing unit (CPU), a micro controller unit (MCU), a network processor (NP) or other conventional processors; it can also be a special-purpose processor, including a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.

[0160] The communication interface 530 includes one or more (only one is shown in the figure), which can be used to communicate directly or indirectly with other devices to exchange data. For example, the communication interface 530 can be an Ethernet interface; it can be a mobile communication network interface, such as an interface of a 3G, 4G, or 5G network; or it can be other types of interfaces with data transceiving functions.

[0161] One or more computer program instructions may be stored in the memory 520, and the processor 510 may read and execute these computer program instructions to implement the model training method and template file generation method provided in the embodiments of the present application and other desired functions.

[0162] Understandably, Figure 5 The structure shown is for illustration only. The electronic device 500 may also include Figure 5 More or fewer components as shown, or with Figure 5 Different configurations shown. Figure 5 Each component shown in the figure can be implemented by hardware, software or a combination thereof. For example, the electronic device 500 can be a single server (or other device with computing processing capabilities), a combination of multiple servers, a cluster of a large number of servers, etc., and can be both a physical device and a virtual device.

[0163] The present application also provides a computer-readable storage medium on which computer program instructions are stored. When the computer program instructions are read and executed by a computer processor, the model training method and template file generation method provided in the present application are executed. For example, the computer-readable storage medium can be implemented as Figure 5 The memory 520 in the electronic device 500.

[0164] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0165] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0166] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0167] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A model training method, characterized in that: It is characterized in that The method comprises: Inputting random noise and real template file features into a generator model to obtain a generated template file generated by the generator model; wherein the real template file features are extracted based on a real template file, the real template file has a template category label, and the template category label is used to guide the generator model to generate a template file of a corresponding category; Input the real template file and the generated template file into the discriminator model to obtain the template file authenticity discrimination result; wherein the real template file and the generated template file both have template authenticity labels; Based on the true and false discrimination result of the template file and the true and false label of the template, the adversarial loss is calculated, and the model parameters of the generator model and the discriminator model are updated according to the adversarial loss; The above steps are iterated repeatedly to perform adversarial training on the generator model and the discriminator model to obtain the trained generator model and the discriminator model.

2. The model training method according to claim 1, characterized in that: The method further comprises: Get the real template file; Extracting real template intermediate features from the real template file; wherein the real template intermediate features include at least one of real template text features, real template structural features and real template semantic features; Based on the real template intermediate feature, the real template file feature is obtained.

3. The model training method according to claim 2, characterized in that: Extracting the real template text features from the real template file includes: Extracting template keywords from the real template file; Subject-classifying the real template file to obtain template keywords; The template keywords and the template subject words are concatenated to obtain the real template text features.

4. The model training method according to claim 2, characterized in that: Extracting the real template structure feature from the real template file includes: Perform paragraph recognition on the real template file to obtain the number of template paragraphs and the length of template paragraphs; Performing title hierarchical analysis on the real template file to obtain the template title and its hierarchical structure; Extracting list items from the real template file to obtain list items and their hierarchical structure; The number of template paragraphs, the length of the template paragraphs, the template title and its hierarchical structure, and the list items and their hierarchical structure are concatenated to obtain the real template structure features.

5. The model training method according to claim 2, characterized in that: Extracting the real template semantic feature from the real template file includes: Convert the text in the real template file into a word vector; Based on the word vector, extracting the semantic vector of each sentence in the real template file; Aggregate the semantic vectors of all sentences to obtain the true template semantic features.

6. The model training method according to any one of claims 1 to 5, characterized in that: The calculating the adversarial loss and updating the model parameters of the generator model and the discriminator model according to the adversarial loss include: Calculating a first loss, and updating a model parameter of the discriminator model based on the first loss; wherein the first loss is used to characterize the ability of the discriminator model to distinguish between real data and generated data; A second loss is calculated, and model parameters of the generator model are updated based on the second loss; wherein the second loss is used to characterize the ability of the generator model to generate real data.

7. A template file generation method, characterized in that: The method comprises: Obtain the requirement information of the template file to be generated; Aggregating the demand information into demand features; The demand feature is input into a generator model to obtain a first template file generated by the generator model; wherein the generator model is a trained generator model obtained by using the model training method described in any one of claims 1 to 6.

8. The template file generation method according to claim 7, characterized in that: The method further comprises: Input the first template file generated by the generator model into the discriminator model to obtain the file authenticity discrimination result of the discriminator model; wherein the discriminator model is a trained discriminator model obtained by using the model training method according to any one of claims 1 to 6; Based on the authenticity determination result of the file, a second template file is obtained; wherein the second template file is the first template file whose authenticity determination result is true.

9. An electronic device, characterized in that: include: A processor, a memory and a communication bus, wherein the processor and the memory communicate with each other via the communication bus; The memory stores program instructions executable by the processor, and the processor can execute the method according to any one of claims 1 to 8 by calling the program instructions.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a computer, the computer is caused to perform the method according to any one of claims 1 to 8.

Citation Information

Cited By

  • Model training method for generating contract template, electronic equipment, storage medium and program product

    CN121902785A