Coding method and device, equipment, storage medium and product

By optimizing the coding parameters through subset segmentation and iterative training of non-numeric feature sets, multi-thread parallel coding is adopted, and the storage method is selected according to the number and discreteness of features, which solves the problem of low single-thread coding efficiency and improves coding efficiency and quality. , reducing storage resource requirements.

CN118780243APending Publication Date: 2024-10-15HANGZHOU HAILIANG DIGITAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410771368.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-14
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

The single-threaded serial encoding of non-numeric features in the existing technology is inefficient, resulting in low coding quality and excessive storage resources, making it impossible to effectively process a large number of non-numeric features.

Method used

By dividing the feature set to be encoded into multiple subsets, iterative training is performed based on encoding parameters, the encoding parameters are adjusted to optimize the encoding process, multiple threads are used for parallel encoding, and appropriate storage methods are selected based on the number and discreteness of features to reduce the amount of calculations. and storage resources.

Benefits of technology

It improves the efficiency and quality of non-numeric feature encoding, reduces the calculation amount and storage resource requirements of single-thread encoding, and achieves a more efficient encoding process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118780243A_ABST
    Figure CN118780243A_ABST
Patent Text Reader

Abstract

The invention provides a coding method and device, equipment, a storage medium and a product, and the method comprises the steps: obtaining a to-be-coded feature set, and dividing the to-be-coded feature set into a plurality of subsets; selecting a current target subset from the current uncoded subset, coding the target subset based on the current coding parameter to obtain a predictive coding resource and an actual coding resource, and carrying out iterative training on the gradient model by adopting a loss function based on the predictive coding resource and the actual coding resource to obtain a predicted coding resource and an actual coding resource; the coding parameter is updated based on an iteration training result, the step of selecting the current target subset from the current uncoded subset is executed again until iteration is completed to obtain a first coding parameter, and the iteration training result comprises a gradient parameter; and coding all uncoded subsets in the to-be-coded feature set by adopting the first coding parameter. According to the method provided by the invention, the efficiency and quality of non-numerical feature coding can be improved, and the calculation amount and storage resources required by single-thread coding are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of educational technology, and in particular to an encoding method, device, equipment, storage medium and product. Background Art

[0002] The algorithm model cannot process non-numerical features, so before training the algorithm model, the non-numerical features need to be encoded and converted into numerical features.

[0003] The current method for encoding non-numerical features is to use single-threaded serial encoding to encode each non-numerical feature in turn until all non-numerical features are encoded. However, the single-threaded serial encoding has a large amount of calculation, and the efficiency and quality of encoding non-numerical features are low. The low encoding quality will result in excessive storage resources occupied after encoding. Summary of the invention

[0004] The present application provides a coding method, apparatus, device, storage medium and product, which can improve the efficiency and quality of non-numerical feature coding and reduce the computing amount and storage resources required for single-threaded coding.

[0005] In a first aspect, the present application provides an encoding method, the method comprising:

[0006] Obtain a feature set to be encoded, the feature set to be encoded includes non-numerical features to be encoded, and divide the feature set to be encoded into multiple subsets;

[0007] Selecting a target subset from the subset that has not been encoded, encoding the target subset based on the current encoding parameters, and obtaining predicted encoding resources and actual encoding resources, wherein the predicted encoding resources are predicted resources required for encoding the target subset based on the encoding parameters, and the actual encoding resources are resources actually consumed for encoding the target subset based on the encoding parameters;

[0008] Based on the predicted coding resources and the actual coding resources, the gradient model is iteratively trained using a loss function, the coding parameters are updated based on the iterative training results, and the step of selecting the target subset from the current uncoded subset is returned to execute until the iteration is completed to obtain the first coding parameters, and the iterative training results include the gradient parameters;

[0009] The first encoding parameter is used to encode all subsets of the feature set to be encoded that have not been encoded.

[0010] In one example, the method further includes:

[0011] Determine whether the number of non-numerical features to be encoded in the target subset exceeds a first threshold;

[0012] If the number of non-numerical features does not exceed a preset first threshold, a preset encoding method is used to encode the non-numerical features to obtain encoded data, and the encoded data is stored in a first storage method; the first storage method includes: if the size of the encoded data does not exceed a preset second threshold, the encoded data is stored in a preset data structure, otherwise, the encoded data is stored in a matrix;

[0013] If the number of non-numerical features exceeds a preset first threshold, the non-numerical features are encoded using a preset encoding method to obtain encoded data, and the encoded data is stored in a second storage method; the second storage method includes: if the size of the encoded data does not exceed the preset second threshold, the encoded data is stored in a matrix, otherwise, part of the encoded data is stored in the matrix, and the rest of the data is cached in a cache, and the data amount of the part of the data is the second threshold.

[0014] In one example, storing the encoded data into a matrix includes:

[0015] Determine the discreteness of the non-numerical features to be encoded in the target subset;

[0016] If the discreteness does not exceed the preset third threshold, the encoded data is stored in a sparse matrix; if the discreteness exceeds the preset third threshold, the encoded data is stored in a dense matrix.

[0017] In one example, updating the encoding parameters based on the iterative training results includes:

