A method for training a document classification model, a document classification method and product
By transforming global and local feature matrices into three-channel RGB color feature images and combining an improved EfficientNet-B2 model with an adjustable loss function, the accuracy and efficiency issues of malicious document detection are resolved, achieving efficient and accurate detection of malicious documents.
Patent Information
- Application Number
- CN202310677635.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-07
- Publication Date
- 2026-11-10
- Estimated Expiration
- 2043-06-07
AI Technical Summary
Existing malicious document detection technologies struggle to detect malicious documents quickly, efficiently, and accurately. In particular, when faced with constantly evolving attack methods and covert variants of malicious documents, traditional methods suffer from false positives, false negatives, and high resource consumption.
A method of fusing global and local feature matrices is adopted, and a three-channel RGB color feature image is generated through min-max normalization and DCT transformation. The improved EfficientNet-B2 model is then trained using adjustable cross-entropy and class-balanced focusing loss function to improve the model's detection accuracy and efficiency.
It improves the accuracy and efficiency of malicious document detection, especially when dealing with imbalanced datasets. By dynamically adjusting the loss function, it can better balance the number of samples and improve the overall performance of the model.
Smart Images

Figure CN116796320B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of document processing, and specifically, the embodiments of this application relate to a method for training a document classification model, a document classification method, and a product. Background Technology
[0002] Office software (such as Word, Excel, and PowerPoint) is widely used in daily life and work, leading to a lack of awareness among ordinary users regarding malicious documents (such as malicious Office documents). This results in an increasing number of cyber attackers using documents for malicious attacks. Common malicious document attack methods targeting Office documents include: exploiting Office vulnerabilities to download and execute malicious code; embedding and executing malicious macro code; using phishing emails to trick users into clicking and executing malicious documents; and using encryption, packing, and obfuscation to evade detection and launch attacks. The diverse and covert nature of malicious Office document attacks poses a significant challenge to their detection. Therefore, how to efficiently and accurately detect malicious documents and implement targeted security measures has become an urgent problem to solve.
[0003] Traditional malicious document detection methods can be broadly categorized into three types: static detection, dynamic detection, and hybrid detection. Static detection methods do not require running a program; they perform static analysis by decompiling or directly extracting document features. However, if the document has been obfuscated, packed, or encrypted, false positives or false negatives may occur, leading to reduced detection accuracy. Furthermore, they struggle to detect unknown or novel malicious documents. Dynamic detection methods utilize virtualization technology, executing the document in a virtual environment. This consumes significant resources and time, heavily relies on manual intervention, and has low efficiency and effectiveness. Hybrid detection methods combine static and dynamic detection techniques, integrating the analysis of document execution behavior with its own static features. This approach has the advantage of excellent identification capabilities for packed, obfuscated, and other malicious documents and their variants. However, it consumes substantial resources, has low detection efficiency, and is less practical for detecting large datasets.
[0004] With the continuous improvement and updating of attack methods, malicious documents and their variants are becoming increasingly sophisticated and difficult to disguise. Traditional malicious document detection technologies struggle to detect them quickly, efficiently, and accurately. The widespread application of machine learning and deep learning in fields such as NLP and CV has brought new detection technologies and research ideas for intelligent, automated, and efficient malicious document detection. While document visualization methods have been used to detect malicious documents, they suffer from problems such as the loss of key feature information and low accuracy and efficiency of detection models. Therefore, there is an urgent need to comprehensively improve the efficiency and accuracy of document visualization detection by focusing on feature extraction and model application. Summary of the Invention
[0005] The purpose of this application is to provide a method for training a document classification model, a document classification method, and a product. Using this application can at least improve the accuracy of document category determination.
[0006] In a first aspect, embodiments of this application provide a method for training a document classification model. The method includes: obtaining a global feature matrix and at least one local feature matrix of a document, wherein the document belongs to a file in a training set; preprocessing the global feature matrix and the at least one local feature matrix and then fusing them to obtain a three-channel RGB color feature image, wherein the preprocessing includes min-max normalization and / or DCT transform operation; and using the three-channel RGB color feature image to train the document classification model to obtain a target document classification model.
[0007] Some embodiments of this application convert multiple types of documents into matrices containing local and global information, perform min-max normalization or DCT transformation on the three two-dimensional matrices respectively, thereby achieving the purpose of data standardization, scale unification and sparsity reduction, and then convert the three two-dimensional matrices into three-channel RGB images, providing rich feature information for model detection.
[0008] In some embodiments, the at least one local feature matrix includes a first local feature matrix and a second local feature matrix, wherein the first local feature matrix is used to characterize the byte value transfer probability of adjacent bytes, and the second local feature matrix is used to characterize the byte value transfer probability of spaced bytes.
[0009] The local feature matrices of some embodiments of this application include two types, providing rich feature information for model training.
[0010] In some embodiments, the step of preprocessing the global feature matrix and the at least one local feature matrix and then fusing them to obtain a three-channel RGB color feature image includes: normalizing the global feature matrix, the first local feature matrix, and the second local feature matrix respectively to obtain three normalized feature matrices; and fusing features based on the three normalized feature matrices to obtain the three-channel RGB color feature image.
[0011] Some embodiments of this application normalize the feature matrix corresponding to each document (e.g., normalize the feature matrix using the maximum and minimum values of the corresponding matrix), thereby achieving the purpose of standardizing data and unifying scale.
[0012] In some embodiments, the step of obtaining the three-channel RGB color feature image by feature fusion based on the three normalized feature matrices includes: performing DCT transformation on the three normalized feature matrices respectively to obtain three DCT transformation feature matrices; and performing the normalization process, dimension change, and merging on the three DCT transformation feature matrices respectively to obtain the three-channel RGB color feature image.
[0013] Some embodiments of this application also require DCT transformation of the normalized feature matrix to achieve the purpose of sparsification.
[0014] In some embodiments, the document classification model to be trained includes: a first convolutional feature extraction layer, repeatedly stacked MBConv feature extraction modules, a convolutional dimensionality reduction layer, a pooling layer, and a fully connected layer, wherein each MBConv feature extraction module further includes: a grouped convolutional layer.
[0015] Some embodiments of this application improve the MBCon structure in the EfficientNet-B2 model to obtain the architecture of the document classification model to be trained. The improvement includes replacing the ordinary convolution module with grouped convolution. Using grouped convolution can reduce the number of parameters and computational overhead.
[0016] In some embodiments, each MBConv feature extraction layer further includes a channel recombination operation layer located between the grouped convolutional layers and the depthwise separable convolutional layers.
[0017] Some embodiments of this application improve the MBCon structure in the EfficientNet-B2 model to obtain the architecture of the document classification model to be trained. The improvement includes replacing the ordinary convolution module with group convolution and then performing channel recombination operation. Group convolution can reduce the number of parameters and computational overhead, and channel recombination can enhance the information flow between the feature channels of each group.
[0018] In some embodiments, each MBConv feature extraction layer further includes a spatial attention (SAM) module located after the channel attention (SE) module.
[0019] Some embodiments of this application improve the MBCon structure in the EfficientNet-B2 model to obtain the architecture of the document classification model to be trained. The improvement includes replacing the ordinary convolution module with group convolution, then performing channel recombination operation, and adding a spatial attention (SAM) module after the channel attention (SE) module. Group convolution can reduce the number of parameters and computational overhead, channel recombination can enhance the information flow between the feature channels of each group, and adding the SAM module can make the network pay more attention to the pixels in the image that play a decisive role in detection or classification while ignoring irrelevant pixels, which greatly improves the overall performance of the model.
[0020] In some embodiments, training the document classification model using the three-channel RGB color feature image includes: obtaining a predicted classification result for the document based on the document classification model and the three-channel RGB color feature image, and adjusting the parameters of the document classification model based on the predicted classification result.
[0021] In some embodiments, adjusting the parameters of the document classification model to be trained based on the predicted classification result includes: selecting a target loss function from a cross-entropy loss function and a class-balanced focusing loss function, wherein the class-balanced focusing loss function is obtained by multiplying each term in the focusing loss function by a class-balanced weight factor and then summing them, each term in the focusing loss function characterizing the loss value of a class of document samples, and the class-balanced weight factor being related to the difference between the total number of samples in the corresponding class of documents and the total number of samples in other classes of documents; obtaining a loss function value based on the predicted classification result and the target loss function; and adjusting the parameters based on the loss function value.
[0022] Some embodiments of this application design two types of loss functions, and select one of the two loss functions to calculate the loss value during training based on the balance between the number of samples in each type. It is easy to understand that through this adjustable loss function, similar to a gating switch, when training the model with a balanced dataset (in which case the cross-entropy loss function is selected as the target loss function) or an imbalanced dataset (in which case the class-balanced focusing loss function is selected as the target loss function), it is necessary to switch to the corresponding loss function to improve the training speed of the document classification model to be trained and improve the performance of the target document classification model obtained by training.
[0023] In some embodiments, selecting one of the cross-entropy loss function and the focus loss function as the target loss function includes: if the total number of samples included in each type of document sample is balanced, selecting the cross-entropy loss function as the target loss function; if the total number of samples included in each type of document sample is unbalanced, selecting the focus loss function as the target loss function.
[0024] Some embodiments of this application design an adjustable loss function, similar to a gate switch, which can be switched to the corresponding loss function when training a model with balanced or imbalanced datasets.
[0025] In some embodiments, the class balance weight factor β corresponding to the j-th class document sample j Characterized as:
[0026]
[0027]
[0028] Where, n j This represents the total number of original document samples contained in the j-th type of document sample, and k represents the total number of document sample categories.
[0029] Some embodiments of this application design a method for adding weight coefficients to the loss function of related classes in an imbalanced dataset, thereby indirectly reducing the classification weight of classes with more samples, or relatively increasing the classification weight of classes with fewer samples.
[0030] In some embodiments, the formula for calculating the loss value corresponding to the j-th term in the focusing loss function is as follows:
[0031]
[0032] Where, p ij Let k be the predicted probability that the i-th sample belongs to the j-th class of document samples, where k represents the number of document sample classes, (1-p ij ) γ γ is a modulo factor, and γ is an adjustable focusing parameter with γ≥0.
[0033] Some embodiments of this application provide a method for quantifying the focusing loss function, thereby improving the accuracy and objectivity of the obtained loss values.
[0034] Secondly, some embodiments of this application provide a method for classifying documents, the method comprising: obtaining a target three-channel RGB color feature image based on a global feature matrix and at least one local feature matrix of the document to be classified; and obtaining a target category of the document to be classified based on the target document classification model obtained by the training method of the first aspect and the target three-channel RGB color feature image.
[0035] In some embodiments, obtaining the target three-channel RGB color feature image based on the global feature matrix of the document to be classified and at least one local feature matrix includes: performing at least normalization processing and DCT transformation processing on the global feature matrix, the first local feature matrix, and the second local feature matrix to obtain the three-channel RGB color feature image.
[0036] Thirdly, some embodiments of this application provide an apparatus for training a document classification model, the apparatus comprising: a feature extraction module configured to acquire a global feature matrix and at least one local feature matrix of a document, wherein the document belongs to a file in a training set; a preprocessing module configured to preprocess the global feature matrix and the at least one local feature matrix and then fuse them to obtain a three-channel RGB color feature image, wherein the preprocessing includes min-max normalization and / or DCT transform operation; and a training module configured to train the document classification model to be trained using the three-channel RGB color feature image to obtain a target document classification model.
[0037] Fourthly, some embodiments of this application provide an apparatus for classifying documents, the apparatus comprising: a preprocessing module configured to obtain a three-channel RGB color feature image based on a global feature matrix of the document to be classified and at least one local feature matrix; and a classification module configured to obtain a target category of the document to be classified based on a target document classification model and the three-channel RGB color feature image.
[0038] Fifthly, some embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can implement the methods described in any embodiment of the first or second aspect.
[0039] In a sixth aspect, some embodiments of this application provide an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, can implement the methods described in any of the embodiments of the first and second aspects. Attached Figure Description
[0040] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1 A schematic diagram illustrating the process of training and applying a document classification model as provided in an embodiment of this application;
[0042] Figure 2 A flowchart illustrating the method for training a document classification model provided in this application embodiment;
[0043] Figure 3One of the architecture diagrams of the EfficientNet-B2 model provided in the embodiments of this application;
[0044] Figure 4 One of the architecture diagrams of the document classification model to be trained and the target document classification model provided in the embodiments of this application;
[0045] Figure 5 The second architectural diagram of the document classification model to be trained and the target document classification model provided in the embodiments of this application;
[0046] Figure 6 A flowchart of a document classification method provided in this application embodiment;
[0047] Figure 7 A block diagram of the apparatus for training a document classification model provided in the embodiments of this application;
[0048] Figure 8 A block diagram illustrating the composition of a document classification apparatus provided in an embodiment of this application;
[0049] Figure 9 This is a schematic diagram illustrating the composition of an electronic device provided in an embodiment of this application. Detailed Implementation
[0050] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0051] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0052] Through long-term research, the inventors of this application have discovered that the document classification methods provided by related technologies (e.g., patent application number CN202210668188, titled: A Malicious Document Detection Method Based on Three-Channel Markov Graphs) have at least the following shortcomings: First, the feature information representation is incomplete. During feature extraction, one directly adjacent byte and two indirectly adjacent bytes are used to calculate the transition matrix between the three byte values. These three transition matrices are then converted into three single-channel Markov color images. It can be seen that only local feature information is used, without reflecting global feature information. Second, the model accuracy needs improvement. This is because the EfficientNet-B0 model algorithm itself significantly reduces model parameters and computational overhead, but the model's accuracy still needs improvement. The large number of parameters consumes a significant amount of memory and computational resources. Using the EfficientNet-B0 model combined with transfer learning helps with model training, but when facing imbalanced datasets, it is difficult to guarantee a high classification accuracy using this model.
[0053] To overcome the shortcomings of existing technologies, this application aims to solve the following technical problems: For example, in some embodiments of this application, global and local information of documents are extracted simultaneously, and feature extraction and fusion are performed by combining local and global information, providing richer feature information. For example, in some embodiments of this application, the EfficientNet-B2 model is improved, effectively reducing model parameters and computational load while improving model detection accuracy. For example, in some embodiments of this application, a method is designed to add weight coefficients (i.e., class balance weight factors) to the loss function for imbalanced datasets, indirectly reducing the weight of classifications with more samples, or relatively increasing the weight of classifications with fewer samples. For example, in some embodiments of this application, an adjustable loss function is designed, similar to a gating switch, which can be switched to the corresponding loss function when training the model on balanced or imbalanced datasets (i.e., a choice can be made between the cross-entropy loss function and the focusing loss function as the target loss function).
[0054] Please refer to Figure 1 , Figure 1The process for training and applying a document classification model provided in this application includes: First, collecting multiple original documents and extracting features from each document to obtain a global feature matrix, a 2-gram frequency matrix (i.e., a first local feature matrix), and a spaced 2-gram frequency matrix (i.e., a second global feature matrix) corresponding to each original document; Second, preprocessing these feature matrices, for example, including at least one of normalization and DCT, and fusing the three preprocessed feature matrices to obtain an RGB image; Third, training and validating the model based on the RGB image. In some embodiments of this application, the document classification model to be trained is based on an improved EfficientNet-B2 model, and in some embodiments, the EfficientNet-B2 model can also be used as the document classification model to be trained. After model training, a target document classification model can be obtained. Then, for documents to be classified, this target document classification model can be directly applied to identify the document type. For example, the trained target document classification model can be used to determine whether the input document to be classified belongs to a benign doc document, a malicious doc document, a benign XLX document, or a malicious XLX document.
[0055] It is easy to understand that some embodiments of this application require the collected original documents to be classified in advance, and then the document classification model can be trained to classify the input documents.
[0056] The following is combined Figure 2 The present application provides exemplary methods for training document classification models based on some embodiments.
[0057] like Figure 2 As shown, some embodiments of this application provide methods for training document classification models, including:
[0058] S101, obtain the global feature matrix and at least one local feature matrix of the document, wherein the document belongs to a file in the training set.
[0059] S102, the global feature matrix and the at least one local feature matrix are preprocessed and then fused to obtain a three-channel RGB color feature image, wherein the preprocessing includes min-max normalization and / or DCT transform operation.
[0060] S103, the three-channel RGB color feature image is used to train the document classification model to obtain the target document classification model.
[0061] In other words, some embodiments of this application convert multiple types of documents into matrices containing local and global information, perform min-max normalization or DCT transformation on the three two-dimensional matrices respectively, thereby achieving the purpose of standardizing data, unifying scale and de-sparsening, and then convert the three two-dimensional matrices into three-channel RGB images, providing rich feature information for model detection.
[0062] The following example illustrates... Figure 2 How each step is implemented.
[0063] It's easy to understand that extracting document features requires pre-collecting documents and dividing them into training, testing, and validation sets. For example, this process might involve collecting benign and malicious MS Office documents with extensions like .doc, .docx, .xls, and .xlsx, dividing the data into eight types (i.e., obtaining eight categories of document samples), and selecting a certain size of sample data in a 6:2:2 ratio as the training, validation, and testing sets.
[0064] To provide rich feature information for the document classification model to be trained, in some embodiments of this application, the at least one local feature matrix in S101 includes a first local feature matrix and a second local feature matrix, wherein the first local feature matrix is used to characterize the byte value transition probability of adjacent bytes, and the second local feature matrix is used to characterize the byte value transition probability of spaced bytes. For example, in some embodiments of this application, S101 generates three two-dimensional matrices by extracting global and local features of the document.
[0065] For example, in some embodiments of this application, the global feature information extraction process includes:
[0066] 2.1) Read the document content as a byte stream and obtain the document length len. A single byte value represents a range of 0-255.
[0067] 2.2) Take the square root of the document length len, round it up to get sqrtLen, and then square sqrtLen to get newLen (note: newLen is greater than or equal to Len).
[0068] 2.3) Create a two-dimensional matrix M with dimensions sqrtLen*sqrtLen and initialize the element values in M to 0. Save the read byte data into matrix M. Matrix M can store newLen bytes of data. If newLen is greater than Len, the subsequent elements in matrix M will be filled with 0 by default. The number of fillers is NewLen minus Len.
[0069] 2.4) Matrix M is scaled using bilinear interpolation to become a two-dimensional matrix Mr with dimensions 256*256. The two-dimensional matrix Mr is used to store global feature information, thus obtaining the global feature matrix.
[0070] For example, in some embodiments of this application, the local feature information extraction process includes:
[0071] 2.1) Create two two-dimensional matrices Mg and Mb with dimensions of 256*256 respectively, and initialize the element values in matrices Mg and Mb to 0.
[0072] 2.2) Traverse the byte stream document in bytes and count the frequency of two directly adjacent and indirectly adjacent (two bytes separated by one byte) byte values appearing together in the document.
[0073] 2.3) Using two directly adjacent and indirectly adjacent bytes as indices respectively, the statistical results are stored in two-dimensional matrices Mg and Mb according to the index correspondence. Two-dimensional matrix Mg is used to store the local feature 2-gram frequency information to obtain the first local feature matrix, and two-dimensional matrix Mb is used to store the local feature indirect 2-gram frequency information to obtain the second local feature matrix.
[0074] 2.4) When reading Office documents, there are a lot of empty characters, that is, 0x00 will appear many times in a row without any practical meaning. In order to reduce the impact of 0x00 on the frequency statistics of 2-grams, the first element in the matrices Mg and Mb is set to 0, that is, Mg[0][0]=0 and Mb[0][0]=0.
[0075] To achieve standardized data and uniform scale, the feature matrix needs to be preprocessed.
[0076] In some embodiments of this application, step S102 includes: normalizing the global feature matrix, the first local feature matrix, and the second local feature matrix to obtain three normalized feature matrices; and performing feature fusion based on the three normalized feature matrices to obtain the three-channel RGB color feature image. In other words, some embodiments of this application normalize the feature matrices corresponding to each document (e.g., normalizing the feature matrix using the maximum and minimum values of the corresponding matrix), thereby achieving the purpose of standardizing data and unifying scale.
[0077] To reduce sparsity, the feature matrix needs to be transformed using DCT.
[0078] In some embodiments of this application, the step of obtaining the three-channel RGB color feature image by feature fusion based on the three normalized feature matrices includes: performing DCT transformation on the three normalized feature matrices respectively to obtain three DCT transformed feature matrices; and at least performing the normalization processing, dimension transformation, and merging on the three DCT transformed feature matrices respectively to obtain the three-channel RGB color feature image. Some embodiments of this application also require performing DCT transformation on the normalized feature matrices to achieve sparsity reduction.
[0079] The preprocessing process is illustrated below using three two-dimensional matrices as an example.
[0080] In some embodiments of this application, S102 involves preprocessing such as normalization (i.e., minimum-maximum normalization) and DCT transformation in the feature fusion to generate the RGB image. The preprocessing process is as follows:
[0081] 3.1) To standardize the data, based on the two-dimensional matrices Mr, Mg, and Mb obtained in the above steps, minimum-maximum normalization (Min-Max Normalization) is performed on the two-dimensional matrices Mr, Mg, and Mb respectively, normalizing the value range of the feature matrix to [0,1]. The Min-Max Normalization formula is as follows:
[0082]
[0083] Where x is an element value in a two-dimensional matrix, x min Let x be the minimum element value in the two-dimensional matrix. max x is the maximum element value in the two-dimensional matrix, and x* is the element value of x after min-max normalization.
[0084] 3.2) Perform DCT transformation on the min-max normalized two-dimensional matrices Mr, Mg, and Mb respectively. After the DCT transformation, the dimensions of matrices Mr, Mg, and Mb remain unchanged. The specific calculation formula is as follows:
[0085]
[0086]
[0087] Where c(u) and c(v) are compensation coefficients that make the DCT transform matrix orthogonal, u = 0, 1, 2, ..., M-1, v = 0, 1, 2, ..., N-1, and f(i,j) is an M×N digital image matrix. In practical applications, the matrix is required to be in square form. If it is not a square matrix, it needs to be padded to become a square matrix (M = N). The matrix form is as follows:
[0088] F = AfA T (3)
[0089]
[0090] After discrete cosine transform, the scale can be unified and sparsity can be reduced (the 2-gram frequency matrix that preserves local features and the indirect 2-gram frequency matrix contain a large number of 0s). In terms of image representation, the low-frequency signal is placed in the upper left corner, which describes the main part of the image and is the key to image recognition; the high-frequency signal is placed in the lower right corner, which describes some details of the image. Removing some high-frequency signals does not have a significant impact on the image.
[0091] 3.3) Perform minimum-maximum normalization on the matrices Mr, Mg and Mb after DCT transformation, and multiply the elements in the matrices Mr, Mg and Mb by 255 and then round them down.
[0092] 3.4) Perform dimension transformation on the two-dimensional matrices Mr, Mg and Mb after the maximum and minimum normalization to transform them into three-dimensional matrices with dimensions of 256*256*1 respectively. Then perform a merging operation to merge the three-dimensional matrices Mr, Mg and Mb into a three-dimensional matrix Mrgb with dimensions of 256*256*3.
[0093] 3.5) Generate a three-channel RGB color image from the 3D matrix Mrgb, which will serve as the RGB feature image for the Office document.
[0094] The following examples illustrate some embodiments of the improved EfficientNet-B2 model provided in this application.
[0095] like Figure 3 As shown in the figure, this diagram illustrates the structure of the EfficientNet-B2 model provided by related technologies. The model sequentially includes: a first convolutional feature extraction layer (…). Figure 3 The Conv 3*3 module), repeatedly stacked MBConv feature extraction modules ( Figure 3 MBConvi 3*3), convolutional dimensionality reduction layer ( Figure 3 Conv1 1*1), pooling layer ( Figure 3 Avgpool) and fully connected layers ( Figure 3 (FC).
[0096] Figure 3The image processing procedure is as follows: The input document to be classified is processed by a 3x3 convolution to extract features. These features are then further extracted using a repeatedly stacked MBConv structure. After dimensionality reduction via a 1x1 convolution, the document passes through an average pooling layer and a fully connected layer to obtain the predicted output. The classification results include: harmless doc documents (benign doc), harmless docx documents (benigndocx), ..., harmful doc documents (malicious doc), and harmful docx documents (malicious docx).
[0097] Figure 4 Provided Figure 3 The structure of the overlapping MBConv feature extraction module consists of: a 1*1 convolutional layer Conv 1*1,s1; a depthwise separable convolutional layer DewiseConv k*k,s1 / s2; an SE module; a 1*1 convolutional layer Conv 1*1; and a Dropout module. The first 1*1 convolution is used for dimensionality increase, changing the input channel number to filters_in*expand_ratio. The Depwise Conv is a depthwise separable convolution. The SE module is a Squeeze-and-Excitation module, an application of Luong's attention mechanism in images. The second 1*1 convolution is used for dimensionality reduction, adjusting the dimension to filters_out. Finally, there is a Dropout layer to reduce overfitting, and the SE module is the attention mechanism.
[0098] and Figure 4 The difference lies in that, in some embodiments of this application, each MBConv feature extraction module in the document classification model to be trained further includes a grouped convolutional layer. Some embodiments of this application improve the MBCon structure in the EfficientNet-B2 model to obtain the architecture of the document classification model to be trained. This improvement includes replacing ordinary convolutional modules with grouped convolutions, which can reduce the number of parameters and computational overhead.
[0099] and Figure 4 The difference lies in that, in some embodiments of this application, each MBConv feature extraction layer further includes a channel reorganization operation layer located between the grouped convolutional layers and the depthwise separable convolutional layers. Some embodiments of this application improve the MBCon structure in the EfficientNet-B2 model to obtain the architecture of the document classification model to be trained. This improvement includes replacing ordinary convolutional modules with grouped convolutions, and then performing channel reorganization operations. Grouped convolutions can reduce the number of parameters and computational overhead, while channel reorganization can enhance the information flow between the feature channels of each group.
[0100] and Figure 4The difference is that in some embodiments of this application, each MBConv feature extraction layer further includes a spatial attention (SAM) module located after the channel attention (SE) module.
[0101] It is not difficult to understand that in some embodiments of this application, such as Figure 5 As shown, Figure 5 Provided different Figure 4 The improved overlapping MBConv feature extraction module layer of this application, with Figure 4 The difference is that this diagram will Figure 4 The first 1x1 convolutional layer Conv 1x1 is replaced with a grouped convolutional layer GConv, and a channel shuffle layer is added after this layer. Figure 4 After SE, add the Spatial Attention (SAM) module.
[0102] Some embodiments of this application improve the MBCon structure in the EfficientNet-B2 model to obtain the architecture of the document classification model to be trained. The improvement includes replacing the ordinary convolution module with group convolution, then performing channel recombination operation, and adding a spatial attention (SAM) module after the channel attention (SE) module. Group convolution can reduce the number of parameters and computational overhead, channel recombination can enhance the information flow between the feature channels of each group, and adding the SAM module can make the network pay more attention to the pixels in the image that play a decisive role in detection or classification while ignoring irrelevant pixels, which greatly improves the overall performance of the model.
[0103] The following examples illustrate the loss functions used in some embodiments of this application.
[0104] It is understood that, in some embodiments of this application, training the document classification model using the three-channel RGB color feature image includes: obtaining a predicted classification result for the document based on the document classification model and the three-channel RGB color feature image, and adjusting the parameters of the document classification model based on the predicted classification result.
[0105] In some embodiments of this application, adjusting the parameters of the document classification model to be trained based on the predicted classification result includes: selecting a target loss function from a cross-entropy loss function and a class-balanced focusing loss function, wherein the class-balanced focusing loss function is obtained by multiplying each term in the focusing loss function by a class-balanced weight factor and then summing them, each term in the focusing loss function being used to characterize the loss value of a class of document samples, and the class-balanced weight factor being related to the difference between the total number of samples in the corresponding class of documents and the total number of samples in other classes of documents; obtaining a loss function value based on the predicted classification result and the target loss function; and adjusting the parameters based on the loss function value.
[0106] It is easy to understand that some embodiments of this application design two types of loss functions, and select one of the two loss functions to calculate the loss value during the training process based on the balance between the number of samples in each type. It is easy to understand that through this adjustable loss function, similar to a gating switch, when training the model with a balanced dataset (in which case the cross-entropy loss function is selected as the target loss function) or an imbalanced dataset (in which case the class-balanced focusing loss function is selected as the target loss function), it is necessary to switch to the corresponding loss function autonomously, thereby improving the training speed of the document classification model to be trained and improving the performance of the target document classification model obtained by training.
[0107] It should be noted that, in some embodiments of this application, selecting one of the cross-entropy loss function and the focusing loss function as the target loss function includes: if the total number of samples in each type of document sample is balanced, selecting the cross-entropy loss function as the target loss function; if the total number of samples in each type of document sample is unbalanced, selecting the focusing loss function as the target loss function. Some embodiments of this application design an adjustable loss function, similar to a gating switch, which can be manually switched to the corresponding loss function when training a model with balanced or imbalanced datasets.
[0108] For example, in some embodiments of this application, the class balance weight factor β corresponding to the j-th class document sample j Characterized as:
[0109]
[0110]
[0111] Where, n j This represents the total number of original document samples contained in the j-th type of document sample, and k represents the total number of document sample categories.
[0112] Some embodiments of this application design a method for adding weight coefficients to the loss function of related classes in an imbalanced dataset, thereby indirectly reducing the classification weight of classes with more samples, or relatively increasing the classification weight of classes with fewer samples.
[0113] In some embodiments, the formula for calculating the loss value corresponding to the j-th term in the focusing loss function is as follows:
[0114]
[0115] Where, p ij Let k be the predicted probability that the i-th sample belongs to the j-th class of document samples, where k represents the number of document sample classes, (1-p ij ) γ γ is a modulo factor, and γ is an adjustable focusing parameter with γ≥0.
[0116] Some embodiments of this application provide a method for quantifying the focusing loss function, thereby improving the accuracy and objectivity of the obtained loss values.
[0117] The following example illustrates the process of improving the EfficientNet-B2 model and the loss functions involved in the training process.
[0118] 4.1) The MBCon structure in the EfficientNet-B2 model is improved as follows:
[0119] 4.1.1) will Figure 4 In the MBCon structure, the first ordinary convolutional module with a 1×1 kernel is replaced with a grouped convolution with a 1×1 kernel to obtain... Figure 5 The GConv is then processed, and a channel reassembly operation is performed to obtain... Figure 5 Channel Shuffle. Grouped convolution can reduce the number of parameters and computational cost, while channel reorganization can enhance the information flow between feature channels in each group, thereby improving the overall performance of the model;
[0120] 4.1.2) Add a spatial attention module SAM (e.g., ...) after the SE module in the MBCon structure. Figure 5 As shown in the image, adding the SAM module, although increasing computation slightly, allows the network to focus more on pixels that play a decisive role in detection or classification while ignoring irrelevant pixels, thus significantly improving model performance. Figure 5 The specific implementation process of the model is as follows:
[0121] ① The feature map M with dimensions [c, w, h] is processed by the SE module, and then subjected to max pooling and average pooling operations along the channel dimension to obtain two feature maps Mmax and Mavg with dimensions [1, w, h]. M is a three-dimensional matrix, where c represents the number of channels, w represents the width, and h represents the height; M is actually the three-dimensional matrix Mrgb generated above, processed in step 4.1.1.
[0122] ② Perform channel-dimension concatenation on the feature maps Mmax and Mavg with dimensions [1, w, h] to obtain a feature map Mt with dimensions [2, w, h]. Then perform convolution on the feature map Mt to fuse the features in the channel dimensions, resulting in a feature map Mtt with dimensions [1, w, h].
[0123] ③ The feature map Mtt is weighted by the sigmoid function, and then the weighted feature map Mtt is multiplied by the input feature map M to obtain the final feature map with spatial weights.
[0124] 4.1.3) Replace the ordinary convolutional module with a 1×1 kernel in the second convolutional kernel of the MBCon structure with a grouped convolution with a 1×1 kernel.
[0125] 4.2) Change the output of the last fully connected layer of the EfficientNet-B2 model to 8 (if the document samples include a total of 8 classes) to adapt to the detection of multiple types of malicious documents in the current dataset.
[0126] 4.3) Some embodiments of this application also design an adjustable loss function, which is composed of a cross-entropy loss function (CEL) and a class-balanced focal loss function (CBFL), and the process is as follows: 4.3.1)
[0128] ①The cross-entropy loss function for the i-th sample is defined as follows:
[0129]
[0130] Among them, CE i p represents the cross-entropy of the i-th sample. ij Let y be the predicted probability that the i-th sample belongs to class j, where k represents the number of sample classes, and y is the predicted probability. ij Let y be a sign function (0 or 1). If the i-th sample belongs to class j, then y ij The value is 1, otherwise y ij The value is 0, and category j usually uses one-hot encoding.
[0131] ②The cross-entropy loss function is defined as follows:
[0132]
[0133] Where n represents the total number of samples.
[0134] ③The focusing loss function for the i-th sample is defined as follows:
[0135]
[0136] Among them, (1-p ij ) γ γ is a moduloizable factor used to indirectly reduce the weight of easily classified samples, which can also be understood as relatively increasing the weight of difficult-to-classify samples; γ is an adjustable focusing parameter and γ≥0. When γ=0, FL is equivalent to CE, and as γ increases, the influence of the moduloizable factor also increases.
[0137] ④ The focus loss function is defined as follows:
[0138]
[0139] ⑤ The class-balanced focusing loss function provided in some embodiments of this application is defined as follows:
[0140]
[0141] Where, β j It is a class balancing weight factor, used to indirectly reduce the classification weight of classes with a large number of samples and increase the classification weight of classes with a small number of samples.
[0142] 4.3.2) A quasi-balanced weighting factor β is proposed. j The implementation method uses the reciprocal of the class frequency for reweighting. The specific design process is as follows:
[0143] ① Calculate the reciprocals of the frequencies of each class to obtain the weighting coefficients for each class.
[0144]
[0145] Where, n j This represents the original number of samples of category j, excluding samples generated through data augmentation, transformation, etc.
[0146] ② Calculate the class-based balancing weight factor so that the sum of the weights of each class-based balancing weight factor is 1.
[0147]
[0148] From the above, we can see from formula (2) that,
[0149] 4.3.3) Some embodiments of this application provide the following adjustable loss functions:
[0150] L = is_ce.L CE +(1-is_ce).L CBFL
[0151] is_ce is a loss function selection factor, taking a value of 0 or 1. When the sample dataset is class-balanced, is_ce = 1, and the cross-entropy loss function L is used. CE As the loss function, when the sample dataset is imbalanced, is_ce = 0, and the class-balanced focusing loss function L is used. CBFL As a loss function.
[0152] The following example illustrates the implementation of some embodiments of this application.
[0153] Some embodiments of this application extract features from each collected document, extracting document information into three two-dimensional matrices that store global and local feature information. The three two-dimensional matrices are then subjected to min-max normalization and DCT transformation to convert the documents into unified three-channel RGB color images. The improved lightweight model EfficientNet-B2 is then trained on the training and validation sets, and tested on the test set after training, effectively achieving the detection and classification of multiple document types.
[0154] The method for training and classifying application models is described in detail according to some embodiments of this application. The specific process is as follows:
[0155] 1. Collect a total of 19,000 MS Office benign and malicious documents with file extensions such as .doc, .docx, .xls, and .xlsx as an example dataset. The example dataset includes 8 categories: 4,000 malicious and 4,000 benign samples with the .doc extension, 3,000 malicious and 3,000 benign samples with the .docx extension, 1,500 malicious and 1,000 benign samples with the .xls extension, and 1,000 malicious and 1,000 benign samples with the .xlsx extension.
[0156] 2. Preprocess each document to extract the document information into a three-dimensional 256*256 matrix to store the document's global feature information, the frequency information of directly adjacent 2-grams of local features, and the frequency information of indirectly adjacent 2-grams.
[0157] 3. Perform min-max normalization and DCT transformation on the three 256*256 two-dimensional matrices corresponding to each document to generate a three-channel RGB color image, which serves as the feature image of the document;
[0158] 4. Generate three-channel RGB color images for all documents according to processes 2 and 3, and select the corresponding images as training set, validation set and test set in a 6:2:2 ratio;
[0159] 5. Since the dataset is imbalanced, the function selection factor is_ce in the adjustable loss function L is set to 0, and the model loss function is... Set β j Parameter value, β j The specific calculation steps are as follows:
[0160] 5.1) Calculate the weighting coefficients for each class.
[0161] According to the formula have to
[0162] 5.2) Calculate the class balance weight factor β j
[0163] According to the formula Obtain β1=0.056, β2=0.056, β3=0.074, β4=0.074…β8=0.222
[0164] 6. Set the adjustable focusing parameter γ. To increase the impact of classifying easy and difficult samples on the loss function, γ is set to 2 here.
[0165] 7. Set the batch size to 64, train the improved lightweight model EfficientNet-B2 on the training and validation sets for 100 epcohs, and select the model parameters that perform best on the validation set for testing.
[0166] 8. Validate the model on the test set to effectively detect and classify multiple document types.
[0167] It is not difficult to understand that this application focuses on the detection and classification of multiple types of malicious documents. The key technical points involved are as follows: (1) In the feature extraction stage, some embodiments of this application combine local information and global information to extract features. The global feature information is extracted into the global feature matrix, and the local feature information is extracted into the 2-grams frequency matrix and the indirect 2-grams frequency matrix, respectively, providing richer feature information; (2) In the feature fusion stage, some embodiments of this application use minimum-maximum normalization and DCT transformation technology, which can standardize data, unify scale and desparse. After DCT transformation, the low-frequency signal in the image is mainly in the upper left corner, which describes the main part of the image and is the key to image recognition. The high-frequency signal is mainly in the lower right corner, which describes some details of the image. Removing some high-frequency signals does not have a significant impact on the image; (3) In some embodiments of this application, the MBCon structure in the EfficientNet-B2 model is improved. The ordinary convolution module is replaced with grouped convolution, and then channel recombination operation is performed. A spatial attention SAM module is added after the channel attention SE module. Grouped convolution can reduce the number of parameters and computational overhead. Channel reorganization can enhance the information flow between the feature channels of each group. Although adding the SAM module increases the computational load slightly, it can make the network pay more attention to the pixels in the image that play a decisive role in detection or classification and ignore irrelevant pixels, which greatly improves the overall performance of the model. (4) The model loss function has been improved. Some embodiments of this application design a way to add weight coefficients to the relevant classes in the loss function for imbalanced datasets, thereby indirectly reducing the classification weight of classes with more samples or relatively increasing the classification weight of classes with fewer samples. At the same time, an adjustable loss function is designed, similar to a gate switch. When training the model on a balanced or imbalanced dataset, it is necessary to switch to the corresponding loss function independently.
[0168] like Figure 6 As shown, some embodiments of this application provide a method for classifying documents, the method comprising: S201, obtaining a target three-channel RGB color feature image based on the global feature matrix and at least one local feature matrix of the document to be classified; S202, obtaining the target category of the document to be classified based on the target document classification model obtained by the training method described above and the target three-channel RGB color feature image.
[0169] In some embodiments of this application, obtaining the target three-channel RGB color feature image based on the global feature matrix of the document to be classified and at least one local feature matrix includes: performing at least normalization processing and DCT transformation processing on the global feature matrix, the first local feature matrix, and the second local feature matrix to obtain the three-channel RGB color feature image.
[0170] Please refer to Figure 7 , Figure 7 The apparatus for training a document classification model provided in the embodiments of this application is shown. It should be understood that this apparatus is similar to the one described above. Figure 2 Corresponding to the method embodiments, it is capable of executing the various steps involved in the above method embodiments. The specific functions of the device can be found in the description above. To avoid repetition, detailed descriptions are appropriately omitted here. The device includes at least one software function module that can be stored in a memory or embedded in the device's operating system in the form of software or firmware. The device for training a document classification model includes: a feature image acquisition module 301, a preprocessing module 302, and a training model 303.
[0171] The feature extraction module is configured to obtain a global feature matrix and at least one local feature matrix of a document, wherein the document belongs to a file in the training set.
[0172] The preprocessing module is configured to preprocess the global feature matrix and the at least one local feature matrix before fusing them to obtain a three-channel RGB color feature image, wherein the preprocessing includes min-max normalization and / or DCT transform operation.
[0173] The training module is configured to train the document classification model to be trained using the three-channel RGB color feature image to obtain the target document classification model.
[0174] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the device described above can be referred to the corresponding process in the aforementioned method, and will not be elaborated further here.
[0175] Please refer to Figure 8 , Figure 8 The present application illustrates an apparatus for classifying documents according to an embodiment of the present application. It should be understood that this apparatus is similar to the one described above. Figure 6 Corresponding to the method embodiments, it is capable of executing the various steps involved in the above method embodiments. The specific functions of the device can be found in the description above; to avoid repetition, detailed descriptions are appropriately omitted here. The device includes at least one software functional module that can be stored in a memory or embedded in the device's operating system in the form of software or firmware. The device for training a document classification model includes: a preprocessing module 401 and a classification module 402.
[0176] The preprocessing module is configured to obtain a three-channel RGB color feature image based on the global feature matrix and at least one local feature matrix of the document to be classified.
[0177] The classification module is configured to obtain the target category of the document to be classified based on the target document classification model and the three-channel RGB color feature image.
[0178] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the device described above can be referred to the corresponding process in the aforementioned method, and will not be elaborated further here.
[0179] Some embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can implement the methods described in any of the embodiments included in the above methods.
[0180] like Figure 9 As shown, some embodiments of this application provide an electronic device 500, including a memory 510, a processor 520, and a computer program stored in the memory 510 and executable on the processor 520, wherein the processor 520 can implement the methods described in any of the embodiments included in the above methods when it reads and executes the program via a bus 530.
[0181] Processor 520 can process digital signals and can include various computing architectures. For example, it can be a complex instruction set computer architecture, a reduced instruction set computer architecture, or an architecture that implements multiple instruction set combinations. In some examples, processor 520 can be a microprocessor.
[0182] The memory 510 can be used to store instructions executed by the processor 520 or data related to the execution of instructions. These instructions and / or data may include code used to implement some or all of the functions of one or more modules described in the embodiments of this application. The processor 520 of the embodiments of this disclosure can be used to execute the instructions in the memory 510 to implement… Figure 2 or Figure 6 The method shown. Memory 510 includes dynamic random access memory, static random access memory, flash memory, optical memory, or other memory well known to those skilled in the art.
[0183] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0184] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0185] If the aforementioned functions are implemented as software functional modules 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 this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0186] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application. It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0187] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0188] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
Claims
1. A method for training a document classification model, characterized in that, The method includes: Obtain the global feature matrix and at least one local feature matrix of the document, wherein the document belongs to a file in the training set; the at least one local feature matrix includes a first local feature matrix and a second local feature matrix, wherein the first local feature matrix is used to characterize the byte value transition probability of adjacent bytes, and the second local feature matrix is used to characterize the byte value transition probability of spaced bytes; The global feature matrix and the at least one local feature matrix are preprocessed and then fused to obtain a three-channel RGB color feature image. The preprocessing includes normalization and / or DCT transform operations. The process of preprocessing the global feature matrix and the at least one local feature matrix and then fusing them to obtain a three-channel RGB color feature image includes: performing the normalization process on the global feature matrix, the first local feature matrix, and the second local feature matrix respectively to obtain three normalized feature matrices; and performing feature fusion based on the three normalized feature matrices to obtain the three-channel RGB color feature image. The three-channel RGB color feature image is used to train the document classification model to obtain the target document classification model. The document classification model to be trained includes an improved MBConv structure, which includes: a grouped convolutional layer for channel expansion, a channel recombination operation layer for enhancing information interaction between channels, and a spatial attention SAM module located after the channel attention (SE) module. The process of training the document classification model to obtain the target document classification model using the three-channel RGB color feature image includes: if the total number of samples in each type of document sample is balanced, the cross-entropy loss function is selected as the target loss function; if the total number of samples in each type of document sample is unbalanced, the focus loss function is selected as the target loss function; and the parameters of the document classification model to be trained are adjusted using the target loss function to obtain the target document classification model.
2. The method as described in claim 1, characterized in that, The step of obtaining the three-channel RGB color feature image by feature fusion based on the three normalized feature matrices includes: Perform DCT transformation on the three normalized feature matrices respectively to obtain three DCT transformation feature matrices; The normalization, dimensionality transformation, and merging processes are performed on at least the three DCT transform feature matrices to obtain the three-channel RGB color feature image.
3. The method as described in claim 1 or 2, characterized in that, The document classification model to be trained includes: a first convolutional feature extraction layer, repeatedly stacked MBConv feature extraction layers, a convolutional dimensionality reduction layer, a pooling layer, and a fully connected layer, wherein each MBConv feature extraction layer further includes: a grouped convolutional layer.
4. The method as described in claim 1, characterized in that, The step of training the document classification model using the three-channel RGB color feature image includes: obtaining a predicted classification result for the document based on the document classification model and the three-channel RGB color feature image, and adjusting the parameters of the document classification model based on the predicted classification result.
5. The method as described in claim 4, characterized in that, The step of adjusting the parameters of the document classification model to be trained based on the predicted classification result includes: Choose one from the cross-entropy loss function and the class-balanced focus loss function as the target loss function. The class-balanced focus loss function is obtained by multiplying each term in the focus loss function by the class-balanced weight factor and then adding them together. Each term in the focus loss function is used to characterize the loss value of a class of document samples. The class-balanced weight factor is related to the difference between the total number of samples in the corresponding class of documents and the total number of samples in other class of documents. The loss function value is obtained based on the predicted classification result and the target loss function; The parameters are adjusted based on the loss function value.
6. The method as described in claim 5, characterized in that, Class balance weight factor corresponding to the j-th class document sample Characterized as: in, This represents the total number of original document samples contained in the j-th type of document, and k represents the total number of document sample categories.
7. The method as described in claim 5, characterized in that, The formula for calculating the loss value corresponding to the j-th term in the focusing loss function is as follows: Where, p ij Let k be the predicted probability that the i-th sample belongs to the j-th class of document samples, where k represents the number of document sample classes. γ is a modulo factor, and γ is an adjustable focusing parameter. .
8. A method for classifying documents, characterized in that, The method includes: The target three-channel RGB color feature image is obtained based on the global feature matrix and at least one local feature matrix of the document to be classified; The target category of the document to be classified is obtained based on the target document classification model obtained by any one of the methods in claims 1-7 and the target three-channel RGB color feature image.
9. The method as described in claim 8, characterized in that, The method further includes: The three-channel RGB color feature image is obtained by performing at least normalization and DCT transformation on the global feature matrix, the first local feature matrix, and the second local feature matrix.
10. An apparatus for training a document classification model, characterized in that, The device includes: The feature extraction module is configured to obtain a global feature matrix and at least one local feature matrix of a document, wherein the document belongs to a file in the training set; the at least one local feature matrix includes a first local feature matrix and a second local feature matrix, wherein the first local feature matrix is used to characterize the byte value transition probability of adjacent bytes, and the second local feature matrix is used to characterize the byte value transition probability of spaced bytes. A preprocessing module is configured to preprocess the global feature matrix and the at least one local feature matrix before fusing them to obtain a three-channel RGB color feature image. The preprocessing operation includes min-max normalization and / or DCT transform. The preprocessing of the global feature matrix and the at least one local feature matrix before fusing them to obtain a three-channel RGB color feature image includes: performing the normalization operation on the global feature matrix, the first local feature matrix, and the second local feature matrix respectively to obtain three normalized feature matrices; and performing feature fusion based on the three normalized feature matrices to obtain the three-channel RGB color feature image. The training module is configured to train the document classification model to be trained using the three-channel RGB color feature image to obtain the target document classification model. The document classification model to be trained includes an improved MBConv structure, which includes: a grouped convolutional layer for channel expansion, a channel recombination operation layer for enhancing information interaction between channels, and a spatial attention SAM module located after the channel attention SE module. The step of training the document classification model to be trained using the three-channel RGB color feature image to obtain the target document classification model includes: if the total number of samples in each type of document sample is balanced, selecting the cross-entropy loss function as the target loss function; if the total number of samples in each type of document sample is unbalanced, selecting the focus loss function as the target loss function; and adjusting the parameters of the document classification model to be trained using the target loss function to obtain the target document classification model.
11. An apparatus for classifying documents, characterized in that, The device includes: The preprocessing module is configured to obtain a three-channel RGB color feature image based on the global feature matrix and at least one local feature matrix of the document to be classified; The classification module is configured to obtain the target category of the document to be classified based on the target document classification model obtained as claimed in claim 10 and the three-channel RGB color feature image.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by a processor, it can implement the method described in any one of claims 1-9.
13. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein, When the processor executes the program, it can implement the method as described in any one of claims 1-9.
Citation Information
Patent Citations
A Malicious Document Detection Method Based on Three-Channel Markov Graphs
CN115080969B
Malicious software classification method based on three-channel image
CN113282926A
Malicious document detection method based on three-channel Markov graph
CN115080969A
