Method, device, equipment and storage medium for determining word vector dimension
By obtaining the basic word vectors and using reinforcement learning training to determine the dimensions of word vectors, the problems of large subjectivity and training overhead in the existing technology are solved, and more efficient word vector training and stronger expression ability are achieved.
Patent Information
- Application Number
- CN202210433528.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-24
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2042-04-24
AI Technical Summary
In the prior art, how to objectively determine the dimension of word vectors is an urgent problem. If the dimension is set too high, the training overhead will be large. If the setting is too small, it will be difficult to obtain sufficient semantic information, which will affect the effect of subsequent tasks.
By obtaining the basic word vector, determining the initial word vector and the corresponding dimensions based on the first subword vector, and using the initial word vector for natural language processing tasks, obtaining performance indicators. Then, reinforcement learning training is carried out based on the second subword vector, dimensions are added, and rewards are given by comparing performance indicators, the total reward value is updated until convergence is achieved, and the dimension of the final word vector is determined.
This method can reduce training overhead, obtain word vectors with stronger expression capabilities, and improve the objectivity and efficiency of word vector dimension determination.
Smart Images

Figure CN114781395B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method, device, equipment and storage medium for determining word vector dimensions. Background Art
[0002] At present, the field of artificial intelligence has entered an era dominated by deep learning. Extracting the representation of samples, then inputting them into the neural network model for training, and then using the trained model to complete tasks in the subdivided field has become a standard paradigm. In the field of natural language processing, discrete representations including One-Hot, TF-IDF, etc. have become difficult to adapt to increasingly complex tasks. In recent years, people have become accustomed to mapping words or phrases from the vocabulary into continuous representation vectors, namely word vectors, and then inputting them into various neural network models and optimizing the models. The trained models are then used for specific tasks such as text classification and text summarization. Due to its good expressive power, word embedding vectors have achieved good results in many sub-fields such as text classification, text matching, and machine translation. In practical applications, people often need to train word vectors from scratch according to specific tasks or train them again based on public word embedding vectors to obtain word vectors. The dimension of word vectors is often determined by manual experience and is highly subjective. If the dimension of word vectors is set too high, it will bring greater training overhead. However, if the dimension is set too small, it will be difficult for the word vector to obtain sufficient semantic information, which will affect the results of subsequent tasks. Therefore, how to objectively determine the dimension of word vectors has become an urgent problem to be solved. Summary of the invention
[0003] The present application provides a method, apparatus, device and storage medium for determining word vector dimensions to solve the problem of how to determine the dimension of word vectors in the prior art.
[0004] To solve the above problems, the present application provides a method for determining word vector dimensions, including:
[0005] Obtain a basic word vector, where the basic word vector includes multiple batches of sub-word vectors;
[0006] Based on the first subword vector, determine the initial word vector and the corresponding dimension;
[0007] Using the initial word vector, perform a natural language processing task to obtain a first performance indicator corresponding to each task;
[0008] Reinforcement learning training is performed based on the second subword vector to obtain a first dimension added in this round of training, a first word vector is determined based on the first dimension corresponding to the initial word vector, a natural language processing task is performed using the first word vector to obtain a second performance indicator corresponding to each task, and a reward is given based on the relationship between the first performance indicator and the second performance indicator;
[0009] The total reward value is updated according to the reward, and multiple rounds of training are performed until the total reward value converges, thereby obtaining the dimension corresponding to the final word vector determined by the last round of training when the total reward value converges.
[0010] Furthermore, the determining of the initial word vector and the corresponding dimension based on the first subword vector includes:
[0011] Based on the dimension of the first subword vector, use the dimension determination algorithm to obtain the dimension corresponding to the initial word vector;
[0012] Based on the dimension corresponding to the initial word vector and the first subword vector, the initial word vector is obtained using a word vector model.
[0013] Further, the obtaining of the initial word vector based on the dimension corresponding to the initial word vector and the first subword vector by using a word vector model includes:
[0014] Based on the dimension corresponding to the initial word vector, extracting data of the corresponding dimension from the first subword vector;
[0015] The data is input into a word vector model for optimization processing to obtain the initial word vector.
[0016] Furthermore, the reinforcement learning training is performed according to the second subword vector to obtain the first dimension added in this round of training, which includes:
[0017] Get the second subword vector used in this round of training;
[0018] Inputting the second subword vector used in the current round of training into the deep learning neural network for processing to obtain a probability value of increasing the dimension size in the current round of training;
[0019] The dimension corresponding to the maximum probability value is determined as the first dimension.
[0020] Furthermore, the awarding of rewards according to the relationship between the first performance indicator and the second performance indicator includes:
[0021] averaging the first performance index and the second performance index respectively to obtain a first average performance index and a second average performance index;
[0022] When the second average performance index is greater than or equal to the first average performance index, giving a first reward;
[0023] When the second average performance index is less than the first average performance index, a second reward is given, wherein the first reward is a positive number, and the first reward and the second reward are opposite numbers.
[0024] Furthermore, after averaging the first performance indicator and the second performance indicator to obtain the first average performance indicator and the second average performance indicator, the method further includes:
[0025] Get the parameter values of the hardware corresponding to the natural language processing task performed in this round of training;
[0026] Normalize the parameter values corresponding to each hardware to obtain the normalized values corresponding to each hardware;
[0027] Based on the normalized values of each hardware, the training cost value is obtained;
[0028] The second average performance indicator is divided by the training cost value to obtain the first reward.
[0029] Furthermore, the training cost value obtained based on the normalized value of each hardware includes:
[0030] Obtaining the weight of each hardware based on the hierarchical analysis method;
[0031] According to the weight of each hardware, the normalized value of each hardware is weighted and summed to obtain the training cost value.
[0032] In order to solve the above problem, the present application also provides a device for determining a word vector dimension, the device comprising:
[0033] An acquisition module, used to acquire a basic word vector, wherein the basic word vector includes multiple batches of sub-word vectors;
[0034] An initial module, used to determine an initial word vector and a corresponding dimension based on the first subword vector;
[0035] A first training module is used to use the initial word vector to perform natural language processing tasks and obtain a first performance indicator corresponding to each task;
[0036] The second training module is used to perform reinforcement learning training based on the second subword vector to obtain a first dimension added in this round of training, determine a first word vector based on the first dimension corresponding to the initial word vector, perform a natural language processing task using the first word vector, obtain a second performance indicator corresponding to each task, and give a reward based on the relationship between the first performance indicator and the second performance indicator;
[0037] An iterative update module is used to update the total reward value according to the reward, and to obtain the dimension corresponding to the final word vector determined by the last round of training when the total reward value converges by performing multiple rounds of training until the total reward value converges.
[0038] In order to solve the above problem, the present application also provides a computer device, including:
[0039] at least one processor; and,
[0040] a memory communicatively connected to the at least one processor; wherein,
[0041] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method for determining the word vector dimension as described above.
[0042] In order to solve the above problems, the present application also provides a non-volatile computer-readable storage medium, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor, the method for determining the word vector dimension as described above is implemented.
[0043] A method, apparatus, device, and storage medium for determining word vector dimensions provided in an embodiment of the present application have at least the following beneficial effects compared with the prior art:
[0044] By obtaining a basic word vector, the basic word vector includes multiple batches of sub-word vectors; based on the first sub-word vector, an initial word vector and a corresponding dimension are determined; by determining the initial vector and the dimension, the speed of determining the final word vector can be improved, and then the initial word vector is used to perform a natural language processing task to obtain a first performance indicator corresponding to each task; reinforcement learning training is performed according to the second sub-word vector to obtain a first dimension added in this round of training, and a first word vector is determined according to the first dimension and the dimension corresponding to the initial word vector, and the first word vector is used to perform a natural language processing task to obtain a second performance indicator corresponding to each task, and a reward is given according to the relationship between the first performance indicator and the second performance indicator; rewards are given accordingly by comparing the performance indicators obtained in two adjacent rounds of training, and the total reward value is updated according to the reward, and multiple rounds of training are performed until the total reward value converges, and the dimension corresponding to the final word vector determined in the last round of training when the total reward value converges is obtained, thereby obtaining the final word vector and the corresponding dimension, reducing training overhead, and obtaining a word vector with stronger expression ability. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the scheme in the present application, a brief introduction will be given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0046] Figure 1 An overall flow chart of a method for determining word vector dimensions provided in an embodiment of the present application;
[0047] Figure 2 for Figure 1 A schematic flow chart of a specific implementation of step S2;
[0048] Figure 3 for Figure 1 A schematic flow chart of a specific implementation of step S4;
[0049] Figure 4 A schematic diagram of a module of a device for determining word vector dimensions provided in an embodiment of the present application;
[0050] Figure 5 A schematic diagram of the structure of a computer device according to an embodiment of the present application. DETAILED DESCRIPTION
[0051] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0052] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly or implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0053] This application provides a method for determining the dimension of a word vector. Figure 1 As shown, Figure 1 A flowchart of a method for determining word vector dimensions provided in one embodiment of the present application.
[0054] In this embodiment, the method for determining the word vector dimension includes:
[0055] S1. Obtain a basic word vector, where the basic word vector includes multiple batches of sub-word vectors;
[0056] Specifically, the basic word vector is obtained from an existing word vector library, which stores a large number of word vectors. In this application, the basic word vector is 500-dimensional, and in other embodiments of this application, it may be other dimensions, such as 400 and 450. The basic word vector is also divided into multiple batches of sub-word vectors, so that different batches of sub-word vectors can be used in subsequent multiple rounds of training.
[0057] In other embodiments of the present application, a large amount of text data may be first obtained, and the text data may be input into the CBOW and Skip-gram models for vectorization, and the initial dimension may be set to 500 dimensions.
[0058] The training input of the CBOW model is the randomly initialized word vector corresponding to the context-related words of a target word. Through model optimization, the word vector of the target word is obtained. For example, the training sample is "Beijing is the capital of China", the context size window value is 2, and the target word is "China". After word segmentation, there are 4 words corresponding to the context, 2 before and after, namely: Beijing, is, of, and capital. These 4 words are the input of the CBOW model. Through the CBOW model, the word vector of the target word "China" can be obtained; the training ideas of the Skip-Gram model and the CBOW model are opposite, that is, the input is the randomly initialized word vector of a specific word, and the word vector of the context word corresponding to the specific word is obtained through neural network optimization. Still taking the above sentence as an example, in the sample construction, the context size window value of the specific word is 2, and the specific word "China" is the input of the Skip-Gram model. Through the Skip-Gram model, the word vectors of the four context words "Beijing, is, of, and capital" can be obtained.
[0059] S2. Based on the first subword vector, determine the initial word vector and the corresponding dimension;
[0060] Specifically, based on the first sub-word vector, a dimension determination algorithm is used to determine the dimension corresponding to the initial word vector, that is, the initial dimension, and then the word vector model is used for training based on the dimension and the first sub-word vector to obtain the initial word vector.
[0061] Further, such as Figure 2 As shown, the determining of the initial word vector and the corresponding dimension based on the first subword vector includes:
[0062] S21, based on the dimension of the first subword vector, using a dimension determination algorithm to obtain the dimension corresponding to the initial word vector;
[0063] S22. Based on the dimension corresponding to the initial word vector and the first subword vector, the initial word vector is obtained using a word vector model.
[0064] Specifically, the initial word vector is determined according to the dimension corresponding to the first subword vector. When the dimension of the first subword vector is N, the dimension a corresponding to the initial word vector needs to satisfy the dimension determination algorithm, and the formula is as follows:
[0065]
[0066] The above formula is used to specifically determine the dimension of the initial word vector. After the dimension of the initial word vector is determined, the vector of the corresponding dimension is intercepted from the first sub-word vector, and the intercepted vector is trained using the word vector model to obtain the initial word vector. The dimension of the initial word vector containing sufficient semantic information can be obtained; in order to obtain better task results, word vectors with more dimensions can be trained on this basis.
[0067] The word vector model may be a CBOW or Skip-gram model.
[0068] By using the dimension determination algorithm to determine the dimension corresponding to the initial word vector, the final initial word vector can contain sufficient semantic information and improve the subsequent training effect; then the word vector model is used for training to obtain the initial word vector.
[0069] Furthermore, the obtaining of the initial word vector based on the dimension corresponding to the initial word vector and the first subword vector using a word vector model includes:
[0070] Based on the dimension corresponding to the initial word vector, extracting data of the corresponding dimension from the first subword vector;
[0071] The data is input into a word vector model for optimization processing to obtain the initial word vector.
[0072] Specifically, according to the dimension corresponding to the determined initial word vector, data of the corresponding dimension is intercepted from the first sub-word vector. For example, when the dimension of the first sub-word vector is 500 dimensions and the dimension corresponding to the initial word vector is 260 dimensions, the first 260-dimensional vectors of the first sub-word vector are directly intercepted, and the intercepted first 260-dimensional vectors are input into the word vector model for training, thereby obtaining the initial word vector.
[0073] Through the word vector model training, the intercepted vector is optimized to obtain a better initial word vector.
[0074] S3. Using the initial word vector, perform a natural language processing task to obtain a first performance indicator corresponding to each task;
[0075] Specifically, in the first round of training, the initial word vector is used to perform natural language processing tasks, such as text classification, text matching, and other tasks, to obtain a first performance indicator corresponding to each task, such as the accuracy of processing the natural language processing task.
[0076] S4, performing reinforcement learning training according to the second subword vector to obtain a first dimension added in this round of training, determining a first word vector according to the first dimension corresponding to the initial word vector, performing a natural language processing task using the first word vector, obtaining a second performance indicator corresponding to each task, and giving a reward according to the relationship between the first performance indicator and the second performance indicator;
[0077] Specifically, in the second round of training, reinforcement learning is introduced, and reinforcement learning training is performed based on the second sub-word vector to obtain a first dimension added in this round of training. Based on the first dimension and the dimension corresponding to the initial word vector, the first word vector is determined using the word vector model, that is, the dimension of the first word vector is obtained by adding the first dimension to the dimension corresponding to the initial word vector, and the first word vector is determined based on the dimension of the first word vector and the second sub-word vector; the first word vector is used to perform natural language processing tasks to obtain second performance indicators corresponding to each task, and rewards are given based on the relationship between the first performance indicator and the second performance indicator.
[0078] Similarly, in the third round of training, reinforcement learning training is performed based on the third sub-word vector to obtain the second dimension added in this round of training, and the second word vector is determined based on the second dimension and the dimension corresponding to the first word vector, that is, the dimension corresponding to the first word vector is added with the second dimension to obtain the dimension of the second word vector, and the second word vector is determined based on the dimension of the second word vector and the third sub-word vector, and the second word vector is used to perform natural language processing tasks to obtain the third performance indicator corresponding to each task, and rewards are given based on the relationship between the second performance indicator and the third performance indicator.
[0079] Multiple rounds of training will be carried out to determine the final word vector and its corresponding dimension.
[0080] In the future, the relationship between the performance indicators obtained from two adjacent rounds of training will be judged in turn, and rewards will be given accordingly.
[0081] The total reward value is updated according to the reward, and multiple rounds of training are continuously performed until the total reward value converges.
[0082] Further, such as Figure 3 As shown, the reinforcement learning training is performed according to the second subword vector, and the first dimension added in this round of training includes:
[0083] S41, obtaining the second subword vector used in this round of training;
[0084] S42, inputting the second subword vector used in the current round of training into the deep learning neural network for processing, and obtaining a probability value of increasing the dimension size in the current round of training;
[0085] S43. Determine the dimension corresponding to the maximum probability value as the first dimension.
[0086] Specifically, in the second round and each subsequent round of training, the word vector dimension of the words in the sample is increased by X dimensions, where X is an even number and can be found in the dimension candidate set DS[2,4,6,...,Dim add ], the size of the dimension candidate set DS is M, Dim add This is a preset upper limit on the dimension that can be increased. The value can be the maximum value of the current mainstream word vector dimension and the sum of the dimensions of the initial word vector, which should not exceed 500.
[0087] By obtaining the second subword vector used in this round of training, the second subword vector used in this round of training is input into the deep learning neural network for processing, and the deep learning neural network is a multi-layer neural network of M actions. Take a two-layer neural network as an example, input vector v (that is, the second subword vector, the word vector corresponding to each word in the second subword vector is added to obtain the average value), set the hidden layer weight matrix to w1, use the relu activation function, the bias is b1, and the output o1=relu(w1*v+b1); set the second hidden layer weight matrix to w2, the bias is b2, and the output o2=relu(w2*o1+b2), and then pass the softmax layer to obtain o3, the o3 is the probability value of the increased dimension size in this round of training, and the dimension corresponding to the maximum probability value is determined as the first dimension.
[0088] The negative value of the product of the probability value and the total reward value is used as the training optimization target. The optimization of multi-layer neural networks can adopt common optimization methods in the field of machine learning such as SGD (stochastic gradient descent) and Adam.
[0089] By using reinforcement learning to determine the number of dimensions added in each round, the speed of obtaining the corresponding dimensions of the final word vector can be increased.
[0090] Furthermore, the awarding of rewards according to the relationship between the first performance indicator and the second performance indicator includes:
[0091] averaging the first performance index and the second performance index respectively to obtain a first average performance index and a second average performance index;
[0092] When the second average performance index is greater than or equal to the first average performance index, giving a first reward;
[0093] When the second average performance index is less than the first average performance index, a second reward is given, wherein the first reward is a positive number, and the first reward and the second reward are opposite numbers.
[0094] Specifically, since the first performance indicator and the second performance indicator are distributed as a set of multiple performance indicators obtained by performing the natural language processing task, the first average performance indicator and the second average performance indicator are obtained by averaging the first performance indicator and the second performance indicator respectively. When the second average performance indicator is greater than or equal to the first average performance indicator, that is, the average performance indicator obtained in this round of training is greater than or equal to the average performance indicator obtained in the previous round of training, a first reward is given. The first reward is
[0095]
[0096] Among them, T Cost is the training cost; when the second average performance index is less than the first average performance index, and the average performance index obtained in this round of training is less than the average performance index obtained in the previous round of training, a second reward is given, and the second reward is
[0097]
[0098] The training overhead includes, but is not limited to, indicators such as the node's CPU operating frequency, memory capacity, GPU operating frequency, GPU video memory capacity, hard disk I / O throughput, and uplink network bandwidth.
[0099] By comparing the performance indicators of two adjacent rounds, rewards are given based on the comparison results, so as to finally determine the optimal dimension of the word vector.
[0100] Furthermore, after averaging the first performance indicator and the second performance indicator to obtain the first average performance indicator and the second average performance indicator, the method further includes:
[0101] Get the parameter values of the hardware corresponding to the natural language processing task performed in this round of training;
[0102] Normalize the parameter values corresponding to each hardware to obtain the normalized values corresponding to each hardware;
[0103] Based on the normalized values of each hardware, the training cost value is obtained;
[0104] The second average performance indicator is divided by the training cost value to obtain the first reward.
[0105] Specifically, by obtaining the parameter values of the corresponding hardware when executing the natural language processing task in this round of training, such as CPU operation frequency, memory capacity, GPU operation frequency, GPU memory capacity, hard disk I / O throughput, uplink network bandwidth, etc., the parameter values corresponding to each hardware are normalized to obtain the normalized value corresponding to each hardware. The specific method is as follows: the value of a certain indicator x in a certain historical period is counted, and three values are sampled, which are the highest value x max , average value x ave , minimum value x min , and the following formula is used for calculation:
[0106]
[0107] A normalized value x corresponding to each hardware is obtained, and a training cost value is obtained by multiplying the normalized value corresponding to each hardware by a corresponding weight. The first reward is obtained by dividing the second average performance indicator by the training cost value.
[0108] By normalizing the parameter values corresponding to the hardware, the normalized values corresponding to each hardware are obtained, and the training cost values are obtained by using the normalized values, so as to finally determine the first reward.
[0109] Furthermore, the training cost value obtained based on the normalized value of each hardware includes:
[0110] Obtaining the weight of each hardware based on the hierarchical analysis method;
[0111] According to the weight of each hardware, the normalized value of each hardware is weighted and summed to obtain the training cost value.
[0112] Specifically, the weights of the hardware are obtained by the analytic hierarchy process, such as CPU operation frequency, memory capacity, GPU operation frequency, GPU memory capacity, hard disk I / O throughput, uplink network bandwidth, etc. The analytic hierarchy process (AHP) refers to a decision-making method that decomposes elements related to decision-making into levels such as goals, criteria, and plans, and performs qualitative and quantitative analysis on this basis. According to the weights of the hardware, the normalized values of the hardware are weighted and summed to obtain the training cost value.
[0113] The weights are obtained based on the hierarchical analysis method, and based on the weights, the normalized values of the hardware are weighted summed to obtain the training cost value, so as to facilitate the calculation of the first reward.
[0114] S5. Update the total reward value according to the reward, and perform multiple rounds of training until the total reward value converges, so as to obtain the dimension corresponding to the final word vector determined by the last round of training when the total reward value converges.
[0115] Specifically, the total reward value is updated using the following formula:
[0116]
[0117] Where γ is the gain decay coefficient, n is the number of training cycles, i = 1 to (n-1), S t is the total reward value obtained in the tth training cycle.
[0118] The deep learning neural network is adjusted according to the total reward value of each training cycle, and is trained for multiple training cycles until the total reward value converges. The optimization of the neural network can be performed using methods such as SGD and Adam.
[0119] Furthermore, the negative value of the product of the probability value of increasing the dimension size and the total reward value obtained in each round of training is the training optimization target. The optimization of multi-layer neural networks can adopt common optimization methods in the field of machine learning such as SGD (stochastic gradient descent) and Adam.
[0120] The final word vector and its corresponding dimension may also be stored in the blockchain.
[0121] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0122] The method for determining the word vector dimension of the present embodiment obtains a basic word vector, wherein the basic word vector includes multiple batches of sub-word vectors; based on the first sub-word vector, an initial word vector and a corresponding dimension are determined; by determining the initial vector and the dimension, the speed of determining the final word vector can be improved, and then the initial word vector is used to perform a natural language processing task to obtain a first performance indicator corresponding to each task; reinforcement learning training is performed according to the second sub-word vector to obtain a first dimension added in this round of training, a first word vector is determined according to the first dimension and the dimension corresponding to the initial word vector, and a natural language processing task is performed using the first word vector to obtain a second performance indicator corresponding to each task, and a reward is given according to the relationship between the first performance indicator and the second performance indicator; rewards are given accordingly by comparing the performance indicators obtained in two adjacent rounds of training, and a total reward value is updated according to the reward, and multiple rounds of training are performed until the total reward value converges, and the dimension corresponding to the final word vector determined in the last round of training when the total reward value converges is obtained, thereby obtaining the final word vector and the corresponding dimension, reducing training overhead, and obtaining a word vector with stronger expression ability.
[0123] This embodiment also provides a device for determining the dimension of a word vector, such as Figure 4 The figure shows a functional module diagram of the device for determining the word vector dimension of the present application.
[0124] The word vector dimension determination device 100 described in the present application can be installed in an electronic device. According to the implemented functions, the word vector dimension determination device 100 may include an acquisition module 101, an initial module 102, a first training module 103, a second training module 104 and an iterative update module 105. The module described in the present application may also be referred to as a unit, which refers to a series of computer program segments that can be executed by an electronic device processor and can complete fixed functions, which are stored in the memory of the electronic device.
[0125] In this embodiment, the functions of each module / unit are as follows:
[0126] An acquisition module 101 is used to acquire a basic word vector, where the basic word vector includes multiple batches of sub-word vectors;
[0127] An initial module 102, configured to determine an initial word vector and a corresponding dimension based on the first subword vector;
[0128] Further, the initial module 102 includes a dimension determination submodule and a word vector determination submodule;
[0129] The dimension determination submodule is used to obtain the dimension corresponding to the initial word vector based on the dimension of the first subword vector using a dimension determination algorithm;
[0130] The word vector determination submodule is used to obtain the initial word vector based on the dimension corresponding to the initial word vector and the first sub-word vector using a word vector model.
[0131] By cooperating with the dimension determination submodule and the word vector determination submodule, the dimension determination algorithm is used to determine the dimension corresponding to the initial word vector, so that the final initial word vector contains sufficient semantic information and improves the subsequent training effect; then the word vector model is used for training to obtain the initial word vector.
[0132] Furthermore, the word vector determination submodule includes a truncation unit and an optimization unit;
[0133] The interception unit is used to intercept data of a corresponding dimension from the first subword vector based on the dimension corresponding to the initial word vector;
[0134] The optimization unit is used to input the data into a word vector model for optimization processing to obtain the initial word vector.
[0135] By cooperating with the interception unit and the optimization unit, the intercepted vector is optimized through training through the word vector model to obtain an initial word vector with better effect.
[0136] A first training module 103 is used to perform natural language processing tasks using the initial word vectors to obtain first performance indicators corresponding to each task;
[0137] The second training module 104 is used to perform reinforcement learning training based on the second subword vector to obtain a first dimension added in this round of training, determine a first word vector based on the first dimension corresponding to the initial word vector, perform a natural language processing task using the first word vector, obtain a second performance indicator corresponding to each task, and give a reward based on the relationship between the first performance indicator and the second performance indicator;
[0138] Furthermore, the second training module 104 includes a vector acquisition submodule, a probability acquisition submodule and a dimension determination submodule;
[0139] The vector acquisition submodule is used to obtain the second subword vector used in this round of training;
[0140] The probability acquisition submodule is used to input the second subword vector used in the current round of training into the deep learning neural network for processing, so as to obtain the probability value of increasing the dimension size in the current round of training;
[0141] The dimension determination submodule is used to determine the dimension corresponding to the maximum probability value as the first dimension
[0142] By cooperating with the vector acquisition submodule, the probability acquisition submodule and the dimension determination submodule, reinforcement learning is used to determine the number of dimensions added in each round, which can increase the speed of obtaining the dimensions corresponding to the final word vector.
[0143] Further, the second training module includes an averaging submodule, a first corresponding processing submodule and a second corresponding processing submodule;
[0144] The averaging submodule is used to average the first performance indicator and the second performance indicator respectively to obtain a first average performance indicator and a second average performance indicator;
[0145] The first corresponding processing submodule is used to give a first reward when the second average performance indicator is greater than or equal to the first average performance indicator;
[0146] The second corresponding processing submodule is used to give a second reward when the second average performance index is less than the first average performance index, wherein the first reward is a positive number, and the first reward and the second reward are opposite numbers.
[0147] Through the cooperation of the average submodule, the first corresponding processing submodule and the second corresponding processing submodule, the performance indicators of two adjacent rounds are compared, and rewards are given according to the comparison results, so as to finally determine the optimal dimension of the word vector.
[0148] Furthermore, the second training module also includes a parameter acquisition submodule, a normalization submodule, a processing submodule and a reward acquisition submodule;
[0149] The parameter acquisition submodule is used to obtain the parameter values of the hardware corresponding to the natural language processing task performed in this round of training;
[0150] The normalization submodule is used to normalize the parameter values corresponding to each hardware to obtain the normalized values corresponding to each hardware;
[0151] The processing submodule is used to obtain a training cost value based on the normalized value of each hardware;
[0152] The reward acquisition submodule is used to divide the second average performance indicator by the training cost value to obtain the first reward.
[0153] Through the cooperation of the parameter acquisition submodule, the normalization submodule, the processing submodule and the reward acquisition submodule, the parameter values corresponding to the hardware are normalized to obtain the normalized values corresponding to each hardware. The training cost value is obtained using the normalized values to finally determine the first reward.
[0154] Furthermore, the processing submodule further includes a weight acquisition unit and a weighted summation unit;
[0155] The weight acquisition unit is used to obtain the weight of each hardware based on the hierarchical analysis method;
[0156] The weighted summing unit is used to perform weighted summing on the normalized values of each hardware according to the weight of each hardware to obtain the training overhead value.
[0157] The weight acquisition unit cooperates with the weighted summation unit to obtain the weight based on the hierarchical analysis method, and based on the weight, the normalized value of the hardware is weighted summed to obtain the training cost value, which is convenient for calculating the first reward.
[0158] The iterative update module 105 is used to update the total reward value according to the reward, and obtain the dimension corresponding to the final word vector determined by the last round of training when the total reward value converges by performing multiple rounds of training until the total reward value converges.
[0159] By adopting the above device, the word vector dimension determination device 100 obtains a basic word vector through the coordinated use of the acquisition module 101, the initial module 102, the first training module 103, the second training module 104 and the iterative update module 105, wherein the basic word vector includes multiple batches of sub-word vectors; based on the first sub-word vector, the initial word vector and the corresponding dimension are determined; by determining the initial vector and the dimension, the speed of determining the final word vector can be improved, and then the initial word vector is used to perform natural language processing tasks to obtain the first performance indicator corresponding to each task; reinforcement learning training is performed according to the second sub-word vector to obtain the first dimension added in this round of training, According to the first dimension and the dimension corresponding to the initial word vector, the first word vector is determined, and the first word vector is used to perform natural language processing tasks to obtain second performance indicators corresponding to each task, and rewards are given according to the relationship between the first performance indicator and the second performance indicator; rewards are given accordingly by comparing the performance indicators obtained in two adjacent rounds of training, and the total reward value is updated according to the reward. Multiple rounds of training are performed until the total reward value converges, and the dimension corresponding to the final word vector determined in the last round of training when the total reward value converges is obtained, thereby obtaining the final word vector and the corresponding dimension, reducing training overhead and obtaining a word vector with stronger expressiveness.
[0160] The present application also provides a computer device. Figure 5 , Figure 5 This is a basic structural block diagram of the computer device in this embodiment.
[0161] The computer device 4 includes a memory 41, a processor 42, and a network interface 43 that are interconnected through a system bus. It should be noted that the figure only shows a computer device 4 with components 41-43, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0162] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0163] The memory 41 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 41 can be an internal storage unit of the computer device 4, such as a hard disk or memory of the computer device 4. In other embodiments, the memory 41 can also be an external storage device of the computer device 4, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. equipped on the computer device 4. Of course, the memory 41 can also include both the internal storage unit of the computer device 4 and its external storage device. In this embodiment, the memory 41 is generally used to store the operating system and various application software installed on the computer device 4, such as computer-readable instructions of the method for determining the word vector dimension, etc. In addition, the memory 41 can also be used to temporarily store various types of data that have been output or are to be output.
[0164] The processor 42 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip in some embodiments. The processor 42 is generally used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is used to run computer-readable instructions stored in the memory 41 or process data, such as computer-readable instructions for running the method for determining the word vector dimension.
[0165] The network interface 43 may include a wireless network interface or a wired network interface. The network interface 43 is generally used to establish a communication connection between the computer device 4 and other electronic devices.
[0166] In this embodiment, when a processor executes computer-readable instructions stored in a memory, the steps of the method for determining the dimension of a word vector in the above embodiment are implemented, by obtaining a basic word vector, the basic word vector includes multiple batches of sub-word vectors; based on the first sub-word vector, an initial word vector and a corresponding dimension are determined; by determining the initial vector and the dimension, the speed of determining the final word vector can be improved, and then the initial word vector is used to perform a natural language processing task to obtain a first performance indicator corresponding to each task; reinforcement learning training is performed according to the second sub-word vector to obtain a first dimension added in this round of training, a first word vector is determined according to the first dimension and the dimension corresponding to the initial word vector, and a natural language processing task is performed using the first word vector to obtain a second performance indicator corresponding to each task, and a reward is given according to the relationship between the first performance indicator and the second performance indicator; rewards are given accordingly by comparing the performance indicators obtained in two adjacent rounds of training, and the total reward value is updated according to the reward, and multiple rounds of training are performed until the total reward value converges, and the dimension corresponding to the final word vector determined in the last round of training when the total reward value converges is obtained, thereby obtaining the final word vector and the corresponding dimension, reducing the training overhead, and obtaining a word vector with stronger expression ability.
[0167] The embodiment of the present application also provides a computer-readable storage medium, which stores computer-readable instructions. The computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the method for determining the dimension of a word vector as described above, by obtaining a basic word vector, wherein the basic word vector includes multiple batches of sub-word vectors; based on the first sub-word vector, an initial word vector and a corresponding dimension are determined; by determining the initial vector and the dimension, the speed of determining the final word vector can be improved, and then the initial word vector is used to perform a natural language processing task to obtain a first performance indicator corresponding to each task; reinforcement learning training is performed according to the second sub-word vector to obtain the first performance indicator of this round The first dimension added during training is used to determine the first word vector according to the dimension corresponding to the first dimension and the initial word vector. The first word vector is used to perform natural language processing tasks to obtain second performance indicators corresponding to each task, and rewards are given according to the relationship between the first performance indicator and the second performance indicator. Rewards are given accordingly by comparing the performance indicators obtained in two adjacent rounds of training, and the total reward value is updated according to the rewards. Multiple rounds of training are performed until the total reward value converges, and the dimension corresponding to the final word vector determined in the last round of training when the total reward value converges is obtained, thereby obtaining the final word vector and the corresponding dimension, reducing training overhead and obtaining a word vector with stronger expressiveness.
[0168] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0169] The word vector dimension determination device, computer device, and computer-readable storage medium of the above-mentioned embodiments of the present application have the same technical effects as the word vector dimension determination method of the above-mentioned embodiments, and will not be expanded here.
[0170] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
Claims
1. A method for determining word vector dimensions, characterized in that: The method comprises: Obtain a basic word vector, wherein the basic word vector includes multiple batches of sub-word vectors; Based on the first subword vector, determine the initial word vector and the corresponding dimension; Using the initial word vector, perform a natural language processing task to obtain a first performance indicator corresponding to each task; Reinforcement learning training is performed based on the second subword vector to obtain a first dimension added in this round of training, a first word vector is determined based on the first dimension corresponding to the initial word vector, a natural language processing task is performed using the first word vector to obtain a second performance indicator corresponding to each task, and a reward is given based on the relationship between the first performance indicator and the second performance indicator; Update the total reward value according to the reward, and perform multiple rounds of training until the total reward value converges, thereby obtaining the dimension corresponding to the final word vector determined by the last round of training when the total reward value converges; The determining of the initial word vector and the corresponding dimension based on the first subword vector includes: Based on the dimension of the first subword vector, use the dimension determination algorithm to obtain the dimension corresponding to the initial word vector; Based on the dimension corresponding to the initial word vector and the first subword vector, the initial word vector is obtained using a word vector model.
2. The method for determining the word vector dimension according to claim 1, characterized in that: The step of obtaining the initial word vector based on the dimension corresponding to the initial word vector and the first subword vector by using a word vector model includes: Based on the dimension corresponding to the initial word vector, extracting data of the corresponding dimension from the first subword vector; The data is input into a word vector model for optimization processing to obtain the initial word vector.
3. The method for determining the word vector dimension according to claim 1, characterized in that: The reinforcement learning training is performed according to the second subword vector, and the first dimension added in this round of training includes: Get the second subword vector used in this round of training; Inputting the second subword vector used in the current round of training into the deep learning neural network for processing to obtain a probability value of increasing the dimension size in the current round of training; The dimension corresponding to the maximum probability value is determined as the first dimension.
4. The method for determining word vector dimensions according to claim 1, characterized in that: The awarding of rewards according to the relationship between the first performance indicator and the second performance indicator includes: averaging the first performance index and the second performance index respectively to obtain a first average performance index and a second average performance index; When the second average performance index is greater than or equal to the first average performance index, giving a first reward; When the second average performance index is less than the first average performance index, a second reward is given, wherein the first reward is a positive number, and the first reward and the second reward are opposite numbers.
5. The method for determining word vector dimensions according to claim 4, characterized in that: After averaging the first performance indicator and the second performance indicator respectively to obtain the first average performance indicator and the second average performance indicator, the method further includes: Get the parameter values of the hardware corresponding to the natural language processing task performed in this round of training; Normalize the parameter values corresponding to each hardware to obtain the normalized values corresponding to each hardware; Based on the normalized values of each hardware, the training cost value is obtained; The second average performance indicator is divided by the training cost value to obtain the first reward.
6. The method for determining word vector dimensions according to claim 5, characterized in that: The training cost value obtained based on the normalized value of each hardware includes: Obtaining the weight of each hardware based on the hierarchical analysis method; According to the weight of each hardware, the normalized value of each hardware is weighted and summed to obtain the training cost value.
7. A device for determining word vector dimension, characterized in that: The device comprises: An acquisition module, used to acquire a basic word vector, wherein the basic word vector includes multiple batches of sub-word vectors; An initial module, used to determine an initial word vector and a corresponding dimension based on the first subword vector; Wherein, the initial module includes a dimension determination submodule and a word vector determination submodule; The dimension determination submodule is used to obtain the dimension corresponding to the initial word vector based on the dimension of the first subword vector using a dimension determination algorithm; The word vector determination submodule is used to obtain the initial word vector using a word vector model based on the dimension corresponding to the initial word vector and the first sub-word vector; A first training module is used to use the initial word vector to perform natural language processing tasks and obtain a first performance indicator corresponding to each task; The second training module is used to perform reinforcement learning training based on the second subword vector to obtain a first dimension added in this round of training, determine a first word vector based on the first dimension corresponding to the initial word vector, perform a natural language processing task using the first word vector, obtain a second performance indicator corresponding to each task, and give a reward based on the relationship between the first performance indicator and the second performance indicator; An iterative update module is used to update the total reward value according to the reward, and to obtain the dimension corresponding to the final word vector determined by the last round of training when the total reward value converges by performing multiple rounds of training until the total reward value converges.
8. A computer device, characterized in that: The computer device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores computer-readable instructions, and when the processor executes the computer-readable instructions, it implements the method for determining the word vector dimension as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the method for determining the word vector dimension as described in any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Patent and enterprise correlation measuring method, device and equipment and readable storage medium
CN109558481A
Text word vector model training method, electronic equipment and computer storage medium
CN109635116A