[0018] Get the current gradient parameters of the gradient model and the bias items corresponding to the encoding parameters;

[0019] The preset first coefficient, the gradient parameter and the coding parameter are multiplied to obtain a calculation result, and the calculation result is added to the bias item corresponding to the coding parameter to obtain an updated coding parameter.

[0020] In one example, the method further includes:

[0021] Get source data;

[0022] Split the source data to obtain a numerical feature set and a non-numerical feature set;

[0023] Determine the number of non-numerical features in the non-numerical feature set. If the number of non-numerical features exceeds a preset fourth threshold, sample the non-numerical features in the non-numerical feature set and set the extracted non-numerical features as the feature set to be encoded; if the number of features does not exceed the preset fourth threshold, use the non-numerical feature set as the feature set to be encoded.

[0024] In one example, the method further includes:

[0025] The encoded data obtained after encoding each subset in the feature set to be encoded is merged with the data in the numerical feature set.

[0026] In a second aspect, the present application provides an encoding device, the device comprising:

[0027] An acquisition module is used to acquire a feature set to be encoded, the feature set to be encoded includes non-numerical features to be encoded, and divide the feature set to be encoded into multiple subsets;

[0028] A processing module, used to select a target subset from a subset that has not been encoded currently, encode the target subset based on current encoding parameters, and obtain predicted encoding resources and actual encoding resources, wherein the predicted encoding resources are predicted resources required for encoding the target subset based on the encoding parameters, and the actual encoding resources are resources actually consumed for encoding the target subset based on the encoding parameters;

[0029] An iteration module, configured to iteratively train a gradient model using a loss function based on predicted coding resources and actual coding resources, update coding parameters based on iterative training results, and return to execute the step of selecting a target subset from a currently uncoded subset until the iteration is completed to obtain a first coding parameter, wherein the iterative training results include gradient parameters;

[0030] The encoding module is used to encode all the subsets in the feature set to be encoded that have not been encoded by using the first encoding parameter.

[0031] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;

[0032] Memory stores computer-executable instructions;

[0033] The processor executes the computer-executable instructions stored in the memory to implement any of the above methods.

[0034] In a fourth aspect, the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement any of the methods described above.

[0035] In a fifth aspect, the present application provides a computer program product, comprising a computer program, which implements any of the methods described above when executed by a processor.

[0036] The encoding method, device, equipment, storage medium and product provided by the present application divide the feature set to be encoded into multiple subsets, encode the selected target subset based on the current encoding parameters, obtain the predicted encoding resources and the actual encoding resources, and use the loss function to iteratively train the gradient model based on the predicted encoding resources and the actual encoding resources until the iteration is completed to obtain the first encoding parameters, and then use the first encoding parameters to encode all the subsets that have not been encoded. In the process of encoding the feature to be encoded, the present application uses the gradient model for iterative training to adjust the encoding parameters and obtain the first encoding parameters. The first encoding parameters are the most preferred encoding parameters obtained based on the iterative training, including CPU, task concurrency and storage memory. Therefore, the first encoding parameters are used to encode the feature set to be encoded, and multiple threads can be used to encode the feature set to be encoded at the same time, which can speed up the encoding speed of the feature set to be encoded, improve the encoding efficiency and quality of the feature set to be encoded, and reduce the amount of calculation and storage resources required for single-threaded encoding. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0038] Figure 1 An application scenario diagram of an example of the prior art;

[0039] Figure 2 A schematic diagram of a flow chart of an encoding method provided in Example 1 of the present application;

[0040] Figure 3 The usage scenario of parallel encoding of the RMSProp gradient model for the example;

[0041] Figure 4 A flowchart of another encoding method provided in Example 1 of the present application;

[0042] Figure 5 A flowchart of another encoding method provided in Embodiment 1 of the present application;

[0043] Figure 6 A flowchart of another encoding method provided in Embodiment 1 of the present application;

[0044] Figure 7 A flowchart of another encoding method provided in Embodiment 1 of the present application;

[0045] Figure 8 A schematic diagram of the structure of an encoding device provided in Embodiment 2 of the present application;

[0046] Fig. 9This is a schematic diagram of the structure of an electronic device provided in Example 3 of the present application.

[0047] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0048] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0049] Figure 1 This is an application scenario diagram of an existing technology example, such as Figure 1 As shown, the algorithm model cannot process non-numerical features, so before training the algorithm model, the non-numerical features need to be encoded, converted into numerical features, and then merged with the numerical features that do not need to be encoded and transmitted to the algorithm model.

[0050] The current method for encoding non-numerical features is to use single-threaded serial encoding to encode each non-numerical feature in turn until all non-numerical features are encoded. However, the single-threaded serial encoding has a large amount of calculation and is inefficient in encoding non-numerical features.

