Method and device for adaptively adjusting learning rate to train model, equipment and storage medium

By introducing the cosine similarity of gradient vectors in deep learning to dynamically adjust the learning rate, the problems of hyperparameter sensitivity, slow convergence at saddle points and unsatisfactory processing in the prior art are solved, and more efficient and accurate model training is achieved.

CN119514726APending Publication Date: 2025-02-25ZHONGKEHONGYUN TECH (BEIJING) CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411560657.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-04
Publication Date
2025-02-25

AI Technical Summary

Technical Problem

The existing adaptive learning rate optimization algorithm is sensitive to hyperparameters, converges slowly at saddle points, and does not ideally handle sparse gradients, which affects the training efficiency and accuracy of the model.

Method used

By introducing the cosine similarity of the gradient vector, the learning rate is dynamically adjusted to achieve adaptive model parameter optimization. The specific methods include initializing the parameters to be optimized and the initial learning rate of the model to be trained, adjusting the learning rate according to the gradient changes of the loss function during the training process until the target learning rate is reached, and adjusting the parameters to be optimized according to the target learning rate.

Benefits of technology

Reliance on hyperparameters is reduced, the robustness of the algorithm is improved, the convergence speed of model training is significantly accelerated, and the accuracy and stability of the model are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119514726A_ABST
    Figure CN119514726A_ABST
Patent Text Reader

Abstract

The invention provides a method and device for adaptively adjusting a learning rate to train a model, equipment and a storage medium, and the method comprises the steps: initializing a to-be-optimized parameter and an initial learning rate of a to-be-trained model; in the process of training the to-be-trained model, the initial learning rate is adjusted according to the gradient change condition of the loss function corresponding to the to-be-trained model, and a target learning rate is obtained; and adjusting the to-be-optimized parameters according to the target learning rate. Through the method, the effect of accurately and adaptively adjusting the learning rate so as to train the model can be achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of deep learning, and in particular, to a method, apparatus, device and storage medium for adaptively adjusting a learning rate to train a model. Background Art

[0002] The adaptive learning rate optimization algorithm based on gradient direction change can improve the convergence speed and accuracy of model training and enhance the stability of model training by dynamically adjusting the learning rate. It is suitable for neural network training and other model optimization processes. In the model training process of machine learning and deep learning, the performance of the optimization algorithm is crucial to training efficiency and model accuracy. The gradient descent method and its variants are one of the most commonly used optimization algorithms. The basic idea is to update the model parameters along the negative direction of the gradient according to the gradient information of the loss function. In recent years, many adaptive learning rate optimization algorithms have been proposed, such as AdaGrad, RMSProp, Adam, etc. These algorithms adaptively adjust the learning rate by weighted averaging the historical gradient information or storing the historical gradient square sum.

[0003] However, these algorithms also have some shortcomings: Sensitive to hyperparameters: Multiple hyperparameters (such as learning rate, decay rate, etc.) need to be carefully adjusted, which has a great impact on model performance. Slow convergence at saddle points: At saddle points or flat areas, the gradient is small, resulting in a small parameter update step size and slow convergence. Poor handling of sparse gradients: When dealing with sparse data or sparse gradients, the gradient information may not be fully utilized, affecting the convergence effect.

[0004] Therefore, how to accurately and adaptively adjust the learning rate and then train the model is a technical problem that needs to be solved. Summary of the invention

[0005] The purpose of the embodiments of the present application is to provide a method for adaptively adjusting the learning rate to train a model. The technical solution of the embodiments of the present application can achieve the effect of accurately adaptively adjusting the learning rate and thus training the model.

[0006] In the first aspect, an embodiment of the present application provides a method for adaptively adjusting the learning rate to train a model, including initializing the parameters to be optimized and the initial learning rate of the model to be trained; in the process of training the model to be trained, adjusting the initial learning rate according to the gradient change of the loss function corresponding to the model to be trained to obtain the target learning rate; according to the target learning rate, adjusting the parameters to be optimized.

[0007] In the above embodiments of the present application, the cosine similarity of the gradient vector is introduced to dynamically adjust the learning rate to achieve adaptive model parameter optimization. The learning rate can be automatically adjusted according to the change in the gradient direction, thereby reducing the reliance on hyperparameters in the prior art and improving the robustness of the algorithm. This method can achieve the effect of accurately and adaptively adjusting the learning rate and then training the model.

