Text processing method, device, electronic device and storage medium
Through the combination of the vectorized representation of the neural network model and the sentence similarity discrimination model, the problem of adding repeated texts in the FAQ corpus is solved, the uniformity and efficiency of the answers are improved, and the number of repeated texts in the corpus is reduced.
Patent Information
- Application Number
- CN202011510960.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-18
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2040-12-18
AI Technical Summary
There are a large number of repeated language materials in the FAQ corpus, resulting in inconsistent and low-efficiency answers. How to avoid adding language materials that are repeated to the language materials in the corpus has become an urgent problem to be solved.
By obtaining the target text set, the target neural network model is used for vectorization representation, the text pairs are determined, and the sentence similarity discrimination model is trained to verify whether the text to be added is repeated with the text in the corpus. If it is not repeated, it is added to the corpus.
It effectively avoids the addition of duplicate texts in the corpus, improves the uniformity and efficiency of answers, and reduces the number of duplicate texts in the corpus.
Smart Images

Figure CN112560428B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a text processing method, device, electronic device and storage medium. Background Art
[0002] With the rapid development of artificial intelligence technology, more and more companies have begun to develop their own intelligent customer service systems. The natural language processing technology used in it plays an important role in the field of artificial intelligence. It can help humans complete various tasks by enabling machines to understand human language and realize human-computer communication.
[0003] As a warehouse for storing language materials, corpus is widely used in natural language processing technology and other technologies. For example, FAQ corpus is used in Frequently Asked Questions (FAQ) module. FAQ module is a common module in intelligent customer service system, which can provide answer services for common questions frequently mentioned by users through pre-organized question and answer pairs. Therefore, the quality of FAQ corpus has an important impact on the accuracy and timeliness of the returned answers. If there are a large number of repeated questions in FAQ corpus, the answers will be inconsistent and inefficient. For example, the two sentences "What is the insurance amount" and "The meaning of the insurance amount" have the same meaning and should not exist as two questions. However, in the actual application process, in order to make the corpus adapt to more business needs, new language materials will be continuously added to the corpus. Among them, a large number of language materials that are repeated with the language materials in the corpus are added to the corpus, resulting in more repeated language materials in the corpus. Therefore, how to avoid adding language materials that are duplicated in the corpus to the corpus becomes an urgent problem to be solved. Summary of the invention
[0004] The embodiments of the present application provide a text processing method, device, electronic device, and storage medium, which can avoid adding language materials that are repeated with language materials in a corpus to the corpus.
[0005] The present application embodiment provides a text processing method, including:
[0006] Acquire a target text set, and use a target neural network model to vectorize each text in the target text set to obtain a text vector for each text in the target text set;
[0007] Determining a plurality of text pairs from the target text set according to the text vectors of the respective texts in the target text set, wherein the text pairs include at least two similar texts;
[0008] Using the multiple text pairs to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model;
[0009] When a first text to be added to the target corpus is detected, verifying whether the first text is repeated with text in the target corpus by using the trained sentence similarity discrimination model;
[0010] When the first text does not overlap with text in the target corpus, the first text is added to the target corpus.
[0011] In one embodiment, the method further comprises:
[0012] Adding a classification layer after the encoding module of the initial neural network model to obtain a neural network model including the encoding module and the classification layer;
[0013] Using the training text set to train the neural network model including the encoding module and the classification layer to obtain a trained neural network model;
[0014] The classification layer included in the trained neural network model is deleted, and the trained neural network model with the classification layer deleted is determined as the target neural network model.
[0015] In one embodiment, the method further comprises:
[0016] annotating the plurality of text pairs with labels indicating whether the texts in the text pairs are similar;
[0017] The method of using the multiple text pairs to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model includes:
[0018] The initial sentence similarity discrimination model is trained using the multiple text pairs and the annotated labels indicating whether the texts in the text pairs are similar, thereby obtaining a trained sentence similarity discrimination model.
[0019] In one embodiment, the method further comprises:
[0020] Acquire the plurality of frequently asked questions groups, wherein the plurality of frequently asked questions groups include questions that are similar to each other;
[0021] Labeling the plurality of FAQ groups with labels indicating whether the questions in the FAQ groups are similar;
[0022] The method of training an initial sentence similarity discrimination model using the plurality of text pairs and the annotated labels indicating whether the texts in the text pairs are similar to each other, and obtaining a trained sentence similarity discrimination model, comprises:
[0023] An initial sentence similarity discrimination model is trained using the multiple text pairs and the annotated labels indicating whether the texts in the text pairs are similar, as well as the multiple common question groups and the annotated labels indicating whether the questions in the common style groups are similar, to obtain a trained sentence similarity discrimination model.
[0024] In one embodiment, the method further comprises:
[0025] Get the initial corpus;
[0026] Vectorizing each text in the initial corpus by using the target neural network model to obtain a text vector for each text in the initial corpus;
[0027] Determining at least two text pairs from the initial corpus according to the text vectors of the texts in the initial corpus;
[0028] Determine a first text pair set and a second text pair set from the at least two text pairs, wherein each text pair in the first text pair set is annotated with a label indicating that the texts in the text pair are similar, and each text pair in the second text pair set is annotated with a label indicating that the texts in the text pair are not similar;
[0029] Each text pair in the first text pairs is deleted until one text remains, so as to obtain a target corpus including the remaining one text of each text pair, the second text pair, and other texts in the initial corpus except the at least two text pairs.
[0030] In one embodiment, the step of verifying whether the first text is repeated with text in a target corpus by using the trained sentence similarity discrimination model includes:
[0031] The first text and the second text in the target corpus are concatenated to obtain a concatenated text, and whether the first text is similar to the second text is determined by the trained sentence similarity discrimination model; the second text is any text that is not determined by the trained sentence similarity discrimination model to be similar to the first text;
[0032] Repeating the steps of concatenating the first text with the second text in the target corpus to obtain a concatenated text, and determining whether the first text is similar to the second text by using the trained sentence similarity discrimination model, until the second text does not exist in the target corpus;
[0033] When the first text is not similar to any text in the target corpus, it is determined that the first text is not repeated with any text in the target corpus.
[0034] In one embodiment, the method further comprises:
[0035] When there are multiple first texts, vectorizing each first text in the multiple first texts by using the target neural network model to obtain a text vector in each first text;
[0036] Determine at least one text pair from the plurality of first texts according to the text vectors of the first texts, the text pair including at least two similar first texts;
[0037] Verifying, by means of the trained sentence similarity discrimination model, whether each text pair in the at least one text pair is repeated with text in the target corpus;
[0038] When it is detected that the target text pair in the at least one text pair does not overlap with the text in the target corpus, one text is selected from the target text pair and added to the target corpus.
[0039] In a second aspect, an embodiment of the present application provides a text processing device, including:
[0040] An acquisition module, used to acquire a target text set, and use a target neural network model to vectorize each text in the target text set to obtain a text vector of each text in the target text set;
[0041] A determination module, configured to determine a plurality of text pairs from the target text set according to the text vectors of the respective texts in the target text set, wherein the text pairs include at least two similar texts;
[0042] A training module, used to train an initial sentence similarity discrimination model using the multiple text pairs to obtain a trained sentence similarity discrimination model;
[0043] A verification module, configured to, when detecting a first text to be added to the target corpus, verify whether the first text is repeated with a text in the target corpus by using the trained sentence similarity discrimination model;
[0044] A processing module is used for adding the first text to the target corpus when the first text does not overlap with the text in the target corpus.
[0045] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory, wherein the processor and the memory are interconnected, wherein the memory is used to store a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions to execute the method described in the first aspect.
[0046] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method described in the first aspect.
[0047] In summary, the electronic device can use the target neural network model to vectorize each text in the target text set, obtain the text vector of each text in the target text set, and determine multiple text pairs from the target text set based on the text vector of each text in the target text set, so as to use the multiple text pairs to train the initial sentence similarity discrimination model to obtain the trained sentence similarity discrimination model, so that when the first text to be added to the target corpus is detected, the trained sentence similarity discrimination model is used to verify whether the first text is repeated with the text in the target corpus, and when the first text is not repeated with the text in the target corpus, the first text is added to the target corpus. The above process verifies whether the text to be added to the corpus is repeated with the text in the corpus through the trained sentence similarity discrimination model, thereby avoiding adding language materials that are repeated with the language materials in the corpus to the corpus. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0049] Figure 1 It is a flowchart of a text processing method provided in an embodiment of the present application;
[0050] Figure 2 It is a flowchart of another text processing method provided in an embodiment of the present application;
[0051] Figure 3 is a structural schematic diagram of a text processing device provided in an embodiment of the present application;
[0052] Figure 4 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0054] See also Figure 1, is a flowchart of a text processing method provided in an embodiment of the present application. The method can be used in an electronic device. The electronic device can be a device with computing capabilities such as a server. Specifically, the method can include the following steps:
[0055] S101, obtaining a target text set, and using a target neural network model to vectorize each text in the target text set to obtain a text vector for each text in the target text set.
[0056] The target text set includes multiple texts. In one embodiment, the texts here can be texts related to the target field, such as insurance field. The target neural network model is a neural network model that can realize text vectorization representation.
[0057] In one embodiment, the target neural network model can be obtained in the following manner: the electronic device adds a classification layer after the encoding module of the initial neural network model to obtain a neural network model including the encoding module and the classification layer, and uses a training text set to train the neural network model including the encoding module and the classification layer to obtain a trained neural network model; the electronic device deletes the classification layer included in the trained neural network model, and determines the trained neural network model with the classification layer deleted as the target neural network model. The above process obtains the target neural network model by fine-tuning the initial neural network model, which can avoid the problems of large computing resource consumption and low model accuracy caused by training a new model.
[0058] Among them, the initial neural network model can realize text vectorization representation, and the fine-tuned neural network model can also realize text vectorization representation. In one embodiment, the encoding encoder module can be composed of an embedding layer and a transformer layer. The embedding layer is used to process the input data to obtain output data. The transformer layer contains a large number of multi-head self-attention sublayers. The transformer layer is used to process the output of the embedding layer as input to obtain the output of the transformer layer, and the output of the transformer layer is the text vector.
[0059] In one embodiment, when the training text set includes multiple texts annotated with intent categories, and the texts here are texts related to the target field, such as the insurance field, the encoding encoder module included in the target neural network model can learn the internal knowledge of the target field, such as the insurance field. For example, for the two insurance names "Three" and "Waddling", compared with the similarity distance between the two obtained by using the initial neural network model, the similarity distance between the two obtained by using the target neural network model will become closer, which means that the knowledge in the field has been learned by fine-tuning the model.
[0060] S102: Determine a plurality of text pairs from the target text set according to the text vector of each text in the target text set, wherein the text pairs include at least two similar texts.
[0061] In an embodiment of the present application, the electronic device may use a similarity algorithm, such as a cosine similarity algorithm, to calculate the similarity between each text according to the text vector of each text, and determine multiple text pairs from the target text set according to the similarity between each text. In one embodiment, the similarity between at least two similar texts included in each text pair in the multiple text pairs is greater than or equal to a first preset similarity.
[0062] S103: Using the multiple text pairs to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model.
[0063] In an embodiment of the present application, the electronic device can use multiple text pairs to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model. The sentence similarity discrimination model can be a model such as a Bidirectional Encoder Representations from Transformers (BERT) model.
[0064] In one embodiment, multiple common question groups can also be introduced to train the initial sentence similarity discrimination model, that is, the electronic device can also obtain multiple common question groups, and the questions included in the common question groups are similar. Accordingly, the electronic device uses multiple text pairs to train the initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model, specifically: the electronic device uses the multiple text pairs and the multiple common question groups to train the initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model. Compared with the method of using only text pairs for training, this process makes the training data of the initial discrimination model richer, which can effectively improve the generalization ability of the model.
[0065] In one embodiment, the electronic device may annotate the multiple text pairs with labels indicating similarities between the texts in the text pairs. For example, the multiple text pairs include text pair 1, text pair 2...text pair n, and the electronic device may annotate label 1 for text pair 1, label 1 for text pair 2, and label 1 for text pair n, where label 1 is a label indicating similarities between the texts in the corresponding text pairs. Accordingly, the electronic device uses the multiple text pairs to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model. The process may be: the electronic device uses the multiple text pairs and the annotated labels indicating similarities between the texts in the text pairs to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model.
[0066] In one embodiment, the electronic device can also annotate multiple common question groups with labels indicating similarities between each question in the common question group. Accordingly, the electronic device uses multiple text pairs to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model, specifically: the electronic device uses and annotated labels indicating similarities between each text in the text pair, as well as the multiple common question groups and annotated labels indicating similarities between each question in the common question group, to train the initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model. Compared with a method of using only text pairs for training, this process makes the training data of the initial discrimination model richer, which can effectively improve the generalization ability of the model.
[0067] In one embodiment, although multiple text pairs are determined, there may be a target text pair among the multiple text pairs, and the texts included in the target text pair are not similar. This may be due to calculation errors and other reasons. At this time, the electronic device can annotate the multiple text pairs with labels indicating whether the texts in the text pair are similar. In one embodiment, the electronic device can use manual annotation to annotate the multiple text pairs with labels indicating whether the texts in the text pair are similar. Compared with the aforementioned method of setting labels indicating the similarity between the texts in the text pair for multiple text pairs, the above process will have labels annotated on the target text pair indicating that the texts included in the target text pair are not similar. For example, multiple text pairs include text pair 1, text pair 2...text pair n, and the electronic device can annotate label 1 for text pair 1, label 2 for text pair 2, and label 1 for text pair n, where label 1 is a label indicating that the texts in the corresponding text pair are similar. Label 2 is a label indicating that the texts in the corresponding text pair are not similar. Accordingly, the electronic device uses the multiple text pairs to train the initial sentence similarity discrimination model to obtain the trained sentence similarity discrimination model. Specifically, the electronic device uses the multiple text pairs and the annotated labels indicating whether the texts in the text pairs are similar to each other to train the initial sentence similarity discrimination model to obtain the trained sentence similarity discrimination model. Considering that there may be a target text pair among the multiple text pairs, and the texts in the target text pair are not similar, the above method is used to label the multiple texts, which can improve the verification accuracy of the trained sentence similarity discrimination model.
[0068] In one embodiment, considering that there may be a target FAQ group among the multiple FAQ groups, and the questions included in the target FAQ group are not similar, the electronic device can mark the multiple FAQ groups with labels indicating whether the questions in the FAQ group are similar. In one embodiment, the electronic device can mark the multiple FAQ groups with labels indicating whether the questions in the FAQ group are similar by manual marking. Compared with the aforementioned method of setting labels indicating the similarities between the questions in the FAQ group for the multiple FAQ groups, the above process will mark the target FAQ group with labels indicating the dissimilarities between the questions included in the target FAQ group. Accordingly, the electronic device uses and the labels indicating whether the texts in the text pair are similar, as well as the multiple FAQ groups and the labels indicating whether the questions in the FAQ group are similar, to train the initial sentence similarity discrimination model to obtain the trained sentence similarity discrimination model.
[0069] S104: When a first text to be added to the target corpus is detected, verify whether the first text is repeated with text in the target corpus by using the trained sentence similarity discrimination model.
[0070] S105: When the first text does not overlap with any text in the target corpus, add the first text to the target corpus.
[0071] In step S104-step S105, when the electronic device detects the first text to be added to the target corpus, it can verify whether the first text is repeated with the text in the target corpus through the trained sentence similarity discrimination model, and when the first text is not repeated with the text in the target corpus, the first text is added to the target corpus. Among them, the first text can be any text to be added to the target corpus, and the text here is the target field, such as text related to the insurance field. For example, the first text can be any question to be added to the target corpus, such as a common question. The first text can be one or more. The target corpus can include multiple texts, and the text here is the target field, such as text related to the insurance field. For example, the target corpus can include multiple questions, and the multiple questions here can be some common questions. In one embodiment, the above-mentioned common questions can be questions with a frequency of occurrence greater than a preset frequency.
[0072] In an embodiment of the present application, the electronic device verifies whether the first text is repeated with the text in the target corpus by the trained sentence similarity discrimination model as follows: the electronic device performs splicing processing on the first text and the second text in the target corpus to obtain the spliced text, and determines whether the first text is similar to the second text by the trained sentence similarity discrimination model. The second text is any text that is not judged to be similar to the first text by the trained sentence similarity discrimination model. The electronic device repeatedly performs the steps of splicing the first text and the second text in the target corpus to obtain the spliced text, and determining whether the first text is similar to the second text by the trained sentence similarity discrimination model until the second text does not exist in the target corpus. When the first text and all the texts in the target corpus are not similar, the electronic device determines that the first text is not repeated with the text in the target corpus.
[0073] In one embodiment, the electronic device can splice the first text and the second text in the target corpus through a separator to obtain the spliced text. The electronic device can judge whether the first text is similar to the second text through the trained sentence similarity discrimination model in the following manner: the electronic device uses the spliced text as input data of the trained sentence similarity discrimination model, and the sentence similarity model judges whether the first text is similar to the second text to obtain a judgment result, which indicates that the first text is similar to the second text, or indicates that the first text is not similar to the second text. The electronic device can judge whether the first text is similar to all the texts in the target corpus based on the obtained judgment results. When the first text is similar to any text in the target corpus, it can be determined that the first text is repeated with the text in the target corpus. After determining that the first text is repeated with the text in the target corpus, the first text can be deleted.
[0074] visible, Figure 1 In the illustrated embodiment, the electronic device can use the target neural network model to vectorize each text in the target text set, obtain the text vector of each text in the target text set, and determine multiple text pairs from the target text set based on the text vector of each text in the target text set, so as to train the initial sentence similarity discrimination model using the multiple text pairs to obtain the trained sentence similarity discrimination model, so that when the first text to be added to the target corpus is detected, the trained sentence similarity discrimination model is used to check whether the first text is repeated with the text in the target corpus, and when the first text is not repeated with the text in the target corpus, the first text is added to the target corpus. This process can avoid adding text that is repeated with the text in the corpus to the corpus, thereby reducing the number of repeated texts in the target corpus.
[0075] The present application can be applied to the field of artificial intelligence, such as the field of natural language processing technology. The present application relates to blockchain technology, such as the feature information of each text in the target corpus can be written into the blockchain, so as to construct business rules related to each text in the target corpus in the blockchain. That is to say, the electronic device can extract the feature information of each text in the target corpus, for example, the feature extraction algorithm can be used to extract the feature information of each text in the target corpus, and then the feature information of each text in the target corpus is written into the blockchain, so as to construct business rules related to each text in the target corpus in regional consideration. In an application scenario, when the target corpus is a FAQ corpus, the business rule can be a question and answer rule, and the question and answer rule can realize the call of the corresponding text through the corresponding feature information. In an application scenario, when the target corpus is a knowledge commodity corpus (such as a paid material corpus), the question and answer rule can be a transaction rule, and the transaction rule can obtain the corresponding knowledge commodity through the feature information in the process of trading a certain knowledge commodity.
[0076] See also Figure 2 , is a flowchart of a text processing method provided in an embodiment of the present application. The method can be used in the electronic device mentioned above. Specifically, the method may include the following steps:
[0077] S201, obtaining a target text set, and using a target neural network model to vectorize each text in the target text set to obtain a text vector for each text in the target text set.
[0078] S202: Determine a plurality of text pairs from the target text set according to the text vector of each text in the target text set, wherein the text pairs include at least two similar texts.
[0079] S203: Using the multiple text pairs to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model.
[0080] Among them, step S201-step S203 refer to Figure 1 Steps S101 to S103 in the embodiment are not described in detail in the embodiment of the present application.
[0081] S204. When a plurality of first texts to be added to the target corpus are detected, each of the plurality of first texts is vectorized by the target neural network model to obtain a text vector in each of the first texts.
[0082] S205 . Determine at least one text pair from the plurality of first texts according to the text vectors of the first texts, where the text pair includes at least two similar first texts.
[0083] In the embodiment of the present application, the electronic device vectorizes each first text in the plurality of first texts through the target neural network model to obtain the text vector in each first text, which can be found in Figure 1 In the embodiment, the electronic device uses the target neural network model to vectorize each text in the target text set to obtain the text vector of each text in the target text set. The embodiment of the present application will not be described in detail here.
[0084] In one embodiment, the above-mentioned method of determining at least one text pair from multiple first texts based on the text vectors of each first text can be as follows: the electronic device calculates the similarity between each first text based on the text vectors of each first text, and determines at least one text pair from multiple first texts based on the similarity between each first text. In one embodiment, the similarity between at least two similar texts included in each text pair in the at least one text pair is greater than a second preset similarity. The second preset similarity can be the first preset similarity mentioned above, or it can be other than the first preset similarity, which is not limited here.
[0085] In the embodiment of the present application, the electronic device does not use the trained sentence similarity discrimination model to verify whether multiple first texts are repeated with the texts in the target corpus. Instead, in order to further reduce the calculation amount of the model and improve the calculation efficiency of the model, the electronic device first screens the text by executing steps S204 and S205, and then executes step S206.
[0086] S206: Using the trained sentence similarity discrimination model, verify whether each text pair in the at least one text pair is repeated with text in the target corpus.
[0087] In one embodiment, the electronic device can verify whether each text in each text pair of the at least one text pair is repeated with the text in the target corpus through the trained sentence similarity discrimination model. The method for the electronic device to verify whether each text in each text pair of the at least one text pair is repeated with the text in the target corpus through the trained sentence similarity discrimination model can refer to the method for the electronic device to verify whether the first text is repeated with the text in the target corpus through the trained sentence similarity discrimination model, which is not described in detail in the embodiments of the present application.
[0088] In one embodiment, the electronic device can verify whether any text in each text pair of the at least one text pair is repeated with the text in the target corpus through the trained sentence similarity discrimination model. The method for the electronic device to verify whether any text in each text pair of the at least one text pair is repeated with the text in the target corpus through the trained sentence similarity discrimination model can refer to the method for the electronic device to verify whether the first text is repeated with the text in the target corpus through the trained sentence similarity discrimination model, which is not described in detail in the embodiments of the present application.
[0089] S207: When it is detected that the target text pair in the at least one text pair does not overlap with the text in the target corpus, select a text from the target text pair and add it to the target corpus.
[0090] The texts in the target text pair are not repeated with the texts in the target corpus.
[0091] In one embodiment, the electronic device may determine that the target text pair in the at least one text pair does not repeat with the text in the target corpus when all texts in the target text pair in the at least one text pair do not repeat with the text in the target corpus.
[0092] In one embodiment, the electronic device may determine that the target text pair in the at least one text pair does not repeat with the text in the target corpus when any text in the target text pair in the at least one text pair does not repeat with the text in the target corpus.
[0093] In one embodiment, when the electronic device detects that the target text pair in the at least one text pair does not repeat with the text in the target corpus, the electronic device may randomly select a text from the target text pair and add it to the target corpus.
[0094] In one embodiment, the aforementioned target corpus can be obtained in the following manner: an electronic device obtains an initial corpus; the electronic device vectorizes each text in the initial corpus through the target neural network model to obtain the text vector of each text in the initial corpus, and determines at least two text pairs from the initial corpus according to the text vector of each text in the initial corpus; a first text pair set and a second text pair set are determined from the at least two text pairs, each text pair in the first text pair set is annotated with a label indicating that the texts in the text pair are similar, and each text pair in the second text pair set is annotated with a label indicating that the texts in the text pair are not similar; the electronic device deletes each text pair in the first text pair until one text is left, and obtains a target corpus including the remaining one text of each text pair, the second text pair, and other texts in the initial corpus except the at least two text pairs. By adopting this process, duplicate texts in the corpus can be effectively cleaned up. In one embodiment, the electronic device can obtain labels annotated for the at least two text pairs indicating whether the texts in the text pairs are similar, and determine a first text pair set and a second text pair set from the at least two text pairs based on the labels annotated for the at least two text pairs indicating whether the texts in the text pairs are similar.
[0095] In one embodiment, the target corpus may be an initial corpus.
[0096] visible, Figure 2 In the illustrated embodiment, when there are multiple first texts, the electronic device can vectorize each first text in the multiple first texts through the target neural network model to obtain the text vectors in each first text, and determine at least one text pair from the multiple first texts based on the text vectors of each first text, and then use the trained sentence similarity discrimination model to verify whether each text pair in the at least one text pair is repeated with the text in the target corpus, so that when it is detected that the target text pair in the at least one text pair is not repeated with the text in the target corpus, a text is selected from the target text pair and added to the target corpus. This process can reduce the computational complexity of the sentence similarity discrimination model and improve the computational efficiency of the model by screening multiple first texts and verifying whether the screened text pairs are repeated with the text in the target corpus through the trained sentence similarity discrimination model.
[0097] See also Figure 3 , is a schematic diagram of the structure of a text processing device provided in an embodiment of the present application. The device can be applied to the electronic device mentioned above. Specifically, the device may include:
[0098] The acquisition module 301 is used to acquire a target text set, and use a target neural network model to vectorize each text in the target text set to obtain a text vector of each text in the target text set.
[0099] The determination module 302 is configured to determine a plurality of text pairs from the target text set according to the text vector of each text in the target text set, wherein the text pairs include at least two similar texts.
[0100] The training module 303 is used to train the initial sentence similarity discrimination model using the multiple text pairs to obtain a trained sentence similarity discrimination model.
[0101] The verification module 304 is used to verify whether the first text is repeated with the text in the target corpus by using the trained sentence similarity discrimination model when the first text to be added to the target corpus is detected.
[0102] The processing module 305 is configured to add the first text to the target corpus when the first text does not overlap with any text in the target corpus.
[0103] In an optional implementation, the processing module 305 is further used to add a classification layer after the encoding module of the initial neural network model to obtain a neural network model including the encoding module and the classification layer.
[0104] In an optional implementation, the training module 303 is further used to train the neural network model including the encoding module and the classification layer using the training text set to obtain a trained neural network model.
[0105] In an optional implementation, the processing module 305 is further configured to delete the classification layer included in the trained neural network model, and determine the trained neural network model with the classification layer deleted as the target neural network model.
[0106] In an optional embodiment, the processing module 305 is further configured to annotate the plurality of text pairs with labels indicating whether the texts in the text pairs are similar.
[0107] In an optional implementation, the training module 303 uses the multiple text pairs to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model. Specifically, the training module 303 uses the multiple text pairs and annotated labels indicating whether the texts in the text pairs are similar to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model.
[0108] In an optional embodiment, the processing module 305 is further configured to obtain the plurality of frequently asked questions groups, wherein the questions included in the plurality of frequently asked questions groups are similar to each other; and to annotate the plurality of frequently asked questions groups with labels indicating whether the questions in the plurality of frequently asked questions groups are similar to each other.
[0109] In an optional embodiment, the training module 303 uses the multiple text pairs and the annotated labels indicating whether the texts in the text pairs are similar to each other to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model. Specifically, the training module 303 uses the multiple text pairs and the annotated labels indicating whether the texts in the text pairs are similar to each other, and the multiple common question groups and the annotated labels indicating whether the questions in the common style groups are similar to each other to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model.
[0110] In an optional embodiment, the processing module 305 is also used to obtain an initial corpus; vectorize each text in the initial corpus through the target neural network model to obtain a text vector of each text in the initial corpus; determine at least two text pairs from the initial corpus based on the text vector of each text in the initial corpus; determine a first text pair set and a second text pair set from the at least two text pairs, each text pair in the first text pair set is marked with a label indicating that the texts in the text pair are similar, and each text pair in the second text pair set is marked with a label indicating that the texts in the text pair are not similar; delete each text pair in the first text pair until there is one text left, to obtain a target corpus including the remaining text of each text pair, the second text pair, and other texts in the initial corpus except the at least two text pairs.
[0111] In an optional embodiment, the verification module 304 verifies whether the first text is repeated with the text in the target corpus through the trained sentence similarity discrimination model, specifically by concatenating the first text and the second text in the target corpus to obtain the concatenated text, and judging whether the first text is similar to the second text through the trained sentence similarity discrimination model; the second text is any text that is not judged to be similar to the first text by the trained sentence similarity discrimination model; repeatedly concatenating the first text and the second text in the target corpus to obtain the concatenated text, and judging whether the first text is similar to the second text through the trained sentence similarity discrimination model until the second text does not exist in the target corpus; when the first text and all texts in the target corpus are not similar, it is determined that the first text is not repeated with the text in the target corpus.
[0112] In an optional implementation, the acquisition module 301 is further used to, when there are multiple first texts, vectorize each first text in the multiple first texts through the target neural network model to obtain the text vector in each first text.
[0113] In an optional implementation, the determination module 302 is further configured to determine at least one text pair from the plurality of first texts according to the text vectors of the first texts, wherein the text pair includes at least two similar first texts.
[0114] In an optional implementation, the verification module 304 verifies whether each text pair in the at least one text pair is repeated with text in the target corpus through the trained sentence similarity discrimination model.
[0115] In an optional implementation, the processing module 305 is further configured to select a text from the target text pair and add it to the target corpus when it is detected that the target text pair in the at least one text pair does not repeat with the text in the target corpus.
[0116] visible, Figure 3 In the illustrated embodiment, the text processing device can use the target neural network model to vectorize each text in the target text set, obtain the text vector of each text in the target text set, and determine multiple text pairs from the target text set based on the text vector of each text in the target text set, so as to train the initial sentence similarity discrimination model using the multiple text pairs to obtain the trained sentence similarity discrimination model, so that when the first text to be added to the target corpus is detected, the trained sentence similarity discrimination model is used to check whether the first text is repeated with the text in the target corpus, and when the first text is not repeated with the text in the target corpus, the first text is added to the target corpus. This process can avoid adding text that is repeated with the text in the corpus to the corpus.
[0117] See also Figure 4 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device described in this embodiment may include: one or more processors 1000 and a memory 2000. The processor 1000 and the memory 2000 may be connected via a bus.
[0118] The processor 1000 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.
[0119] The memory 2000 may be a high-speed RAM memory or a non-volatile memory, such as a disk memory. The memory 2000 is used to store a set of program codes, and the processor 1000 may call the program codes stored in the memory 2000. Specifically:
[0120] Processor 1000 is used to obtain a target text set, and use a target neural network model to vectorize each text in the target text set to obtain a text vector of each text in the target text set; according to the text vector of each text in the target text set, determine a plurality of text pairs from the target text set, wherein the text pair includes at least two similar texts; use the plurality of text pairs to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model; when a first text to be added to a target corpus is detected, verify whether the first text is repeated with a text in the target corpus through the trained sentence similarity discrimination model; when the first text is not repeated with a text in the target corpus, add the first text to the target corpus.
[0121] In one embodiment, processor 1000 is further used to add a classification layer after the encoding module of the initial neural network model to obtain a neural network model including the encoding module and the classification layer; train the neural network model including the encoding module and the classification layer using a training text set to obtain a trained neural network model; delete the classification layer included in the trained neural network model, and determine the trained neural network model with the classification layer deleted as the target neural network model.
[0122] In one embodiment, the processor 1000 is further configured to annotate the multiple text pairs with labels indicating whether the texts in the text pairs are similar. The processor 1000 uses the multiple text pairs to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model, specifically using the multiple text pairs and the annotated labels indicating whether the texts in the text pairs are similar to train the initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model.
[0123] In one embodiment, the processor 1000 is further used to obtain the multiple common problem groups, wherein the questions included in the multiple common problem groups are similar to each other; annotate the multiple common problem groups with labels indicating whether the questions in the common problem groups are similar to each other; the processor 1000 uses the multiple text pairs and the annotated labels indicating whether the texts in the text pairs are similar to each other to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model, specifically using the multiple text pairs and the annotated labels indicating whether the texts in the text pairs are similar to each other, and the multiple common problem groups and the annotated labels indicating whether the questions in the common style group are similar to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model.
[0124] In one embodiment, the processor 1000 is further used to obtain an initial corpus; vectorize each text in the initial corpus through the target neural network model to obtain a text vector of each text in the initial corpus; determine at least two text pairs from the initial corpus according to the text vector of each text in the initial corpus; determine a first text pair set and a second text pair set from the at least two text pairs, each text pair in the first text pair set is marked with a label indicating that the texts in the text pair are similar, and each text pair in the second text pair set is marked with a label indicating that the texts in the text pair are not similar; delete each text pair in the first text pair until there is one text left, to obtain a target corpus including the remaining text of each text pair, the second text pair, and other texts in the initial corpus except the at least two text pairs.
[0125] In one embodiment, the processor 1000 verifies whether the first text is repeated with the text in the target corpus through the trained sentence similarity discrimination model, specifically by concatenating the first text and the second text in the target corpus to obtain the concatenated text, and judging whether the first text is similar to the second text through the trained sentence similarity discrimination model; the second text is any text that is not judged to be similar to the first text by the trained sentence similarity discrimination model; repeatedly concatenating the first text and the second text in the target corpus to obtain the concatenated text, and judging whether the first text is similar to the second text through the trained sentence similarity discrimination model until the second text does not exist in the target corpus; when the first text and all texts in the target corpus are not similar, it is determined that the first text is not repeated with the text in the target corpus.
[0126] In one embodiment, the processor 1000 is further used to, when there are multiple first texts, vectorize each first text in the multiple first texts through the target neural network model to obtain the text vector of each first text; determine at least one text pair from the multiple first texts according to the text vector of each first text, and the text pair includes at least two similar first texts; verify whether each text pair in the at least one text pair is repeated with the text in the target corpus through the trained sentence similarity discrimination model; when it is detected that the target text pair in the at least one text pair is not repeated with the text in the target corpus, select a text from the target text pair and add it to the target corpus.
[0127] In a specific implementation, the processor 1000 described in the embodiment of the present application may execute Figure 1 Example Figure 2 The implementation method described in the embodiment can also execute the implementation method described in the embodiment of the present application, which will not be repeated here.
[0128] Each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of sampling hardware or sampling software functional modules.
[0129] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the computer-readable storage medium can be volatile or non-volatile. For example, the computer storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM). The computer-readable storage medium can mainly include a storage program area and a storage data area, wherein the storage program area can store an operating system, at least one application required for a function, etc.; the storage data area can store data created according to the use of the blockchain node, etc.
[0130] Among them, the blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0131] What is disclosed above is only a preferred embodiment of the present application, and it certainly cannot be used to limit the scope of rights of the present application. Ordinary technicians in this field can understand that all or part of the processes of implementing the above embodiment and equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A text processing method, characterized in that: include: Acquire a target text set, and use a target neural network model to vectorize each text in the target text set to obtain a text vector for each text in the target text set; Determining a plurality of text pairs from the target text set according to the text vectors of the respective texts in the target text set, wherein the text pairs include at least two similar texts; Using the multiple text pairs to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model; When a first text to be added to a target corpus is detected, the first text and a second text in the target corpus are concatenated to obtain a concatenated text, and the trained sentence similarity discrimination model is used to determine whether the first text is similar to the second text; the second text is any text that is not determined to be similar to the first text by the trained sentence similarity discrimination model; the steps of concatenating the first text and the second text in the target corpus to obtain a concatenated text, and determining whether the first text is similar to the second text by the trained sentence similarity discrimination model, are repeated until the second text does not exist in the target corpus; when the first text and all texts in the target corpus are not similar, it is determined that the first text is not repeated with texts in the target corpus; When the first text does not overlap with text in the target corpus, adding the first text to the target corpus; The method further comprises: Adding a classification layer after the encoding module of the initial neural network model to obtain a neural network model including the encoding module and the classification layer; Using the training text set to train the neural network model including the encoding module and the classification layer to obtain a trained neural network model; deleting the classification layer included in the trained neural network model, and determining the trained neural network model with the classification layer deleted as the target neural network model; Acquire an initial corpus; vectorize each text in the initial corpus through the target neural network model to obtain a text vector of each text in the initial corpus; determine at least two text pairs from the initial corpus according to the text vector of each text in the initial corpus; determine a first text pair set and a second text pair set from the at least two text pairs, wherein each text pair in the first text pair set is annotated with a label indicating similarities between the texts in the text pair, and each text pair in the second text pair set is annotated with a label indicating dissimilarities between the texts in the text pair; delete each text pair in the first text pair until one text remains, and obtain a target corpus including the remaining one text of each text pair, the second text pair, and other texts in the initial corpus except the at least two text pairs.
2. The method according to claim 1, characterized in that The method further comprises: annotating the plurality of text pairs with labels indicating whether the texts in the text pairs are similar; The method of using the multiple text pairs to train an initial sentence similarity discrimination model to obtain a trained sentence similarity discrimination model includes: The initial sentence similarity discrimination model is trained using the multiple text pairs and the annotated labels indicating whether the texts in the text pairs are similar, thereby obtaining a trained sentence similarity discrimination model.
3. The method according to claim 2, characterized in that The method further comprises: Acquire multiple common problem groups, where each of the multiple common problem groups includes similar questions; Labeling the plurality of FAQ groups with labels indicating whether the questions in the FAQ groups are similar; The method of training an initial sentence similarity discrimination model using the plurality of text pairs and the annotated labels indicating whether the texts in the text pairs are similar to each other, and obtaining a trained sentence similarity discrimination model, comprises: An initial sentence similarity discrimination model is trained using the multiple text pairs and the annotated labels indicating whether the texts in the text pairs are similar, as well as the multiple common question groups and the annotated labels indicating whether the questions in the common question groups are similar, to obtain a trained sentence similarity discrimination model.
4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: When there are multiple first texts, vectorizing each first text in the multiple first texts by using the target neural network model to obtain a text vector in each first text; Determine at least one text pair from the plurality of first texts according to the text vectors of the first texts, the text pair including at least two similar first texts; Verifying, by means of the trained sentence similarity discrimination model, whether each text pair in the at least one text pair is repeated with text in the target corpus; When it is detected that the target text pair in the at least one text pair does not overlap with the text in the target corpus, one text is selected from the target text pair and added to the target corpus.
5. A text processing device, characterized in that: The device is used to perform the method according to any one of claims 1 to 4, and the device comprises: An acquisition module, used to acquire a target text set, and use a target neural network model to vectorize each text in the target text set to obtain a text vector of each text in the target text set; A determination module, configured to determine a plurality of text pairs from the target text set according to the text vectors of the respective texts in the target text set, wherein the text pairs include at least two similar texts; A training module, used to train an initial sentence similarity discrimination model using the multiple text pairs to obtain a trained sentence similarity discrimination model; A verification module, configured to, when detecting a first text to be added to the target corpus, verify whether the first text is repeated with a text in the target corpus by using the trained sentence similarity discrimination model; A processing module is used for adding the first text to the target corpus when the first text does not overlap with the text in the target corpus.
6. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the processor and the memory are connected to each other, wherein the memory is used to store a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions to execute the method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method according to any one of claims 1 to 4.