[0051] The present application divides the feature set to be encoded into multiple subsets, encodes the selected target subset based on the current encoding parameters, obtains predicted encoding resources and actual encoding resources, and uses a loss function to iteratively train the gradient model based on the predicted encoding resources and the actual encoding resources until the iteration is completed to obtain the first encoding parameters, and then uses the first encoding parameters to encode all subsets that have not been encoded. In the process of encoding the feature to be encoded, the present application iteratively trains the gradient model to adjust the encoding parameters and obtain the first encoding parameters. The first encoding parameters are the most preferred encoding parameters obtained based on iterative training, including CPU, task concurrency and storage memory. Therefore, the first encoding parameters are used to encode the feature set to be encoded, and multiple threads can be used to encode the feature set to be encoded at the same time, which can speed up the encoding speed of the feature set to be encoded, improve the encoding efficiency and quality of the feature set to be encoded, and reduce the computational complexity and storage resources required for single-threaded encoding.

[0052] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0053] Embodiment 1

[0054] Figure 2 A schematic diagram of a coding method provided in Example 1 of the present application is shown in FIG. Figure 2 As shown, the method includes:

[0055] Step 201: Obtain a feature set to be encoded, the feature set to be encoded includes non-numerical features to be encoded, and divide the feature set to be encoded into multiple subsets;

[0056] Step 202: Select a target subset from the subset that has not been encoded, encode the target subset based on the current encoding parameters, and obtain predicted encoding resources and actual encoding resources, wherein the predicted encoding resources are predicted resources required for encoding the target subset based on the encoding parameters, and the actual encoding resources are resources actually consumed for encoding the target subset based on the encoding parameters;

[0057] Step 203: Based on the predicted coding resources and the actual coding resources, the gradient model is iteratively trained using a loss function, the coding parameters are updated based on the iterative training results, and the step of selecting the target subset from the current uncoded subset is returned to be executed until the iteration is completed to obtain the first coding parameters, and the iterative training results include the gradient parameters;

[0058] Step 204: Use the first encoding parameter to encode all subsets in the feature set to be encoded that have not been encoded.

[0059] Combined with the scenario example, the feature set to be encoded is a feature set composed of non-numerical features. The feature set to be encoded can be divided into multiple subsets according to the fixed number of non-numerical features, and then each subset is encoded in turn. One of the unencoded subsets can be used as the target subset to be encoded in this iteration. The ways to encode non-numerical features include Label Encoding, Ordinal Encoding, One-Hot Encoding, Count Encoding, TargetEncoding, StringIndex Encoding, etc. Users can choose the appropriate encoding method according to actual needs. Get the current encoding parameters, which include: Central Processing Unit (CPU), task concurrency and storage memory. Task concurrency represents the number of threads that perform encoding processing at the same time.

[0060] The encoding parameter can be recorded as x i , the predictive coding resource can be recorded as h θ (x i ), the actual encoding resource is recorded as y i , wherein the predicted coding resource can be calculated according to the following first formula:

[0061] First formula: h θ (x i )=θ t-1 +θ t x i

[0062] where θ t is the gradient parameter of the gradient model at time t, θ t The calculation of can be obtained by the following second formula:

[0063] Second formula:

[0064] Among them, α represents the global learning rate, ε is a constant, which can be taken as

[0065] In the second formula, Characterizes the gradient at time t; It represents the mean of the square of the gradient parameters of the previous t times, where β is the momentum factor, which is generally 0.1-0.9.

[0066] The loss function is the third formula below:

[0067] The third formula:

[0068] The gradient model used in this example can be selected as the RMSProp gradient model. Figure 3In the example of the use scenario of RMSProp gradient model parallel coding, the target subset is encoded based on the coding parameters to obtain the actual coding resources. The coding resources are the number of coding threads, computing resources and storage resources used in the coding process. J(θ) obtained based on the loss function can be characterized as the error value between the predicted coding resources and the actual coding resources. If the error value is less than the preset threshold, or the number of iterations reaches the preset maximum value, the iteration is characterized to be completed. If the error value is not less than the preset threshold, and the number of iterations does not reach the preset maximum value, the gradient parameters are updated based on the second formula to obtain the iterative training result of this time, and the updated gradient parameters are used to adjust the coding parameters. The next target subset is iteratively calculated based on the adjusted coding parameters until the first coding parameters are obtained after the iteration is completed. The first coding parameter is the coding parameter adjusted after the iteration is completed. After that, for the subset of non-numerical features that have not been encoded, the first coding parameter can be directly used for encoding processing until all subsets of non-numerical features are encoded.

[0069] In the process of encoding the features to be encoded in this example, iterative training is performed through the gradient model to adjust the encoding parameters and obtain the first encoding parameters. The first encoding parameters are the most preferred encoding parameters obtained based on the iterative training, including CPU, task concurrency and storage memory. Therefore, the first encoding parameters are used to encode the feature set to be encoded, and multiple threads can be used to encode the feature set to be encoded at the same time, which can speed up the encoding speed of the feature set to be encoded, improve the encoding efficiency and quality of the feature set to be encoded, and reduce the computing power and storage resources required for single-thread encoding.

[0070] Optional, Figure 4 A flowchart of another encoding method provided in Example 1 of the present application is shown as follows: Figure 4 As shown, the method also includes:

[0071] Step 401, determining whether the number of non-numerical features to be encoded in the target subset exceeds a first threshold;

[0072] Step 402: if the number of non-numerical features does not exceed a preset first threshold, the non-numerical features are encoded using a preset encoding method to obtain encoded data, and the encoded data is stored in a first storage method; the first storage method includes: if the size of the encoded data does not exceed a preset second threshold, the encoded data is stored in a preset data structure, otherwise, the encoded data is stored in a matrix;