[0008] In some embodiments, the initial learning rate is adjusted according to the gradient change of the loss function corresponding to the model to be trained to obtain the target learning rate, including: determining the cosine similarity between the current gradient vector and the previous gradient vector of the loss function; when the cosine similarity is greater than a preset threshold, adjusting the initial learning rate according to a preset increment to obtain the target learning rate; when the cosine similarity is less than or equal to the preset threshold, adjusting the initial learning rate according to a preset decrement to obtain the target learning rate.

[0009] In the above embodiments of the present application, the learning rate can be dynamically adjusted according to the comparison between the cosine similarity and the threshold value to achieve adaptive model parameter optimization and thus complete the model training.

[0010] In some embodiments, determining the cosine similarity between a current gradient vector and a previous gradient vector of a loss function includes: smoothing the current gradient vector and the previous gradient vector to obtain two processed gradient vectors; and calculating the cosine similarity between the two processed gradient vectors.

[0011] In the above embodiment of the present application, a sliding average is introduced when calculating the cosine similarity to smooth the gradient. The algorithm relies on the change of the gradient direction to avoid being sensitive to gradient jitter.

[0012] In some embodiments, after adjusting the parameters to be optimized according to the target learning rate, it also includes: determining the number of times the parameters to be optimized are adjusted and the loss value calculated by the loss function; when the number of times the parameters to be optimized reaches a preset number or the loss value is less than a preset loss value, the training of the model to be trained is completed.

[0013] In the above embodiments of the present application, model training and optimization are completed after the model converges and the conditions are met, thereby improving the model accuracy.

[0014] In a second aspect, an embodiment of the present application provides a device for adaptively adjusting a learning rate to train a model, comprising:

[0015] The initialization module is used to initialize the parameters to be optimized and the initial learning rate of the model to be trained;

[0016] An adjustment module is used to adjust the initial learning rate according to the gradient change of the loss function corresponding to the model to be trained during the training process to obtain a target learning rate;

[0017] The optimization module is used to adjust the parameters to be optimized according to the target learning rate.

[0018] Optionally, the adjustment module is specifically used for:

[0019] Determine the cosine similarity between the current gradient vector and the previous gradient vector of the loss function;

[0020] When the cosine similarity is greater than a preset threshold, the initial learning rate is adjusted according to a preset increment to obtain a target learning rate;

[0021] When the cosine similarity is less than or equal to the preset threshold, the initial learning rate is adjusted according to the preset reduction to obtain the target learning rate.

[0022] Optionally, the adjustment module is specifically used for:

[0023] Smoothing the current gradient vector and the previous gradient vector to obtain two processed gradient vectors;

[0024] Compute the cosine similarity between the two processed gradient vectors.

[0025] Optionally, the device further comprises:

[0026] A judgment module is used to determine the number of times to adjust the parameters to be optimized and the loss value calculated by the loss function after the optimization module adjusts the parameters to be optimized according to the target learning rate;

[0027] When the number of parameters to be optimized reaches the preset number or the loss value is less than the preset loss value, the training of the model to be trained is completed.

[0028] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps in the method provided in the first aspect are performed.

[0029] In a fourth aspect, an embodiment of the present application provides a readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps in the method provided in the first aspect are performed.

[0030] Other features and advantages of the present application will be further described in the subsequent description, and partly become apparent from the description, or be understood by practicing the embodiments of the present application. The purpose and other advantages of the present application can be realized and obtained by the structures particularly described in the attached description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0032] Figure 1 A flowchart of a method for adaptively adjusting the learning rate to train a model provided in an embodiment of the present application;

[0033] Figure 2 A flowchart of an implementation method for adaptively adjusting the learning rate to train a model provided in an embodiment of the present application;

[0034] Figure 3 A schematic block diagram of a device for adaptively adjusting a learning rate to train a model provided in an embodiment of the present application;

[0035] Figure 4 A schematic diagram of the structure of a device for adaptively adjusting the learning rate to train a model provided in an embodiment of the present application. DETAILED DESCRIPTION

[0036] The technical solutions in the embodiments of the present application will be described in detail and clearly below in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application usually described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.

[0037] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

[0038] First, some terms involved in the embodiments of the present application are explained to facilitate understanding by those skilled in the art.

[0039] AdaGrad, the full name of which is Adaptive Gradient, is also called adaptive gradient algorithm. It is a gradient descent optimization method with adaptive learning rate.

