A text classification method, device and storage medium
By acquiring and fusing word feature and semantic feature information of text pairs, and calculating attention features between keywords, the problem of poor text pair classification in the existing technology is solved, and higher classification accuracy is achieved.
Patent Information
- Application Number
- CN201910872891.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-09-16
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2039-09-16
AI Technical Summary
In the classification of text pairs, the existing technology has poor classification effect and fails to effectively consider the interactive information between text pairs.
By obtaining the word feature information and semantic feature information of the text pairs to be classified, the attention feature information between keywords is calculated and fused for classification.
The accuracy of text classification is improved. By considering the interactive information between text pairs and the influence of keywords, the classification effect is significantly improved compared to simple feature combination or direct input into the model.
Smart Images

Figure CN110796160B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a text classification method, device and storage medium. Background Art
[0002] With the development of artificial intelligence (AI), natural language processing technology has become an important research direction in Internet applications. In the natural language processing (NLP) system based on deep neural networks, the classification problem of text pairs is a very basic and important problem, which is widely used in search, recommendation, dialogue and other fields. Usually, text A in a pair of texts refers to user questions, and text B refers to the content source to be matched, such as questions in the question and answer library, the content of the web page, the text description of the product, etc. The classification of text pairs should not only consider the information of a single text, but also the interactive information between text pairs. At present, many methods simply combine the features of the texts on both sides, or directly input them into a model with a self-attention mechanism for classification, and the classification effect is poor. Summary of the invention
[0003] The embodiments of the present invention provide a text classification method, device and storage medium, which can effectively improve the accuracy of text classification.
[0004] An embodiment of the present invention provides a text classification method, including:
[0005] Get the text pair to be classified;
[0006] Extracting features of each word in the text pair to be classified to obtain word feature information of each word and semantic feature information of the text pair to be classified;
[0007] Calculating the attention of the key words in the to-be-classified text pair to the respective words according to the word feature information to obtain attention feature information;
[0008] Fusing the attention feature information and the semantic feature information to obtain text fusion information;
[0009] The text pairs to be classified are classified based on the text fusion information to obtain a classification result.
[0010] Accordingly, an embodiment of the present invention further provides a text classification device, comprising:
[0011] An acquisition unit, configured to acquire a text pair to be classified, wherein the text pair to be classified includes a first text and a second text;
[0012] A selection unit, configured to select a first keyword of the first text and a second keyword of the second text from the pair of texts to be classified;
[0013] An extraction unit, used for performing feature extraction on the text in the to-be-classified text pair to obtain word feature information and first semantic feature information of the first text, and word feature information and second semantic feature information of the second text;
[0014] A first calculation unit is used to obtain first attention feature information according to the word feature information of the first text and the word feature information of the second keyword, wherein the first attention feature information is word feature information focusing on the correlation between the second keyword and each word in the first text;
[0015] A second calculation unit is used to obtain second attention feature information according to the word feature information of the second text and the word feature information of the second keyword, wherein the second attention feature information is word feature information focusing on the correlation between the first keyword and each word in the second text;
[0016] A classification unit is used to classify the text pair to be classified based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information to obtain a classification result.
[0017] Optionally, in some embodiments, the first calculation unit may include a first calculation subunit and a first adjustment subunit, as follows:
[0018] The first calculation subunit is used to calculate first correlation information between the second keyword and each word in the first text according to the word feature information of the first text and the word feature information of the second keyword;
[0019] The first adjustment subunit is used to adjust the word feature information of the first text based on the first correlation information to obtain first attention feature information.
[0020] Optionally, in some embodiments, the first computing subunit is specifically used to generate a first query vector based on word feature information of the first text, and to generate a second key vector based on word feature information of the second keyword, and to calculate a first weight representing the relevance between the second keyword and each word in the first text based on the first query vector and the second key vector.
[0021] At this time, the first adjustment subunit can be specifically used to adjust the word feature information of the first text based on the first weight to obtain first attention feature information.
[0022] Optionally, in some embodiments, the first adjustment subunit is specifically used to generate a first value vector according to word feature information of the first text, and perform a weighted operation on the first value vector based on the first weight to obtain first attention feature information.
[0023] Optionally, in some embodiments, the second calculation unit may include a second calculation subunit and a second adjustment subunit, as follows:
[0024] The second calculation subunit is used to calculate second correlation information between the first keyword and each word in the second text according to the word feature information of the second text and the word feature information of the second keyword;
[0025] The second adjustment subunit is used to adjust the word feature information of the second text based on the second correlation information to obtain second attention feature information.
[0026] Optionally, in some embodiments, the second computing subunit is specifically used to generate a second query vector based on word feature information of the second text, and to generate a first key vector based on word feature information of the first keyword, and to calculate a second weight representing the correlation between the first keyword and each word in the second text based on the second query vector and the first key vector.
[0027] At this time, the second adjustment subunit can be specifically used to adjust the word feature information of the second text based on the second weight to obtain second attention feature information.
[0028] Optionally, in some embodiments, the second adjustment subunit is specifically used to generate a second value vector according to word feature information of the second text, and perform a weighted operation on the second value vector based on the second weight to obtain second attention feature information.
[0029] Optionally, in some embodiments, the extraction unit may include a first extraction subunit, a second extraction subunit and a third extraction subunit, as follows:
[0030] The first extraction subunit is used to extract word features from each word in the first text to obtain word feature information of the first text;
[0031] The second extraction subunit is used to extract word features from each word in the second text to obtain word feature information of the second text;
[0032] The third extraction subunit is used to extract semantic features from the first text and the second text pair respectively to obtain first semantic feature information of the first text and second semantic feature information of the second text.
[0033] Optionally, in some embodiments, the first extraction subunit is specifically used to perform position feature extraction and word feature extraction on each word in the first text, respectively, to obtain the position feature and word feature of the first text, to mark each word in the first text, to obtain the mark feature of the first text, and to perform feature fusion on the position feature, word feature and mark feature of the first text, to obtain the word feature information of the first text.
[0034] Optionally, in some embodiments, the second extraction subunit is specifically used to perform position feature extraction and word feature extraction on each word in the second text, respectively, to obtain position features and word features of the second text, to mark each word in the second text, to obtain mark features of the second text, and to synthesize the position features, word features and mark features of the second text to obtain word feature information of the second text.
[0035] Optionally, in some embodiments, the selection unit is specifically used to perform word segmentation on the text pair to be classified, obtain a word set of the text pair to be classified, determine the fields to which the first text and the second text respectively belong, and determine the first keyword of the first text and the second keyword of the second text from the word set based on a preset dictionary corresponding to the fields.
[0036] Optionally, in some embodiments, the classification unit may include a fusion subunit, a third calculation subunit and a classification subunit, as follows:
[0037] The fusion subunit is used to fuse the first semantic feature information and the second semantic feature information to obtain fused semantic feature information;
[0038] The third calculation subunit is used to calculate the matching degree between the first text and the second text according to the first text information, the second text information and the fused semantic feature information;
[0039] The classification subunit is used to classify the text pairs to be classified based on the matching degree to obtain a classification result.
[0040] Optionally, in some embodiments, the third computing subunit is specifically used to perform feature expansion on the first text information, the second text information and the fused semantic feature information to obtain text expansion information, and calculate the matching degree between the first text and the second text based on the text expansion information.
[0041] In addition, an embodiment of the present invention further provides a computer-readable storage medium, which stores a plurality of instructions, and the instructions are suitable for a processor to load to execute the steps in any text classification method provided by the embodiment of the present invention.
[0042] In addition, an embodiment of the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps in any text classification method provided in the embodiment of the present invention are implemented.
[0043] After obtaining a pair of texts to be classified, the embodiment of the present invention includes a first text and a second text. The first keyword of the first text and the second keyword of the second text can be selected from the pair of texts to be classified, and then the texts in the pair of texts to be classified are feature extracted to obtain word feature information and first semantic feature information of the first text, and word feature information and second semantic feature information of the second text. Then, first attention feature information is obtained based on the word feature information of the first text and the word feature information of the second keyword, and second attention feature information is obtained based on the word feature information of the second text and the word feature information of the second keyword. Then, based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information, the pair of texts to be classified is classified to obtain a classification result. This solution can effectively improve the accuracy of text classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0045] Figure 1a is a schematic diagram of a scenario of a text classification method provided by an embodiment of the present invention;
[0046] Figure 1b is a flowchart of a text classification method provided by an embodiment of the present invention;
[0047] Figure 1c is a schematic diagram of feature extraction provided by an embodiment of the present invention;
[0048] Figure 1d is a structural example diagram of an attention module provided by an embodiment of the present invention;
[0049] Figure 1e is a diagram showing an example structure of an encoder network provided by an embodiment of the present invention;
[0050] Figure 1f is a schematic diagram of the structure of a decoder network provided by an embodiment of the present invention;
[0051] Figure 1gis a schematic diagram of the structure of a trained classification model provided by an embodiment of the present invention;
[0052] Figure 2a is another flow chart of the text classification method provided by an embodiment of the present invention;
[0053] Figure 2b It is a structural schematic diagram of a text classification method provided by an embodiment of the present invention;
[0054] Figure 3 is a structural schematic diagram of a text classification device provided by an embodiment of the present invention;
[0055] Figure 4 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0056] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0057] The embodiments of the present invention provide a text classification method, device and storage medium, wherein the text classification can be integrated in an electronic device, which can be a computer device, a server, a terminal or other device.
[0058] Text classification refers to the process of automatically categorizing input text into certain categories using algorithms. For example, see Figure 1a First, after the electronic device integrated with the text classification device obtains a text pair to be classified, the text pair to be classified includes a first text and a second text. The first keyword of the first text and the second keyword of the second text can be selected from the text pair to be classified, and then the texts in the text pair to be classified are subjected to feature extraction to obtain word feature information and first semantic feature information of the first text, and word feature information and second semantic feature information of the second text. Then, first attention feature information is obtained based on the word feature information of the first text and the word feature information of the second keyword, and second attention feature information is obtained based on the word feature information of the second text and the word feature information of the second keyword. Then, based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information, the text pair to be classified is classified to obtain a classification result.
[0059] The text classification method provided in the embodiment of the present application relates to the natural language processing direction in the field of artificial intelligence. The embodiment of the present application can extract word feature information and semantic feature information of the text pair to be classified through semantic understanding technology, and then classify the text pair to be classified.
[0060] Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science. It attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making. Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level technology and software-level technology. Among them, artificial intelligence software technology mainly includes computer vision technology, machine learning / deep learning and other directions.
[0061] Natural language processing (NLP) is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can achieve effective communication between people and computers using natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field will involve natural language, that is, the language people use in daily life, so it is closely related to the study of linguistics. Natural language processing technology usually includes text processing, semantic understanding, machine translation, robot question answering, knowledge graph and other technologies.
[0062] Since this scheme not only considers the feature information of a single text, but also the interactive information between text pairs, it can effectively improve the accuracy of text classification by obtaining attention feature information by enhancing the influence of the text's keyword information, and then classifying the text pairs based on their feature information and attention information.
[0063] It should be noted that the description order of the following embodiments is not intended to limit the preferred order of the embodiments.
[0064] This embodiment will be described from the perspective of a text classification device, which can be specifically integrated into an electronic device, which can be a computer device, a server, or a terminal. The terminal can include a mobile phone, a tablet computer, a laptop computer, and a personal computer (PC).
[0065] A text classification method comprises: obtaining a pair of texts to be classified, the pair of texts to be classified comprising a first text and a second text, segmenting the first text and the second text, and determining keywords, then extracting word feature information and semantic feature information from the first text and the second text, then calculating the correlation between the second keyword and each word in the first text according to the word feature information to obtain first related information; and calculating the correlation between the first keyword and each word in the second text to obtain second related information, and then classifying the pair of texts to be classified based on the first related information, the second related information and the semantic feature information to obtain a classification result.
[0066] like Figure 1b As shown, the specific process of the text classification method can be as follows:
[0067] 101. Obtain the text pair to be classified.
[0068] The text pair to be classified may include two texts to be classified, such as a first text and a second text. For example, the first text may refer to a user question, and the second text may refer to a content source to be matched, such as a question in a question-and-answer library, a webpage content, a text description of a product, etc. The text may include words, phrases, sentences, paragraphs, or articles, etc. The language of the text may be any language, such as Chinese, English, French, German, and / or Russian, etc., without any special limitation.
[0069] For example, articles or information that need to be classified can be obtained from a network database, and texts uploaded by users, such as e-books or electronic texts, can also be received.
[0070] 102. Select a first keyword of the first text and a second keyword of the second text from the pair of texts to be classified.
[0071] For example, the text pair to be classified can be segmented to obtain a word set of the text pair to be classified, the fields to which the first text and the second text respectively belong can be determined, and based on the preset dictionary corresponding to the field, the first keyword of the first text and the second keyword of the second text can be determined from the word set.
[0072] For example, the first text can be segmented to obtain a word set of the first text, the second text can be segmented to obtain a word set of the second text, the field where the first text is located and the field where the second text is located can be determined, and based on a preset dictionary corresponding to the field where the first text is located, a first keyword of the first text can be determined from the word set of the first text, and based on the preset dictionary corresponding to the field where the second text is located, a second keyword of the second text can be determined from the word set of the second text.
[0073] There are many ways to segment the content in the text pair to be classified, such as a segmentation method based on string matching, a segmentation method based on understanding, and / or a segmentation method based on statistics. Segmentation can also be performed with the help of a segmentation tool to extract words or phrases in the first text and the second text, and the extracted words or phrases are arranged and combined to obtain a word set corresponding to the first text and the second text. The language of the words or phrases obtained after segmentation can be any language, such as Chinese, English, French, German, and / or Russian, etc., without special limitation.
[0074] Among them, there are many ways to set the preset dictionary of the field. For example, the domain model can be trained according to the needs of the actual application to obtain the dictionary of the field, or it can be pre-set and stored in the electronic device. In addition, the preset dictionary can be built into the electronic device, or it can be stored in the memory and sent to the electronic device, etc. For example, the method for generating a domain dictionary can be to obtain relevant text of the target field; obtain a character unit set based on the relevant text, the character unit set includes multiple character units, and the character unit is obtained by combining continuous characters in the relevant text; obtain the mutual correlation of each character unit to obtain the original dictionary of the target field; calculate the contribution of each character unit in the original dictionary to the target field to obtain the target dictionary of the target field.
[0075] 103. Perform feature extraction on the texts in the text pair to be classified to obtain word feature information and first semantic feature information of the first text, and word feature information and second semantic feature information of the second text.
[0076] For example, word feature extraction can be performed on each word in the first text to obtain word feature information of the first text, word feature extraction can be performed on each word in the second text to obtain word feature information of the second text, and semantic feature extraction can be performed on the first text and the second text pair to obtain first semantic feature information of the first text and second semantic feature information of the second text.
[0077] There are many ways to extract features. For example, you can use the feature extraction module of the trained classification model to extract features, or you can use other feature extractors to extract features, and then input them into the trained classification model. For example, you can use the trained classification model to extract word features for each word in the first text to obtain word feature information of the first text; use the trained classification model to extract word features for each word in the second text to obtain word feature information of the second text; and perform semantic feature extraction on the first text and the second text pair to obtain first semantic feature information of the first text and second semantic feature information of the second text.
[0078] The word feature information may include the semantic information of each word in the text to be classified by a multi-dimensional vector. The dimension of the vector is the size of the word set corresponding to the text. The semantic feature information may include the grammar, semantics and other information of the words in the text.
[0079] For example, each word in the word set corresponding to the text can be numbered sequentially, and the features of each numbered word in the word set can be extracted through the word embedding algorithm. For example, the word set corresponding to the text is taken as a whole, and the numbered words in the word set become a very long vector. The dimension of the vector is the size of the word set. For example, the word set is divided into N grids, and the numbered word corresponding to the grid is defined as 1, and the number of other grids is defined as 0, and the word vector of the numbered word in the word set is obtained. Similar operation steps are used to embed each word in the word set to obtain the word vector corresponding to each word in the word set. The word vector is a multi-dimensional vector. For example, the dimension of the vector can be 512 dimensions, or it can be 256 dimensions. The word vector of each word in the word set corresponding to the text is used as the word feature information corresponding to each word. The word vector contains semantic information representing the word in the text set.
[0080] For example, the trained classification model can be a Bidirectional Encoder Representations from Transformers (BERT) model, and the feature extraction module can use a word embedding algorithm. For example, each word in the first text and the second text can be numbered sequentially, and the feature extraction module in the trained classification model can extract features for each numbered word in the text to be classified. The input representation can represent a single text sentence or a pair of texts (for example, [question, answer]) in a word sequence. For a given word, its input representation can be composed of the sum of three embeddings. Among them, the visual representation of the embedding can be as follows: Figure 1c As shown in the figure, token embeddings represent word features; segment embeddings represent tag features, which are used to distinguish two texts (for example, the first text and the second text), so that the model can perform classification tasks with two texts as input; position embeddings represent position features, which are learned by the model. That is, "extracting word features from each word in the first text to obtain word feature information of the first text" may include:
[0081] Perform position feature extraction and word feature extraction on each word in the first text to obtain position features and word features of the first text, mark each word in the first text to obtain mark features of the first text, perform feature fusion on the position features, word features and mark features of the first text to obtain word feature information of the first text.
[0082] For example, the feature extraction module of the trained classification model can be used to extract the position feature of each word in the first text to obtain the position feature of the first text, the feature extraction module of the trained classification model can be used to extract the word feature of each word in the first text to obtain the word feature of the first text, the feature extraction module of the trained classification model can be used to mark each word in the first text to obtain the mark feature of the first text, and the position feature, word feature and mark feature of the first text can be feature fused to obtain the word feature information of the first text. The feature fusion here can be the sum of the three features of the position feature, word feature and mark feature of the first text, or other fusion methods, etc.
[0083] Similarly, “extracting word features from each word in the second text to obtain word feature information of the second text” may include:
[0084] Perform position feature extraction and word feature extraction on each word in the second text to obtain position features and word features of the second text, mark each word in the second text to obtain mark features of the second text, perform feature fusion on the position features, word features and mark features of the second text to obtain word feature information of the second text.
[0085] For example, the feature extraction module of the trained classification model can be used to extract the position feature of each word in the second text to obtain the position feature of the second text, the feature extraction module of the trained classification model can be used to extract the word feature of each word in the second text to obtain the word feature of the second text, the feature extraction module of the trained classification model can be used to mark each word in the second text to obtain the mark feature of the second text, and the position feature, word feature and mark feature of the second text can be feature fused to obtain the word feature information of the second text. The feature fusion here can be the sum of the three features of the position feature, word feature and mark feature of the second text, or other fusion methods, etc.
[0086] 104. Obtain first attention feature information according to the word feature information of the first text and the word feature information of the second keyword.
[0087] The first attention feature information is word feature information that focuses on the relevance between the second keyword and each word in the first text. For example, the first relevance information between the second keyword and each word in the first text can be calculated based on the word feature information of the first text and the word feature information of the second keyword, and the word feature information of the first text is adjusted based on the first relevance information to obtain the first attention feature information.
[0088] Among them, the first relevance information refers to the influence of the second keyword on each word in the first text. For example, the first relevance information may include a first weight. For example, a first query vector may be generated based on the word feature information of the first text, and a second keyword vector may be generated based on the word feature information of the second keyword. According to the first query vector and the second keyword vector, a first weight representing the relevance between the second keyword and each word in the first text is calculated. At this time, the word feature information of the first text is adjusted based on the relevance information to obtain the first attention feature information, which may include: adjusting the word feature information of the first text based on the first weight to obtain the first attention feature information. Among them, when there are multiple keywords, the first weight is a first weight set.
[0089] Among them, there can be many ways to adjust the word feature information of the first text. For example, a first value vector can be generated according to the word feature information of the first text, and a weighted operation can be performed on the first value vector based on the first weight to obtain the first attention feature information.
[0090] Wherein, the first attention feature information can be obtained by using a trained classification model, and the trained classification model can include a feature extraction module, an encoder network, a decoder network and a classification module. Wherein, the encoder network includes multiple first attention modules, at least one first feedforward neural network and at least one first residual module. For example, the word feature information of the first text and the word feature information of the second keyword are respectively input into multiple first representation subspaces, and the first attention module is used to extract the word feature information of each word in the first text and the word feature information of the second keyword in each first representation subspace. Taking the first attention module extracting the word feature information of each word in the first text and the word feature information of the second keyword in a first representation subspace as an example, the first attention module reduces the dimension of the word feature information of each word in the first text and the word feature information of the second keyword, generates a query vector, a key vector and a value vector in the reduced word feature information, determines the target word in the word set of the first text, calculates the self-attention vector of the target word through the word feature information of the second keyword, and obtains the first initial encoding feature information of the target word.
[0091] Among them, the first initial encoded feature information output by the self-attention mechanism of the target word can be calculated by scaled dot-Product attention as follows:
[0092]
[0093] Among them, q i is the query vector of the target word, K T is the key vector of the second keyword, V is the value vector of the target word, and d is the dimension of the key vector of the second keyword. Among them, softmax is a function that can output continuous numbers into a number between 0 and 1. Its output represents the relative probability between different categories.
[0094] Through the calculation formula, it can be seen that the attention vector of the target word, that is, the first initial encoding feature information, can be calculated through these three vectors, for example, Figure 1d As shown, the key vector of the second keyword and the query vector of the target word can be dot-producted (i.e., matrix multiplication (MatMul)) to obtain the self-attention vector set of the target word, i.e., the first weight, and the value in the self-attention vector set of the target word is reduced in dimension again (i.e., scaled (Scale)), and the dimension reduction method can be achieved by dividing by the square root of the key vector of the second keyword. Among them, the mask is optional (Mask (opt.)), and then the result is passed through the function (SoftMax), and the self-attention vector in the self-attention vector set of the target word is multiplied with the value vector corresponding to the target word (i.e., matrix multiplication (MatMul)), and the multiplied result is weighted and summed to obtain the self-attention output of the target word, i.e., the initial context information of the target word, and the above steps are repeated to complete the self-attention output of the remaining words in the first text, and finally the first initial encoding feature information of each word in the first text in different first representation subspaces is obtained.
[0095] Then, the first initial coding feature information of each word in the first text under each first representation subspace is weighted. For example, the first initial coding feature information of each word in the first text under different first representation subspaces is spliced, and the first initial coding feature information of each word after splicing is weighted to obtain the fused first initial coding feature information of each word in all first representation subspaces. Then, the fused first initial coding feature information of each word is input into the first residual module through the first feedforward neural network for feature extraction. For example, the fused first initial coding feature information of each word is input into the first residual module through the first feedforward neural network for summing and normalization to obtain the first coding feature information.
[0096] It should be noted that the trained classification model may include an encoder network, and the encoder network may include a first attention module, a first feedforward neural network, and a first residual module, such as Figure 1e As shown. In the process of encoding the word feature information of each word in the first text to obtain the first encoded feature information of each word in the first text, it can be obtained by connecting multiple encoder networks in series. For example, the first encoder network parses the word feature information of each word in the first text to obtain the first layer of first encoded feature information of each word in the first text, and the second encoder network repeats the parsing or encoding steps of the first encoder network for the first layer of first encoded feature information of each word in the first text to obtain the second layer of first encoded feature information, and so on. The final first encoded feature information of each word in the first text is obtained through the analysis of multiple layers of encoder networks. Among them, the number of encoder networks needs to be set according to actual application requirements.
[0097] After receiving the first encoding feature information output by the last layer of the encoder network, feature extraction is performed on the first encoding feature information of each word in the first text to obtain the initial first decoding feature information of each word in the first text. For example, the decoder network of the trained classification model can be used to extract the first encoding feature information of each word in the first text. The decoder network of the trained classification model includes at least one attention module, at least one second feedforward neural network and at least one second residual module. For example, the specific method can be as follows:
[0098] The first coded feature information of each word in the first text is input into multiple second representation subspaces respectively, and the first coded feature information of each word is extracted by the second attention module in each second representation subspace. The feature extraction of the first coded feature information of each word by the second attention module in a second representation subspace is used as an example to illustrate that the key vector and value vector are extracted from the first coded feature information of each word, and the decoder network generates the intermediate vector of each word in the second representation subspace, and the intermediate vector is used as the query vector. The target word is determined in the first text, and the self-attention of the target word is calculated and decoded through the second keyword. For example, the self-attention vector set of the target word can be obtained by performing a dot product between the key vector of the second keyword and the query vector of the target word, and the value in the self-attention vector set of the target word is reduced in dimension again, and the dimensionality reduction method can be achieved by dividing by the square root of the key vector of the second keyword. The self-attention vector in the self-attention vector set of the target word is multiplied by the value vector corresponding to the target word, and the multiplication result is weighted and summed to obtain the self-attention output of the target word selected in the first text, and the initial first decoding feature information of the target word is obtained. The above steps are repeated to complete the self-attention output of the remaining words in the first text, and finally the initial first decoding feature information of all words in the first text in each second representation subspace is obtained. Then, the initial first decoding feature information of each word in the first text under each second representation subspace is weighted. For example, the initial first decoding feature information of each word in the first text under different second representation subspaces is spliced, and the initial first decoding feature information of each word after splicing is weighted to obtain the fused initial first decoding feature information of each word in all second representation subspaces. Next, the fused initial first decoding feature information of each word in the first text is input into the second residual module through the second feedforward neural network for feature extraction. For example, the fused initial first decoding feature information of each word is input into the second residual module through the second feedforward neural network for summing and normalization to obtain the first decoding feature information of each word in the first text. Finally, the first decoding feature information is linearly transformed to obtain the first attention feature information.
[0099] It should be noted here that the second attention module in the decoder network can also be called a "decoding-encoding attention layer". The "decoding-encoding attention layer", the second feedforward neural network and the second residual module can form a decoder network of the trained classification model, such as Figure 1fAs shown. In the process of decoding the first encoded feature information of each word in the first text to obtain the first decoded feature information of each word, it can be obtained by connecting multiple decoder networks in series. For example, the first decoder network extracts the first encoded feature information of each word in the first text to obtain the first layer of first decoding feature information of each word, and the second decoder network repeats the feature extraction steps of the first decoder network for the first layer of first decoding feature information of each word in the first text to obtain the second layer of first decoding feature information, and so on. The first decoding feature information finally outputted by each word in the first text is obtained through feature extraction of multiple layers of decoder networks. Among them, the number of decoder networks is set according to actual application needs.
[0100] Among them, the encoded feature information can be the interaction information between each word in the first text and the second keyword, and the decoded feature information can be the relevant semantics, grammar, logic and other information of each word in the first text in the first text word set obtained after the interaction between each word in the first text and the second keyword.
[0101] Optionally, the trained classification model can be pre-set by the operation and maintenance personnel or obtained by self-training of the text classification device. That is, before using the trained classification model, the text classification method can also include:
[0102] (1) Collect multiple text pair samples as training data sets.
[0103] The text pair samples include the labeled real classification results. For example, multiple text pair samples can be collected, such as obtaining text samples from a database or the Internet, and then feature extraction is performed on the text sample pairs to obtain word feature information input into the classification model.
[0104] (2) Training a preset classification model according to the training data set to obtain a trained classification model.
[0105] For example, the preset classification model can be used to classify the text pair to obtain a predicted classification result, obtain the actual classification result of the text pair, converge the preset classification model according to the predicted classification result and the actual classification result, and obtain a trained classification model.
[0106] For example, the word feature information can be encoded through an encoder network to obtain encoded feature information, and then the encoded feature information can be decoded to obtain decoded feature information. Then, the decoded feature information can be linearly transformed to obtain attention feature information. According to the word feature information and the attention feature information, the text pair is classified to obtain a predicted classification result.
[0107] For example, the pre-set classification model can be converged according to the predicted classification results and the actual classification results through the interpolation loss function to obtain the trained classification model. Figure 1g shown.
[0108] Optionally, in order to improve the accuracy of context features, in addition to the interpolation loss function, other loss functions such as the cross entropy loss function may be used for convergence.
[0109] 105. Obtain second attention feature information according to the word feature information of the second text and the word feature information of the second keyword.
[0110] The second attention feature information is word feature information that focuses on the correlation between the first keyword and each word in the second text. For example, the second correlation information between the first keyword and each word in the second text can be calculated based on the word feature information of the second text and the word feature information of the first keyword, and the word feature information of the second text can be adjusted based on the second correlation information to obtain the second attention feature information.
[0111] Among them, the second relevance information refers to the influence of the first keyword on each word in the second text, and the second relevance information may include a second weight. For example, a second query vector may be generated based on the word feature information of the second text, and a first key vector may be generated based on the word feature information of the first keyword, and a second weight representing the relevance between the first keyword and each word in the second text is calculated based on the second query vector and the first key vector. At this time, adjusting the word feature information of the second text based on the relevance information to obtain the second attention feature information may include: adjusting the word feature information of the second text based on the second weight to obtain the second attention feature information.
[0112] There are many ways to adjust the word feature information of the second text. For example, a second value vector can be generated based on the word feature information of the second text, and a weighted operation is performed on the second value vector based on the second weight to obtain the second attention feature information. When there are multiple keywords, the second weight is a second weight set.
[0113] Similarly, the second attention feature information can also be obtained by using a trained classification model. For example, the word feature information of the second text and the word feature information of the first keyword can be input into multiple first representation subspaces respectively, and the first attention module is used to extract the word feature information of each word in the second text and the word feature information of the first keyword in each first representation subspace. Taking the example of the first attention module extracting the word feature information of each word in the second text and the word feature information of the first keyword in a first representation subspace, the first attention module reduces the dimension of the word feature information of each word in the second text and the word feature information of the first keyword, generates a query vector, a key vector and a value vector in the reduced word feature information, determines the target word in the word set of the second text, calculates the self-attention vector of the target word through the word feature information of the first keyword, and obtains the second initial encoding feature information of the target word.
[0114] Among them, the second initial encoding feature information output by the self-attention mechanism of the target word can be calculated by scaled dot-Product attention as follows:
[0115]
[0116] Among them, q i is the query vector of the target word, K T is the key vector of the first keyword, V is the value vector of the target word, and d is the dimension of the key vector of the first keyword.
[0117] Through the calculation formula, it can be seen that the attention vector of the target word, that is, the second initial coding feature information, can be calculated through these three vectors. For example, the key vector of the first keyword and the query vector of the target word can be dot-producted to obtain the self-attention vector set of the target word, that is, the second weight, and the value in the self-attention vector set of the target word is reduced in dimension again. The dimension reduction method can be achieved by dividing by the square root of the key vector of the first keyword. The self-attention vector in the self-attention vector set of the target word is multiplied by the value vector corresponding to the target word, and the multiplication result is weighted and summed to obtain the self-attention output of the target word, that is, the second initial coding feature information of the target word. Repeat the above steps to complete the self-attention output of the remaining words in the second text, and finally obtain the second initial coding feature information of each word in the second text in different first representation subspaces.
[0118] Then, the second initial coding feature information of each word in the second text under each first representation subspace is weighted. For example, the second initial coding feature information of each word in the first text under different first representation subspaces is spliced, and the second initial coding feature information of each word after splicing is weighted to obtain the fused second initial coding feature information of each word in all first representation subspaces. Then, the fused second initial coding feature information of each word is input into the first residual module through the first feedforward neural network for feature extraction. For example, the fused second initial coding feature information of each word is input into the first residual module through the first feedforward neural network for summing and normalization to obtain the second coding feature information.
[0119] It should be noted that the post-training classification model may include an encoder network, and the encoder network may include a first attention module, a first feedforward neural network, and a first residual module. In the process of encoding the word feature information of each word in the second text to obtain the second encoded feature information of each word in the second text, it can be obtained by connecting multiple encoder networks in series. For example, the first encoder network parses the word feature information of each word in the second text to obtain the first layer of second encoded feature information of each word in the second text, and the second encoder network repeats the parsing or encoding steps of the first encoder network for the first layer of second encoded feature information of each word in the second text to obtain the second layer of second encoded feature information, and so on. The final second encoded feature information of each word in the second text is obtained by parsing the multi-layer encoder network. Among them, the number of encoder networks needs to be set according to actual application requirements.
[0120] After receiving the second encoding feature information output by the last layer of the encoder network, feature extraction is performed on the second encoding feature information of each word in the second text to obtain the initial second decoding feature information of each word in the second text. For example, the decoder network of the trained classification model can be used to extract the second encoding feature information of each word in the second text. The decoder network of the trained classification model includes at least one attention module, at least one second feedforward neural network and at least one second residual module. For example, the specific method can be as follows:
[0121] The second encoding feature information of each word in the second text is input into multiple second representation subspaces respectively, and the second attention module is used to extract the second encoding feature information of each word in each second representation subspace. The second attention module extracts the second encoding feature information of each word in a second representation subspace as an example to illustrate that the key vector and value vector are extracted from the second encoding feature information of each word, and the decoder network generates the intermediate vector of each word in the second representation subspace, and the intermediate vector is used as the query vector. The target word is determined in the second text, and the self-attention of the target word is calculated and decoded through the first keyword. For example, the self-attention vector set of the target word can be obtained by performing a dot product between the key vector of the first keyword and the query vector of the target word, and the value in the self-attention vector set of the target word is reduced in dimension again, and the dimension reduction method can be achieved by dividing by the square root of the key vector of the first keyword. The self-attention vector in the self-attention vector set of the target word is multiplied by the value vector corresponding to the target word, and the multiplication result is weighted and summed to obtain the self-attention output of the target word selected in the second text, and the initial second decoding feature information of the target word is obtained. The above steps are repeated to complete the self-attention output of the remaining words in the second text, and finally the initial second decoding feature information of all words in the second text in each second representation subspace is obtained. Then, the initial second decoding feature information of each word in the second text under each second representation subspace is weighted, for example, the initial second decoding feature information of each word in the second text under different second representation subspaces is spliced, and the initial second decoding feature information of each word after splicing is weighted to obtain the fused initial second decoding feature information of each word in all second representation subspaces. Then, the fused initial second decoding feature information of each word in the second text is input into the second residual module through the second feedforward neural network for feature extraction. For example, the fused initial second decoding feature information of each word is input into the second residual module through the second feedforward neural network for summing and normalization to obtain the second decoding feature information of each word in the second text. The second decoding feature information is linearly transformed to obtain the second attention feature information.
[0122] It should be noted here that the second attention module in the decoder network can also be called a "decoding-encoding attention layer", and the "decoding-encoding attention layer", the second feedforward neural network and the second residual module can form a decoder network of the trained classification model. In the process of decoding the second encoded feature information of each word in the second text to obtain the second decoded feature information of each word, it can be obtained by connecting multiple decoder networks in series. For example, the first decoder network extracts the second encoded feature information of each word in the second text to obtain the first layer of second decoding feature information of each word, and the second decoder network repeats the feature extraction steps of the first decoder network for the first layer of second decoding feature information of each word in the second text to obtain the second layer of second decoding feature information, and so on. The second decoding feature information of each word in the second text is finally outputted through feature extraction of multiple layers of decoder networks. Among them, the number of decoder networks is set according to actual application needs.
[0123] 106. Based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information, classify the text pair to be classified to obtain a classification result.
[0124] For example, the first semantic feature information and the second semantic feature information can be fused to obtain fused semantic feature information, and the matching degree between the first text and the second text can be calculated based on the first text information, the second text information and the fused semantic feature information, and the text pair to be classified can be classified based on the matching degree to obtain a classification result.
[0125] The fused semantic feature information may refer to the fusion information at the semantic level between the first text and the second text as a whole.
[0126] There are many ways to calculate the degree of match between the first text and the second text. For example, the first text information, the second text information and the fused semantic feature information may be feature expanded to obtain text expansion information, and the degree of match between the first text and the second text may be calculated based on the text expansion information.
[0127] There are many ways to expand features, for example, inputting the first text information, the second text information and the fused semantic feature information into a fusion layer, performing feature expansion through addition, subtraction, multiplication and other operations to obtain text expansion information. The fusion layer may only perform simple feature expansion operations, such as simple vector concatenation, without performing additional addition, subtraction and multiplication operations.
[0128] Next, the text expansion information is sent to the classification layer, where the classification label is related to the task. For text matching, the classification is a simple binary classification, that is, whether the first text and the second text are similar. For more complex tasks, it can be multi-classification, such as the matching degree of the first text and the second text, which can be divided into multiple levels and correspond to multiple labels.
[0129] As can be seen from the above, after obtaining the text pair to be classified, the text pair to be classified includes the first text and the second text. The first keyword of the first text and the second keyword of the second text can be selected from the text pair to be classified, and then the text in the text pair to be classified is subjected to feature extraction to obtain the word feature information and the first semantic feature information of the first text, and the word feature information and the second semantic feature information of the second text. Then, according to the word feature information of the first text and the word feature information of the second keyword, the first attention feature information is obtained, and according to the word feature information of the second text and the word feature information of the second keyword, the second attention feature information is obtained. Then, based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information, the text pair to be classified is classified to obtain the classification result. This scheme can effectively improve the accuracy of text classification; because this scheme not only considers the feature information of a single text, but also considers the interactive information between text pairs, the attention feature information is obtained by enhancing the influence of the keyword information of the text, and then the feature information and attention information of the text pair are used for classification, which can effectively improve the accuracy of text classification.
[0130] According to the method described in the previous embodiment, an example is given below to further illustrate it in detail.
[0131] In this embodiment, the text classification device is specifically integrated into an electronic device as an example for description.
[0132] (I) First, the classification model needs to be trained, which can be done as follows:
[0133] (1) Collect multiple text pair samples as training data sets.
[0134] The text pair samples include the labeled real classification results. For example, multiple text pair samples can be collected, such as obtaining text samples from a database or the Internet, and then feature extraction is performed on the text sample pairs to obtain word feature information input into the classification model.
[0135] (2) Training a preset classification model according to the training data set to obtain a trained classification model.
[0136] For example, the preset classification model can be used to classify the text pair to obtain a predicted classification result, obtain the actual classification result of the text pair, converge the preset classification model according to the predicted classification result and the actual classification result, and obtain a trained classification model.
[0137] For example, the word feature information can be encoded through an encoder network to obtain encoded feature information, and then the encoded feature information can be decoded to obtain decoded feature information. Then, the decoded feature information can be linearly transformed to obtain attention feature information. According to the word feature information and the attention feature information, the text pair is classified to obtain a predicted classification result.
[0138] For example, the pre-set classification model can be converged according to the predicted classification results and the actual classification results through the interpolation loss function to obtain the trained classification model.
[0139] Optionally, in order to improve the accuracy of context features, in addition to the interpolation loss function, other loss functions such as the cross entropy loss function may be used for convergence.
[0140] (II) Through the trained classification model, the text pairs to be classified can be classified. For details, please refer to Figure 2a and 2b .
[0141] like Figure 2a As shown in FIG. 1 , a text classification method can be described as follows:
[0142] 201. The electronic device obtains a text pair to be classified.
[0143] The text pair to be classified may include a first text and a second text. For example, the electronic device may obtain articles or information to be classified from a network database, and may also receive text uploaded by a user, such as an e-book or an electronic text. For example, the first text may be "How far is the sun from the earth", and the second text may be "What is the distance between the earth and the sun".
[0144] 202. The electronic device selects a first keyword of the first text and a second keyword of the second text from the pair of texts to be classified.
[0145] For example, the electronic device can specifically segment the text pair to be classified, obtain a word set of the text pair to be classified, determine the fields to which the first text and the second text respectively belong, and based on a preset dictionary corresponding to the field, determine the first keyword of the first text and the second keyword of the second text from the word set.
[0146] For example, the first text "How far is the sun from the earth" can be divided into "sun", "from", "earth", and "how far", from which the keywords can be determined to be "sun", "earth", and "how far". The second text "What is the distance between the earth and the sun" can be divided into "earth", "and", "sun", "between", "of", "distance", "is", and "how much", from which the keywords can be determined to be "earth", "sun", and "distance".
[0147] 203. The electronic device performs feature extraction on the texts in the text pair to be classified to obtain word feature information and first semantic feature information of the first text, and word feature information and second semantic feature information of the second text.
[0148] For example, the electronic device can specifically use the feature extraction module of the trained classification model to extract the position feature of each word in the first text to obtain the position feature of the first text, use the feature extraction module of the trained classification model to extract the word feature of each word in the first text to obtain the word feature of the first text, use the feature extraction module of the trained classification model to mark each word in the first text to obtain the mark feature of the first text, and perform feature fusion on the position feature, word feature and mark feature of the first text to obtain the word feature information of the first text. Figure 2b As shown, the word features of the first text can be token a1, token a2...token ai, the position features of the first text can be pos a1, pos a2...pos ai, the tag features of the first text can be seg a1, sega2...seg ai, and the word feature information of the first text can be Token A1, Token A2...Token Ai. At the same time, the label CLS of the first text, that is, the first semantic feature information, is extracted.
[0149] For example, the feature extraction module of the trained classification model can be used to extract the position feature of each word in the second text to obtain the position feature of the second text, the feature extraction module of the trained classification model can be used to extract the word feature of each word in the second text to obtain the word feature of the second text, the feature extraction module of the trained classification model can be used to mark each word in the second text to obtain the mark feature of the second text, and the position feature, word feature and mark feature of the second text can be fused to obtain the word feature information of the second text. The feature fusion here can be the sum of the three features of the position feature, word feature and mark feature of the second text, or other fusion methods, and so on. For example, Figure 2bAs shown, the word features of the second text may be token a1, token a2, ... token ai, the position features of the second text may be pos b1, pos b2, ... pos bi, the tag features of the second text may be seg b1, seg b2, ... seg bi, and the word feature information of the second text may be Token B1, Token B2, ... Token Bi. At the same time, the label CLS of the second text, that is, the second semantic feature information, is extracted.
[0150] 204. The electronic device obtains first attention feature information according to the word feature information of the first text and the word feature information of the second keyword.
[0151] For example, the electronic device can input the extracted feature information into the KeywordAttention layer. For example, a first query vector can be generated based on the word feature information of the first text, and a second key vector can be generated based on the word feature information of the second keyword. A first weight representing the relevance between the second keyword and each word in the first text is calculated based on the first query vector and the second key vector. A first value vector is generated based on the word feature information of the first text, and a weighted operation is performed on the first value vector based on the first weight to obtain first attention feature information.
[0152] For example, the word feature information of the first text and the word feature information of the second keyword are respectively input into a plurality of first representation subspaces, and the first attention module is used to extract features of the word feature information of each word in the first text and the word feature information of the second keyword in each first representation subspace. Taking the extraction of the word feature information of each word in the first text and the word feature information of the second keyword by the first attention module in a first representation subspace as an example, the first attention module performs dimensionality reduction on the word feature information of each word in the first text and the word feature information of the second keyword, generates a query vector, a key vector and a value vector in the reduced dimensionality word feature information, determines a target word in the word set of the first text, calculates a self-attention vector for the target word through the word feature information of the second keyword, and obtains the first initial encoding feature information of the target word.
[0153] Among them, the first initial encoded feature information output by the self-attention mechanism of the target word can be calculated by scaled dot-Product attention as follows:
[0154]
[0155] Among them, q i is the query vector of the target word, K Tis the key vector of the second keyword, V is the value vector of the target word, and d is the dimension of the key vector of the second keyword.
[0156] Through the calculation formula, it can be seen that the attention vector of the target word, that is, the first initial encoding feature information, can be calculated through these three vectors. For example, the self-attention vector set of the target word, that is, the first weight, can be obtained by performing a dot product between the key vector of the second keyword and the query vector of the target word. For example, when the query vector q of the word w_A in the first text interacts with the key vector K of the second keyword, only the keywords in the second text are considered. For example, the keywords of the second text "What is the distance between the earth and the sun" can be "earth", "sun", and "distance". There are 3 of them, recorded as kw_B1~kw_B3, then at this time
[0157] K=[h(kw_B1),..,h(kw_B3)]
[0158] That is, after the interaction of K and Q, there are 3 weights (i.e., the first weight set), which represents the influence of the 3 keywords in the second text on the current word (i.e., the target word) in the first text.
[0159] The value in the self-attention vector set of the target word is reduced in dimension again, and the dimension reduction method can be achieved by dividing by the square root of the key vector of the second keyword. The self-attention vector in the self-attention vector set of the target word is multiplied by the value vector corresponding to the target word, and the multiplication result is weighted summed to obtain the self-attention output of the target word, that is, the initial context information of the target word. The above steps are repeated to complete the self-attention output of the remaining words in the first text, and finally the first initial encoding feature information of each word in the first text in different first representation subspaces is obtained.
[0160] Then, the first initial coding feature information of each word in the first text under each first representation subspace is weighted. For example, the first initial coding feature information of each word in the first text under different first representation subspaces is spliced, and the first initial coding feature information of each word after splicing is weighted to obtain the fused first initial coding feature information of each word in all first representation subspaces. Then, the fused first initial coding feature information of each word is input into the first residual module through the first feedforward neural network for feature extraction. For example, the fused first initial coding feature information of each word is input into the first residual module through the first feedforward neural network for summing and normalization to obtain the first coding feature information.
[0161] After receiving the first encoding feature information output by the last layer of the encoder network, feature extraction is performed on the first encoding feature information of each word in the first text to obtain the initial first decoding feature information of each word in the first text. For example, the decoder network of the trained classification model can be used to extract the first encoding feature information of each word in the first text. The decoder network of the trained classification model includes at least one attention module, at least one second feedforward neural network and at least one second residual module. For example, the specific method can be as follows:
[0162] The first coded feature information of each word in the first text is input into multiple second representation subspaces respectively, and the first coded feature information of each word is extracted by the second attention module in each second representation subspace. The feature extraction of the first coded feature information of each word by the second attention module in a second representation subspace is used as an example to illustrate that the key vector and value vector are extracted from the first coded feature information of each word, and the decoder network generates the intermediate vector of each word in the second representation subspace, and the intermediate vector is used as the query vector. The target word is determined in the first text, and the self-attention of the target word is calculated and decoded through the second keyword. For example, the self-attention vector set of the target word can be obtained by performing a dot product between the key vector of the second keyword and the query vector of the target word, and the value in the self-attention vector set of the target word is reduced in dimension again, and the dimensionality reduction method can be achieved by dividing by the square root of the key vector of the second keyword. The self-attention vector in the self-attention vector set of the target word is multiplied by the value vector corresponding to the target word, and the multiplication result is weighted and summed to obtain the self-attention output of the target word selected in the first text, and the initial first decoding feature information of the target word is obtained. The above steps are repeated to complete the self-attention output of the remaining words in the first text, and finally the initial first decoding feature information of all words in the first text in each second representation subspace is obtained. Then, the initial first decoding feature information of each word in the first text under each second representation subspace is weighted. For example, the initial first decoding feature information of each word in the first text under different second representation subspaces is spliced, and the initial first decoding feature information of each word after splicing is weighted to obtain the fused initial first decoding feature information of each word in all second representation subspaces. Next, the fused initial first decoding feature information of each word in the first text is input into the second residual module through the second feedforward neural network for feature extraction. For example, the fused initial first decoding feature information of each word is input into the second residual module through the second feedforward neural network for summing and normalization to obtain the first decoding feature information of each word in the first text. Finally, the first decoding feature information is linearly transformed to obtain the first attention feature information.
[0163] For example, Figure 2bAs shown, the word feature information of the first text after the keyword attention layer is recorded as [h(A1),…,h(Ai)], corresponding to Token_A1~Token_Ai in the figure. At this time, it can be mapped to a vector h(A) with the same dimension as h(Ai), which represents the sentence vector after the sentence of the first text is fused with the keywords of the second text.
[0164] 205. The electronic device obtains second attention feature information based on the word feature information of the second text and the word feature information of the second keyword.
[0165] For example, the electronic device can specifically generate a second query vector based on the word feature information of the second text, and generate a first key vector based on the word feature information of the first keyword, and calculate a second weight representing the relevance between the first keyword and each word in the second text based on the second query vector and the first key vector. A second value vector is generated based on the word feature information of the second text, and a weighted operation is performed on the second value vector based on the second weight to obtain second attention feature information.
[0166] For example, the word feature information of the second text and the word feature information of the first keyword can be input into multiple first representation subspaces respectively, and the first attention module is used to extract the word feature information of each word in the second text and the word feature information of the first keyword in each first representation subspace. Taking the example of the first attention module extracting the word feature information of each word in the second text and the word feature information of the first keyword in a first representation subspace, the first attention module reduces the dimension of the word feature information of each word in the second text and the word feature information of the first keyword, generates a query vector, a key vector and a value vector in the reduced-dimensional word feature information, determines the target word in the word set of the second text, calculates the self-attention vector of the target word through the word feature information of the first keyword, and obtains the second initial encoding feature information of the target word.
[0167] Among them, the second initial encoding feature information output by the self-attention mechanism of the target word can be calculated by scaled dot-Product attention as follows:
[0168]
[0169] Among them, q i is the query vector of the target word, K T is the key vector of the first keyword, V is the value vector of the target word, and d is the dimension of the key vector of the first keyword.
[0170] Through the calculation formula, it can be seen that the attention vector of the target word, that is, the second initial encoding feature information, can be calculated through these three vectors. For example, the self-attention vector set of the target word, that is, the second weight, can be obtained by performing a dot product between the key vector of the first keyword and the query vector of the target word. For example, when the query vector q of the word w_B in the second text interacts with the key vector K of the second keyword, only the keywords of the first text are considered. For example, the first text "How far is the sun from the earth" has three keywords, namely "sun", "earth" and "how far", recorded as kw_A1~kw_A3, then at this time
[0171] K=[h(kw_A1),..,h(kw_A3)]
[0172] That is, after the interaction of K and Q, there are 3 weights (i.e., the second weight set), which represent the influence of the 3 keywords in the first text on the current word (i.e., the target word) in the second text.
[0173] The value in the self-attention vector set of the target word is reduced in dimension again, and the dimension reduction method can be achieved by dividing by the square root of the key vector of the first keyword. The self-attention vector in the self-attention vector set of the target word is multiplied by the value vector corresponding to the target word, and the multiplication result is weighted summed to obtain the self-attention output of the target word, that is, the second initial encoding feature information of the target word. The above steps are repeated to complete the self-attention output of the remaining words in the second text, and finally the second initial encoding feature information of each word in the second text in different first representation subspaces is obtained.
[0174] Then, the second initial coding feature information of each word in the second text under each first representation subspace is weighted. For example, the second initial coding feature information of each word in the first text under different first representation subspaces is spliced, and the second initial coding feature information of each word after splicing is weighted to obtain the fused second initial coding feature information of each word in all first representation subspaces. Then, the fused second initial coding feature information of each word is input into the first residual module through the first feedforward neural network for feature extraction. For example, the fused second initial coding feature information of each word is input into the first residual module through the first feedforward neural network for summing and normalization to obtain the second coding feature information.
[0175] After receiving the second encoding feature information output by the last layer of the encoder network, feature extraction is performed on the second encoding feature information of each word in the second text to obtain the initial second decoding feature information of each word in the second text. For example, the decoder network of the trained classification model can be used to extract the second encoding feature information of each word in the second text. The decoder network of the trained classification model includes at least one attention module, at least one second feedforward neural network and at least one second residual module. For example, the specific method can be as follows:
[0176] The second encoding feature information of each word in the second text is input into multiple second representation subspaces respectively, and the second attention module is used to extract the second encoding feature information of each word in each second representation subspace. The second attention module extracts the second encoding feature information of each word in a second representation subspace as an example to illustrate that the key vector and value vector are extracted from the second encoding feature information of each word, and the decoder network generates the intermediate vector of each word in the second representation subspace, and the intermediate vector is used as the query vector. The target word is determined in the second text, and the self-attention of the target word is calculated and decoded through the first keyword. For example, the self-attention vector set of the target word can be obtained by performing a dot product between the key vector of the first keyword and the query vector of the target word, and the value in the self-attention vector set of the target word is reduced in dimension again, and the dimension reduction method can be achieved by dividing by the square root of the key vector of the first keyword. The self-attention vector in the self-attention vector set of the target word is multiplied by the value vector corresponding to the target word, and the multiplication result is weighted and summed to obtain the self-attention output of the target word selected in the second text, and the initial second decoding feature information of the target word is obtained. The above steps are repeated to complete the self-attention output of the remaining words in the second text, and finally the initial second decoding feature information of all words in the second text in each second representation subspace is obtained. Then, the initial second decoding feature information of each word in the second text under each second representation subspace is weighted, for example, the initial second decoding feature information of each word in the second text under different second representation subspaces is spliced, and the initial second decoding feature information of each word after splicing is weighted to obtain the fused initial second decoding feature information of each word in all second representation subspaces. Then, the fused initial second decoding feature information of each word in the second text is input into the second residual module through the second feedforward neural network for feature extraction. For example, the fused initial second decoding feature information of each word is input into the second residual module through the second feedforward neural network for summing and normalization to obtain the second decoding feature information of each word in the second text. The second decoding feature information is linearly transformed to obtain the second attention feature information.
[0177] For example, Figure 2bAs shown, the word feature information of the second text after the keyword attention layer is recorded as [h(B1),…,h(Bi)], corresponding to Token_B1~Token_Bi in the figure. At this time, it can be mapped to a vector h(B) with the same dimension as h(Bi), which represents the sentence vector after the second text is fused with the keywords of the first text.
[0178] 206. The electronic device fuses the first semantic feature information and the second semantic feature information to obtain fused semantic feature information.
[0179] For example, the electronic device may specifically fuse the semantic level between the first text and the second text as a whole to obtain fused semantic feature information h(CLS).
[0180] 207. The electronic device calculates a matching degree between the first text and the second text according to the first text information, the second text information and the fused semantic feature information.
[0181] For example, the electronic device can specifically input the first text information, the second text information and the fused semantic feature information into a fusion layer, perform simple vector splicing, and obtain text expansion information H, H = [h(A); h(B); h(CLS)], and calculate the matching degree between the first text and the second text based on the text expansion information.
[0182] Next, the text expansion information is sent to the classification layer, where the classification label is related to the task. For text matching, the classification is a simple binary classification, that is, whether the first text and the second text are similar. For more complex tasks, it can be multi-classification, such as the matching degree of the first text and the second text, which can be divided into multiple levels and correspond to multiple labels.
[0183] 208. The electronic device classifies the to-be-classified text pair based on the matching degree to obtain a classification result.
[0184] For example, the electronic device can specifically input the text expansion information H into the classification layer to classify the first text and the second text, for example, to determine whether the first text "how far is the sun from the earth" and the second text "how far is the distance between the earth and the sun" are similar. Alternatively, the first text and the second text can be multi-classified, for example, the matching degree of the first text and the second text can be divided into multiple levels corresponding to multiple labels.
[0185] Although the sentence structures of the first text "How far is the sun from the earth" and the second text "What is the distance between the earth and the sun" are different, their keywords both contain the two entities "earth" and "sun", and the two semantically similar descriptions "how far" and "distance" can also be extracted. Since the trained classification model pays attention to the impact of keywords on each other, the classification accuracy of the trained classification model can be greatly enhanced.
[0186] As can be seen from the above, after obtaining the text pair to be classified, the text pair to be classified includes the first text and the second text. The first keyword of the first text and the second keyword of the second text can be selected from the text pair to be classified, and then the texts in the text pair to be classified are subjected to feature extraction to obtain word feature information and first semantic feature information of the first text, and word feature information and second semantic feature information of the second text. Then, according to the word feature information of the first text and the word feature information of the second keyword, the first attention feature information is obtained, and according to the word feature information of the second text and the word feature information of the second keyword, the second attention feature information is obtained. force feature information, and then, based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information, the text pair to be classified is classified to obtain a classification result; since the scheme not only considers the feature information of a single text, but also considers the interactive information between text pairs, the attention feature information is obtained by enhancing the influence of the keyword information of the text, and then the feature information and attention information of the text pair are used for classification, therefore, compared with merely combining the features of the text pair to be classified, or directly inputting them into a model with a self-attention mechanism, the accuracy of text classification can be effectively improved.
[0187] In order to better implement the above method, accordingly, an embodiment of the present invention further provides a text classification device, which can be integrated in an electronic device, and the electronic device can be a server, a terminal or other devices.
[0188] For example, Figure 3 As shown, the text classification device may include an acquisition unit 301, a selection unit 302, an extraction unit 303, a first calculation unit 304, a second calculation unit 305 and a classification unit 306, as follows:
[0189] (1) Acquisition unit 301;
[0190] The acquisition unit 301 is used to acquire the text pairs to be classified.
[0191] The pair of texts to be classified may include a first text and a second text. For example, the acquisition unit 301 may specifically acquire articles or information to be classified from a network database, or may receive texts uploaded by users, such as e-books or electronic texts.
[0192] (2) Selecting unit 302;
[0193] The selection unit 302 is used to select the first keyword of the first text and the second keyword of the second text from the text pair to be classified.
[0194] For example, the selection unit 302 can be specifically used to segment the text pair to be classified, obtain a word set of the text pair to be classified, determine the fields to which the first text and the second text respectively belong, and based on the preset dictionary corresponding to the field, determine the first keyword of the first text and the second keyword of the second text from the word set.
[0195] (3) Extraction unit 303;
[0196] The extraction unit 303 is used to extract features from the text in the pair of texts to be classified, and obtain word feature information and first semantic feature information of the first text, and word feature information and second semantic feature information of the second text.
[0197] Optionally, in some embodiments, the extraction unit may include a first extraction subunit, a second extraction subunit and a third extraction subunit, as follows:
[0198] A first extraction subunit is used to extract word features of each word in the first text to obtain word feature information of the first text;
[0199] A second extraction subunit is used to extract word features of each word in the second text to obtain word feature information of the second text;
[0200] The third extraction subunit is used to extract semantic features from the first text and the second text pair respectively to obtain first semantic feature information of the first text and second semantic feature information of the second text.
[0201] Optionally, in some embodiments, the first extraction subunit is specifically used to perform position feature extraction and word feature extraction on each word in the first text, respectively, to obtain the position feature and word feature of the first text, to mark each word in the first text, to obtain the mark feature of the first text, to perform feature fusion on the position feature, word feature and mark feature of the first text, to obtain the word feature information of the first text.
[0202] Optionally, in some embodiments, the second extraction subunit is specifically used to perform position feature extraction and word feature extraction on each word in the second text, respectively, to obtain the position feature and word feature of the second text, to mark each word in the second text, to obtain the mark feature of the second text, and to synthesize the position feature, word feature and mark feature of the second text to obtain the word feature information of the second text.
[0203] (4) a first calculation unit 304;
[0204] The first calculation unit 304 is used to obtain first attention feature information according to the word feature information of the first text and the word feature information of the second keyword.
[0205] The first attention feature information is word feature information focusing on the relevance between the second keyword and each word in the first text.
[0206] Optionally, in some embodiments, the first calculation unit may include a first calculation subunit and a first adjustment subunit, as follows:
[0207] A first calculation subunit, configured to calculate first correlation information between the second keyword and each word in the first text according to the word feature information of the first text and the word feature information of the second keyword;
[0208] The first adjustment subunit is used to adjust the word feature information of the first text based on the first correlation information to obtain first attention feature information.
[0209] Optionally, in some embodiments, the first computing subunit is specifically used to generate a first query vector based on word feature information of the first text, and to generate a second key vector based on word feature information of the second keyword, and to calculate a first weight representing the correlation between the second keyword and each word in the first text based on the first query vector and the second key vector.
[0210] At this time, the first adjustment subunit can be specifically used to adjust the word feature information of the first text based on the first weight to obtain first attention feature information.
[0211] Optionally, in some embodiments, the first adjustment subunit is specifically used to generate a first value vector according to word feature information of the first text, and perform a weighted operation on the first value vector based on the first weight to obtain first attention feature information.
[0212] According to the word feature information of the first text and the word feature information of the second keyword, the first attention feature information can be acquired by using a trained classification model. For specific implementation, please refer to the above method embodiment.
[0213] Optionally, the trained classification model can be pre-set by the operation and maintenance personnel or obtained by the text classification device through self-training. That is, the classification model can also include a collection unit and a training unit, as follows:
[0214] The collection unit is used to collect multiple text pair samples as training data sets.
[0215] The text pair samples include the labeled real classification results. For example, multiple text pair samples can be collected, such as obtaining text samples from a database or the Internet, and then feature extraction is performed on the text sample pairs to obtain word feature information input into the classification model.
[0216] The training unit is used to train the preset classification model according to the training data set to obtain a trained classification model.
[0217] For example, the preset classification model can be used to classify the text pair to obtain a predicted classification result, obtain the actual classification result of the text pair, converge the preset classification model according to the predicted classification result and the actual classification result, and obtain a trained classification model.
[0218] For example, the word feature information can be encoded through an encoder network to obtain encoded feature information, and then the encoded feature information can be decoded to obtain decoded feature information. Then, the decoded feature information can be linearly transformed to obtain attention feature information. According to the word feature information and the attention feature information, the text pair is classified to obtain a predicted classification result.
[0219] For example, the pre-set classification model can be converged according to the predicted classification results and the actual classification results through the interpolation loss function to obtain the trained classification model.
[0220] Optionally, in order to improve the accuracy of context features, in addition to the interpolation loss function, other loss functions such as the cross entropy loss function may be used for convergence.
[0221] (5) a second calculation unit 305;
[0222] The second calculation unit is used to obtain second attention feature information according to the word feature information of the second text and the word feature information of the second keyword.
[0223] The second attention feature information is word feature information that focuses on the correlation between the first keyword and each word in the second text. According to the word feature information of the second text and the word feature information of the second keyword, the second attention feature information can be obtained by using a trained classification model. For specific implementation, please refer to the previous method embodiment.
[0224] Optionally, in some embodiments, the second calculation unit may include a second calculation subunit and a second adjustment subunit, as follows:
[0225] A second calculation subunit, configured to calculate second correlation information between the first keyword and each word in the second text according to the word feature information of the second text and the word feature information of the second keyword;
[0226] The second adjustment subunit is used to adjust the word feature information of the second text based on the second correlation information to obtain second attention feature information.
[0227] Optionally, in some embodiments, the second computing subunit is specifically used to generate a second query vector based on word feature information of the second text, and to generate a first key vector based on word feature information of the first keyword, and to calculate a second weight representing the correlation between the first keyword and each word in the second text based on the second query vector and the first key vector.
[0228] At this time, the second adjustment subunit can be specifically used to adjust the word feature information of the second text based on the second weight to obtain second attention feature information.
[0229] Optionally, in some embodiments, the second adjustment subunit is specifically used to generate a second value vector according to word feature information of the second text, and perform a weighted operation on the second value vector based on the second weight to obtain second attention feature information.
[0230] (6) Classification unit 306.
[0231] A classification unit is used to classify the to-be-classified text pair based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information to obtain a classification result
[0232] Optionally, in some embodiments, the classification unit may include a fusion subunit, a third calculation subunit and a classification subunit, as follows:
[0233] A fusion subunit, used for fusing the first semantic feature information with the second semantic feature information to obtain fused semantic feature information;
[0234] A third calculation subunit, configured to calculate a matching degree between the first text and the second text according to the first text information, the second text information and the fused semantic feature information;
[0235] The classification subunit is used to classify the text pair to be classified based on the matching degree to obtain a classification result.
[0236] Optionally, in some embodiments, the third computing subunit is specifically used to perform feature expansion on the first text information, the second text information and the fused semantic feature information to obtain text expansion information, and calculate the matching degree between the first text and the second text based on the text expansion information.
[0237] In specific implementation, the above units can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units can refer to the previous method embodiments, which will not be repeated here.
[0238] As can be seen from the above, in this embodiment, after the acquisition unit 301 acquires the text pair to be classified, the text pair to be classified includes the first text and the second text, and the selection unit 302 can select the first keyword of the first text and the second keyword of the second text from the text pair to be classified, and then the extraction unit 303 performs feature extraction on the text in the text pair to be classified to obtain the word feature information and the first semantic feature information of the first text, and the word feature information and the second semantic feature information of the second text, and then the first calculation unit 304 obtains the first attention feature information based on the word feature information of the first text and the word feature information of the second keyword, and the second calculation unit 305 performs feature extraction on the text in the text pair to be classified to obtain the word feature information and the first semantic feature information of the first text, and the word feature information and the second semantic feature information of the second text. The word feature information of the first and second keywords is used to obtain the second attention feature information, and then the classification unit 306 classifies the text pair to be classified based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information to obtain a classification result. Since the scheme not only considers the feature information of a single text, but also considers the interactive information between text pairs, the attention feature information is obtained by enhancing the influence of the keyword information of the text, and then the feature information and attention information of the text pair are used for classification, so compared with merely combining the features of the text pair to be classified, or directly inputting it into a model with a self-attention mechanism, the accuracy of text classification can be effectively improved.
[0239] In addition, an embodiment of the present invention further provides an electronic device, such as Figure 4 As shown, it shows a schematic diagram of the structure of an electronic device involved in an embodiment of the present invention, specifically:
[0240] The electronic device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, and an input unit 404. Those skilled in the art will appreciate that Figure 4 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0241] The processor 401 is the control center of the electronic device, and uses various interfaces and lines to connect various parts of the entire electronic device. By running or executing software programs and / or modules stored in the memory 402, and calling data stored in the memory 402, the processor 401 performs various functions of the electronic device and processes data, thereby performing overall detection of the electronic device. Optionally, the processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401.
[0242] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.
[0243] The electronic device also includes a power supply 403 for supplying power to each component. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, so as to manage charging, discharging, power consumption and other functions through the power management system. The power supply 403 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators and other arbitrary components.
[0244] The electronic device may further include an input unit 404, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0245] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 401 in the electronic device will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the application programs stored in the memory 402, thereby realizing various functions, as follows:
[0246] A text pair to be classified is obtained, the text pair to be classified includes a first text and a second text, a first keyword of the first text and a second keyword of the second text can be selected from the text pair to be classified, and then feature extraction is performed on the texts in the text pair to be classified to obtain word feature information and first semantic feature information of the first text, and word feature information and second semantic feature information of the second text. Then, first attention feature information is obtained based on the word feature information of the first text and the word feature information of the second keyword, and second attention feature information is obtained based on the word feature information of the second text and the word feature information of the second keyword. Then, based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information, the text pair to be classified is classified to obtain a classification result.
[0247] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0248] From the above, it can be seen that after obtaining the text pair to be classified, the present embodiment includes a first text and a second text. The first keyword of the first text and the second keyword of the second text can be selected from the text pair to be classified, and then feature extraction is performed on the texts in the text pair to be classified to obtain word feature information and first semantic feature information of the first text, and word feature information and second semantic feature information of the second text. Then, first attention feature information is obtained based on the word feature information of the first text and the word feature information of the second keyword, and second attention feature information is obtained based on the word feature information of the second text and the word feature information of the second keyword. Then, based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information, the text pair to be classified is classified to obtain a classification result. This scheme can effectively improve the accuracy of text classification; since this scheme not only considers the feature information of a single text, but also the interactive information between text pairs, it obtains attention feature information by enhancing the influence of the text's keyword information, and then classifies the text pairs based on their feature information and attention information. Therefore, compared with simply combining the features of the text pairs to be classified, or directly inputting them into a model with a self-attention mechanism, it can effectively improve the accuracy of text classification.
[0249] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0250] To this end, an embodiment of the present invention further provides a storage medium in which a plurality of instructions are stored, and the instructions can be loaded by a processor to execute the steps in any text classification method provided in the embodiment of the present invention. For example, the instructions can execute the following steps:
[0251] A text pair to be classified is obtained, the text pair to be classified includes a first text and a second text, a first keyword of the first text and a second keyword of the second text can be selected from the text pair to be classified, and then feature extraction is performed on the texts in the text pair to be classified to obtain word feature information and first semantic feature information of the first text, and word feature information and second semantic feature information of the second text. Then, first attention feature information is obtained based on the word feature information of the first text and the word feature information of the second keyword, and second attention feature information is obtained based on the word feature information of the second text and the word feature information of the second keyword. Then, based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information, the text pair to be classified is classified to obtain a classification result.
[0252] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0253] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0254] Since the instructions stored in the storage medium can execute the steps in any text classification method provided in the embodiments of the present invention, the beneficial effects that can be achieved by any text classification method provided in the embodiments of the present invention can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0255] The above is a detailed introduction to a text classification method, device and storage medium provided in an embodiment of the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A text classification method, characterized in that: include: Acquire a text pair to be classified, wherein the text pair to be classified includes a first text and a second text; Selecting a first keyword of the first text and a second keyword of the second text from the pair of texts to be classified; Performing feature extraction on the texts in the to-be-classified text pair to obtain word feature information and first semantic feature information of the first text, and word feature information and second semantic feature information of the second text; Calculating first correlation information between the second keyword and each word in the first text according to the word feature information of the first text and the word feature information of the second keyword; Adjusting the word feature information of the first text based on the first correlation information to obtain first attention feature information, where the first attention feature information is word feature information focusing on the correlation between the second keyword and each word in the first text; Calculating second correlation information between the first keyword and each word in the second text according to the word feature information of the second text and the word feature information of the second keyword; Based on the second correlation information, the word feature information of the second text is adjusted to obtain second attention feature information, where the second attention feature information is word feature information focusing on the correlation between the first keyword and each word in the second text; Based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information, the text pair to be classified is classified to obtain a classification result.
2. The method according to claim 1, characterized in that The first correlation information includes a first weight, and the calculating, based on the word feature information of the first text and the word feature information of the second keyword, the first correlation information between the second keyword and each word in the first text includes: generating a first query vector according to word feature information of the first text, and generating a second keyword vector according to word feature information of the second keyword; Calculating a first weight representing the relevance between the second keyword and each word in the first text according to the first query vector and the second key vector; The adjusting the word feature information of the first text based on the correlation information to obtain the first attention feature information includes: adjusting the word feature information of the first text based on the first weight to obtain the first attention feature information.
3. The method according to claim 2, characterized in that The step of adjusting the word feature information of the first text based on the first weight to obtain first attention feature information includes: Generate a first value vector according to word feature information of the first text; Based on the first weight, a weighted operation is performed on the first value vector to obtain first attention feature information.
4. The method according to any one of claims 1 to 3, characterized in that: The feature extraction of the text in the to-be-classified text pair to obtain word feature information and first semantic feature information of the first text, and word feature information and second semantic feature information of the second text includes: Extracting word features from each word in the first text to obtain word feature information of the first text; Extracting word features from each word in the second text to obtain word feature information of the second text; Semantic feature extraction is performed on the first text and the second text pair respectively to obtain first semantic feature information of the first text and second semantic feature information of the second text.
5. The method according to claim 4, characterized in that The extracting word features of each word in the first text to obtain word feature information of the first text includes: Performing position feature extraction and word feature extraction on each word in the first text to obtain position features and word features of the first text; Marking each word in the first text to obtain a marking feature of the first text; Feature fusion is performed on the position features, word features and tag features of the first text to obtain word feature information of the first text.
6. The method according to claim 4, characterized in that The extracting word features of each word in the second text to obtain word feature information of the second text includes: Performing position feature extraction and word feature extraction on each word in the second text to obtain position features and word features of the second text; Marking each word in the second text to obtain a marking feature of the second text; The position feature, word feature and mark feature of the second text are synthesized to obtain word feature information of the second text.
7. The method according to any one of claims 1 to 3, characterized in that: The step of selecting a first keyword of the first text and a second keyword of the second text from the pair of texts to be classified includes: Performing word segmentation on the text pair to be classified to obtain a word set of the text pair to be classified; Determine the fields to which the first text and the second text belong respectively; Based on a preset dictionary corresponding to the field, a first keyword of the first text and a second keyword of the second text are determined from the word set.
8. The method according to any one of claims 1 to 3, characterized in that: The classifying the to-be-classified text pair based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information to obtain a classification result includes: fusing the first semantic feature information and the second semantic feature information to obtain fused semantic feature information; Calculating a matching degree between the first text and the second text according to the first text information, the second text information and the fused semantic feature information; The to-be-classified text pairs are classified based on the matching degree to obtain a classification result.
9. The method according to claim 8, characterized in that The calculating the matching degree between the first text and the second text according to the first text information, the second text information and the fused semantic feature information includes: Performing feature expansion on the first text information, the second text information and the fused semantic feature information to obtain text expansion information; The matching degree between the first text and the second text is calculated according to the text expansion information.
10. A text classification device, characterized in that: include: An acquisition unit, configured to acquire a text pair to be classified, wherein the text pair to be classified includes a first text and a second text; A selection unit, configured to select a first keyword of the first text and a second keyword of the second text from the pair of texts to be classified; An extraction unit, used for performing feature extraction on the text in the to-be-classified text pair to obtain word feature information and first semantic feature information of the first text, and word feature information and second semantic feature information of the second text; A first calculation unit is used to calculate first correlation information between the second keyword and each word in the first text according to the word feature information of the first text and the word feature information of the second keyword; adjust the word feature information of the first text based on the first correlation information to obtain first attention feature information, where the first attention feature information is word feature information focusing on the correlation between the second keyword and each word in the first text; A second calculation unit is used to calculate second correlation information between the first keyword and each word in the second text according to the word feature information of the second text and the word feature information of the second keyword; based on the second correlation information, the word feature information of the second text is adjusted to obtain second attention feature information, where the second attention feature information is word feature information focusing on the correlation between the first keyword and each word in the second text; A classification unit is used to classify the text pair to be classified based on the first attention feature information, the second attention feature information, the first semantic feature information, and the second semantic feature information to obtain a classification result.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the steps in the text classification method according to any one of claims 1 to 9.
12. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the method according to any one of claims 1 to 9 are implemented.
