Text processing method, device, computer equipment and storage medium
By obtaining the first and second features of a word and using a feature encoding model for encoding and training, the problem of inaccurate encoding features in the prior art is solved, and the accuracy and effect of text processing are improved.
Patent Information
- Application Number
- CN202111081005.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-15
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2041-09-15
AI Technical Summary
In the prior art, the coding features of text only consider the number of occurrences of words, which results in inaccurate coding features.
By obtaining the first feature and the second feature of the word, encoding them respectively using a feature encoding model, and training the model based on the correlation feature between the first encoding feature and the second encoding feature, the accuracy of the encoding feature is improved.
It improves the accuracy of the feature encoding model, enhances the accuracy of the encoding features, takes into account the semantics and contextual relationships of words, and improves the effect of text processing.
Smart Images

Figure CN114281933B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a text processing method, apparatus, computer equipment, and storage medium. Background Art
[0002] Text is an important object in machine learning and natural language processing. The encoding features of text can be widely used in various fields such as text recognition and text search, and have important research significance.
[0003] In related technologies, a word frequency feature is obtained from a text. This word frequency feature represents the number of times each word appears in the text. By encoding this word frequency feature, a coding feature corresponding to the text is obtained. However, this method only considers the number of times each word appears in the text, and the resulting coding feature is not accurate enough. Summary of the Invention
[0004] The embodiments of the present application provide a text processing method, apparatus, computer device, and storage medium that can improve the accuracy of coding features. The technical solution is as follows:
[0005] In one aspect, a text processing method is provided, the method comprising:
[0006] Obtaining a first feature corresponding to each word in a first text and a second feature corresponding to the first text, wherein the first feature corresponding to the word represents the semantics of the word in the first text, and the second feature is determined based on the first feature corresponding to each word;
[0007] Calling a feature encoding model to encode each of the first features and the second features respectively to obtain a first encoding feature corresponding to each of the first features and a second encoding feature corresponding to the second features;
[0008] training the feature encoding model based on a first correlation feature between each of the first encoding features and the second encoding features, wherein the first correlation feature indicates a correlation degree between the first encoding feature and the second encoding feature;
[0009] Call the trained feature encoding model to encode the features of any text.
[0010] In another aspect, a text processing device is provided, comprising:
[0011] a feature acquisition module, configured to acquire a first feature corresponding to each word in a first text and a second feature corresponding to the first text, wherein the first feature corresponding to the word represents the semantics of the word in the first text, and the second feature is determined based on the first feature corresponding to each word;
[0012] a first encoding module, configured to call a feature encoding model to encode each of the first features and the second features respectively, to obtain a first encoding feature corresponding to each of the first features and a second encoding feature corresponding to each of the second features;
[0013] a model training module, configured to train the feature coding model based on a first correlation feature between each of the first coding features and the second coding features, wherein the first correlation feature indicates a degree of correlation between the first coding feature and the second coding feature;
[0014] The second encoding module is used to call the trained feature encoding model to encode the features of any text.
[0015] Optionally, the model training module includes:
[0016] a loss value determining unit, configured to determine a loss value based on a first correlation feature corresponding to each of the first coding features, wherein the loss value is negatively correlated with the first correlation feature;
[0017] A model training unit is used to train the feature encoding model based on the loss value.
[0018] Optionally, the device further includes an association determination module, configured to:
[0019] Invoking a discriminant model to discriminate the first coding feature and the second coding feature to obtain a discrimination result, wherein the discrimination result indicates a likelihood that the word corresponding to the first coding feature belongs to the text corresponding to the second coding feature;
[0020] The discrimination result is determined as a first associated feature corresponding to the first coding feature.
[0021] Optionally, the model training module includes:
[0022] a loss value determining unit, configured to determine a loss value based on a first correlation feature corresponding to each of the first coding features, wherein the loss value is negatively correlated with the first correlation feature;
[0023] A model training unit is used to train the feature encoding model and the discriminant model based on the loss value.
[0024] Optionally, the device further comprises:
[0025] The feature acquisition module is further configured to acquire a third feature corresponding to a word in a second text, wherein the third feature corresponding to the word represents the semantics of the word in the second text, and the second text is different from the first text;
[0026] The first encoding module is further configured to call the feature encoding model to encode the third feature to obtain a third encoding feature corresponding to the third feature;
[0027] an association determination module, configured to determine a second association feature between the third coding feature and the second coding feature, wherein the second association feature indicates a degree of association between the third coding feature and the second coding feature;
[0028] The loss value determining unit is configured to:
[0029] The loss value is determined based on each of the first correlation feature and the second correlation feature, wherein the loss value is negatively correlated with the first correlation feature and the loss value is positively correlated with the second correlation feature.
[0030] Optionally, the first text includes words located at multiple positions, and the loss value determining unit is configured to:
[0031] Determine a loss component corresponding to each position based on a first association feature and a second association feature corresponding to each position, respectively, where the loss component is positively correlated with the first association feature and negatively correlated with the second association feature, wherein the first association feature corresponding to the position refers to the first association feature corresponding to the word located at the position in the first text, and the second association feature corresponding to the position refers to the second association feature corresponding to the word located at the position in the second text;
[0032] The loss components corresponding to each of the positions are fused to obtain the loss value, and the loss value is negatively correlated with the loss components.
[0033] Optionally, the device further comprises:
[0034] The feature acquisition module is further configured to determine a first text feature corresponding to the first text, where the first text feature represents the semantics of the first text;
[0035] The first encoding module is further configured to call the feature encoding model to encode the first text feature to obtain a fourth encoding feature;
[0036] an association determination module, configured to determine a third association feature between the fourth coding feature and the second coding feature, wherein the third association feature indicates a degree of association between the fourth coding feature and the second coding feature;
[0037] The loss value determining unit is configured to:
[0038] Based on each of the first correlation feature and the third correlation feature, the loss value is determined, and the loss value is negatively correlated with the first correlation feature and the third correlation feature.
[0039] Optionally, the device further comprises:
[0040] The feature acquisition module is further configured to determine a second text feature corresponding to a second text, wherein the second text feature represents the semantics of the second text, and the second text is different from the first text;
[0041] The first encoding module is further configured to call the feature encoding model to encode the second text feature to obtain a fifth encoding feature;
[0042] an association determination module, configured to determine a fourth association feature between the fifth coding feature and the second coding feature, wherein the fourth association feature indicates a degree of association between the fifth coding feature and the second coding feature;
[0043] The loss value determining unit is configured to:
[0044] The loss value is determined based on each of the first correlation feature, the third correlation feature, and the fourth correlation feature, wherein the loss value is negatively correlated with the first correlation feature and the third correlation feature, and the loss value is positively correlated with the fourth correlation feature.
[0045] Optionally, the feature acquisition module includes:
[0046] a word feature determination unit, configured to determine a word feature corresponding to each word in the first text;
[0047] The first feature determining unit is configured to determine a first feature corresponding to each of the words based on a word feature corresponding to each of the words and a word feature corresponding to at least one word following each of the words.
[0048] Optionally, the first feature determining unit is configured to:
[0049] determining a plurality of target numbers, the plurality of target numbers being different and less than the number of words in the first text;
[0050] For each target number, determining a word group corresponding to the word, and determining a first sub-feature corresponding to the word based on a word feature corresponding to each word in the word group, wherein the word group includes the word and subsequent words of the word, the subsequent words of the word refer to words located after the word, and the number of the subsequent words in the word group is not greater than the target number;
[0051] The multiple first sub-features corresponding to the word are fused to obtain the first feature corresponding to the word.
[0052] Optionally, the first feature determining unit is configured to:
[0053] When the total number of subsequent words of the word is not less than the target number, the word and the target number of words following the word are determined as the word group corresponding to the word;
[0054] When the total number of subsequent words of the word is less than the target number, the word and each word following the word are determined as the word group corresponding to the word.
[0055] Optionally, the first feature determining unit is configured to:
[0056] Performing convolution processing on the word features corresponding to each word in the word group to obtain the convolution features corresponding to each word;
[0057] The sum of the multiple convolution features is determined as the first sub-feature corresponding to the word.
[0058] Optionally, the feature acquisition module includes:
[0059] A second feature determination unit is configured to perform mean pooling on the first features corresponding to the plurality of words in the first text to obtain the second feature; or
[0060] The second feature determining unit is configured to determine a median of first features corresponding to a plurality of words in the first text as the second feature.
[0061] Optionally, the second encoding module is configured to:
[0062] Determine the word features corresponding to each word in the target text;
[0063] Determining a fourth feature corresponding to each of the words based on the word feature corresponding to each of the words in the target text and the word feature corresponding to at least one word following each of the words;
[0064] determining a fifth feature corresponding to the target text based on the fourth feature corresponding to each of the words in the target text;
[0065] The trained feature encoding model is called to encode the fifth feature to obtain a sixth encoded feature corresponding to the fifth feature.
[0066] Optionally, the device further comprises:
[0067] A feature query module is used to obtain candidate coding features corresponding to multiple candidate texts, where the candidate coding features corresponding to each candidate text are obtained by encoding by calling the trained coding model;
[0068] a similarity determination module, configured to respectively determine a similarity between each candidate coding feature and the sixth coding feature;
[0069] The text determination module is used to determine the candidate texts corresponding to the candidate coding features with a similarity greater than a target threshold as texts similar to the target text.
[0070] On the other hand, a computer device is provided, comprising a processor and a memory, wherein the memory stores at least one computer program, and the at least one computer program is loaded and executed by the processor to implement the operations performed in the text processing method described in the above aspects.
[0071] On the other hand, a computer-readable storage medium is provided, in which at least one computer program is stored. The at least one computer program is loaded and executed by a processor to implement the operations performed in the text processing method described in the above aspects.
[0072] On the other hand, a computer program product is provided, which includes a computer program, and the computer program is loaded and executed by a processor to implement the operations performed in the text processing method as described in the above aspects.
[0073] The method, apparatus, computer device, and storage medium provided in the embodiments of the present application utilize a feature coding model to perform feature coding on the first feature and the second feature, respectively, to obtain a first coding feature and a second coding feature. Since the first feature contains the semantics of some words in the text, and the second feature contains the semantics of each word in the same text, the correlation between the first feature and the second feature is relatively high. If the accuracy of the feature coding model is sufficiently high, the correlation between the obtained first coding feature and the second coding feature is also relatively high. Therefore, training the feature coding model based on the correlation feature between each first coding feature and the second coding feature can improve the accuracy of the feature coding model, thereby improving the accuracy of the coding feature obtained by the feature coding model. BRIEF DESCRIPTION OF THE DRAWINGS
[0074] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0075] Figure 1 It is a schematic diagram of an implementation environment provided by an embodiment of the present application.
[0076] Figure 2 This is a flowchart of a text processing method provided in an embodiment of the present application.
[0077] Figure 3 This is a flowchart of a text processing method provided in an embodiment of the present application.
[0078] Figure 4 This is a flowchart of a model training method provided in an embodiment of the present application.
[0079] Figure 5 This is a flowchart of a text processing method provided in an embodiment of the present application.
[0080] Figure 6 It is a schematic diagram of a text processing method provided in an embodiment of the present application.
[0081] Figure 7 This is a flowchart of a text search method provided in an embodiment of the present application.
[0082] Figure 8 It is a schematic diagram of a text search method provided in an embodiment of the present application.
[0083] Figure 9 It is a structural diagram of a text processing device provided in an embodiment of the present application.
[0084] Figure 10 It is a structural diagram of another text processing device provided in an embodiment of the present application.
[0085] Figure 11 This is a schematic diagram of the structure of a terminal provided in an embodiment of the present application.
[0086] Figure 12 This is a structural diagram of a server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0087] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0088] It is understood that the terms "first," "second," and the like used herein may be used to describe various concepts, but unless otherwise specified, these concepts are not limited by these terms. These terms are used solely to distinguish one concept from another. For example, a first document may be referred to as a second document, and similarly, a second document may be referred to as a first document without departing from the scope of this application.
[0089] Here, "at least one" means one or more than one. For example, at least one text can be one text, two texts, three texts, or any other integer greater than or equal to one. "Multiple" means two or more than two. For example, "multiple" can be two texts, three texts, or any other integer greater than or equal to two. "Each" means each of at least one. For example, "each text" means each text in the multiple texts. If the multiple texts are three texts, "each text" means each of the three texts.
[0090] Artificial Intelligence (AI) refers to the theories, methods, techniques, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, to perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that seeks to understand the essence of intelligence and produce new intelligent machines that can respond in a manner similar to human intelligence. AI also involves studying the design principles and implementation methods of various intelligent machines, enabling them to possess the capabilities of perception, reasoning, and decision-making.
[0091] Artificial intelligence (AI) technology is a comprehensive discipline encompassing a wide range of fields, encompassing both hardware and software technologies. Foundational AI technologies generally include sensors, specialized AI chips, cloud computing, distributed storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, speech processing, natural language processing, as well as machine learning / deep learning, autonomous driving, and smart transportation.
[0092] Machine learning (ML) is a multidisciplinary field that encompasses probability theory, statistics, approximation theory, convex analysis, and algorithmic complexity theory. It specifically studies how computers can simulate or implement human learning behaviors to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is at the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications span all areas of AI. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and learning through demonstration.
[0093] Natural language processing (NLP) is a key area of research in computer science and artificial intelligence. It studies the theories and methods that enable effective communication between humans and computers using natural language. Natural language processing (NLP) integrates linguistics, computer science, and mathematics. Therefore, research in this field involves natural language—the language we use in everyday life—and is closely linked to the study of linguistics. Natural language processing technologies typically include text processing, semantic understanding, machine translation, robotic question answering, and knowledge graphs.
[0094] The following describes the text processing method provided in the embodiment of the present application based on artificial intelligence technology and natural language processing technology.
[0095] The text processing method provided in the embodiment of the present application can be used in a computer device. Optionally, the computer device is a terminal or a server. Optionally, the server is an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Optionally, the terminal is a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, etc., but is not limited to this.
[0096] In one possible implementation, the computer program involved in the embodiments of the present application can be deployed and executed on a computer device, or on multiple computer devices located at one location, or on multiple computer devices distributed at multiple locations and interconnected through a communication network. Multiple computer devices distributed at multiple locations and interconnected through a communication network can constitute a blockchain system.
[0097] In one possible implementation, the computer device used to train the feature encoding model in the embodiment of the present application is a node in the blockchain system. The node can store the trained feature encoding model in the blockchain. Thereafter, the node or the node corresponding to other devices in the blockchain can encode the features of any text based on the feature encoding model.
[0098] Figure 1 This is a schematic diagram of an implementation environment provided by an embodiment of the present application, see Figure 1The implementation environment includes: a terminal 101 and a server 102. The terminal 101 and the server 102 are connected via a wireless or wired network. Optionally, the server 102 is used to train a feature coding model using the method provided in the embodiment of the present application, and the feature coding model is used to encode the features of any text. The server 102 sends the trained feature coding model to the terminal 101, and the terminal 101 can call the feature coding model to encode the features of any text to obtain coding features. The coding features can be applied to various fields such as text recognition or text retrieval.
[0099] In one possible implementation, terminal 101 runs an application client provided by the server. Server 102 stores a trained feature encoding model in the application client, which has text processing capabilities. Terminal 101, based on the application client, invokes the feature encoding model to encode features of any text to obtain encoded features.
[0100] It should be noted that Figure 1 In the example, the server 102 trains the feature coding model and sends it to the terminal 101. In another embodiment, the terminal 101 may directly train the feature coding model.
[0101] Figure 2 This is a flowchart of a text processing method provided by an embodiment of the present application. The execution subject of the embodiment of the present application is a computer device, see Figure 2 , the method comprising:
[0102] 201. A computer device obtains a first feature corresponding to each word in a first text and a second feature corresponding to the first text.
[0103] The first text can be any type of text. The first feature corresponding to a word represents the semantic meaning of the word in the first text. The second feature is determined based on the first feature corresponding to each word, so the second feature can represent the semantic meaning of each word in the first text. The first and second features are features in a continuous space.
[0104] 202. The computer device calls a feature coding model to encode each first feature and second feature respectively to obtain a first coding feature corresponding to each first feature and a second coding feature corresponding to each second feature.
[0105] The feature encoding model is used to encode text features. After obtaining each first feature and second feature, the computer device invokes the feature encoding model to encode each first feature, obtaining a first encoding feature corresponding to each first feature. The computer device then invokes the feature encoding model to encode each second feature, obtaining a second encoding feature corresponding to the second feature.
[0106] 203. The computer device trains a feature coding model based on the first correlation feature between each first coding feature and the second coding feature.
[0107] The computer device obtains a first correlation feature between each first coding feature and the second coding feature, where the first correlation feature corresponding to the first coding feature can indicate a correlation degree between the first coding feature and the second coding feature.
[0108] The computer device trains the feature encoding model based on the first correlation feature. Since the first and second coding features are obtained by the feature encoding model by encoding the first and second features, respectively, and the first and second features can represent the semantics of words in the same text, the correlation between the first and second features is relatively high. The higher the correlation between the first and second coding features, the higher the encoding capability of the feature encoding model, that is, the more accurate the feature encoding model. Since the first correlation feature represents the correlation between the first and second coding features, the computer device can use the first correlation feature to train the feature encoding model so that the correlation between the coding features obtained by the feature encoding model becomes increasingly higher, thereby improving the accuracy of the feature encoding model.
[0109] 204. The computer device calls the trained feature encoding model to encode the features of any text.
[0110] The computer device trains the feature encoding model to obtain a trained feature encoding model. The computer device can call the trained feature encoding model to encode features of any text to obtain corresponding encoding features.
[0111] It should be noted that to train the feature encoding model, the computer device first obtains multiple texts as a sample dataset. The process of training the feature encoding model based on the multiple texts includes multiple iterations, with training based on at least one text in each iteration. Steps 201-204 in the embodiment of the present application are described using the example of processing a single text in a single iteration.
[0112] The method provided in the embodiment of the present application utilizes a feature coding model to perform feature coding on the first feature and the second feature respectively to obtain a first coding feature and a second coding feature. Since the first feature contains the semantics of some words in the text and the second feature contains the semantics of each word in the same text, the correlation between the first feature and the second feature is relatively high. If the accuracy of the feature coding model is high enough, the correlation between the obtained first coding feature and the second coding feature is also relatively high. Therefore, training the feature coding model based on the correlation feature between each first coding feature and the second coding feature can improve the accuracy of the feature coding model, thereby improving the accuracy of the coding feature obtained by the feature coding model.
[0113] Figure 3 This is a flowchart of a text processing method provided by an embodiment of the present application. The execution subject of the embodiment of the present application is a computer device, see Figure 3 , the method comprising:
[0114] 301. A computer device obtains a first feature corresponding to each word in a first text and a second feature corresponding to the first text.
[0115] The first feature corresponding to the word represents the semantics of the word in the first text, and the second feature is determined based on the first feature corresponding to each word. Since the first feature can characterize the semantics of some words in the first text, and the second feature can characterize the semantics of each word in the first text, it can be understood that the first feature is a "local" feature of the first text, and the second feature is a "global" feature of the first text. Each word in the first text corresponds to a first feature, and the first text corresponds to a second feature, and the first feature and the second feature are features in a continuous space. Optionally, the first feature and the second feature are feature vectors or feature matrices, etc., which are not limited in the embodiments of the present application.
[0116] In one possible implementation, a computer device obtains a first text, determines a word feature corresponding to each word in the first text, and determines a first feature corresponding to each word based on the word feature corresponding to each word and the word feature corresponding to at least one word following each word. The word feature corresponding to a word represents the semantics corresponding to the word, for example, the word feature is a BERT (Bidirectional Encoder Representations from Transformers) feature, or the word feature is a word2vec (word to vector) feature, etc. The embodiment of the present application does not limit the type of word feature.
[0117] Among them, multiple words in the first text are arranged according to word order, and the arranged multiple words constitute a complete sentence. Since the word feature corresponding to a word can only represent the semantics of a single word, it cannot represent the semantics between the contexts in the text. Therefore, for each word, the computer device determines the word feature corresponding to the word and the word feature corresponding to the word after the word to determine the first feature corresponding to the word. The first feature integrates the semantics of the word itself and the semantics around the word. Therefore, the first feature can represent the contextual relationship between the word and the surrounding words, thereby increasing the amount of information contained in the first feature.
[0118] Optionally, the computer device determines multiple target quantities, each of which is different and less than the number of words in the first text. For each target quantity, a word group corresponding to the word is determined, and based on the word features corresponding to each word in the word group, a first sub-feature corresponding to the word is determined, wherein the word group includes the word and the subsequent words of the word, and the subsequent words of the word refer to the words located after the word, and the number of subsequent words in the word group is not greater than the target quantity. The computer device fuses the multiple first sub-features corresponding to the word to obtain the first feature corresponding to the word. For example, the computer device splices the multiple first sub-features to obtain the first feature.
[0119] To further increase the information content of the first feature, the computer device may fuse multiple first sub-features corresponding to a word into the first feature. To extract first sub-features of varying granularity, different first sub-features may be determined based on word features corresponding to different numbers of words. Therefore, the computer device first obtains multiple different target quantities, optionally pre-set by the computer device.
[0120] For each target quantity, the computer device determines at least one subsequent word that is no greater than the target quantity following the word, forms a word group corresponding to the word with the word and the determined subsequent words, and determines a word feature corresponding to the word and a word feature corresponding to the subsequent words in the word group. Based on the word feature corresponding to each word in the word group, the computer device determines a first sub-feature corresponding to the word. The computer device sequentially traverses each target quantity in the multiple target quantities in the above manner, thereby obtaining a first sub-feature corresponding to each target quantity, that is, obtaining multiple first sub-features corresponding to the word.
[0121] Optionally, for each target number, the computer device determines the word group corresponding to the word, including the following two situations: when the total number of subsequent words of the word is not less than the target number, the word and the target number of words following the word are determined as the word group corresponding to the word. When the total number of subsequent words of the word is less than the target number, the word and each word following the word are determined as the word group corresponding to the word.
[0122] Among them, the computer device can add the word to the word group, and obtain the first word after the word, add the first word to the word group, and the computer device continues to obtain the second word after the word, and adds the second word to the word group, until the computer device obtains the target number of words after the word, and adds the target number of words to the word group, that is, when the total number of subsequent words of the word is not less than the target number, the computer device can obtain the target number of subsequent words, so the computer device adds the obtained target number of subsequent words to the word group. If the computer device has obtained the last word in the first text and added the last word to the word group, but the computer device has not obtained the target number of words at this time, that is, when the total number of subsequent words of the word is less than the target number, the computer device cannot obtain the target number of subsequent words, so the computer device adds each obtained subsequent word to the word group.
[0123] Alternatively, the computer device may first determine the total number of subsequent words of the word and determine whether the total number of subsequent words is less than a target number. If the total number is not less than the target number, the computer device may directly obtain the target number of subsequent words following the word, and determine the word and the obtained target number of subsequent words as the word group corresponding to the word. If the total number is less than the target number, the computer device may directly obtain each subsequent word following the word, and determine the word and each obtained subsequent word as the word group corresponding to the word.
[0124] For example, the target numbers are 0, 2, and 4 respectively. The computer device determines a first sub-feature corresponding to the word based on the word feature corresponding to the word, determines a first sub-feature corresponding to the word based on the word feature corresponding to the word and the word features corresponding to the two words following the word, determines a first sub-feature corresponding to the word based on the word feature corresponding to the word and the word features corresponding to the four words following the word, and finally obtains three first sub-features corresponding to the word.
[0125] Optionally, the computer device determines a first sub-feature corresponding to each word in the word group based on a word feature corresponding to each word in the word group, including: performing convolution processing on the word feature corresponding to each word in the word group to obtain a convolution feature corresponding to each word, and determining the sum of the multiple convolution features as the first sub-feature corresponding to the word. Optionally, the computer device processes the sum of the convolution features using an activation function and determines the processed feature as the first sub-feature. For example, the activation function is ReLU (Rectified Linear Unit).
[0126] The computer device may perform convolution processing on the word feature corresponding to the first word in the word group to obtain a first convolution feature, and then continue to perform convolution processing on the word feature corresponding to the second word in the word group to obtain a second convolution feature, until the computer device obtains the convolution feature corresponding to the last word in the word group, thereby obtaining a convolution feature corresponding to each word in the word group. Alternatively, the computer device may perform convolution processing on the word feature corresponding to each word in the word group in parallel to obtain a convolution feature corresponding to each word.
[0127] Among them, the convolution feature corresponding to the word is a feature vector, and the computer device adds the multiple convolution features to obtain the sum of the convolution features, and determines the sum of the convolution features as the first sub-feature corresponding to the word.
[0128] In another possible implementation, the computer device obtains the second feature corresponding to the first text, including: the computer device performs mean pooling on the first features corresponding to multiple words in the first text to obtain the second feature. Alternatively, the computer device determines the median of the first features corresponding to the multiple words in the first text as the second feature. In addition, the computer device may also use other methods to determine the second feature, such as concatenating the first features corresponding to each word to obtain the second feature corresponding to the first text.
[0129] For ease of understanding, the following formula is used to illustrate the process of the computer device obtaining the first feature and the second feature. First, the feature of the first text is represented as X = {e1, e2, ..., e T}, where e i represents the word feature corresponding to the i-th word in the first text, T represents the number of multiple words in the first text, and i is a positive integer not greater than T. The computer device will e i Input convolutional neural network, where the convolution kernel is recorded as K is the number of convolution kernels, and n represents the convolution step size. In order to capture features of different granularities, different convolution step sizes are used for convolution. The convolution step size can also be understood as a sliding window of convolution.
[0130] The computer device uses formula (1) to determine the first sub-feature corresponding to each convolution step.
[0131]
[0132] in, Represents the first sub-feature corresponding to the i-th word, n represents the convolution step, which is also the target number mentioned above. * represents the convolution operation, e i:i+n Represents the i-th word and the n words after the i-th word. i:i+n Represents the use of convolution kernel W to perform convolution processing on the i-th word and the n words after the i-th word. RELU() represents the activation function. The set of multiple first sub-features corresponding to the i-th word is h={h1,h2,……,h T}.
[0133] The computer device uses formula (2) to determine the first feature corresponding to the i-th word corresponding to the word.
[0134]
[0135] Among them, N represents a set of multiple convolution steps, Represents the first sub-feature corresponding to the i-th word, n represents the convolution step, CONCAT() represents the concatenation function, and MLP() represents the multi-layer perceptron.
[0136] The computer device uses formula (3) to determine the second feature corresponding to the first text.
[0137]
[0138] Wherein, H represents the second feature, and the READOUT function is used to process multiple parameters to obtain a parameter. For example, the READOUT function is used to perform mean pooling on multiple parameters in the time dimension.
[0139] 302. The computer device calls a feature coding model to encode each first feature and second feature respectively to obtain a first coding feature corresponding to each first feature and a second coding feature corresponding to each second feature.
[0140] The feature encoding model is used to encode text features. After obtaining each first feature and second feature, the computer device invokes the feature encoding model to encode each first feature, obtaining a first encoding feature corresponding to each first feature. The computer device then invokes the feature encoding model to encode each second feature, obtaining a second encoding feature corresponding to the second feature.
[0141] Since the first coding feature can represent the semantics of a word and at least one word after the word, and the second coding feature can represent the semantics of each word in the first text, the first coding feature and the second coding feature are subsequently used to train the feature coding model, taking into account the order of words in the text and the dependency between the contexts, so that the feature coding model can learn the contextual information between words in the text, which is conducive to improving the accuracy of feature coding.
[0142] In one possible implementation, the first feature and the second feature obtained in the above step 301 are composed of feature values, such as feature vectors or feature matrices. The first feature and the second feature are features in a continuous space, or the feature values in the first feature and the second feature are values in a continuous space, and the continuous space is a space composed of a continuous numerical range, for example, the continuous space is 0-1. The computer device maps the first text to at least one feature value in the numerical range according to the semantics of the first text, and obtains features in the continuous space. The encoding in the embodiment of the present application refers to mapping features in a continuous space to features in a discrete space, so the first coding feature and the second coding feature are features in a discrete space, or the feature values in the first coding feature and the second coding feature are values in a discrete space, and a discrete space refers to a space composed of discrete values, for example, the discrete space is 0 and 1, and the computer device maps the feature values in the first feature and the second feature to values in the discrete space to obtain features in the discrete space.
[0143] Since the first and second features are features in a continuous space, directly applying them to fields such as text recognition or text search would result in high processing overhead. Therefore, the present embodiment encodes the first and second features to obtain first and second encoded features in a discrete space. By converting features in a continuous space into features in a discrete space, data storage costs and processing speed can be reduced.
[0144] In one possible implementation, the feature encoding model is a Transformer (an encoder based on machine translation) model, or the feature encoding model is an LSTM (Long Short-Term Memory) model, or the feature encoding model is a text CNN (text-Convolutional Neural Networks) model, etc. The embodiment of the present application does not limit the type of the feature encoding model.
[0145] In a possible implementation, the feature encoding model is used for hash encoding, and the first encoding feature and the second encoding feature obtained by the feature encoding model are hash features.
[0146] 303. The computer device determines a first correlation feature between each first coding feature and a second coding feature.
[0147] After obtaining the first coding feature corresponding to each word and the second coding feature corresponding to the first text, the computer device determines a first correlation feature between each first coding feature and the second coding feature. The first correlation feature corresponding to the first coding feature can indicate the degree of correlation between the first coding feature and the second coding feature. Optionally, the first correlation feature is a numerical feature, where a larger first correlation feature indicates a greater degree of correlation between the first coding feature and the second coding feature, and a smaller first correlation feature indicates a smaller degree of correlation between the first coding feature and the second coding feature.
[0148] In one possible implementation, the first correlation feature is the mutual information between the first coding feature and the first correlation feature. Mutual information is an information measure in information theory, which can be regarded as the amount of information contained in a random variable about another random variable, or the uncertainty of a random variable reduced due to the knowledge of another random variable.
[0149] In one possible implementation, a computer device invokes a discriminant model to discriminate between a first coding feature and a second coding feature to obtain a discriminant result. The discriminant result indicates a likelihood that a word corresponding to the first coding feature belongs to the text corresponding to the second coding feature. The computer device determines the discriminant result as a first associated feature corresponding to the first coding feature.
[0150] In an embodiment of the present application, the first coding feature can characterize the semantics of some words in the first text, and the second coding feature can characterize the semantics of each word in the first text. It can be understood that the first coding feature is the "local coding feature" corresponding to the first text, and the second coding feature is the "global coding feature" corresponding to the first text. The degree of association between the first coding feature and the second coding feature can be understood as the possibility that the first coding feature and the second coding feature correspond to the same text, that is, the possibility that the word corresponding to the first coding feature belongs to the text corresponding to the second coding feature. The higher the degree of association between the first coding feature and the second coding feature, the higher the possibility that the first coding feature and the second coding feature correspond to the same text, and the lower the degree of association between the first coding feature and the second coding feature, the lower the possibility that the first coding feature and the second coding feature correspond to the same text. Therefore, the computer device can determine the discrimination result of the first coding feature and the second coding feature as the first association feature between the first coding feature and the second coding feature.
[0151] 304. The computer device obtains a third feature corresponding to a word in the second text.
[0152] The second text is different from the first text, and the third feature corresponding to the word in the second text represents the semantics of the word in the second text. Similar to the first feature in the above step, the third feature can be understood as a "local feature" of the second text.
[0153] 305. The computer device calls the feature coding model to encode the third feature to obtain a third coded feature corresponding to the third feature.
[0154] 306. The computer device determines a second correlation feature between the third coding feature and the second coding feature.
[0155] The second correlation feature indicates the correlation degree between the third coding feature and the second coding feature.
[0156] The process of determining the second correlation feature in steps 304 - 306 is similar to the process of determining the first correlation feature in steps 301 - 303 , and will not be described in detail here.
[0157] 307. The computer device determines a first text feature corresponding to the first text.
[0158] The computer device performs feature extraction on the first text to obtain a first text feature corresponding to the first text, where the first text feature represents the semantics of the first text.
[0159] Among them, the above-mentioned first feature, second feature and third feature are obtained based on the semantics of the words, and the first feature, second feature and third feature are features of the word dimension. The first text feature is obtained based on the semantics of the text, and the first text feature is a feature of the text dimension.
[0160] 308. The computer device calls the feature encoding model to encode the first text feature to obtain a fourth encoded feature.
[0161] 309. The computer device determines a third correlation feature between the fourth coding feature and the second coding feature.
[0162] The third correlation feature represents the correlation degree between the fourth coding feature and the second coding feature;
[0163] The process of determining the third correlation feature in steps 308 - 309 is similar to the process of determining the first correlation feature in steps 302 - 303 , and will not be described in detail here.
[0164] 310. The computer device determines a second text feature corresponding to the second text.
[0165] The computer device extracts features from the second text to obtain second text features corresponding to the second text. The second text features represent the semantics of the second text. Similar to the first text features in the above step, the second text features can be understood as text-level features of the second text.
[0166] 311. The computer device calls the feature encoding model to encode the second text feature to obtain a fifth encoded feature.
[0167] 312. The computer device determines a fourth association feature between the fifth coding feature and the second coding feature.
[0168] The fourth correlation feature indicates the correlation degree between the fifth coding feature and the second coding feature.
[0169] The process of determining the fourth correlation feature in the above steps 311 - 312 is similar to the process of determining the first correlation feature in the above steps 302 - 303 , and will not be repeated here.
[0170] 313. The computer device determines a loss value based on each first association feature, second association feature, third association feature, and fourth association feature, and trains a feature encoding model based on the loss value.
[0171] The loss value is negatively correlated with the first and third associated features, and positively correlated with the second and fourth associated features. Based on the loss value, the computer device trains the feature encoding model so that the loss value gradually converges. That is, the larger the first and third associated features are, the smaller the loss value is, and the smaller the first and third associated features are, the larger the loss value is. The larger the second and fourth associated features are, the larger the loss value is, and the smaller the second and fourth associated features are, the smaller the loss value is. The smaller the loss value is, the greater the accuracy of the feature encoding model is, and the larger the loss component is, the lower the accuracy of the feature encoding model is.
[0172] Since the first and second coding features are obtained by encoding the first and second features respectively by the feature coding model, the word corresponding to the first feature belongs to the text corresponding to the second feature, and the degree of correlation between the first and second features is relatively high, then the higher the degree of correlation between the first and second coding features, the higher the encoding capability of the feature coding model, that is, the more accurate the feature coding model. Since the first correlation feature represents the degree of correlation between the first and second coding features, the computer device can use the first correlation feature as a positive sample of the word dimension to train the feature coding model, so that the first correlation feature becomes increasingly larger, thereby improving the accuracy of the feature coding model.
[0173] Since the third and second coding features are obtained by encoding the third and second features respectively by the feature coding model, and the word corresponding to the third feature does not belong to the text corresponding to the second feature, the degree of correlation between the third and second features is relatively low. Therefore, the lower the degree of correlation between the third and second coding features, the higher the encoding capability of the feature coding model, that is, the more accurate the feature coding model. Since the second correlation feature indicates the degree of correlation between the first and second coding features, the computer device can use the second correlation feature as a negative sample of the word dimension to train the feature coding model, so as to make the second correlation feature smaller and smaller, thereby improving the accuracy of the feature coding model.
[0174] The above-mentioned first and second association features belong to the association features of the word dimension. In order to enable the feature encoding model to learn richer semantic information, the computer device further uses the third and fourth association features of the text dimension to train the feature encoding model.
[0175] Since the fourth coding feature and the second coding feature are obtained by encoding the first text feature and the second feature respectively by the feature coding model, the text corresponding to the first text feature and the text corresponding to the second feature belong to the same text, and the first text feature and the second feature have a high degree of correlation, then the higher the degree of correlation between the fourth coding feature and the second coding feature, the higher the encoding capability of the feature coding model, that is, the more accurate the feature coding model. Since the third correlation feature represents the degree of correlation between the first coding feature and the second coding feature, the computer device can use the third correlation feature as a negative sample of the text dimension to train the feature coding model, so that the third correlation feature becomes increasingly larger, thereby improving the accuracy of the feature coding model.
[0176] Since the fifth coding feature and the second coding feature are obtained by encoding the second text feature and the second feature, respectively, the text corresponding to the second text feature and the text corresponding to the second feature do not belong to the same text, and the second text feature and the second feature have a relatively low degree of correlation, the lower the degree of correlation between the fifth coding feature and the second coding feature, the higher the encoding capability of the feature coding model, that is, the more accurate the feature coding model. Since the fourth correlation feature represents the degree of correlation between the fifth coding feature and the second coding feature, the computer device can use the fourth correlation feature as a negative sample of the text dimension to train the feature coding model, so as to make the fourth correlation feature smaller and smaller, thereby improving the accuracy of the feature coding model.
[0177] In the related art, the word features corresponding to the words in the text are directly used to train the feature encoding model. However, since the feature encoding task focuses more on the category information in the encoding features, that is, it is hoped that the encoding features corresponding to the texts of the same category are similar, the encoding features obtained by the method of the related art contain a large amount of redundant information, and the performance of the feature encoding model is relatively low. In the embodiment of the present application, by maximizing the degree of correlation between the local features (first encoding features) and the global features (second encoding features), the encoded global features retain as much semantic information as possible related to the local features, thereby ignoring the redundant information that is too detailed in each local feature, thereby improving the encoding quality of the feature encoding model.
[0178] In one possible implementation, a first text includes words at multiple positions. The computer device determines a loss component corresponding to each position based on a first association feature and a second association feature corresponding to each position, wherein the loss component is positively correlated with the first association feature and negatively correlated with the second association feature. The first association feature corresponding to a position refers to the first association feature corresponding to the word at position in the first text, and the second association feature corresponding to a position refers to the second association feature corresponding to the word at position in the second text. The loss components corresponding to each position are fused to obtain a loss value, wherein the loss value is negatively correlated with the loss component.
[0179] The first text includes words at multiple positions, and the second text includes words at multiple positions. For each position, the computer device obtains a first association feature corresponding to the word at that position in the first text, and obtains a second association feature corresponding to the word at that position in the second text. The first association feature is a positive sample corresponding to the position, and the second association feature is a negative sample corresponding to the position. Based on the positive and negative samples, the computer device determines the loss component corresponding to the position. The larger the first association feature, the larger the loss component; the smaller the first association feature, the smaller the loss component; the larger the second association feature, the smaller the loss component; the smaller the second association feature, the larger the loss component. The loss component can be understood as the accuracy of each coding feature corresponding to the position. The larger the loss component, the greater the accuracy of the feature coding model; the smaller the loss component, the lower the accuracy of the feature coding model.
[0180] Because the first text corresponds to multiple locations, each location corresponds to a loss component, resulting in multiple loss components. The computer device fuses the multiple loss components to obtain a loss value. For example, the computer device adds the multiple loss components and then negates them to obtain the loss value. The loss value is negatively correlated with the loss component, meaning that a larger loss component indicates a smaller loss value, and a smaller loss component indicates a larger loss value.
[0181] In another possible implementation, as described in step 303 above, the computer device invokes the discriminant model to obtain the first, second, third, and fourth correlation features. The computer device then trains the feature encoding model and the discriminant model based on the loss value. That is, while the computer device trains the feature encoding model based on the loss value, it also trains the discriminant model based on the loss value to improve the accuracy of the discriminant model.
[0182] In another possible implementation, the feature encoding model is used to perform hash encoding. The first feature, the second feature, the third feature, the first text feature, and the second text feature in the above steps are features in a continuous space, and the first encoding feature, the second encoding feature, the third encoding feature, the fourth encoding feature, and the fifth encoding feature are hash features in a discrete space. The hash feature obeys a Bernoulli distribution. Taking the first encoding feature and the second encoding feature as an example, the first encoding feature and the second encoding feature obey the following distribution:
[0183] b i ~Bernoulli(σ(h i ));
[0184] B~Bernoulli(σ(H));
[0185] Among them, b i represents the first coding feature corresponding to the i-th word, B represents the second coding feature, and h i Denotes the first feature, H denotes the second feature, σ() is the activation function, and Bernoulli() is the Bernoulli function. In the embodiment of the present application, a discrete gradient estimation algorithm can be used to train the feature encoding model, and the hash features output by the trained feature encoding model obey the above distribution.
[0186] In the embodiment of the present application, the feature coding model is trained by maximizing the mutual information between the first coding feature and the second coding feature. The objective function of the feature coding model training can be expressed by the following formula (4).
[0187]
[0188] in, represents the parameters of the feature encoding model, b i represents the first coding feature corresponding to the i-th word, B represents the second coding feature, I(b i B) represents the mutual information between the first coding feature and the second coding feature, which can represent the degree of association between the first coding feature and the second coding feature. The mutual information is also the first association feature in the above step. T represents the number of multiple words in the first text. Formula (4) represents The value of parameter θ when θ is maximum.
[0189] However, since the true distribution of hash features is unknown, the I(b i Therefore, the embodiment of the present application estimates the mutual information between the first coding feature and the second coding feature by other means, that is, adopts other means to express the degree of association between the first coding feature and the second coding feature.
[0190] For ease of understanding, the following formula is used to illustrate the process of a computer device determining a loss value for training a feature encoding model. In one possible implementation, the computer device uses the following formula (5) to determine the loss component of the word dimension corresponding to the i-th word.
[0191]
[0192] in, represents the loss component corresponding to the i-th position, b i represents the first coding feature corresponding to the i-th word in the first text, and B represents the second coding feature corresponding to the first text. Indicates the third encoding feature corresponding to the i-th word in the second text, the b i is a positive sample, is a negative sample. Softplus is an activation function, which is defined as softplus(x)=log(1+e x ). Ep[] represents the mathematical expectation. D φ represents the discriminant model, which is defined as Where φ = {W, b} is the parameter of the discriminant model and σ() is the activation function.
[0193] However, the above formula (5) only includes the encoding features of the word dimension, and the loss component of the above formula (5) is only the loss component of the word dimension. In order to enable the feature encoding model to learn richer semantic information, the embodiment of the present application also considers the loss component of the text dimension. In one possible implementation, the computer device uses the following formula (6) to determine the loss component of the text dimension corresponding to the first text.
[0194]
[0195] in, represents the loss component corresponding to the first text, E represents the fourth encoding feature corresponding to the first text, and B represents the second encoding feature corresponding to the first text. Represents the fifth encoding feature corresponding to the second text, where E is a positive sample. is a negative sample. Softplus is an activation function, which is defined as softplus(x)=log(1+e x ). Ep[] represents the mathematical expectation. D φ Denotes the discriminant model, which is defined as D φ (E,B)=σ(E T WB+b), where φ={W,b} is the parameter of the discriminant model and σ() is the activation function.
[0196] The above formula (5) provides the loss component of the word dimension, and the above formula (6) provides the loss component of the text dimension. The computer device then uses the following formula (7) to determine the loss value.
[0197]
[0198] represents the loss value, and θ represent the parameters of the feature encoding model, represents the loss component corresponding to the i-th position, T represents the number of positions corresponding to the first text, and β is the weight parameter. Represents the loss component corresponding to the first text.
[0199] Figure 4 This is a flow chart of a model training method provided in an embodiment of the present application. Figure 4 As shown, the first text includes words A1, A2 and A3, and the second text includes words B1, B2 and B3. The computer device calls the feature coding model to obtain the first coding feature 1, the first coding feature 2 and the first coding feature 3 corresponding to the words in the first text, as well as the second coding feature of the word dimension and the fourth coding feature of the text dimension corresponding to the first text. The computer device calls the feature coding model to obtain the third coding feature 4, the third coding feature 5 and the third coding feature 6 corresponding to the words in the second text, as well as the sixth coding feature of the word dimension and the fifth coding feature of the text dimension corresponding to the second text.
[0200] The computer device processes the first text as a positive sample and the second text as a negative sample, and respectively inputs each first coding feature, each third coding feature, fourth coding feature and fifth coding feature and the second coding feature as an input pair, and inputs them into the discriminant model for discrimination, and obtains the mutual information between each coding feature and the second coding feature. The feature coding model and the discriminant model are trained by maximizing the mutual information of the positive sample and minimizing the mutual information of the negative sample.
[0201] The computer device processes the second text as a positive sample and the first text as a negative sample, and inputs each first coding feature, each third coding feature, fourth coding feature, fifth coding feature and sixth coding feature as input pairs, and inputs them into the discriminant model for discrimination, thereby obtaining the mutual information between each coding feature and the sixth coding feature, and training the feature coding model and the discriminant model by maximizing the mutual information of the positive sample and minimizing the mutual information of the negative sample.
[0202] The goal of the above training process is to enable the discrimination model to obtain correct discrimination results based on the encoding features corresponding to the first text and the second text. Figure 4 As shown, Figure 4 The “+” in the text indicates that the word belongs to the text, and the “-” indicates that the word does not belong to the text. The correct judgment result is that words A1, A2 and A3 belong to the first text, words B1, B2 and B3 do not belong to the first text, words A1, A2 and A3 do not belong to the second text, and words B1, B2 and B3 belong to the second text.
[0203] It should be noted that the embodiment of the present application is only described by training a model based on the first correlation feature, the second correlation feature, the third correlation feature, and the fourth correlation feature. In another embodiment, the computer device may not perform the above steps 304-306. The computer device then determines a loss value based on each of the first correlation feature, the third correlation feature, and the fourth correlation feature, and trains the feature encoding model based on the loss value. The loss value is negatively correlated with the first correlation feature and the third correlation feature, and positively correlated with the fourth correlation feature.
[0204] Alternatively, in another embodiment, the computer device may not perform steps 307-312 above. That is, the computer device only needs to determine the first correlation feature and the second correlation feature, determine a loss value based on each of the first correlation feature and the second correlation feature, and train the feature encoding model based on the loss value. The loss value is negatively correlated with the first correlation feature, and the loss value is positively correlated with the second correlation feature.
[0205] Alternatively, in another embodiment, the computer device may not perform steps 304-306 and steps 310-312. That is, the computer device only needs to determine the first correlation feature and the third correlation feature, determine a loss value based on each of the first correlation feature and the third correlation feature, and train the feature encoding model based on the loss value. The loss value is negatively correlated with the first correlation feature and the third correlation feature.
[0206] Alternatively, in another embodiment, the computer device may not perform steps 304-312 above. That is, the computer device only needs to determine the first correlation feature and train the feature encoding model based on the first correlation feature between each first encoding feature and the second encoding feature. In one possible implementation, the computer device determines a loss value based on the first correlation feature corresponding to each first encoding feature and trains the feature encoding model based on the loss value. The loss value is negatively correlated with the first correlation feature.
[0207] It should be noted that to train the feature encoding model, the computer device first obtains multiple texts as a sample dataset. The process of training the feature encoding model based on the multiple texts includes multiple iterations, with training based on two different texts in each iteration. In the embodiments of the present application, steps 301-313 are described using only one iteration to process the first and second texts as an example.
[0208] 314. The computer device calls the trained feature encoding model to encode the features of any text.
[0209] The computer device trains the feature encoding model to obtain a trained feature encoding model. The computer device can call the trained feature encoding model to encode the features of any text to obtain the corresponding encoding features. The process is detailed below. Figure 5 The embodiments of the present invention will not be described here for the time being.
[0210] The method provided in the embodiment of the present application utilizes a feature coding model to perform feature coding on the first feature and the second feature respectively to obtain a first coding feature and a second coding feature. Since the first feature contains the semantics of some words in the text and the second feature contains the semantics of each word in the same text, the correlation between the first feature and the second feature is relatively high. If the accuracy of the feature coding model is high enough, the correlation between the obtained first coding feature and the second coding feature is also relatively high. Therefore, training the feature coding model based on the correlation feature between each first coding feature and the second coding feature can improve the accuracy of the feature coding model, thereby improving the accuracy of the coding feature obtained by the feature coding model.
[0211] In addition, the word features corresponding to the word and the word features corresponding to the words following the word are determined to determine the first feature corresponding to the word. The first feature integrates the semantics of the word itself and the semantics surrounding the word. Therefore, the first feature can represent the contextual relationship between the word and the surrounding words, thereby increasing the amount of information contained in the first feature.
[0212] Furthermore, the first feature and the second feature in the continuous space are encoded to obtain the first encoded feature and the second encoded feature in the discrete space. By converting the features in the continuous space into features in the discrete space, the storage cost and processing speed of the data can be reduced.
[0213] Moreover, the first and second association features belong to the association features of the word dimension, and the third and fourth association features belong to the association features of the sentence dimension. Using the first, second, third and fourth association features to train the feature coding model can enable the feature coding model to learn richer semantic information, which is conducive to improving the coding ability and accuracy of the feature coding model.
[0214] Moreover, the first association feature and the third association feature are association features of positive samples, and the second association feature and the fourth association feature are association features of negative samples. Using the first association feature, the second association feature, the third association feature and the fourth association feature to train the feature coding model can enable the feature coding model to learn from both positive and negative sample perspectives, which is conducive to further improving the coding ability and accuracy of the feature coding model.
[0215] Figure 5 This is a flowchart of a text processing method provided by an embodiment of the present application. Figure 3 The execution subject of the embodiment of the present application is a computer device, see Figure 5 , the method comprising:
[0216] 501. The computer device determines a word feature corresponding to each word in the target text.
[0217] The target text is any text that needs to be processed.
[0218] 502. The computer device determines a fourth feature corresponding to each word based on the word feature corresponding to each word in the target text and the word feature corresponding to at least one word following each word.
[0219] 503. The computer device determines a fifth feature corresponding to the target text based on the fourth feature corresponding to each word in the target text.
[0220] 504. The computer device calls the trained feature encoding model to encode the fifth feature to obtain a sixth encoded feature corresponding to the fifth feature.
[0221] The process of determining the sixth coding feature in the above steps 501-504 is similar to the process of determining the second coding feature in the above steps 301-302, and will not be repeated here.
[0222] Figure 6 is a schematic diagram of a text processing method provided in an embodiment of the present application, such as Figure 6 As shown, the computer device performs convolution processing on the word features corresponding to the words in the target text 601 to obtain the fourth feature 602 corresponding to each word, and performs fusion processing on each fourth feature 602 to obtain the fifth feature 603 corresponding to the target text 601. The computer device inputs the fifth feature 603 into the feature encoding model, and processes it through the activation function and sampling function in the feature encoding model to output the sixth encoding feature 604. The sixth encoding feature 604 is a hash feature, such as Figure 6 As shown, the sixth coding feature is a feature vector composed of 0s and 1s.
[0223] 505. The computer device obtains candidate coding features corresponding to multiple candidate texts.
[0224] When the sixth coding feature obtained in the embodiment of the present application is applied to the scenario of text search, the computer device obtains the sixth coding feature corresponding to the target text and then obtains the candidate coding features corresponding to multiple candidate texts. Based on the candidate coding features, the computer device searches for texts similar to the target text among the multiple candidate texts. Among them, the candidate coding feature corresponding to each candidate text is obtained by encoding by calling the trained coding model. The candidate coding feature and the sixth coding feature are both coding features of the word dimension and belong to the "global features" of the text. The process of determining the candidate coding feature is the same as that of determining the sixth coding feature, and will not be repeated here.
[0225] In one possible implementation, the computer device includes a text database that stores the multiple candidate texts. The computer device then uses a method similar to the method for determining the sixth coding feature in steps 501-504 to determine the candidate coding feature corresponding to each candidate text in real time. Alternatively, the computer device determines the candidate coding feature corresponding to each candidate text in the text database in advance and stores each candidate coding feature in the text database in correspondence with the candidate text. In step 505, the computer device then directly obtains the candidate coding feature corresponding to each candidate text from the text database.
[0226] 506. The computer device determines the similarity between each candidate coding feature and the sixth coding feature.
[0227] In order to determine whether each candidate text is similar to the target text, the computer device determines the similarity between each candidate coding feature and the sixth coding feature respectively. The similarity between the candidate coding feature and the sixth coding feature can represent the similarity between the corresponding candidate text and the target text.
[0228] In one possible implementation, the computer device determines a Hamming distance between the candidate coding feature and the sixth coding feature, and determines the Hamming distance as the similarity between the candidate coding feature and the sixth coding feature. Alternatively, the computer device may use other methods to determine the similarity between the candidate coding feature and the sixth coding feature. This embodiment of the application does not limit the method for determining the similarity.
[0229] 507. The computer device determines the candidate text corresponding to the candidate coding feature with a similarity greater than the target threshold as a text similar to the target text.
[0230] After obtaining the similarity corresponding to each candidate coding feature, the computer device determines a candidate coding feature whose similarity is greater than a target threshold among multiple candidate coding features, and determines the candidate text corresponding to the candidate coding feature as a text similar to the target text.
[0231] Optionally, the target threshold is a threshold preset by the computer device. If the similarity corresponding to the candidate coding feature is greater than the target threshold, the candidate text corresponding to the candidate coding feature is considered similar to the target text; if the similarity corresponding to the candidate coding feature is not greater than the target threshold, the candidate text corresponding to the candidate coding feature is considered dissimilar to the target text.
[0232] It should be noted that the present embodiment uses the example of searching for text similar to the target text. In one possible implementation, the computer device executes steps 501-507 of the present embodiment in response to the search request for the target text. Alternatively, in another embodiment, the sixth coding feature is not used for text search, and the computer device does not execute steps 505-507.
[0233] To verify the accuracy of the feature encoding model trained in the examples of this application, the feature encoding model was tested on Dataset 1 and Dataset 2. Specifically, for a text, the feature encoding model was called to encode the text's features, obtaining encoded features. The encoded features of the text were then compared to the encoded features of other texts in the text database to determine the 1,000 texts with the highest similarity. The accuracy of the search was then used as an evaluation metric for the feature encoding model. The results are shown in Table 1.
[0234] Table 1
[0235]
[0236] Among them, related technologies 1-6 are semantic hashing methods based on generative models, respectively. The methods of related technologies 1-6 are used to encode TFIDF (Term Frequency–Inverse Document Frequency) features and BERT features, respectively, with the accuracy rates shown in Table 1. The method of this application is used to encode the “global features” of the word dimension, with the accuracy rates shown in Table 1. As can be seen from Table 1, the performance of using BERT features as input is worse than that of using TFIDF features as input. This is because BERT features contain a large amount of redundant information. The semantic hashing method based on the generative model requires that the hash features can completely reconstruct the BERT features, thereby introducing a large amount of redundant noise, resulting in reduced performance. The method proposed in the embodiment of this application has a higher accuracy rate than the method of the related technology, which proves the effectiveness of maximizing mutual information based on “local features” and “global features”.
[0237] The above embodiments can be applied to any scenario where text processing is required. For example, in a text search scenario, the method provided by the above embodiments can be used to search for other texts similar to any text. Figure 7 This is a flowchart of a text search method provided by an embodiment of the present application, see Figure 7 , the method comprising:
[0238] 701. The computer device displays a text search interface.
[0239] 702. The computer device obtains the input target text based on the text search interface.
[0240] 703. The computer device responds to the search request for the target text by using the above Figure 5 The method provided in the embodiment determines a sixth encoding feature corresponding to the target text.
[0241] 704. The computer device obtains a candidate coding feature corresponding to each candidate text in the text database, and determines a similarity between each candidate coding feature and the sixth coding feature.
[0242] 705. The computer device determines the candidate text corresponding to the candidate coding feature with the highest similarity, and displays the candidate text in the text search interface.
[0243] The above text can be any type of text. Taking the text search scenario in the medical field as an example, medical text search is an important research issue in the field of information retrieval. However, in low-resource application scenarios, due to the limited computing power and storage space of computer equipment, if similarity calculation is performed directly based on the text, it will incur a lot of overhead. Therefore, using the text processing method provided in the embodiment of the present application, medical text can be converted into coded features, and similarity calculation is performed based on the coded features, thereby reducing storage costs and improving search speed in low-resource scenarios.
[0244] Figure 8 is a schematic diagram of a text search method provided in an embodiment of the present application, Figure 8 The text search interface 801 includes a search box. The patient enters the question text 802 he wants to ask in the search box of the text search interface 801 and performs a search operation on the question text 802. The computer device responds to the search operation and uses the text search method provided in the embodiment of the present application to search for the answer text 803 with the highest similarity to the question text 802, and displays the answer text 803 in the text search interface 801. Through this method, the answer to the question can be provided to the patient quickly and accurately. Alternatively, in addition to the patient question and answer scenario, the computer device can also store the doctor's historical diagnosis plan in the case database. Other doctors search the current case, and the computer device uses the text search method provided in the embodiment of the present application to search for historical diagnosis plans similar to the current case and return them to the doctor, thereby providing a reference for the diagnosis method of the current case. In addition, the text search method provided in the embodiment of the present application can also be applied to medical insurance question and answer scenarios, etc.
[0245] Figure 9 This is a structural diagram of a text processing device provided by an embodiment of the present application. Figure 9 , the device comprises:
[0246] A feature acquisition module 901 is configured to acquire a first feature corresponding to each word in a first text and a second feature corresponding to the first text, wherein the first feature corresponding to the word represents the semantic meaning of the word in the first text, and the second feature is determined based on the first feature corresponding to each word;
[0247] A first encoding module 902 is configured to call a feature encoding model to encode each first feature and second feature respectively to obtain a first encoding feature corresponding to each first feature and a second encoding feature corresponding to each second feature;
[0248] A model training module 903 is configured to train a feature coding model based on a first correlation feature between each first coding feature and the second coding feature, where the first correlation feature indicates a correlation degree between the first coding feature and the second coding feature;
[0249] The second encoding module 904 is used to call the trained feature encoding model to encode the features of any text.
[0250] The text processing device provided in the embodiment of the present application uses a feature coding model to perform feature coding on the first feature and the second feature respectively to obtain the first coding feature and the second coding feature. Since the first feature contains the semantics of some words in the text and the second feature contains the semantics of each word in the same text, the correlation between the first feature and the second feature is relatively high. If the accuracy of the feature coding model is high enough, the correlation between the obtained first coding feature and the second coding feature is also relatively high. Therefore, training the feature coding model based on the correlation feature between each first coding feature and the second coding feature can improve the accuracy of the feature coding model, thereby improving the accuracy of the coding feature obtained by the feature coding model.
[0251] Alternatively, see Figure 10 , the model training module 903 includes:
[0252] a loss value determining unit 913, configured to determine a loss value based on a first correlation feature corresponding to each first coding feature, where the loss value is negatively correlated with the first correlation feature;
[0253] The model training unit 923 is used to train the feature encoding model based on the loss value.
[0254] Alternatively, see Figure 10 The device further includes an association determination module 905, configured to:
[0255] Calling the discriminant model to discriminate the first coding feature and the second coding feature to obtain a discrimination result, where the discrimination result indicates the possibility that the word corresponding to the first coding feature belongs to the text corresponding to the second coding feature;
[0256] The discrimination result is determined as the first associated feature corresponding to the first coding feature.
[0257] Alternatively, see Figure 10 , model training module, including:
[0258] a loss value determining unit 913, configured to determine a loss value based on a first correlation feature corresponding to each first coding feature, wherein the loss value is negatively correlated with the first correlation feature;
[0259] The model training unit 923 is used to train the feature encoding model and the discriminant model based on the loss value.
[0260] Alternatively, see Figure 10 , the device further comprises:
[0261] The feature acquisition module 901 is further configured to acquire a third feature corresponding to a word in the second text, wherein the third feature corresponding to the word represents the semantics of the word in the second text, and the second text is different from the first text;
[0262] The first encoding module 902 is further configured to call a feature encoding model to encode the third feature to obtain a third encoding feature corresponding to the third feature;
[0263] The association determination module 905 is configured to determine a second association feature between the third coding feature and the second coding feature, where the second association feature indicates a degree of association between the third coding feature and the second coding feature.
[0264] The loss value determining unit 913 is configured to:
[0265] Based on each of the first correlation feature and the second correlation feature, a loss value is determined, where the loss value is negatively correlated with the first correlation feature and the loss value is positively correlated with the second correlation feature.
[0266] Alternatively, see Figure 10 The first text includes words located at multiple positions, and the loss value determining unit 913 is configured to:
[0267] Based on the first association feature and the second association feature corresponding to each position, respectively, determine the loss component corresponding to each position, the loss component is positively correlated with the first association feature, and the loss component is negatively correlated with the second association feature, wherein the first association feature corresponding to the position refers to the first association feature corresponding to the word located at the position in the first text, and the second association feature corresponding to the position refers to the second association feature corresponding to the word located at the position in the second text;
[0268] The loss components corresponding to each position are fused to obtain the loss value, which is negatively correlated with the loss component.
[0269] Alternatively, see Figure 10 , the device further comprises:
[0270] The feature acquisition module 901 is further configured to determine a first text feature corresponding to the first text, where the first text feature represents the semantics of the first text;
[0271] The first encoding module 902 is further configured to call a feature encoding model to encode the first text feature to obtain a fourth encoding feature;
[0272] The association determination module 905 is configured to determine a third association feature between the fourth coding feature and the second coding feature, where the third association feature indicates a degree of association between the fourth coding feature and the second coding feature.
[0273] The loss value determining unit 913 is configured to:
[0274] Based on each of the first correlation feature and the third correlation feature, a loss value is determined, the loss value being negatively correlated with the first correlation feature and the third correlation feature.
[0275] Alternatively, see Figure 10 , the device further comprises:
[0276] The feature acquisition module 901 is further configured to determine a second text feature corresponding to the second text, where the second text feature represents the semantics of the second text, and the second text is different from the first text;
[0277] The first encoding module 902 is further configured to call a feature encoding model to encode the second text feature to obtain a fifth encoding feature;
[0278] an association determination module 905 , configured to determine a fourth association feature between the fifth coding feature and the second coding feature, where the fourth association feature indicates a degree of association between the fifth coding feature and the second coding feature;
[0279] The loss value determining unit 913 is configured to:
[0280] Based on each of the first correlation feature, the third correlation feature, and the fourth correlation feature, a loss value is determined, the loss value is negatively correlated with the first correlation feature and the third correlation feature, and the loss value is positively correlated with the fourth correlation feature.
[0281] Alternatively, see Figure 10 , the feature acquisition module 901 includes:
[0282] A word feature determination unit 911 is configured to determine a word feature corresponding to each word in the first text;
[0283] The first feature determining unit 921 is configured to determine a first feature corresponding to each word based on the word feature corresponding to each word and the word feature corresponding to at least one word following each word.
[0284] Alternatively, see Figure 10 , the first feature determination unit 921 is configured to:
[0285] determining a plurality of target quantities, the plurality of target quantities being different and less than the number of words in the first text;
[0286] For each target number, determine a word group corresponding to the word, and determine a first sub-feature corresponding to the word based on the word feature corresponding to each word in the word group, wherein the word group includes the word and subsequent words of the word, and the subsequent words of the word refer to words located after the word, and the number of subsequent words in the word group is not greater than the target number;
[0287] The multiple first sub-features corresponding to the word are fused to obtain the first feature corresponding to the word.
[0288] Alternatively, see Figure 10 , the first feature determination unit 921 is configured to:
[0289] When the total number of subsequent words of a word is not less than the target number, the word and the target number of words following the word are determined as the word group corresponding to the word;
[0290] When the total number of subsequent words of a word is less than the target number, the word and each word following the word are determined as the word group corresponding to the word.
[0291] Alternatively, see Figure 10 , the first feature determination unit 921 is configured to:
[0292] Perform convolution processing on the word features corresponding to each word in the word group to obtain the convolution features corresponding to each word;
[0293] The sum of multiple convolutional features is determined as the first sub-feature corresponding to the word.
[0294] Alternatively, see Figure 10 , the feature acquisition module 901 includes:
[0295] The second feature determination unit 931 is configured to perform mean pooling on the first features corresponding to the multiple words in the first text to obtain the second feature; or
[0296] The second feature determining unit 931 is configured to determine the median of the first features corresponding to the multiple words in the first text as the second feature.
[0297] Alternatively, see Figure 10 , the second encoding module 904 is used to:
[0298] Determine the word features corresponding to each word in the target text;
[0299] Determining a fourth feature corresponding to each word based on the word feature corresponding to each word in the target text and the word feature corresponding to at least one word following each word;
[0300] Determining a fifth feature corresponding to the target text based on the fourth feature corresponding to each word in the target text;
[0301] The trained feature encoding model is called to encode the fifth feature to obtain a sixth encoded feature corresponding to the fifth feature.
[0302] Alternatively, see Figure 10 , the device further comprises:
[0303] Feature query module 906, used to obtain candidate coding features corresponding to multiple candidate texts, where the candidate coding features corresponding to each candidate text are obtained by encoding using the trained coding model;
[0304] A similarity determination module 907 is used to determine the similarity between each candidate coding feature and the sixth coding feature;
[0305] The text determination module 908 is configured to determine the candidate texts corresponding to the candidate coding features having a similarity greater than a target threshold as texts similar to the target text.
[0306] It should be noted that the text processing device provided in the above embodiment is merely illustrated by the division of the aforementioned functional modules when processing text. In actual applications, the aforementioned functions can be assigned to different functional modules as needed, that is, the internal structure of the computer device can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the text processing device provided in the above embodiment and the text processing method embodiment are based on the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0307] An embodiment of the present application also provides a computer device, which includes a processor and a memory, wherein the memory stores at least one computer program, and the at least one computer program is loaded and executed by the processor to implement the operations performed in the text processing method of the above embodiment.
[0308] Optionally, the computer device is provided as a terminal. Figure 11 FIG. 1 shows a schematic structural diagram of a terminal 1100 provided by an exemplary embodiment of the present application.
[0309] The terminal 1100 includes a processor 1101 and a memory 1102 .
[0310] The processor 1101 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 1101 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field Programmable Gate Array), or PLA (Programmable Logic Array). The processor 1101 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 1101 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 1101 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0311] Memory 1102 may include one or more computer-readable storage media, which may be non-transitory. Memory 1102 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices and flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in memory 1102 is used to store at least one computer program, which is used by processor 1101 to implement the text processing method provided in the method embodiment of the present application.
[0312] In some embodiments, terminal 1100 further includes a peripheral device interface 1103 and at least one peripheral device. Processor 1101, memory 1102, and peripheral device interface 1103 may be connected via a bus or signal lines. Each peripheral device may be connected to peripheral device interface 1103 via a bus, signal lines, or circuit boards. Optionally, the peripheral device includes at least one of a radio frequency circuit 1104, a display screen 1105, and a camera assembly 1106.
[0313] The peripheral device interface 1103 can be used to connect at least one I / O (Input / Output)-related peripheral device to the processor 1101 and the memory 1102. In some embodiments, the processor 1101, the memory 1102, and the peripheral device interface 1103 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 1101, the memory 1102, and the peripheral device interface 1103 can be implemented on separate chips or circuit boards, which is not limited in this embodiment.
[0314] The RF circuit 1104 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The RF circuit 1104 communicates with communication networks and other communication devices via electromagnetic signals. The RF circuit 1104 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. Optionally, the RF circuit 1104 includes an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. The RF circuit 1104 can communicate with other devices via at least one wireless communication protocol. Such wireless communication protocols include, but are not limited to, metropolitan area networks, various generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks, and / or WiFi (Wireless Fidelity) networks. In some embodiments, the RF circuit 1104 may also include circuits related to Near Field Communication (NFC), which is not limited in this application.
[0315] The display screen 1105 is used to display a UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 1105 is a touch screen display, the display screen 1105 also has the ability to collect touch signals on the surface or above the surface of the display screen 1105. The touch signal can be input as a control signal to the processor 1101 for processing. At this time, the display screen 1105 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, there can be one display screen 1105, which is set on the front panel of the terminal 1100; in other embodiments, there can be at least two display screens 1105, which are respectively set on different surfaces of the terminal 1100 or in a folding design; in other embodiments, the display screen 1105 can be a flexible display screen, which is set on the curved surface or folding surface of the terminal 1100. Even more, the display screen 1105 can be set to a non-rectangular irregular shape, that is, a special-shaped screen. The display screen 1105 can be made of materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).
[0316] The camera assembly 1106 is used to capture images or videos. Optionally, the camera assembly 1106 includes a front camera and a rear camera. The front camera is arranged on the front panel of the terminal 1100, and the rear camera is arranged on the back of the terminal 1100. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera assembly 1106 may also include a flash. The flash can be a single-color temperature flash or a dual-color temperature flash. The dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which can be used for light compensation under different color temperatures.
[0317] Those skilled in the art will understand that Figure 11 The structure shown in the figure does not constitute a limitation on the terminal 1100, and the terminal 1100 may include more or fewer components than shown in the figure, or combine certain components, or adopt a different component arrangement.
[0318] Optionally, the computer device is provided as a server. Figure 12This is a schematic diagram of the structure of a server provided in an embodiment of the present application. The server 1200 may have relatively large differences due to different configurations or performances, and may include one or more processors (Central Processing Units, CPU) 1201 and one or more memories 1202, wherein the memory 1202 stores at least one computer program, and the at least one computer program is loaded and executed by the processor 1201 to implement the methods provided in the above-mentioned various method embodiments. Of course, the server may also have components such as a wired or wireless network interface, a keyboard, and an input and output interface for input and output. The server may also include other components for implementing device functions, which will not be described in detail here.
[0319] An embodiment of the present application further provides a computer-readable storage medium, in which at least one computer program is stored. The at least one computer program is loaded and executed by a processor to implement the operations performed in the text processing method of the above embodiment.
[0320] The present application also provides a computer program product, which includes a computer program loaded and executed by a processor to implement the operations performed in the text processing method described in the above aspects. In some embodiments, the computer program involved in the embodiments of the present application can be deployed and executed on a computer device, or on multiple computer devices located in one location, or on multiple computer devices distributed in multiple locations and interconnected by a communication network. Multiple computer devices distributed in multiple locations and interconnected by a communication network can constitute a blockchain system.
[0321] Those skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware, or by a program to instruct the relevant hardware, and the program may be stored in a computer-readable storage medium, which may be a read-only memory, a disk, or an optical disk, etc.
[0322] The above description is merely an optional embodiment of the embodiments of the present application and is not intended to limit the embodiments of the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the embodiments of the present application shall be included in the scope of protection of the present application.
Claims
1. A text processing method, characterized in that: The method comprises: Obtaining a first feature corresponding to each word in a first text and a second feature corresponding to the first text, wherein the first feature corresponding to the word represents the semantics of the word in the first text, and the second feature is determined based on the first feature corresponding to each word; Calling a feature encoding model to encode each of the first features and the second features respectively to obtain a first encoding feature corresponding to each of the first features and a second encoding feature corresponding to the second features; Invoking a discriminant model to discriminate the first coding feature and the second coding feature to obtain a first association feature, where the first association feature indicates a possibility that a word corresponding to the first coding feature belongs to the text corresponding to the second coding feature; Obtaining a third feature corresponding to a word in a second text, where the third feature corresponding to the word represents the semantics of the word in the second text, where the second text is different from the first text; calling the feature encoding model to encode the third feature to obtain a third encoded feature corresponding to the third feature; calling the discriminant model to discriminate the third coding feature and the second coding feature to obtain a second association feature, where the second association feature indicates a possibility that the word corresponding to the third coding feature belongs to the text corresponding to the second coding feature; determining a loss value based on a first association feature and a second association feature corresponding to each of the first coding features, wherein the loss value is negatively correlated with the first association feature and positively correlated with the second association feature; Based on the loss value, training the feature encoding model and the discriminant model; Call the trained feature encoding model to encode the features of any text.
2. The method according to claim 1, characterized in that The first text includes words located at multiple positions, and determining the loss value based on each of the first association features and the second association features includes: Determine a loss component corresponding to each position based on a first association feature and a second association feature corresponding to each position, respectively, where the loss component is positively correlated with the first association feature and negatively correlated with the second association feature, wherein the first association feature corresponding to the position refers to the first association feature corresponding to the word located at the position in the first text, and the second association feature corresponding to the position refers to the second association feature corresponding to the word located at the position in the second text; The loss components corresponding to each of the positions are fused to obtain the loss value, and the loss value is negatively correlated with the loss components.
3. The method according to claim 1, characterized in that The method further comprises: determining a first text feature corresponding to the first text, where the first text feature represents the semantics of the first text; Calling the feature encoding model to encode the first text feature to obtain a fourth encoding feature; calling the discriminant model to discriminate the fourth coding feature and the second coding feature to obtain a third correlation feature, where the third correlation feature indicates a possibility that the text corresponding to the fourth coding feature belongs to the text corresponding to the second coding feature; The determining of the loss value based on the first association feature and the second association feature corresponding to each of the first coding features includes: The loss value is determined based on each of the first correlation feature, the second correlation feature, and the third correlation feature, wherein the loss value is negatively correlated with the first correlation feature and the third correlation feature, and the loss value is positively correlated with the second correlation feature.
4. The method according to claim 3, characterized in that The method further comprises: determining a second text feature corresponding to a second text, where the second text feature represents semantics of the second text, and the second text is different from the first text; calling the feature encoding model to encode the second text feature to obtain a fifth encoding feature; calling the discriminant model to discriminate the fifth coding feature and the second coding feature to obtain a fourth association feature, where the fourth association feature indicates a possibility that the text corresponding to the fifth coding feature belongs to the text corresponding to the second coding feature; The determining the loss value based on each of the first correlation feature, the second correlation feature, and the third correlation feature includes: The loss value is determined based on each of the first association feature, the second association feature, the third association feature and the fourth association feature, wherein the loss value is negatively correlated with the first association feature and the third association feature, and the loss value is positively correlated with the second association feature and the fourth association feature.
5. The method according to any one of claims 1 to 4, characterized in that Obtaining a first feature corresponding to each word in the first text includes: Determining a word feature corresponding to each of the words in the first text; The first feature corresponding to each of the words is determined based on the word feature corresponding to each of the words and the word feature corresponding to at least one word following each of the words.
6. The method according to claim 5, characterized in that The determining the first feature corresponding to each word based on the word feature corresponding to each word and the word feature corresponding to at least one word following each word includes: determining a plurality of target numbers, the plurality of target numbers being different and less than the number of words in the first text; For each target number, determining a word group corresponding to the word, and determining a first sub-feature corresponding to the word based on a word feature corresponding to each word in the word group, wherein the word group includes the word and subsequent words of the word, the subsequent words of the word refer to words located after the word, and the number of the subsequent words in the word group is not greater than the target number; The multiple first sub-features corresponding to the word are fused to obtain the first feature corresponding to the word.
7. The method according to claim 6, characterized in that Determining the word group corresponding to the word includes: When the total number of subsequent words of the word is not less than the target number, the word and the target number of words following the word are determined as the word group corresponding to the word; When the total number of subsequent words of the word is less than the target number, the word and each word following the word are determined as the word group corresponding to the word.
8. The method according to claim 6, characterized in that The determining, based on the word feature corresponding to each word in the word group, the first sub-feature corresponding to the word includes: Performing convolution processing on the word features corresponding to each word in the word group to obtain the convolution features corresponding to each word; The sum of the multiple convolution features is determined as the first sub-feature corresponding to the word.
9. The method according to any one of claims 1 to 4, characterized in that Obtaining a second feature corresponding to the first text includes: Perform mean pooling on the first features corresponding to the multiple words in the first text to obtain the second feature; or The median of the first features corresponding to the multiple words in the first text is determined as the second feature.
10. The method according to any one of claims 1 to 4, characterized in that The calling of the trained feature encoding model to encode the features of any text includes: Determine the word features corresponding to each word in the target text; Determining a fourth feature corresponding to each of the words based on the word feature corresponding to each of the words in the target text and the word feature corresponding to at least one word following each of the words; determining a fifth feature corresponding to the target text based on the fourth feature corresponding to each of the words in the target text; The trained feature encoding model is called to encode the fifth feature to obtain a sixth encoded feature corresponding to the fifth feature.
11. The method according to claim 10, characterized in that After calling the trained feature encoding model to encode the fifth feature to obtain a sixth encoded feature corresponding to the fifth feature, the method further includes: Obtain candidate coding features corresponding to multiple candidate texts, where the candidate coding features corresponding to each candidate text are obtained by encoding by calling the trained feature coding model; Determining the similarity between each candidate coding feature and the sixth coding feature respectively; The candidate texts corresponding to the candidate coding features having a similarity greater than a target threshold are determined as texts similar to the target text.
12. A text processing device, characterized in that: The device comprises: a feature acquisition module, configured to acquire a first feature corresponding to each word in a first text and a second feature corresponding to the first text, wherein the first feature corresponding to the word represents the semantics of the word in the first text, and the second feature is determined based on the first feature corresponding to each word; a first encoding module, configured to call a feature encoding model to encode each of the first features and the second features respectively, to obtain a first encoding feature corresponding to each of the first features and a second encoding feature corresponding to each of the second features; an association determination module, configured to call a discriminant model to discriminate the first coding feature and the second coding feature to obtain a first association feature, where the first association feature indicates a possibility that a word corresponding to the first coding feature belongs to the text corresponding to the second coding feature; The feature acquisition module is further configured to acquire a third feature corresponding to a word in a second text, wherein the third feature corresponding to the word represents the semantics of the word in the second text, and the second text is different from the first text; The first encoding module is further configured to call the feature encoding model to encode the third feature to obtain a third encoding feature corresponding to the third feature; The association determination module is configured to call the discriminant model to discriminate the third coding feature and the second coding feature to obtain a second association feature, where the second association feature indicates a possibility that the word corresponding to the third coding feature belongs to the text corresponding to the second coding feature; a model training module, configured to determine a loss value based on a first correlation feature and a second correlation feature corresponding to each of the first coding features, wherein the loss value is negatively correlated with the first correlation feature and the loss value is positively correlated with the second correlation feature; The model training module is further used to train the feature encoding model and the discriminant model based on the loss value; The second encoding module is used to call the trained feature encoding model to encode the features of any text.
13. The device according to claim 12, characterized in that The first text includes words located at multiple positions, and the model training module is used to: Determine a loss component corresponding to each position based on a first association feature and a second association feature corresponding to each position, respectively, where the loss component is positively correlated with the first association feature and negatively correlated with the second association feature, wherein the first association feature corresponding to the position refers to the first association feature corresponding to the word located at the position in the first text, and the second association feature corresponding to the position refers to the second association feature corresponding to the word located at the position in the second text; The loss components corresponding to each of the positions are fused to obtain the loss value, and the loss value is negatively correlated with the loss components.
14. The device according to claim 12, characterized in that The device further comprises: The feature acquisition module is further configured to determine a first text feature corresponding to the first text, where the first text feature represents the semantics of the first text; The first encoding module is further configured to call the feature encoding model to encode the first text feature to obtain a fourth encoding feature; The association determination module is further configured to call the discriminant model to discriminate the fourth coding feature and the second coding feature to obtain a third association feature, wherein the third association feature indicates a possibility that the text corresponding to the fourth coding feature belongs to the text corresponding to the second coding feature; The model training module is used to: The loss value is determined based on each of the first correlation feature, the second correlation feature, and the third correlation feature, wherein the loss value is negatively correlated with the first correlation feature and the third correlation feature, and the loss value is positively correlated with the second correlation feature.
15. The device according to claim 14, characterized in that The device further comprises: The feature acquisition module is further configured to determine a second text feature corresponding to a second text, wherein the second text feature represents the semantics of the second text, and the second text is different from the first text; The first encoding module is further configured to call the feature encoding model to encode the second text feature to obtain a fifth encoding feature; The association determination module is further configured to call the discriminant model to discriminate the fifth coding feature and the second coding feature to obtain a fourth association feature, wherein the fourth association feature indicates a possibility that the text corresponding to the fifth coding feature belongs to the text corresponding to the second coding feature; The model training module is used to: The loss value is determined based on each of the first association feature, the second association feature, the third association feature and the fourth association feature, wherein the loss value is negatively correlated with the first association feature and the third association feature, and the loss value is positively correlated with the second association feature and the fourth association feature.
16. The device according to any one of claims 12 to 15, characterized in that The feature acquisition module includes: a word feature determination unit, configured to determine a word feature corresponding to each word in the first text; The first feature determining unit is configured to determine a first feature corresponding to each of the words based on a word feature corresponding to each of the words and a word feature corresponding to at least one word following each of the words.
17. The device according to claim 16, characterized in that The first feature determination unit is configured to: determining a plurality of target numbers, the plurality of target numbers being different and less than the number of words in the first text; For each target number, determining a word group corresponding to the word, and determining a first sub-feature corresponding to the word based on a word feature corresponding to each word in the word group, wherein the word group includes the word and subsequent words of the word, the subsequent words of the word refer to words located after the word, and the number of the subsequent words in the word group is not greater than the target number; The multiple first sub-features corresponding to the word are fused to obtain the first feature corresponding to the word.
18. The device according to claim 17, characterized in that The first feature determination unit is configured to: When the total number of subsequent words of the word is not less than the target number, the word and the target number of words following the word are determined as the word group corresponding to the word; When the total number of subsequent words of the word is less than the target number, the word and each word following the word are determined as the word group corresponding to the word.
19. The device according to claim 17, characterized in that The first feature determination unit is configured to: Performing convolution processing on the word features corresponding to each word in the word group to obtain the convolution features corresponding to each word; The sum of the multiple convolution features is determined as the first sub-feature corresponding to the word.
20. The device according to any one of claims 12 to 15, characterized in that The feature acquisition module includes: A second feature determination unit is configured to perform mean pooling on the first features corresponding to the plurality of words in the first text to obtain the second feature; or The second feature determining unit is configured to determine a median of first features corresponding to a plurality of words in the first text as the second feature.
21. The device according to any one of claims 12 to 15, characterized in that The second encoding module is configured to: Determine the word features corresponding to each word in the target text; Determining a fourth feature corresponding to each of the words based on the word feature corresponding to each of the words in the target text and the word feature corresponding to at least one word following each of the words; determining a fifth feature corresponding to the target text based on the fourth feature corresponding to each of the words in the target text; The trained feature encoding model is called to encode the fifth feature to obtain a sixth encoded feature corresponding to the fifth feature.
22. The device according to claim 21, characterized in that The device further comprises: A feature query module is used to obtain candidate coding features corresponding to multiple candidate texts, where the candidate coding features corresponding to each candidate text are obtained by encoding by calling the trained feature coding model; a similarity determination module, configured to respectively determine a similarity between each candidate coding feature and the sixth coding feature; The text determination module is used to determine the candidate texts corresponding to the candidate coding features with a similarity greater than a target threshold as texts similar to the target text.
23. A computer device, characterized in that: The computer device includes a processor and a memory, wherein the memory stores at least one computer program, and the at least one computer program is loaded and executed by the processor to implement the operations performed by the text processing method according to any one of claims 1 to 11.
24. A computer-readable storage medium, characterized in that The computer-readable storage medium stores at least one computer program, and the at least one computer program is loaded and executed by a processor to implement the operations performed by the text processing method according to any one of claims 1 to 11.
25. A computer program product comprising a computer program, characterized in that The computer program is loaded and executed by a processor to implement the operations performed by the text processing method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Model training method and text information processing method, system and device and storage medium
CN113392644A