[0073] Step 403: If the number of non-numerical features exceeds a preset first threshold, a preset encoding method is used to encode the non-numerical features to obtain encoded data, and the encoded data is stored in a second storage method; the second storage method includes: if the size of the encoded data does not exceed the preset second threshold, the encoded data is stored in a matrix, otherwise, part of the encoded data is stored in the matrix, and the rest of the data is cached in a cache, and the data amount of the part of the data is the second threshold.

[0074] Combined with the scenario example, after the non-numerical features in the target subset are encoded, the encoded data needs to be stored. First, it can be determined whether the number of non-numerical features in the target subset exceeds the first threshold. For example, the first threshold can be set to 1000. If the number of non-numerical features in the target subset does not exceed 1000, the first storage method is used to store the encoded data after the non-numerical features are encoded. If the number of non-numerical features in the target subset exceeds 1000, the second storage method is used to store the encoded data after the non-numerical features are encoded.

[0075] Specifically, if the number of non-numerical features in the target subset does not exceed 1000, then the non-numerical features in the target subset are first deduplicated, and then the encoding of the non-data features in the target subset is completed using the encoding method selected by the user, and then it is determined whether the size of the encoded data exceeds the second threshold. For example, the second threshold may be 20M. If the encoded data does not exceed 20M, the encoded data may be stored in a preset data structure. For example, the preset data structure may be a Linked Hash Map data structure of PySpark. If the encoded data exceeds 20M, the encoded data may be stored in a matrix, such as a sparse matrix or a dense matrix. If the number of non-numerical features in the target subset exceeds 1000, then the non-numerical features in the target subset are first deduplicated, and then the encoding of the non-data features in the target subset is completed using the encoding method selected by the user, and then it is determined whether the size of the encoded data exceeds the second threshold. For example, the second threshold may be 20M. If the encoded data does not exceed 20M, the encoded data may be stored in a matrix, such as a sparse matrix or a dense matrix. If the encoded data exceeds 20M, the 20M data is first stored in the matrix, and the data exceeding 20M is stored in the cache. The matrix and PySpark's Linked Hash Map data structure are both located in the memory, and the storage resources occupied by the encoded data include the storage space occupied in the memory and the storage space occupied in the cache. Based on the method provided in this example, the storage method of the encoded data can be determined, which can improve the encoding speed of non-numerical features.

[0076] Optional, Figure 5A flowchart of another encoding method provided in Example 1 of the present application is shown as follows: Figure 5 As shown, storing the encoded data into a matrix includes:

[0077] Step 501, determining the discreteness of the non-numerical features to be encoded in the target subset;

[0078] Step 502: If the discreteness does not exceed the preset third threshold, the encoded data is stored in a sparse matrix; if the discreteness exceeds the preset third threshold, the encoded data is stored in a dense matrix.

[0079] Combined with the scenario example, the discreteness of non-numerical features can be the ratio between the number of feature categories of non-numerical features and the total number of non-numerical features. For example, there are 500 elements in the target subset, that is, the total number of non-numerical features is 500. Among these 500 non-numerical features, the feature categories are feature A, feature B, feature C, feature D and feature E. Even if the non-numerical features that meet each feature category are inconsistent, there are only 5 different feature categories in the target subset. At this time, the discreteness of the target subset is 5 / 500*100%, that is, 1%, and the discreteness of non-numerical features is low. Similarly, if the total number of non-numerical features in the target subset is 500, but the number of feature categories is 200, the number of feature categories is large, and the number of non-numerical features that meet each feature category is small. At this time, the discreteness of the target subset is 200 / 500*100%, that is, 40%, and the discreteness of non-numerical features is high.

[0080] Therefore, a third threshold value for discreteness can be set, for example, the third threshold value is set to 10%. If the discreteness of the non-numerical features to be encoded in the target subset exceeds 10%, the encoded data is then stored in a dense matrix. If the discreteness of the non-numerical features in the target subset does not exceed 10%, the encoded data is stored in a coefficient matrix. Based on the method provided in this example, the matrix type in which the encoded data is stored can be determined, which can improve the encoding speed of non-numerical features.

[0081] Optional, Figure 6 A flowchart of another encoding method provided in Example 1 of the present application is shown as follows: Figure 6 As shown, in step 203, updating the encoding parameters based on the iterative training results includes:

[0082] Step 601: Obtain the current gradient parameters of the gradient model and the bias items corresponding to the encoding parameters;

[0083] Step 602: multiply the preset first coefficient, the gradient parameter and the coding parameter to obtain a calculation result, and add the calculation result and the bias item corresponding to the coding parameter to obtain an updated coding parameter.

[0084] Combined with the scenario example, the number of CPU cores in the encoding parameters can be recorded as C, and the bias item corresponding to the number of CPU cores can be recorded as C0; the memory coefficient can be recorded as M, and the bias item corresponding to the memory coefficient can be recorded as M0; the concurrency coefficient can be recorded as P, and the bias item corresponding to the concurrency coefficient can be recorded as P0.

