Training method, system and related equipment for text classification model

Through the iterative training method of tensor network, using initial and calculated hyperparameters, the problem of difficulty in training and overfitting of neural network models in text classification is solved, and the training efficiency and accuracy are improved.

CN112256867BActive Publication Date: 2024-09-20HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011035101.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-27
Publication Date
2024-09-20
Estimated Expiration
2040-09-27

AI Technical Summary

Technical Problem

Existing neural network models have unexplainable and complex parameter adjustment processes in text classification tasks, making training difficult and costly, and prone to overfitting.

Method used

The tensor network is used to train the text classification model, and the initial hyperparameters and calculated hyperparameters are used respectively through the first and second rounds of iterative training to reduce the difficulty and cost of model training and reduce the occurrence of overfitting.

Benefits of technology

It reduces the difficulty and cost of text classification model training, reduces the over-fitting phenomenon, and improves the training efficiency and accuracy of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112256867B
    Figure CN112256867B
Patent Text Reader

Abstract

The embodiment of the present application provides a training method, system and related equipment for a text classification model, wherein the method includes: using a first hyperparameter and a plurality of sample word vector sequences to perform a first round of iterative training on a tensor network to obtain a target entanglement entropy, wherein the value of the target entanglement entropy is the value when the first entanglement entropy obtained during the first round of iterative training converges; calculating a second hyperparameter based on the target entanglement entropy; using the second hyperparameter and the plurality of sample word vector sequences to perform a second round of iterative training on the tensor network to obtain the text classification model, wherein the text classification model is a tensor network model when the second entanglement entropy calculated during the second round of iterative training converges. The embodiment of the present application can greatly reduce the difficulty and cost of model training and the occurrence of overfitting.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a training method, system and related equipment for a text classification model. Background Art

[0002] In the prior art, neural network models are usually used to implement text classification tasks. For example, first, a convolutional neural network (CNN) structure is used to implement sentence-level classification tasks such as sentiment and question-answering. Second, a hierarchical agglomerative clustering (HAC) model is proposed, which uses the intermediate information of deep CNN to form hierarchical structural features (corresponding to words, phrases, and clauses, etc.), and then the model uses capsule modules and attention mechanisms to fully aggregate features. Third, the model learns text features based on the attention mechanism, which can be used not only for text classification, but also for natural language processing (NLP) tasks such as machine translation. Fourth, a restricted recursive neural network is used, and a preset weight matrix set is used to reduce the weight of function words in model training, thereby improving the accuracy of text sentiment classification.

[0003] However, although the current neural network model can achieve good text classification results, the input and output of the neural network model are unexplainable. During training, an unexplainable and complex parameter adjustment process is required to obtain a text classification model that can be used to implement text classification tasks. The training process is relatively complex and requires a lot of debugging. The training is difficult and costly. Secondly, the text classification model in deep learning uses a large number of parameters to learn text features, which may lead to overfitting, making parameters redundant and reducing computational efficiency. Summary of the invention

[0004] The embodiments of the present application disclose a training method, system and related equipment for a text classification model. By adopting a tensor network to train the text classification model, the difficulty and cost of model training and the occurrence of overfitting can be greatly reduced.

[0005] A first aspect of an embodiment of the present application discloses a training method for a text classification model, which is executed by a computer device, and includes: performing a first round of iterative training on a tensor network using a first hyperparameter and a plurality of sample word vector sequences to obtain a target entanglement entropy, wherein the value of the target entanglement entropy is a value when the first entanglement entropy obtained during the first round of iterative training converges; calculating a second hyperparameter based on the target entanglement entropy; performing a second round of iterative training on the tensor network using the second hyperparameter and the plurality of sample word vector sequences to obtain the text classification model, wherein the text classification model is a tensor network model when the second entanglement entropy calculated during the second round of iterative training converges.

[0006] Among them, the first hyperparameter and the second hyperparameter are different values ​​of the hyperparameters for the same task. It should be understood that one round of iterative training includes multiple iterations, that is, in one round of iteration, multiple sample word vector sequences are input into the tensor network for training multiple times. After each training, the loss of this training is calculated, and the model parameters of the tensor network are adjusted according to the loss of this training to obtain the tensor network model for the next training, and then the next training is carried out until the model converges.

[0007] It should be understood that the multiple sample word vector sequences are obtained by converting multiple texts. As for the conversion of one text into a sample word vector sequence, the specific conversion process is: convert each word in the text into a word vector, obtain multiple word vectors, and then form a sequence of the multiple word vectors to obtain the sample word vector sequence. Among them, when a sample word vector sequence is composed of multiple word vectors, the multiple word vectors can be sorted according to the order of the words corresponding to the word vectors in the text, so as to obtain the sample word vector sequence.

[0008] It can be seen that, in this embodiment, the initial hyperparameters (i.e., the first hyperparameters) and multiple sample word vector sequences are used to perform the first round of iterative training on the tensor network, and a first entanglement entropy is calculated each iteration, and the value of the first entanglement entropy when it converges is used as the value of the target entanglement entropy; then the hyperparameter (i.e., the second hyperparameter) is calculated according to the target entanglement entropy; then the second hyperparameter and the multiple sample word vector sequences are used to perform the second round of iterative training on the tensor network, and a second entanglement entropy is calculated each iteration, and the tensor network model when the second entanglement entropy converges is used as the required text classification model for text classification; since the embodiment of the present application only needs to perform one pre-training to directly calculate the hyperparameters of the model, the calculated hyperparameters can be brought into the re-training to output a model that can be used to implement the text classification task, which greatly reduces the difficulty and cost of model training and the occurrence of overfitting.

[0009] In an exemplary embodiment, the tensor network includes a discriminative tensor network (DTN) and r generative tensor networks (GTN), and the output data of the r generative tensor networks are the input data of the discriminative tensor network; wherein r is a positive integer.

[0010] Among them, the r generative tensor networks are used to perform dimensionality reduction processing on the sample word vector sequence, and the discriminative tensor network is used to perform text classification on the word vector sequence after dimensionality reduction.

[0011] It can be seen that in this example, the tensor network used for text classification model training includes a discriminative tensor network and r generative tensor networks. The output of the r generative tensor networks is the input of the discriminative tensor network. The r generative tensor networks are used to reduce the dimension of the input sample word vector sequence, and then input the reduced word vector sequence into the discriminative tensor network for sentence modeling and text classification. Since the sample dimension during training is reduced, it is helpful to reduce the difficulty and cost of model training.

[0012] In an exemplary embodiment, the iterative training includes: performing the following operations on each sample word vector sequence in the multiple sample word vector sequences to obtain multiple first prediction labels, wherein the multiple sample word vector sequences correspond to the multiple first prediction labels: using the tensor network model M t The r generative tensor networks in the first target word vector sequence perform dimensionality reduction processing on each first word vector in the first target word vector sequence to obtain a second target word vector sequence, wherein the first target word vector sequence is any one of the multiple sample word vector sequences, and t is the number of iterations; the second target word vector sequence is input into the tensor network model M t The discriminant tensor network in the example is used to obtain a first predicted label of the target text, wherein the target text is the text corresponding to the first target word vector sequence; and the loss value L is calculated according to the multiple first predicted labels and the true labels corresponding to the multiple sample word vector sequences. t According to the loss value L t Adjust the tensor network model M t Parameters in to get the tensor network model M t+1 ; and according to the tensor network model M t+1 The third entanglement entropy is calculated by using the parameters in ; when the third entanglement entropy does not converge, set t=t+1, and repeat the above steps until the third entanglement entropy converges; when the third entanglement entropy converges, if the iterative training is the first round of iterative training, the target entanglement entropy is the third entanglement entropy; if the iterative training is the second round of iterative training, the text classification model is the tensor network model M t+1 ; Wherein, when t=1, the tensor network model M t is the initial tensor network model.

[0013] It should be understood that when t=1, the tensor network model M t is an initial tensor network model, which is a tensor network model after initial model parameters are configured for the tensor network.

[0014] It can be seen that in this example, in each iteration of the iterative training of the tensor network, for each sample word vector sequence in the multiple sample word vector sequences, it is first input into r generative tensor networks for dimensionality reduction processing in turn, and then input into the discriminative tensor network for text classification after dimensionality reduction, so as to obtain the predicted labels corresponding to the multiple sample word vector sequences; then, the loss value is calculated according to the predicted labels corresponding to the multiple sample word vector sequences and the true labels corresponding to the multiple sample word vector sequences, and the model parameters are adjusted according to the loss value to obtain the model of the next iteration, and the third entanglement entropy is calculated according to the parameters in the model of the next iteration; when the third entanglement entropy does not converge, repeat the above steps for the next iteration until the third entanglement entropy converges; when the third entanglement entropy converges, if it is the first round of iterative training, the hyperparameters can be calculated according to the third entanglement entropy; if it is the second round of iterative training, the model of the next iteration is the required text classification model, which can be used for text classification tasks.

[0015] In an exemplary embodiment, the first target word vector sequence includes n first word vectors, wherein n is a positive integer, and the tensor network model M is used. t The r generative tensor networks in the first target word vector sequence perform dimensionality reduction processing on each first word vector in the first target word vector sequence to obtain a second target word vector sequence, including: performing feature mapping on the n first word vectors respectively to obtain n first tensors, wherein the first tensor is a tensor representation of the first word vector; using the tensor network model M t The r generative tensor networks in perform dimensionality reduction processing on each of the n first tensors to obtain the second target word vector sequence.

[0016] When performing feature mapping on a word vector, the word vector can be mapped to a Hilbert high-dimensional space. After mapping the first word vector to the Hilbert high-dimensional space (i.e., performing a tensor product operation between each dimension of the vector), a high-order tensor is obtained.

[0017] It should be understood that only by performing a tensor product operation on each dimension of the word vector and mapping it to a high-dimensional Hilbert space can it be input into the generative tensor network for contraction operation.

[0018] It can be seen that in this example, each first word vector in the sample word vector sequence in the input model is first mapped to a high-dimensional space, and dimensionality is increased to obtain a first tensor; then the r generative tensor networks in the tensor network model are used to reduce the dimension of the first tensor to obtain a second word vector, wherein the dimension of the second word vector is lower than that of the first word vector; the first word vector is firstly increased in dimension to facilitate feature extraction of the word vector; then the word vector is reduced in dimension, and the word vector sequence after dimensionality reduction is input into the discriminant tensor network for prediction, which is beneficial to improve the efficiency of word vector expression for words and reduce the cost of model training.

[0019] In an exemplary embodiment, the tensor network model M t The r generative tensor networks in the example correspond to the r first weight parameters, and the tensor network model M is used. t The r generative tensor networks in the method perform dimensionality reduction processing on each of the n first tensors to obtain the second target word vector sequence, including: performing the following operations on each of the n first tensors to obtain n second word vectors, wherein the n second word vectors correspond to the n first tensors: performing tensor contraction operations on the r first weight parameters and the second tensor respectively to obtain r tensor contraction operation results, wherein the second tensor is any one of the n first tensors; obtaining r target probability values ​​according to the r tensor contraction operation results, wherein the sum of the r target probability values ​​is 1; obtaining a second word vector according to the r target probability values; and the n second word vectors constitute the second target word vector sequence.

[0020] Among them, the first weight parameter can be the tensor network state of the generative tensor network, and the target probability value can be understood as the importance of the current word for certain decisions made by the model to make classification.

