Sentence semantic retrieval method and system based on semantic saliency

By calculating the semantic saliency of each word in a sentence and distilling it into a pre-trained language model, the problem of difficulty in identifying the semantic focus of sentences in the existing technology is solved, and more accurate semantic similarity calculation and sentence understanding are achieved.

CN118069787BActive Publication Date: 2024-10-29BEIJING DEEPLANG AI TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410250262.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-05
Publication Date
2024-10-29
Estimated Expiration
2044-03-05

AI Technical Summary

Technical Problem

The existing technology cannot accurately identify the semantic focus of the sentence, resulting in the semantic similarity calculation granularity being too rough and unable to distinguish the primary and secondary sentences, which affects the value of the retrieval results.

Method used

By encoding the sentences, the semantic saliency of each word is calculated, and the contrastive learning method is used to distill the semantic saliency knowledge into the pre-trained language model to improve the semantic information encoding ability and calculate the semantic similarity between sentences.

Benefits of technology

Effectively identify the semantic focus of sentences, improve the accuracy and fine-grainedness of semantic similarity calculation, and enhance the relevance of sentence understanding and retrieval results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118069787B_ABST
    Figure CN118069787B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses a sentence semantic retrieval method and system based on semantic saliency, which encodes sentences to obtain the overall vector corresponding to the sentences and the contextualized code corresponding to each word in the sentences; wherein the sentences include a first sentence and a second sentence; based on the semantic relationship between each word in the sentences and the sentences, the semantic saliency of each word is calculated to obtain semantic saliency knowledge; based on the contextualized code and semantic saliency corresponding to each word in the first sentence and the second sentence, the semantic similarity between the first sentence and the second sentence is calculated to obtain semantic similarity information; the semantic similarity information is learned by a contrastive learning method, and the semantic saliency knowledge is distilled into a pre-trained language model, so that the pre-trained language model learns good semantic information encoding capabilities. The sentence semantic retrieval method based on semantic saliency solves the problem in the prior art that the semantic focus of sentences cannot be accurately identified.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a sentence semantic retrieval method, system, electronic device and storage medium based on semantic significance. Background Art

[0002] Sentence semantic retrieval is to retrieve sentences with similar meanings to the query text from the sentence library. It has a wide range of applications, including sentence material recommendation, synonym retrieval and deduplication, similar text recommendation, question-answering system, etc. Currently, pre-trained language models are widely used in natural language processing tasks and perform best in sentence semantic retrieval tasks. When performing a search, the model calculates the semantic similarity between the query sentence and all sentences in the sentence library, and sorts them from high to low by similarity to obtain the recommended results. Therefore, the core technology of the semantic retrieval task is the calculation of semantic similarity.

[0003] However, current semantic similarity calculation methods have a poor understanding of the core semantics of sentences. For example, the core of the sentence "The most beautiful music of the soul is kindness" should be "kindness" rather than "music". Grasping the core semantics of a sentence plays a very important role in retrieving sentences with matching semantics, which directly determines whether the search results are valuable to the current query.

[0004] The current sentence understanding model encodes sentences into a single fixed-length vector through a pre-trained model, and obtains the semantic similarity between sentences by calculating the similarity between vectors. However, the granularity of this method is too coarse, and the sentences are compressed into an overall vector. The semantics of the important parts of the sentence are diluted by other unimportant parts, resulting in the problem that the sentences cannot be distinguished from the main ones. Although there are also fine-grained solutions that consider the encoding of each word, the existing solutions still consider all words equally, without considering the importance of each word, making the current sentence encoding model unable to identify the semantic focus.

[0005] Therefore, there is an urgent need for a sentence semantic retrieval method that can identify semantic focus. Summary of the invention

[0006] The purpose of the embodiments of the present invention is to provide a sentence semantic retrieval method, system, electronic device and storage medium based on semantic significance, so as to solve the problem in the prior art that the semantic focus of a sentence cannot be accurately identified.

[0007] To achieve the above object, an embodiment of the present invention provides a sentence semantic retrieval method based on semantic significance, and the method specifically includes:

[0008] Encode the sentence to obtain an overall vector corresponding to the sentence and a contextualized code corresponding to each word in the sentence; wherein the sentence includes a first sentence and a second sentence;

