WO2021027218A1 - 文本分类的方法、装置以及计算机可读介质 - Google Patents

文本分类的方法、装置以及计算机可读介质 Download PDF

Info

Publication number
WO2021027218A1
WO2021027218A1 PCT/CN2019/126947 CN2019126947W WO2021027218A1 WO 2021027218 A1 WO2021027218 A1 WO 2021027218A1 CN 2019126947 W CN2019126947 W CN 2019126947W WO 2021027218 A1 WO2021027218 A1 WO 2021027218A1
Authority
WO
WIPO (PCT)
Prior art keywords
text
sentence
matrix
feature
classification
Prior art date
Application number
PCT/CN2019/126947
Other languages
English (en)
French (fr)
Inventor
彭程
Original Assignee
北京国双科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 北京国双科技有限公司 filed Critical 北京国双科技有限公司
Publication of WO2021027218A1 publication Critical patent/WO2021027218A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/35Clustering; Classification
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/24Classification techniques
    • G06F18/241Classification techniques relating to the classification model, e.g. parametric or non-parametric approaches
    • G06F18/2411Classification techniques relating to the classification model, e.g. parametric or non-parametric approaches based on the proximity to a decision surface, e.g. support vector machines
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks

Definitions

  • the present invention relates to the technical field of classification prediction, in particular to a method, device and computer readable medium for text classification.
  • each sentence in the text usually have a certain order, and each sentence also has related characteristics with the surrounding sentences.
  • each sentence also has related characteristics with the surrounding sentences.
  • the existing text classification methods only the feature extraction of each sentence is considered separately, and the correlation characteristics of each sentence and surrounding sentences are not considered, resulting in a low accuracy of prediction classification.
  • the present invention provides a method, device, and computer readable medium for text classification that overcomes the above problems or at least partially solves the above problems, so as to extract the correlation between the feature vector of each sentence and the feature vector of other sentences.
  • a method, device, and computer readable medium for text classification that overcomes the above problems or at least partially solves the above problems, so as to extract the correlation between the feature vector of each sentence and the feature vector of other sentences.
  • the first aspect of the present invention discloses a method for text classification, including:
  • a feature matrix of the text is calculated; wherein the feature matrix of the text includes the feature vector of each sentence in the text;
  • the first associated feature matrix of the text is calculated; wherein, the first associated feature matrix of the text includes the first associated feature vector of each sentence in the text;
  • the first relevance feature vector of the sentence is used to describe the relevance between each sentence and other sentences in the text;
  • the classification prediction matrix of the text is calculated according to the first association feature matrix of the text; wherein the classification prediction matrix of the text includes the classification prediction vector of each sentence in the text; the classification of each sentence The prediction vector is used to describe the weight value of each sentence belonging to each preset label.
  • the calculating the first associated feature matrix of the text according to the feature matrix of the text includes:
  • the first associated feature matrix of the text is calculated according to the feature matrix of the text.
  • said calculating the classification prediction matrix of the text according to the first associated feature matrix of the text includes:
  • the classification prediction matrix of the text is calculated according to the first associated feature matrix of the text.
  • said calculating the feature matrix of the text according to the input text includes:
  • the words in each sentence in the text are converted into corresponding word vectors to obtain the original matrix of each sentence in the text; wherein, the original matrix of each sentence includes the The word vector corresponding to the word in each sentence;
  • the second correlation feature matrix of each sentence in the text is calculated according to the original matrix of each sentence in the text; wherein, the second correlation feature matrix of each sentence is Including the second correlation feature vector corresponding to the word in each sentence; the second correlation feature vector corresponding to each word is used to describe the correlation between each word and other words in the sentence;
  • the method further includes:
  • the prediction probability that each sentence in the text belongs to each preset label is calculated.
  • the method further includes:
  • the parameters of the model used in the text classification method are adjusted.
  • the second aspect of the present invention discloses a text classification device, including:
  • the obtaining unit is used to obtain the input text; wherein the text is composed of multiple sentences arranged in a specific order;
  • the first calculation unit is configured to calculate a feature matrix of the text according to the input text; wherein the feature matrix of the text includes the feature vector of each sentence in the text;
  • the second calculation unit is configured to calculate the first correlation feature matrix of the text according to the feature matrix of the text; wherein the first correlation feature matrix of the text includes the first correlation of each sentence in the text Feature vector; the first associated feature vector of each sentence is used to describe the relationship between each sentence and other sentences in the text;
  • the third calculation unit is configured to calculate the classification prediction matrix of the text according to the first association feature matrix of the text; wherein the classification prediction matrix of the text includes the classification prediction vector of each sentence in the text; The classification prediction vector of each sentence is used to describe the weight value of each sentence belonging to each preset label.
  • the second calculation unit includes:
  • the first calculation subunit is configured to calculate the first associated feature matrix of the text based on the bidirectional cyclic neural network model and the feature matrix of the text.
  • the third calculation unit includes:
  • the embedding unit is used to convert the words in each sentence in the text into corresponding word vectors according to the embedding matrix to obtain the original matrix of each sentence in the text; wherein The original matrix includes word vectors corresponding to words in each sentence;
  • the convolution unit is used to perform deep feature extraction on the mosaic matrix of each sentence in the text based on the convolutional neural network model using multiple convolution kernels to obtain multiple convolutions corresponding to each sentence in the text Feature vector;
  • the constituent unit is used for arranging in the specific order, and composing the feature vector of each sentence in the text into a feature matrix of the text.
  • the above text classification device it further includes:
  • the fourth calculation subunit is used to calculate the predicted probability that each sentence in the text belongs to each preset label according to the classification prediction matrix of the text.
  • the above text classification device it further includes:
  • the fifth calculation subunit is used to use cross entropy as a loss function to calculate the loss value between the predicted probability and the actual probability of each sentence in the text belonging to each preset label;
  • the adjustment unit is configured to adjust the parameters of the model used in the text classification method according to the loss value.
  • the third aspect of the present invention discloses a computer-readable medium on which a computer program is stored, wherein the program is executed by a processor to implement the method according to any one of the above-mentioned first aspects.
  • the input text is obtained, and then the feature matrix of the text is obtained according to the input text.
  • the feature matrix of the text includes the feature vector of each sentence in the text.
  • the first associated feature matrix of the text can be calculated.
  • the first associated feature matrix of the text includes the first associated feature vector of each sentence in the text.
  • the first correlation feature vector of each sentence is used to describe the correlation between each sentence and other sentences in the text.
  • the classification prediction matrix of the text is calculated.
  • the classification prediction matrix of the text includes the classification prediction vector of each sentence in the text.
  • the classification prediction vector of each sentence is used to describe the weight value of each sentence belonging to each preset label. Since this application considers the relevance of each sentence in the text to other sentences in the text when calculating the classification prediction matrix of the text, the accuracy of the text prediction classification is improved.
  • FIG. 1 is a schematic flowchart of a method for text classification disclosed in an embodiment of the present invention
  • FIG. 2 is a schematic flowchart of a method for calculating a feature matrix of a text disclosed in an embodiment of the present invention
  • FIG. 3 is a schematic diagram of the positional relationship between a convolution kernel and a sentence splicing matrix disclosed in an embodiment of the present invention
  • FIG. 4 is a schematic flowchart of a method for optimizing a model in a method for text classification disclosed in an embodiment of the present invention
  • Fig. 5 is a schematic structural diagram of a text classification device disclosed in an embodiment of the present invention.
  • the existing text classification method only considers the feature extraction of each sentence separately, and does not consider the correlation characteristics between each sentence and the surrounding sentences, resulting in a low accuracy of prediction classification.
  • a classification error such as marking the last sentence as a background label, which will affect the accuracy of subsequent processing , For example, unable to correctly identify the emotional orientation of the text and wrongly present the core content of the paper.
  • this application discloses a method, device and computer-readable medium for text classification.
  • an embodiment of the present application discloses a text classification method, which specifically includes the following steps:
  • the text is composed of multiple sentences arranged in a specific order.
  • the text input in step S101 may refer to a text sequence, and the specific order refers to an arrangement order, that is, the arrangement structure of the text sequence.
  • the input text contains three parts: title, body, and end. These three parts will be arranged in the order of title, body, and end, and the sentences of each part are also in order Arrange.
  • Each sentence in the text is composed of Chinese, English, characters, numbers and other characters.
  • the feature matrix of the text includes the feature vector of each sentence in the text.
  • the feature vector of each sentence is used to describe the feature information of each sentence.
  • the feature matrix of the text is an n ⁇ m matrix, that is, a matrix of n rows and m columns, consisting of n feature vectors of 1 ⁇ m sentences composition.
  • m is the length of the feature vector of each sentence, which can be specifically set according to the parameter value of the adjustment model.
  • step S102 feature extraction is performed on each sentence in the text, the feature information of the sentence is extracted from the semantics of the words in the sentence, and the feature vector of each sentence in the text is finally obtained, in a specific order Permutation and combination into a feature matrix of text.
  • the text input in step S101 includes a first sentence, a second sentence, and a third sentence in total.
  • the feature vector S1 of the first sentence is obtained.
  • the feature vector S2 of the second sentence is obtained.
  • feature vector of the third sentence is obtained.
  • an implementation manner of performing step S102 includes:
  • the original matrix of each sentence includes the word vector corresponding to the word in each sentence.
  • the embedding matrix contains word vectors corresponding to all words in the text, and the words in the sentence can be converted into word vectors through the embedding matrix.
  • Wn refers to the word vector corresponding to the nth word in the sentence.
  • the original matrix of each sentence contains the semantic feature information of the words in the sentence. It should be noted that, how many sentences are included in the text input in step S101 shown in FIG. 1, and how many original matrices of sentences will be obtained in step S201.
  • Bi-RNN can use its internal memory to process input sequences of arbitrary timing.
  • its current output will also be related to the previous output.
  • Bi-RNN will memorize the previous information, save it in the internal state of the network, and apply it to the calculation of the current output, that is, the nodes between the hidden layers are linked, and the input of the hidden layer includes not only the input
  • the output of the layer also contains the output of the hidden layer at the previous moment. Therefore, Bi-RNN can handle the relevance between words in a sentence.
  • the original matrix W of the sentence obtained in step S201 only the original semantic features of the words in the sentence can be explained, while the second associated feature matrix of the sentence obtained in step S202 can explain the association between the words in each sentence Sex.
  • Bi-RNNs that can be used in step S202, such as Bidirectional Long Short-Term Memory (Bi-LSTM) and Bidirectional Gated Recurrent Unit (Bi-GRU). Recurrent Unit) and so on.
  • Bi-LSTM Bidirectional Long Short-Term Memory
  • Bi-GRU Bidirectional Gated Recurrent Unit
  • S203 Concatenate the original matrix of each sentence in the text and the corresponding second associated feature matrix to obtain the concatenation matrix of each sentence in the text.
  • S204 Based on the convolutional neural network model, perform deep feature extraction on the splicing matrix of each sentence in the text by using multiple convolution kernels to obtain multiple convolution feature vectors corresponding to each sentence in the text.
  • the convolutional layer in the convolutional neural network model (Convolutional Neural Networks, CNN) is composed of multiple convolution kernels, and the number of columns of the convolution kernel is the same as that of the sentence mosaic matrix. If the mosaic matrix of the sentence obtained in step S203 is a matrix of n ⁇ (m+1), then the window size of the convolution kernel is k ⁇ (m+1), where k is a number smaller than n. For a specific example, referring to FIG. 3, one sentence in the text is composed of 8 words, and the concatenation matrix 302 of the sentence is 8 ⁇ 4 in size.
  • a matrix 301 with a convolution kernel size of 3 ⁇ 4 can be used.
  • the convolution kernel 301 performs deep feature extraction for the feature combination in this range of the splicing matrix 302 to obtain deep feature information.
  • other convolution kernels of different sizes can also be used to perform deep feature extraction on the splicing matrix of the sentence. For example, for the splicing matrix 302 shown in FIG. 3, a convolution kernel of 4 ⁇ 4 size, 2 ⁇ 4 The large and small convolution kernel performs deep feature extraction.
  • the value of each element in the convolution kernel can be obtained through pre-training, and the value of each element in the convolution kernel is corrected according to the deviation between the final classification result and the actual classification, and the final result is high in reliability.
  • the convolution kernel can be obtained through pre-training, and the value of each element in the convolution kernel is corrected according to the deviation between the final classification result and the actual classification, and the final result is high in reliability.
  • the 8 ⁇ 4 mosaic matrix shown in FIG. 3 is calculated according to the following formula.
  • K j is the convolution kernel 301
  • t is the number of words in the convolution area (that is, the number of rows of the convolution kernel)
  • b j is the bias term
  • r i:i+t-1 is the sentence mosaic matrix 302
  • the matrix of the area covered by the convolution kernel 301, ⁇ is the activation function.
  • Fig. 3 shows that after the convolution kernel K j is aligned with the first row of the splicing matrix 302, the elements in the convolution kernel 301 are multiplied with the corresponding elements in the splicing matrix 302, that is, one row and one column in the convolution kernel 301 The elements are multiplied by the elements of one row and one column in the splicing matrix 302, and the elements of one row and two columns in the convolution kernel 301 are spliced and multiplied by the elements of one row and two columns in the splicing matrix 302. In this way, in the embodiment shown in FIG.
  • bias term b j is obtained through pre-training, and the value of the bias term b j is corrected according to the deviation between the final classification result and the actual classification, and the bias term b with higher reliability is finally obtained. j .
  • S205 Perform maximum pooling operation processing on the multiple convolution feature vectors corresponding to each sentence to obtain the feature vector of each sentence.
  • the multiple convolution feature vectors corresponding to each sentence obtained in step S204 are respectively extracted from the element with the largest value as the result of the processing of this convolution feature vector.
  • the processing results of all the convolution feature vectors are determined by each
  • the relative position relationship between the convolution feature vectors is arranged to form a new vector, which is the feature vector of each sentence.
  • a convolution feature vector C 1 ⁇ C 1 , C 2 , C 3 , C 4 , C 5 , C 6 ⁇ .
  • the element with the largest value is extracted from the convolution feature vector C 1 as the result of the maximum pooling operation of the convolution feature vector C 1 .
  • the element with the maximum value will be extracted from the corresponding convolution feature vector.
  • 5 convolution kernels 5 elements will be selected and arranged according to the relative position relationship to form a feature vector of a sentence with a size of 1 ⁇ 5.
  • Each sentence in the text will get the same size feature vector after the above conversion.
  • steps S204 and S205 may be directly performed on the original matrix of the sentence obtained in step S201 or the second relevance feature matrix of the sentence obtained in step S202.
  • the feature vector of the sentence calculated by using the sentence splicing matrix in step S203 not only contains the original semantic features of the words in the sentence, but also contains the features of the relevance between the words in the sentence, so the resulting feature vector of the sentence If used for classification prediction, the accuracy will be higher.
  • S206 Arrange according to a specific order, and compose the feature vector of each sentence in the text into a feature matrix of the text.
  • the first associated feature matrix of the text includes the first associated feature vector of each sentence in the text.
  • the first correlation feature vector of each sentence is used to describe the correlation between each sentence and other sentences in the text.
  • the feature vector Sp of the p-th sentence in the feature matrix S of the text can only describe the feature information of the p-th sentence itself, while the first associated feature of the p-th sentence in the first associated feature matrix H of the text
  • the vector Hp can combine the features of sentences other than the Pth sentence to illustrate the feature information of the Pth sentence.
  • an implementation manner of performing step S103 includes:
  • the first associated feature matrix of the text is calculated according to the feature matrix of the text.
  • Bi-RNN can use its internal memory to process input sequences of arbitrary timing.
  • a sequence is input into Bi-RNN, its current output will also be related to the previous output.
  • Bi-RNN will memorize the previous information, save it in the internal state of the network, and apply it to the calculation of the current output, that is, the nodes between the hidden layers are linked, and the input of the hidden layer includes not only the input
  • the output of the layer also contains the output of the hidden layer at the previous moment. Therefore, Bi-RNN can handle the relevance between sentences in the text. Inputting the feature matrix of the text obtained in step S102 into the Bi-RNN, the first relevance feature matrix of the text that can explain the relevance between sentences can be obtained.
  • the feature matrix of the text before inputting the feature matrix of the text into the Bi-RNN, can also be input into the CNN first, and then input into the Bi-RNN after the convolution operation.
  • the feature matrix of the text can also be input into the CNN first, and then input into the Bi-RNN after the convolution operation.
  • Bi-RNNs that can be used in step S103, such as Bidirectional Long Short-Term Memory (Bi-LSTM, Bidirectional Long-Term Memory), and Bidirectional Gated Recurrent Unit (Bi-GRU). Unit) and so on.
  • Bi-LSTM Bidirectional Long Short-Term Memory
  • Bi-GRU Bidirectional Gated Recurrent Unit
  • S104 Calculate the classification prediction matrix of the text according to the first associated feature matrix of the text.
  • the classification prediction matrix of the text includes the classification prediction vector of each sentence in the text.
  • the classification prediction vector of each sentence is used to describe the weight value of each sentence belonging to each preset label.
  • the classification prediction matrix y ⁇ y1, y2,..., yp ⁇ .
  • yp represents the classification prediction vector of the p-th sentence.
  • the length of the yp vector is the same as the number of preset classification labels.
  • an implementation manner of performing step S104 includes:
  • the classification prediction matrix of the text is calculated according to the first correlation feature matrix of the text.
  • the first relevance feature matrix of the text obtained in step S103 is input into the CNN, and the first relevance feature matrix is converted into a real number matrix through the convolution layer of the CNN and output to obtain the classification prediction matrix of the text.
  • classification tags of sentences in the text can be customized.
  • the sentences in the text can be divided into categories such as main text, headings, and endings, or they can be classified according to the different functions of the sentences in the text.
  • step S104 after step S104 is performed, the method further includes:
  • the predicted probability of each sentence in the text belonging to each preset label is calculated.
  • the classification prediction vector of each sentence describes the absolute weight value of the sentence belonging to each classification label.
  • p i identifies the predicted probability of the tag of the sentence belonging to the i-th category; C refers to the total number of tags; y i refers to the weight value of the tag of the sentence belonging to the i-th category.
  • the label with the largest predicted probability value is selected as the classification label of the sentence to realize the classification of the text.
  • the classification prediction matrix of the text can also be input into the Conditional Random Field (CRF) algorithm, and the category to which each sentence belongs is finally output .
  • CRF Conditional Random Field
  • the label with the largest weight value can be directly selected from the classification prediction vector of each sentence as the category label to which the sentence belongs. But this method only considers the local optimal solution for the sentence, but does not consider the overall optimal solution.
  • the conversion matrix used in the CRF algorithm introduces the probability that when the sentence belongs to the i tag, the next sentence of the sentence belongs to the j tag, so an output result with the best overall probability can be obtained, avoiding unreasonable labeling. . For example, it is obviously unreasonable to mark the third sentence as the body tag and four sentences as the title tag. This situation can be avoided by using the CRF algorithm.
  • the method further includes:
  • Loss is the loss value of text classification
  • Is the actual probability that the sentence belongs to the i-th category label
  • p i (a) is the predicted probability that the sentence belongs to the i-th category label
  • a represents the text
  • D represents the training data
  • C represents the total number of category labels.
  • the parameters of the model used in the method for adjusting text classification refer to the parameters in the Bi-RNN model and the CNN model mentioned in the foregoing embodiment.
  • the input text is obtained, and then the feature matrix of the text is obtained according to the input text.
  • the feature matrix of the text includes the feature vector of each sentence in the text.
  • the first associated feature matrix of the text can be calculated.
  • the first associated feature matrix of the text includes the first associated feature vector of each sentence in the text.
  • the first relevance feature vector of each sentence is used to illustrate the relevance between each sentence and other sentences in the text.
  • the classification prediction matrix of the text is calculated.
  • the classification prediction matrix of the text includes the classification prediction vector of each sentence in the text.
  • the classification prediction vector of each sentence is used to describe the weight value of each sentence belonging to each preset label. Since this application considers the relevance of each sentence in the text to other sentences in the text when calculating the classification prediction matrix of the text, the accuracy of the text prediction classification is improved.
  • the embodiment of the application also correspondingly discloses a text classification apparatus 500, including: an acquisition unit 501, a first calculation unit 502, and a second calculation unit 503 And the third calculation unit 504.
  • the obtaining unit 501 is used to obtain input text.
  • the text is composed of multiple sentences arranged in a specific order.
  • the first calculation unit 502 is configured to calculate the feature matrix of the text according to the input text.
  • the feature matrix of the text includes the feature vector of each sentence in the text.
  • the first calculation unit 502 includes: an embedding unit, a third calculation sub-unit, a splicing unit, a convolution unit, a maximum pooling unit, and a constituent unit.
  • the embedding unit is used to convert the words in each sentence in the text into corresponding word vectors according to the embedding matrix to obtain the original matrix of each sentence in the text.
  • the original matrix of each sentence includes the word vector corresponding to the word in each sentence.
  • the third calculation subunit is used to calculate the second correlation feature matrix of each sentence in the text based on the bidirectional cyclic neural network model and the original matrix of each sentence in the text.
  • the second correlation feature matrix of each sentence includes the second correlation feature vector corresponding to the word in each sentence.
  • the second correlation feature vector corresponding to each word is used to illustrate the correlation between each word and other words in the sentence.
  • the splicing unit is used for splicing the original matrix of each sentence in the text and the corresponding second associated feature matrix to obtain the splicing matrix of each sentence in the text.
  • the convolution unit is used to perform deep feature extraction on the splicing matrix of each sentence in the text based on the convolutional neural network model, and obtain multiple convolution feature vectors corresponding to each sentence in the text.
  • the maximum pooling unit is used to perform maximum pooling operation processing on multiple convolution feature vectors corresponding to each sentence to obtain the feature vector of each sentence.
  • the constituent unit is used for arranging in a specific order and composing the feature vector of each sentence in the text into a feature matrix of the text.
  • the second calculation unit 503 is configured to calculate the first associated feature matrix of the text according to the feature matrix of the text.
  • the first associated feature matrix of the text includes the first associated feature vector of each sentence in the text.
  • the first correlation feature vector of each sentence is used to describe the correlation between each sentence and other sentences in the text.
  • the second calculation unit 503 includes:
  • the first calculation subunit is configured to calculate the first associated feature matrix of the text based on the bidirectional cyclic neural network model and the feature matrix of the text.
  • the third calculation unit 504 includes:
  • the second calculation subunit is used to calculate the classification prediction matrix of the text based on the convolutional neural network model and the first correlation feature matrix of the text.
  • the fourth calculation subunit is used to calculate the predicted probability that each sentence in the text belongs to each preset label according to the classification prediction matrix of the text.
  • the adjustment unit is used to adjust the parameters of the model used in the text classification method according to the loss value.
  • the input text is obtained through the obtaining unit 501, and then the first calculation unit 502 obtains the feature matrix of the text according to the input text.
  • the feature matrix of the text includes the feature vector of each sentence in the text.
  • the second calculation unit 503 can calculate the first associated feature matrix of the text according to the feature matrix of the text.
  • the first associated feature matrix of the text includes the first associated feature vector of each sentence in the text.
  • the first correlation feature vector of each sentence is used to describe the correlation between each sentence and other sentences in the text.
  • the third calculation unit 504 calculates the classification prediction matrix of the text according to the first associated feature matrix of the text. Among them, the classification prediction matrix of the text includes the classification prediction vector of each sentence in the text.
  • the classification prediction vector of each sentence is used to describe the weight value of each sentence belonging to each preset label. Since this application considers the relevance of each sentence in the text to other sentences in the text when calculating the classification prediction matrix of the text, the accuracy of the text prediction classification is improved.
  • the processor contains the kernel, which calls the corresponding program unit from the memory.
  • One or more kernels can be set, and the accuracy of text prediction and classification can be improved by adjusting kernel parameters.
  • the memory may include non-permanent memory in computer-readable media, random access memory (RAM) and/or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM), and the memory includes at least one Memory chip.
  • RAM random access memory
  • ROM read-only memory
  • flash RAM flash random access memory
  • the embodiment of the present invention provides a storage medium on which a program is stored, and the method for implementing the text classification when the program is executed by a processor.
  • the embodiment of the present invention provides a processor configured to run a program, wherein the method for text classification is executed when the program is running.
  • the embodiment of the present invention provides a device.
  • the device includes a processor, a memory, and a program stored on the memory and running on the processor, and the processor implements the following steps when the program is executed:
  • a feature matrix of the text is calculated; wherein the feature matrix of the text includes the feature vector of each sentence in the text;
  • the first associated feature matrix of the text is calculated; wherein, the first associated feature matrix of the text includes the first associated feature vector of each sentence in the text;
  • the first relevance feature vector of the sentence is used to describe the relevance between each sentence and other sentences in the text;
  • the classification prediction matrix of the text is calculated according to the first association feature matrix of the text; wherein the classification prediction matrix of the text includes the classification prediction vector of each sentence in the text; the classification of each sentence The prediction vector is used to describe the weight value of each sentence belonging to each preset label.
  • the calculating the first associated feature matrix of the text according to the feature matrix of the text includes:
  • the first associated feature matrix of the text is calculated according to the feature matrix of the text.
  • the classification prediction matrix of the text is calculated according to the first associated feature matrix of the text.
  • said calculating the feature matrix of the text according to the input text includes:
  • the words in each sentence in the text are converted into corresponding word vectors to obtain the original matrix of each sentence in the text; wherein, the original matrix of each sentence includes the The word vector corresponding to the word in each sentence;
  • the second correlation feature matrix of each sentence in the text is calculated according to the original matrix of each sentence in the text; wherein, the second correlation feature matrix of each sentence is Including the second correlation feature vector corresponding to the word in each sentence; the second correlation feature vector corresponding to each word is used to describe the correlation between each word and other words in the sentence;
  • the method further includes:
  • the prediction probability of each sentence in the text belonging to each preset label is calculated.
  • the method further includes:
  • the model used in the text classification method is adjusted.
  • the devices in this article can be servers, PCs, etc.
  • This application also provides a computer program product, which when executed on a data processing device, is suitable for executing a program that initializes the following method steps:
  • a feature matrix of the text is calculated; wherein the feature matrix of the text includes the feature vector of each sentence in the text;
  • the classification prediction matrix of the text is calculated according to the first association feature matrix of the text; wherein the classification prediction matrix of the text includes the classification prediction vector of each sentence in the text; the classification of each sentence The prediction vector is used to describe the weight value of each sentence belonging to each preset label.
  • the calculating the first associated feature matrix of the text according to the feature matrix of the text includes:
  • the first associated feature matrix of the text is calculated according to the feature matrix of the text.
  • said calculating the classification prediction matrix of the text according to the first associated feature matrix of the text includes:
  • the classification prediction matrix of the text is calculated according to the first associated feature matrix of the text.
  • said calculating the feature matrix of the text according to the input text includes:
  • the second correlation feature matrix of each sentence in the text is calculated according to the original matrix of each sentence in the text; wherein, the second correlation feature matrix of each sentence is Including the second correlation feature vector corresponding to the word in each sentence; the second correlation feature vector corresponding to each word is used to describe the correlation between each word and other words in the sentence;
  • the method further includes:
  • the prediction probability that each sentence in the text belongs to each preset label is calculated.
  • the method further includes:
  • the parameters of the model used in the text classification method are adjusted.
  • the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, this application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
  • a computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.
  • These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing equipment to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction device.
  • the device implements the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
  • These computer program instructions can also be loaded on a computer or other programmable data processing equipment, so that a series of operation steps are executed on the computer or other programmable equipment to produce computer-implemented processing, so as to execute on the computer or other programmable equipment.
  • the instructions provide steps for implementing functions specified in a flow or multiple flows in the flowchart and/or a block or multiple blocks in the block diagram.
  • the computing device includes one or more processors (CPU), input/output interfaces, network interfaces, and memory.
  • processors CPU
  • input/output interfaces network interfaces
  • memory volatile and non-volatile memory
  • the memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and/or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM).
  • RAM random access memory
  • ROM read-only memory
  • flash RAM flash memory
  • Computer-readable media include permanent and non-permanent, removable and non-removable media, and information storage can be realized by any method or technology.
  • the information can be computer-readable instructions, data structures, program modules, or other data.
  • Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, CD-ROM, digital versatile disc (DVD) or other optical storage, Magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media can be used to store information that can be accessed by computing devices. According to the definition in this article, computer-readable media does not include transitory media, such as modulated data signals and carrier waves.
  • this application can be provided as methods, systems, or computer program products. Therefore, this application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, this application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
  • computer-usable storage media including but not limited to disk storage, CD-ROM, optical storage, etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Evolutionary Computation (AREA)
  • Molecular Biology (AREA)
  • Computational Linguistics (AREA)
  • Databases & Information Systems (AREA)
  • Software Systems (AREA)
  • Health & Medical Sciences (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Mathematical Physics (AREA)
  • General Health & Medical Sciences (AREA)
  • Computing Systems (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Evolutionary Biology (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种文本分类的方法、装置以及计算机可读介质,通过获取输入的文本(S101);根据输入的文本,计算得到文本的特征矩阵(S102);根据文本的特征矩阵,计算得到文本的第一关联特征矩阵(S103);文本的第一关联特征矩阵包括文本中每一个句子的第一关联特征向量;第一关联特征向量用于说明每一个句子与文本中的其他句子间的关联性;根据文本的第一关联特征矩阵,计算得到文本的分类预测矩阵(S104);其中,文本的分类预测矩阵包括文本中每一个句子的分类预测向量;分类预测向量用于说明每一个句子属于每一个预设标签的权重值。该方法在计算文本的分类预测矩阵时,考虑到文本中的每一个句子与文本中其他句子的关联性,因此提高了文本预测分类的准确度。

Description

文本分类的方法、装置以及计算机可读介质
本申请要求于2019年08月12日提交中国专利局、申请号为201910741430.1、发明名称为“文本分类的方法、装置以及计算机可读介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本发明涉及分类预测技术领域,尤其涉及一种文本分类的方法、装置以及计算机可读介质。
背景技术
文本分类是一种按照预定义的标签,对文本中的语句进行自动分类的技术,广泛应用于涉及自然语言处理的领域中。现有的文本分类的方法大多采用朴素贝叶斯、支持向量机、非线性深度神经网络等模型进行文本分类。
然而,文本中的句子通常都具有一定的顺序,每一个句子与周围句子间也具有相关特性。而现有的文本分类方法中,只考虑了对每一个句子单独进行特征提取,没有考虑到每一个句子与周围句子的相关性特征,造成预测分类的准确度并不高。
发明内容
鉴于上述问题,本发明提供一种克服上述问题或者至少部分地解决上述问题的文本分类的方法、装置以及计算机可读介质,以通过提取每一个句子的特征向量与其他句子的特征向量间的关联特征,提高文本预测分类的准确度。
本发明第一方面公开了一种文本分类的方法,包括:
获取输入的文本;其中,所述文本由多个句子按照特定的顺序排列构成;
根据所述输入的文本,计算得到文本的特征矩阵;其中,所述文本的特征矩阵包括所述文本中每一个句子的特征向量;
根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵;其中,所述文本的第一关联特征矩阵包括所述文本中每一个句子的第一关 联特征向量;所述每一个句子的第一关联特征向量用于说明所述每一个句子与所述文本中的其他句子间的关联性;
根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵;其中,所述文本的分类预测矩阵包括所述文本中每一个句子的分类预测向量;所述每一个句子的分类预测向量用于说明所述每一个句子属于每一个预设标签的权重值。
可选地,在上述文本分类的方法中,所述根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵,包括:
基于双向循环神经网络模型,根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵。
可选地,在上述文本分类的方法中,所述根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵,包括:
基于卷积神经网络模型,根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵。
可选地,在上述文本分类的方法中,所述根据所述输入的文本,计算得到文本的特征矩阵,包括:
根据嵌入矩阵,将所述文本中的每一个句子中的单词转换成相对应的单词向量,得到所述文本中的每一个句子的原始矩阵;其中,所述每一个句子的原始矩阵包括所述每一个句子中的单词对应的单词向量;
基于双向循环神经网络模型,根据所述文本中的每一个句子的原始矩阵,计算得到所述文本中的每一个句子的第二关联特征矩阵;其中,所述每一个句子的第二关联特征矩阵包括所述每一个句子中的单词对应的第二关联特征向量;每一个单词对应的第二关联特征向量用于说明所述每一个单词与句子中的其他单词的关联性;
拼接所述文本中的每一个句子的原始矩阵以及对应的所述第二关联特征矩阵,得到所述文本中的每一个句子的拼接矩阵;
基于卷积神经网络模型,利用多个卷积核对所述文本中的每一个句子的拼接矩阵进行深层特征提取,得到所述文本中的每一个句子对应的多个卷积特征向量;
对所述每一个句子对应的多个卷积特征向量分别进行最大池化操作处理,得到所述每一个句子的特征向量;
按照所述特定的顺序排列,将所述文本中每一个句子的特征向量组成所述文本的特征矩阵。
可选地,在上述文本分类的方法中,所述根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵之后,还包括:
根据所述文本的分类预测矩阵,计算出所述文本中的每一个句子属于每一个预设标签的预测概率。
可选地,在上述文本分类的方法中,所述根据所述文本的分类预测矩阵,计算出所述文本中的每一个句子属于每一个预设标签的预测概率之后,还包括:
使用交叉熵作为损失函数,计算所述文本中的每一个句子属于每一个预设标签的预测概率与实际概率间的损失值;
根据所述损失值,调整所述文本分类的方法中使用的模型的参数。
本发明第二方面公开了一种文本分类的装置,包括:
获取单元,用于获取输入的文本;其中,所述文本由多个句子按照特定的顺序排列构成;
第一计算单元,用于根据所述输入的文本,计算得到文本的特征矩阵;其中,所述文本的特征矩阵包括所述文本中每一个句子的特征向量;
第二计算单元,用于根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵;其中,所述文本的第一关联特征矩阵包括所述文本中每一个句子的第一关联特征向量;所述每一个句子的第一关联特征向量用于说明所述每一个句子与所述文本中的其他句子间的关联性;
第三计算单元,用于根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵;其中,所述文本的分类预测矩阵包括所述文本中每一个句子的分类预测向量;所述每一个句子的分类预测向量用于说明所述每一个句子属于每一个预设标签的权重值。
可选地,在上述文本分类的装置中,所述第二计算单元,包括:
第一计算子单元,用于基于双向循环神经网络模型,根据所述文本的 特征矩阵,计算得到所述文本的第一关联特征矩阵。
可选地,在上述文本分类的装置中,所述第三计算单元,包括:
第二计算子单元,用于基于卷积神经网络模型,根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵。
可选地,在上述文本分类的装置中,所述第一计算单元,包括:
嵌入单元,用于根据嵌入矩阵,将所述文本中的每一个句子中的单词转换成相对应的单词向量,得到所述文本中的每一个句子的原始矩阵;其中,所述每一个句子的原始矩阵包括所述每一个句子中的单词对应的单词向量;
第三计算子单元,用于基于双向循环神经网络模型,根据所述文本中的每一个句子的原始矩阵,计算得到所述文本中的每一个句子的第二关联特征矩阵;其中,所述每一个句子的第二关联特征矩阵包括所述每一个句子中的单词对应的第二关联特征向量;每一个单词对应的第二关联特征向量用于说明所述每一个单词与句子中的其他单词的关联性;
拼接单元,用于拼接所述文本中的每一个句子的原始矩阵以及对应的所述第二关联特征矩阵,得到所述文本中的每一个句子的拼接矩阵;
卷积单元,用于基于卷积神经网络模型,利用多个卷积核对所述文本中的每一个句子的拼接矩阵进行深层特征提取,得到所述文本中的每一个句子对应的多个卷积特征向量;
最大池化单元,用于对所述每一个句子对应的多个卷积特征向量分别进行最大池化操作处理,得到所述每一个句子的特征向量;
组成单元,用于按照所述特定的顺序排列,将所述文本中每一个句子的特征向量组成所述文本的特征矩阵。
可选地,在上述文本分类的装置中,还包括:
第四计算子单元,用于根据所述文本的分类预测矩阵,计算出所述文本中的每一个句子属于每一个预设标签的预测概率。
可选地,在上述文本分类的装置中,还包括:
第五计算子单元,用于使用交叉熵作为损失函数,计算所述文本中的每一个句子属于每一个预设标签的预测概率与实际概率间的损失值;
调整单元,用于根据所述损失值,调整所述文本分类的方法中使用的模型的参数。
本发明第三方面公开了一种计算机可读介质,其上存储有计算机程序,其中,所述程序被处理器执行时实现如上述第一方面中任一所述的方法。
从上述技术方案可以看出,本申请实施例提出的文本分类的方法中,通过获取输入的文本,再根据输入的文本,得到文本的特征矩阵。其中,文本的特征矩阵包括文本中每一个句子的特征向量。根据文本的特征矩阵,可计算得到文本的第一关联特征矩阵。其中,文本的第一关联特征矩阵包括文本中每一个句子的第一关联特征向量。每一个句子的第一关联特征向量用于说明每一个句子与文本中的其他句子间的关联性。根据文本的第一关联特征矩阵,计算得到文本的分类预测矩阵。其中,文本的分类预测矩阵包括文本中每一个句子的分类预测向量。其中,每一个句子的分类预测向量用于说明每一个句子属于每一个预设标签的权重值。由于本申请在计算文本的分类预测矩阵时,考虑到了文本中的每一个句子与文本中其他句子的关联性,因此提高了文本预测分类的准确度。
上述说明仅是本发明技术方案的概述,为了能够更清楚了解本发明的技术手段,而可依照说明书的内容予以实施,并且为了让本发明的上述和其它目的、特征和优点能够更明显易懂,以下特举本发明的具体实施方式。
附图说明
通过阅读下文优选实施方式的详细描述,各种其他的优点和益处对于本领域普通技术人员将变得清楚明了。附图仅用于示出优选实施方式的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的参考符号表示相同的部件。在附图中:
图1为本发明实施例公开的一种文本分类的方法的流程示意图;
图2为本发明实施例公开的一种计算文本的特征矩阵的方法的流程示意图;
图3为本发明实施例公开的一种卷积核和句子的拼接矩阵的位置关系示意图;
图4为本发明实施例公开的一种优化文本分类的方法中的模型的方法 的流程示意图;
图5为本发明实施例公开的一种文本分类的装置的结构示意图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
目前,在很多场景中都需要对文本的内容进行分类,这些文本可能是来源于网络抓取,也可能是之前收录的。例如,在对从网络爬取的文本进行分析之前,要通过文本分类来确定文本的标题、正文、以及评论等部分,之后才能对不同的部分采用不同的方式进行分析,例如,确定标题和正文所涉及的对象、确定评论的情感倾向;再比如,一些论文网站为了便于用户能够快速了解到论文的核心内容,会对收集的论文进行文本分类处理,将每一篇论文的摘要文本中的句子,分成目标、背景、方法、结果和总结五类标签,并将论文的摘要文本按照分类标签呈现在网页上,以供用户阅读。用户通过分类后的摘要文本能够快速直观的了解到论文的核心内容。
然而,现有的文本分类方法只考虑了对每一个句子单独进行特征提取,没有考虑到每一个句子与周围句子的相关性特征,造成预测分类的准确度并不高。例如,对论文的摘要文本进行分类时,由于没有考虑到其中一个句子与周围句子的相关性,可能会出现将最后一个句子标记成背景标签这样的分类错误的情况,进而影响后续处理的准确性,例如,无法正确识别文本的感情倾向,错误地展示论文的核心内容。
针对上述问题,本申请公开了一种文本分类的方法、装置以及计算机可读介质。
参阅图1,本申请实施例公开了一种文本分类方法,具体包括以下步骤:
S101、获取输入的文本。
其中,文本由多个句子按照特定的顺序排列构成。步骤S101输入的文 本可以是指文本序列,特定的顺序指的是一种排列顺序,即文本序列的排列结构。例如,输入的文本中包含有标题、正文以及结尾三个部分,这三个部分会按照先标题,然后到正文,最后是结尾的这一排列顺序进行排列,且每一个部分的句子也按照顺序进行排列。文本中的每一个句子由中文、英文、字符、数字等多种字符组合而成。执行步骤S101时,除了获取输入文本的字符信息外,还获取了输入的文本中的句子的排列顺序以及每一个句子中的单词的排列顺序信息。获取的输入的文本可以以句子为单位进行划分,以便后续分别对文本中每一个句子进行处理。
S102、根据输入的文本,计算得到文本的特征矩阵。
其中,文本的特征矩阵包括文本中每一个句子的特征向量。每一个句子的特征向量用于说明每一个句子的特征信息。例如,步骤S101中获取的输入文本中总共有n个句子,则文本的特征矩阵就是一个n×m的矩阵,即是一个n行m列的矩阵,由n个1×m的句子的特征向量组成。其中,m是每一个句子的特征向量的长度,具体可根据调整模型的参数值进行设定。
具体的,执行步骤S102时,分别对文本中的每一个句子进行特征提取,从句子中的单词的语义中提取到句子的特征信息,最终得到文本中每一个句子的特征向量,又按照特定顺序排列组合成文本的特征矩阵。例如,步骤S101中输入的文本一共包含有第一句子、第二句子以及第三句子。对第一句子进行特征提取后,得到第一句子的特征向量S1,对第二句子进行特征提取后,得到第二句子的特征向量S2,对第三句子进行特征提取后,得到第三句子的特征向量S3,并按照文本中本身句子的排序,将S1、S2以及S3进行组合,得到文本的特征矩阵S={S1,S2,S3}。
可选地,参阅图2,在本申请一具体实施例中,执行步骤S102的一种实施方式,包括:
S201、根据嵌入矩阵,将文本中的每一个句子中的单词转换成相对应的单词向量,得到文本中的每一个句子的原始矩阵。
其中,每一个句子的原始矩阵包括每一个句子中的单词对应的单词向量。而嵌入矩阵中包含有文本中所有的单词对应的单词向量,通过嵌入矩阵可将句子中的单词转换成单词向量来表示。
具体的,创建一个词汇表,词汇表中包含了多个可能会在文本中出现的单词,并按照顺序给每一个单词编号。可选地,可以采用离散的独热码给词汇表中的单词编号。然后再通过训练,将单词从离散的独热码表示映射到低维空间中的密集实值向量,即变成单词向量。并将词汇表中的单词所对应的单词向量全部堆叠在嵌入矩阵中。若词汇表中有n个单词,则嵌入矩阵为n×m的矩阵,其中m为单词向量的维度。执行步骤S201时,先是将文本中的每一个句子用单词的标识信息表示。根据单词的标识信息可以找到该单词在嵌入矩阵中的位置,进而可从嵌入矩阵中找到该单词对应的单词向量,并将该句子用单词向量进行表示,得到每一个句子的原始矩阵W={W1,W2,...,Wn}。其中,Wn指的是该句子中的第n个单词对应的单词向量。每一个句子的原始矩阵中都包含有句子中的单词的语义特征信息。需要说明的是,图1示出的步骤S101中输入的文本包含了多少个句子,步骤S201中就会得到多少个句子的原始矩阵。
S202、基于双向循环神经网络模型,根据文本中的每一个句子的原始矩阵,计算得到文本中的每一个句子的第二关联特征矩阵。
其中,每一个句子的第二关联特征矩阵包括每一个句子中的单词对应的第二关联特征向量。每一个单词对应的第二关联特征向量用于说明每一个单词与句子中的其他单词的关联性。例如,文本中的其中一个句子由n个单词组成,步骤S201得到的该句子的原始矩阵W={W1,W2,...,Wn},将该句子的原始矩阵W输入至双向循环神经网络模型(Bidirectional Recurrent Neural Networks,Bi-RNN)中,从Bi-RNN中输出该句子的第二关联特征矩阵h={h1,h2,...,hn}。其中,hn为该句子第n个单词对应的第二关联特征向量,用于说明第n个单词与句子中其他单词的关联性。
Bi-RNN可以利用它内部的记忆来处理任意时序的输入序列。一个序列输入至Bi-RNN中,它当前的输出也会与之前的输出也有关。Bi-RNN会对前面的信息进行记忆,保存在网络的内部状态中,并应用于当前输出的计算中,即隐含层之间的节点是有链接的,并且隐含层的输入不仅包含输入层的输出还包含上一时刻隐含层的输出。因此,通过Bi-RNN可以处理句子中的单词间的关联性。步骤S201中得到的句子的原始矩阵W中,仅能说明 句子中的单词的原始语义特征,而步骤S202得到的句子的第二关联特征矩阵,可说明了每一个句子中的单词之间的关联性。例如,对于文本中的一句“今天有火箭队的比赛”,单看句子中的“火箭”这个单词,可能会解释为一种飞行器,而联系后边的“队”这个单词,以及“比赛”这个单词,就可以得出“火箭”是指的球队名。需要说明的是,图1示出的步骤S101中输入的文本包含了多少个句子,步骤S202中就会得到多少个句子的第二关联特征矩阵。
还需要说明的是,步骤S202中可以使用的Bi-RNN的种类很多,例如双向长短期记忆神经网络(Bi-LSTM,Bidirectional Long Short-Term Memory)、双向门循环单元(Bi-GRU,Bidirectional Gated Recurrent Unit)等。
S203、拼接文本中的每一个句子的原始矩阵以及对应的第二关联特征矩阵,得到文本中的每一个句子的拼接矩阵。
将步骤S201中的每一个句子的原始矩阵以及对应的第二关联特征矩阵进行拼接,得到每一个句子的拼接矩阵。例如,文本中的其中一个句子含有n个单词,该句子从步骤S201中得到的原始矩阵为一个n×m矩阵,而该句子从步骤S202中得到的第二关联特征矩阵为一个n×l的矩阵,则拼接后的该句子的拼接矩阵为n×(m+l)的矩阵。文本中每一个句子的拼接矩阵既融合了句子原本单词的语义特征信息,又融合了句子中的单词间的关联性特征信息。
S204、基于卷积神经网络模型,利用多个卷积核对文本中的每一个句子的拼接矩阵进行深层特征提取,得到文本中的每一个句子对应的多个卷积特征向量。
其中,深层特征是相较于浅层特征而言,对分类来说更为重要的特征。卷积神经网络模型(Convolutional Neural Networks,CNN)中的卷积层由多个卷积核组成,卷积核的列数与句子的拼接矩阵的列数相同。若步骤S203中得到的句子的拼接矩阵为n×(m+l)的矩阵,那么卷积核的窗口大小就为k×(m+l),其中k为小于n的数。具体举例说明,参阅图3,文本中的其中一个句子由8个单词构成,该句子的拼接矩阵302为8×4的大小。对该句子 的拼接矩阵302进行深层特征提取时,则可采用卷积核的大小为3×4的矩阵301。卷积核301针对拼接矩阵302的这一范围内的特征组合进行深一层的特征提取,得到深层特征信息。可选地,还可以采用其他不同大小的卷积核对句子的拼接矩阵进行深层特征提取,例如,对于图3示出的拼接矩阵302,还可以采用4×4大小的卷积核、2×4大小的卷积核进行深层特征提取。
需要说明的是,卷积核中各元素的取值可以通过预先训练得到,根据最终的分类结果与实际分类的偏差对卷积核中个元素的取值进行修正,最终获得可信度较高的卷积核。
下面简要介绍利用卷积核对一个句子的拼接矩阵进行计算的过程。
以图3示出的句子的拼接矩阵302为例,根据以下公式对图3示出的8×4大小的拼接矩阵进行计算。
C j=σ(K j·r i:i+t-1+b j)
其中,K j为卷积核301,t为卷积区域的单词数(即卷积核的行数),b j为偏置项,r i:i+t-1是句子的拼接矩阵302被卷积核301所覆盖的区域的矩阵,σ为激活函数。
图3示出卷积核K j与拼接矩阵302的第一行对齐后,将卷积核301中的元素与拼接矩阵302中对应的元素进行相乘,即卷积核301中的一行一列的元素与拼接矩阵302中的一行一列的元素相乘、卷积核301中的一行二列的元素与拼接矩阵302中的一行二列的元素拼接相乘……这样图3示出的实施例中总共会得到3×4=12个乘积,并将12个乘积累加后与b j相加,得到的相加结果再代入至激活函数σ中,若相加结果大于0,即可直接将相加结果作为输出的结果,若相加结果小于或等于0,则将0作为输出的结果。需要说明的是,卷积核K j与拼接矩阵302的第一行对齐时的输出结果为C 1,卷积核K j与拼接矩阵302的第二行对齐时的输出结果为C 2……以此类推,该卷积核301最后可对齐至拼接矩阵302的第六行,因此对于句子的拼接矩阵302,通过计算可得到卷积特征向量C 1={C 1,C 2,C 3,C 4,C 5,C 6}。其他的不同大小的卷积核的计算也与上述示出的执行过程及原理是相同的,此处不再赘述。若选用了5个不同大小的卷积核对句子的拼接矩阵进行计算,那么一共会得到5个长度不同的卷积特征向量。其中,选取卷积核的个数可根据实 际情况进行调整。
还需要说明的是,偏置项b j通过预先训练得到,根据最终的分类结果与实际分类的偏差对偏置项b j的取值进行修正,最终获得可信度较高的偏置项b j
S205、对每一个句子对应的多个卷积特征向量分别进行最大池化操作处理,得到每一个句子的特征向量。
具体的,将步骤S204得到的每一个句子对应的多个卷积特征向量分别提取出数值最大的一个元素,作为这个卷积特征向量处理后的结果,所有卷积特征向量的处理结果,按各卷积特征向量之间的相对位置关系排列,构成一个新的向量,就是每一个句子的特征向量。
例如,对图3示出的句子的拼接矩阵302采用卷积核301执行步骤S204的计算后,得到一个卷积特征向量C 1={C 1,C 2,C 3,C 4,C 5,C 6}。从卷积特征向量C 1中提取出数值最大的元素,作为卷积特征向量C 1的最大池化操作处理的结果。同样的,对于其他不同于卷积核301大小的卷积核,也会从对应的卷积特征向量中提取出最大值的元素。最终,如果使用了5个卷积核,那么就会选取出5个元素,又按照相对位置关系排列,组成了一个大小为1×5的句子的特征向量。文本中的每一个句子经过上述转换后都会得到大小相同的特征向量。
经过最大池化操作后可得到保留了句子最主要的特征信息的向量,同时减少了参数数量,更利于后续处理。
需要说明的是,在本申请一具体实施例中,也可以直接对步骤S201得到的句子的原始矩阵或者步骤S202得到的句子的第二关联特征矩阵执行步骤S204及步骤S205。但采用步骤S203的句子的拼接矩阵计算出的句子的特征向量中,既有包含句子中的单词的原始语义特征,也包含了句子中单词间的关联性的特征,因此得到的句子的特征向量用于进行分类预测的话,准确率会更高。
S206、按照特定的顺序排列,将文本中每一个句子的特征向量组成文本的特征矩阵。
其中,步骤S206中说的特定的顺序,指的是图1示出的步骤S101文本 中的句子的排列顺序。将步骤S205得到的文本中的每一个句子的特征向量,按照文本中的句子的排列顺序,组合成文本的特征矩阵。
S103、根据文本的特征矩阵,计算得到文本的第一关联特征矩阵。
其中,文本的第一关联特征矩阵包括文本中每一个句子的第一关联特征向量。每一个句子的第一关联特征向量用于说明每一个句子与文本中的其他句子间的关联性。文本的特征矩阵记为S矩阵,若文本中共有P个句子,则文本的特征矩阵S={S1,S2,......,Sp},其中,Sp表示为文本中第p个句子的特征向量。根据第p个句子的特征向量Sp与文本中其他句子间的关联性,可以计算得到第p个句子的第一关联特征向量Hp,文本的第一关联特征矩阵H={H1,H2,......,Hp}。文本的特征矩阵S中的第p个句子的特征向量Sp仅能说明第p个句子自身带有的的特征信息,而文本的第一关联特征矩阵H中的第p个句子的第一关联特征向量Hp则能结合除了第P个句子以外的其他句子的特征来说明第P个句子的特征信息。
可选地,在本申请一具体实施例中,执行步骤S103的一种实施方式,包括:
基于双向循环神经网络模型,根据文本的特征矩阵,计算得到文本的第一关联特征矩阵。
Bi-RNN可以利用它内部的记忆来处理任意时序的输入序列。一个序列输入至Bi-RNN中,它当前的输出也会与之前的输出也有关。Bi-RNN会对前面的信息进行记忆,保存在网络的内部状态中,并应用于当前输出的计算中,即隐含层之间的节点是有链接的,并且隐含层的输入不仅包含输入层的输出还包含上一时刻隐含层的输出。因此,通过Bi-RNN可以处理文本中的句子间的关联性。将步骤S102得到的文本的特征矩阵输入至Bi-RNN中,可得到能够说明句子间的关联性的文本的第一关联特征矩阵。
可选地,将文本的特征矩阵输入至Bi-RNN前,还可以先将文本的特征矩阵输入CNN中,经过卷积运算后再输入至Bi-RNN中。通过结合Bi-RNN模型以及CNN模型的优点,得到更优的文本的第一关联特征矩阵表示。
需要说明的是,步骤S103中可以使用的Bi-RNN的种类很多,例如双向长短期记忆神经网络(Bi-LSTM,Bidirectional Long Short-Term Memory)、 双向门循环单元(Bi-GRU,Bidirectional Gated Recurrent Unit)等。
S104、根据文本的第一关联特征矩阵,计算得到文本的分类预测矩阵。
其中,文本的分类预测矩阵包括文本中每一个句子的分类预测向量。每一个句子的分类预测向量用于说明每一个句子属于每一个预设标签的权重值。利用步骤S103得到的文本的第一关联特征矩阵H={H1,H2,......,Hp},可得到文本的分类预测矩阵y={y1,y2,......,yp}。其中,yp表示第p个句子的分类预测向量。yp向量的长度与预设的分类标签的数目相同。例如,本申请实施例中需要将文本中的句子分成5类,那么每一个句子的分类预测向量的长度就为5,例如第p个句子的分类预测向量yp={yp1,yp2,yp3,yp4,yp5}。其中,yp1代表第p个句子属于第一类标签的权重值,yp2代表第p个句子属于第二类标签的权重值,yp3则代表第p个句子属于第三类标签的权重值……而yp1、yp2、yp3、yp4以及yp5中数值最大的一个,即代表着该句子的分类预测向量预测出的该句子所属的标签类别。
可选地,在本申请一具体实施例中,执行步骤S104的一种实施方式,包括:
基于卷积神经网络模型,根据文本的第一关联特征矩阵,计算得到文本的分类预测矩阵。
将步骤S103得到的文本的第一关联特征矩阵输入至CNN中,经过CNN的卷积层将第一关联特征矩阵转换为实数矩阵输出,得到文本的分类预测矩阵。
需要说明的是,文本中的句子的分类标签可自定义设置。例如,可以将文本中的句子划分成正文、标题、结尾等类别,也可以依据文本中的句子具有的不同的功能进行分类。
可选地,在本申请一具体实施例中,执行步骤S104之后,还包括:
根据文本的分类预测矩阵,计算出文本中的每一个句子属于每一个预设标签的预测概率。
步骤S104得到的文本的分类预测矩阵中,每一个句子的分类预测向量中说明的是该句子属于每一个分类标签的绝对权重值,为了更直观的预测出该句子的所属的类别,需要计算出该句子属于每一个类别的预测概率。 例如第p个句子的分类预测向量yp={yp1,yp2,yp3,yp4,yp5},通过计算出yp1占总的权重值的比例,即可得到第p个句子属于第一类标签的预测概率。
可选地,使用以下公式来计算每一个句子属于每一个预设标签的预测概率:
Figure PCTCN2019126947-appb-000001
其中,p i标识该句子属于第i个类别的标签的预测概率;C指的是总的标签数;y i指的是该句子属于第i个类别的标签的权重值。
计算出了每个类别的标签的预测概率后,选择预测概率值最大的标签作为该句子的分类标签,实现对文本的分类。
可选地,在本申请一具体实施例中,执行完步骤S104之后,还可以将文本的分类预测矩阵输入至条件随机场(Conditional Random Field,CRF)算法中,最终输出每一个句子所属的类别。虽然执行完步骤S104后,可以直接从每一个句子的分类预测向量选出权重值最大的标签作为句子所属于的类别标签。但这种方法只考虑到了针对该句子的局部最优解,而没有考虑到整体的最优解。CRF算法中使用到的转换矩阵引入了该句子属于i标签的情况下,该句子的下一个句子属于j标签的概率,因此可得到整体概率最优的一个输出结果,避免了不合理标注的情况。例如,对第3个句子标记为正文标签,对四个句子却标记为标题标签,这样的情况显然不合理,使用了CRF算法后就能避免这样的情况发生。
可选地,参阅图4,在本申请一具体实施例中,根据文本的分类预测矩阵,计算出文本中的每一个句子属于每一个预设标签的预测概率之后,还包括:
S401、使用交叉熵作为损失函数,计算文本中的每一个句子属于每一个预设标签的预测概率与实际概率间的损失值。
具体的,计算损失值的交叉熵公式为:
Figure PCTCN2019126947-appb-000002
其中,Loss为文本分类的损失值,
Figure PCTCN2019126947-appb-000003
是该句子属于第i类别标签的实际概率,p i(a)为句子属于第i类别标签的预测概率,a表示文本,D表示训练 数据,C表示总的类别标签数。
Loss值越小,则说明文本分类预测准确率越高。
S402、根据损失值,调整文本分类的方法中使用的模型的参数。
其中,调整文本分类的方法中使用的模型的参数指的是上述实施例中提到的Bi-RNN模型、CNN模型中的参数。通过对文本分类的方法中使用的模型进行参数调整,可提高文本分类的准确率。
具体的,执行步骤S402时,根据步骤S401得到的损失值Loss,通过反向传播算法对文本分类的方法中使用的模型的参数进行自动优化调整。直至调整后的模型符合预设的标准为止。可选地,在本申请一具体实施例中,当验证数据集的准确率、召回率等参数达到预设的标准后,即可结束对文本分类中使用到的模型进行参数优化。
本申请实施例提出的文本分类的方法中,通过获取输入的文本,再根据输入的文本,得到文本的特征矩阵。其中,文本的特征矩阵包括文本中每一个句子的特征向量。根据文本的特征矩阵,可计算得到文本的第一关联特征矩阵。其中,文本的第一关联特征矩阵包括文本中每一个句子的第一关联特征向量。每一个句子的第一关联特征向量用于说明每一个句子与文本中的其他句子间的关联性。根据文本的第一关联特征矩阵,计算得到文本的分类预测矩阵。其中,文本的分类预测矩阵包括文本中每一个句子的分类预测向量。其中,每一个句子的分类预测向量用于说明每一个句子属于每一个预设标签的权重值。由于本申请在计算文本的分类预测矩阵时,考虑到了文本中的每一个句子与文本中其他句子的关联性,因此提高了文本预测分类的准确度。
参阅图5,基于上述本申请实施例公开的文本分类的方法,本申请实施例还对应公开了一种文本分类的装置500,包括:获取单元501、第一计算单元502、第二计算单元503以及第三计算单元504。
获取单元501,用于获取输入的文本。其中,文本由多个句子按照特定的顺序排列构成。
第一计算单元502,用于根据输入的文本,计算得到文本的特征矩阵。
其中,文本的特征矩阵包括文本中每一个句子的特征向量。
可选地,在本申请一具体实施例中,第一计算单元502,包括:嵌入单元、第三计算子单元、拼接单元、卷积单元、最大池化单元以及组成单元。
嵌入单元,用于根据嵌入矩阵,将文本中的每一个句子中的单词转换成相对应的单词向量,得到文本中的每一个句子的原始矩阵。其中,每一个句子的原始矩阵包括每一个句子中的单词对应的单词向量。
第三计算子单元,用于基于双向循环神经网络模型,根据文本中的每一个句子的原始矩阵,计算得到文本中的每一个句子的第二关联特征矩阵。其中,每一个句子的第二关联特征矩阵包括每一个句子中的单词对应的第二关联特征向量。每一个单词对应的第二关联特征向量用于说明每一个单词与句子中的其他单词的关联性。
拼接单元,用于拼接文本中的每一个句子的原始矩阵以及对应的第二关联特征矩阵,得到文本中的每一个句子的拼接矩阵。
卷积单元,用于基于卷积神经网络模型,利用多个卷积核对文本中的每一个句子的拼接矩阵进行深层特征提取,得到文本中的每一个句子对应的多个卷积特征向量。
最大池化单元,用于对每一个句子对应的多个卷积特征向量分别进行最大池化操作处理,得到每一个句子的特征向量。
组成单元,用于按照特定的顺序排列,将所述文本中每一个句子的特征向量组成文本的特征矩阵。
第二计算单元503,用于根据文本的特征矩阵,计算得到文本的第一关联特征矩阵。其中,文本的第一关联特征矩阵包括文本中每一个句子的第一关联特征向量。每一个句子的第一关联特征向量用于说明每一个句子与文本中的其他句子间的关联性。
可选地,在本申请一具体实施例中,第二计算单元503,包括:
第一计算子单元,用于基于双向循环神经网络模型,根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵。
第三计算单元504,用于根据文本的第一关联特征矩阵,计算得到文本的分类预测矩阵。其中,文本的分类预测矩阵包括文本中每一个句子的分 类预测向量。每一个句子的分类预测向量用于说明每一个句子属于每一个预设标签的权重值。
可选地,在本申请一具体实施例中,第三计算单元504,包括:
第二计算子单元,用于基于卷积神经网络模型,根据文本的第一关联特征矩阵,计算得到文本的分类预测矩阵。
可选地,在本申请一具体实施例中,文本分类的装置500还包括:
第四计算子单元,用于根据文本的分类预测矩阵,计算出文本中的每一个句子属于每一个预设标签的预测概率。
可选地,在本申请一具体实施例中,文本分类的装置500还包括:第五计算子单元和调整单元。
第五计算子单元,用于使用交叉熵作为损失函数,计算文本中的每一个句子属于每一个预设标签的预测概率与实际概率间的损失值。
调整单元,用于根据损失值,调整文本分类的方法中使用的模型的参数。
上述本申请实施例公开的文本分类的装置500中的具体的原理和执行过程,与上述本申请实施例公开的文本分类的方法相同,可参见上述本申请实施例公开的文本分类的方法中相应的部分,这里不再进行赘述。
本申请实施例提出的文本分类的装置500中,通过获取单元501获取输入的文本,再通过第一计算单元502根据输入的文本,得到文本的特征矩阵。其中,文本的特征矩阵包括文本中每一个句子的特征向量。第二计算单元503根据文本的特征矩阵,可计算得到文本的第一关联特征矩阵。其中,文本的第一关联特征矩阵包括文本中每一个句子的第一关联特征向量。每一个句子的第一关联特征向量用于说明每一个句子与文本中的其他句子间的关联性。第三计算单元504根据文本的第一关联特征矩阵,计算得到文本的分类预测矩阵。其中,文本的分类预测矩阵包括文本中每一个句子的分类预测向量。其中,每一个句子的分类预测向量用于说明每一个句子属于每一个预设标签的权重值。由于本申请在计算文本的分类预测矩阵时,考虑到了文本中的每一个句子与文本中其他句子的关联性,因此提高了文本预测分类的准确度。
所述文本分类的装置500包括处理器和存储器,上述获取单元501、第一计算单元502、第二计算单元503以及第三计算单元504等均作为程序单元存储在存储器中,由处理器执行存储在存储器中的上述程序单元来实现相应的功能。
处理器中包含内核,由内核去存储器中调取相应的程序单元。内核可以设置一个或以上,通过调整内核参数来提高文本预测分类的准确度。
存储器可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM),存储器包括至少一个存储芯片。
本发明实施例提供了一种存储介质,其上存储有程序,该程序被处理器执行时实现所述文本分类的方法。
本发明实施例提供了一种处理器,所述处理器用于运行程序,其中,所述程序运行时执行所述文本分类的方法。
本发明实施例提供了一种设备,设备包括处理器、存储器及存储在存储器上并可在处理器上运行的程序,处理器执行程序时实现以下步骤:
获取输入的文本;其中,所述文本由多个句子按照特定的顺序排列构成;
根据所述输入的文本,计算得到文本的特征矩阵;其中,所述文本的特征矩阵包括所述文本中每一个句子的特征向量;
根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵;其中,所述文本的第一关联特征矩阵包括所述文本中每一个句子的第一关联特征向量;所述每一个句子的第一关联特征向量用于说明所述每一个句子与所述文本中的其他句子间的关联性;
根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵;其中,所述文本的分类预测矩阵包括所述文本中每一个句子的分类预测向量;所述每一个句子的分类预测向量用于说明所述每一个句子属于每一个预设标签的权重值。
可选地,在上述文本分类的方法中,所述根据所述文本的特征矩阵, 计算得到所述文本的第一关联特征矩阵,包括:
基于双向循环神经网络模型,根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵。
可选地,在上述文本分类的方法中,所述根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵,包括:
基于卷积神经网络模型,根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵。
可选地,在上述文本分类的方法中,所述根据所述输入的文本,计算得到文本的特征矩阵,包括:
根据嵌入矩阵,将所述文本中的每一个句子中的单词转换成相对应的单词向量,得到所述文本中的每一个句子的原始矩阵;其中,所述每一个句子的原始矩阵包括所述每一个句子中的单词对应的单词向量;
基于双向循环神经网络模型,根据所述文本中的每一个句子的原始矩阵,计算得到所述文本中的每一个句子的第二关联特征矩阵;其中,所述每一个句子的第二关联特征矩阵包括所述每一个句子中的单词对应的第二关联特征向量;每一个单词对应的第二关联特征向量用于说明所述每一个单词与句子中的其他单词的关联性;
拼接所述文本中的每一个句子的原始矩阵以及对应的所述第二关联特征矩阵,得到所述文本中的每一个句子的拼接矩阵;
基于卷积神经网络模型,利用多个卷积核对所述文本中的每一个句子的拼接矩阵进行深层特征提取,得到所述文本中的每一个句子对应的多个卷积特征向量;
对所述每一个句子对应的多个卷积特征向量分别进行最大池化操作处理,得到所述每一个句子的特征向量;
按照所述特定的顺序排列,将所述文本中每一个句子的特征向量组成所述文本的特征矩阵。
可选地,在上述文本分类的方法中,所述根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵之后,还包括:
根据所述文本的分类预测矩阵,计算出所述文本中的每一个句子属于 每一个预设标签的预测概率。
可选地,在上述文本分类的方法中,所述根据所述文本的分类预测矩阵,计算出所述文本中的每一个句子属于每一个预设标签的预测概率之后,还包括:
使用交叉熵作为损失函数,计算所述文本中的每一个句子属于每一个预设标签的预测概率与实际概率间的损失值;
根据所述损失值,调整所述文本分类的方法中使用的模型。
本文中的设备可以是服务器、PC等。
本申请还提供了一种计算机程序产品,当在数据处理设备上执行时,适于执行初始化有如下方法步骤的程序:
获取输入的文本;其中,所述文本由多个句子按照特定的顺序排列构成;
根据所述输入的文本,计算得到文本的特征矩阵;其中,所述文本的特征矩阵包括所述文本中每一个句子的特征向量;
根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵;其中,所述文本的第一关联特征矩阵包括所述文本中每一个句子的第一关联特征向量;所述每一个句子的第一关联特征向量用于说明所述每一个句子与所述文本中的其他句子间的关联性;
根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵;其中,所述文本的分类预测矩阵包括所述文本中每一个句子的分类预测向量;所述每一个句子的分类预测向量用于说明所述每一个句子属于每一个预设标签的权重值。
可选地,在上述文本分类的方法中,所述根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵,包括:
基于双向循环神经网络模型,根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵。
可选地,在上述文本分类的方法中,所述根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵,包括:
基于卷积神经网络模型,根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵。
可选地,在上述文本分类的方法中,所述根据所述输入的文本,计算得到文本的特征矩阵,包括:
根据嵌入矩阵,将所述文本中的每一个句子中的单词转换成相对应的单词向量,得到所述文本中的每一个句子的原始矩阵;其中,所述每一个句子的原始矩阵包括所述每一个句子中的单词对应的单词向量;
基于双向循环神经网络模型,根据所述文本中的每一个句子的原始矩阵,计算得到所述文本中的每一个句子的第二关联特征矩阵;其中,所述每一个句子的第二关联特征矩阵包括所述每一个句子中的单词对应的第二关联特征向量;每一个单词对应的第二关联特征向量用于说明所述每一个单词与句子中的其他单词的关联性;
拼接所述文本中的每一个句子的原始矩阵以及对应的所述第二关联特征矩阵,得到所述文本中的每一个句子的拼接矩阵;
基于卷积神经网络模型,利用多个卷积核对所述文本中的每一个句子的拼接矩阵进行深层特征提取,得到所述文本中的每一个句子对应的多个卷积特征向量;
对所述每一个句子对应的多个卷积特征向量分别进行最大池化操作处理,得到所述每一个句子的特征向量;
按照所述特定的顺序排列,将所述文本中每一个句子的特征向量组成所述文本的特征矩阵。
可选地,在上述文本分类的方法中,所述根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵之后,还包括:
根据所述文本的分类预测矩阵,计算出所述文本中的每一个句子属于每一个预设标签的预测概率。
可选地,在上述文本分类的方法中,所述根据所述文本的分类预测矩阵,计算出所述文本中的每一个句子属于每一个预设标签的预测概率之后,还包括:
使用交叉熵作为损失函数,计算所述文本中的每一个句子属于每一个 预设标签的预测概率与实际概率间的损失值;
根据所述损失值,调整所述文本分类的方法中使用的模型的参数。
本领域内的技术人员应明白,本申请的实施例可提供为方法、系统、或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本申请是参照根据本申请实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。
存储器可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash  RAM)。存储器是计算机可读介质的示例。
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括要素的过程、方法、商品或者设备中还存在另外的相同要素。
本领域技术人员应明白,本申请的实施例可提供为方法、系统或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
以上仅为本申请的实施例而已,并不用于限制本申请。对于本领域技术人员来说,本申请可以有各种更改和变化。凡在本申请的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在本申请的权利要求范围之内。

Claims (10)

  1. 一种文本分类的方法,其特征在于,包括:
    获取输入的文本;其中,所述文本由多个句子按照特定的顺序排列构成;
    根据所述输入的文本,计算得到文本的特征矩阵;其中,所述文本的特征矩阵包括所述文本中每一个句子的特征向量;
    根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵;其中,所述文本的第一关联特征矩阵包括所述文本中每一个句子的第一关联特征向量;所述每一个句子的第一关联特征向量用于说明所述每一个句子与所述文本中的其他句子间的关联性;
    根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵;其中,所述文本的分类预测矩阵包括所述文本中每一个句子的分类预测向量;所述每一个句子的分类预测向量用于说明所述每一个句子属于每一个预设标签的权重值。
  2. 根据权利要求1所述的方法,其特征在于,所述根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵,包括:
    基于双向循环神经网络模型,根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵。
  3. 根据权利要求1所述的方法,其特征在于,所述根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵,包括:
    基于卷积神经网络模型,根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵。
  4. 根据权利要求1所述的方法,其特征在于,所述根据所述输入的文本,计算得到文本的特征矩阵,包括:
    根据嵌入矩阵,将所述文本中的每一个句子中的单词转换成相对应的单词向量,得到所述文本中的每一个句子的原始矩阵;其中,所述每一个句子的原始矩阵包括所述每一个句子中的单词对应的单词向量;
    基于双向循环神经网络模型,根据所述文本中的每一个句子的原始矩阵,计算得到所述文本中的每一个句子的第二关联特征矩阵;其中,所述 每一个句子的第二关联特征矩阵包括所述每一个句子中的单词对应的第二关联特征向量;每一个单词对应的第二关联特征向量用于说明所述每一个单词与句子中的其他单词的关联性;
    拼接所述文本中的每一个句子的原始矩阵以及对应的所述第二关联特征矩阵,得到所述文本中的每一个句子的拼接矩阵;
    基于卷积神经网络模型,利用多个卷积核对所述文本中的每一个句子的拼接矩阵进行深层特征提取,得到所述文本中的每一个句子对应的多个卷积特征向量;
    对所述每一个句子对应的多个卷积特征向量分别进行最大池化操作处理,得到所述每一个句子的特征向量;
    按照所述特定的顺序排列,将所述文本中每一个句子的特征向量组成所述文本的特征矩阵。
  5. 根据权利要求1至4中任意一项所述的方法,其特征在于,所述根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵之后,还包括:
    根据所述文本的分类预测矩阵,计算出所述文本中的每一个句子属于每一个预设标签的预测概率。
  6. 根据权利要求5所述的方法,其特征在于,所述根据所述文本的分类预测矩阵,计算出所述文本中的每一个句子属于每一个预设标签的预测概率之后,还包括:
    使用交叉熵作为损失函数,计算所述文本中的每一个句子属于每一个预设标签的预测概率与实际概率间的损失值;
    根据所述损失值,调整所述文本分类的方法中使用的模型的参数。
  7. 一种文本分类的装置,其特征在于,包括:
    获取单元,用于获取输入的文本;其中,所述文本由多个句子按照特定的顺序排列构成;
    第一计算单元,用于根据所述输入的文本,计算得到文本的特征矩阵;其中,所述文本的特征矩阵包括所述文本中每一个句子的特征向量;
    第二计算单元,用于根据所述文本的特征矩阵,计算得到所述文本的 第一关联特征矩阵;其中,所述文本的第一关联特征矩阵包括所述文本中每一个句子的第一关联特征向量;所述每一个句子的第一关联特征向量用于说明所述每一个句子与所述文本中的其他句子间的关联性;
    第三计算单元,用于根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵;其中,所述文本的分类预测矩阵包括所述文本中每一个句子的分类预测向量;所述每一个句子的分类预测向量用于说明所述每一个句子属于每一个预设标签的权重值。
  8. 根据权利要求7所述的装置,其特征在于,所述第二计算单元,包括:
    第一计算子单元,用于基于双向循环神经网络模型,根据所述文本的特征矩阵,计算得到所述文本的第一关联特征矩阵;
    所述第三计算单元,包括:
    第二计算子单元,用于基于卷积神经网络模型,根据所述文本的第一关联特征矩阵,计算得到所述文本的分类预测矩阵。
  9. 根据权利要求7所述的装置,其特征在于,所述第一计算单元,包括:
    嵌入单元,用于根据嵌入矩阵,将所述文本中的每一个句子中的单词转换成相对应的单词向量,得到所述文本中的每一个句子的原始矩阵;其中,所述每一个句子的原始矩阵包括所述每一个句子中的单词对应的单词向量;
    第三计算子单元,用于基于双向循环神经网络模型,根据所述文本中的每一个句子的原始矩阵,计算得到所述文本中的每一个句子的第二关联特征矩阵;其中,所述每一个句子的第二关联特征矩阵包括所述每一个句子中的单词对应的第二关联特征向量;每一个单词对应的第二关联特征向量用于说明所述每一个单词与句子中的其他单词的关联性;
    拼接单元,用于拼接所述文本中的每一个句子的原始矩阵以及对应的所述第二关联特征矩阵,得到所述文本中的每一个句子的拼接矩阵;
    卷积单元,用于基于卷积神经网络模型,利用多个卷积核对所述文本中的每一个句子的拼接矩阵进行深层特征提取,得到所述文本中的每一个 句子对应的多个卷积特征向量;
    最大池化单元,用于对所述每一个句子对应的多个卷积特征向量分别进行最大池化操作处理,得到所述每一个句子的特征向量;
    组成单元,用于按照所述特定的顺序排列,将所述文本中每一个句子的特征向量组成所述文本的特征矩阵。
  10. 一种计算机可读介质,其特征在于,其上存储有计算机程序,其中,所述程序被处理器执行时实现如权利要求1至6中任一所述的方法。
PCT/CN2019/126947 2019-08-12 2019-12-20 文本分类的方法、装置以及计算机可读介质 WO2021027218A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910741430.1 2019-08-12
CN201910741430.1A CN112395412B (zh) 2019-08-12 2019-08-12 文本分类的方法、装置以及计算机可读介质

Publications (1)

Publication Number Publication Date
WO2021027218A1 true WO2021027218A1 (zh) 2021-02-18

Family

ID=74569747

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/126947 WO2021027218A1 (zh) 2019-08-12 2019-12-20 文本分类的方法、装置以及计算机可读介质

Country Status (2)

Country Link
CN (1) CN112395412B (zh)
WO (1) WO2021027218A1 (zh)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113704478A (zh) * 2021-09-07 2021-11-26 平安银行股份有限公司 文本要素提取方法、装置、电子设备及介质
CN113806507A (zh) * 2021-09-16 2021-12-17 厦门快商通科技股份有限公司 一种多标签分类方法、装置及可读介质
CN115510193A (zh) * 2022-10-10 2022-12-23 北京百度网讯科技有限公司 查询结果向量化方法、查询结果确定方法及相关装置

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112579784B (zh) * 2021-03-01 2021-06-01 江西师范大学 一种基于深度强化学习的云边协同文档分类系统及方法

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106599933A (zh) * 2016-12-26 2017-04-26 哈尔滨工业大学 一种基于联合深度学习模型的文本情感分类方法
CN108170667A (zh) * 2017-11-30 2018-06-15 阿里巴巴集团控股有限公司 词向量处理方法、装置以及设备
US20180300608A1 (en) * 2017-04-12 2018-10-18 Yodlee, Inc. Neural Networks for Information Extraction From Transaction Data
CN109783618A (zh) * 2018-12-11 2019-05-21 北京大学 基于注意力机制神经网络的药物实体关系抽取方法及系统

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106599933A (zh) * 2016-12-26 2017-04-26 哈尔滨工业大学 一种基于联合深度学习模型的文本情感分类方法
US20180300608A1 (en) * 2017-04-12 2018-10-18 Yodlee, Inc. Neural Networks for Information Extraction From Transaction Data
CN108170667A (zh) * 2017-11-30 2018-06-15 阿里巴巴集团控股有限公司 词向量处理方法、装置以及设备
CN109783618A (zh) * 2018-12-11 2019-05-21 北京大学 基于注意力机制神经网络的药物实体关系抽取方法及系统

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113704478A (zh) * 2021-09-07 2021-11-26 平安银行股份有限公司 文本要素提取方法、装置、电子设备及介质
CN113704478B (zh) * 2021-09-07 2023-08-22 平安银行股份有限公司 文本要素提取方法、装置、电子设备及介质
CN113806507A (zh) * 2021-09-16 2021-12-17 厦门快商通科技股份有限公司 一种多标签分类方法、装置及可读介质
CN113806507B (zh) * 2021-09-16 2023-06-23 厦门快商通科技股份有限公司 一种多标签分类方法、装置及可读介质
CN115510193A (zh) * 2022-10-10 2022-12-23 北京百度网讯科技有限公司 查询结果向量化方法、查询结果确定方法及相关装置
CN115510193B (zh) * 2022-10-10 2024-04-16 北京百度网讯科技有限公司 查询结果向量化方法、查询结果确定方法及相关装置

Also Published As

Publication number Publication date
CN112395412A (zh) 2021-02-23
CN112395412B (zh) 2024-05-03

Similar Documents

Publication Publication Date Title
WO2021027218A1 (zh) 文本分类的方法、装置以及计算机可读介质
US11948058B2 (en) Utilizing recurrent neural networks to recognize and extract open intent from text inputs
Zeng et al. A convolution BiLSTM neural network model for Chinese event extraction
CN111444723B (zh) 信息抽取方法、计算机设备和存储介质
CN109948149B (zh) 一种文本分类方法及装置
US11699275B2 (en) Method and system for visio-linguistic understanding using contextual language model reasoners
US11860684B2 (en) Few-shot named-entity recognition
US11016997B1 (en) Generating query results based on domain-specific dynamic word embeddings
CN113591483A (zh) 一种基于序列标注的文档级事件论元抽取方法
JP5809381B1 (ja) 自然言語処理システム、自然言語処理方法、および自然言語処理プログラム
US20200364216A1 (en) Method, apparatus and storage medium for updating model parameter
CN110968725B (zh) 图像内容描述信息生成方法、电子设备及存储介质
CN110598210B (zh) 实体识别模型训练、实体识别方法、装置、设备及介质
CN114036950B (zh) 一种医疗文本命名实体识别方法及系统
CN113590784A (zh) 三元组信息抽取方法、装置、电子设备、及存储介质
WO2014073206A1 (ja) 情報処理装置、及び、情報処理方法
RU2712101C2 (ru) Предсказание вероятности появления строки с использованием последовательности векторов
CN111339775A (zh) 命名实体识别方法、装置、终端设备及存储介质
CN110968697A (zh) 文本分类方法、装置、设备及可读存储介质
CN111563380A (zh) 一种命名实体识别方法及其装置
CN112434533A (zh) 实体消歧方法、装置、电子设备及计算机可读存储介质
WO2020114109A1 (zh) 嵌入结果的解释方法和装置
US11494431B2 (en) Generating accurate and natural captions for figures
CN115600597A (zh) 基于注意力机制和词内语义融合的命名实体识别方法、装置、系统及存储介质
CN112818687B (zh) 一种用于构建标题识别模型的方法、装置、电子设备以及存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19940971

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19940971

Country of ref document: EP

Kind code of ref document: A1