[0021] It can be seen that in this example, when the high-dimensional first tensor is reduced to a low-dimensional second word vector, with respect to a first tensor, the tensor network states of r generative tensor networks are respectively subjected to tensor contraction operations with the first tensor to obtain r tensor contraction operation results; then, r target probability values ​​are obtained based on the r tensor contraction operation results, wherein the sum of the r target probability values ​​is 1, and the target probability value can be understood as the importance of the current word to certain decisions made by the model for classification; and then, the second word vector is obtained based on the r target probability values, so that the second word vector satisfies the characteristics of probability, that is, the second word vector has r dimensions, and the r dimensions correspond to the r target probability values, which is conducive to the discriminant tensor network making text classification results for the word vector sequence.

[0022] In an exemplary embodiment, the tensor network model M tThe discriminant tensor network in includes n nodes, each of the first predicted labels includes n second predicted labels, and the n second predicted labels are output by the n nodes respectively, wherein n is a positive integer, and the loss value L is calculated according to the multiple first predicted labels and the real labels corresponding to the multiple sample word vector sequences. t , including: performing the following operations on each of the multiple first prediction labels to obtain multiple cross entropy losses: performing multiplication and accumulation calculations based on n second prediction labels in the first target label and the second weight parameters corresponding to the n nodes to obtain a third prediction label, wherein the first target label is any one of the multiple first prediction labels; calculating the cross entropy loss based on the third prediction label and the second target label, wherein the second target label is the true label corresponding to the fourth target word vector sequence, and the fourth target word vector sequence is the sample word vector sequence corresponding to the first target label; calculating the loss value L based on the multiple cross entropy losses t .

[0023] It should be understood that the traditional discriminant tensor network only selects the prediction result at a certain node in the tensor contraction operation for training, that is, only one function is predicted and trained, which results in the learning process being unable to learn all the features in the sentence modeling process. Therefore, this example designs an all-function learning algorithm during the training process, that is, the prediction result of each node in the discriminant tensor network is trained. Specifically, after the word vector sequence is input into the discriminant tensor network, each node in the discriminant tensor network outputs a prediction label, and the weighted average of the prediction labels output by each node is calculated, and the result of the weighted average is used as the prediction label of the word vector sequence.

[0024] It can be seen that in this example, during training, after the word vector sequence is input into the discriminant tensor network, each node in the discriminant tensor network outputs a prediction label, and the predicted labels output by each node are weighted averaged, and the result of the weighted average is used as the predicted label of the word vector sequence; thereby, multiple cross losses are calculated using the weighted average predicted labels corresponding to multiple word vector sequences and the corresponding true labels, and then the loss value of an iteration is obtained based on the multiple cross losses, and the model parameters are adjusted based on the loss value, which can improve the training stability of the model and the prediction accuracy.

[0025] In an exemplary embodiment, the tensor network model M t+1 The third entanglement entropy is obtained by calculating the parameters in the tensor network model M t+1 The jth node and the j+1th node in the discriminant tensor network in the tensor are subjected to tensor contraction and merge operations to obtain the target node, where The n is the tensor network model M t+1 The number of nodes of the discriminant tensor network in the matrix, wherein n is a positive integer; performing singular value decomposition (SVD) on the target node to obtain k singular values, wherein k is a positive integer; and calculating the third entanglement entropy according to the k singular values.

[0026] The target node is the node synthesized by performing tensor shrinking and merging operations on the j-th node and the j+1-th node.

[0027] It can be seen that in this example, by performing tensor contraction operation on the jth node and the j+1th node in the discriminant tensor network, the jth node and the j+1th node are combined into one node, where: n is the number of nodes of the discriminant tensor network, and n is a positive integer; then the synthesized nodes are subjected to singular value decomposition to obtain k singular values; and then the k singular values ​​are used to calculate the entanglement entropy, which is conducive to calculating the hyperparameters based on the entanglement entropy, and realizing the computability of the hyperparameters in the model training.

[0028] A second aspect of an embodiment of the present application discloses a training system for a text classification model, the system comprising a text tensor network module and a hyperparameter calculation module; the text tensor network module is used to perform a first round of iterative training on the tensor network using a first hyperparameter and a plurality of sample word vector sequences; the hyperparameter calculation module is used to calculate a first entanglement entropy after each iteration of the first round of iterative training to obtain a target entanglement entropy, and to calculate a second hyperparameter based on the target entanglement entropy, wherein the value of the target entanglement entropy is the value when the first entanglement entropy converges; the text tensor network module is also used to perform a second round of iterative training on the tensor network using the second hyperparameter and the plurality of sample word vector sequences; the hyperparameter calculation module is also used to calculate a second entanglement entropy after each iteration of the second round of iterative training; wherein the tensor network model when the second entanglement entropy converges is the text classification model.

[0029] In an exemplary embodiment, the tensor network includes a discriminant tensor network and r generative tensor networks, and the output data of the r generative tensor networks are the input data of the discriminant tensor network; wherein r is a positive integer.

[0030] In an exemplary embodiment, the text tensor network module is used to: perform the following operations on each sample word vector sequence in the multiple sample word vector sequences to obtain multiple first prediction labels, wherein the multiple sample word vector sequences correspond to the multiple first prediction labels: using the tensor network model Mt The r generative tensor networks in the first target word vector sequence perform dimensionality reduction processing on each first word vector in the first target word vector sequence to obtain a second target word vector sequence, wherein the first target word vector sequence is any one of the multiple sample word vector sequences, and t is the number of iterations; and the second target word vector sequence is input into the tensor network model M t The discriminant tensor network in the example is used to obtain a first predicted label of a target text, wherein the target text is a text corresponding to the first target word vector sequence; and a loss value L is calculated based on the multiple first predicted labels and the true labels corresponding to the multiple sample word vector sequences. t ; and according to the loss value L t Adjust the tensor network model M t Parameters in to obtain the tensor network model M t+1 ; The hyperparameter calculation module is used to: according to the tensor network model M t+1 The third entanglement entropy is calculated by the parameters in; if it is the first round of iterative training, the third entanglement entropy is the first entanglement entropy; if it is the second round of iterative training, the third entanglement entropy is the second entanglement entropy; wherein, when t=1, the tensor network model M t is the initial tensor network model.

[0031] In an exemplary embodiment, the first target word vector sequence includes n first word vectors, wherein n is a positive integer, and the text tensor network module is used to: perform feature mapping on the n first word vectors respectively to obtain n first tensors, wherein the first tensor is a tensor representation of the first word vector; adopt the tensor network model M t The r generative tensor networks in perform dimensionality reduction processing on each of the n first tensors to obtain the second target word vector sequence.

[0032] In an exemplary embodiment, the tensor network model M t The r generative tensor networks in the text tensor network correspond to the r first weight parameters, and the text tensor network module is used to: perform the following operations on each of the n first tensors to obtain n second word vectors, wherein the n second word vectors correspond to the n first tensors: perform tensor contraction operations on the r first weight parameters and the second tensor respectively to obtain r tensor contraction operation results, wherein the second tensor is any one of the n first tensors; obtain r target probability values ​​according to the r tensor contraction operation results, wherein the sum of the r target probability values ​​is 1; obtain a second word vector according to the r target probability values; and the n second word vectors constitute the second target word vector sequence.

[0033] In an exemplary embodiment, the tensor network model M t The discriminant tensor network in comprises n nodes, each of the first prediction labels comprises n second prediction labels, and the n second prediction labels are respectively output by the n nodes, wherein n is a positive integer, and the text tensor network module is used to: perform the following operations on each of the multiple first prediction labels to obtain multiple cross entropy losses: perform multiplication and accumulation calculations based on the n second prediction labels in the first target label and the second weight parameters corresponding to the n nodes to obtain a third prediction label, wherein the first target label is any one of the multiple first prediction labels; calculate the cross entropy loss based on the third prediction label and the second target label, wherein the second target label is the true label corresponding to the fourth target word vector sequence, and the fourth target word vector sequence is the sample word vector sequence corresponding to the first target label; calculate the loss value L based on the multiple cross entropy losses t .

[0034] In an exemplary embodiment, the hyperparameter calculation module is used to: t+1 The jth node and the j+1th node in the discriminant tensor network in the tensor are subjected to tensor contraction and merge operations to obtain the target node, where The n is the tensor network model M t+1 The number of nodes of the discriminant tensor network in , wherein n is a positive integer; performing singular value decomposition on the target node to obtain k singular values, wherein k is a positive integer; and calculating the third entanglement entropy according to the k singular values.

[0035] A third aspect of an embodiment of the present application discloses a training device for a text classification model, the device comprising: a training unit, configured to perform a first round of iterative training on a tensor network using a first hyperparameter and a plurality of sample word vector sequences to obtain a target entanglement entropy, wherein the value of the target entanglement entropy is a value obtained when the first entanglement entropy obtained during the first round of iterative training converges; a calculation unit, configured to calculate a second hyperparameter based on the target entanglement entropy; the training unit, further configured to perform a second round of iterative training on the tensor network using the second hyperparameter and the plurality of sample word vector sequences to obtain the text classification model, wherein the text classification model is a tensor network model when the second entanglement entropy calculated during the second round of iterative training converges.

[0036] In an exemplary embodiment, the tensor network includes a discriminant tensor network and r generative tensor networks, and the output data of the r generative tensor networks are the input data of the discriminant tensor network; wherein r is a positive integer.

[0037] In an exemplary embodiment, the training unit is used to: perform the following operations on each sample word vector sequence in the multiple sample word vector sequences to obtain multiple first prediction labels, wherein the multiple sample word vector sequences correspond to the multiple first prediction labels: using the tensor network model M t The r generative tensor networks in the first target word vector sequence perform dimensionality reduction processing on each first word vector in the first target word vector sequence to obtain a second target word vector sequence, wherein the first target word vector sequence is any one of the multiple sample word vector sequences, and t is the number of iterations; the second target word vector sequence is input into the tensor network model M t The discriminant tensor network in the example is used to obtain a first predicted label of the target text, wherein the target text is the text corresponding to the first target word vector sequence; and the loss value L is calculated according to the multiple first predicted labels and the true labels corresponding to the multiple sample word vector sequences. t According to the loss value L t Adjust the tensor network model M t Parameters in to obtain the tensor network model M t+1 ; and according to the tensor network model M t+1 The third entanglement entropy is calculated by using the parameters in ; when the third entanglement entropy does not converge, set t=t+1, and repeat the above steps until the third entanglement entropy converges; when the third entanglement entropy converges, if the iterative training is the first round of iterative training, the target entanglement entropy is the third entanglement entropy; if the iterative training is the second round of iterative training, the text classification model is the tensor network model M t+1 ; Wherein, when t=1, the tensor network model M t is the initial tensor network model.

[0038] In an exemplary embodiment, the first target word vector sequence includes n first word vectors, wherein n is a positive integer, and the training unit is used to: perform feature mapping on the n first word vectors respectively to obtain n first tensors, wherein the first tensor is a tensor representation of the first word vector; adopt the tensor network model M t The r generative tensor networks in perform dimensionality reduction processing on each of the n first tensors to obtain the second target word vector sequence.

[0039] In an exemplary embodiment, the tensor network model M tThe r generative tensor networks in the training unit correspond to the r first weight parameters, and the training unit is used to: perform the following operations on each of the n first tensors to obtain n second word vectors, wherein the n second word vectors correspond to the n first tensors: perform tensor contraction operations on the r first weight parameters and the second tensor respectively to obtain r tensor contraction operation results, wherein the second tensor is any one of the n first tensors; obtain r target probability values ​​according to the r tensor contraction operation results, wherein the sum of the r target probability values ​​is 1; obtain a second word vector according to the r target probability values; and the n second word vectors constitute the second target word vector sequence.