[0040] The RMSProp algorithm is an algorithm for optimizing the weights of a neural network that accelerates the training process by adjusting the learning rate of each parameter. The RMSProp algorithm adjusts the learning rate of each parameter by calculating the root mean square of past gradients, so that the learning rate is low in flat areas in the parameter space and high in steep areas.

[0041] The Adam algorithm is an optimization algorithm that combines the momentum method and adaptive learning rate.

[0042] MNIST is a large database of handwritten digits used for training and testing machine learning models, especially deep learning.

[0043] This application is applied to the scenario of deep learning, and specifically proposes an adaptive learning rate optimization algorithm based on gradient direction change. The algorithm adjusts the learning rate by utilizing the similarity between the current gradient and the previous gradient direction, which more directly reflects the local curvature change of the loss function, reduces dependence on hyperparameters, and improves the robustness of the algorithm.

[0044] The adaptive learning rate optimization algorithm based on the change of gradient direction can improve the convergence speed and accuracy of model training and enhance the stability of model training by dynamically adjusting the learning rate. It is suitable for neural network training and other model optimization processes. In the model training process of machine learning and deep learning, the performance of the optimization algorithm is crucial to the training efficiency and model accuracy. The gradient descent method and its variants are one of the most commonly used optimization algorithms. The basic idea is to update the model parameters along the negative direction of the gradient according to the gradient information of the loss function. In recent years, many adaptive learning rate optimization algorithms have been proposed, such as AdaGrad, RMSProp, Adam, etc. These algorithms adaptively adjust the learning rate by weighted averaging the historical gradient information or storing the sum of the squares of the historical gradients. However, these algorithms also have some shortcomings: Sensitive to hyperparameters: Multiple hyperparameters (such as learning rate, decay rate, etc.) need to be carefully adjusted, which has a great impact on model performance. Slow convergence at saddle points: At saddle points or flat areas, the gradient is small, resulting in too small a parameter update step and slow convergence. Unsatisfactory handling of sparse gradients: When processing sparse data or sparse gradients, the gradient information may not be fully utilized, affecting the convergence effect.

[0045] To this end, the present application initializes the parameters to be optimized and the initial learning rate of the model to be trained; in the process of training the model to be trained, the initial learning rate is adjusted according to the gradient change of the loss function corresponding to the model to be trained to obtain the target learning rate; according to the target learning rate, the parameters to be optimized are adjusted. By introducing the cosine similarity of the gradient vector, the learning rate is dynamically adjusted to achieve adaptive model parameter optimization, and the learning rate can be automatically adjusted according to the change of the gradient direction, reducing the reliance on hyperparameters like the prior art, and improving the robustness of the algorithm. This method can achieve the effect of accurately and adaptively adjusting the learning rate and then training the model.

[0046] In the embodiment of the present application, the execution entity can be an adaptive learning rate training model device in an adaptive learning rate training model system. In actual applications, the adaptive learning rate training model device can be electronic devices such as terminal devices and servers, which is not limited here.

[0047] Combine the following Figure 1 The method for adaptively adjusting the learning rate training model in an embodiment of the present application is described in detail.

[0048] Please see Figure 1 , Figure 1 A flowchart of a method for adaptively adjusting the learning rate to train a model provided in an embodiment of the present application, such as Figure 1 The method shown for adaptively adjusting the learning rate training model includes:

[0049] Step 110: Initialize the parameters to be optimized and the initial learning rate of the model to be trained.

[0050] Specifically, the existing basic model parameters can be used as the parameters to be optimized, and the learning power of the model during historical deep learning process optimization can be used as the initial learning rate. The optimization process of the model to be trained in this application can be training a multi-layer perceptron on the MNIST dataset, training a convolutional neural network on the CIFAR-10 dataset, and other scenarios.

[0051] Step 120: During the training of the model to be trained, the initial learning rate is adjusted according to the gradient change of the loss function corresponding to the model to be trained to obtain the target learning rate.

[0052] In some embodiments of the present application, the initial learning rate is adjusted according to the gradient change of the loss function corresponding to the model to be trained to obtain the target learning rate, including: determining the cosine similarity between the current gradient vector and the previous gradient vector of the loss function; when the cosine similarity is greater than a preset threshold, adjusting the initial learning rate according to a preset increment to obtain the target learning rate; when the cosine similarity is less than or equal to the preset threshold, adjusting the initial learning rate according to a preset decrement to obtain the target learning rate.