[0009] Based on the semantic relationship between each word in the sentence, the semantic significance of each word is calculated to obtain semantic significance knowledge;

[0010] Calculating the semantic similarity between the first sentence and the second sentence based on the contextualized code and semantic significance corresponding to each word in the first sentence and the second sentence to obtain semantic similarity information;

[0011] The semantic similarity information is learned by using a contrastive learning method, and the semantic saliency knowledge is distilled into a pre-trained language model, so that the pre-trained language model learns good semantic information encoding capabilities.

[0012] On the basis of the above technical solution, the present invention can also be improved as follows:

[0013] Furthermore, encoding the sentence to obtain an overall vector corresponding to the sentence and a contextualized code corresponding to each word in the sentence includes:

[0014] Inserting a special word before the first sentence and the second sentence respectively;

[0015] After concatenating the special word with the sentence, each word in the sentence is encoded into a vector containing sentence information through the pre-trained language model.

[0016] Furthermore, the encoding of the sentence to obtain the overall vector corresponding to the sentence and the contextualized code corresponding to each word in the sentence also includes

[0017] At the output end of the pre-trained language model, the special word is embedded as the sentence as a whole, and the vectors of the other words at their respective positions are taken as the contextualized encoding of the corresponding words.

[0018] Furthermore, the method of calculating the semantic significance of each word based on the semantic relationship between each word in the sentence and the sentence to obtain semantic significance knowledge includes:

[0019] The original semantic significance of the i-th word is calculated by formula 1;

[0020]

[0021] In the formula, is the original semantic significance of the i-th word, S is the sentence, Contextualized encoding for special words, is the contextualized encoding of the i-th word in the sentence.

[0022] Furthermore, the method of calculating the semantic significance of each word based on the semantic relationship between each word in the sentence and the sentence to obtain semantic significance knowledge also includes:

[0023] Center the original semantic significance of each word in the sentence by subtracting the overall mean from the original semantic significance of each word in the sentence;

[0024] The negative part is clipped by the ReLU function to obtain the semantic significance of each word.

[0025] Furthermore, the calculating the semantic similarity between the first sentence and the second sentence based on the contextualized coding and semantic significance corresponding to each word in the first sentence and the second sentence to obtain the semantic similarity information includes:

[0026] The semantic similarity between the first sentence and the second sentence is calculated by formula 2;

[0027]

[0028] In the formula, f bi (s1, s2) is the semantic similarity between the first sentence and the second sentence, f uni (s1, s2) is the one-way semantic similarity from the first sentence to the second sentence, f uni (s2, s1) is the one-way semantic similarity from the second sentence to the first sentence.

[0029] Furthermore, the method of learning the semantic similarity information by contrastive learning and distilling the semantic saliency knowledge into a pre-trained language model so that the pre-trained language model learns good semantic information encoding capability includes:

[0030] The loss function of the pre-trained language model training is calculated by formula 3:

[0031]

[0032] Where τ is an adjustable temperature hyperparameter, f bi is a symmetric semantic similarity calculation function, s i is the original sentence, s i + is a positive sentence, is a negative sentence.

[0033] A sentence semantic retrieval system based on semantic saliency, comprising:

[0034] Constructing a pre-trained language model, wherein the pre-trained language model includes a sentence encoding module, a semantic significance calculation module, a similarity calculation module and a contrastive learning training module;

[0035] A sentence encoding module, used to encode the sentence to obtain an overall vector corresponding to the sentence and a contextualized code corresponding to each word in the sentence; wherein the sentence includes a first sentence and a second sentence;

[0036] A semantic saliency calculation module, used to calculate the semantic saliency of each word in a sentence based on the semantic relationship between each word and the sentence;

[0037] A similarity calculation module, used to calculate the semantic similarity of the first sentence and the second sentence based on the contextualized coding and semantic significance corresponding to each word in the first sentence and the second sentence, so as to obtain semantic similarity information;

[0038] The contrastive learning training module is used to learn the semantic similarity information between the first sentence and the second sentence by using the contrastive learning method, and to distill the semantic saliency knowledge into the pre-trained language model so that the pre-trained language model can learn good semantic information encoding ability.