[0040] In an exemplary embodiment, the tensor network model M t The discriminant tensor network in comprises n nodes, each of the first prediction labels comprises n second prediction labels, and the n second prediction labels are respectively output by the n nodes, wherein n is a positive integer, and the training unit is used to: perform the following operations on each of the multiple first prediction labels to obtain multiple cross entropy losses: perform multiplication and accumulation calculations based on the n second prediction labels in the first target label and the second weight parameters corresponding to the n nodes to obtain a third prediction label, wherein the first target label is any one of the multiple first prediction labels; calculate the cross entropy loss based on the third prediction label and the second target label, wherein the second target label is the true label corresponding to the fourth target word vector sequence, and the fourth target word vector sequence is the sample word vector sequence corresponding to the first target label; calculate the loss value L based on the multiple cross entropy losses t .

[0041] In an exemplary embodiment, the training unit is used to: train the tensor network model M t+1 The jth node and the j+1th node in the discriminant tensor network in the tensor are subjected to tensor contraction and merge operations to obtain the target node, where The n is the tensor network model M t+1 The number of nodes of the discriminant tensor network in , wherein n is a positive integer; performing singular value decomposition on the target node to obtain k singular values, wherein k is a positive integer; and calculating the third entanglement entropy according to the k singular values.

[0042] It can be understood that since the method embodiment and the device embodiment are different presentation forms of the same technical concept, the content of the first aspect of the embodiment of the present application should be synchronously adapted to the second and third aspects of the embodiment of the present application, and will not be repeated here.

[0043] The fourth aspect of an embodiment of the present application discloses a computer device, including a processor, a memory, a communication interface, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the processor, and the program includes instructions for executing the steps in the method described in any one of the first aspects above.

[0044] The fifth aspect of the embodiment of the present application discloses a chip, characterized in that it includes: a processor, used to call and run a computer program from a memory, so that a device equipped with the above chip executes any one of the above methods in the above first aspect.

[0045] A sixth aspect of an embodiment of the present application discloses a computer-readable storage medium storing a computer program for electronic data exchange, wherein the computer program enables a computer to execute a method as described in any one of the above-mentioned first aspects.

[0046] A seventh aspect of the embodiments of the present application discloses a computer program product, which enables a computer to execute a method as described in any one of the above-mentioned first aspects. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] The following is an introduction to the drawings used in the embodiments of the present application.

[0048] Figure 1 It is a schematic diagram of the architecture of a text classification model training system provided in an embodiment of the present application;

[0049] Figure 2 It is a schematic diagram of the architecture of a text tensor network provided in an embodiment of the present application;

[0050] Figure 3 is a schematic diagram of a full function learning algorithm provided in an embodiment of the present application;

[0051] Figure 4 It is a schematic diagram of hyper parameters in the DMRG algorithm provided in the embodiment of the present application;

[0052] Figure 5 It is a flowchart of a training method for a text classification model provided in an embodiment of the present application;

[0053] Figure 6 This is a graph showing the relationship between entanglement entropy and the number of iterations during a text classification model training process provided in an embodiment of the present application;

[0054] Figure 7 This is a relationship diagram between prediction accuracy, entanglement entropy and hyperparameters provided in an embodiment of the present application;

[0055] Figure 8It is a structural schematic diagram of a training device for a text classification model provided in an embodiment of the present application;

[0056] Fig. 9 It is a structural schematic diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0057] The embodiments of the present application are described below in conjunction with the drawings in the embodiments of the present application.

[0058] In order to facilitate those skilled in the art to understand the present application, firstly, some terms in the embodiments of the present application are explained here, and relevant technical knowledge involved in the embodiments of the present application are introduced.

[0059] Tensor network: Tensor network is a sparse data structure used to efficiently represent and manipulate high-dimensional data. It has been greatly developed and applied in statistical mechanics, quantum field theory, and machine learning.

[0060] Text classification: Text classification is the use of computer algorithms to automatically classify and label text sets according to a certain classification system or standard. It finds the relationship model between document features and document categories based on a set of labeled training documents, and then uses this learned relationship model to classify new documents.

[0061] Hyperparameters: Hyperparameters generally define higher-level concepts about the model, which cannot be learned directly from the model training process and need to be defined in advance. In practice, they can be determined by setting different hyperparameter values, training different models and selecting the best test value.

[0062] Text classification is a traditional machine learning task, which aims to automatically classify and label text sets according to a certain classification system through computer algorithms. Text classification tasks usually require the use of a training document set that has been labeled with classification labels for learning. Earlier technical means are rule-based. The learning process can be considered as summarizing the basic rules of the training set and using these rules to classify the newly input text. Subsequently, machine learning technology is used for text classification, transforming the task into learning a function in the statistical mathematical sense from the training set, usually called a model; among them, both the construction of the model and the final use of the model for prediction must first select features for the input text. The commonly used feature selection method is to select important words or phrases in the text and use the frequency of occurrence of these words or phrases and other related values ​​as feature values. In recent years, with the development of deep neural network technology, deep learning neural network models have continuously refreshed the accuracy of text classification tasks. However, the current methods based on deep neural networks generally have problems such as the need for a large number of model parameter adjustments and overfitting. The main reason is the black box structure of the neural network and the uncontrollable model training process. This defect limits the further optimization of the neural network text classification model, resulting in excessively high costs for training deep neural networks.

[0063] Tensor networks are sparse data structures used to efficiently represent and manipulate high-dimensional data. They have been greatly developed and applied in statistical mechanics, quantum field theory, and machine learning. The application of tensor networks in the field of machine learning has a strong theoretical explanation advantage, and has made great progress in the field of images in recent years. However, in the field of text, which has a wide range of applications, tensor networks still lack effective technical devices, and their theoretical advantages have not been truly applied to the training process of the model. The model still needs to be adjusted multiple times to obtain the optimal classification effect.

[0064] The application of using tensor networks for text classification is still relatively blank, but in the field of image processing, some work using tensor networks for image classification can be seen, as follows: using tensor network structures to model image classification tasks, the model is based on the MPS structure; using hierarchical tree tensor network states to learn image features for image recognition; based on the MPS unsupervised generation model, MPS structures are generated for different categories, and the handwriting recognition (MNIST) task is classified using the MPS after unsupervised training. The tensor network model has strong theoretical interpretability, but this theoretical advantage is not reflected in actual training, that is, in order to obtain the best classification accuracy, the tensor network still relies on an aimless parameter adjustment process. In terms of model effect, the image classification accuracy of the tensor network has not exceeded the classic neural network model (such as CNN, etc.), and the tensor network structure needs to be further optimized. At the same time, the tensor network model architecture mentioned above cannot be directly used for text classification tasks.

[0065] In the field of text classification, the current mainstream deep neural network methods have achieved good results, but deep neural networks have poor interpretability, and the training process is completely black-box. The model's hyperparameters often need to be determined by setting a candidate set and training and verifying multiple times. The tensor network, which has recently emerged in the field of machine learning, has good interpretability and has been applied to image processing, but there is currently no architecture that can be applied to natural language processing tasks.

[0066] In summary, the technical problem to be solved by this application is to design and implement a text classification architecture based on a tensor network that can be used for natural language processing tasks. On the one hand, this architecture should achieve an accuracy no less than that of a deep neural network in text classification tasks to ensure its usability; on the other hand, it should give full play to the interpretability of the tensor network and derive a theoretical formula for calculating the network's hyperparameters, thereby reducing the difficulty of model training in practice; and finally realize a set of tensor network text classification methods and devices that can calculate hyperparameters. Specifically, this application proposes a text tensor network architecture that can be used for text classification. The text tensor network (TextTN) architecture consists of several word-level generative tensor networks (word-GTNs) and a sentence-level discriminative tensor network (sentence-DTN). The sentences of text classification are converted into word vector sequences composed of vectors corresponding to words, and input into several word-level generative tensor networks, so as to obtain the word vector sequences composed of vectors corresponding to words after dimensionality reduction; the text classification sentences represented by the word vector sequences composed of vectors corresponding to words after dimensionality reduction are input into the sentence-level discriminant tensor network, and the representation vector of the sentence can be obtained, and the classification label is output at the same time. In the actual network training process, the text of the training set is pre-trained with the text tensor network according to the above-mentioned project, and the hyperparameter calculation formula is used to calculate the hyperparameter after the word training is completed; the hyperparameter value calculated is used to set the hyperparameter of the text tensor network, and the text tensor network is retrained to obtain a network model that can be used to implement text classification tasks. This application can be implemented in a variety of programming languages ​​and can be deployed on a general-purpose computer or other device that can provide computing power.

[0067] See also Figure 1 , Figure 1 Schematic diagram of the architecture of a text classification model training system provided in an embodiment of the present application. Figure 1As shown, the system includes a text tensor network (TextTN) module and a hyperparameter calculation module; the text tensor network module is used to use a first hyperparameter and a plurality of sample word vector sequences to perform a first round of iterative training on the tensor network; the hyperparameter calculation module is used to calculate the first entanglement entropy after each iteration of the first round of iterative training to obtain a target entanglement entropy, and calculate a second hyperparameter based on the target entanglement entropy, wherein the value of the target entanglement entropy is the value when the first entanglement entropy converges; the text tensor network module is also used to use a second hyperparameter and a plurality of sample word vector sequences to perform a second round of iterative training on the tensor network; the hyperparameter calculation module is also used to calculate the second entanglement entropy after each iteration of the second round of iterative training; wherein the tensor network model when the second entanglement entropy converges is a text classification model.

[0068] Specifically, the training system of the text classification model includes two main modules and two operation processes.

[0069] Among them, the two main modules include the text tensor network (TextTN) module and the hyperparameter calculation module. The text tensor network module is a tensor network architecture. Its first layer is a word-level generative tensor network (word-GTNs), which is used to reduce the dimension of the word vector of the text represented by the input word vector sequence; the second layer is a sentence-level discriminant tensor network (sentence-DTN), which is used to model the sentences composed of the word vector sequence after dimensionality reduction and output the final classification label. The hyperparameter calculation module can use the formula to directly calculate the hyperparameters in the text tensor network through theoretical derivation, that is, to calculate the second hyperparameter.