[0085] For the update of CPU, memory and task concurrency, the first coefficient can be set to 10; the bias terms are: C0, M0 and P0; the gradient parameter is θ(t); the fourth formula, the fifth formula and the sixth formula below can be used in turn to update, and the updated CPU, memory and task concurrency can be obtained respectively;

[0086] The fourth formula: x ci =θ(t)*C*10+C0

[0087] Fifth formula: x mi =θ(t)*M*10+M0

[0088] Sixth formula: x pi =θ(t)*P*10+P0

[0089] Based on the method provided in this example, the purpose of updating the encoding parameters can be achieved.

[0090] Optional, Figure 7 A flowchart of another encoding method provided in Example 1 of the present application is shown as follows: Figure 7 As shown, the method also includes:

[0091] Step 701: Obtain source data;

[0092] Step 702: Split the source data to obtain a numerical feature set and a non-numerical feature set;

[0093] Step 703: determine the number of non-numerical features in the non-numerical feature set. If the number of non-numerical features exceeds a preset fourth threshold, sample the non-numerical features in the non-numerical feature set and set the extracted non-numerical features as the feature set to be encoded; if the number of features does not exceed the preset fourth threshold, set the non-numerical feature set as the feature set to be encoded.

[0094] Combined with the scenario example, before encoding the non-numerical features in the target subset, you can first use PySpark to create a SparkSession. PySpark is the Python interface of Apache Spark, which is used to run Python applications in parallel on a distributed cluster. Apache Spark is a fast and general computing engine designed for large-scale data processing. SparkSession provides users with a unified entry point to use various functions of Spark. The source data is the training data used to train the algorithm model, which includes numerical features and non-numerical features. PySpark can be used to obtain the type of each feature data in the source data, and the source data can be split according to numerical features and non-numerical features to obtain numerical feature sets and non-numerical feature sets. If there are too many non-numerical features in the non-numerical feature set, it is necessary to sample the non-numerical feature set and set the sampled non-numerical feature set as the feature set to be encoded. For example, the fourth threshold value may be set to 5000. If the number of non-numerical features in the non-numerical feature set exceeds 5000, 5000 non-numerical features are extracted from the non-numerical feature set as the feature set to be encoded. However, if the number of non-numerical features in the non-numerical feature set does not exceed 5000, the non-numerical feature set is directly used as the feature set to be encoded. Based on the method provided in this example, it is possible to determine whether the non-numerical features in the non-numerical feature set need to be sampled based on whether the number of non-numerical features in the non-numerical feature set exceeds the fourth threshold value, thereby obtaining the feature set to be encoded.

[0095] Optionally, the method further includes:

[0096] The encoded data obtained after encoding each subset in the feature set to be encoded is merged with the data in the numerical feature set.

[0097] Since the purpose of encoding the non-numerical features in the feature set to be encoded is to encode them into numerical features so as to train the algorithm model, after completing the encoding of the non-numerical features in each subset of the feature set to be encoded, the encoded data, that is, the encoded numerical features can be merged with the numerical features in the source data that do not need to be encoded, and then the merged data can be used to complete the training of the algorithm model.

[0098] In the process of encoding the features to be encoded, this embodiment uses iterative training through the gradient model to adjust the encoding parameters and obtain the first encoding parameters. The first encoding parameters are the most preferred encoding parameters obtained based on the iterative training, including CPU, task concurrency and storage memory. Therefore, the first encoding parameters are used to encode the feature set to be encoded, and multiple threads can be used to encode the feature set to be encoded at the same time, which can speed up the encoding speed of the feature set to be encoded, improve the encoding efficiency and quality of the feature set to be encoded, and reduce the computing power and storage resources required for single-thread encoding.

[0099] Embodiment 2

[0100] Figure 8 A schematic diagram of the structure of an encoding device provided in Embodiment 2 of the present application is shown in FIG. Figure 8 As shown, the device comprises:

[0101] An acquisition module 81 is used to acquire a feature set to be encoded, the feature set to be encoded includes non-numerical features to be encoded, and divide the feature set to be encoded into multiple subsets;

[0102] The processing module 82 is used to select a target subset from the subset that has not been encoded currently, encode the target subset based on the current encoding parameters, and obtain predicted encoding resources and actual encoding resources, wherein the predicted encoding resources are predicted resources required for encoding the target subset based on the encoding parameters, and the actual encoding resources are resources actually consumed for encoding the target subset based on the encoding parameters;

[0103] An iteration module 83 is used to iteratively train the gradient model using a loss function based on the predicted coding resources and the actual coding resources, update the coding parameters based on the iterative training results, and return to execute the step of selecting the target subset from the current uncoded subset until the iteration is completed to obtain the first coding parameters, and the iterative training results include the gradient parameters;

[0104] The encoding module 84 is used to encode all the subsets in the feature set to be encoded that have not been encoded by using the first encoding parameter.