[0039] An electronic device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the steps of the method are implemented when the processor executes the computer program.

[0040] A non-transitory computer-readable storage medium stores a computer program, which implements the steps of the method when executed by a processor.

[0041] The embodiments of the present invention have the following advantages:

[0042] The sentence semantic retrieval method based on semantic significance in the present invention encodes the sentence to obtain the overall vector corresponding to the sentence and the contextualized code corresponding to each word in the sentence; wherein the sentence includes a first sentence and a second sentence; based on the semantic relationship between each word in the sentence and the sentence, the semantic significance of each word is calculated to obtain semantic significance knowledge; based on the contextualized code and semantic significance corresponding to each word in the first sentence and the second sentence, the semantic similarity between the first sentence and the second sentence is calculated to obtain semantic similarity information; the semantic similarity information is learned by a contrastive learning method, and the semantic significance knowledge is distilled into a pre-trained language model, so that the pre-trained language model learns good semantic information encoding capabilities, thereby solving the problem that the semantic focus of a sentence cannot be accurately identified in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the implementation methods of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for the implementation methods or the description of the prior art. Obviously, the drawings in the following description are only exemplary, and for ordinary technicians in this field, other implementation drawings can be derived from the provided drawings without creative work.

[0044] The structures, proportions, sizes, etc. illustrated in this specification are only used to match the contents disclosed in the specification so as to facilitate understanding and reading by persons familiar with the technology. They are not used to limit the conditions under which the present invention can be implemented, and therefore have no substantial technical significance. Any structural modification, change in proportion or adjustment of size shall still fall within the scope of the technical contents disclosed in the present invention without affecting the effects and purposes that can be achieved by the present invention.

[0045] Figure 1 It is a flowchart of the sentence semantic retrieval method based on semantic significance of the present invention;

[0046] Figure 2 It is an architecture diagram of the sentence semantic retrieval system based on semantic significance of the present invention;

[0047] Figure 3 This is a schematic diagram of the physical structure of the electronic device provided by the present invention.

[0048] The accompanying drawings are denoted as follows:

[0049] Pre-trained language model 10, sentence encoding module 20, semantic significance calculation module 30, similarity calculation module 40, comparative learning training module 50, electronic device 60, processor 601, memory 602, bus 603. DETAILED DESCRIPTION

[0050] The following is a description of the implementation of the present invention by specific embodiments. People familiar with the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0051] Example

[0052] Figure 1 FIG. 1 is a flow chart of an embodiment of a sentence semantic retrieval method based on semantic significance of the present invention. Figure 1 As shown, a sentence semantic retrieval method based on semantic significance provided by an embodiment of the present invention comprises the following steps:

[0053] S101, encoding the sentence to obtain an overall vector corresponding to the sentence and a contextualized code corresponding to each word in the sentence; wherein the sentence includes a first sentence and a second sentence;

[0054] Specifically, the sentence encoding module 20 encodes the entire sentence to obtain a vector representation of the overall semantics of the sentence, and simultaneously obtains the encoding of each word in the sentence to represent the contextual encoding represented by the word in the sentence.

[0055] Inserting a special word before the first sentence and the second sentence respectively;

[0056] After the special word [CLS] is concatenated with the sentence, each word in the sentence is encoded into a vector containing sentence information through the pre-trained language model 10, and each word is converted into a word embedding and encoded into a fixed-length vector containing sentence information through the Transformer layer.

[0057] At the output end of the pre-trained language model 10, the special word [CLS] is embedded as the sentence as a whole, and the vectors of the other words at their respective positions are taken as the contextualized encoding of the corresponding words.

[0058] The output vector corresponding to the special word [CLS] is used as the semantic representation of the entire text for text classification.

[0059] S102, based on the semantic relationship between each word in the sentence and the sentence, the semantic significance of each word is calculated to obtain semantic significance knowledge;

[0060] Specifically, we first need to obtain the original semantic significance value of each word. The original semantic significance value can reflect the contribution of each word to the overall semantics of the sentence, so that the semantic understanding can be focused and the key semantics can be grasped. Based on the training based on semantic similarity, the similarity of vectors can reflect the similarity of semantics. Therefore, the similarity between contextualized word encoding and sentence encoding can be used to reflect the semantic similarity between words and sentences, which can be calculated using cosine similarity. The more similar the semantics of the contextualized word is to the semantics of the sentence, the more common semantics they have, that is, the greater the semantic contribution of the word to the sentence.