[0070] Among them, the two operation processes are the pre-training process ( Figure 1 Solid line marking process) and the final training process ( Figure 1For the pre-training process, i.e. the first round of iterative training, the training sample (i.e. text) is first converted into a word vector sequence, and then the word vector sequence is directly input into the text tensor network (TextTN), and a round of training is performed using the first random initial hyperparameter. In the first round of iterative training, after each iterative training, the hyperparameter calculation module calculates the entanglement entropy once, i.e. the first entanglement entropy. As the number of iterative training increases, the calculation amount derived by the hyperparameter calculation module, i.e. the first entanglement entropy, will gradually converge, and the hyperparameter calculation module can calculate the hyperparameter, i.e. the hyperparameter calculation module uses the converged value of the first entanglement entropy to calculate the second hyperparameter. For the final training process, that is, the second round of iterative training, it is basically the same as the pre-training process, except that the random initial first hyperparameter is no longer used for training. Instead, the hyperparameter needs to be reset, that is, the second hyperparameter calculated in the pre-training process is configured in the text tensor network (TextTN); then after one round of training, a text classification model that can be used to implement text classification tasks can be obtained, and the text classification model is output for text classification prediction; among them, in the second round of training, the computational amount derived by the hyperparameter calculation module - the tensor network model when the second entanglement entropy tends to converge is the text classification model.

[0071] In an exemplary embodiment, the tensor network includes a discriminative tensor network and r generative tensor networks, and the output data of the r generative tensor networks are the input data of the discriminative tensor network; wherein r is a positive integer.

[0072] In an exemplary embodiment, the text tensor network module is used to: perform the following operations on each sample word vector sequence in a plurality of sample word vector sequences to obtain a plurality of first prediction labels, wherein the plurality of sample word vector sequences correspond to the plurality of first prediction labels: adopt the tensor network model M t The r generative tensor networks in the first target word vector sequence perform dimensionality reduction processing on each first word vector in the first target word vector sequence to obtain a second target word vector sequence, where the first target word vector sequence is any one of the multiple sample word vector sequences, and t is the number of iterations; and the second target word vector sequence is input into the tensor network model M t The discriminant tensor network in the example is used to obtain a first predicted label of the target text, wherein the target text is the text corresponding to the first target word vector sequence; and a loss value L is calculated based on the multiple first predicted labels and the true labels corresponding to the multiple sample word vector sequences. t ; and according to the loss value L t Adjust the tensor network model M t Parameters in to obtain the tensor network model M t+1 ; The hyperparameter calculation module is used to: According to the tensor network model M t+1The third entanglement entropy is calculated by the parameters in; if it is the first round of iterative training, the third entanglement entropy is the first entanglement entropy; if it is the second round of iterative training, the third entanglement entropy is the second entanglement entropy; where, when t = 1, the tensor network model M t is the initial tensor network model.

[0073] In an exemplary embodiment, the first target word vector sequence includes n first word vectors, where n is a positive integer, and the text tensor network module is used to: perform feature mapping on the n first word vectors respectively to obtain n first tensors, where the first tensor is a tensor representation of the first word vector; using the tensor network model M t The r generative tensor networks in perform dimensionality reduction processing on each of the n first tensors to obtain a second target word vector sequence.

[0074] In an exemplary embodiment, the tensor network model M t The r generative tensor networks in the text tensor network correspond to the r first weight parameters. The text tensor network module is used to: perform the following operations on each of the n first tensors to obtain n second word vectors, wherein the n second word vectors correspond to the n first tensors: perform tensor contraction operations on the r first weight parameters and the second tensor respectively to obtain r tensor contraction operation results, wherein the second tensor is any first tensor among the n first tensors; obtain r target probability values ​​according to the r tensor contraction operation results, wherein the sum of the r target probability values ​​is 1; obtain a second word vector according to the r target probability values; and the n second word vectors constitute a second target word vector sequence.

[0075] In an exemplary embodiment, the tensor network model M t The discriminant tensor network in includes n nodes, each first prediction label includes n second prediction labels, and the n second prediction labels are output by n nodes respectively, wherein n is a positive integer, and the text tensor network module is used to: perform the following operations on each first prediction label in multiple first prediction labels to obtain multiple cross entropy losses: perform multiplication and accumulation calculations based on the n second prediction labels in the first target label and the second weight parameters corresponding to the n nodes to obtain a third prediction label, wherein the first target label is any one of the multiple first prediction labels; calculate the cross entropy loss based on the third prediction label and the second target label, wherein the second target label is the true label corresponding to the fourth target word vector sequence, and the fourth target word vector sequence is the sample word vector sequence corresponding to the first target label; calculate the loss value L based on multiple cross entropy losses t .

[0076] In an exemplary embodiment, the hyperparameter calculation module is used to: t+1The jth node and the j+1th node in the discriminant tensor network in the tensor are subjected to tensor contraction and merge operations to obtain the target node, where n is the tensor network model M t+1 The number of nodes in the discriminant tensor network in , n is a positive integer; singular value decomposition is performed on the target node to obtain k singular values, where k is a positive integer; the third entanglement entropy is calculated based on the k singular values.

[0077] The specific implementation of the text tensor network module and the hyperparameter calculation module provided in the embodiments of the present application is introduced below.

[0078] 1. Text Tensor Network Module

[0079] See also Figure 2 , Figure 2 It is a schematic diagram of the architecture of a text tensor network provided in an embodiment of the present application. Among them, the text tensor network includes two layers of tensor networks, the first layer of which is a generative tensor network (GTNs), called word-GTNs or w-GTNs, and their tensor network parameters are shared, and its function is to reduce the dimension of each word vector in the word vector sequence input to the text tensor network, wherein r generative tensor networks can reduce the word vector to r dimensions; its second layer is a discriminant tensor network (DTN), called sentence-DTN or s-DTN, and its function is to model the sentence of the word vector sequence after dimensionality reduction, and output the classification category at the same time. The following introduces the two layers of network structure respectively.

[0080] (1) Word-GTNs submodule

[0081] exist Figure 2 In the equation, w1, w2, ..., w n Represents word vectors; Φ(w1), Φ(w2)..., Φ(w n ) represents the tensor representation of word vector in Hilbert high-dimensional space; v1, v2, ..., v n represents the word vector after dimensionality reduction; x1, x2, ..., x n Respectively represent word vectors w1, w2, ..., w n The intermediate input obtained after sine and cosine transform; Φ(X) represents the high-order tensor obtained after tensor product of the input word vector.

[0082] The input to word-GTNs is a sentence represented by a sequence of word vectors. Assume that the word vector w corresponding to each word in the sentence is i =(θ1,θ2,…,θ m ) Tis an m-dimensional vector. Usually, the value of m ranges from tens to hundreds. The operation to be performed by each word-GTN includes the following two steps:

[0083] The first step is to perform feature mapping on the word vector and map it to the Hilbert high-dimensional space, that is, to perform sine and cosine transform on the value of each dimension of the word vector, and then calculate the tensor product to obtain Φ(w i ), where Φ(w i ) is an m-order tensor. The specific calculation process is shown in formula (1).

[0084]

[0085] It should be understood that only by performing a tensor product operation on each dimension of the word vector and mapping it to a high-dimensional Hilbert space can it be input into the generative tensor network for contraction operation.

[0086] The second step is to initialize r word-GTNs networks to reduce the dimensionality of the words in the high-dimensional feature map, that is, to configure the initial model parameters into the network, and then perform word vector dimensionality reduction calculation. The specific calculation process is shown in formula (2).

[0087]

[0088] In formula (2), W1, W2, ..., W r They are the tensor network states of r word-GTNs. When the first iteration is r is the initial tensor network state; is the tensor contraction operation; p i 1. p i 2.......,p i r It can be understood as the importance of the current word for the model to make certain classification decisions, which satisfies the constraint condition p i 1+p i 2+......+p i r =1.

[0089] The value of r can be adjusted according to actual needs. For example, when r = 2, when there are 2 word-GTNs in the text tensor network, formula (2) can be simplified to formula (3).

[0090]

[0091] At this time, in formula (3), W1 and W2 are the tensor network states of two word-GTNs; · is the tensor contraction operation; p i 1 and p i2 represents the probability that the current word is important or unimportant for the model to make a classification decision, which satisfies the constraint condition p i 1+p i 2=1.

[0092] (2) Sentence-DTN submodule

[0093] exist Figure 2 A s1 , A s2 ,....,A sn They represent nodes respectively; l represents the output prediction label, A s2 l The predicted labels representing the outputs of multiple nodes are synthesized from A s2 Output at the node, where A s2 The output at the node is only exemplary and can be output from any node; α1, α2, ..., α n-1 They represent the connection keys between adjacent nodes.

[0094] From the above, we can see that the input to sentence-DTN is the word vector sequence S = (v1, v2, ..., v n ), when there are r word-GTNs in the text tensor network, the word vector sequence S = (v1, v2, ..., v n ) is a sequence of n vectors, each of which has r dimensions; when there are two word-GTNs in the text tensor network, the word vector sequence S = (v1, v2, …, v n ) is a sequence of n vectors, each of which has a dimension of 2. The specific calculation process of sentence-DTN for text classification prediction is shown in formula (4).

[0095] f(S)=W l ·Φ(S) (4)

[0096] In formula (4), f(S) represents the predicted value of the output; Φ(S) is the tensor product of the word vectors in the sentence, that is, Φ(S) = W l is the network parameter of sentence-DTN. When the first iteration is l are the initial network parameters; · is the tensor contraction operation.

[0097] The contraction operation is the operation between tensors, which is the middle point “·” in formula (4), that is, W land Φ(S) are both tensors. Φ(S) is the tensor product of word vectors, which is an n-order tensor because it is calculated by the tensor product of n vectors. l is a tensor of higher order than Φ(S), so W l After shrinking and merging with Φ(S), only one "leg" (i.e., the dimension corresponding to the category label of the classification) will remain. Specifically, Figure 2 As shown, node A in DTN s1 , A s2 ,....,A sn There is one output "leg" each, indicating that Φ(S) is an n-order tensor, but W l is a tensor of order n+1, W l After being contracted and merged with Φ(S), it becomes a first-order tensor, so node A s1 , A s2 ,....,A sn The outputs of are combined into one "leg" output, that is, Figure 2 The l in.

[0098] The traditional discriminant tensor network only selects the prediction result at a certain node in the tensor contraction operation for training, that is, only one function is predicted and trained, which results in the learning process being unable to learn all the features in the sentence modeling process. Therefore, the present application designs an all-function learning algorithm during the training process, that is, the prediction result of each node in the discriminant tensor network is trained, which can improve the training stability of the model and the accuracy of prediction.

[0099] See also Figure 3 , Figure 3 Schematic diagram of a full function learning algorithm provided in the embodiment of the present application. Figure 3 As shown, for an input of a word vector sequence S, the output of each node in the tensor network is f 1 (X), f 2 (X),......,f n (X), and then according to the weights ε1, ε2, ..., ε n The output f of each node 1 (X), f 2 (X),......,f n (X) calculates the weighted average to obtain the output f(X) of the tensor network. The full function learning algorithm, that is, the prediction results at each node in the tensor shrinking operation are involved in the learning process, so the loss function of the full function learning algorithm can be defined as:

[0100]

[0101] In formula (5), L(W l ,ε) represents the loss value; N is the number of samples; CE represents the cross entropy loss; ε i is a vector, and the value in each dimension corresponds to the weight of each output; Φ(S) is the tensor product of the word vectors in the sentence, that is, l i Indicates the node output position of sentence-DTN; W li Represents the network parameters corresponding to each node; y r Represents the true label vector.

[0102] 2. Hyperparameter Calculation Module

[0103] Tensor networks are generally optimized using the DMRG (Density Matrix Renormalization Group) algorithm. The hyperparameter involved in the DMRG algorithm is the dimension of the bond-dimension between nodes.

[0104] Please also read Figure 4 , Figure 4 Schematic diagram of hyper parameters in the DMRG algorithm provided in the embodiment of the present application. Figure 4 As shown in the figure, the jth node and the j+1th node have three "legs" extending outward. Among them, the jth node is the output node of the entire tensor network, so it has two "legs", and the j+1th node has one "leg". After tensor contraction operation is performed on the jth node and the j+1th node, they are merged into one node, and the merged node also has three "legs". Then singular value decomposition is performed on the merged node to obtain three nodes, namely U sj , S, V l sj+1 , where node U sj has one "leg", node S has no "leg", node V l sj+1 is an output node with two "legs". The hyperparameters are node S and node U sj or node V l sj+1 The dimension of the connection key, that is, the dimension corresponding to the edge connecting the middle diamond node to the circular node after singular value decomposition.

[0105] Calculating hyperparameters can be divided into two steps:

[0106] In the first step, during the network training of the text tensor network, after each round of iteration, the entanglement entropy in the network is calculated at the position where (n-1) / 2 of the number of nodes in the sentence-DTN structure is rounded down, where n represents the number of nodes in the tensor network. The calculation formula of the entanglement entropy is shown in formula (6).

[0107]

[0108] Among them, g h It is the singular value obtained by SVD decomposition of the sentence-DTN structure at the position rounded down to (n-1) / 2, and k is the number of singular values.

[0109] The second step is to calculate the balanced tensor network hyperparameters, i.e., the dimension of the connection key. The specific calculation formula is shown in formula (7).

[0110]

[0111] Among them, E is the entanglement entropy calculated in the first step, and the exponent is obtained and then rounded down.

[0112] The technical solution provided by this application is introduced in detail below in conjunction with specific implementation methods.

[0113] See also Figure 5 , Figure 5 is a flowchart of a text classification model training method provided in an embodiment of the present application, which can be applied to Figure 1 The system shown in the figure, the method is executed by a computer device, and the method includes but is not limited to the following steps:

[0114] Step 501: Perform a first round of iterative training on a tensor network using a first hyperparameter and multiple sample word vector sequences to obtain a target entanglement entropy, wherein the value of the target entanglement entropy is a value when the first entanglement entropy obtained during the first round of iterative training converges.

[0115] It should be understood that one round of iterative training includes multiple iterations, that is, in one round of iteration, multiple sample word vector sequences are input into the tensor network for training multiple times. After each training, the loss of this training is calculated, and the model parameters of the tensor network are adjusted according to the loss of this training to obtain the tensor network model for the next training, and then the next training is carried out until the model converges.

[0116] It should be understood that the multiple sample word vector sequences are obtained by converting multiple texts. As for the conversion of one text into a sample word vector sequence, the specific conversion process is: convert each word in the text into a word vector, obtain multiple word vectors, and then form a sequence of the multiple word vectors to obtain the sample word vector sequence. Among them, when a sample word vector sequence is composed of multiple word vectors, the multiple word vectors can be sorted according to the order of the words corresponding to the word vectors in the text, so as to obtain the sample word vector sequence.

[0117] Specifically, the training data for text classification is preprocessed, including operations such as word segmentation and filtering of stop words, and each sample (sentence) of the training data is converted into a word vector, and then a word vector sequence is formed. The construction of the word vector includes but is not limited to the use of word vector tools such as word2vec.

[0118] Among them, the tensor network can be Figure 2 The specific process of the first round of iterative training is as follows: the word vector sequence of the training data is input into the text tensor network, and a round of training is performed on the training data set using random initial hyperparameters. During each iteration of the training process, the entanglement entropy is calculated and output using the above formula (6). The training is stopped when the change in the entanglement entropy converges.

[0119] Step 502: Calculate a second hyperparameter according to the target entanglement entropy.

[0120] Among them, the first hyperparameter and the second hyperparameter are different values ​​of hyperparameters for the same task.

[0121] Specifically, according to the entanglement entropy value when the first round of iterative training converges, the hyperparameters of the text tensor network are calculated using the above formula (7).

[0122] Step 503: Perform a second round of iterative training on the tensor network using the second hyperparameters and the multiple sample word vector sequences to obtain the text classification model, wherein the text classification model is a tensor network model when the second entanglement entropy calculated during the second round of iterative training converges.

[0123] Specifically, the hyperparameters in the text tensor network are set to the second hyperparameters, and a new round of training is performed. The training is stopped when the change in the entanglement entropy tends to converge. The model obtained at this time is the required text classification model.

[0124] exist Figure 5In the training method of the described text classification model, the tensor network is trained for the first round of iterative training using the initial hyperparameters (i.e., the first hyperparameters) and multiple sample word vector sequences, and a first entangled entropy is calculated each iteration, and the value of the first entangled entropy when it converges is used as the target entangled entropy value; then the hyperparameter (i.e., the second hyperparameter) is calculated based on the target entangled entropy; the second hyperparameter and the multiple sample word vector sequences are used to train the tensor network for the second round of iterative training, and a second entangled entropy is calculated each iteration, and the tensor network model when the second entangled entropy converges is used as the required text classification model for text classification; since the embodiment of the present application only needs to perform pre-training once to directly calculate the hyperparameters of the model, the calculated hyperparameters can be brought into re-training to output a model that can be used to implement text classification tasks, which greatly reduces the difficulty and cost of model training and the occurrence of overfitting.

[0125] In an exemplary embodiment, the tensor network includes a discriminative tensor network (DTN) and r generative tensor networks (GTN), and the output data of the r generative tensor networks are the input data of the discriminative tensor network; wherein r is a positive integer.

[0126] Among them, the r generative tensor networks are used to perform dimensionality reduction processing on the sample word vector sequence, and the discriminative tensor network is used to perform text classification on the word vector sequence after dimensionality reduction.

[0127] It can be seen that in this example, the tensor network used for text classification model training includes a discriminative tensor network and r generative tensor networks. The output of the r generative tensor networks is the input of the discriminative tensor network. The r generative tensor networks are used to reduce the dimension of the input sample word vector sequence, and then input the reduced word vector sequence into the discriminative tensor network for sentence modeling and text classification. Since the sample dimension during training is reduced, it is helpful to reduce the difficulty and cost of model training.

[0128] In an exemplary embodiment, the iterative training includes: performing the following operations on each sample word vector sequence in the multiple sample word vector sequences to obtain multiple first prediction labels, wherein the multiple sample word vector sequences correspond to the multiple first prediction labels: using the tensor network model M t The r generative tensor networks in the first target word vector sequence perform dimensionality reduction processing on each first word vector in the first target word vector sequence to obtain a second target word vector sequence, where the first target word vector sequence is any one of the multiple sample word vector sequences, and t is the number of iterations; the second target word vector sequence is input into the tensor network model M tThe discriminant tensor network in the example is used to obtain the first predicted label of the target text, where the target text is the text corresponding to the first target word vector sequence; the loss value L is calculated based on the multiple first predicted labels and the true labels corresponding to the multiple sample word vector sequences. t ; According to the loss value L t Adjust the tensor network model M t Parameters in to get the tensor network model M t+1 ; and according to the tensor network model M t+1 The third entanglement entropy is calculated by using the parameters in ; when the third entanglement entropy does not converge, set t = t + 1, and repeat the above steps until the third entanglement entropy converges; when the third entanglement entropy converges, if the iterative training is the first round of iterative training, the target entanglement entropy is the third entanglement entropy; if the iterative training is the second round of iterative training, the text classification model is the tensor network model M t+1 ; Among them, when t = 1, the tensor network model M t is the initial tensor network model.

[0129] It should be understood that when t=1, the tensor network model M t is an initial tensor network model, which is a tensor network model after initial model parameters are configured for the tensor network.

[0130] Specifically, for the word vector sequence of the input text tensor network, each word is generally represented by a vector of dozens to hundreds of dimensions. First, the value of each dimension of the word vector is substituted into the above formula (1) for tensor product calculation, thereby realizing feature mapping to the Hilbert high-dimensional space; then, r word-GTNs are initialized, that is, the initial model parameters are configured into the r word-GTNs, and the above formula (2) is used to reduce the dimension of the mapping of the word vector in the Hilbert high-dimensional space to obtain an r-dimensional word vector; the sentence-DTN is initialized, that is, the initial model parameters are configured into the sentence-DTN, wherein the initial model parameters configured into the r word-GTNs are different from the initial model parameters configured into the sentence-DTN; specifically, the model parameters configured into the r word-GTNs are W1, W2, ..., W r , the model parameters configured in sentence-DTN are W l ; Input the n-dimensional word vector sequence of the sentence obtained after dimensionality reduction into sentence-DTN for sentence modeling, and output the classification result. Specifically, use the above formula (4) to calculate the predicted label; calculate the error between the output classification result and the category label marked in the training data (that is, the real label) according to the above formula (5), and adjust the model parameters W1, W2, ..., W according to the errorr and W l The value of is obtained to obtain the model for the next iterative training, and then the next iterative training is carried out.

[0131] It can be seen that in this example, in each iteration of the iterative training of the tensor network, for each sample word vector sequence in the multiple sample word vector sequences, it is first input into r generative tensor networks for dimensionality reduction processing in turn, and then input into the discriminative tensor network for text classification after dimensionality reduction, so as to obtain the predicted labels corresponding to the multiple sample word vector sequences; then, the loss value is calculated according to the predicted labels corresponding to the multiple sample word vector sequences and the true labels corresponding to the multiple sample word vector sequences, and the model parameters are adjusted according to the loss value to obtain the model of the next iteration, and the third entanglement entropy is calculated according to the parameters in the model of the next iteration; when the third entanglement entropy does not converge, repeat the above steps for the next iteration until the third entanglement entropy converges; when the third entanglement entropy converges, if it is the first round of iterative training, the hyperparameters can be calculated according to the third entanglement entropy; if it is the second round of iterative training, the model of the next iteration is the required classification model, which can be used for text classification tasks.

[0132] In an exemplary embodiment, the first target word vector sequence includes n first word vectors, where n is a positive integer, and the tensor network model M is used. t The r generative tensor networks in the first target word vector sequence perform dimensionality reduction processing on each first word vector in the first target word vector sequence to obtain a second target word vector sequence, including: performing feature mapping on the n first word vectors respectively to obtain n first tensors, wherein the first tensor is a tensor representation of the first word vector; using the tensor network model M t The r generative tensor networks in perform dimensionality reduction processing on each of the n first tensors to obtain a second target word vector sequence.

[0133] When performing feature mapping on word vectors, the word vectors can be mapped to Hilbert high-dimensional space.

[0134] It should be understood that only by performing a tensor product operation on each dimension of the word vector and mapping it to a high-dimensional Hilbert space can it be input into the generative tensor network for contraction operation.

[0135] It can be seen that in this example, each first word vector in the sample word vector sequence in the input model is first mapped to a high-dimensional space, and dimensionality is increased to obtain a first tensor; then the r generative tensor networks in the tensor network model are used to reduce the dimension of the first tensor to obtain a second word vector, wherein the dimension of the second word vector is lower than that of the first word vector; the first word vector is firstly increased in dimension to facilitate feature extraction of the word vector; then the word vector is reduced in dimension, and the word vector sequence after dimensionality reduction is input into the discriminant tensor network for prediction, which is beneficial to improve the efficiency of word vector expression for words and reduce the cost of model training.

[0136] In an exemplary embodiment, the tensor network model M t The r generative tensor networks in correspond to the r first weight parameters, using the tensor network model M t The r generative tensor networks in the dimensionality reduction process are performed on each of the n first tensors to obtain a second target word vector sequence, including: performing the following operations on each of the n first tensors to obtain n second word vectors, wherein the n second word vectors correspond to the n first tensors: performing tensor contraction operations on the r first weight parameters and the second tensors respectively to obtain r tensor contraction operation results, wherein the second tensor is any first tensor of the n first tensors; obtaining r target probability values ​​according to the r tensor contraction operation results, wherein the sum of the r target probability values ​​is 1; obtaining a second word vector according to the r target probability values; and the n second word vectors constitute a second target word vector sequence.

[0137] Among them, the first weight parameter can be the tensor network state of the generative tensor network, and the target probability value can be understood as the importance of the current word for certain decisions made by the model to make classification.

[0138] It can be seen that in this example, when the high-dimensional first tensor is reduced to a low-dimensional second word vector, with respect to a first tensor, the tensor network states of r generative tensor networks are respectively subjected to tensor contraction operations with the first tensor to obtain r tensor contraction operation results; then, r target probability values ​​are obtained based on the r tensor contraction operation results, wherein the sum of the r target probability values ​​is 1, and the target probability value can be understood as the importance of the current word to certain decisions made by the model for classification; and then, the second word vector is obtained based on the r target probability values, so that the second word vector satisfies the characteristics of probability, that is, the second word vector has r dimensions, and the r dimensions correspond to the r target probability values, which is conducive to the discriminant tensor network making text classification results for the word vector sequence.

[0139] In an exemplary embodiment, the tensor network model M tThe discriminant tensor network in includes n nodes, each first prediction label includes n second prediction labels, and the n second prediction labels are output by n nodes respectively, where n is a positive integer. The loss value L is calculated based on the real labels corresponding to the multiple first prediction labels and the multiple sample word vector sequences. t , including: performing the following operations on each of the multiple first prediction labels to obtain multiple cross entropy losses: performing multiplication and accumulation calculations based on the n second prediction labels in the first target label and the second weight parameters corresponding to the n nodes to obtain a third prediction label, wherein the first target label is any one of the multiple first prediction labels; calculating the cross entropy loss based on the third prediction label and the second target label, wherein the second target label is the true label corresponding to the fourth target word vector sequence, and the fourth target word vector sequence is the sample word vector sequence corresponding to the first target label; calculating the loss value L based on the multiple cross entropy losses t .

[0140] It should be understood that the traditional discriminant tensor network only selects the prediction result at a certain node in the tensor contraction operation for training, that is, only one function is predicted and trained, which results in the learning process being unable to learn all the features in the sentence modeling process. Therefore, this example designs an all-function learning algorithm during the training process, that is, the prediction result of each node in the discriminant tensor network is trained. Specifically, after the word vector sequence is input into the discriminant tensor network, each node in the discriminant tensor network outputs a prediction label, and the weighted average of the prediction labels output by each node is calculated, and the result of the weighted average is used as the prediction label of the word vector sequence.

[0141] It can be seen that in this example, during training, after the word vector sequence is input into the discriminant tensor network, each node in the discriminant tensor network outputs a prediction label, and the predicted labels output by each node are weighted averaged, and the result of the weighted average is used as the predicted label of the word vector sequence; thereby, multiple cross losses are calculated using the weighted average predicted labels corresponding to multiple word vector sequences and the corresponding true labels, and then the loss value of an iteration is obtained based on the multiple cross losses, and the model parameters are adjusted based on the loss value, which can improve the training stability of the model and the prediction accuracy.

[0142] In an exemplary embodiment, according to the tensor network model M t+1 The third entanglement entropy is calculated by the parameters in, including: t+1 The jth node and the j+1th node in the discriminant tensor network in the tensor are subjected to tensor contraction and merge operations to obtain the target node, where n is the tensor network model M t+1The number of nodes in the discriminant tensor network, n is a positive integer; singular value decomposition (SVD) is performed on the target node to obtain k singular values, where k is a positive integer; the third entanglement entropy is calculated based on the k singular values.

[0143] The target node is the node synthesized by performing tensor shrinking and merging operations on the j-th node and the j+1-th node.

[0144] It can be seen that in this example, by performing tensor contraction operation on the jth node and the j+1th node in the discriminant tensor network, the jth node and the j+1th node are combined into one node, where: n is the number of nodes of the discriminant tensor network, and n is a positive integer; then the synthesized nodes are subjected to singular value decomposition to obtain k singular values; and then the k singular values ​​are used to calculate the entanglement entropy, which is conducive to calculating the hyperparameters based on the entanglement entropy, and realizing the computability of the hyperparameters in the model training.

[0145] The technical solution provided by this application is described in detail below with reference to specific examples.

[0146] according to Figure 5 The method flow shown is to train a text tensor network, and is illustrated with a specific example.

[0147] (1) Collect text classification training corpus, taking English sentiment classification corpus as an example. One of the sentences is as follows:

[0148] "it's a terrible movie in every regard, and utterly painful to watch1".

[0149] Among them, the English text is marked with label 1, indicating negative sentiment polarity.

[0150] The training corpus is a large amount of text integrated in this format. First, the text is preprocessed by word segmentation, and the word vector of each word is obtained using the word2vec word vector tool, thereby converting the above text into a word vector sequence composed of word vectors.

[0151] (2) Input the word vector sequence of the training data into the text tensor network, and perform a round of training on the training data set using random initial hyperparameters. During each iteration of the training process, the entanglement entropy is calculated using the above formula (6), and the entanglement entropy calculated each time is output; the calculated entanglement entropy value and the number of iterations are plotted in a coordinate system, as shown in Figure 6 As shown, Figure 6is a graph showing the relationship between entanglement entropy and the number of iterations in a text classification model training process provided by an embodiment of the present application. Figure 6 The trend of the middle curve can be used to determine whether the change in entanglement entropy tends to converge. When the entanglement entropy converges, stop this round of training.

[0152] (3) By Figure 6 It can be seen that the entanglement entropy value is 4.40 when the change of entanglement entropy tends to converge. According to the above formula (7), the hyperparameter of the text tensor network, the dimension of the connection key, is calculated to be 21, that is, Among them, Figure 6 In the above figure, Entanglement Entropy represents entanglement entropy, and Epoch represents the number of iterations.

[0153] (4) The dimension of the connection key in the text tensor network is set to 21, and a new round of training is performed. The entanglement entropy calculated at each iteration during the training process is output, and the training is stopped after the entanglement entropy converges.

[0154] (5) The model obtained after training is the required text classification model, which can be used to implement text classification prediction tasks.

[0155] In the embodiment of the present application, when constructing a text classification model, the value of the hyperparameter can be calculated through only one pre-training, and the calculated hyperparameter can be brought into the training again to obtain a model that can be used to implement the text classification task. However, according to the traditional machine learning model training method, the dimension of the hyperparameter-connection key needs to be set by setting a number of values, training a model for each value, and verifying the effect of each model, and determining the hyperparameter based on the peak value of the model effect, such as Figure 7 As shown; among them, Figure 7 In the example, Accuracy (Acc) represents accuracy, Entanglement Entropy represents entanglement entropy, and Bond Dimension represents the dimension of the bond. The embodiment of the present application can calculate the hyperparameters of the model, give full play to the interpretability advantage of the tensor network, and reduce the difficulty of model parameter adjustment.

[0156] In addition, the text classification model trained by the embodiment of the present application is shown in the experiment on the public text classification data set, and the effect is basically the same as that of the deep neural network. The effect of some data sets is better than the traditional neural network model, which proves that the text classification model trained by the embodiment of the present application has no loss of accuracy. The specific comparison results are shown in Table 1.

[0157] Table 1 Model effect comparison results

[0158] Model MR CR Subj MPQA CNN[1] 81.5 85.5 93.4 89.6 Capsule-B[2] 82.3 85.1 93.8 -- HAC[3] 83.3 86.4 95.1 89.8 HCapsNet[4] 83.5 -- 94.2 -- GTNs* 77.8 79.0 90.6 88.0 TextTN* 80.5 85.7 94.2 89.8

[0159] Among them, the comparison index in Table 1 is accuracy; the public text classification datasets are:

[0160] (1) TREC: The dataset covers six question types (entity, person, abbreviation, description, location, and value); there are 5452 questions in the training set and 500 questions in the test set.

[0161] (2) MR: Each movie review has only one sentence and is divided into positive and negative categories; the size of the positive dataset is 5331 and the size of the negative dataset is 5331.

[0162] (3) CR: The customer review dataset contains 3775 samples, and the task is to predict positive or negative product reviews.

[0163] (4) SUBJ: Subjectivity dataset, the goal is to classify text as subjective or objective, with a total of 10,000 samples.

[0164] (5) MPQA: Opinion polarity detection subtask, which contains 10,606 samples and is a binary classification task.

[0165] Among them, test accuracy is the evaluation indicator of these datasets.

[0166] Among them, the comparison models compared with the text classification model trained by the embodiment of the present application are:

[0167] CNN: [1] Yoon Kim. Convolutional neural networks for sentence classification. (EMNLP), pages 1746–1751, 2014.

[0168] Capsule-B: [2] Min Yang, Wei Zhao, Jianbo Ye, Zeyang Lei, Zhou Zhao, and Soufei Zhang. Investigating capsule networks402 with dynamic routing for text classification. (EMNLP), pages3110–3119, 2018.

[0169] HAC: [3] Hai Wan Chuan Chen Wanshan Zheng, Zibin Zheng, Hai Wan, and ChuanChen. Dynamically route405hierarchical structure representation to attentivecapsule for text classification. pages 5464–5470. AAAI Press, 2019.

[0170] HCapsNet: [4] Chunning Du, Haifeng Sun, Jingyu Wang, Qi Qi, Jianxin Liao, Chun Wang, and Bing Ma. Investigating326capsule network and semantic feature onhyperplanes for text classification (EMNLP), pages 456–465, 2019.

[0171] The method of the embodiment of the present application is described in detail above, and the device of the embodiment of the present application is provided below.

[0172] See also Figure 8 , Figure 8 8 is a structural diagram of a text classification model training device 800 provided in an embodiment of the present application. The text classification model training device 800 may include a training unit 801 and a computing unit 802, wherein each unit is described in detail as follows:

[0173] A training unit 801 is used to perform a first round of iterative training on the tensor network using a first hyperparameter and a plurality of sample word vector sequences to obtain a target entanglement entropy, wherein the value of the target entanglement entropy is a value when the first entanglement entropy obtained during the first round of iterative training converges;

[0174] A calculation unit 802, configured to calculate a second hyperparameter according to a target entanglement entropy;

[0175] The training unit 801 is also used to perform a second round of iterative training on the tensor network using a second hyperparameter and multiple sample word vector sequences to obtain a text classification model, wherein the text classification model is a tensor network model when the second entanglement entropy calculated during the second round of iterative training converges.

[0176] In an exemplary embodiment, the tensor network includes a discriminative tensor network and r generative tensor networks, and the output data of the r generative tensor networks are the input data of the discriminative tensor network; wherein r is a positive integer.

[0177] In an exemplary embodiment, the training unit 801 is used to: perform the following operations on each sample word vector sequence in the multiple sample word vector sequences to obtain multiple first prediction labels, wherein the multiple sample word vector sequences correspond to the multiple first prediction labels: using the tensor network model M t The r generative tensor networks in the first target word vector sequence perform dimensionality reduction processing on each first word vector in the first target word vector sequence to obtain a second target word vector sequence, where the first target word vector sequence is any one of the multiple sample word vector sequences, and t is the number of iterations; the second target word vector sequence is input into the tensor network model M t The discriminant tensor network in the example is used to obtain the first predicted label of the target text, where the target text is the text corresponding to the first target word vector sequence; the loss value L is calculated based on the multiple first predicted labels and the true labels corresponding to the multiple sample word vector sequences. t ; According to the loss value L t Adjust the tensor network model M t Parameters in to get the tensor network model M t+1 ; and according to the tensor network model M t+1 The third entanglement entropy is calculated by using the parameters in ; when the third entanglement entropy does not converge, set t = t + 1, and repeat the above steps until the third entanglement entropy converges; when the third entanglement entropy converges, if the iterative training is the first round of iterative training, the target entanglement entropy is the third entanglement entropy; if the iterative training is the second round of iterative training, the text classification model is the tensor network model M t+1 ; Among them, when t = 1, the tensor network model M t is the initial tensor network model.

[0178] In an exemplary embodiment, the first target word vector sequence includes n first word vectors, where n is a positive integer, and the training unit is used to: perform feature mapping on the n first word vectors respectively to obtain n first tensors, where the first tensor is a tensor representation of the first word vector; use the tensor network model M t The r generative tensor networks in perform dimensionality reduction processing on each of the n first tensors to obtain a second target word vector sequence.

[0179] In an exemplary embodiment, 12. The device according to claim 11, characterized in that the tensor network model M tThe r generative tensor networks in the training unit correspond to the r first weight parameters, and the training unit is used to: perform the following operations on each of the n first tensors to obtain n second word vectors, wherein the n second word vectors correspond to the n first tensors: perform tensor contraction operations on the r first weight parameters and the second tensor respectively to obtain r tensor contraction operation results, wherein the second tensor is any first tensor among the n first tensors; obtain r target probability values ​​according to the r tensor contraction operation results, wherein the sum of the r target probability values ​​is 1; obtain a second word vector according to the r target probability values; and the n second word vectors constitute a second target word vector sequence.

[0180] In an exemplary embodiment, the tensor network model M t The discriminant tensor network in includes n nodes, each first prediction label includes n second prediction labels, and the n second prediction labels are output by n nodes respectively, wherein n is a positive integer, and the training unit 801 is used to: perform the following operations on each first prediction label in the plurality of first prediction labels to obtain a plurality of cross entropy losses: perform multiplication and accumulation calculations based on the n second prediction labels in the first target label and the second weight parameters corresponding to the n nodes to obtain a third prediction label, wherein the first target label is any one of the plurality of first prediction labels; calculate the cross entropy loss based on the third prediction label and the second target label, wherein the second target label is the true label corresponding to the fourth target word vector sequence, and the fourth target word vector sequence is the sample word vector sequence corresponding to the first target label; calculate the loss value L based on the plurality of cross entropy losses t .

[0181] In an exemplary embodiment, the training unit 801 is used to: train the tensor network model M t+1 The jth node and the j+1th node in the discriminant tensor network in the tensor are subjected to tensor contraction and merge operations to obtain the target node, where n is the tensor network model M t+1 The number of nodes in the discriminant tensor network in , n is a positive integer; singular value decomposition is performed on the target node to obtain k singular values, where k is a positive integer; the third entanglement entropy is calculated based on the k singular values.

[0182] It should be noted that the implementation of each unit can also refer to Figure 5 Of course, the text classification model training device 800 provided in the embodiment of the present application includes but is not limited to the above-mentioned unit modules, for example: the text classification model training device 800 may also include a storage unit 803, which may be used to store the program code and data of the text classification model training device 800.

[0183] exist Figure 8 In the training device 800 of the described text classification model, the tensor network is trained for the first round of iterative training using the initial hyperparameters (i.e., the first hyperparameters) and multiple sample word vector sequences, and a first entangled entropy is calculated each iteration, and the value of the first entangled entropy when it converges is used as the target entangled entropy value; then the hyperparameter (i.e., the second hyperparameter) is calculated based on the target entangled entropy; then the second hyperparameter and the multiple sample word vector sequences are used to perform a second round of iterative training on the tensor network, and a second entangled entropy is calculated each iteration, and the tensor network model when the second entangled entropy converges is used as the required text classification model for text classification; since the embodiment of the present application only needs to perform pre-training once to directly calculate the hyperparameters of the model, the calculated hyperparameters can be brought into re-training to output a model that can be used to implement text classification tasks, which greatly reduces the difficulty and cost of model training and the occurrence of overfitting.

[0184] See also Fig. 9 , Fig. 9 9 is a schematic diagram of the structure of a computer device 910 provided in an embodiment of the present application. The computer device 910 includes a processor 911, a memory 912 and a communication interface 913. The processor 911, the memory 912 and the communication interface 913 are interconnected via a bus 914.

[0185] The memory 912 includes, but is not limited to, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), or a portable read-only memory (CD-ROM), and the memory 912 is used for related computer programs and data. The communication interface 913 is used to receive and send data.