[0105] Combined with the scenario example, the feature set to be encoded is a feature set composed of non-numerical features. The acquisition module 81 can divide the feature set to be encoded into multiple subsets according to the fixed number of non-numerical features, and then the processing module 82 encodes each subset in turn. One of the unencoded subsets can be used as the target subset to be encoded in this iteration. The ways to encode non-numerical features include Label Encoding, Ordinal Encoding, One-Hot Encoding, CountEncoding, Target Encoding, StringIndex Encoding, etc. Users can choose the appropriate encoding method according to actual needs. Get the current encoding parameters, the encoding parameters include: Central Processing Unit (CPU), task concurrency and storage memory, the task concurrency represents the number of threads that are encoded at the same time.

[0106] The encoding parameter can be recorded as x i , the predictive coding resource can be recorded as h θ (x i ), the actual encoding resource is recorded as y i , wherein the predicted coding resource can be calculated according to the following first formula:

[0107] First formula: h θ (x i )=θ t-1 +θ t x i

[0108] where θ t is the gradient parameter of the gradient model at time t, θ t The calculation of can be obtained by the following second formula:

[0109] Second formula:

[0110] Among them, α represents the global learning rate, ε is a constant, which can be taken as

[0111] In the second formula, Characterizes the gradient at time t; It represents the mean of the square of the gradient parameters of the previous t times, where β is the momentum factor, which is generally 0.1-0.9.

[0112] The loss function is the third formula below:

[0113] The third formula:

[0114] The processing module 82 encodes the target subset based on the encoding parameters to obtain the actual encoding resources, and the encoding resources are the number of encoding threads, computing resources and storage resources used in the encoding process. The J(θ) obtained by the iteration module 83 based on the loss function can be characterized as the error value between the predicted encoding resources and the actual encoding resources. If the error value is less than the preset threshold, or the number of iterations reaches the preset maximum value, the iteration is characterized to be completed. If the error value is not less than the preset threshold, and the number of iterations does not reach the preset maximum value, the gradient parameter is updated based on the second formula to obtain the iterative training result of this time, and the updated gradient parameter is used to adjust the encoding parameter, and the next target subset is iteratively calculated based on the adjusted encoding parameter until the first encoding parameter is obtained after the iteration is completed. The first encoding parameter is the encoding parameter adjusted after the iteration is completed. After that, the encoding module 84 can directly use the first encoding parameter to encode the subset of non-numerical features that have not been encoded until all subsets of non-numerical features are encoded.

[0115] In the process of encoding the features to be encoded in this example, the iteration module 83 performs iterative training through the gradient model to adjust the encoding parameters and obtain the first encoding parameters. The first encoding parameters are the most preferred encoding parameters obtained based on the iterative training, including CPU, task concurrency and storage memory. Therefore, the encoding module 84 uses the first encoding parameters to encode the feature set to be encoded, and can use multiple threads to encode the feature set to be encoded at the same time, which can speed up the encoding speed of the feature set to be encoded, improve the encoding efficiency and quality of the feature set to be encoded, and reduce the computing power and storage resources required for single-threaded encoding.

[0116] Optionally, after the non-numerical features in the target subset are encoded, the processing module needs to store the encoded data. The processing module may first determine whether the number of non-numerical features in the target subset exceeds a first threshold value. For example, the first threshold value may be set to 1000. If the number of non-numerical features in the target subset does not exceed 1000, the first storage method is used to store the encoded data after the non-numerical features are encoded. If the number of non-numerical features in the target subset exceeds 1000, the second storage method is used to store the encoded data after the non-numerical features are encoded.

[0117] Specifically, if the number of non-numerical features in the target subset does not exceed 1000, then the non-numerical features in the target subset are first deduplicated, and then the encoding of the non-data features in the target subset is completed using the encoding method selected by the user, and then it is determined whether the size of the encoded data exceeds the second threshold. For example, the second threshold may be 20M. If the encoded data does not exceed 20M, the encoded data may be stored in a preset data structure. For example, the preset data structure may be a Linked Hash Map data structure of PySpark. If the encoded data exceeds 20M, the encoded data may be stored in a matrix, such as a sparse matrix or a dense matrix. If the number of non-numerical features in the target subset exceeds 1000, then the non-numerical features in the target subset are first deduplicated, and then the encoding of the non-data features in the target subset is completed using the encoding method selected by the user, and then it is determined whether the size of the encoded data exceeds the second threshold. For example, the second threshold may be 20M. If the encoded data does not exceed 20M, the encoded data may be stored in a matrix, such as a sparse matrix or a dense matrix. If the encoded data exceeds 20M, the 20M data is first stored in the matrix, and the data exceeding 20M is stored in the cache. The matrix and PySpark's Linked Hash Map data structure are both located in the memory, and the storage resources occupied by the encoded data include the storage space occupied in the memory and the storage space occupied in the cache. Based on the method provided in this example, the storage method of the encoded data can be determined, which can improve the encoding speed of non-numerical features.

[0118] Optionally, the discreteness of non-numerical features can be the ratio between the number of feature categories of non-numerical features and the total number of total non-numerical features. For example, there are 500 elements in the target subset, that is, the total number of non-numerical features is 500. Among these 500 non-numerical features, the feature categories are feature A, feature B, feature C, feature D and feature E. Even if the non-numerical features that meet each feature category are inconsistent, there are only 5 different feature categories in the target subset. In this case, the discreteness of the target subset is 5 / 500*100%, that is, 1%, and the discreteness of the non-numerical features is relatively low. Similarly, if the total number of non-numerical features in the target subset is 500, but the number of feature categories is 200, the number of feature categories is large, and the number of non-numerical features that meet each feature category is small. In this case, the discreteness of the target subset is 200 / 500*100%, that is, 40%, and the discreteness of the non-numerical features is relatively high.