[0061] The original semantic significance of the i-th word is calculated by formula 1;

[0062]

[0063] In the formula, is the original semantic significance of the i-th word, S is the sentence, Contextualized encoding for special words, is the contextualized encoding of the i-th word in the sentence.

[0064] If the original semantic significance value is directly used for similarity calculation, significance collapse will occur, that is, the significance of each word obtained by the pre-trained language model 10 after training will tend to be the same, and it will not be able to distinguish the key points. The reason is that if no pruning is performed, the pre-trained language model 10 cannot ignore those unimportant words. In order to eliminate the influence, the pre-trained language model 10 has to let the unimportant words share more semantics during the contextualization process. Finally, the pre-trained language model 10 loses the ability to distinguish the semantics between each word and distinguish the key points.

[0065] Therefore, the original saliency needs to be trimmed. First, the saliency of all words is centered, that is, the saliency of each word is subtracted from the overall mean, and then the negative value part is trimmed using the ReLU function. After processing, the semantic saliency of the i-th word is:

[0066]

[0067] The overall significance is then normalized with a norm of 1, and the final semantic significance can be understood as a weight, that is, the proportion of the overall semantics of the sentence that this contextualized word bears.

[0068] S103, calculating the semantic similarity between the first sentence and the second sentence based on the contextualized code and semantic significance corresponding to each word in the first sentence and the second sentence to obtain semantic similarity information;

[0069] Specifically, this module can calculate the semantic similarity between the first sentence and the second sentence, with the input being the contextualized encoding of each word in the first sentence and the second sentence, and the final semantic significance of each word. For each word in the first sentence, the word with the most similar semantics is found in the second sentence as the semantic similarity between the word and the second sentence. Then, the semantic significance of each word in the first sentence is used as the weight, and the similarity of each word in the first sentence is weighted and summed to calculate the one-way semantic similarity from the first sentence to the second sentence.

[0070] The similarity calculation function of this part can be expressed as:

[0071]

[0072] Taking into account the symmetry, we can calculate the average of two sets of one-way semantic similarities as the similarity calculation function in symmetric form, that is:

[0073] The semantic similarity between the first sentence and the second sentence is calculated by formula 2;

[0074]

[0075] In the formula, f bi (s1, s2) is the semantic similarity between the first sentence and the second sentence, f uni (s1, s2) is the one-way semantic similarity from the first sentence to the second sentence, f uni (s2, s1) is the one-way semantic similarity from the second sentence to the first sentence.

[0076] The similarity calculation function has good interpretability. You can intuitively see which word the semantic focus of the sentence is on and how much impact it has on the semantic similarity calculation of the summary.

[0077] S104, using contrastive learning method to learn semantic similarity information, and distilling semantic saliency knowledge into the pre-trained language model, so that the pre-trained language model can learn good semantic information encoding ability.

[0078] Specifically, a contrastive learning framework is used to perform end-to-end training on the entire pre-trained language model 10. The training data is the natural language inference dataset NLI. NLI (Natural Language Inference) is as its name suggests, natural language inference. It is mainly used to judge the semantic relationship between two sentences, which can generally be divided into: Entailment, Contradiction, and Neutral. Among them, sentence pairs with semantic inclusion relationships are used as positive examples, and sentences with contradictory relationships are used as difficult negative examples. At the same time, an in-batch negative sample training data scheme is adopted, and other irrelevant sentences in a batch of data are used as negative examples. The training goal is to make the positive examples have a greater semantic similarity value than the negative examples.

[0079] The loss function of the pre-trained language model 10 training is calculated by formula 3:

[0080]

[0081] Where τ is an adjustable temperature hyperparameter, f bi is a symmetric semantic similarity calculation function, s i is the original sentence, s i + is a positive sentence, is a negative sentence. The training method of the pre-trained language model 10 is to use synonymous sentences to train the data, using the synonymous sentences as positive sentences for comparative learning and the random sentences as negative sentences for comparative learning, so that the pre-trained language model 10 learns that the synonymous sentences are more semantically similar than other random sentences. This is sentence-level supervision data. After using the similarity calculation method that considers word significance, the semantic significance knowledge at the word level can be distilled from the semantic similarity information at the sentence level.