[0186] The processor 911 may be one or more central processing units (CPUs). When the processor 911 is a CPU, the CPU may be a single-core CPU or a multi-core CPU.

[0187] The processor 911 in the computer device 910 is used to read the computer program code stored in the above-mentioned memory 912, and perform the following operations: perform a first round of iterative training on the tensor network using a first hyperparameter and multiple sample word vector sequences to obtain a target entanglement entropy, wherein the value of the target entanglement entropy is a value when the first entanglement entropy obtained during the first round of iterative training converges; calculate a second hyperparameter based on the target entanglement entropy; perform a second round of iterative training on the tensor network using the second hyperparameter and multiple sample word vector sequences to obtain a text classification model, wherein the text classification model is a tensor network model when the second entanglement entropy calculated during the second round of iterative training converges.

[0188] It should be noted that the implementation of each operation can also refer to Figure 5 The corresponding description of the method embodiment shown.

[0189] exist Fig. 9 In the described computer device 910, the tensor network is trained for the first round of iterative training using the initial hyperparameters (i.e., the first hyperparameters) and multiple sample word vector sequences, and a first entanglement entropy is calculated for each iteration, and the value of the first entanglement entropy when it converges is used as the value of the target entanglement entropy; then the hyperparameter (i.e., the second hyperparameter) is calculated based on the target entanglement entropy; the second hyperparameter and the multiple sample word vector sequences are used to perform a second round of iterative training on the tensor network, and a second entanglement entropy is calculated for each iteration, and the tensor network model when the second entanglement entropy converges is used as the required text classification model for text classification; since the embodiment of the present application only needs to perform pre-training once to directly calculate the hyperparameters of the model, the calculated hyperparameters can be brought into re-training to output a model that can be used to implement text classification tasks, which greatly reduces the difficulty and cost of model training and the occurrence of overfitting.