[0119] Therefore, a third threshold value for discreteness can be set, for example, the third threshold value is set to 10%. If the discreteness of the non-numerical features to be encoded in the target subset exceeds 10%, the encoded data is then stored in a dense matrix. If the discreteness of the non-numerical features in the target subset does not exceed 10%, the encoded data is stored in a coefficient matrix. Based on the method provided in this example, the matrix type in which the encoded data is stored can be determined, which can improve the encoding speed of non-numerical features.

[0120] Optionally, the number of CPU cores in the encoding parameters may be denoted as C, and the bias term corresponding to the number of CPU cores may be denoted as C0; the memory coefficient may be denoted as M, and the bias term corresponding to the memory coefficient may be denoted as M0; the concurrency coefficient may be denoted as P, and the bias term corresponding to the concurrency coefficient may be denoted as P0.

[0121] For the update of CPU, memory and task concurrency, the first coefficient can be set to 10; the bias terms are: C0, M0 and P0; the gradient parameter is θ(t); the fourth formula, the fifth formula and the sixth formula below can be used in turn to update, and the updated CPU, memory and task concurrency can be obtained respectively;

[0122] The fourth formula: x ci =θ(t)*C*10+C0

[0123] Fifth formula: x mi =θ(t)*M*10+M0

[0124] Sixth formula: x pi =θ(t)*P*10+P0

[0125] Based on the method provided in this example, the purpose of updating the encoding parameters can be achieved.

[0126] Optionally, before encoding the non-numerical features in the target subset, you can first use PySpark to create a SparkSession. PySpark is the Python interface of Apache Spark, which is used to run Python applications in parallel on a distributed cluster. Apache Spark is a fast and general computing engine designed for large-scale data processing. SparkSession provides users with a unified entry point to use various functions of Spark. The source data is the training data used to train the algorithm model, which includes numerical features and non-numerical features. PySpark can be used to obtain the type of each feature data in the source data, and the source data can be split according to the numerical features and non-numerical features to obtain the numerical feature set and the non-numerical feature set. If there are too many non-numerical features in the non-numerical feature set, it is necessary to sample the non-numerical feature set and set the sampled non-numerical feature set as the feature set to be encoded. For example, the fourth threshold value may be set to 5000. If the number of non-numerical features in the non-numerical feature set exceeds 5000, 5000 non-numerical features are extracted from the non-numerical feature set as the feature set to be encoded. However, if the number of non-numerical features in the non-numerical feature set does not exceed 5000, the non-numerical feature set is directly used as the feature set to be encoded. Based on the method provided in this example, it is possible to determine whether the non-numerical features in the non-numerical feature set need to be sampled based on whether the number of non-numerical features in the non-numerical feature set exceeds the fourth threshold value, thereby obtaining the feature set to be encoded.

[0127] Since the purpose of encoding the non-numerical features in the feature set to be encoded is to encode them into numerical features so as to train the algorithm model, after completing the encoding of the non-numerical features in each subset of the feature set to be encoded, the encoded data, that is, the encoded numerical features can be merged with the numerical features in the source data that do not need to be encoded, and then the merged data can be used to complete the training of the algorithm model.

[0128] In the process of encoding the features to be encoded in this embodiment, the iteration module performs iterative training through the gradient model to adjust the encoding parameters and obtain the first encoding parameters. The first encoding parameters are the most preferred encoding parameters obtained based on the iterative training, including CPU, task concurrency and storage memory. Therefore, the encoding module uses the first encoding parameters to encode the feature set to be encoded, and can use multiple threads to encode the feature set to be encoded at the same time, which can speed up the encoding speed of the feature set to be encoded, improve the encoding efficiency and quality of the feature set to be encoded, and reduce the computing power and storage resources required for single-thread encoding.

[0129] Embodiment 3

[0130] Fig. 9 This is a schematic diagram of the structure of an electronic device provided in Example 3 of this application. Fig. 9 As shown, the electronic device may include: a transceiver 121 , a processor 122 , and a memory 123 .

[0131] The processor 122 executes the computer execution instructions stored in the memory, so that the processor 122 executes the scheme in the above embodiment. The processor 122 can be a general-purpose processor, including a central processing unit CPU, a network processor (network processor, NP), etc.; it can also be 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.

[0132] The memory 123 is connected to the processor 122 via a system bus and completes communication between them. The memory 123 is used to store computer program instructions.

[0133] The transceiver 121 may be used to obtain tasks to be executed and configuration information of the tasks to be executed.

[0134] The system bus can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The system bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The transceiver is used to realize the communication between the database access device and other computers (such as clients, read-write libraries, and read-only libraries). The memory may include random access memory (RAM) and may also include non-volatile memory.

[0135] The electronic device provided in the embodiment of the present application may be the terminal device of the above embodiment.

[0136] An embodiment of the present application also provides a chip for running instructions, which is used to execute the technical solution of the file encryption and delivery method in the above embodiment.

