Method, device, equipment and storage medium for training hidden Markov model
By calculating and updating the role weight values in the Hidden Markov model, the problem of requiring a large amount of training data in the existing technology to achieve good entity recognition effect is solved, and the goal of improving entity recognition effect under small-scale data is achieved.
Patent Information
- Application Number
- CN202010056835.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-01-16
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2040-01-16
AI Technical Summary
The existing hidden Markov model requires a large amount of training sample data in entity recognition tasks to achieve better results, resulting in large data demand and complex training.
By obtaining the role probability of candidate word segmentation, compute the role weight value, and update the role weight value using the multi-dimensional stochastic gradient descent algorithm to reduce the need for training sample data.
It realizes improving the entity recognition effect of hidden Markov models under smaller-scale training data, reducing the demand for training data, and improving training efficiency.
Smart Images

Figure CN111222341B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a method, apparatus, device and storage medium for training a hidden Markov model. Background Art
[0002] Entity recognition is a basic task in natural language processing, with a wide range of applications. Named entity recognition is often achieved through supervised learning, semi-supervised learning, unsupervised learning, or hybrid learning machine learning methods. Hidden Markov Model (HMM) is used as a statistical Markov model of the Markov process and unobserved (hidden) state of entity recognition, and recognition is achieved through supervised learning methods. Currently, the Chinese word segmentation system NLPIR, the lexical analyzer HanLP, the Chinese word segmenter Ansj, and the Chinese word segmentation tool Jieba, which use HMM for entity recognition, are based on the definition of roles and data annotation as the model. The probability chain is inferred through the Viterbi algorithm, the maximum probability chain is found, the target word (character) is role-labeled, and then the pattern entity recognition is performed. There may be corresponding entity sequences in different patterns. When predicting and correcting model parameters by observing data, the corresponding states of guided parameter learning are all manually labeled, and the required amount of sample data is very large, or the corresponding states of unguided parameter learning are too many and the weights corresponding to each state are the same, so a larger scale of annotated corpus is needed, so that the HMM model needs a huge training set data to achieve better entity recognition effect. Summary of the invention
[0003] The present application provides a method for training a hidden Markov model by configuration, aiming to reduce the training sample data of a hidden Markov model with higher entity recognition effect.
[0004] In a first aspect, the present application provides a method for training a hidden Markov model, comprising:
[0005] Obtaining the role probability of a candidate word segmentation through a hidden Markov model, wherein the candidate word segmentation is used to indicate the word segmentation of the training text that has been annotated with a role, and the role probability is used to indicate the frequency of occurrence of the role in a preset corpus;
[0006] Calculating role weight values in the training text according to the role probabilities;
[0007] Calculating a value of a loss function for entity recognition of the training text, and using the value of the loss function as an effect value;
[0008] Executing a multi-dimensional stochastic gradient descent algorithm through the loss function to perform cyclic iterative updates on the role weight value;
[0009] Draw an effect value curve according to the effect value;
[0010] Analyze the stability of the convergence of the effect value curve to obtain a target role weight value, and obtain a target role corresponding to the target role weight value;
[0011] Based on the target role, a role chain with the maximum probability value is calculated by using the Viterbi algorithm, and entity recognition is performed according to the role combination pattern in the role chain to obtain a target hidden Markov model.
[0012] Optionally, analyzing the stability of convergence of the effect value curve to obtain a target role weight value includes:
[0013] Obtaining a stiffness matrix of a unit for evaluating the effect value, and calculating a residual value according to the stiffness matrix;
[0014] When the residual value is greater than or equal to the preset convergence value, updating the preset convergence value and the role weight value for a number of loop iterations until the residual value is less than the preset convergence value;
[0015] When the residual value is less than the preset convergence value, it is determined that the effect value curve converges stably;
[0016] The effect value curve with the smallest residual value is obtained, and the role weight value corresponding to the effect value curve with the smallest residual value is used as the target role weight value.
[0017] Optionally, the step of obtaining the role probability of a candidate word segmentation through a hidden Markov model, wherein the candidate word segmentation is used to indicate a word segmentation of a training text that has been annotated with a role, and the role probability is used to indicate a frequency of occurrence of a role in a preset corpus, and calculating a role weight value in the training text according to the role probability includes:
[0018] Analyze the field to which the training text belongs, call the core dictionary of the field to perform word segmentation on the training text, and obtain candidate word segmentations;
[0019] Obtaining a rough coding result corresponding to the candidate word segmentation, and calculating the coding with the highest matching degree with the candidate word segmentation in the rough coding result, and taking the role corresponding to the coding with the highest matching degree as the role of the candidate word segmentation;
[0020] Calculating a first role frequency of the role of the candidate participle in the training text, and calculating a second role frequency of the role of the candidate participle in the corpus corresponding to the field to which it belongs;
[0021] Calculating a role probability according to the first role frequency and the second role frequency;
[0022] The contribution of the role of the candidate participle to the compound word corresponding to the field is calculated based on the role probability, and the contribution is used as the role weight value. The compound word is used to indicate a word that conforms to grammatical rules and is composed of multiple candidate participles.
[0023] Optionally, the step of calculating a role chain with a maximum probability value based on the target role by using a Viterbi algorithm, and performing entity recognition according to a role combination pattern in the role chain to obtain a target hidden Markov model includes:
[0024] pass Calculate the emission probability of the role corresponding to the target role weight value, where Role represents the role corresponding to the target role weight value, w represents the word corresponding to the role, P(w|Role) represents the probability of word w appearing under the role Role, Represents the weight of the role, represents the formula approximated by the law of large numbers, wherein f(w,Role) represents the frequency of the role marked with w, and f(Role) represents the frequency of the overall occurrence of words marked as roles. Represents the average frequency of all roles;
[0025] Calculating the prior probability and state transition probability of the role corresponding to the target role weight value;
[0026] Analyze the emission probability, the prior probability and the state transition probability by using a Viterbi algorithm, and calculate a role chain with a maximum probability value, wherein the role chain includes a plurality of role combination modes;
[0027] Sort the role chains corresponding to the probability values from large to small according to the probability values to obtain the best role sorting sequence;
[0028] The hidden Markov model corresponding to the optimal role sorting sequence is used as the target hidden Markov model.
[0029] Optionally, the calculating the role weight value in the training text according to the role probability further includes:
[0030] Perform word segmentation processing on the training text based on the knowledge graph to obtain candidate word segmentations, and obtain the role tags of the candidate word segmentations in the knowledge graph to obtain the roles of the candidate word segmentations;
[0031] Calculating the third role frequency of the role of the candidate participle in the training text, and calculating the fourth role frequency of the role of the candidate participle in the corpus;
[0032] Obtaining the role probability by calculating the ratio of the third role frequency to the fourth role frequency;
[0033] The contribution of the role of the candidate word segment to the compound word corresponding to the field is calculated based on the role probability, and the contribution is used as the role weight value.
[0034] Optionally, calculating a value of a loss function for entity recognition of the training text and using the value of the loss function as an effect value includes:
[0035] Labeling the training samples into positive samples and negative samples;
[0036] pass Calculate the F1 score value of entity recognition for the training text, wherein the TP represents the number of the training texts accurately recognized as positive sample entities, the FP represents the number of the training texts correctly recognized as negative sample entities, and the FN represents the number of the training texts incorrectly recognized as positive sample entities;
[0037] pass The F1 score value is used as the loss function value of the synchronously updated iterative operation, the state represents the role weight, the Value represents the F1 score value, the Value(state) represents the reward value after the role weight value is iteratively updated, the Reward(state) represents the current reward value, and the Represents the expected return of the parameter adjustment operation after the loop iteration.
[0038] Optionally, executing a multi-dimensional stochastic gradient descent algorithm through the loss function to perform cyclic iterative updates on the role weight value includes:
[0039] Obtaining parameters corresponding to the role weight value, wherein the parameters refer to the weight of a neuron and the bias of a neuron in a hidden Markov model;
[0040] pass The partial derivative of the parameter is obtained to obtain a stochastic gradient, and the parameter and the role weight value are updated according to the stochastic gradient loop iteration, wherein j represents the number of the parameters, m represents the number of samples of the training text, and represents the loss function, the represents the weight of the neuron in the hidden Markov model, represents the bias of the neuron, the represents the learning rate, Indicates taking a sample from all training text instances.
[0041] In a second aspect, the present application provides a device for training a hidden Markov model, which has the function of implementing the method corresponding to the platform for training a hidden Markov model provided in the first aspect. The function can be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions, and the modules can be software and / or hardware.
[0042] The device for training the hidden Markov model comprises:
[0043] An acquisition module, used for acquiring the role probability of a candidate word segmentation through a hidden Markov model, wherein the candidate word segmentation is used to indicate the word segmentation of a training text that has been annotated with a role, and the role probability is used to indicate the frequency of occurrence of a role in a preset corpus;
[0044] A calculation module, used for calculating the role weight value in the training text according to the role probability;
[0045] The calculation module is also used to calculate the value of the loss function for entity recognition of the training text, and use the value of the loss function as the effect value;
[0046] An iterative update module, used to execute a multi-dimensional stochastic gradient descent algorithm through the loss function to perform cyclic iterative updates on the role weight value;
[0047] A drawing module, used for drawing an effect value curve according to the effect value;
[0048] An analysis module, used for analyzing the stability of the convergence of the effect value curve to obtain a target role weight value, and obtaining a target role corresponding to the target role weight value;
[0049] The recognition module is used to calculate the role chain with the maximum probability value based on the target role through the Viterbi algorithm, and perform entity recognition according to the role combination pattern in the role chain to obtain the target hidden Markov model.
[0050] Optionally, the analysis module is further used for:
[0051] Obtaining a stiffness matrix of a unit for evaluating the effect value, and calculating a residual value according to the stiffness matrix;
[0052] When the residual value is greater than or equal to the preset convergence value, updating the preset convergence value and the role weight value for a number of loop iterations until the residual value is less than the preset convergence value;
[0053] When the residual value is less than the preset convergence value, it is determined that the effect value curve converges stably;
[0054] The effect value curve with the smallest residual value is obtained, and the role weight value corresponding to the effect value curve with the smallest residual value is used as the target role weight value.
[0055] Optionally, the calculation module is further used for:
[0056] Analyze the field to which the training text belongs, call the core dictionary of the field to perform word segmentation on the training text, and obtain candidate word segmentations;
[0057] Obtaining a rough coding result corresponding to the candidate word segmentation, and calculating the coding with the highest matching degree with the candidate word segmentation in the rough coding result, and taking the role corresponding to the coding with the highest matching degree as the role of the candidate word segmentation;
[0058] Calculating a first role frequency of the role of the candidate participle in the training text, and calculating a second role frequency of the role of the candidate participle in the corpus corresponding to the field to which it belongs;
[0059] Calculating a role probability according to the first role frequency and the second role frequency;
[0060] The contribution of the role of the candidate participle to the compound word corresponding to the field is calculated based on the role probability, and the contribution is used as the role weight value. The compound word is used to indicate a word that conforms to grammatical rules and is composed of multiple candidate participles.
[0061] Optionally, the identification module is further used for:
[0062] pass Calculate the emission probability of the role corresponding to the target role weight value, where Role represents the role corresponding to the target role weight value, w represents the word corresponding to the role, P(w|Role) represents the probability of word w appearing under the role Role, Represents the weight of the role, represents the formula approximated by the law of large numbers formula, wherein f(w,Role) represents the frequency of the role marked with w, and f(Role) represents the frequency of the overall occurrence of words marked as roles. Represents the average frequency of all roles;
[0063] Calculating the prior probability and state transition probability of the role corresponding to the target role weight value;
[0064] Analyze the emission probability, the prior probability and the state transition probability by using a Viterbi algorithm, and calculate a role chain with a maximum probability value, wherein the role chain includes a plurality of role combination patterns;
[0065] Sort the role chains corresponding to the probability values from large to small according to the probability values to obtain the best role sorting sequence;
[0066] The hidden Markov model corresponding to the optimal role sorting sequence is used as the target hidden Markov model.
[0067] Optionally, the calculation module is further used for:
[0068] Perform word segmentation processing on the training text based on the knowledge graph to obtain candidate word segmentations, and obtain the role tags of the candidate word segmentations in the knowledge graph to obtain the roles of the candidate word segmentations;
[0069] Calculating the third role frequency of the role of the candidate participle in the training text, and calculating the fourth role frequency of the role of the candidate participle in the corpus;
[0070] Obtaining the role probability by calculating the ratio of the third role frequency to the fourth role frequency;
[0071] The contribution of the role of the candidate word segment to the compound word corresponding to the field is calculated based on the role probability, and the contribution is used as the role weight value.
[0072] Optionally, the calculation module is further used for:
[0073] Labeling the training samples into positive samples and negative samples;
[0074] pass Calculate the F1 score value of entity recognition for the training text, wherein the TP represents the number of the training texts accurately recognized as positive sample entities, the FP represents the number of the training texts correctly recognized as negative sample entities, and the FN represents the number of the training texts incorrectly recognized as positive sample entities;
[0075] pass The F1 score value is used as the loss function value of the synchronously updated iterative operation, the state represents the role weight, the Value represents the F1 score value, the Value(state) represents the reward value after the role weight value is iteratively updated, the Reward(state) represents the current reward value, and the Represents the expected return of the parameter adjustment operation after the loop iteration.
[0076] Optionally, the iterative update module is further used for:
[0077] Obtaining parameters corresponding to the role weight value, wherein the parameters refer to the weight of a neuron and the bias of a neuron in a hidden Markov model;
[0078] pass The partial derivative of the parameter is obtained to obtain a stochastic gradient, and the parameter and the role weight value are updated according to the stochastic gradient loop iteration, wherein j represents the number of the parameters, m represents the number of samples of the training text, and represents the loss function, the represents the weight of the neuron in the hidden Markov model, represents the bias of the neuron, the represents the learning rate, Indicates taking a sample from all training text instances.
[0079] In addition, to achieve the above-mentioned purpose, the present invention also provides a method device for training a hidden Markov model, the device comprising: a memory, a processor, and a method program for training a hidden Markov model stored in the memory and executable on the processor, wherein the method program for training a hidden Markov model implements the steps of the method for training a hidden Markov model as described above when executed by the processor.
[0080] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, on which is stored a method program for training a hidden Markov model, and when the method program for training a hidden Markov model is executed by a processor, the steps of the method for training a hidden Markov model as described above are implemented.
[0081] The present application provides a dimensional improved hidden Markov model (HMM) entity recognition method based on role weight training, which can obtain the effect value of training text entity recognition by training target words that mark probability values of different roles, and use the weight corresponding to the maximum effect value as the final trained role weight result. The model is improved based on role weight training, reducing the training sample data of the HMM model with higher entity recognition effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0082] Figure 1 A schematic diagram of a flow chart of a first embodiment of a method for training a hidden Markov model in the present application;
[0083] Figure 2 A schematic diagram of the structure of the first embodiment of the apparatus for training a hidden Markov model in the present application;
[0084] Figure 3 This is a schematic diagram of the structure of the first embodiment of the device for training a hidden Markov model in the present application.
[0085] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0086] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application. The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than the content illustrated or described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device including a series of steps or modules is not necessarily limited to those steps or modules clearly listed, but may include other steps or modules that are not clearly listed or inherent to these processes, methods, products or devices. The division of the modules that appear in the present application is only a logical division, and there may be other division methods when implemented in practical applications, for example, multiple modules can be combined into or integrated in another system, or some features can be ignored or not executed.
[0087] In order to solve the above technical problems, this application mainly provides the following technical solutions
[0088] The present application provides a dimensional improved hidden Markov model (HMM) entity recognition method based on role weight training, which can obtain the effect value of training text entity recognition by training target words that mark probability values of different roles, and use the weight corresponding to the maximum effect value as the final trained role weight result. The model is improved based on role weight training, reducing the training sample data of the HMM model with higher entity recognition effect.
[0089] Please refer to Figure 1 The following is an example of a method for training a hidden Markov model provided by the present application, the method comprising:
[0090] 101. The role probability of the candidate segmentation word is obtained through the hidden Markov model. The candidate segmentation word is used to indicate the segmentation word of the training text that has been annotated with the role, and the role probability is used to indicate the frequency of the role appearing in the preset corpus.
[0091] The role probability of candidate word segmentation of the training text with role annotation is obtained through the hidden Markov model, and the role weight value is calculated according to the role probability to obtain the role weight value. The role probability is the frequency of the role in the corpus. The entity role is defined for the training text, and the training text is segmented to obtain the candidate word segmentation.
[0092] 102. Calculate the role weight value in the training text according to the role probability.
[0093] The candidate word segmentation is labeled with roles, the role probability is calculated based on the labeled roles, and the role weight value is calculated based on the role probability. For example, if the training text is "We remember Comrade Zhou Moumou", the corresponding role is "AKBYL", then the role frequencies of each role in the training text are: F(A) = 1, F(K) = 1, F(B) = 1, F(Y) = 1, F(L) = 1, and the frequency values obtained by statistically analyzing each role with a large number of corpus sets in the corpus approximate the probability value. The role probability of each role can be obtained by statistically analyzing the frequency of each role in the corpus set of the corpus. The contribution of role B to the discovery of name naming when the role frequency is F(B) = 1 is 1.2, that is, the role weight of role B is 1.2, and the contribution of role K to the discovery of name naming when the role frequency is F(K) = 1 is 0.9, that is, the role weight value of role K is 0.9, and the role A, role Y and role L are the same, which will not be described in detail here. The above examples are only for illustration, and the actual operation and accuracy of the content are not considered.
[0094] 103. Calculate the value of the loss function for entity recognition of the training text, and use the value of the loss function as the effect value.
[0095] The effect of the hidden Markov model is evaluated to verify the performance of the hidden Markov model. The value of the loss function refers to the sum of squares of the difference between the theoretical value and the test value of the machine learning model.
[0096]
[0097] L(Y, f(X)) refers to the loss function, Y refers to the theoretical role probability in the test set and training set data, and f(X) refers to the actual role probability predicted by the model through the features in the training set and the prediction set. To obtain a hidden Markov model with better performance and better entity recognition effect. The entity recognition effect of the hidden Markov model can be evaluated by calculating the precision, recall, accuracy, harmonic mean of precision and recall, true positive rate TPR, false positive rate FPR and the area under the receiver operating characteristic ROC curve of the hidden Markov model.
[0098] 104. Execute a multi-dimensional stochastic gradient descent algorithm through the loss function to iteratively update the role weight value.
[0099] According to the loss function, the role weight is updated iteratively through the multi-dimensional stochastic gradient descent algorithm. The role weight parameters are tuned by synchronous update iterative operation, that is, the profit results obtained after each adjustment of the role weight parameters are not updated immediately, but stored after all parameters are updated, and then updated uniformly. The tuning process of the role weight parameters is to find a series of parameters from initialization to the final optimal return:
[0100] . By adopting the multi-dimensional stochastic gradient descent algorithm, the efficiency of the loop iteration update operation and the convergence speed of the hidden Markov model are improved. The training effect (loss function value) of the previous round is modified by the multi-dimensional stochastic gradient descent algorithm to the role weight value of the previous operation, and then used as the role weight value of the hidden Markov model training of the next operation until the optimal role weight value is obtained.
[0101] By controlling the role weights, the entity recognition effect can be improved by 10% with a small amount of training data. For example, in name recognition, increasing the weights of roles B, C, D, and E can significantly improve the name recognition effect, with a 4.3% increase in the F1 value (the entity recognition effect value of the hidden Markov model); reducing the weights of roles K and L can also improve the name recognition effect by 5%; increasing the weights of roles X, Y, and Z can also improve the name recognition effect to a certain extent; and changing the weights of roles A and M will not change the name recognition effect. Finally, by jointly controlling the role weights, the name recognition effect can be improved by 10%. The above examples are for illustration only, and the actual operation and accuracy of the content are not considered.
[0102] 105. Draw the effect value curve according to the effect value.
[0103] Perform stability analysis on the convergence of negative curves on the effect value to obtain the target role corresponding to the target role weight value. When the learning rate changes slightly, the training state will change accordingly. If the change is not large, and when the training state returns to the original state, the neuron will return to the original state accordingly, then the process is called stable; on the contrary, if the learning rate changes slightly, the operating state changes significantly, and the neuron cannot return to the original state after the training state returns to the original state, then the process is called unstable. Stability analysis must be performed to study these processes.
[0104] 106. Analyze the stability of the convergence of the effect value curve to obtain the target role weight value, and obtain the target role corresponding to the target role weight value.
[0105] The negative value of the effect value is used to judge the curve convergence stability. The loss function is iterated through a multi-dimensional stochastic gradient descent algorithm so that the negative value curve of the effect value gradually tends to the minimum value. When the negative value curve of the effect value is a nonlinear curve, the minimum value of the minimum value can be obtained by comparing the sizes of multiple minimum values, the role weight value corresponding to the minimum value of the minimum value can be obtained, the role weight value corresponding to the minimum value of the minimum value can be obtained, the role weight value corresponding to the minimum value of the minimum value can be used as the target role weight value, and the target role corresponding to the target role weight value can be obtained. When the negative value curve of the effect value is a convex function curve, the role weight value corresponding to the only minimum value can be used as the target role weight value, and the target role corresponding to the target role weight value can be obtained. It is also possible to compare the residual value with the convergence value to obtain the role weight value corresponding to the minimum value of the convergent and stable negative value curve as the target weight value, and obtain the target role corresponding to the target role weight value. Among them, the stability analysis of the convergence of the negative value curve also performs convergence verification. When the negative value curve does not converge and stabilize, the non-convergence solution result and the possible factors causing the non-convergence are obtained, and the query command resultsummary in the postprocessor post1 is called to set the non-convergence solution result as the number of sub-steps.
[0106] 107. Based on the target role, the role chain with the largest probability value is calculated through the Viterbi algorithm, and entity recognition is performed according to the role combination pattern in the role chain to obtain the target hidden Markov model.
[0107] The role chains corresponding to the probability values are sorted from large to small according to the probability values to obtain the best role sorting sequence, find the best role sorting sequence that is most similar to the actual situation, and obtain the target hidden Markov model corresponding to the best role sorting sequence. The target hidden Markov model can avoid the complexity of modeling the behavior time interval. Because human motion has Markov properties, the current state is only affected by the previous state. This method regards human motion as a Markov process that cannot be directly observed, fully considers the dynamic process of human behavior, regards the human motion sequence as a traversal between states, and probabilistically identifies the human motion spatiotemporal sequence. This method is currently the most commonly used human motion recognition method. Its advantages are good robustness to small changes in motion on time and space scales, can avoid modeling behavior time intervals, and the duration of motion is well resolved. The disadvantages are that the calculation is relatively complex, a nonlinear model needs to be established, model training is complex, there is no fixed solution, and the appropriate number of states and dimension of the feature vector need to be selected.
[0108] The present application provides a dimensional improved hidden Markov model (HMM) entity recognition method based on role weight training, which can obtain the effect value of training text entity recognition by training target words that mark probability values of different roles, and use the weight corresponding to the maximum effect value as the final trained role weight result. The model is improved based on role weight training, reducing the training sample data of the HMM model with higher entity recognition effect.
[0109] Furthermore, based on the first embodiment of the method for training a hidden Markov model of the present invention, a second embodiment of the method for training a hidden Markov model of the present invention is proposed.
[0110] In this embodiment, the stability of the convergence of the effect value curve is analyzed to obtain the target role weight value, including:
[0111] Get the stiffness matrix of the element for which the effect value is to be evaluated, and calculate the residual value based on the stiffness matrix.
[0112] In mathematical statistics, residual refers to the difference between the actual observed value and the estimated value. Using the information provided by the residual to examine the rationality of the model assumptions and the reliability of the data is called residual analysis.
[0113] When the residual value is less than the preset convergence value, it is determined that the effect value curve converges stably.
[0114] Iteration is the activity of repeating a feedback process, usually to get closer to the desired goal or result. Each repetition of the process is called an iteration, and the result of each iteration is used as the initial value of the next iteration.
[0115] Get the effect value curve with the minimum residual value, and use the role weight value corresponding to the minimum residual value as the target role weight value.
[0116] For example, if the convergence value is 0.01, convergence is determined when the residual value is less than 0.01.
[0117] Get the effect value curve with the minimum residual value, and use the role weight value corresponding to the minimum residual value as the target role weight value.
[0118] For example, if the residual value of A is 0.001 and the residual value of B is 0.002, the role weight value of A is used as the target weight value.
[0119] By comparing the residual value with the convergence value, we can analyze whether the negative value curve of the effect value is convergent and stable. We use the role weight value corresponding to the minimum value of the convergent and stable negative value curve of the effect value (i.e., the maximum value of the effect value) as the target role weight value, and obtain the target role corresponding to the target role weight value to obtain the optimal return value of the optimal operation path.
[0120] Furthermore, based on the first embodiment of the method for training a hidden Markov model of the present invention, a third embodiment of the method for training a hidden Markov model of the present invention is proposed.
[0121] In this embodiment, the role probability of the candidate segmentation is obtained through the hidden Markov model, the candidate segmentation is used to indicate the segmentation of the training text after the role annotation, the role probability is used to indicate the frequency of the role in the preset corpus, and the role weight value in the training text is calculated according to the role probability, including:
[0122] Analyze the field to which the training text belongs, call the core dictionary of the field to perform word segmentation on the training text, and obtain candidate word segmentations.
[0123] Generally, the samples need to be divided into three independent parts: training set, validation set and test set. The training set is used to estimate the model, the validation set is used to determine the network structure or the parameters that control the complexity of the model, and the test set is used to test the performance of the optimal model. A typical division is that the training set accounts for 50% of the total samples, and the other 25% each. The three parts are randomly selected from the samples. For example, if I love to eat apples, I can divide the words into four words: I, love, eat, and apple.
[0124] Obtain the coarse-division encoding result corresponding to the candidate segmentation, and calculate the encoding with the highest matching degree with the candidate segmentation in the coarse-division encoding result, and take the role corresponding to the encoding with the highest matching degree as the role of the candidate segmentation.
[0125] Coding is the process of converting information from one form or format to another. It is also called the code of computer programming language, or simply coding. Use a predetermined method to encode text, numbers or other objects into digital form, or convert information or data into a specified electrical pulse signal. Coding is widely used in electronic computers, televisions, remote controls and communications. Coding is the process of converting information from one form or format to another. For example, I love to eat apples, which can be divided into four words: I, love, eat, and apple. Encode 16 words such as I, love, eat, apple, banana, grape, etc. with a hexadecimal number, and the result is 11110000000000.
[0126] Calculate the first role frequency of the candidate word in the training text, and calculate the second role frequency of the candidate word in the corpus corresponding to the field. Use the term frequency-inverse document frequency (TF-IDF) formula to calculate the first frequency and the second frequency.
[0127] The role probability is calculated based on the first role frequency and the second role frequency. The role probability is calculated using cosine similarity.
[0128] The contribution of the role of the candidate participle to the compound word corresponding to the corresponding field is calculated based on the role probability, and the contribution is used as the role weight value. The compound word is used to indicate a word that conforms to grammatical rules and is composed of multiple candidate participles.
[0129] Grammatical rules are the habits that must be followed when speaking. They exist objectively and are summarized and organized by linguists, who then choose appropriate ways to describe them. Taking "I love to eat apples" as an example, the segmentation results are five words: I, love, eat, and apple. Compound words can include love to eat, eat apples, love apples, etc.
[0130] In the above manner, the training text is segmented by using the core dictionary of the field of the training text to improve the accuracy of the candidate segmentation and ensure the accurate acquisition of the role of the candidate segmentation. The role of the candidate segmentation is roughly divided and then the optimal encoding calculation is performed to improve the accuracy of role acquisition.
[0131] Furthermore, based on the first embodiment of the method for training a hidden Markov model of the present invention, a fourth embodiment of the method for training a hidden Markov model of the present invention is proposed.
[0132] In this embodiment, the role chain with the largest probability value is calculated based on the target role by using the Viterbi algorithm, and entity recognition is performed according to the role combination pattern in the role chain to obtain the target hidden Markov model, including:
[0133] pass Calculate the emission probability of the role corresponding to the target role weight value. Role represents the role corresponding to the target role weight value, w represents the word corresponding to the role, and P(w|Role) represents the probability of word w appearing under the role Role. Indicates the weight of the role, represents the formula approximated by the law of large numbers, f(w,Role) represents the frequency of w corresponding to the labeled role, and f(Role) represents the overall frequency of words labeled as role. Indicates the average frequency of all roles.
[0134] The law of large numbers is a law that describes the nature of probability when the number of trials is large. The law of large numbers is not an empirical law, but a theorem that has been strictly proven under some additional conditions. It is a natural law and is usually not called a theorem but the law of large numbers. When the average frequency of all characters is 10 and the frequency of occurrence is 100, the weight of the character is 2.
[0135] Calculate the prior probability and state transition probability of the role corresponding to the target role weight value.
[0136] An informative prior expresses specific, explicit information about the variable. Take, for example, the distribution of temperatures before noon tomorrow. A reasonable approach would be to take the normal distribution with expected value equal to today's noon temperature and variance equal to the daily variation in atmospheric temperature, or the distribution of temperatures for that day of the year.
[0137] The emission probability, prior probability and state transition probability are analyzed by Viterbi algorithm, and the role chain with the maximum probability value is calculated. The role chain includes multiple role combination modes.
[0138] Transition probability is an important concept in Markov chains. If a Markov chain is composed of m states, historical data is converted into a sequence composed of these m states. Starting from any state, after any transition, one of the states 1, 2, ..., m will appear. This transition between states is called transition probability. For example, if the emission probability of A is 0.5 and the prior probability is 0.6, the probability value can be 1*0.5+0.6*1=1.1 or 2*0.5+0.6=1.6. The weights of the emission probability, prior probability and state transition probability are determined according to the application scenario.
[0139] Sort the role chains corresponding to the probability values from large to small according to the probability values to obtain the best role sorting sequence.
[0140] The bubble sort method can be used to arrange the role sequence in order of probability values.
[0141] The hidden Markov model corresponding to the best role sorting sequence is used as the target hidden Markov model.
[0142] The statistical machine learning method regards named entity recognition (NER) as a sequence labeling task, and uses large-scale corpus to learn the labeling model, so as to label each position of the sentence. Commonly used models applied to NER tasks include generative models HMM, discriminative models conditional random fields (CRF), etc.
[0143] In the above manner, the multi-dimensional stochastic gradient descent method is adopted to improve the operational efficiency of the loop iteration update and accelerate the convergence speed of the hidden Markov model. The loss function is processed by the multi-dimensional stochastic gradient descent method to tune the parameters from initialization to the final optimal return, so as to obtain the maximum benefit value after a series of role weight parameter adjustment operations in the current state.
[0144] Furthermore, based on the first embodiment of the method for training a hidden Markov model of the present invention, a fifth embodiment of the method for training a hidden Markov model of the present invention is proposed.
[0145] In this embodiment, the role probability of the candidate word segmentation is obtained through the hidden Markov model, and the role weight value is calculated according to the role probability to obtain the role weight value, which also includes:
[0146] The training text is segmented based on the knowledge graph to obtain candidate segmentations, and the role tags of the candidate segmentations are obtained in the knowledge graph to obtain the roles of the candidate segmentations.
[0147] Knowledge graph, known as knowledge domain visualization or knowledge domain mapping map in the library and information industry, is a series of various graphics that show the development process and structural relationship of knowledge. It uses visualization technology to describe knowledge resources and their carriers, and mine, analyze, construct, draw and display knowledge and their mutual connections. For example, if Xiao Ming loves to eat apples, the segmentation role is Xiao Ming, and the segmentation results are the four words Xiao Ming, love, eat, and apple.
[0148] The third role frequency of the candidate word in the training text is calculated, and the fourth role frequency of the candidate word in the corpus is calculated.
[0149] The third frequency and the fourth frequency are calculated using the term frequency-inverse document frequency TF-IDF formula.
[0150] The role probability is obtained by calculating the ratio of the third role frequency to the fourth role frequency. For example, if the third role frequency is 10 and the fourth role frequency is 20, then the role probability = 10 / 20 = 0.5;
[0151] Based on the role probability, the contribution of the candidate segmentation role to the compound word corresponding to the field is calculated, and the contribution is used as the role weight value. A word composed of two or more morphemes is called a compound word. In modern Chinese vocabulary, compound words account for the vast majority. Taking "I love to eat apples" as an example, the segmentation results are four words: I, love, eat, and apple. Compound words can include love to eat, eat apples, love apples, etc. Taking Xiao Ming's role probability as 0.5 as an example, the probability of Xiao Ming eating apples in each text is 0.1, and the weight value is 0. / 1*0.5=0.2.
[0152] In the above manner, a knowledge graph is constructed based on candidate segmentation words, role tags, parts of speech, word meanings, grammar, and grammatical relations. The training text is identified and analyzed through the knowledge graph, the training text is segmented, and the corresponding role tags are obtained in the knowledge graph based on the candidate segmentation words, thereby obtaining the role of the candidate segmentation word. The frequency of the role of the candidate segmentation word is calculated to obtain the role probability, and the role weight value is obtained by analyzing the role probability. By obtaining the role weight value, the hidden Markov model can be trained by updating the role weight value in the future, so as to achieve the function of improving the entity recognition effect with a small amount of training data.
[0153] Furthermore, based on the first embodiment of the method for training a hidden Markov model of the present invention, a sixth embodiment of the method for training a hidden Markov model of the present invention is proposed.
[0154] In this embodiment, the value of the loss function for entity recognition of the training text is calculated, and the value of the loss function is used as the effect value, including:
[0155] The training samples are labeled as positive samples and negative samples. Positive samples are samples corresponding to the categories we want to correctly classify. For example, if we want to classify a picture to determine whether it belongs to a car, then during training, the picture of the car is the positive sample. In principle, any other picture that is not a car can be selected as a negative sample. In this way, a car classification network can be trained. When testing this network, it will be found that it will mistakenly report some non-car pictures as cars. These false positive pictures are "difficult samples". When training later, these difficult samples are added to the negative sample set for training. The final network model effect will be better. This process is called "difficult example mining". In addition, when selecting negative samples, in principle, any non-car picture can be selected as a negative sample, but the more reasonable situation should be to consider the actual application scenario. For example, the actual application is to classify the pictures captured on the dashcam. Then, the negative samples should be other non-car pictures captured, such as roads, trees, street lights, etc.
[0156] pass Calculate the F1 score of entity recognition for the training text. TP represents the number of training texts that are correctly recognized as positive examples, FP represents the number of training texts that are correctly recognized as negative examples, and FN represents the number of training texts that are incorrectly recognized as positive examples. Calculate the recall and precision through the above steps, and use the recall and precision to evaluate whether the model is usable.
[0157] Taking the recall rate of model A as 0 and the precision as 1, and the recall rate of model B as 0.7 and the precision as 0.8 as an example, the score of A is higher than that of B. The above formula can be used to select a model with higher precision.
[0158] pass The F1 score value is used as the loss function value of the synchronously updated iterative operation. State represents the role weight, Value represents the F1 score value, Value(state) represents the reward value after the role weight value is iteratively updated, and Reward(state) represents the current reward value. It indicates that the expected return of the parameter adjustment operation after the loop iteration continuously updates the model score and the value of the loss function. When all the training data are input, the iteration of the model is stopped, and the model with the smallest error is obtained as the ideal model and deployed.
[0159] In the above method, the emission probability value is the probability of the word w corresponding to the role condition Role corresponding to the target role weight value. When calculating the emission probability value, the role is regarded as a lamp, and the probability size is the brightness of the lamp. This method is to make different adjustments to the brightness of the lamps of different roles, and then calculate the role chain with the largest probability value, so that it is easier to obtain the correct entity. Through this operation, the role weight value is adjusted flexibly, so that the hidden Markov model can achieve the effect of the original large training set data in a small training set data.
[0160] Furthermore, based on the first embodiment of the method for training a hidden Markov model of the present invention, a seventh embodiment of the method for training a hidden Markov model of the present invention is proposed.
[0161] In this embodiment, a multi-dimensional stochastic gradient descent algorithm is performed through a loss function to complete the cyclic iterative update of the role weight value, including:
[0162] Get the parameters corresponding to the role weight value. The parameters refer to the weights and biases of neurons in the hidden Markov model.
[0163] pass The stochastic gradient is obtained by partial derivative of the parameters. The parameters and role weight values are updated according to the stochastic gradient loop iteration. j represents the number of parameters, and m represents the number of samples of training text. represents the loss function, represents the weight of the neuron in the hidden Markov model, represents the bias of the neuron, represents the learning rate, Indicates taking a sample from all training text instances.
[0164] Gradient descent is an iterative method that can be used to solve least squares problems. Gradient descent is one of the most commonly used methods for solving model parameters of machine learning algorithms, that is, unconstrained optimization problems. Take the linear function y=x*x+1 as an example. The derivative of the function is 2x. When a value is 3, when x changes to -0.1, it is calculated according to y=3*3+1+(-0.1*2*3)=9.4.
[0165] In the above manner, the multi-dimensional stochastic gradient descent method is adopted to improve the operational efficiency of the loop iteration update and accelerate the convergence speed of the hidden Markov model. The loss function is processed by the multi-dimensional stochastic gradient descent method to tune the parameters from initialization to the final optimal return, so as to obtain the maximum benefit value after a series of role weight parameter adjustment operations in the current state.
[0166] The present invention also provides a method and device for training a hidden Markov model. Figure 2 , Figure 2 This is a schematic diagram of a module of an embodiment of a method and apparatus for training a hidden Markov model of the present invention. In this embodiment, the method and apparatus for training a hidden Markov model includes:
[0167] An acquisition module 201 is used to acquire the role probability of a candidate word segmentation through a hidden Markov model, wherein the candidate word segmentation is used to indicate the word segmentation of the training text that has been annotated with a role, and the role probability is used to indicate the frequency of occurrence of the role in a preset corpus;
[0168] A calculation module 202, configured to calculate a role weight value in the training text according to the role probability;
[0169] The calculation module 202 is also used to calculate the value of the loss function for entity recognition of the training text, and use the value of the loss function as the effect value;
[0170] An iterative updating module 203, configured to execute a multi-dimensional stochastic gradient descent algorithm through the loss function to perform cyclic iterative updating on the role weight value;
[0171] A drawing module 204, used for drawing an effect value curve according to the effect value;
[0172] An analysis module 205 is used to analyze the stability of the convergence of the effect value curve to obtain a target role weight value and obtain a target role corresponding to the target role weight value;
[0173] The identification module 206 is used to calculate the role chain with the maximum probability value based on the target role through the Viterbi algorithm, and perform entity recognition according to the role combination pattern in the role chain to obtain the target hidden Markov model.
[0174] Furthermore, the analysis module 205 is also used for:
[0175] Obtaining a stiffness matrix of a unit for evaluating the effect value, and calculating a residual value according to the stiffness matrix;
[0176] When the residual value is greater than or equal to the preset convergence value, updating the preset convergence value and the role weight value for a number of loop iterations until the residual value is less than the preset convergence value;
[0177] When the residual value is less than the preset convergence value, it is determined that the effect value curve converges stably;
[0178] The effect value curve with the smallest residual value is obtained, and the role weight value corresponding to the effect value curve with the smallest residual value is used as the target role weight value.
[0179] Furthermore, the calculation module 202 is also used for:
[0180] Analyze the field to which the training text belongs, call the core dictionary of the field to perform word segmentation on the training text, and obtain candidate word segmentations;
[0181] Obtaining a rough coding result corresponding to the candidate word segmentation, and calculating the coding with the highest matching degree with the candidate word segmentation in the rough coding result, and taking the role corresponding to the coding with the highest matching degree as the role of the candidate word segmentation;
[0182] Calculating a first role frequency of the role of the candidate participle in the training text, and calculating a second role frequency of the role of the candidate participle in the corpus corresponding to the field to which it belongs;
[0183] Calculating a role probability according to the first role frequency and the second role frequency;
[0184] The contribution of the role of the candidate participle to the compound word corresponding to the field is calculated based on the role probability, and the contribution is used as the role weight value. The compound word is used to indicate a word that conforms to grammatical rules and is composed of multiple candidate participles.
[0185] Furthermore, the identification module 206 is also used for:
[0186] pass Calculate the emission probability of the role corresponding to the target role weight value, where Role represents the role corresponding to the target role weight value, w represents the word corresponding to the role, P(w|Role) represents the probability of word w appearing under the role Role, Represents the weight of the role, represents the formula approximated by the law of large numbers formula, wherein f(w,Role) represents the frequency of the word corresponding to the role w corresponding to the marked role, and f(Role) represents the frequency of the overall occurrence of the words marked as the role Role, Represents the average frequency of all roles;
[0187] Calculating the prior probability and state transition probability of the role corresponding to the target role weight value;
[0188] Analyze the emission probability, the prior probability and the state transition probability by using a Viterbi algorithm, and calculate a role chain with a maximum probability value, wherein the role chain includes a plurality of role combination modes;
[0189] Sort the role chains corresponding to the probability values from large to small according to the probability values to obtain the best role sorting sequence;
[0190] The hidden Markov model corresponding to the optimal role sorting sequence is used as the target hidden Markov model.
[0191] Furthermore, the calculation module 202 is also used for:
[0192] Perform word segmentation processing on the training text based on the knowledge graph to obtain candidate word segmentations, and obtain the role tags of the candidate word segmentations in the knowledge graph to obtain the roles of the candidate word segmentations;
[0193] Calculating the third role frequency of the role of the candidate participle in the training text, and calculating the fourth role frequency of the role of the candidate participle in the corpus;
[0194] Obtaining the role probability by calculating the ratio of the third role frequency to the fourth role frequency;
[0195] The contribution of the role of the candidate word segment to the compound word corresponding to the field is calculated based on the role probability, and the contribution is used as the role weight value.
[0196] Furthermore, the calculation module 202 is also used for:
[0197] Labeling the training samples into positive samples and negative samples;
[0198] pass Calculate the F1 score value of entity recognition for the training text, wherein the TP represents the number of the training texts accurately recognized as positive sample entities, the FP represents the number of the training texts correctly recognized as negative sample entities, and the FN represents the number of the training texts incorrectly recognized as positive sample entities;
[0199] pass The F1 score value is used as the loss function value of the synchronously updated iterative operation, the state represents the role weight, the Value represents the F1 score value, the Value(state) represents the reward value after the role weight value is iteratively updated, the Reward(state) represents the current reward value, and the Represents the expected return of the parameter adjustment operation after the loop iteration.
[0200] Furthermore, the processing module 203 is also used for:
[0201] Obtaining parameters corresponding to the role weight value, wherein the parameters refer to the weight of a neuron and the bias of a neuron in a hidden Markov model;
[0202] pass The partial derivative of the parameter is obtained to obtain a stochastic gradient, and the parameter and the role weight value are updated according to the stochastic gradient loop iteration, wherein j represents the number of the parameters, m represents the number of samples of the training text, and represents the loss function, the represents the weight of the neuron in the hidden Markov model, represents the bias of the neuron, the represents the learning rate, Indicates taking a sample from all training text instances.
[0203] like Figure 3 As shown, Figure 3 It is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present invention.
[0204] The device for training the hidden Markov model in the embodiment of the present invention may be a server.
[0205] like Figure 3 As shown, the device may include: a processor 3001, such as a CPU, a network interface 3004, a user interface 3003, a memory 3005, and a communication bus 3002. Among them, the communication bus 3002 is used to realize the connection and communication between these components. The user interface 3003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 3003 may also include a standard wired interface and a wireless interface. The network interface 3004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 3005 may be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory. The memory 3005 may also be a storage device independent of the aforementioned processor 3001.
[0206] Those skilled in the art will understand that Figure 3 The device structure shown in the figure does not constitute a limitation of the device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0207] like Figure 3 As shown, the memory 3005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a program for training a hidden Markov model.
[0208] exist Figure 3 In the terminal shown, the network interface 3004 is mainly used to connect to the background server and communicate data with the background server; the user interface 3003 is mainly used to connect to the client (user end) and communicate data with the client; and the processor 3001 can be used to call the program for training the hidden Markov model stored in the memory 3005, and perform the operations in each embodiment of the above-mentioned method for training the hidden Markov model.
[0209] By running or executing the computer programs and / or modules stored in the memory, and calling the data stored in the memory, the various functions of the computer device are realized. The memory may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, video data, etc.), etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0210] The input-output unit can also be replaced by a receiver and a transmitter, which can be the same or different physical entities. When they are the same physical entities, they can be collectively referred to as input-output units. The input-output can be a transceiver.
[0211] The memory may be integrated into the processor or may be arranged separately from the processor.
[0212] 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) and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0213] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the inspiration of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims. All equivalent structures or equivalent process changes made using the contents of the specification and drawings of this application, or directly or indirectly used in other related technical fields, are protected by the present application.
Claims
1. A method for training a hidden Markov model, characterized in that: The method comprises: Obtaining the role probability of a candidate word segmentation through a hidden Markov model, wherein the candidate word segmentation is used to indicate the word segmentation of the training text that has been annotated with a role, and the role probability is used to indicate the frequency of occurrence of the role in a preset corpus; Calculating role weight values in the training text according to the role probabilities; Calculating a value of a loss function for entity recognition of the training text, and using the value of the loss function as an effect value; Executing a multi-dimensional stochastic gradient descent algorithm through the loss function to perform cyclic iterative updates on the role weight value; Draw an effect value curve according to the effect value; Analyze the stability of the convergence of the effect value curve to obtain a target role weight value, and obtain a target role corresponding to the target role weight value; Based on the target role, the role chain with the largest probability value is calculated by the Viterbi algorithm, and entity recognition is performed according to the role combination pattern in the role chain to obtain a target hidden Markov model; The step of calculating the role chain with the maximum probability value based on the target role by using the Viterbi algorithm, and performing entity recognition according to the role combination pattern in the role chain to obtain the target hidden Markov model includes: pass Calculate the emission probability of the role corresponding to the target role weight value, where Role represents the role corresponding to the target role weight value, w represents the word corresponding to the role, P(w|Role) represents the probability of word w appearing under the role Role, Represents the weight of the role, represents the formula approximated by the law of large numbers, wherein f(w,Role) represents the frequency of the role marked with w, and f(Role) represents the frequency of the overall occurrence of words marked as roles. Represents the average frequency of all roles; Calculating the prior probability and state transition probability of the role corresponding to the target role weight value; Analyze the emission probability, the prior probability and the state transition probability by using a Viterbi algorithm, and calculate a role chain with a maximum probability value, wherein the role chain includes a plurality of role combination modes; Sort the role chains corresponding to the probability values from large to small according to the probability values to obtain the best role sorting sequence; The hidden Markov model corresponding to the optimal role sorting sequence is used as the target hidden Markov model.
2. The method according to claim 1, characterized in that: The analyzing the stability of the convergence of the effect value curve to obtain the target role weight value includes: Obtaining a stiffness matrix of a unit for evaluating the effect value, and calculating a residual value according to the stiffness matrix; When the residual value is greater than or equal to the preset convergence value, updating the preset convergence value and the role weight value for a number of loop iterations until the residual value is less than the preset convergence value; When the residual value is less than the preset convergence value, it is determined that the effect value curve converges stably; The effect value curve with the minimum residual value is obtained, and the role weight value corresponding to the effect value curve with the minimum residual value is used as the target role weight value.
3. The method according to claim 1, characterized in that The step of obtaining the role probability of a candidate word segmentation through a hidden Markov model, wherein the candidate word segmentation is used to indicate a word segmentation of a training text that has been annotated with a role, and the role probability is used to indicate the frequency of occurrence of a role in a preset corpus, and calculating the role weight value in the training text according to the role probability includes: Analyze the field to which the training text belongs, call the core dictionary of the field to perform word segmentation on the training text, and obtain candidate word segmentations; Obtaining a rough coding result corresponding to the candidate word segmentation, and calculating the coding with the highest matching degree with the candidate word segmentation in the rough coding result, and taking the role corresponding to the coding with the highest matching degree as the role of the candidate word segmentation; Calculating a first role frequency of the role of the candidate participle in the training text, and calculating a second role frequency of the role of the candidate participle in the corpus corresponding to the field to which it belongs; Calculating a role probability according to the first role frequency and the second role frequency; The contribution of the role of the candidate participle to the compound word corresponding to the field is calculated based on the role probability, and the contribution is used as the role weight value. The compound word is used to indicate a word that conforms to grammatical rules and is composed of multiple candidate participles.
4. The method according to claim 1, characterized in that: The step of calculating the role weight value in the training text according to the role probability also includes: Perform word segmentation processing on the training text based on the knowledge graph to obtain candidate word segmentations, and obtain the role tags of the candidate word segmentations in the knowledge graph to obtain the roles of the candidate word segmentations; Calculating the third role frequency of the role of the candidate participle in the training text, and calculating the fourth role frequency of the role of the candidate participle in the corpus; Obtaining the role probability by calculating the ratio of the third role frequency to the fourth role frequency; The contribution of the role of the candidate word segment to the compound word corresponding to the field is calculated based on the role probability, and the contribution is used as the role weight value.
5. The method according to claim 1, characterized in that The step of calculating the value of a loss function for entity recognition of the training text and using the value of the loss function as an effect value includes: Labeling the training samples into positive samples and negative samples; pass Calculate the F1 score value of entity recognition for the training text, wherein the TP represents the number of the training texts accurately recognized as positive sample entities, the FP represents the number of the training texts correctly recognized as negative sample entities, and the FN represents the number of the training texts incorrectly recognized as positive sample entities; pass The F1 score value is used as the loss function value of the synchronously updated iterative operation, the state represents the role weight, the Value represents the F1 score value, the Value(state) represents the reward value after the role weight value is iteratively updated, the Reward(state) represents the current reward value, and the Represents the expected return of the parameter adjustment operation after the loop iteration.
6. The method according to any one of claims 1 to 5, characterized in that The multi-dimensional stochastic gradient descent algorithm is executed through the loss function to perform cyclic iterative updates on the role weight value, including: Obtaining parameters corresponding to the role weight value, wherein the parameters refer to the weight of a neuron and the bias of a neuron in a hidden Markov model; pass The partial derivative of the parameter is obtained to obtain a stochastic gradient, and the parameter and the role weight value are updated according to the stochastic gradient loop iteration, wherein j represents the number of the parameters, m represents the number of samples of the training text, and represents the loss function, the represents the weights of the neurons in the hidden Markov model, Representation weight The vector represents the bias of the neuron, Indicates bias The vector represents the learning rate, Indicates taking a sample from all training text instances.
7. A device for training a hidden Markov model, characterized in that: The device comprises: An acquisition module, used for acquiring the role probability of a candidate word segmentation through a hidden Markov model, wherein the candidate word segmentation is used to indicate the word segmentation of a training text that has been annotated with a role, and the role probability is used to indicate the frequency of occurrence of a role in a preset corpus; A calculation module, used for calculating the role weight value in the training text according to the role probability; The calculation module is also used to calculate the value of the loss function for entity recognition of the training text, and use the value of the loss function as the effect value; An iterative update module, used to execute a multi-dimensional stochastic gradient descent algorithm through the loss function to perform cyclic iterative updates on the role weight value; A drawing module, used for drawing an effect value curve according to the effect value; An analysis module, used for analyzing the stability of the convergence of the effect value curve to obtain a target role weight value, and obtaining a target role corresponding to the target role weight value; A recognition module, used to calculate a role chain with the maximum probability value based on the target role by using a Viterbi algorithm, and perform entity recognition according to a role combination pattern in the role chain to obtain a target hidden Markov model; The step of calculating the role chain with the maximum probability value based on the target role by using the Viterbi algorithm, and performing entity recognition according to the role combination pattern in the role chain to obtain the target hidden Markov model includes: pass Calculate the emission probability of the role corresponding to the target role weight value, where Role represents the role corresponding to the target role weight value, w represents the word corresponding to the role, P(w|Role) represents the probability of word w appearing under the role Role, Represents the weight of the role, represents the formula approximated by the law of large numbers, wherein f(w,Role) represents the frequency of the role marked with w, and f(Role) represents the frequency of the overall occurrence of words marked as roles. Represents the average frequency of all roles; Calculating the prior probability and state transition probability of the role corresponding to the target role weight value; Analyze the emission probability, the prior probability and the state transition probability by using a Viterbi algorithm, and calculate a role chain with a maximum probability value, wherein the role chain includes a plurality of role combination modes; Sort the role chains corresponding to the probability values from large to small according to the probability values to obtain the best role sorting sequence; The hidden Markov model corresponding to the optimal role sorting sequence is used as the target hidden Markov model.
8. A device for training a hidden Markov model, characterized in that The device comprises: a memory, a processor, and a program for training a hidden Markov model stored in the memory and executable on the processor. When the program for training a hidden Markov model is executed by the processor, the steps of the method for training a hidden Markov model as described in any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a program for training a hidden Markov model. When the program for training a hidden Markov model is executed by a processor, the steps of the method for training a hidden Markov model according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Labeling method of Tibetan named entities
CN108268447A
Method and Device for Identifying Specific Text Information
US20190272319A1