[0190] The embodiment of the present application further provides a chip, the chip comprising at least one processor, a memory and an interface circuit, the memory, the transceiver and the at least one processor are interconnected through a line, the at least one memory stores a computer program; when the computer program is executed by the processor, Figure 5 The method flow shown is realized.

[0191] The present application also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, which, when executed on a computer, Figure 5 The method flow shown is realized.

[0192] The present application also provides a computer program product. When the computer program product is run on a computer, Figure 5 The method flow shown is realized.

[0193] In summary, by implementing the embodiments of the present application, the tensor network is trained for the first round of iterative training using the initial hyperparameters (i.e., the first hyperparameters) and multiple sample word vector sequences, and a first entanglement entropy is calculated each iteration, and the value of the first entanglement entropy when it converges is used as the value of the target entanglement entropy; then the hyperparameter (i.e., the second hyperparameter) is calculated according to the target entanglement entropy; the second hyperparameter and the multiple sample word vector sequences are used to perform a second round of iterative training on the tensor network, and a second entanglement entropy is calculated each iteration, and the tensor network model when the second entanglement entropy converges is used as the required text classification model for text classification; since the embodiments of the present application only require one pre-training to directly calculate the hyperparameters of the model, the calculated hyperparameters can be brought into the re-training to output a model that can be used to implement text classification tasks, which greatly reduces the difficulty and cost of model training and the occurrence of overfitting.