[0137] The embodiment of the present application also provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on a computer, the computer executes the technical solution of the file encryption and delivery method of the above embodiment.

[0138] An embodiment of the present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When at least one processor executes the computer program, it can implement the technical solution of the file encryption delivery method in the above embodiment.

[0139] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules 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 an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.

[0140] The modules described as separate components may or may not be physically separated, and the components shown as modules 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 modules may be selected according to actual needs to implement the solution of this embodiment.

[0141] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each module can exist physically separately, or two or more modules can be integrated into one unit. The above-mentioned module-composed unit can be implemented in the form of hardware or in the form of hardware plus software functional units.

[0142] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform some steps of the methods of various embodiments of the present application.

[0143] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.

[0144] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.

[0145] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.

[0146] The above storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.

[0147] An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the storage medium can also exist as discrete components in an electronic control unit or a main control device.

[0148] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.

[0149] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.

[0150] In the above embodiments, the description of each embodiment has its own emphasis. For parts not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0151] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0152] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A coding method, characterized in that: include: Obtaining a feature set to be encoded, the feature set to be encoded including non-numerical features to be encoded, and dividing the feature set to be encoded into a plurality of subsets; Selecting a target subset from a subset that has not been encoded currently, encoding the target subset based on current encoding parameters, and obtaining predicted encoding resources and actual encoding resources, wherein the predicted encoding resources are predicted resources required for encoding the target subset based on the encoding parameters, and the actual encoding resources are resources actually consumed for encoding the target subset based on the encoding parameters; Based on the predicted coding resources and the actual coding resources, a loss function is used to iteratively train the gradient model, the coding parameters are updated based on the iterative training results, and the step of selecting the target subset from the currently uncoded subset is returned to be executed until the iteration is completed to obtain the first coding parameters, and the iterative training results include gradient parameters; The first encoding parameter is used to encode all subsets of the feature set to be encoded that have not been encoded.

2. The method according to claim 1, characterized in that The method further comprises: Determine whether the number of non-numerical features to be encoded in the target subset exceeds a first threshold; If the number of non-numerical features does not exceed a preset first threshold, a preset encoding method is used to encode the non-numerical features to obtain encoded data, and the encoded data is stored in a first storage method; the first storage method includes: if the size of the encoded data does not exceed a preset second threshold, the encoded data is stored in a preset data structure, otherwise, the encoded data is stored in a matrix; If the number of non-numerical features exceeds a preset first threshold, the non-numerical features are encoded using a preset encoding method to obtain encoded data, and the encoded data is stored in a second storage method; the second storage method includes: if the size of the encoded data does not exceed the preset second threshold, the encoded data is stored in a matrix, otherwise, part of the encoded data is stored in the matrix, and the rest of the data is cached in a buffer, and the data amount of the part of the data is the second threshold.

3. The method according to claim 2, characterized in that The storing the encoded data into the matrix comprises: Determining the discreteness of the non-numerical features to be encoded in the target subset; If the discreteness does not exceed a preset third threshold, the encoded data is stored in a sparse matrix; if the discreteness exceeds the preset third threshold, the encoded data is stored in a dense matrix.

4. The method according to claim 1, characterized in that: The updating of the encoding parameters based on the iterative training result comprises: Obtaining a bias item corresponding to a current gradient parameter of the gradient model and an encoding parameter; A calculation result is obtained by multiplying a preset first coefficient, the gradient parameter and a coding parameter, and the calculation result is added to a bias item corresponding to the coding parameter to obtain an updated coding parameter.

5. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: Get source data; Splitting the source data to obtain a numerical feature set and a non-numerical feature set; Determine the number of non-numerical features in the non-numerical feature set. If the number of non-numerical features exceeds a preset fourth threshold, sample the non-numerical features in the non-numerical feature set and set the extracted non-numerical features as the feature set to be encoded; if the number of features does not exceed the preset fourth threshold, use the non-numerical feature set as the feature set to be encoded.

6. The method according to claim 5, characterized in that The method further comprises: The encoded data obtained after encoding each subset in the feature set to be encoded is merged with the data in the numerical feature set.

7. A coding device, characterized in that: include: An acquisition module, used for acquiring a feature set to be encoded, wherein the feature set to be encoded includes non-numerical features to be encoded, and dividing the feature set to be encoded into a plurality of subsets; A processing module, configured to select a target subset for this time from a subset that has not been encoded currently, encode the target subset based on current encoding parameters, and obtain predicted encoding resources and actual encoding resources, wherein the predicted encoding resources are predicted resources required for encoding the target subset based on the encoding parameters, and the actual encoding resources are resources actually consumed for encoding the target subset based on the encoding parameters; an iteration module, configured to iteratively train a gradient model using a loss function based on the predicted coding resource and the actual coding resource, update the coding parameters based on the iterative training result, and return to execute the step of selecting the target subset from the currently uncoded subset until the iteration is completed to obtain the first coding parameter, wherein the iterative training result includes the gradient parameter; The encoding module is used to encode all the subsets in the feature set to be encoded that have not been encoded by using the first encoding parameter.

8. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed by a processor.

10. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 6 when being executed by a processor.