[0053] In the above process, the present application can dynamically adjust the learning rate according to the comparison of cosine similarity and threshold, realize adaptive model parameter optimization, and then complete model training.

[0054] Among them, the preset threshold, preset increment and preset decrement can be set according to needs.

[0055] Optionally, the cosine similarity between the current gradient vector and the previous gradient vector of the loss function can be obtained by the following formula:

[0056]

[0057] Among them, the current gradient vector g t , the previous gradient vector g t-1 , cosine similarity cos(θ t ), g t ·g t-1 represents the inner product of two gradient vectors, ∥g t ∥ and ∥g t-1 ∥ represents the Euclidean norm of the current gradient vector and the previous gradient vector respectively. To prevent the denominator from being zero, when the gradient modulus is zero, the cosine similarity cos(θ t )=0,θ t Indicates the angle of the current gradient vector.

[0058] Optional, when the gradient is zero, ie ∥g t ∥=0 or ∥g t-1 When ∥=0, the cosine similarity cos(θ t ) is set to 0, indicating that the gradient direction changes greatly, and the learning rate is reduced. To prevent the learning rate from being too small and affecting the training speed, the lower limit of the learning rate η can be set min , ensuring η t ≥η min .

[0059] Optionally, when the cosine similarity is greater than a preset threshold, the initial learning rate is adjusted according to a preset increment to obtain a target learning rate; when the cosine similarity is less than or equal to the preset threshold, the initial learning rate is adjusted according to a preset decrement to obtain the target learning rate, which can be achieved by the following situations:

[0060] Increase the learning rate: When cos(θ t )>δ(preset threshold), it means that the current gradient direction is similar to the previous one, and the learning rate is increased (the initial learning rate is adjusted according to the preset increment) to speed up the convergence.

[0061] η t =η t-1 ×(1+β×cos(θ t ));

[0062] Reduce the learning rate: When cos(θ t )≤δ, it means that the gradient direction changes greatly, and the learning rate is reduced (the initial learning rate is adjusted according to the preset reduction) to enhance the training stability.

[0063] η t =η t-1 ×(1-β×(1-cos(θ t )));

[0064] Among them, β is the learning rate adjustment coefficient, δ is the cosine similarity threshold, the value range can be set between [-1,1], η t-1 represents the initial learning rate, η t represents the target learning rate.

[0065] For example, the initial learning rate η t-1 It can be set to 0.01 or 0.001, depending on the specific task and model. Learning rate adjustment coefficient β: The value can generally be 0.01 or 0.1, which is used to control the amplitude of the learning rate adjustment. Preset threshold δ: It can generally be set to 0, indicating that the learning rate is increased when the gradient direction is not opposite. When the learning rate adjustment needs to be more strictly controlled, it can be set to a positive or negative value.

[0066] In some embodiments of the present application, determining the cosine similarity between a current gradient vector and a previous gradient vector of a loss function includes: smoothing the current gradient vector and the previous gradient vector to obtain two processed gradient vectors; and calculating the cosine similarity between the two processed gradient vectors.

[0067] In the above process, the present application introduces sliding average when calculating cosine similarity to smooth the gradient. The algorithm relies on the change of gradient direction to avoid being sensitive to gradient jitter.

[0068] Specifically, the current gradient vector and the previous gradient vector are smoothed, and the smoothing method for obtaining the two processed gradient vectors can be obtained by the following formula:

[0069]

[0070] Among them, γ represents the smoothing coefficient, which can take values ​​between [0,1]. represents the gradient vector obtained after smoothing, represents the previous gradient vector after smoothing, g t Represents the current gradient vector.

[0071] Step 130: Adjust the parameters to be optimized according to the target learning rate.

[0072] Optionally, the parameters to be optimized can be adjusted using the following formula:

[0073] θ t =θ t-1 -η t ×g t ;

[0074] Among them, θ t Represents the current gradient vector angle, θ t-1 The angle of the previous gradient, g t represents the current gradient vector, η t represents the target learning rate.

[0075] In some embodiments of the present application, after adjusting the parameters to be optimized according to the target learning rate, Figure 1 The method shown also includes: determining the number of times the parameters to be optimized are adjusted and the loss value calculated by the loss function; when the number of times the parameters to be optimized reaches a preset number or the loss value is less than a preset loss value, the training of the model to be trained is completed.

