CN-116266268-B - Semantic analysis method and device based on contrast learning and semantic perception
Abstract
The invention discloses a semantic analysis method and device based on contrast learning and semantic perception, comprising the steps of collecting various positive and negative examples for each pair of sentences and semantic representation in a training set, inputting a semantic analysis model after multi-level label representation is carried out on the pairs of sentences and semantic representation and the positive and negative examples, updating model parameters through the overall similarity of the sentences and the semantic representation and the labels by the semantic analysis model, and inputting sentences to be analyzed into the trained semantic analysis model to obtain the semantic representation of the sentences to be analyzed. The invention enables the model to pay attention to the whole semantics of the semantic representation, improves the discrimination capability of the model to fine granularity, and can compare and learn more detailed and more accurate dividing samples, thereby reducing noise brought by fuzzy samples to model modeling.
Inventors
- WU SHAN
- XIN CHUNLEI
- CHEN BO
- HAN XIANPEI
- SUN LE
Assignees
- 中国科学院软件研究所
Dates
- Publication Date
- 20260508
- Application Date
- 20211214
Claims (9)
- 1. A semantic analysis method based on contrast learning and semantic perception comprises the following steps: For each < sentence in the training set Semantic representation Pair, generate sentence A kind of electronic device Each positive example sentence Acquiring sentences A kind of electronic device Personal semantic representation And will < sentence Semantic representation Pair, < sentence Semantic representation Pair and < sentence Semantic representation Respectively expressed as < sentence pair Semantic representation A pair; For each < sentence Semantic representation After labeling, inputting a semantic analysis model To make the semantic analysis model By sentence With semantic representation And updating model parameters with the label to obtain a semantic analysis model Wherein Training rounds; when semantic parsing model When the set condition is reached, the semantic analysis model is adopted As a trained semantic parsing model ; Inputting sentences to be parsed into a semantic parsing model Obtaining semantic representation of sentences to be analyzed; wherein the labels include positive, fuzzy, or negative sample labels, wherein the correct semantic representation of the < sentence Semantic representation Pairs are marked as positive examples, < sentences Semantic representation For the same < sentence as the execution result ] Semantic representation For < sentences with different execution results, marked as fuzzy sample labels Semantic representation Pairs are labeled negative sample labels.
- 2. The method of claim 1, wherein sentences are generated The method of (1) includes sentence alignment Performing a rendition, obtaining a semantic representation The method of (1) includes the steps of Input semantic parsing model 。
- 3. The method of claim 1, wherein the overall similarity comprises at least one of an average sequence representation similarity, an attention sequence similarity, and a conditional sequence similarity.
- 4. A method according to claim 3, wherein the average sequence representation similarity is calculated by: 1) Calculating sentences Vector representation of (a) ; 2) Computing semantic representations Vector representation of (a) ; 3) Representing vectors And vector representation And after the conversion to the same space, similarity calculation is carried out to obtain the average sequence representation similarity.
- 5. A method according to claim 3, wherein the attention sequence similarity is calculated by: 1) Computing semantic representations Middle (f) Personal word Corresponding representation ; 2) Calculate word Representation weighted at sentence end attention ; 3) Each representation is represented And each representation And after the conversion to the same space, similarity calculation is carried out to obtain the attention sequence similarity.
- 6. A method according to claim 3, wherein the conditional sequence similarity is calculated by: 1) Calculating sentences Vector representation of (a) ; 2) Acquiring decoded semantic representations Middle (f) Personal word When the vector represents Is a weighted representation of (2) ; 3) Computing semantic representations Middle (f) Personal word Corresponding representation ; 4) Representing each weighted representation And representation And after the conversion to the same space, similarity calculation is carried out to obtain the similarity of the conditional sequence.
- 7. The method of claim 1, wherein the semantic parsing model is obtained by : 1) Based on < sentence Semantic representation Overall similarity of > pairs, each < sentence Semantic representation Overall similarity of pairs and corresponding labels, and performing sentence end comparison learning to obtain sentence end comparison loss ; 2) Based on < sentence Semantic representation Overall similarity of > pairs, each < sentence Semantic representation Overall similarity of pairs and corresponding labels, and performing contrast learning of semantic representation ends to obtain contrast loss of the semantic representation ends ; 3) Calculating end-to-end decoding loss ; 4) According to sentence end contrast loss Semantic representation end contrast loss Loss with end-to-end decoding Obtaining the integral loss of the model ; 5) Integral loss using model With the tag, for < sentence Semantic representation Training to obtain semantic analysis model 。
- 8. A storage medium having a computer program stored therein, wherein the computer program is arranged to perform the method of any of claims 1-7 when run.
- 9. An electronic device comprising a memory, in which a computer program is stored, and a processor arranged to run the computer program to perform the method of any of claims 1-7.
Description
Semantic analysis method and device based on contrast learning and semantic perception Technical Field The invention belongs to the technical field of natural language processing, and particularly relates to a semantic analysis method and device based on contrast learning and semantic perception. Background Semantic parsing is a core task in natural language processing and is also a key to achieving natural language understanding. In recent years, attention has been paid to a large number of researchers. For semantic parsing, each training instance is a < sentence, semantic representation > pair, and a test phase gives a sentence requiring the output of a corresponding semantic representation. A key challenge in building a neuro-semantic parsing model is the nature of the integrity and fine granularity of the semantic representation. For the semantic parsing task, the semantic representation of the output should be word-invariant. Once a word is changed or missing, the semantics of the whole semantic representation change greatly, for example, from Property (λs (snum turnovers. Gtoreq.3)) level to Property (λs (snum turnovers < 3)) level, changing by only one symbol but the whole semantics are completely opposite (meaning of semantic representation is respectively a player with a miss of 3 or more and a player with a miss of 3). Such fine-grained differentiation is common, and a common semantic parsing method is to optimize word-by-word, thus lacking modeling of semantic representation integrity and fine-grained characteristics, such as one of the semantic parsing methods and apparatus disclosed in chinese patent application CN105095186 a. Disclosure of Invention In order to solve the problems, the invention provides a semantic analysis method and a semantic analysis device based on contrast learning and semantic perception. The method of the invention separates the < sentences, semantic representation > with different semanteme on the vector representation space, and pulls the < sentences, semantic representation > pairs with the same semanteme. The invention uses a multi-level division mode to divide the collected samples. In the process of optimizing the model, firstly, in order to improve the overall sensitivity, the invention designs an overall perception similarity function, semantic representation can be used as an overall to be compared so as to accurately evaluate the similarity between sentences and semantic representation, meanwhile, in cooperation with multi-level samples, the invention provides a multi-level contrast loss function, the samples with the same semantics are pulled together on the representation layer, and negative examples are pushed away, so that the problem that the existing semantic analysis model is insensitive to the granularity and the integrity is solved. The technical scheme of the invention comprises the following steps: a semantic analysis method based on contrast learning and semantic perception comprises the following steps: For each < sentence x, semantic representation y > pair in the training set, generating M positive sample sentences x ' m of the sentence x, obtaining N semantic representations y ' n of the sentence x, and representing the < sentence x, semantic representation y > pair, < sentence x ' m, semantic representation y > pair and < sentence x, semantic representation y ' n > pair as < sentence x ' i, semantic representation y″ i > pair respectively; after labeling each < sentence x 'i and semantic representation y' i > pair, inputting a semantic analysis model F j-1 to enable the semantic analysis model F j-1 to update model parameters through the overall similarity of the sentence x 'i and the semantic representation y' i and the label to obtain a semantic analysis model F j, wherein j is a training round; When the semantic analysis model F j reaches a set condition, the semantic analysis model F j is used as a trained semantic analysis model F; And inputting the sentence to be analyzed into a semantic analysis model F to obtain the semantic representation of the sentence to be analyzed. Further, the method of generating sentence x' m includes repeating sentence x. Further, the method of obtaining the semantic representation y' n includes inputting the sentence x into the semantic parsing model F j-1. Further, the labels comprise a positive sample label, a fuzzy sample label or a negative sample label, wherein the < sentence x ' ' i, the semantic representation y ' ' i > pair of the correct semantic representation is marked as a positive sample, the < sentence x ' m, the semantic representation y > pair of the correct semantic representation is marked as a fuzzy sample label, the < sentence x, the semantic representation y ' n > pair of the same execution result is marked as a fuzzy sample label, and the < sentence x, the semantic representation y ' n > pair of the execution result is marked as a negative sample label. Further, the overall similarity i