Text similarity calculation method and device, electronic equipment and storage medium
By combining part-of-speech analysis and similarity prediction models, the problem of semantic focus loss caused by ambiguity in text-to-text interaction operations is solved, achieving rapid and accurate identification of text similarity and improving user experience.
Patent Information
- Application Number
- CN202210864906.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-21
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2042-07-21
AI Technical Summary
In existing technologies, the interaction between texts is ambiguous, leading to a loss of semantic focus, reduced accuracy of text similarity recognition, and a poor user experience.
By acquiring user-input text and feeding it into a trained part-of-speech (POS) analysis model, the model outputs POS information. This POS information is then input into a similarity prediction model. The model utilizes POS information for sentence encoding and feature vector concatenation, and a POS attention network is used to improve model performance and avoid loss of semantic focus.
It achieves fast and accurate text similarity recognition, improves recognition accuracy and speed, enhances user experience, and reduces model inference time.
Smart Images

Figure CN115221284B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, in particular to a text similarity calculation method and device, electronic equipment and storage medium. BACKGROUND
[0002] With the rapid development of artificial intelligence technologies such as intelligent customer service and dialogue robots, and intelligent question answering being an important influencing factor of the artificial intelligence technologies, how to improve the accuracy of intelligent question answering is particularly important. Among them, text similarity recognition is one of the keys to realizing intelligent question answering, and user input information is expressed in various ways, such as omission of some words and reverse order of words, which will bring certain difficulty to text similarity.
[0003] In related technologies, the semantic similarity between texts is compared by artificially constructing features, and after these artificial features are extracted, a traditional machine learning model is used to calculate the text similarity. However, the interaction between texts in related technologies is ambiguous, and the information of the mutual influence between texts cannot be clearly determined, which easily loses the semantic focus and greatly reduces the accuracy of text similarity recognition, resulting in poor user experience. SUMMARY
[0004] The present application provides a text similarity calculation method, device, electronic equipment and storage medium to solve the problem that the interaction between texts is ambiguous in related technologies, resulting in loss of semantic focus, reduction of accuracy of text similarity recognition, and poor user experience.
[0005] The first aspect of the present application provides a text similarity calculation method, comprising the following steps: obtaining a first text and a second text input by a user; inputting the first text and the second text into a trained part-of-speech analysis model to output first part-of-speech information of the first text and second part-of-speech information of the second text, wherein the part-of-speech analysis model is trained based on a first training sample carrying a part-of-speech label; inputting the first part-of-speech information and the second part-of-speech information into a trained similarity prediction model to output a text similarity result between the first text and the second text, wherein the similarity prediction model is trained based on a second training sample carrying a text similarity label.
[0006] According to the above technical means, the present application embodiment can help the model to determine the semantic focus based on the part-of-speech information, realize the rapid and accurate recognition of the text similarity, so as to clearly determine the interaction between texts, avoid the loss of text semantic focus, effectively improve the accuracy of text similarity recognition, and improve the speed of recognition based on the model recognition of part-of-speech and similarity, and improve the user experience.
[0007] Optionally, in an embodiment of the present application, the inputting the first text and the second text into the trained part-of-speech analysis model to output first part-of-speech information of the first text and second part-of-speech information of the second text comprises: extracting at least one target keyword of the first text and the second text from the vertical domain; identifying the actual part-of-speech of each target keyword and performing part-of-speech tagging on the each target keyword to obtain the first part-of-speech information and the second part-of-speech information.
[0008] According to the above technical means, the embodiment of the present application can extract the target keyword of the text information from the vertical domain and identify the actual part-of-speech, and obtain the part-of-speech information of the text by tagging the keyword, which is more reliable and accurate.
[0009] Optionally, in an embodiment of the present application, the part-of-speech analysis model is trained based on a first training sample carrying a part-of-speech label, comprising: obtaining a first training sample carrying a part-of-speech label; extracting at least one target keyword of the first training sample from the vertical domain; identifying the actual part-of-speech of each target keyword and performing part-of-speech tagging on the each target keyword until the number of tagged keywords meets a preset number to obtain the part-of-speech analysis model.
[0010] According to the above technical means, the embodiment of the present application can extract the target keyword of the training sample carrying the part-of-speech label from the vertical domain, and obtain the part-of-speech analysis model by identifying the actual part-of-speech of each target keyword and performing tagging until the number meets the preset number, which has small calculation amount and high accuracy.
[0011] Optionally, in an embodiment of the present application, the inputting the first part-of-speech information and the second part-of-speech information into the trained similarity prediction model to output a text similarity result between the first text and the second text comprises: inputting the first part-of-speech information and the second part-of-speech information into a sentence encoding network to output a first sentence encoding result of the first part-of-speech information and a second sentence encoding result of the second part-of-speech information; inputting the first sentence encoding result and the second sentence encoding result into a part-of-speech attention network to output a first feature vector of the first sentence encoding result and a second feature vector of the second sentence encoding result; splicing the first feature vector and the second feature vector to obtain a splicing result, inputting the splicing result into a full connection layer for classification, and matching the classification result to obtain the text similarity result.
[0012] According to the technical means, the embodiments of the present application can encode a sentence by using part-of-speech information, so that the model can better grasp the semantic focus, improve the model effect without increasing the model inference time too much, and has the landing ability, so that a large pre-training model does not need to be used, and good similarity calculation effect can be obtained while the inference speed is considered.
[0013] Optionally, in an embodiment of the present application, the similarity prediction model is trained based on the second training sample carrying the text similarity label, and the method comprises: obtaining the second training sample carrying the text similarity label, wherein the second training sample comprises part-of-speech information of a first training text and part-of-speech information of a second training text; inputting the part-of-speech information of the first training text and the part-of-speech information of the second training text into a sentence encoding network to output a first sentence encoding result of the part-of-speech information of the first training text and a second sentence encoding result of the part-of-speech information of the second training text; inputting the first sentence encoding result and the second sentence encoding result into a part-of-speech attention network to output a first feature vector of the first sentence encoding result and a second feature vector of the second sentence encoding result; splicing the first feature vector and the second feature vector to obtain a splicing result, and inputting the splicing result into a full connection layer for classification, and matching the text similarity result according to a classification result until a training iteration termination condition is met, to obtain the similarity prediction model.
[0014] According to the technical means, the embodiments of the present application can increase the part-of-speech attention network of the training sample carrying the text similarity label, so that the network can encode a sentence based on part-of-speech by using the prior knowledge of part-of-speech, obtain a splicing result, input the splicing result into a full connection layer for classification, match a text similarity result, perform multiple training, obtain a similarity prediction model, and have high accuracy, so that the model can better grasp the semantic focus and improve the efficiency of text similarity calculation.
[0015] The second aspect embodiment of the present application provides a text similarity calculation device, comprising: an acquisition module configured to acquire a first text and a second text input by a user; an analysis module configured to input the first text and the second text into a part-of-speech analysis model trained based on a first training sample carrying a part-of-speech label, and output first part-of-speech information of the first text and second part-of-speech information of the second text; and a calculation module configured to input the first part-of-speech information and the second part-of-speech information into a similarity prediction model trained based on a second training sample carrying a text similarity label, and output a text similarity result between the first text and the second text.
[0016] Optionally, in one embodiment of this application, the analysis module includes: an extraction unit, configured to extract at least one target keyword from the first text and the second text from the vertical domain; and an identification unit, configured to identify the actual part-of-speech of each target keyword and perform part-of-speech tagging on each target keyword to obtain the first part-of-speech information and the second part-of-speech information.
[0017] Optionally, in one embodiment of this application, it further includes: a first training module, configured to acquire a first training sample carrying part-of-speech tags, extract at least one target keyword from the first training sample in the vertical domain, identify the actual part-of-speech of each target keyword, and perform part-of-speech tagging on each target keyword until the number of tagged keywords meets a preset number, thereby obtaining the part-of-speech analysis model.
[0018] Optionally, in one embodiment of this application, the computing module includes: a first generation unit, configured to input the first part-of-speech information and the second part-of-speech information into a sentence encoding network, and output a first sentence encoding result of the first part-of-speech information and a second sentence encoding result of the second part-of-speech information; a second generation unit, configured to input the first sentence encoding result and the second sentence encoding result into a part-of-speech attention network, and output a first feature vector of the first sentence encoding result and a second feature vector of the second sentence encoding result; and a concatenation unit, configured to concatenate the first feature vector and the second feature vector to obtain a concatenation result, input the concatenation result into a fully connected layer for classification, and obtain the text similarity result based on the classification result.
[0019] Optionally, in one embodiment of this application, it further includes: a second training module, configured to acquire a second training sample carrying text similarity labels, wherein the second training sample includes part-of-speech information of a first training text and part-of-speech information of a second training text; inputting the part-of-speech information of the first training text and the part-of-speech information of the second training text into a sentence encoding network, outputting a first sentence encoding result of the part-of-speech information of the first training text and a second sentence encoding result of the part-of-speech information of the second training text; inputting the first sentence encoding result and the second sentence encoding result into a part-of-speech attention network, outputting a first feature vector of the first sentence encoding result and a second feature vector of the second sentence encoding result; concatenating the first feature vector and the second feature vector to obtain a concatenated result, and inputting the concatenated result into a fully connected layer for classification, and matching the text similarity result according to the classification result, until the training iteration termination condition is met, to obtain the similarity prediction model.
[0020] A third aspect of this application provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the text similarity calculation method as described in the above embodiments.
[0021] A fourth aspect of this application provides a computer-readable storage medium having a computer program stored thereon, which is executed by a processor to implement the text similarity calculation method as described in the above embodiments.
[0022] Therefore, this application has at least the following beneficial effects:
[0023] 1. The embodiments of this application can help the model determine the semantic focus based on part-of-speech information, realize the rapid and accurate recognition of text similarity, thereby clarifying the interactive operations between texts, avoiding the loss of text semantic focus, effectively improving the accuracy of text similarity recognition, and can recognize part-of-speech and similarity based on the model, improving the recognition speed and enhancing the user experience.
[0024] 2. The embodiments of this application can extract target keywords from text information in the vertical domain and identify the actual part of speech. By annotating the keywords, the part of speech information of the text can be obtained, which has higher reliability and accuracy.
[0025] 3. The embodiments of this application can extract target keywords of training samples carrying part-of-speech tags from vertical regions. By identifying the actual part of speech of each target keyword and annotating it to meet the preset number, a part-of-speech analysis model is obtained. The computation is small and the accuracy is high.
[0026] 4. The embodiments of this application can use part-of-speech information to encode sentences, enabling the model to better grasp the semantic focus, improve the model performance without increasing the model inference time too much, and have the ability to be deployed. Therefore, without using a large pre-trained model, it can achieve good similarity calculation results while taking into account inference speed.
[0027] 5. In this embodiment, a part-of-speech attention network can be added to the training samples carrying text similarity labels, so that the network can use the input part-of-speech prior knowledge to encode sentences based on the part of speech, obtain the concatenation result and input it into the fully connected layer for classification, match to obtain the text similarity result, perform multiple trainings to obtain a similarity prediction model with high accuracy, so that the model can better grasp the semantic focus and improve the efficiency of text similarity calculation.
[0028] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0029] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein:
[0030] Figure 1 This is a flowchart illustrating a method for calculating text similarity according to an embodiment of this application;
[0031] Figure 2 This is a schematic diagram illustrating the composition of the text similarity calculation method provided according to the embodiments of this application;
[0032] Figure 3 This is a specific network structure diagram of the improved ESIM model provided according to the embodiments of this application;
[0033] Figure 4 This is a block diagram of a text similarity calculation device according to an embodiment of this application;
[0034] Figure 5 This is a schematic diagram of the structure of an electronic device provided according to an embodiment of this application.
[0035] Explanation of reference numerals in the attached diagram: Acquisition module-100, Analysis module-200, Calculation module-300, Memory-501, Processor-502, Communication interface-503. Detailed Implementation
[0036] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this application, and should not be construed as limiting this application.
[0037] The following description, with reference to the accompanying drawings, illustrates a method, apparatus, electronic device, and storage medium for calculating text similarity according to embodiments of this application. Addressing the issues mentioned in the background art, such as ambiguous text-to-text interactions, the inability to clearly define the mutual influence between texts, the easy loss of semantic focus, significantly reduced accuracy of text similarity recognition, and poor user experience, this application provides a method for calculating text similarity. In this method, a first text and a second text input by a user are obtained. The user-input text information is then input into a trained part-of-speech (POS) analysis model to obtain the first POS information of the first text and the second POS information of the second text. This POS information is then input into a trained similarity prediction model to obtain the similarity result between the first text and the second text. By using the POS analysis model and the similarity prediction model, the semantic focus can be better grasped, improving model performance without significantly increasing model inference time. Therefore, this solves the problems in related technologies where ambiguous text-to-text interactions lead to lost semantic focus, reduced accuracy of text similarity recognition, and poor user experience.
[0038] Specifically, Figure 1 This is a flowchart illustrating a method for calculating text similarity provided in an embodiment of this application.
[0039] like Figure 1 As shown, the method for calculating text similarity includes the following steps:
[0040] In step S101, the first text and the second text input by the user are obtained.
[0041] The text can be a string of characters arranged in a specific order, including letters, Chinese characters, numbers, operators, punctuation marks, and other symbols, as well as some functional symbols. The first text and the second text can be user-inputted questions; for example, the first text could be "Does drinking milk before bed improve sleep?", and the second text could be "Does drinking milk before bed help me fall asleep?".
[0042] It is understandable that, in order to accurately calculate the similarity between texts, embodiments of this application may first obtain the first text and the second text input by the user.
[0043] In actual implementation, the embodiments of this application can obtain the first text and the second text in various ways, such as voice, manual input, client push, server transmission, database information import, computer automatic acquisition, etc., without making specific limitations.
[0044] In step S102, the first text and the second text are input into the trained part-of-speech analysis model, and the first part-of-speech information of the first text and the second part-of-speech information of the second text are output. The part-of-speech analysis model is trained based on the first training sample carrying part-of-speech labels.
[0045] Part of speech (PS) refers to the classification of words based on their characteristics. PSs can include verbs, nouns, pronouns, adjectives, numerals, and classifiers. The PSs of corresponding words in two texts reflect their similarity to some extent. Words with different PSs play different roles in the calculation process and have a significant impact on semantics.
[0046] Therefore, in order to obtain the part-of-speech information of the input text more accurately, embodiments of this application can input the first text and the second text into a part-of-speech analysis model trained based on the first training sample carrying part-of-speech labels, thereby obtaining the first part-of-speech information of the first text and the second part-of-speech information of the second text more accurately.
[0047] In one embodiment of this application, the first text and the second text are input into a trained part-of-speech analysis model, and the first part-of-speech information of the first text and the second part-of-speech information of the second text are output, including: extracting at least one target keyword from the first text and the second text from the vertical domain; identifying the actual part of speech of each target keyword, and performing part-of-speech tagging on each target keyword to obtain the first part-of-speech information and the second part-of-speech information.
[0048] Since some unique entities in the vertical domain cannot be accurately identified by their part of speech, this embodiment of the application needs to extract entities in the vertical domain. The target keywords of the first and second texts can be extracted from the vertical domain by methods such as topic modeling, left and right entropy or textRank. By labeling the target keywords with their part of speech, the first part of speech information and the second part of speech information can be obtained.
[0049] In one embodiment of this application, the part-of-speech analysis model is trained based on a first training sample carrying part-of-speech tags, including: obtaining the first training sample carrying part-of-speech tags; extracting at least one target keyword from the first training sample from the vertical domain; identifying the actual part of speech of each target keyword, and tagging each target keyword with part-of-speech tags until the number of tagged keywords meets a preset number, thereby obtaining the part-of-speech analysis model.
[0050] The first training sample can be text with part-of-speech tags. Target keywords can be key noun keywords or verb keywords, etc. The preset number can be determined according to the actual situation and is not specifically limited.
[0051] It is understood that the embodiments of this application can obtain a certain number of first training texts and extract target keywords from the first training samples from the vertical domain. By labeling the target keywords with their parts of speech, the number of keywords reaches a preset value, and a part-of-speech analysis model can be trained. Therefore, the embodiments of this application can quickly and accurately determine the part-of-speech information in the text to be analyzed based on the pre-trained part-of-speech analysis model.
[0052] In step S103, the first part-of-speech information and the second part-of-speech information are input into the trained similarity prediction model, and the text similarity result between the first text and the second text is output. The similarity prediction model is trained based on the second training sample carrying text similarity labels.
[0053] It is understood that the embodiments of this application can use part-of-speech information to encode sentences, enabling the model to better grasp the semantic focus, improve the model performance without increasing the model inference time too much, and obtain the similarity results between texts more accurately and quickly.
[0054] In one embodiment of this application, inputting first part-of-speech information and second part-of-speech information into a trained similarity prediction model and outputting a text similarity result between the first text and the second text includes: inputting the first part-of-speech information and the second part-of-speech information into a sentence encoding network, outputting a first sentence encoding result of the first part-of-speech information and a second sentence encoding result of the second part-of-speech information; inputting the first sentence encoding result and the second sentence encoding result into a part-of-speech attention network, outputting a first feature vector of the first sentence encoding result and a second feature vector of the second sentence encoding result; concatenating the first feature vector and the second feature vector to obtain a concatenated result, inputting the concatenated result into a fully connected layer for classification, and matching the text similarity result based on the classification result.
[0055] This application embodiment can improve model performance by adding a part-of-speech attention network, enabling the network to encode sentences based on the input part-of-speech prior knowledge, thus helping the network better capture semantic focus. The added part-of-speech attention network obtains feature vectors after encoding the sentence. For example, the obtained first text feature vector can be a 128-dimensional vector, and the obtained second text feature vector can also be a 128-dimensional vector. After averaging and maximizing the first and second text feature vectors respectively, these vectors are concatenated and then input into a fully connected layer for classification, outputting text similarity results.
[0056] In one embodiment of this application, the similarity prediction model is trained based on a second training sample carrying text similarity labels, including: obtaining a second training sample carrying text similarity labels, wherein the second training sample includes part-of-speech information of a first training text and part-of-speech information of a second training text; inputting the part-of-speech information of the first training text and the part-of-speech information of the second training text into a sentence encoding network, and outputting a first sentence encoding result of the part-of-speech information of the first training text and a second sentence encoding result of the part-of-speech information of the second training text; inputting the first sentence encoding result and the second sentence encoding result into a part-of-speech attention network, and outputting a first feature vector of the first sentence encoding result and a second feature vector of the second sentence encoding result; concatenating the first feature vector and the second feature vector to obtain a concatenated result, and inputting the concatenated result into a fully connected layer for classification, and matching the text similarity result according to the classification result, until the training iteration termination condition is met, thereby obtaining the similarity prediction model.
[0057] By performing part-of-speech tagging on target keywords in text information through the above embodiments, when the number of tagged keywords reaches a preset value, it can be determined that the text has a high degree of similarity. In this embodiment, the second training sample can be text with high similarity and similarity tags.
[0058] Specifically, in this embodiment, the part-of-speech (POS) information of the first and second training texts, each carrying text similarity labels, is input into a sentence encoding network. The encoding results are then input into an attention network, allowing the network to utilize the prior knowledge of the input POS to encode sentences based on the POS. This helps the network better capture semantic focus. After encoding the sentences, the resulting vector representations are directly concatenated to the feature representations generated in the corresponding network stages and input into the next network stage for further calculation. By training the similarity prediction model using a dataset with added POS labels and saving the optimal model results, the model can better grasp semantic focus, improving the efficiency of text similarity calculation and enabling its application in practical engineering projects.
[0059] In actual execution, the output layer of the similarity prediction model is connected to the fully connected layer to obtain the concatenated result vector. In this embodiment, the fully connected layer can be trained by deep learning algorithm to classify the acquired text.
[0060] The method for calculating text similarity in the embodiments of this application will be described in detail below with reference to the accompanying drawings and specific examples. For example... Figure 2 As shown, the text similarity calculation method of the embodiments of this application is divided into three parts: data annotation, model training, and model prediction. The three parts will be described in detail below.
[0061] 1) Data labeling
[0062] Currently available part-of-speech tagging tools, such as Baidu's LAC (Lexical Analysis of Chinese), are mostly trained on public domain general datasets. Therefore, they cannot accurately identify the parts of speech of some entities specific to vertical domains. The embodiments of this application need to extract entities from vertical domains to enrich the tool's dictionary. The specific method is as follows: First, keywords are extracted from the vertical domain using methods such as topic modeling, left / right entropy, or textRank. Second, noisy keywords are filtered and removed. Finally, the filtered keywords are labeled with their parts of speech to form a part-of-speech dictionary and saved. After obtaining the part-of-speech dictionary, it is imported into the part-of-speech tagging tool, and finally, the parts of speech of the training data are analyzed and labeled.
[0063] 2) Model Training
[0064] Analysis of the text similarity calculation process revealed that words with different parts of speech play varying roles in the calculation. Furthermore, existing large-scale pre-trained models suffer from excessive computational complexity due to their large number of parameters and long inference times, making them impractical for engineering projects. Therefore, this application's embodiment adds a part-of-speech attention network to the ESIM (Enhanced Sequential Inference Model). This allows the network to utilize prior part-of-speech knowledge to encode sentences based on their parts of speech, helping it better capture semantic focus and thus improving model performance. The specific network structure of the improved ESIM model is as follows: Figure 3 As shown, a POS-BasedEncoding network is added to the LocalInferenceModeling and InferenceComposition stages at the bottom layer of the original network to correct semantic focus. The calculation process of sentence encoding is as follows:
[0065]
[0066] The `index_select` function selects weights from the weight matrix based on their part-of-speech tag indices; W pos Represents the part-of-speech weight matrix; a pos_index This represents the part-of-speech index array corresponding to sentence a; b pos_index W represents the part-of-speech index array corresponding to sentence b. ab This represents the part-of-speech weight of each word in sentence a compared to each word in sentence b; a Indicates the length of sentence a; l b Indicates the length of sentence b; This is the vector representation of sentence a obtained through part-of-speech encoding; This is the vector representation of sentence b obtained from the computation of the previous layer network.
[0067] The two added part-of-speech attention networks directly concatenate the vector representations obtained after sentence encoding to the feature representations generated in their respective network stages, and then input them into the next network stage for further computation. Finally, after applying averaging and maximization operations to the obtained feature vectors, these vectors are concatenated together and then input into a fully connected layer for classification, outputting the final result. The objective function for model training is cross-entropy, and its calculation formula is as follows:
[0068]
[0069] Among them, y i For label values; y′ i is the predicted value, and n is the number of training samples.
[0070] The modified ESIM model was trained using a dataset with added part-of-speech tagging, and the optimal model results were saved.
[0071] 3) Model prediction
[0072] During model prediction, the saved optimal model is loaded first, and then the part-of-speech analysis tool (with a pre-loaded part-of-speech dictionary) is used to obtain the part-of-speech information of the input sentence. Then, the input that meets the requirements of the model is constructed, and finally it is passed into the model to obtain the similarity results of sentence pairs.
[0073] According to the text similarity calculation method proposed in this application, a first text and a second text input by the user are obtained. The user-input text information is then fed into a trained part-of-speech (POS) analysis model to obtain the first POS information of the first text and the second POS information of the second text. This POS information is then fed into a trained similarity prediction model to obtain the similarity result between the first text and the second text. By using the POS analysis model and the similarity prediction model, the semantic focus can be better grasped, improving model performance without significantly increasing model inference time. This solves the problems in related technologies where ambiguity in text-to-text interaction leads to loss of semantic focus, reduced accuracy of text similarity recognition, and poor user experience.
[0074] Next, referring to the accompanying drawings, a text similarity calculation device according to an embodiment of this application is described.
[0075] Figure 4 This is a block diagram of a text similarity calculation device according to an embodiment of this application.
[0076] like Figure 4 As shown, the text similarity calculation device 10 includes: an acquisition module 100, an analysis module 200, and a calculation module 300.
[0077] The system includes an acquisition module 100 for acquiring first and second text input by the user; an analysis module 200 for inputting the first and second text into a trained part-of-speech (POS) analysis model and outputting first POS information of the first text and second POS information of the second text, wherein the POS analysis model is trained based on first training samples carrying POS tags; and a calculation module 300 for inputting the first and second POS information into a trained similarity prediction model and outputting the text similarity result between the first and second texts, wherein the similarity prediction model is trained based on second training samples carrying text similarity tags.
[0078] Optionally, in one embodiment of this application, the analysis module 200 includes an extraction unit and an identification unit.
[0079] The extraction unit is used to extract at least one target keyword from the first text and the second text from the vertical domain; the identification unit is used to identify the actual part of speech of each target keyword and to perform part-of-speech tagging on each target keyword to obtain the first part-of-speech information and the second part-of-speech information.
[0080] Optionally, in one embodiment of this application, the text similarity calculation device 10 further includes a first training module. The first training module is configured to acquire a first training sample carrying part-of-speech tags, extract at least one target keyword from the first training sample in a vertical domain, identify the actual part-of-speech of each target keyword, and perform part-of-speech tagging on each target keyword until the number of tagged keywords meets a preset number, thereby obtaining a part-of-speech analysis model.
[0081] Optionally, in one embodiment of this application, the calculation module 300 includes: a first generation unit, a second generation unit, and a splicing unit.
[0082] The system comprises: a first generation unit, which inputs first part-of-speech information and second part-of-speech information into a sentence encoding network and outputs a first sentence encoding result for the first part-of-speech information and a second sentence encoding result for the second part-of-speech information; a second generation unit, which inputs the first sentence encoding result and the second sentence encoding result into a part-of-speech attention network and outputs a first feature vector for the first sentence encoding result and a second feature vector for the second sentence encoding result; and a concatenation unit, which concatenates the first feature vector and the second feature vector to obtain a concatenation result, inputs the concatenation result into a fully connected layer for classification, and obtains a text similarity result based on the classification result.
[0083] Optionally, in one embodiment of this application, the text similarity calculation device 10 further includes a second training module. The second training module is configured to acquire second training samples carrying text similarity labels, wherein the second training samples include part-of-speech information of a first training text and part-of-speech information of a second training text; input the part-of-speech information of the first and second training texts into a sentence encoding network, outputting a first sentence encoding result of the part-of-speech information of the first and second training texts; input the first and second sentence encoding results into a part-of-speech attention network, outputting a first feature vector of the first sentence encoding result and a second feature vector of the second sentence encoding result; concatenate the first and second feature vectors to obtain a concatenated result, input the concatenated result into a fully connected layer for classification, and match the text similarity result according to the classification result, until the training iteration termination condition is met, thus obtaining a similarity prediction model.
[0084] It should be noted that the foregoing explanation of the text similarity calculation method embodiment also applies to the text similarity calculation device of this embodiment, and will not be repeated here.
[0085] The text similarity calculation device proposed in this application obtains a first text and a second text input by a user. The user-input text information is then fed into a trained part-of-speech (POS) analysis model to obtain the first POS information of the first text and the second POS information of the second text. This POS information is then input into a trained similarity prediction model to obtain the similarity result between the first text and the second text. By using both the POS analysis model and the similarity prediction model, the semantic focus can be better grasped, improving model performance without significantly increasing inference time. This solves the problems in related technologies, such as unclear text-to-text interaction operations leading to loss of semantic focus and poor performance, as well as the slow inference speed of large pre-trained models.
[0086] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device may include:
[0087] The memory 501, the processor 502, and the computer program stored on the memory 501 and capable of running on the processor 502.
[0088] When the processor 502 executes the program, it implements the text similarity calculation method provided in the above embodiments.
[0089] Furthermore, electronic devices also include:
[0090] Communication interface 503 is used for communication between memory 501 and processor 502.
[0091] The memory 501 is used to store computer programs that can run on the processor 502.
[0092] The memory 501 may include high-speed RAM (Random Access Memory) memory, and may also include non-volatile memory, such as at least one disk storage.
[0093] If the memory 501, processor 502, and communication interface 503 are implemented independently, then the communication interface 503, memory 501, and processor 502 can be interconnected via a bus to complete communication between them. The bus can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0094] Optionally, in a specific implementation, if the memory 501, processor 502, and communication interface 503 are integrated on a single chip, then the memory 501, processor 502, and communication interface 503 can communicate with each other through an internal interface.
[0095] Processor 502 may be a CPU (Central Processing Unit), an ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement embodiments of this application.
[0096] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the above-described method for calculating text similarity.
[0097] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0098] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "N" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0099] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more N executable instructions for implementing custom logic functions or processes, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as should be understood by those skilled in the art to which embodiments of this application pertain.
[0100] It should be understood that the various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, the N steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (FPGAs), field-programmable gate arrays (FPGAs), etc.
[0101] Those skilled in the art will understand that all or part of the steps of the methods described in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it includes one or a combination of the steps of the method embodiments.
[0102] Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of this application.
Claims
1. A method for calculating text similarity, characterized in that, Includes the following steps: Get the first and second text input by the user; The first text and the second text are input into the trained part-of-speech analysis model, which outputs the first part-of-speech information of the first text and the second part-of-speech information of the second text. The part-of-speech analysis model is trained based on the first training sample carrying part-of-speech tags. The first part-of-speech information and the second part-of-speech information are input into the trained similarity prediction model, and the text similarity result between the first text and the second text is output. The similarity prediction model is trained based on the second training sample carrying text similarity labels. The step of inputting the first part-of-speech information and the second part-of-speech information into a trained similarity prediction model and outputting the text similarity result between the first text and the second text includes: inputting the first part-of-speech information and the second part-of-speech information into a sentence encoding network, outputting a first sentence encoding result of the first part-of-speech information and a second sentence encoding result of the second part-of-speech information; inputting the first sentence encoding result and the second sentence encoding result into a part-of-speech attention network, outputting a first feature vector of the first sentence encoding result and a second feature vector of the second sentence encoding result; concatenating the first feature vector and the second feature vector to obtain a concatenated result, inputting the concatenated result into a fully connected layer for classification, and matching the text similarity result according to the classification result.
2. The method according to claim 1, characterized in that, The step of inputting the first text and the second text into the trained part-of-speech analysis model and outputting the first part-of-speech information of the first text and the second part-of-speech information of the second text includes: Extract at least one target keyword from the first text and the second text within the vertical domain; Identify the actual part of speech of each target keyword and perform part-of-speech tagging on each target keyword to obtain the first part-of-speech information and the second part-of-speech information.
3. The method according to claim 1 or 2, characterized in that, The part-of-speech analysis model is trained based on a first training sample carrying part-of-speech tags, including: Obtain the first training sample carrying part-of-speech tags; Extract at least one target keyword from the first training sample from the vertical domain; Identify the actual part of speech of each target keyword and perform part-of-speech tagging on each target keyword until the number of tagged keywords meets the preset number, thus obtaining the part-of-speech analysis model.
4. The method according to claim 1, characterized in that, The similarity prediction model is trained based on a second training sample carrying text similarity labels, and includes: Obtain a second training sample carrying text similarity labels, wherein the second training sample includes part-of-speech information of the first training text and part-of-speech information of the second training text; The part-of-speech information of the first training text and the part-of-speech information of the second training text are input into the sentence encoding network, and the first sentence encoding result of the part-of-speech information of the first training text and the second sentence encoding result of the part-of-speech information of the second training text are output. The first sentence encoding result and the second sentence encoding result are input into the part-of-speech attention network, and the first feature vector of the first sentence encoding result and the second feature vector of the second sentence encoding result are output. The first feature vector and the second feature vector are concatenated to obtain a concatenation result. The concatenation result is then input into a fully connected layer for classification. The text similarity result is obtained by matching the classification result until the training iteration termination condition is met, thus obtaining the similarity prediction model.
5. A device for calculating text similarity, characterized in that, include: The acquisition module is used to acquire the first and second text input by the user. The analysis module is used to input the first text and the second text into the trained part-of-speech analysis model, and output the first part-of-speech information of the first text and the second part-of-speech information of the second text, wherein the part-of-speech analysis model is trained based on the first training sample carrying part-of-speech tags; The calculation module is used to input the first part-of-speech information and the second part-of-speech information into the trained similarity prediction model and output the text similarity result between the first text and the second text, wherein the similarity prediction model is trained based on the second training sample carrying text similarity labels; The computation module includes: a first generation unit, used to input the first part-of-speech information and the second part-of-speech information into a sentence encoding network, and output a first sentence encoding result of the first part-of-speech information and a second sentence encoding result of the second part-of-speech information; a second generation unit, used to input the first sentence encoding result and the second sentence encoding result into a part-of-speech attention network, and output a first feature vector of the first sentence encoding result and a second feature vector of the second sentence encoding result; and a concatenation unit, used to concatenate the first feature vector and the second feature vector to obtain a concatenation result, input the concatenation result into a fully connected layer for classification, and obtain the text similarity result based on the classification result.
6. The apparatus according to claim 5, characterized in that, The analysis module includes: An extraction unit is used to extract at least one target keyword from the first text and the second text from a vertical domain; The identification unit is used to identify the actual part of speech of each target keyword and to perform part-of-speech tagging on each target keyword to obtain the first part-of-speech information and the second part-of-speech information.
7. An electronic device, characterized in that, include: A memory, a processor, and a computer program stored in the memory and executable on the processor, the processor executing the program to implement the text similarity calculation method as described in any one of claims 1-4.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, The program is executed by the processor to implement the text similarity calculation method as described in any one of claims 1-4.
Citation Information
Patent Citations
Text semantic similarity prediction method based on Transformer model
CN112949284A
Word meaning relationship extraction device
US20150227505A1