[0076] In the above process, this application completes model training and optimization through model convergence and meets the conditions to improve model accuracy.

[0077] Among them, the preset loss value can be set according to needs.

[0078] In the above Figure 1 In the process shown, the present application initializes the parameters to be optimized and the initial learning rate of the model to be trained; in the process of training the model to be trained, the initial learning rate is adjusted according to the gradient change of the loss function corresponding to the model to be trained to obtain the target learning rate; according to the target learning rate, the parameters to be optimized are adjusted. By introducing the cosine similarity of the gradient vector, the learning rate is dynamically adjusted to achieve adaptive model parameter optimization, and the learning rate can be automatically adjusted according to the change of the gradient direction, reducing the reliance on hyperparameters like the prior art, and improving the robustness of the algorithm. This method can achieve the effect of accurately and adaptively adjusting the learning rate and then training the model.

[0079] In one embodiment, by Figure 1 The described method trains a multi-layer perceptron (MLP) on the MNIST dataset.

[0080] Dataset: MNIST handwritten digit recognition dataset.

[0081] Model structure: input layer (784 dimensions), two hidden layers, 128 neurons in each layer, activation function is ReLU, output layer has 10 neurons, activation function is Softmax.

[0082] Hyperparameter settings: initial learning rate η0 = 0.01. Cosine similarity threshold δ = 0. Learning rate adjustment coefficient β = 0.1. Smoothing coefficient γ = 0.9. Batch size: 64. Number of training rounds: 20 epochs.

[0083] Comparison algorithm: fixed learning rate gradient descent (learning rate is 0.01) and Adam optimization algorithm. Figure 1 The method shown is used to process the above data to obtain the test results.

[0084] Experimental results: Convergence speed: In the first 5 epochs (one round of model optimization), the training loss of the algorithm of the present invention decreases rapidly, and the convergence speed is significantly faster than the gradient descent algorithm with a fixed learning rate, and slightly better than the Adam algorithm.

[0085] Model accuracy: The accuracy on the test set reaches 98.2%, which is higher than the 97.5% of the fixed learning rate gradient descent algorithm and comparable to the 98.0% of the Adam algorithm.

[0086] Learning rate change curve: The learning rate gradually increases in the early stage of training, reaching a maximum of about twice the initial learning rate; in the later stage of training, as the gradient direction changes more, the learning rate gradually decreases, stabilizing the model training process.

[0087] Comparative analysis: Compared with the fixed learning rate gradient descent algorithm, the algorithm of this application significantly accelerates the convergence speed, improves the model accuracy, and avoids the slow convergence or oscillation problems caused by the fixed learning rate. Compared with the Adam algorithm, the algorithm of the present invention is competitive in terms of convergence speed and model accuracy, while having lower computational complexity and being easier to implement.

[0088] In one embodiment, by Figure 1 The method described trains a convolutional neural network (CNN) on the CIFAR-10 dataset.

[0089] Dataset: CIFAR-10 image classification dataset.

[0090] Model structure: Typical CNN, including convolutional layer, pooling layer, fully connected layer, using ReLU activation function.

[0091] Initial learning rate η0 = 0.01. Cosine similarity threshold δ = 0. Learning rate adjustment coefficient β = 0.1. Smoothing coefficient γ = 0.9. Batch size: 64. Number of training rounds: 20 epochs.

[0092] Comparison algorithm: fixed learning rate gradient descent (learning rate is 0.01) and Adam optimization algorithm. Figure 1 The method shown is used to process the above data to obtain the test results.

[0093] Experimental results: Convergence speed: In the first 10 epochs of training, the loss function of the proposed algorithm decreases significantly faster than that of the comparison algorithm. Model accuracy: The accuracy on the test set reaches 85.5%, which is higher than the 83.0% of the fixed learning rate gradient descent algorithm and is on par with the 85.0% of the Adam algorithm.

[0094] Scope of application verification: The algorithm in this application shows good performance on different types of models (MLP, CNN) and data sets (MNIST, CIFAR-10), verifying the wide applicability of the algorithm.

[0095] Combine the following Figure 2 The implementation method of the adaptive adjustment learning rate training model in the embodiment of the present application is described in detail.

[0096] Please see Figure 2 , Figure 2 A flowchart of an implementation method of adaptively adjusting the learning rate to train a model provided in an embodiment of the present application, such as Figure 2 The implementation method of adaptively adjusting the learning rate training model shown includes:

[0097] Step 210: Initialize model parameters and learning rate.

[0098] Specifically: Initialize the parameters to be optimized and the initial learning rate of the model to be trained

[0099] Step 220: Calculate the current gradient.

[0100] Specifically: The current gradient of the model to be trained can be calculated through the back propagation algorithm.

[0101] Step 230: Calculate cosine similarity.

[0102] Specifically: Calculate the cosine phase between the current gradient vector and the previous gradient vector of the loss function.

[0103] Step 240: Dynamically adjust the learning rate.

[0104] Specifically: adjust the initial learning rate according to the gradient change of the loss function corresponding to the model to be trained to obtain the target learning rate.

[0105] Step 250: Update model parameters.

[0106] Specifically: Adjust the parameters to be optimized according to the target learning rate.

[0107] Step 260: Check the training stop condition.

[0108] Specifically: After the model converges and the conditions are met, the model training and optimization are completed.

[0109] also, Figure 2 The specific methods and steps shown can be found in Figure 1 The method shown will not be described in detail here.

[0110] Previous article Figure 1-Figure 2 Describes the method of adaptively adjusting the learning rate training model. Figure 3-Figure 4 Describes a device that adaptively adjusts the learning rate to train a model.

[0111] Please refer to Figure 3 , is a schematic block diagram of a device 300 for adaptively adjusting the learning rate to train a model provided in an embodiment of the present application. The device 300 may be a module, program segment or code on an electronic device. The device 300 is similar to the above Figure 1 The method embodiment corresponds to and can be executed Figure 1 The various steps involved in the method embodiment and the specific functions of the device 300 can be found in the description below. To avoid repetition, the detailed description is appropriately omitted here.

[0112] Optionally, the device 300 includes:

[0113] An initialization module 310 is used to initialize the parameters to be optimized and the initial learning rate of the model to be trained;

[0114] An adjustment module 320 is used to adjust the initial learning rate according to the gradient change of the loss function corresponding to the model to be trained during the training of the model to be trained, so as to obtain a target learning rate;

[0115] The optimization module 330 is used to adjust the parameters to be optimized according to the target learning rate.

[0116] Optionally, the adjustment module is specifically used for:

[0117] Determine the cosine similarity between the current gradient vector and the previous gradient vector of the loss function; when the cosine similarity is greater than a preset threshold, adjust the initial learning rate according to a preset increment to obtain a target learning rate; when the cosine similarity is less than or equal to the preset threshold, adjust the initial learning rate according to a preset decrement to obtain the target learning rate.

[0118] Optionally, the adjustment module is specifically used for:

[0119] The current gradient vector and the previous gradient vector are smoothed to obtain two processed gradient vectors; and the cosine similarity between the two processed gradient vectors is calculated.

[0120] Optionally, the device further comprises:

[0121] The judgment module is used to determine the number of times to adjust the parameters to be optimized and the loss value calculated by the loss function after the optimization module adjusts the parameters to be optimized according to the target learning rate; when the number of times the parameters to be optimized reaches the preset number or the loss value is less than the preset loss value, the training of the model to be trained is completed.

[0122] Please refer to Figure 4 The structure schematic block diagram of a device for adaptively adjusting the learning rate to train a model provided in an embodiment of the present application, the device may include a memory 410 and a processor 420. Optionally, the device may also include: a communication interface 430 and a communication bus 440. The device and the above Figure 1 The method embodiment corresponds to and can be executed Figure 1 The various steps involved in the method embodiment and the specific functions of the device can be found in the description below.

[0123] Specifically, the memory 410 is used to store computer-readable instructions.

[0124] Processor 420 is used to process the readable instructions stored in the memory and can execute Figure 1 The steps in the method.

[0125] The communication interface 430 is used for signaling or data communication with other node devices, for example, for communication with a server or a terminal, or for communication with other device nodes, but the embodiments of the present application are not limited thereto.

[0126] The communication bus 440 is used to realize direct connection and communication among the above components.

[0127] The communication interface 430 of the device in the embodiment of the present application is used to communicate signals or data with other node devices. The memory 410 can be a high-speed RAM memory or a non-volatile memory, such as at least one disk memory. The memory 410 can also be at least one storage device located away from the aforementioned processor. The memory 410 stores computer-readable instructions. When the computer-readable instructions are executed by the processor 420, the electronic device executes the aforementioned Figure 1The method process shown. The processor 420 can be used on the device 300 and is used to perform the functions in the present application. Exemplarily, the above-mentioned processor 420 can be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, and the embodiments of the present application are not limited thereto.

