Text similarity detection method and device and text similarity detection model training method and device
By using bidirectional LSTM and multi-scale convolutional attention module in the text similarity detection model, and using the target sample data set and prompt word engineering driven language model to expand the corpus data, the problem of low accuracy of text similarity detection in the prior art is solved, and more efficient text semantic understanding and detection accuracy are achieved.
Patent Information
- Application Number
- CN202411658722.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-03-18
AI Technical Summary
The prior art is difficult to capture complex semantic relationships and text connotations in text similarity detection, resulting in low detection accuracy, especially when processing long texts and texts with complex semantic structures.
The text similarity detection model of the bidirectional long and short-term memory network (LSTM) module and the multi-scale convolutional attention module is used to train the target sample data set, and the initial corpus data is expanded with the prompt word engineering driven language model to generate the sample data set to improve the generalization of the model and the accuracy of feature extraction.
It improves the accuracy of text similarity detection, can more effectively capture the deep semantic relationships of the text, and enhances the generalization ability of the model and the accuracy of feature extraction.
Smart Images

Figure CN119647446A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of deep learning technology, and in particular to a method and device for text similarity detection and a training method for a text similarity detection model. Background Art
[0002] With the rapid development of information technology, chatbots and question-answering systems that use large language models have become increasingly popular. These chatbots and question-answering systems usually need to understand and process natural language input and generate high-quality, relevant output. Therefore, it is crucial to ensure the accuracy and consistency of the output text. To achieve this goal, text similarity detection models are widely used to detect whether the text output by the system has achieved the expected accuracy.
[0003] In the related art, the edit distance method is usually used to implement text similarity detection. However, the edit distance method is effective in detecting spelling errors and typing errors, but it cannot capture complex semantic relationships and the connotation of the text. Since the literal similarity in long texts and texts with complex semantic structures often cannot reflect the true meaning of the text, the text similarity detection implemented by the edit distance method cannot guarantee the accuracy of the detection. Summary of the invention
[0004] Based on this, it is necessary to provide a text similarity detection and a training method and device for a text similarity detection model that can improve the accuracy of text similarity detection in response to the above technical problems.
[0005] In a first aspect, the present application provides a text similarity detection method, comprising:
[0006] Obtain a first text to be tested and a second text to be tested;
[0007] Inputting the first text to be tested and the second text to be tested into a text similarity detection model, and obtaining a similarity label between the first text to be tested and the second text to be tested output by the text similarity detection model;
[0008] Among them, the text similarity detection model is generated after training with a target sample data set, and the target sample data set is a sample data set generated after the prompt word engineering-driven language model expands the initial corpus data. The text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolutional attention module. The bidirectional LSTM module and the multi-scale convolutional attention module are used to extract features from the input data of the text similarity detection model.
[0009] In one embodiment, the method further comprises:
[0010] Get the initial corpus data;
[0011] Segmenting the initial expected data to obtain a plurality of first text samples;
[0012] Replacing the plurality of first text samples with synonyms or antonyms respectively;
[0013] Inputting the plurality of first text samples after synonyms or antonyms are replaced into the prompt word engineering driven language model respectively, and obtaining the plurality of second text samples generated by the prompt word engineering driven language model according to the correlation of synonyms or antonyms replacement and the similarity labels respectively corresponding to the plurality of second text samples;
[0014] Generate the target sample data set according to the plurality of first text samples, the plurality of second text samples and the similarity labels respectively corresponding to the plurality of second text samples;
[0015] The text similarity detection model is trained using the target sample data set.
[0016] In one embodiment, after obtaining the plurality of second text samples generated by the prompt word engineering driven language model according to the relevance of synonym or antonym replacement and the similarity labels respectively corresponding to the plurality of second text samples, the method further includes:
[0017] According to a preset word order processing ratio, determining text samples to be processed from the plurality of first text samples and the plurality of second text samples respectively;
[0018] The text sample to be processed is input into a word order processing model to exchange the word order of the text sample to be processed.
[0019] In one embodiment, the similarity label includes a first label and a second label, the first label is used to indicate that the first text sample and the second text sample are similar, and the second label is used to indicate that the first text sample and the second text sample are not similar.
[0020] In one embodiment, if the correlation is greater than zero, the similarity label is the first label; if the correlation is less than or equal to zero, the similarity label is the second label.
[0021] In one of the embodiments, the output of the text similarity detection model also includes the confidence of the similarity label;
[0022] After the text similarity detection model is trained using the target sample data set, the method further includes:
[0023] Acquire test questions and standard answer texts corresponding to the test questions from a database;
[0024] Inputting the test question into a large language model, and obtaining a generated answer text corresponding to the test question output by the large language model;
[0025] Inputting the standard answer text and the generated answer text into the text similarity detection model, and obtaining the similarity label and confidence between the standard answer text and the generated answer text output by the text similarity detection model;
[0026] According to the confidence level, the reliability of the similarity label output by the text similarity detection model is determined.
[0027] In one embodiment, determining the reliability of the similarity label output by the text similarity detection model according to the confidence level includes:
[0028] If the confidence is less than the confidence threshold, determining that the similarity label output by the text similarity detection model is unreliable;
[0029] If the confidence is greater than or equal to the confidence threshold, the reliability of the similarity label output by the text similarity detection model is determined.
[0030] In one embodiment, after determining that the similarity label output by the text similarity detection model is unreliable, the method further includes:
[0031] The similarity labels output by the text similarity detection model are converted into label types.
[0032] In one embodiment, the bidirectional LSTM module includes a forward LSTM module and a backward LSTM module, and the text similarity detection model also includes a data dimension enhancement module, a data dimension reduction module, a feature weighting module and a classifier module;
[0033] The forward LSTM module is used to encode the input data of the text similarity detection model into a first feature sequence, obtain the positive dependency information in the first feature sequence from the start direction to the end direction of the first feature sequence, and convert the first feature sequence into a second feature sequence according to the positive dependency information;
[0034] The data dimension upgrading module is used to add features of a target dimension to the second feature sequence by performing dimension rearrangement and dimension expansion on the second feature sequence, so as to generate a third feature sequence;
[0035] The multi-scale convolutional attention module is used to extract context information from the third feature sequence;
[0036] The feature weighting module is used to perform weighted processing on the third feature sequence according to the context information to obtain a fourth feature sequence;
[0037] The data dimension reduction module is used to remove the features of the target dimension from the fourth feature sequence to obtain a fifth feature sequence;
[0038] The backward LSTM module is used to obtain reverse dependency information in the fifth feature sequence from the end direction to the start direction of the fifth feature sequence, and convert the fifth feature sequence into a sixth feature sequence according to the reverse dependency information;
[0039] The classifier module is used to generate a similarity label of the input data and confidence data of the similarity label according to the sixth feature sequence.
[0040] In one of the embodiments, the text similarity detection model further includes an adaptive temperature module and a model evaluation module;
[0041] The model evaluation module is used to obtain the model evaluation parameters of the text similarity detection model in each round of training according to the target sample data set and output data of the text similarity detection model;
[0042] The adaptive temperature module is used to obtain the value of the temperature control matrix according to the preset initial temperature and the model evaluation parameters of the text similarity detection model in each round of training, and control the smoothness of the normalization function of the text similarity detection model according to the value of the temperature control matrix.
[0043] In a second aspect, the present application provides a method for training a text similarity detection model, comprising:
[0044] Get the initial corpus data;
[0045] Segmenting the initial expected data to obtain a plurality of first text samples;
[0046] Replacing the plurality of first text samples with synonyms or antonyms respectively;
[0047] Inputting a plurality of first text samples after synonyms or antonyms are replaced into a prompt word engineering driven language model respectively, and obtaining a plurality of second text samples generated by the prompt word engineering driven language model according to the correlation of synonyms or antonyms replacement and similarity labels respectively corresponding to the plurality of second text samples, wherein the text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolutional attention module, and the bidirectional LSTM module and the multi-scale convolutional attention module are used to extract features from the input data of the text similarity detection model;
[0048] Generate a target sample data set according to the plurality of first text samples, the plurality of second text samples and the similarity labels respectively corresponding to the plurality of second text samples;
[0049] The text similarity detection model is trained using the target sample data set.
[0050] In a third aspect, the present application provides a text similarity detection device, comprising:
[0051] A first acquisition module, used to acquire a first text to be tested and a second text to be tested;
[0052] A detection module, used for inputting the first text to be tested and the second text to be tested into a text similarity detection model, and obtaining a similarity label between the first text to be tested and the second text to be tested output by the text similarity detection model;
[0053] Among them, the text similarity detection model is generated after training with a target sample data set, and the target sample data set is a sample data set generated after the prompt word engineering-driven language model expands the initial corpus data. The text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolutional attention module. The bidirectional LSTM module and the multi-scale convolutional attention module are used to extract features from the input data of the text similarity detection model.
[0054] In one embodiment, the text similarity detection device further includes:
[0055] The training module is used to obtain initial corpus data; segment the initial expected data to obtain multiple first text samples; replace the multiple first text samples with synonyms or antonyms respectively; input the multiple first text samples after the synonyms or antonyms are replaced into the prompt word engineering driven language model respectively, and obtain the multiple second text samples generated by the prompt word engineering driven language model according to the correlation of the synonyms or antonyms replacement and the similarity labels respectively corresponding to the multiple second text samples; generate the target sample data set according to the multiple first text samples, the multiple second text samples and the similarity labels respectively corresponding to the multiple second text samples; use the target sample data set to train the text similarity detection model.
[0056] In one of the embodiments, the training module is further used to determine the text samples to be processed from the multiple first text samples and the multiple second text samples respectively according to a preset word order processing ratio; input the text samples to be processed into the word order processing model to exchange the word order of the text samples to be processed.
[0057] In one embodiment, the similarity label includes a first label and a second label, the first label is used to indicate that the first text sample and the second text sample are similar, and the second label is used to indicate that the first text sample and the second text sample are not similar.
[0058] In one embodiment, if the correlation is greater than zero, the similarity label is the first label; if the correlation is less than or equal to zero, the similarity label is the second label.
[0059] In one of the embodiments, the output of the text similarity detection model also includes the confidence of the similarity label;
[0060] The text similarity detection device further includes:
[0061] A verification module is used to obtain a test question and a standard answer text corresponding to the test question from a database; input the test question into a large language model, and obtain a generated answer text corresponding to the test question output by the large language model; input the standard answer text and the generated answer text into the text similarity detection model, and obtain a similarity label and confidence between the standard answer text and the generated answer text output by the text similarity detection model; and determine the reliability of the similarity label output by the text similarity detection model based on the confidence.
[0062] In one of the embodiments, the verification module is further used to determine that the similarity label output by the text similarity detection model is unreliable if the confidence is less than a confidence threshold; and to determine that the similarity label output by the text similarity detection model is reliable if the confidence is greater than or equal to the confidence threshold.
[0063] In one of the embodiments, the verification module is further used to convert the similarity label output by the text similarity detection model into a label type.
[0064] In one embodiment, the bidirectional LSTM module includes a forward LSTM module and a backward LSTM module, and the text similarity detection model also includes a data dimension enhancement module, a data dimension reduction module, a feature weighting module and a classifier module;
[0065] The forward LSTM module is used to encode the input data of the text similarity detection model into a first feature sequence, obtain the positive dependency information in the first feature sequence from the start direction to the end direction of the first feature sequence, and convert the first feature sequence into a second feature sequence according to the positive dependency information;
[0066] The data dimension upgrading module is used to add features of a target dimension to the second feature sequence by performing dimension rearrangement and dimension expansion on the second feature sequence, so as to generate a third feature sequence;
[0067] The multi-scale convolutional attention module is used to extract context information from the third feature sequence;
[0068] The feature weighting module is used to perform weighted processing on the third feature sequence according to the context information to obtain a fourth feature sequence;
[0069] The data dimension reduction module is used to remove the features of the target dimension from the fourth feature sequence to obtain a fifth feature sequence;
[0070] The backward LSTM module is used to obtain reverse dependency information in the fifth feature sequence from the end direction to the start direction of the fifth feature sequence, and convert the fifth feature sequence into a sixth feature sequence according to the reverse dependency information;
[0071] The classifier module is used to generate a similarity label of the input data and confidence data of the similarity label according to the sixth feature sequence.
[0072] In one of the embodiments, the text similarity detection model further includes an adaptive temperature module and a model evaluation module;
[0073] The model evaluation module is used to obtain the model evaluation parameters of the text similarity detection model in each round of training according to the target sample data set and output data of the text similarity detection model;
[0074] The adaptive temperature module is used to obtain the value of the temperature control matrix according to the preset initial temperature and the model evaluation parameters of the text similarity detection model in each round of training, and control the smoothness of the normalization function of the text similarity detection model according to the value of the temperature control matrix.
[0075] In a fourth aspect, the present application provides a training device for a text similarity detection model, comprising:
[0076] The second acquisition module is used to acquire initial corpus data;
[0077] A processing module, configured to segment the initial expected data to obtain a plurality of first text samples; and replace the plurality of first text samples with synonyms or antonyms respectively;
[0078] A generation module is used to input multiple first text samples after synonyms or antonyms are replaced into a prompt word engineering driven language model, and obtain multiple second text samples generated by the prompt word engineering driven language model according to the correlation of synonyms or antonyms replacement and similarity labels corresponding to the multiple second text samples, wherein the text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolutional attention module, and the bidirectional LSTM module and the multi-scale convolutional attention module are used to extract features from the input data of the text similarity detection model; generate a target sample data set according to the multiple first text samples, the multiple second text samples and the similarity labels corresponding to the multiple second text samples; and use the target sample data set to train the text similarity detection model.
[0079] In a fifth aspect, the present application provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the method described in the first aspect or the second aspect are implemented.
[0080] In a sixth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the method described in the first aspect or the second aspect are implemented.
[0081] In a seventh aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the method described in the first aspect or the second aspect above.
[0082] The above-mentioned text similarity detection, text similarity detection model training method and device, first, obtain a first text to be tested and a second text to be tested; input the first text to be tested and the second text to be tested into the text similarity detection model, and obtain the similarity label between the first text to be tested and the second text to be tested output by the text similarity detection model; wherein the text similarity detection model is generated after training with a target sample data set, the target sample data set is a sample data set generated after the prompt word engineering-driven language model expands the initial corpus data, and the text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolution attention module, and the bidirectional LSTM module and the multi-scale convolution attention module are used to extract features from the input data of the text similarity detection model. Since the text similarity detection model in the present application is generated after training with a sample data set generated after the initial corpus data is expanded, the generalization of the text similarity detection model can be improved, and at the same time, the text similarity detection model improves the accuracy of feature extraction by extracting features from the LSTM module and the multi-scale convolution attention module. Based on this, the text similarity detection method provided in the present application can improve the accuracy of text similarity detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0083] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions 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 related drawings can be obtained based on these drawings without paying creative work.
[0084] Figure 1 An application environment diagram of a text similarity detection method provided in an embodiment of the present application;
[0085] Figure 2 A flowchart of a text similarity detection method provided in an embodiment of the present application;
[0086] Figure 3 A model structure diagram of a text similarity detection model provided in an embodiment of the present application
[0087] Figure 4 A flowchart of a method for training a text similarity detection model provided in an embodiment of the present application;
[0088] Figure 5 A flowchart of another text similarity detection method provided in an embodiment of the present application;
[0089] Figure 6 A structural block diagram of a text similarity detection device provided in an embodiment of the present application;
[0090] Figure 7 A structural block diagram of a training device for a text similarity detection model provided in an embodiment of the present application;
[0091] Figure 8 An internal structure diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0092] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0093] First, the related technology will be described below.
[0094] With the rapid development of information technology, chatbots and question-answering systems that use large language models have become increasingly popular. These chatbots and question-answering systems usually need to understand and process natural language input and generate high-quality, relevant output. Therefore, it is crucial to ensure the accuracy and consistency of the output text. To achieve this goal, text similarity detection models are widely used to detect whether the text output by the system has achieved the expected accuracy.
[0095] In related technologies, the edit distance method or machine learning model is usually used to realize text similarity detection.
[0096] Edit distance methods focus on character-level changes, including insertions, deletions, and substitutions, rather than the deeper meaning of the language. This results in significant results in detecting spelling errors and typos, but is unable to capture complex semantic relationships and the connotation of the text. Therefore, edit distance methods are limited in their effectiveness in processing natural languages with complex semantics and structures, and the literal similarity they detect often cannot reflect the true meaning of the text.
[0097] The machine learning models for text similarity detection mainly include support vector machine (SVM) model or random forest model. The above machine learning models can learn from text features, but they often rely on surface-level statistical features, such as word frequency and Chinese language model (n-gram) pattern, lack the understanding of deep language semantics, and thus rely on text length and literal similarity of vocabulary, ignoring the coherence of context and the depth of semantics.
[0098] In addition, text similarity detection models in related technologies such as edit distance methods or machine learning models usually have the following shortcomings.
[0099] First, when comparing texts, the text similarity detection model in the related art finds it difficult to take into account the context of sentences or paragraphs in the entire text, resulting in the inability to understand the meaning of words and phrases in a specific context. The meaning of words and phrases in a specific context is particularly critical to whether the generated answer is consistent with the context of a given question.
[0100] Secondly, the detection accuracy of text similarity detection models in related technologies is largely limited by the quality and scale of training data. Most traditional training sets do not contain sufficiently diverse and specialized samples, which leads to poor performance of the model in applications, especially in text matching in professional or specific fields.
[0101] Finally, the text similarity detection model in the related art has weak generalization ability when facing different fields or new types of text. The model performs well on the training set or a specific type of text, but its performance drops significantly on unseen text types or fields.
[0102] Based on this, the text similarity detection models in the related art lack deep semantic understanding and are often unable to accurately evaluate the text generated by large language models, such as detecting whether the answer fully conforms to the context of a given question. Therefore, the detection accuracy of the text similarity detection models in the related art is not high.
[0103] To solve the above problems, the embodiments of the present application provide a text similarity detection, a training method and a device for a text similarity detection model. The text similarity detection model is generated by training a sample data set generated after expanding the initial corpus data, which can improve the generalization of the text similarity detection model. At the same time, the text similarity detection model improves the accuracy of feature extraction by performing feature extraction on the LSTM module and the multi-scale convolutional attention module. Based on this, the text similarity detection method provided by the present application can improve the accuracy of text similarity detection.
[0104] The following describes the application scenarios of the text similarity detection method provided in the embodiments of the present application.
[0105] The text similarity detection method provided in the embodiment of the present application can be applied to Figure 1In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The terminal 102 sends a text similarity detection request to the server 104, and the text similarity detection request includes a first text to be tested and a second text to be tested. The server 104 obtains the first text to be tested and the second text to be tested. Subsequently, the server 104 inputs the first text to be tested and the second text to be tested into the text similarity detection model, and obtains the similarity label between the first text to be tested and the second text to be tested output by the text similarity detection model. Among them, the text similarity detection model is generated after training with a target sample data set, and the target sample data set is a sample data set generated after the prompt word engineering drives the language model to expand the initial corpus data. The text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolution attention module, and the bidirectional LSTM module and the multi-scale convolution attention module are used to extract features from the input data of the text similarity detection model.
[0106] The terminal 102 may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car devices, projection devices, etc. Portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. Head-mounted devices may be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. The server 104 may be an independent physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server that provides cloud computing services.
[0107] In an exemplary embodiment, Figure 2 As shown, a text similarity detection method is provided, which is applied to Figure 1 The following is an example of the server in Figure 1, including S202-S202:
[0108] S201: Obtain a first text to be tested and a second text to be tested.
[0109] In the present application, when text similarity detection is required, the server can obtain a first text to be tested and a second text to be tested.
[0110] The first text to be tested and the second text to be tested may be texts to be tested for similarity. Exemplarily, the first text to be tested may include an output answer text of a large language model, and the second text to be tested may be a preset standard answer text.
[0111] It should be understood that the embodiments of the present application do not limit how to obtain the first text to be tested and the second text to be tested. In some embodiments, the terminal can send a text similarity detection request to the server, and the text similarity detection request includes the first text to be tested and the second text to be tested, so that the server adopts a text similarity detection method to detect the similarity between the first text to be tested and the second text to be tested.
[0112] S202: Input the first text to be tested and the second text to be tested into a text similarity detection model, and obtain a similarity label between the first text to be tested and the second text to be tested output by the text similarity detection model.
[0113] In this step, after the server obtains the first text to be tested and the second text to be tested, the first text to be tested and the second text to be tested can be input into the text similarity detection model, and the similarity label between the first text to be tested and the second text to be tested output by the text similarity detection model can be obtained.
[0114] It should be understood that the embodiments of the present application do not limit the text similarity detection model. In some embodiments, the text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolutional attention module. The bidirectional LSTM module and the multi-scale convolutional attention module are used to extract features from the input data of the text similarity detection model.
[0115] In some embodiments, the bidirectional LSTM module includes a forward LSTM module and a backward LSTM module, and the text similarity detection model also includes a data dimension enhancement module, a data dimension reduction module, a feature weighting module and a classifier module.
[0116] In some embodiments, a forward LSTM module is used to encode the input data of the text similarity detection model into a first feature sequence, obtain the forward dependency information in the first feature sequence from the start direction to the end direction of the first feature sequence, and convert the first feature sequence into a second feature sequence according to the forward dependency information.
[0117] It should be understood that the embodiment of the present application does not limit how to perform the encoding conversion. For example, the encoding conversion can be performed in the form of a vocabulary (vocab). It should be understood that the embodiment of the present application does not limit how to obtain the positive dependency information in the first feature sequence. A forward LSTM with 400 hidden layers can be used to capture the positive dependency information.
[0118] For example, Figure 3 A model structure diagram of a text similarity detection model provided in an embodiment of the present application. Figure 3As shown in the figure, after the text similarity detection model receives the input data, the input data (the sentences in this article) can be encoded and converted through vocab to convert the text information into a first feature sequence. Subsequently, a forward LSTM containing 400 hidden layers can be used to process the data from the beginning to the end of the sequence to capture the positive dependency information in the first feature sequence, thereby converting the first feature sequence into a second feature sequence based on the positive dependency information.
[0119] In some embodiments, the data dimension upgrading module is used to add features of the target dimension to the second feature sequence by dimensional rearrangement and dimensional expansion of the second feature sequence to generate a third feature sequence.
[0120] It should be understood that the above-mentioned dimensionality rearrangement and dimensionality expansion are used to expand the second feature sequence output by the forward LSTM module into a 4D convolution.
[0121] Continue to refer Figure 3 The size of the second feature sequence is (W, B, H). The second feature sequence is first rearranged into a sequence of (W, H, B), and then expanded into a size of (W, H, H, B).
[0122] For example, assuming that the size of the input second feature sequence is (256, 128, 16), after rearrangement and expansion, the second feature sequence is expanded to a 4D feature sequence of (256, 16, 16, 128), that is, the third feature sequence, and the value of the extra dimension of the third feature sequence can be 0.
[0123] In some embodiments, a multi-scale convolutional attention module is used to extract contextual information from the third feature sequence.
[0124] It should be understood that the embodiments of the present application do not limit the multi-scale convolutional attention module, and multiple small convolution sums of different sizes can be used to simulate the feature extraction effect of a large convolution sum.
[0125] Continue to refer Figure 3 After the third feature sequence is input into the multi-scale convolutional attention module, the multiple deep convolutions in the multi-scale convolutional attention module can capture contextual information of different ranges. Exemplarily, the multi-scale convolutional attention module may include 6 small convolutions of different sizes: 5x1, 1x5, 11x1, 1x11, 15x1, and 1x15 to simulate the feature extraction effect of multiple large-size convolutions. In addition, a set of 1x1 convolutions may be added between the 5x1, 1x5 convolutions and between the 15x1, 1x15 convolutions to enhance the feature expression capability.
[0126] In some embodiments, the feature weighting module is used to perform weighted processing on the third feature sequence according to context information to obtain a fourth feature sequence.
[0127] It should be understood that the embodiments of the present application do not limit how to perform weighted processing. In some embodiments, feature weighting can be achieved through element-by-element multiplication.
[0128] Continue to refer Figure 3 After the feature weighting module receives the context information and the third feature sequence, it can perform element-by-element multiplication of the convolution corresponding to the context information and the third feature sequence to achieve feature weighting and obtain the fourth feature sequence.
[0129] In some embodiments, the data dimension reduction module is used to remove the features of the target dimension in the fourth feature sequence to obtain a fifth feature sequence.
[0130] Exemplarily, the fourth feature sequence generated by the feature weighting module after weighting can be input to the data dimension reduction module, which removes all 0 dimensions to achieve feature dimension reduction and obtain the fifth feature sequence. At this time, the fifth feature sequence is the attention feature sequence of the input sequence.
[0131] In some embodiments, the backward LSTM module is used to obtain reverse dependency information in the fifth feature sequence from the end direction to the start direction of the fifth feature sequence, and convert the fifth feature sequence into a sixth feature sequence according to the reverse dependency information.
[0132] It should be understood that the embodiment of the present application does not limit how to obtain the reverse dependency information in the fifth feature sequence, and a backward LSTM with 400 hidden layers can be used to capture the forward dependency information. In some embodiments, after the backward LSTM with 400 hidden layers is used to capture the forward dependency information and convert it into the sixth feature sequence, it can also be processed by average pooling to determine the final output sequence.
[0133] In some embodiments, the classifier module is used to generate similarity labels and confidence data of the similarity labels for the input data according to the sixth feature sequence.
[0134] Exemplarily, the confidence data may be a single-precision floating-point confidence, and the similarity label includes a first label and a second label, the first label is used to indicate that the first text sample and the second text sample are similar, and the second label is used to indicate that the first text sample and the second text sample are not similar.
[0135] Exemplarily, the value of the first tag may be 1, and the value of the second tag may be 0.
[0136] In other embodiments, the text similarity detection model further includes an adaptive temperature module and a model evaluation module. The model evaluation module is used to obtain the model evaluation parameters of the text similarity detection model in each round of training according to the target sample data set and output data of the text similarity detection model. The adaptive temperature module is used to obtain the value of the temperature control matrix according to the preset initial temperature and the model evaluation parameters of the text similarity detection model in each round of training, and control the smoothness of the normalization function of the text similarity detection model according to the value of the temperature control matrix.
[0137] Among them, the above-mentioned model evaluation parameter may be an Area Under Curve (AUC) parameter. The AUC parameter can be used as an evaluation criterion for the model and can be used to reflect the authenticity of the model output. The closer the value of the AUC parameter is to 1.0, the higher the authenticity of the model output. When the value of the AUC parameter is 0.5, the authenticity of the model output is the lowest.
[0138] Exemplarily, the adaptive temperature layer is used to control the smoothness of the distribution in the normalization function. When the AUC parameter fed back by the model evaluation module is low, it indicates that the model has poor ability to distinguish different categories. At this time, the adaptive temperature module can improve the value of the temperature control matrix, thereby accelerating the model fitting process. For example, by setting the initial temperature and dividing the initial temperature by the logarithm of the average AUC of 5 rounds of training on the model to nonlinearly control the value of the temperature matrix, adaptive temperature is achieved.
[0139] Among them, the above-mentioned initial temperature can be specifically set according to actual conditions, and the embodiments of the present application do not limit this.
[0140] The following describes how to train a text similarity detection model.
[0141] In some embodiments, the text similarity detection model is generated after training with a target sample data set, where the target sample data set is a sample data set generated after the prompt word engineering-driven language model expands the initial corpus data.
[0142] In some embodiments, the server may first obtain the initial corpus data, and secondly, the server may segment the initial expected data to obtain multiple first text samples, and replace the multiple first text samples with synonyms or antonyms respectively. Thirdly, the server may input the multiple first text samples after the synonyms or antonyms are replaced into the prompt word engineering driven language model, and obtain the multiple second text samples generated by the prompt word engineering driven language model according to the correlation of the synonym or antonym replacement and the similarity labels corresponding to the multiple second text samples respectively. Finally, the server may generate a target sample data set according to the multiple first text samples, the multiple second text samples and the similarity labels corresponding to the multiple second text samples respectively, and use the target sample data set to train the text similarity detection model.
[0143] Among them, the above-mentioned initial expected data can be Chinese corpus data, and the above-mentioned initial expected data can be obtained from multiple data sources, and can be obtained from a preset data source, which is not limited in the embodiment of the present application.
[0144] For example, after the server obtains the initial expected data, each sentence in the initial expected data can be segmented into 50 words, and each segmented text is a set of first text samples. Subsequently, multiple first text samples can be replaced with synonyms or antonyms, and for the first text sample corresponding to the first label, the words therein can be replaced with synonyms, and for the first text sample corresponding to the second label, the words therein can be replaced with antonyms.
[0145] The similarity tag includes a first tag and a second tag, the first tag is used to indicate that the first text sample and the second text sample are similar, and the second tag is used to indicate that the first text sample and the second text sample are not similar. Exemplarily, the first tag can be a tag with a value of 1, and the second tag can be a tag with a value of 0.
[0146] Exemplarily, after synonym or antonym replacement, multiple first text samples after synonym or antonym replacement can be respectively input into the prompt word engineering driven language model, and the text generation capability of the prompt word engineering driven language model is used to generate second text samples and similarity labels according to the degree of similarity.
[0147] In some embodiments, if the correlation is greater than zero, the similarity tag is the first tag; if the correlation is less than or equal to zero, the similarity tag is the second tag.
[0148] For example, the correlation can be divided into six types: correlation 0, correlation 20%, correlation 40%, correlation 60%, correlation 80%, and correlation 100%. At this time, the part with correlation greater than 0 can be recorded as the first label, and the sample data corresponding to the first label can account for 50% of the target sample data set. The remaining sentences are assigned to correlation 0 and marked as the second label.
[0149] In some embodiments, after obtaining the plurality of second text samples generated by the prompt word engineering driven language model according to the correlation of synonym or antonym replacement and the similarity labels respectively corresponding to the plurality of second text samples, the server may also determine the text samples to be processed from the plurality of first text samples and the plurality of second text samples respectively according to the preset word order processing ratio. Subsequently, the server may input the text samples to be processed into the word order processing model to perform word order exchange on the text samples to be processed.
[0150] Among them, the above-mentioned preset word order processing ratio can be specifically set according to actual conditions. For example, the preset word order processing ratio can include 10%, 15%, 20%, and 30%.
[0151] Exemplarily, after completing data generation by driving the language model through prompt word engineering, 20% of the text samples to be processed can be randomly extracted from the first label and the second label and input into the word order processing model. The word order of the text samples to be processed can be exchanged using the word order processing model to improve the generalization ability of the text similarity detection model.
[0152] In this application, through the training method of the above-mentioned text similarity detection model, 260,000 low-quality data can be expanded to 490,000 high-quality data, thereby generating a target sample data set. Through the training method of the text similarity detection model, the grammatical similarity such as synonyms and similar sentences can be covered, which can not only improve the generalization ability of the text similarity detection model. It can also better expand the target sample data set.
[0153] The following describes how to test the text similarity detection model.
[0154] In some embodiments, the output of the text similarity detection model also includes the confidence of the similarity label. Accordingly, after the text similarity detection model is trained using the target sample data set, the server can first obtain the test question and the standard answer text corresponding to the test question from the database. Secondly, the server can input the test question into the large language model and obtain the generated answer text corresponding to the test question output by the large language model. Thirdly, the server can input the standard answer text and the generated answer text into the text similarity detection model and obtain the similarity label and confidence between the standard answer text and the generated answer text output by the text similarity detection model. Finally, the server can determine the reliability of the similarity label output by the text similarity detection model based on the confidence.
[0155] Exemplarily, after the standard answer text and the generated answer text are combined into a sequence to test the input text similarity detection model, the text similarity detection model can output a test result, which includes a similarity label and confidence between the standard answer text and the generated answer text. If the output similarity label is 1 (first label), it means that the standard answer text and the generated answer text are consistent. If the output similarity label is 0 (second label), it means that the standard answer text and the generated answer text are inconsistent.
[0156] It should be understood that the embodiments of the present application do not limit how to determine the reliability of the similarity label output by the text similarity detection model according to the confidence level. In some embodiments, if the confidence level is less than the confidence threshold, the similarity label output by the text similarity detection model is determined to be unreliable. If the confidence level is greater than or equal to the confidence threshold, the similarity label output by the text similarity detection model is determined to be reliable.
[0157] Among them, the above-mentioned confidence threshold can be specifically set according to actual conditions, and the embodiment of the present application does not limit this. Exemplarily, it can be set to 0.7, 0.8, 0.9, etc.
[0158] In some embodiments, after determining that the similarity labels output by the text similarity detection model are unreliable, the similarity labels output by the text similarity detection model are converted into label types.
[0159] For example, the label type conversion based on whether the similarity label is reliable can be a linear optimization process of the text similarity detection model output. When the similarity label output by the model is 1 and the label confidence is less than 0.7, the output of the model is considered unreliable, so the output similarity label is converted to a label of 0.
[0160] In this application, by verifying and linearly optimizing the text similarity detection model in the above manner, the deep semantic relationship between the generated answer text of the large language model and the standard answer text can be accurately determined, thereby determining whether the text similarity detection model has errors, disorders or hallucinations.
[0161] The similarity detection method provided by the present application is a method that takes into account both accuracy and speed, and can replace the traditional manual judgment method to determine whether there is disorder or hallucination problems in the output of the judgment model.
[0162] Exemplarily, Table 1 is a performance comparison table of the text similarity detection model provided in the embodiment of the present application and related models. As shown in Table 1, the text similarity detection model provided in the embodiment of the application uses a novel data set expansion method and an efficient network structure. While improving computational efficiency, it has higher performance than open source models such as the Attention-Based Convolutional Neural Network (ABCNN) model, Albert model, Bert model, Bilateral Multi-Perspective Matching (BIMPM) model, Decomposable Attention model, Distil Bert model, Enhanced Sequential Inference Model (ESIM), Roberta model, SiaGRU model, and Generalized Autoregressive Pretraining for Language Understanding (XlNet) model, and has achieved the best performance on the same 12,500 test sets. The text similarity detection model provided in the application embodiment has a small number of model parameters, fast calculation speed, small video memory occupancy, low model overfitting degree, strong semantic extraction capability, and strong model generalization capability.
[0163] Table 1
[0164]
[0165] The text similarity detection method provided in the embodiment of the present application, first, obtains a first text to be tested and a second text to be tested; inputs the first text to be tested and the second text to be tested into a text similarity detection model, and obtains a similarity label between the first text to be tested and the second text to be tested output by the text similarity detection model; wherein the text similarity detection model is generated after training with a target sample data set, the target sample data set is a sample data set generated after the prompt word engineering-driven language model expands the initial corpus data, and the text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolution attention module, and the bidirectional LSTM module and the multi-scale convolution attention module are used to extract features from the input data of the text similarity detection model. Since the text similarity detection model in the present application is generated after training with a sample data set generated after the initial corpus data is expanded, the generalization of the text similarity detection model can be improved, and at the same time, the text similarity detection model improves the accuracy of feature extraction by extracting features from the LSTM module and the multi-scale convolution attention module, based on this, the text similarity detection method provided by the present application can improve the accuracy of text similarity detection.
[0166] The following describes how to train the above text similarity detection method. Figure 4 A flowchart of a method for training a text similarity detection model provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, the training method of the text similarity detection model includes S301-S306:
[0167] S301, obtaining initial corpus data.
[0168] Among them, the above-mentioned initial expected data can be Chinese corpus data, and the above-mentioned initial expected data can be obtained from multiple data sources, and can be obtained from a preset data source, which is not limited in the embodiment of the present application.
[0169] S302: Segment the initial expected data to obtain a plurality of first text samples.
[0170] Exemplarily, after the server obtains the initial expected data, each sentence in the initial expected data may be segmented into segments of 50 words, and each segmented text is a set of first text samples.
[0171] S303: Replace the plurality of first text samples with synonyms or antonyms respectively.
[0172] In some embodiments, multiple first text samples can be replaced with synonyms or antonyms respectively. For the first text sample corresponding to the first label, the words therein can be replaced with synonyms, and for the first text sample corresponding to the second label, the words therein can be replaced with antonyms.
[0173] The similarity label includes a first label and a second label, the first label is used to indicate that the first text sample and the second text sample are similar, and the second label is used to indicate that the first text sample and the second text sample are not similar.
[0174] S304, inputting the plurality of first text samples after synonym or antonym replacement into the prompt word engineering driven language model respectively, and obtaining the plurality of second text samples generated by the prompt word engineering driven language model according to the correlation of synonym or antonym replacement and the similarity labels respectively corresponding to the plurality of second text samples.
[0175] Among them, the text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolutional attention module. The bidirectional LSTM module and the multi-scale convolutional attention module are used to extract features from the input data of the text similarity detection model.
[0176] If the correlation is greater than zero, the similarity label is the first label; if the correlation is less than or equal to zero, the similarity label is the second label.
[0177] In some embodiments, after obtaining multiple second text samples generated by the prompt word engineering driven language model according to the correlation of synonym or antonym replacement and the similarity labels respectively corresponding to the multiple second text samples, the text samples to be processed can be determined from the multiple first text samples and the multiple second text samples according to the preset word order processing ratio. Subsequently, the text samples to be processed are input into the word order processing model to perform word order exchange on the text samples to be processed.
[0178] S305: Generate a target sample data set according to the plurality of first text samples, the plurality of second text samples, and the similarity labels respectively corresponding to the plurality of second text samples.
[0179] S306: Use the target sample data set to train the text similarity detection model.
[0180] Figure 5 A flowchart of another text similarity detection method provided in an embodiment of the present application is shown as follows: Figure 5 As shown, the text similarity detection method includes S401-S415:
[0181] S401: Obtain initial corpus data.
[0182] S402: Segment the initial expected data to obtain a plurality of first text samples.
[0183] S403: Replace the plurality of first text samples with synonyms or antonyms respectively.
[0184] S404, inputting the plurality of first text samples after synonym or antonym replacement into the prompt word engineering driven language model respectively, and obtaining the plurality of second text samples generated by the prompt word engineering driven language model according to the correlation of synonym or antonym replacement and the similarity labels respectively corresponding to the plurality of second text samples.
[0185] S405: Generate a target sample data set according to the plurality of first text samples, the plurality of second text samples, and the similarity labels respectively corresponding to the plurality of second text samples.
[0186] S406: Determine text samples to be processed from the plurality of first text samples and the plurality of second text samples respectively according to a preset word order processing ratio.
[0187] S407: Input the text sample to be processed into a word order processing model to exchange the word order of the text sample to be processed.
[0188] S408: Use the target sample data set to train the text similarity detection model.
[0189] S409: Obtain test questions and standard answer texts corresponding to the test questions from a database.
[0190] S410: Input a test question into the large language model, and obtain a generated answer text corresponding to the test question output by the large language model.
[0191] S411. Input the standard answer text and the generated answer text into a text similarity detection model, and obtain a similarity label and confidence between the standard answer text and the generated answer text output by the text similarity detection model.
[0192] S412: Determine the reliability of the similarity label output by the text similarity detection model according to the confidence level.
[0193] S413: If it is determined that the similarity label output by the text similarity detection model is unreliable, the similarity label output by the text similarity detection model is converted into a label type.
[0194] S414: Obtain a first text to be tested and a second text to be tested.
[0195] S415: Input the first text to be tested and the second text to be tested into a text similarity detection model, and obtain a similarity label between the first text to be tested and the second text to be tested output by the text similarity detection model.
[0196] Among them, the text similarity detection model is generated after training with the target sample data set. The target sample data set is a sample data set generated after the prompt word engineering-driven language model expands the initial corpus data. The text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolutional attention module. The bidirectional LSTM module and the multi-scale convolutional attention module are used to extract features from the input data of the text similarity detection model.
[0197] The text similarity detection method provided in the embodiment of the present application, first, obtains a first text to be tested and a second text to be tested; inputs the first text to be tested and the second text to be tested into a text similarity detection model, and obtains a similarity label between the first text to be tested and the second text to be tested output by the text similarity detection model; wherein the text similarity detection model is generated after training with a target sample data set, the target sample data set is a sample data set generated after the prompt word engineering-driven language model expands the initial corpus data, and the text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolution attention module, and the bidirectional LSTM module and the multi-scale convolution attention module are used to extract features from the input data of the text similarity detection model. Since the text similarity detection model in the present application is generated after training with a sample data set generated after the initial corpus data is expanded, the generalization of the text similarity detection model can be improved, and at the same time, the text similarity detection model improves the accuracy of feature extraction by extracting features from the LSTM module and the multi-scale convolution attention module, based on this, the text similarity detection method provided by the present application can improve the accuracy of text similarity detection.
[0198] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0199] Based on the same inventive concept, the embodiment of the present application also provides a text similarity detection device for implementing the above-mentioned text similarity detection method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above-mentioned method, so the specific limitations in the one or more text similarity detection device embodiments provided below can refer to the limitations of the text similarity detection method above, and will not be repeated here.
[0200] In an exemplary embodiment, Figure 6 As shown, a text similarity detection device 500 is provided, comprising: a first acquisition module 501 and a detection module 502, wherein:
[0201] The first acquisition module 501 is used to acquire a first text to be tested and a second text to be tested.
[0202] The detection module 502 is used to input the first text to be tested and the second text to be tested into a text similarity detection model, and obtain a similarity label between the first text to be tested and the second text to be tested output by the text similarity detection model.
[0203] Among them, the text similarity detection model is generated after training with the target sample data set. The target sample data set is a sample data set generated after the prompt word engineering-driven language model expands the initial corpus data. The text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolutional attention module. The bidirectional LSTM module and the multi-scale convolutional attention module are used to extract features from the input data of the text similarity detection model.
[0204] In one embodiment, the text similarity detection device further includes:
[0205] The training module is used to obtain initial corpus data; segment the initial expected data to obtain multiple first text samples; replace the multiple first text samples with synonyms or antonyms respectively; input the multiple first text samples after the synonyms or antonyms are replaced into a prompt word engineering driven language model respectively, and obtain multiple second text samples generated by the prompt word engineering driven language model according to the correlation of the synonyms or antonyms replacement and the similarity labels corresponding to the multiple second text samples respectively; generate a target sample data set according to the multiple first text samples, the multiple second text samples and the similarity labels corresponding to the multiple second text samples respectively; and use the target sample data set to train the text similarity detection model.
[0206] In one of the embodiments, the training module is further used to determine the text samples to be processed from multiple first text samples and multiple second text samples respectively according to a preset word order processing ratio; and input the text samples to be processed into the word order processing model to exchange the word order of the text samples to be processed.
[0207] In one embodiment, the similarity tag includes a first tag and a second tag, the first tag is used to indicate that the first text sample and the second text sample are similar, and the second tag is used to indicate that the first text sample and the second text sample are not similar.
[0208] In one embodiment, if the correlation is greater than zero, the similarity label is the first label; if the correlation is less than or equal to zero, the similarity label is the second label.
[0209] In one of the embodiments, the output of the text similarity detection model also includes the confidence of the similarity label.
[0210] The text similarity detection device also includes:
[0211] The verification module is used to obtain test questions and standard answer texts corresponding to the test questions from a database; input the test questions into a large language model and obtain the generated answer texts corresponding to the test questions output by the large language model; input the standard answer texts and the generated answer texts into a text similarity detection model and obtain the similarity labels and confidences between the standard answer texts and the generated answer texts output by the text similarity detection model; and determine the reliability of the similarity labels output by the text similarity detection model based on the confidences.
[0212] In one embodiment, the verification module is further used to determine that the similarity label output by the text similarity detection model is unreliable if the confidence is less than the confidence threshold; and to determine that the similarity label output by the text similarity detection model is reliable if the confidence is greater than or equal to the confidence threshold.
[0213] In one of the embodiments, the verification module is further used to convert the similarity labels output by the text similarity detection model into label types.
[0214] In one embodiment, the bidirectional LSTM module includes a forward LSTM module and a backward LSTM module, and the text similarity detection model also includes a data dimension enhancement module, a data dimension reduction module, a feature weighting module and a classifier module.
[0215] The forward LSTM module is used to encode the input data of the text similarity detection model into a first feature sequence, obtain the positive dependency information in the first feature sequence from the start direction to the end direction of the first feature sequence, and convert the first feature sequence into a second feature sequence according to the positive dependency information.
[0216] The data dimension upgrading module is used to add the features of the target dimension to the second feature sequence by rearranging and expanding the dimensions of the second feature sequence to generate a third feature sequence.
[0217] Multi-scale convolutional attention module to extract contextual information from the third feature sequence.
[0218] The feature weighting module is used to perform weighted processing on the third feature sequence according to the context information to obtain a fourth feature sequence.
[0219] The data dimension reduction module is used to remove the features of the target dimension in the fourth feature sequence to obtain the fifth feature sequence.
[0220] The backward LSTM module is used to obtain reverse dependency information in the fifth feature sequence from the end direction to the start direction of the fifth feature sequence, and convert the fifth feature sequence into a sixth feature sequence according to the reverse dependency information.
[0221] The classifier module is used to generate similarity labels of input data and confidence data of the similarity labels according to the sixth feature sequence.
[0222] In one of the embodiments, the text similarity detection model further includes an adaptive temperature module and a model evaluation module.
[0223] The model evaluation module is used to obtain the model evaluation parameters of the text similarity detection model in each round of training based on the target sample data set and output data of the text similarity detection model.
[0224] The adaptive temperature module is used to obtain the value of the temperature control matrix according to the preset initial temperature and the model evaluation parameters of the text similarity detection model in each round of training, and control the smoothness of the normalization function of the text similarity detection model according to the value of the temperature control matrix.
[0225] Each module in the above-mentioned text similarity detection device can be implemented in whole or in part by software, hardware and a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.
[0226] Based on the same inventive concept, the embodiment of the present application also provides a training device for a text similarity detection model for implementing the training method for the text similarity detection model involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiments of the training device for one or more text similarity detection models provided below can refer to the limitations of the training method for the text similarity detection model above, and will not be repeated here.
[0227] In an exemplary embodiment, Figure 7As shown, a training device 600 for a text similarity detection model is provided, comprising: a second acquisition module 601, a processing module 602 and a generation module 603, wherein:
[0228] The second acquisition module 601 is used to acquire initial corpus data.
[0229] The processing module 602 is used to segment the initial expected data to obtain a plurality of first text samples; and replace the plurality of first text samples with synonyms or antonyms respectively.
[0230] The generation module 603 is used to input the multiple first text samples after the synonyms or antonyms are replaced into the prompt word engineering driven language model respectively, and obtain the multiple second text samples generated by the prompt word engineering driven language model according to the correlation of the synonyms or antonyms replacement and the similarity labels corresponding to the multiple second text samples respectively, wherein the text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolutional attention module, and the bidirectional LSTM module and the multi-scale convolutional attention module are used to extract features from the input data of the text similarity detection model; generate a target sample data set according to the multiple first text samples, the multiple second text samples and the similarity labels corresponding to the multiple second text samples respectively; and use the target sample data set to train the text similarity detection model.
[0231] Each module in the training device of the above text similarity detection model can be implemented in whole or in part by software, hardware and a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module above.
[0232] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 8As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a text similarity detection method or a training method for a text similarity detection model is implemented.
[0233] Those skilled in the art will understand that Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0234] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the above-mentioned text similarity detection method or text similarity detection model training method when executing the computer program.
[0235] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned text similarity detection method or text similarity detection model training method is implemented.
[0236] In one embodiment, a computer program product is provided, including a computer program, which implements the above-mentioned text similarity detection method or text similarity detection model training method when executed by a processor.
[0237] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0238] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0239] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A text similarity detection method, characterized in that: The method comprises: Obtain a first text to be tested and a second text to be tested; Inputting the first text to be tested and the second text to be tested into a text similarity detection model, and obtaining a similarity label between the first text to be tested and the second text to be tested output by the text similarity detection model; Among them, the text similarity detection model is generated after training with a target sample data set, and the target sample data set is a sample data set generated after the prompt word engineering-driven language model expands the initial corpus data. The text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolutional attention module. The bidirectional LSTM module and the multi-scale convolutional attention module are used to extract features from the input data of the text similarity detection model.
2. The method according to claim 1, characterized in that The method further comprises: Get the initial corpus data; Segmenting the initial expected data to obtain a plurality of first text samples; Replacing the plurality of first text samples with synonyms or antonyms respectively; Inputting the plurality of first text samples after synonyms or antonyms are replaced into the prompt word engineering driven language model respectively, and obtaining the plurality of second text samples generated by the prompt word engineering driven language model according to the correlation of synonyms or antonyms replacement and the similarity labels respectively corresponding to the plurality of second text samples; Generate the target sample data set according to the plurality of first text samples, the plurality of second text samples and the similarity labels respectively corresponding to the plurality of second text samples; The target sample data set is used to train the text similarity detection model.
3. The method according to claim 2, characterized in that After obtaining the plurality of second text samples generated by the prompt word engineering driven language model according to the relevance of synonym or antonym replacement and the similarity labels respectively corresponding to the plurality of second text samples, the method further includes: According to a preset word order processing ratio, determining text samples to be processed from the plurality of first text samples and the plurality of second text samples respectively; The text sample to be processed is input into a word order processing model to exchange the word order of the text sample to be processed.
4. The method according to claim 2, characterized in that: The similarity label includes a first label and a second label, the first label is used to indicate that the first text sample and the second text sample are similar, and the second label is used to indicate that the first text sample and the second text sample are not similar.
5. The method according to claim 4, characterized in that If the correlation is greater than zero, the similarity label is the first label; if the correlation is less than or equal to zero, the similarity label is the second label.
6. The method according to claim 2, characterized in that The output of the text similarity detection model also includes the confidence of the similarity label; After the text similarity detection model is trained using the target sample data set, the method further includes: Acquire test questions and standard answer texts corresponding to the test questions from a database; Inputting the test question into a large language model, and obtaining a generated answer text corresponding to the test question output by the large language model; Inputting the standard answer text and the generated answer text into the text similarity detection model, and obtaining the similarity label and confidence between the standard answer text and the generated answer text output by the text similarity detection model; According to the confidence level, the reliability of the similarity label output by the text similarity detection model is determined.
7. The method according to claim 6, characterized in that Determining the reliability of the similarity label output by the text similarity detection model according to the confidence level includes: If the confidence is less than the confidence threshold, determining that the similarity label output by the text similarity detection model is unreliable; If the confidence is greater than or equal to the confidence threshold, the reliability of the similarity label output by the text similarity detection model is determined.
8. The method according to claim 7, characterized in that After determining that the similarity label output by the text similarity detection model is unreliable, the method further includes: The similarity labels output by the text similarity detection model are converted into label types.
9. The method according to claim 1, characterized in that: The bidirectional LSTM module includes a forward LSTM module and a backward LSTM module, and the text similarity detection model also includes a data dimension increase module, a data dimension reduction module, a feature weighting module and a classifier module; The forward LSTM module is used to encode the input data of the text similarity detection model into a first feature sequence, obtain the positive dependency information in the first feature sequence from the start direction to the end direction of the first feature sequence, and convert the first feature sequence into a second feature sequence according to the positive dependency information; The data dimension upgrading module is used to add features of a target dimension to the second feature sequence by performing dimension rearrangement and dimension expansion on the second feature sequence, so as to generate a third feature sequence; The multi-scale convolutional attention module is used to extract context information from the third feature sequence; The feature weighting module is used to perform weighted processing on the third feature sequence according to the context information to obtain a fourth feature sequence; The data dimension reduction module is used to remove the features of the target dimension from the fourth feature sequence to obtain a fifth feature sequence; The backward LSTM module is used to obtain reverse dependency information in the fifth feature sequence from the end direction to the start direction of the fifth feature sequence, and convert the fifth feature sequence into a sixth feature sequence according to the reverse dependency information; The classifier module is used to generate a similarity label of the input data and confidence data of the similarity label according to the sixth feature sequence.
10. The method according to claim 9, characterized in that The text similarity detection model also includes an adaptive temperature module and a model evaluation module; The model evaluation module is used to obtain the model evaluation parameters of the text similarity detection model in each round of training according to the target sample data set and output data of the text similarity detection model; The adaptive temperature module is used to obtain the value of the temperature control matrix according to the preset initial temperature and the model evaluation parameters of the text similarity detection model in each round of training, and control the smoothness of the normalization function of the text similarity detection model according to the value of the temperature control matrix.
11. A training method for a text similarity detection model, characterized in that: The method comprises: Get the initial corpus data; Segmenting the initial expected data to obtain a plurality of first text samples; Replacing the plurality of first text samples with synonyms or antonyms respectively; Inputting a plurality of first text samples after synonyms or antonyms are replaced into a prompt word engineering driven language model respectively, and obtaining a plurality of second text samples generated by the prompt word engineering driven language model according to the correlation of synonyms or antonyms replacement and similarity labels respectively corresponding to the plurality of second text samples, wherein the text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolutional attention module, and the bidirectional LSTM module and the multi-scale convolutional attention module are used to extract features from the input data of the text similarity detection model; Generate a target sample data set according to the plurality of first text samples, the plurality of second text samples and the similarity labels respectively corresponding to the plurality of second text samples; The target sample data set is used to train the text similarity detection model.
12. A text similarity detection device, characterized in that: The device comprises: A first acquisition module, used to acquire a first text to be tested and a second text to be tested; A detection module, used for inputting the first text to be tested and the second text to be tested into a text similarity detection model, and obtaining a similarity label between the first text to be tested and the second text to be tested output by the text similarity detection model; Among them, the text similarity detection model is generated after training with a target sample data set, and the target sample data set is a sample data set generated after the prompt word engineering-driven language model expands the initial corpus data. The text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolutional attention module. The bidirectional LSTM module and the multi-scale convolutional attention module are used to extract features from the input data of the text similarity detection model.
13. A training device for a text similarity detection model, characterized in that: The device comprises: The second acquisition module is used to acquire initial corpus data; A processing module, configured to segment the initial expected data to obtain a plurality of first text samples; and replace the plurality of first text samples with synonyms or antonyms respectively; A generation module is used to input multiple first text samples after synonyms or antonyms are replaced into a prompt word engineering driven language model, and obtain multiple second text samples generated by the prompt word engineering driven language model according to the correlation of synonyms or antonyms replacement and similarity labels corresponding to the multiple second text samples, wherein the text similarity detection model includes a bidirectional long short-term memory network LSTM module and a multi-scale convolutional attention module, and the bidirectional LSTM module and the multi-scale convolutional attention module are used to extract features from the input data of the text similarity detection model; generate a target sample data set according to the multiple first text samples, the multiple second text samples and the similarity labels corresponding to the multiple second text samples; and use the target sample data set to train the text similarity detection model.
14. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 11 are implemented.
15. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
16. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
Citation Information
Cited By
Patent agency whole-process intelligent management method based on artificial intelligence and big data
CN120235734A