[0194] It should be understood that the processor mentioned in the embodiments of the present application may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.

[0195] It should also be understood that the memory mentioned in the embodiments of the present application may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus random access memory (Direct Rambus RAM, DR RAM).

[0196] It should be noted that when the processor is a general-purpose processor, DSP, ASIC, FPGA or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, the memory (storage module) is integrated in the processor.

[0197] It should be noted that the memory described herein is intended to include, but is not limited to, these and any other suitable types of memory.

[0198] It should also be understood that the first, second, third, fourth and various numerical numbers involved in this document are only distinctions made for convenience of description and are not intended to limit the scope of the present application.

[0199] It should be understood that the term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0200] It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0201] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0202] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0203] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0204] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0205] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0206] If the above functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method shown in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0207] The steps in the method of the embodiment of the present application can be adjusted in order, combined and deleted according to actual needs.

[0208] The modules in the device of the embodiment of the present application can be merged, divided and deleted according to actual needs.

[0209] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A training method for a text classification model, characterized in that: The method is performed by a computer device, and comprises: Performing a first round of iterative training on the tensor network using a first hyperparameter and a plurality of sample word vector sequences to obtain a target entanglement entropy, wherein a value of the target entanglement entropy is a value when a first entanglement entropy obtained during the first round of iterative training converges, and the tensor network includes r generative tensor networks and a discriminative tensor network, where r is a positive integer; Calculate a second hyperparameter according to the target entanglement entropy; The second hyperparameters and the multiple sample word vector sequences are used to perform a second round of iterative training on the tensor network to obtain the text classification model, wherein the text classification model is a tensor network model when the second entanglement entropy calculated during the second round of iterative training converges.

2. The method according to claim 1, characterized in that The output data of the r generative tensor networks are the input data of the discriminative tensor network.

3. The method according to claim 2, characterized in that The iterative training includes: Perform the following operations on each sample word vector sequence in the multiple sample word vector sequences to obtain multiple first prediction labels, wherein the multiple sample word vector sequences correspond to the multiple first prediction labels: Using tensor network model M t The r generative tensor networks in perform dimensionality reduction processing on each first word vector in the first target word vector sequence to obtain a second target word vector sequence, wherein the first target word vector sequence is any one of the multiple sample word vector sequences, and t is the number of iterations; Input the second target word vector sequence into the tensor network model M t The discriminant tensor network in obtains a first predicted label of a target text, wherein the target text is a text corresponding to the first target word vector sequence; The loss value L is calculated based on the multiple first predicted labels and the real labels corresponding to the multiple sample word vector sequences. t ; According to the loss value L t Adjust the tensor network model M t Parameters in to get the tensor network model M t+1 ; and according to the tensor network model M t+1 The third entanglement entropy is calculated by the parameters in; When the third entanglement entropy does not converge, set t=t+1, and repeat the above steps until the third entanglement entropy converges; when the third entanglement entropy converges, if the iterative training is the first round of iterative training, the target entanglement entropy is the third entanglement entropy; if the iterative training is the second round of iterative training, the text classification model is the tensor network model M t+1 ; Among them, when t=1, the tensor network model M t is the initial tensor network model.

4. The method according to claim 3, characterized in that The first target word vector sequence includes n first word vectors, wherein n is a positive integer, and the tensor network model M is used. t The r generative tensor networks in perform dimensionality reduction processing on each first word vector in the first target word vector sequence to obtain a second target word vector sequence, including: Perform feature mapping on the n first word vectors respectively to obtain n first tensors, wherein the first tensor is a tensor representation of the first word vector; Using the tensor network model M t The r generative tensor networks in perform dimensionality reduction processing on each of the n first tensors to obtain the second target word vector sequence.

5. The method according to claim 4, characterized in that The tensor network model M t The r generative tensor networks in the embodiment correspond to the r first weight parameters, and the tensor network model M is adopted. t The r generative tensor networks in perform dimensionality reduction processing on each of the n first tensors to obtain the second target word vector sequence, including: Perform the following operations on each of the n first tensors to obtain n second word vectors, wherein the n second word vectors correspond to the n first tensors: Perform tensor contraction operations on the r first weight parameters and the second tensor respectively, to obtain r tensor contraction operation results, wherein the second tensor is any first tensor among the n first tensors; Obtaining r target probability values ​​according to the r tensor contraction and union operation results, wherein the sum of the r target probability values ​​is 1; Obtain a second word vector according to the r target probability values; The n second word vectors constitute the second target word vector sequence.