[0128] The embodiment of the present application also provides a readable storage medium, when the computer program is executed by a processor, Figure 1 The method process in the method embodiment shown is executed by the electronic device.

[0129] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method, and will not be described in detail here.

[0130] In summary, the embodiments of the present application provide a method, apparatus, device and storage medium for adaptively adjusting the learning rate to train a model, the method comprising initializing the parameters to be optimized and the initial learning rate of the model to be trained; in the process of training the model to be trained, adjusting the initial learning rate according to the gradient change of the loss function corresponding to the model to be trained to obtain the target learning rate; and adjusting the parameters to be optimized according to the target learning rate. This method can achieve the effect of accurately adaptively adjusting the learning rate and then training the model.

[0131] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

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

[0133] If the functions are implemented in the form of software function 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 the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0134] The above description is only an embodiment of the present application and is not intended to limit the scope of protection of the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application. It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings.

[0135] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0136] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

Claims

1. A method for adaptively adjusting the learning rate to train a model, characterized in that: include: Initialize the parameters to be optimized and the initial learning rate of the model to be trained; In the process of training the model to be trained, adjusting the initial learning rate according to the gradient change of the loss function corresponding to the model to be trained to obtain a target learning rate; According to the target learning rate, the parameter to be optimized is adjusted.

2. The method according to claim 1, characterized in that The step of adjusting the initial learning rate according to the gradient change of the loss function corresponding to the model to be trained to obtain the target learning rate includes: Determining the cosine similarity between the current gradient vector and the previous gradient vector of the loss function; When the cosine similarity is greater than a preset threshold, adjusting the initial learning rate according to a preset increment to obtain the target learning rate; When the cosine similarity is less than or equal to the preset threshold, the initial learning rate is adjusted according to a preset decrement to obtain the target learning rate.

3. The method according to claim 2, characterized in that Determining the cosine similarity between the current gradient vector and the previous gradient vector of the loss function includes: Smoothing the current gradient vector and the previous gradient vector to obtain two processed gradient vectors; The cosine similarity between the two processed gradient vectors is calculated.

4. The method according to any one of claims 1 to 3, characterized in that: After adjusting the parameter to be optimized according to the target learning rate, the method further includes: Determining the number of times to adjust the parameter to be optimized and the loss value calculated by the loss function; When the number of times the parameter to be optimized reaches a preset number or the loss value is less than a preset loss value, the training of the model to be trained is completed.

5. A device for adaptively adjusting the learning rate to train a model, characterized in that: include: The initialization module is used to initialize the parameters to be optimized and the initial learning rate of the model to be trained; An adjustment module, used for adjusting the initial learning rate according to the gradient change of the loss function corresponding to the model to be trained during the training of the model to be trained, so as to obtain a target learning rate; The optimization module is used to adjust the parameters to be optimized according to the target learning rate.

6. The device according to claim 5, characterized in that The adjustment module is specifically used for: Determining the cosine similarity between the current gradient vector and the previous gradient vector of the loss function; When the cosine similarity is greater than a preset threshold, adjusting the initial learning rate according to a preset increment to obtain the target learning rate; When the cosine similarity is less than or equal to the preset threshold, the initial learning rate is adjusted according to a preset decrement to obtain the target learning rate.

7. The device according to claim 6, characterized in that: The adjustment module is specifically used for: Smoothing the current gradient vector and the previous gradient vector to obtain two processed gradient vectors; The cosine similarity between the two processed gradient vectors is calculated.

8. The device according to any one of claims 5 to 7, characterized in that: Also includes: A judgment module, used for the optimization module to determine the number of times the parameter to be optimized is adjusted and the loss value calculated by the loss function after the parameter to be optimized is adjusted according to the target learning rate; When the number of times the parameter to be optimized reaches a preset number or the loss value is less than a preset loss value, the training of the model to be trained is completed.

9. An electronic device, characterized in that: include: A memory and a processor, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps in the method according to any one of claims 1 to 4 are executed.

10. A computer-readable storage medium, characterized in that: include: A computer program, when the computer program is run on a computer, causes the computer to execute the method according to any one of claims 1 to 4.

Citation Information

Cited By

  • Robot walking control method, device and equipment and medium

    CN120909328A