[0082] The present invention proposes a sentence semantic retrieval method based on semantic significance. Through four submodules, namely, a sentence encoding module 20, a semantic significance calculation module 30, a similarity calculation module 40 and a comparative learning training module 50, the semantic key information of the sentence can be effectively learned, and similarity modeling is performed interpretably, which is conducive to better sentence understanding and semantically similar sentence search, and further a more accurate sentence semantic retrieval system can be constructed, which has good practicality.

[0083] The sentence semantic retrieval method based on semantic saliency encodes the sentence to obtain the overall vector corresponding to the sentence and the contextualized code corresponding to each word in the sentence; wherein the sentence includes the first sentence and the second sentence; based on the semantic relationship between each word in the sentence and the sentence, the semantic saliency of each word is calculated to obtain semantic saliency knowledge; based on the contextualized code and semantic saliency corresponding to each word in the first sentence and the second sentence, the semantic similarity between the first sentence and the second sentence is calculated to obtain semantic similarity information; the semantic similarity information is learned by a contrastive learning method, and the semantic saliency knowledge is distilled into the pre-trained language model 10, so that the pre-trained language model 10 learns good semantic information encoding capabilities. The problem that the semantic focus of a sentence cannot be accurately identified in the prior art is solved.

[0084] Figure 2 FIG. 4 is a diagram showing an embodiment of a sentence semantic retrieval system based on semantic significance of the present invention; Figure 2 As shown, a sentence semantic retrieval system based on semantic significance provided by an embodiment of the present invention includes the following steps:

[0085] Constructing a pre-trained language model 10, wherein the pre-trained language model 10 includes a sentence encoding module 20, a semantic significance calculation module 30, a similarity calculation module 40 and a contrastive learning training module 50;

[0086] A sentence encoding module 20 is used to encode the sentence to obtain an overall vector corresponding to the sentence and a contextualized code corresponding to each word in the sentence; wherein the sentence includes a first sentence and a second sentence;

[0087] The sentence encoding module 20 is also used for:

[0088] Inserting a special word before the first sentence and the second sentence respectively;

[0089] After the special word is concatenated with the sentence, each word in the sentence is encoded into a vector containing sentence information through the pre-trained language model 10.

[0090] At the output end of the pre-trained language model 10, the special word is embedded as the sentence as a whole, and the vectors of the other words at their respective positions are taken as the contextualized encoding of the corresponding words.

[0091] A semantic significance calculation module 30, used to calculate the semantic significance of each word in the sentence based on the semantic relationship between each word and the sentence;

[0092] The semantic significance calculation module 30 is also used for:

[0093] The original semantic significance of the i-th word is calculated by formula 1;

[0094]

[0095] In the formula, is the original semantic significance of the i-th word, S is the sentence, Contextualized encoding for special words, is the contextualized encoding of the i-th word in the sentence.

[0096] Center the original semantic significance of each word in the sentence by subtracting the overall mean from the original semantic significance of each word in the sentence;

[0097] The negative part is clipped by the ReLU function to obtain the semantic significance of each word.

[0098] A similarity calculation module 40, configured to calculate the semantic similarity between the first sentence and the second sentence based on the contextualized code and semantic significance corresponding to each word in the first sentence and the second sentence, and obtain semantic similarity information;

[0099] The similarity calculation module 40 is also used for:

[0100] The semantic similarity between the first sentence and the second sentence is calculated by formula 2;

[0101]

[0102] In the formula, f bi (s1, s2) is the semantic similarity between the first sentence and the second sentence, f uni (s1, s2) is the one-way semantic similarity from the first sentence to the second sentence, f uni (s2, s1) is the one-way semantic similarity from the second sentence to the first sentence.

[0103] The contrastive learning training module 50 is used to learn the semantic similarity information between the first sentence and the second sentence using a contrastive learning method, and to distill the semantic saliency knowledge into the pre-trained language model 10, so that the pre-trained language model 10 can learn good semantic information encoding capabilities.

[0104] The contrastive learning training module 50 is also used for:

[0105] The loss function of the pre-trained language model 10 training is calculated by formula 3:

[0106]

[0107] Where τ is an adjustable temperature hyperparameter, f bi is a symmetric semantic similarity calculation function, s i is the original sentence, s i + is a positive sentence, is a negative sentence.

[0108] The present invention discloses a sentence semantic retrieval system based on semantic saliency, which constructs a pre-trained language model 10, wherein the pre-trained language model 10 includes a sentence encoding module 20, a semantic saliency calculation module 30, a similarity calculation module 40 and a contrastive learning training module 50; the sentence is encoded by the sentence encoding module 20 to obtain the overall vector corresponding to the sentence and the contextualized code corresponding to each word in the sentence; wherein the sentence includes a first sentence and a second sentence; the semantic saliency calculation module 30 calculates the semantic saliency of each word based on the semantic relationship between each word and the sentence; the similarity calculation module 40 calculates the semantic similarity between the first sentence and the second sentence based on the contextualized code and semantic saliency corresponding to each word in the first sentence and the second sentence to obtain semantic similarity information; the contrastive learning training module 50 adopts a contrastive learning method to learn the semantic similarity information between the first sentence and the second sentence, and distills the semantic saliency knowledge into the pre-trained language model 10, so that the pre-trained language model 10 learns good semantic information encoding ability. The sentence semantic retrieval method based on semantic saliency solves the problem that the semantic focus of a sentence cannot be accurately identified in the prior art.

[0109] Figure 3 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present invention, such as Figure 3 As shown, the electronic device 60 includes: a processor 601 (processor), a memory 602 (memory) and a bus 603;

[0110] The processor 601 and the memory 602 communicate with each other via the bus 603;

[0111] The processor 601 is used to call the program instructions in the memory 602 to execute the methods provided by the above-mentioned method embodiments, for example, including: encoding the sentence to obtain the overall vector corresponding to the sentence and the contextualized code corresponding to each word in the sentence; wherein the sentence includes a first sentence and a second sentence; based on the semantic relationship between each word in the sentence and the sentence, the semantic significance of each word is calculated to obtain semantic significance knowledge; based on the contextualized code and semantic significance corresponding to each word in the first sentence and the second sentence, the semantic similarity between the first sentence and the second sentence is calculated to obtain semantic similarity information; using a contrastive learning method to learn the semantic similarity information, and distilling the semantic significance knowledge into the pre-trained language model 10, so that the pre-trained language model 10 learns good semantic information encoding capabilities.

[0112] The present embodiment provides a non-transitory computer-readable storage medium, which stores computer instructions. The computer instructions enable a computer to execute the methods provided by the above-mentioned method embodiments, for example, including: encoding a sentence to obtain an overall vector corresponding to the sentence and a contextualized code corresponding to each word in the sentence; wherein the sentence includes a first sentence and a second sentence; based on the semantic relationship between each word in the sentence and the sentence, calculating the semantic significance of each word to obtain semantic significance knowledge; based on the contextualized code and semantic significance corresponding to each word in the first sentence and the second sentence, calculating the semantic similarity between the first sentence and the second sentence to obtain semantic similarity information; using a contrastive learning method to learn the semantic similarity information, and distilling the semantic significance knowledge into a pre-trained language model 10, so that the pre-trained language model 10 learns good semantic information encoding capabilities.

[0113] A person skilled in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk, etc., various storage media that can store program codes.

[0114] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, i.e., they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.

[0115] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiment.

[0116] Although the present invention has been described in detail above by general description and specific embodiments, it is obvious to those skilled in the art that some modifications or improvements can be made to the present invention. Therefore, these modifications or improvements made without departing from the spirit of the present invention all belong to the scope of protection claimed by the present invention.

Claims