6. The method according to claim 3, characterized in that The tensor network model M t The discriminant tensor network in includes n nodes, each of the first predicted labels includes n second predicted labels, and the n second predicted labels are output by the n nodes respectively, wherein n is a positive integer, and the loss value L is calculated according to the multiple first predicted labels and the real labels corresponding to the multiple sample word vector sequences. t ,include: The following operations are performed on each of the multiple first prediction labels to obtain multiple cross entropy losses: Perform multiplication and accumulation calculations according to the n second prediction labels in the first target label and the second weight parameters corresponding to the n nodes to obtain a third prediction label, wherein the first target label is any one of the multiple first prediction labels; A cross entropy loss is calculated according to the third predicted label and the second target label, wherein the second target label is a true label corresponding to the fourth target word vector sequence, and the fourth target word vector sequence is a sample word vector sequence corresponding to the first target label; The loss value L is obtained by calculating the multiple cross entropy losses t .

7. The method according to claim 3, characterized in that According to the tensor network model M t+1 The third entanglement entropy is calculated by the parameters in, including: For the tensor network model M t+1 The jth node and the j+1th node in the discriminant tensor network in the tensor are subjected to tensor contraction and merge operations to obtain the target node, where The n is the tensor network model M t+1 The number of nodes of the discriminant tensor network in , wherein n is a positive integer; Performing singular value decomposition on the target node to obtain k singular values, where k is a positive integer; The third entanglement entropy is calculated based on the k singular values.

8. A text classification model training system, characterized in that: The system includes a text tensor network module and a hyperparameter calculation module; The text tensor network module is used to perform a first round of iterative training on the tensor network using a first hyperparameter and a plurality of sample word vector sequences, wherein the tensor network includes r generative tensor networks and a discriminative tensor network, where r is a positive integer; The hyperparameter calculation module is used to calculate the first entanglement entropy after each iterative training of the first round of iterative training is completed to obtain a target entanglement entropy, and calculate a second hyperparameter according to the target entanglement entropy, wherein the value of the target entanglement entropy is the value when the first entanglement entropy converges; The text tensor network module is further used to perform a second round of iterative training on the tensor network using the second hyperparameter and the multiple sample word vector sequences; The hyperparameter calculation module is further used to calculate the second entanglement entropy after each iteration training of the second round of iterative training is completed; Among them, the tensor network model when the second entanglement entropy converges is the text classification model.

9. The system according to claim 8, characterized in that The output data of the r generative tensor networks are the input data of the discriminative tensor network.

10. The system according to claim 9, characterized in that The text tensor network module is used to: perform the following operations on each sample word vector sequence in the multiple sample word vector sequences to obtain multiple first prediction labels, wherein the multiple sample word vector sequences correspond to the multiple first prediction labels: adopt the tensor network model M t The r generative tensor networks in the first target word vector sequence perform dimensionality reduction processing on each first word vector in the first target word vector sequence to obtain a second target word vector sequence, wherein the first target word vector sequence is any one of the multiple sample word vector sequences, and t is the number of iterations; and the second target word vector sequence is input into the tensor network model M t The discriminant tensor network in the example is used to obtain a first predicted label of a target text, wherein the target text is a text corresponding to the first target word vector sequence; and a loss value L is calculated based on the multiple first predicted labels and the true labels corresponding to the multiple sample word vector sequences. t ; and according to the loss value L t Adjust the tensor network model M t Parameters in to get the tensor network model M t+1 ; The hyperparameter calculation module is used to: t+1 The third entanglement entropy is calculated by the parameters in; If it is the first round of iterative training, the third entanglement entropy is the first entanglement entropy; if it is the second round of iterative training, the third entanglement entropy is the second entanglement entropy; Among them, when t=1, the tensor network model M t is the initial tensor network model.

11. The system according to claim 10, characterized in that The first target word vector sequence includes n first word vectors, wherein n is a positive integer, and the text tensor network module is used to: Perform feature mapping on the n first word vectors respectively to obtain n first tensors, wherein the first tensor is a tensor representation of the first word vector; Using the tensor network model M t The r generative tensor networks in perform dimensionality reduction processing on each of the n first tensors to obtain the second target word vector sequence.

12. The system according to claim 11, characterized in that The tensor network model M t The r generative tensor networks in correspond to the r first weight parameters, and the text tensor network module is used for: Perform the following operations on each of the n first tensors to obtain n second word vectors, wherein the n second word vectors correspond to the n first tensors: Perform tensor contraction operations on the r first weight parameters and the second tensor respectively, to obtain r tensor contraction operation results, wherein the second tensor is any first tensor among the n first tensors; Obtaining r target probability values ​​according to the r tensor contraction and union operation results, wherein the sum of the r target probability values ​​is 1; Obtain a second word vector according to the r target probability values; The n second word vectors constitute the second target word vector sequence.

13. The system according to claim 10, characterized in that The tensor network model M t The discriminant tensor network in includes n nodes, each of the first prediction labels includes n second prediction labels, and the n second prediction labels are respectively output by the n nodes, wherein n is a positive integer, and the text tensor network module is used to: The following operations are performed on each of the multiple first prediction labels to obtain multiple cross entropy losses: Perform multiplication and accumulation calculations according to the n second prediction labels in the first target label and the second weight parameters corresponding to the n nodes to obtain a third prediction label, wherein the first target label is any one of the multiple first prediction labels; A cross entropy loss is calculated according to the third predicted label and the second target label, wherein the second target label is a true label corresponding to the fourth target word vector sequence, and the fourth target word vector sequence is a sample word vector sequence corresponding to the first target label; The loss value L is obtained by calculating the multiple cross entropy losses t .

14. The system according to claim 10, characterized in that The hyperparameter calculation module is used to: For the tensor network model M t+1 The jth node and the j+1th node in the discriminant tensor network in the tensor are subjected to tensor contraction and merge operations to obtain the target node, where The n is the tensor network model M t+1 The number of nodes of the discriminant tensor network in , wherein n is a positive integer; Performing singular value decomposition on the target node to obtain k singular values, where k is a positive integer; The third entanglement entropy is calculated based on the k singular values.

15. A training device for a text classification model, characterized in that: The device comprises: A training unit, configured to perform a first round of iterative training on a tensor network using a first hyperparameter and a plurality of sample word vector sequences to obtain a target entanglement entropy, wherein a value of the target entanglement entropy is a value when a first entanglement entropy obtained during the first round of iterative training converges, and the tensor network includes r generative tensor networks and a discriminative tensor network, and r is a positive integer; A calculation unit, configured to calculate a second hyperparameter according to the target entanglement entropy; The training unit is also used to perform a second round of iterative training on the tensor network using the second hyperparameters and the multiple sample word vector sequences to obtain the text classification model, wherein the text classification model is a tensor network model when the second entanglement entropy calculated during the second round of iterative training converges.

16. The device according to claim 15, characterized in that The output data of the r generative tensor networks are the input data of the discriminative tensor network.

17. The device according to claim 16, characterized in that The training unit is used to: Perform the following operations on each sample word vector sequence in the multiple sample word vector sequences to obtain multiple first prediction labels, wherein the multiple sample word vector sequences correspond to the multiple first prediction labels: Using tensor network model M t The r generative tensor networks in perform dimensionality reduction processing on each first word vector in the first target word vector sequence to obtain a second target word vector sequence, wherein the first target word vector sequence is any one of the multiple sample word vector sequences, and t is the number of iterations; Input the second target word vector sequence into the tensor network model M t The discriminant tensor network in obtains a first predicted label of a target text, wherein the target text is a text corresponding to the first target word vector sequence; The loss value L is calculated based on the multiple first predicted labels and the real labels corresponding to the multiple sample word vector sequences. t ; According to the loss value L t Adjust the tensor network model M t Parameters in to get the tensor network model M t+1 ; and according to the tensor network model M t+1 The third entanglement entropy is calculated by the parameters in; When the third entanglement entropy does not converge, set t=t+1, and repeat the above steps until the third entanglement entropy converges; when the third entanglement entropy converges, if the iterative training is the first round of iterative training, the target entanglement entropy is the third entanglement entropy; if the iterative training is the second round of iterative training, the text classification model is the tensor network model M t+1 ; Among them, when t=1, the tensor network model M t is the initial tensor network model.

18. The device according to claim 17, characterized in that The first target word vector sequence includes n first word vectors, wherein n is a positive integer, and the training unit is used to: Perform feature mapping on the n first word vectors respectively to obtain n first tensors, wherein the first tensor is a tensor representation of the first word vector; Using the tensor network model M t The r generative tensor networks in perform dimensionality reduction processing on each of the n first tensors to obtain the second target word vector sequence.

19. The device according to claim 18, characterized in that The tensor network model M t The r generative tensor networks in correspond to the r first weight parameters, and the training unit is used for: Perform the following operations on each of the n first tensors to obtain n second word vectors, wherein the n second word vectors correspond to the n first tensors: Perform tensor contraction operations on the r first weight parameters and the second tensor respectively, to obtain r tensor contraction operation results, wherein the second tensor is any first tensor among the n first tensors; Obtaining r target probability values ​​according to the r tensor contraction and union operation results, wherein the sum of the r target probability values ​​is 1; Obtain a second word vector according to the r target probability values; The n second word vectors constitute the second target word vector sequence.

20. The device according to claim 17, characterized in that The tensor network model M t The discriminant tensor network in includes n nodes, each of the first prediction labels includes n second prediction labels, and the n second prediction labels are respectively output by the n nodes, wherein n is a positive integer, and the training unit is used to: The following operations are performed on each of the multiple first prediction labels to obtain multiple cross entropy losses: Perform multiplication and accumulation calculations according to the n second prediction labels in the first target label and the second weight parameters corresponding to the n nodes to obtain a third prediction label, wherein the first target label is any one of the multiple first prediction labels; A cross entropy loss is calculated according to the third predicted label and the second target label, wherein the second target label is a true label corresponding to the fourth target word vector sequence, and the fourth target word vector sequence is a sample word vector sequence corresponding to the first target label; The loss value L is obtained by calculating the multiple cross entropy losses t .

21. The device according to claim 17, characterized in that The training unit is used to: For the tensor network model M t+1 The jth node and the j+1th node in the discriminant tensor network in the tensor are subjected to tensor contraction and merge operations to obtain the target node, where The n is the tensor network model M t+1 The number of nodes of the discriminant tensor network in , wherein n is a positive integer; Performing singular value decomposition on the target node to obtain k singular values, where k is a positive integer; The third entanglement entropy is calculated based on the k singular values.

22. A computer device, characterized in that: The method comprises a processor, a memory, a communication interface, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the processor, and the programs include instructions for executing the steps in the method according to any one of claims 1 to 7.

23. A chip, characterized in that: include: A processor, configured to call and run a computer program from a memory, so that a device equipped with the chip executes a method as claimed in any one of claims 1 to 7.

24. A computer-readable storage medium, characterized in that: It stores a computer program for electronic data exchange, wherein the computer program enables a computer to execute the method according to any one of claims 1 to 7.

25. A computer program product, the computer program product causing a computer to execute the method according to any one of claims 1 to 7.