1. A sentence semantic retrieval method based on semantic saliency, characterized in that: The method specifically comprises: Encode the sentence to obtain an overall vector corresponding to the sentence and a contextualized code corresponding to each word in the sentence; wherein the sentence includes a first sentence and a second sentence; Based on the semantic relationship between each word in the sentence, the semantic significance of each word is calculated to obtain semantic significance knowledge, including: The original semantic significance of the i-th word is calculated by formula 1; In the formula, is the original semantic significance of the i-th word, S is the sentence, Contextualized encoding for special words, Contextualized code for the i-th word in the sentence; Center the original semantic significance of each word in the sentence by subtracting the overall mean from the original semantic significance of each word in the sentence; The negative value part is clipped by the ReLU function to obtain the semantic significance of each word; Calculating the semantic similarity between the first sentence and the second sentence based on the contextualized code and semantic significance corresponding to each word in the first sentence and the second sentence to obtain semantic similarity information includes: The semantic similarity between the first sentence and the second sentence is calculated by formula 2; In the formula, f bi (s1, s2) is the semantic similarity between the first sentence and the second sentence, f uni (s1, s2) is the one-way semantic similarity from the first sentence to the second sentence, f uni (s2, s1) is the one-way semantic similarity from the second sentence to the first sentence; The semantic similarity information is learned by using a contrastive learning method, and the semantic saliency knowledge is distilled into a pre-trained language model, so that the pre-trained language model learns good semantic information encoding capabilities, including: The loss function of the pre-trained language model training is calculated by formula 3: Where τ is an adjustable temperature hyperparameter, f bi is a symmetric semantic similarity calculation function, s i For the original sentence, is a positive example sentence.

2. The sentence semantic retrieval method based on semantic significance according to claim 1, characterized in that: The encoding of the sentence to obtain the overall vector corresponding to the sentence and the contextualized encoding corresponding to each word in the sentence includes: Inserting a special word before the first sentence and the second sentence respectively; After concatenating the special word with the sentence, each word in the sentence is encoded into a vector containing sentence information through the pre-trained language model.

3. The sentence semantic retrieval method based on semantic significance according to claim 2, characterized in that: The encoding of the sentence to obtain the overall vector corresponding to the sentence and the contextualized encoding corresponding to each word in the sentence also includes At the output end of the pre-trained language model, the special word is embedded as the sentence as a whole, and the vectors of the other words at their respective positions are taken as the contextualized encoding of the corresponding words.

4. A sentence semantic retrieval system based on semantic saliency, characterized in that: include: Constructing a pre-trained language model, wherein the pre-trained language model includes a sentence encoding module, a semantic significance calculation module, a similarity calculation module and a contrastive learning training module; A sentence encoding module, used to encode the sentence to obtain an overall vector corresponding to the sentence and a contextualized code corresponding to each word in the sentence; wherein the sentence includes a first sentence and a second sentence; A semantic saliency calculation module, used to calculate the semantic saliency of each word in a sentence based on the semantic relationship between each word and the sentence; The original semantic significance of the i-th word is calculated by formula 1; In the formula, is the original semantic significance of the i-th word, S is the sentence, Contextualized encoding for special words, Contextualized code for the i-th word in the sentence; Center the original semantic significance of each word in the sentence by subtracting the overall mean from the original semantic significance of each word in the sentence; The negative value part is clipped by the ReLU function to obtain the semantic significance of each word; A similarity calculation module, used to calculate the semantic similarity of the first sentence and the second sentence based on the contextualized coding and semantic significance corresponding to each word in the first sentence and the second sentence, so as to obtain semantic similarity information; The semantic similarity between the first sentence and the second sentence is calculated by formula 2; In the formula, f bi (s1, s2) is the semantic similarity between the first sentence and the second sentence, f uni (s1, s2) is the one-way semantic similarity from the first sentence to the second sentence, f uni (s2, s1) is the one-way semantic similarity from the second sentence to the first sentence; A contrastive learning training module, used for learning semantic similarity information between a first sentence and a second sentence by using a contrastive learning method, and distilling semantic saliency knowledge into a pre-trained language model, so that the pre-trained language model learns good semantic information encoding capability; The loss function of the pre-trained language model training is calculated by formula 3: Where τ is an adjustable temperature hyperparameter, f bi is a symmetric semantic similarity calculation function, s i For the original sentence, is a positive example sentence.

5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 3 are implemented.

6. A non-transitory 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 3 are implemented.

Citation Information

Patent Citations

  • Semantic retrieval method and system based on pre-training model

    CN110309267A

  • Neural network training method, semantic similarity calculation method and semantic retrieval system

    CN114662668A