A vectorized semantic representation method and system for multiple conditional statements
By introducing conditional correlation routers and dynamic attention mechanisms into the Transformer encoder, the problems of low computational efficiency and model complexity in the C-STS task are solved, and efficient and accurate sentence semantic representation is achieved.
Patent Information
- Application Number
- CN202411497587.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-24
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2044-10-24
AI Technical Summary
The prior art has low computational efficiency in conditional text similarity matching (C-STS) tasks, and the performance differences between dual encoder and triencoder architectures are large, and the use of hypernetworks leads to excessively large models.
A Transformer-based sentence encoder is used as the backbone of the framework to obtain the embedding of the set conditions, and the query vector of the common language specification word token is extracted at the last layer of the sentence encoder. Select a specific layer to build a conditional correlation router, and generate a vectorized representation of multi-condition specific sentences by dynamically adjusting the attention mechanism of words.
It improves the computational efficiency of the C-STS task, reduces performance degradation, integrates the advantages of dual-encoder and three-encoder architectures, reduces model complexity, and significantly improves the accuracy of sentence semantic representation recognition.
Smart Images

Figure CN119005207B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of information analysis semantic recognition intelligent evaluation, and more specifically, to a method and system for vectorized semantic representation of multi-conditional statements. Background Art
[0002] Sentence Text Similarity (STS) matching, i.e. predicting the semantic similarity between two sentences, has long been an important task for evaluating the quality of sentence representation and the semantic understanding ability of Natural Language Processing (NLP) models; however, traditional STS evaluation methods focus on the overall meaning of the entire sentence, thereby ignoring the fine-grained semantics associated with different aspects; to address this limitation, Conditional Text Similarity Matching (C-STS) aims to measure the similarity between two sentences in the context of a set condition C sentence; for example, sentence one: a hotel room decorated in silver and white with a large mirror above the bed; sentence two: a small bedroom suite in a hotel setting, furnished with a bed, a small table and two chairs; sentences one and two are considered similar when the condition is the place name, because both sentences describe a room located in a hotel; in addition, when the condition is the number of chairs, the two sentences are considered different because sentence one does not mention any chairs, while sentence one explicitly mentions that there are two chairs; solving the C-STS task requires sentence vectorization models to be able to Generate different representations of the same sentence under different conditions; multiple architecture encoders include dual encoders and triple encoders; calculate the similarity score between every two sentences; need to solve the problem of computational efficiency; the dual encoder in the C-STS task connects each sentence with each condition; generate representations for each unique sentence and condition combination; the triple encoder independently pre-computes the representations of sentences and conditions, and then uses a separate combination function to merge the semantics of sentences and conditions; the pre-computed sentence and condition representations are processed using Hadamard products or concatenation operations to obtain conditional sentence representations for similarity calculations; HyperCL projects the original sentence representation into a specific conditional subspace by integrating hypernetworks, thereby reducing the performance difference between the triple encoder method and the dual encoder method; the use of hypernetworks introduces an external parameter set that is three times larger than the backbone model, and the encoder as a whole is very large, and other issues remain to be resolved; therefore, it is necessary to propose a vectorized semantic representation method and system for multi-conditional sentences to at least partially solve the problems existing in the prior art. Summary of the invention
[0003] A series of simplified concepts are introduced in the content of the invention, which will be further described in detail in the specific implementation method section; the content of the invention of the present invention does not mean to attempt to limit the key features and essential technical features of the technical solution claimed for protection, nor does it mean to attempt to determine the scope of protection of the technical solution claimed for protection.
[0004] To at least partially solve the above problems, the present invention provides a method for vectorizing semantic representation of multiple conditional statements, comprising:
[0005] S100, setting a Transformer-based sentence encoder F as a framework backbone to obtain an embedding of a set condition C;
[0006] S200, extracting the query vector of the common language standard word token in the last layer of the sentence encoder F, and inputting the sentence S to be recognized into the same sentence encoder F;
[0007] S300, selecting the tth layer of the sentence encoder F, constructing a conditional-related router, and starting to introduce the conditional-related router to perform semantic representation operations;
[0008] S400, calculates the weight for each word in the sentence S to be recognized, determines the relevance of each word to the set condition C according to the weight, selects and sets the most relevant word with the highest relevance to condition C to perform heavy attention and the non-most relevant word to perform light attention dynamic adjustment mechanism, generates a vectorized representation of a multi-condition specific sentence, and reflects the semantic information of the multi-condition text.
[0009] Preferably, S100 includes:
[0010] S101, setting the Transformer-based sentence encoder F as the framework backbone;
[0011] S102, according to the sentence encoder F, obtain the embedding of the set condition C.
[0012] Preferably, S200 includes:
[0013] S201, extracting the query vector of the common language standard word token in the last layer of the sentence encoder F, and performing subsequent input and output operations;
[0014] S202, inputting the sentence S to be recognized into the same sentence encoder F;
[0015] Query vector qc∈Rdc; subsequent input and output operations include: qc = f (c) function input and output.
[0016] Preferably, S300 includes:
[0017] S301, select the tth layer of the sentence encoder F;
[0018] S302, constructing a conditional correlation router based on the multi-head attention hidden state;
[0019] S303, starting from the tth layer of the sentence encoder F, a conditional correlation router is introduced to perform semantic representation operations.
[0020] Preferably, S400 includes:
[0021] S401, calculating a weight for each word in the sentence S to be recognized, determining the relevance of each word to the set condition C according to the weight, selecting the most relevant word in the sentence S to be recognized with the highest relevance to the set condition C to reflect the semantics emphasized by the set condition C; normalizing the weight to obtain a normalized routing weight; the normalized routing weight includes: a first normalized routing weight and a second normalized routing weight, which are used to respectively perform heavy attention and light attention;
[0022] S402, the most relevant word performs heavy attention by multiplying the word value vector by the first normalized routing weight; the remaining words other than the most relevant word perform light attention by multiplying the word value vector by the second normalized routing weight;
[0023] S403, calculating different weight distributions for sentences according to different conditions, generating vectorized representations of multi-conditional specific sentences; dynamically modifying sentence representations according to the influence of conditions of another text, reflecting the semantic information of the multi-conditional text.
[0024] The present invention provides a multi-conditional statement vectorized semantic representation system, comprising:
[0025] The backbone frame condition subsystem sets the Transformer-based sentence encoder F as the frame backbone and obtains the embedding of the set condition C;
[0026] The query vector extraction subsystem extracts the query vector of the common language standard word token in the last layer of the sentence encoder F, and inputs the sentence S to be recognized into the same sentence encoder F;
[0027] The conditional router introduces a subsystem, selects the tth layer of the sentence encoder F, builds a conditional-related router, and begins to introduce the conditional-related router for semantic representation operations;
[0028] The multi-conditional text vectorization subsystem calculates the weight for each word in the sentence S to be recognized, determines the relevance of each word to the set condition C based on the weight, selects and sets the most relevant word with the highest relevance to condition C to perform heavy attention and the non-most relevant word to perform light attention dynamic adjustment mechanism, generates a vectorized representation of a multi-conditional specific sentence, and reflects the semantic information of the multi-conditional text.
[0029] Preferably, the backbone framework condition subsystem includes:
[0030] The framework backbone encoding module sets the Transformer-based sentence encoder F as the framework backbone;
[0031] The conditional embedding module is set to obtain the embedding of the set condition C according to the sentence encoder F.
[0032] Preferably, the query vector extraction subsystem includes:
[0033] The query vector acquisition module extracts the query vector of the common language standard word token in the last layer of the sentence encoder F for subsequent input and output operations;
[0034] The encoder sentence input module inputs the sentence to be recognized S into the same sentence encoder F;
[0035] Query vector qc∈Rdc; subsequent input and output operations include: qc = f (c) function input and output.
[0036] Preferably, the conditional router introduces a subsystem, including:
[0037] The encoder layer selection module selects the tth layer of the sentence encoder F;
[0038] The attention mechanism router module builds a conditional correlation router based on the multi-head attention hidden state;
[0039] The semantic representation module is introduced. Starting from the tth layer of the sentence encoder F, a conditional correlation router is introduced to perform semantic representation operations.
[0040] Preferably, the multi-conditional text vectorization subsystem includes:
[0041] The semantically related word selection module calculates the weight for each word in the sentence S to be recognized, determines the relevance of each word to the set condition C according to the weight, and selects the most relevant word with the highest relevance to the set condition C in the sentence S to be recognized to reflect the semantics emphasized by the set condition C; the weight is normalized to obtain the normalized routing weight; the normalized routing weight includes: a first normalized routing weight and a second normalized routing weight, which are used to respectively perform heavy attention and light attention;
[0042] In the heavy-light attention execution module, the most relevant words are subjected to heavy attention by multiplying the word value vector by the first normalized routing weight; the remaining words other than the most relevant words are subjected to light attention by multiplying the word value vector by the second normalized routing weight;
[0043] The weight distribution vectorization module calculates different weight distributions for sentences according to different conditions and generates vectorized representations of multi-conditional specific sentences. It dynamically modifies the sentence representation according to the conditional influence of another text to reflect the semantic information of the multi-conditional text.
[0044] Compared with the prior art, the present invention has at least the following beneficial effects:
[0045] The present invention provides a multi-conditional sentence vectorization semantic representation method and system, which sets a sentence encoder F based on Transformer as a framework backbone to obtain the embedding of a set condition C; extracts the query vector of a common language standard word token at the last layer of the sentence encoder F, and inputs a sentence S to be recognized into the same sentence encoder F; selects the tth layer of the sentence encoder F, constructs a condition-related router, and begins to introduce the condition-related router for semantic representation operation; calculates a weight for each word in the sentence S to be recognized, determines the relevance of each word to the set condition C according to the weight, selects and sets the most relevant word with the highest relevance to the condition C to perform a heavy attention and a non-most relevant word to perform a light attention dynamic adjustment mechanism, generates a multi-conditional specific sentence vectorization representation, and reflects the semantic information of the multi-conditional text; sets a given sentence set ,in, Represent sentences s1 and s2 respectively, set the condition C = ci, ci represents the conditions, and aggregate them to obtain each possible conditional sentence representation; in the BI-ENCODER architecture, a |S| × |C| forward encoding process is performed; in the TRI-ENCODER architecture, it is simplified to an |S| + |C| forward encoding process, and a |S| × |C| lightweight combination calculation; the computational efficiency of TRI-ENCODER is improved; there is no direct interaction between the sentences and conditions in the encoder, and routers are only added in the last few layers. An embodiment includes setting t to T layers and adding condition-related routers only in the t = T-1 layer, reducing performance degradation, improving the trade-off between performance and computational efficiency, effectively integrating the advantages of the two architectures, improving the performance of TRI-ENCODER, and maintaining efficient computing; the change curve proves that the framework of the present invention has significant superiority; the present invention simultaneously passes multiple sentences to Transformer The network model generates an output value between the set range interval to reflect the similarity of the input sentence group; maps words to the real vector space; each word is represented as a real vector of fixed length, obtains the word vector mark in the abstract space, and represents the word semantic information in the high-dimensional vector space; and maps the discrete word vector to the continuous word embedding vector; the Transformer network model embedding layer is set as the first layer of the model; the word embedding vector is input into the first layer of the Transformer network model, and the output of the first layer of the Transformer network model is passed to the subsequent layers of the model; the word embedding vector is learned through the training process; it can be more adapted to the task context; it understands the semantic structure more accurately; some advantages and technical effects: no additional parameters are introduced; all vectors qc and vectors Ks used in the router mechanism are directly derived from the original backbone encoder; the selected conditional related tokens are directly enhanced by multiplying the word value vector by the standardized router weight, with a higher representation of the router weight; process training: given a training sample (s1, s2, ci, y*), the mean square error target training framework is adopted, in which the cosine distance function is calculated as follows The dot product of two vectors is divided by the product of the lengths of the two vectors to calculate the cosine similarity; Calculate the cosine similarity of the sentence pair (s1, s2) and condition c: first calculate the single text similarity; According to the single text similarity, perform h conversion, convert the dimension from two dimensions to one dimension, and calculate the cosine similarity; Evaluate the CSR framework of the C-STS task with different backbone models; The backbone models include: SimCSE backbone model and DiffCSE backbone model; CSR framework is the abbreviation of Conditioned Sentence Representation framework; The multi-conditional sentence representation framework adopted in the present invention has the same basic architecture, data set segmentation, hyperparameters and evaluation indicators as the baselines of Deshpan and others, and the evaluation indicators are Spearman and Pearson correlation, and pre-order settings are performed; According to the performance of the validation set, select a specific hyperparameter t and the best model checkpoint; The CSR framework is designed for the TRI-ENCODER architecture, but it can be extended to BI-ENCODER by using the conditional common language specification word token CLS and the attention weight of the sentence tag as the router score w to calculate the sentence hidden state calculation. architecture; the effectiveness of the router mechanism of the present invention in multiple architectures is demonstrated; the addition results are averaged over three runs; the experimental results of the CSR framework of the present invention in the C-STS task show significant improvements over the C-STS baseline, with Spearman and Pearson correlation coefficients increased by 6.7% and 7.1% respectively; the number of parameters of HyperCL is doubled without adding any additional parameters; combining the router mechanism of the present invention with the BI-ENCODER architecture also shows significant advantages over Deshpande et al.
[0046] The present invention describes a method and system for vectorizing semantic representation of multiple conditional statements. Other advantages, objectives, and features of the present invention will be partially reflected through the following description, and will also be partially understood by technicians in the field through research and practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0048] Figure 1 A diagram of an embodiment of a method for vectorized semantic representation of multiple conditional statements described in the present invention.
[0049] Figure 2This is a graph showing an implementation example of a curve of the performance and time taken for a multi-conditional statement vectorization semantic representation method and system model described in the present invention as a function of a hyperparameter t.
[0050] Figure 3 This is a diagram of an implementation example of a vectorized semantic representation method for multiple conditional statements and system data comparison according to the present invention. DETAILED DESCRIPTION
[0051] The present invention is further described in detail below in conjunction with the accompanying drawings and embodiments so that those skilled in the art can implement the invention with reference to the description. As shown in the drawings, the present invention provides a method for vectorizing semantic representation of multiple conditional statements, including:
[0052] S100, setting a Transformer-based sentence encoder F as a framework backbone to obtain an embedding of a set condition C;
[0053] S200, extracting the query vector of the common language standard word token in the last layer of the sentence encoder F, and inputting the sentence S to be recognized into the same sentence encoder F;
[0054] S300, selecting the tth layer of the sentence encoder F, constructing a conditional-related router, and starting to introduce the conditional-related router to perform semantic representation operations;
[0055] S400, calculates the weight for each word in the sentence S to be recognized, determines the relevance of each word to the set condition C according to the weight, selects and sets the most relevant word with the highest relevance to condition C to perform heavy attention and the non-most relevant word to perform light attention dynamic adjustment mechanism, generates a vectorized representation of a multi-condition specific sentence, and reflects the semantic information of the multi-condition text.
[0056] The principle and effect of the above technical solution are as follows: the present invention provides a method for vectorized semantic representation of multi-conditional sentences, including: setting a sentence encoder F based on Transformer as a framework backbone to obtain the embedding of a set condition C; extracting the query vector of the common language standard word token at the last layer of the sentence encoder F, and inputting the sentence S to be recognized into the same sentence encoder F; selecting the tth layer of the sentence encoder F, constructing a condition-related router, and starting to introduce the condition-related router for semantic representation operation; calculating a weight for each word in the sentence S to be recognized, determining the relevance of each word to the set condition C according to the weight, selecting and setting the most relevant word with the highest relevance to the condition C to perform a heavy attention and a non-most relevant word to perform a light attention dynamic adjustment mechanism, generating a vectorized representation of a multi-conditional specific sentence, and reflecting the semantic information of the multi-conditional text;
[0057] Given a set of sentences ,in, Represent sentences s1 and s2 respectively, set the condition C = ci, ci represents the conditions, and aggregate them to obtain each possible conditional sentence representation; in the BI-ENCODER architecture, a |S| × |C| forward encoding process is performed; in the TRI-ENCODER architecture, it is simplified to an |S| + |C| forward encoding process, and a |S| × |C| lightweight combination calculation; the computational efficiency of TRI-ENCODER is improved; there is no direct interaction between the sentences and conditions in the encoder, and routers are only added in the last few layers. An embodiment includes setting t to T layers and adding condition-related routers only in the t = T-1 layer, reducing performance degradation, improving the trade-off between performance and computational efficiency, effectively integrating the advantages of the two architectures, improving the performance of TRI-ENCODER, and maintaining efficient computing; the change curve proves that the framework of the present invention has significant superiority; the present invention simultaneously passes multiple sentences to Transformer The network model generates an output value between the set range interval to reflect the similarity of the input sentence group; maps words to real vector space; each word is represented as a real vector of fixed length, obtains the position of the word vector in the abstract space, and represents the semantic information of the word in the high-dimensional vector space; and maps the discrete word vector to a continuous word embedding vector; the embedding layer of the Transformer network model is set as the first layer of the model; the word embedding vector is input into the first layer of the Transformer network model, and the output of the first layer of the Transformer network model is passed to the subsequent layers of the model; the word embedding vector is learned through the training process; it can be more adapted to the task context; it understands the semantic structure more accurately; some advantages and technical effects: no additional parameters are introduced; all vectors qc and vectors Ks used in the router mechanism are directly derived from the original backbone encoder; the selected condition-related tokens are directly enhanced by multiplying the word value vector by the standardized router weight, with a higher representation of the router weight; process training: given a training sample (s1, s2, ci, y*), the mean square error target training framework formula is:
[0058]
[0059] Where: φ represents the cosine distance function; They represent the vector of sentence s1 under condition C and the vector of sentence s2 under condition C respectively; y* represents the basic true label similarity score between sentence s1 and sentence s2 under condition C; the cosine distance function is calculated as The dot product of two vectors is divided by the product of the lengths of the two vectors to calculate the cosine similarity. Calculate the cosine similarity of the sentence pair (s1, s2) and condition c: first calculate the similarity of a single text; based on the similarity of a single text, perform h conversion, convert the dimension from two dimensions to one dimension, and calculate the cosine similarity;
[0060] The CSR framework for C-STS tasks is evaluated with different backbone models; the backbone models include: SimCSE backbone model and DiffCSE backbone model; CSR framework is short for Conditioned Sentence Representation framework; the multi-conditional sentence representation framework adopted by the present invention has the same basic architecture, dataset segmentation, hyperparameters and evaluation indicators as the baselines of Deshpan et al., and the evaluation indicators are Spearman and Pearson correlation, and pre-order settings are performed; according to the performance of the validation set, the specific hyperparameter t and the best model checkpoint are selected; the CSR framework is designed for the TRI-ENCODER architecture, but it can be extended to the BI-ENCODER architecture by using the conditional common language specification word token CLS and the attention weights of the sentence tags as the router score w to calculate the sentence hidden state calculation; the effectiveness of the router mechanism of the present invention in multiple architectures is proved; the addition results are averaged over three runs;
[0061] The experimental results of the CSR framework of the present invention in the C-STS task have achieved significant improvements compared with the C-STS baseline, with the Spearman and Pearson correlation coefficients increased by 6.7% and 7.1% respectively; without adding any additional parameters, the number of parameters of HyperCL has been doubled; combining the router mechanism of the present invention with the BI-ENCODER architecture also shows significant advantages over Deshpande et al.
[0062] In one embodiment, S100 includes:
[0063] S101, setting the Transformer-based sentence encoder F as the framework backbone;
[0064] S102, according to the sentence encoder F, obtain the embedding of the set condition C.
[0065] The principle and effect of the above technical solution are: set the sentence encoder F based on Transformer as the framework backbone; obtain the embedding of the set condition C according to the sentence encoder F; set a given sentence set ,in, Represent sentences s1 and s2 respectively, set the condition C = ci, ci represents the conditions, and aggregate them to obtain each possible conditional sentence representation; perform | S | × | C | forward encoding process in the BI-ENCODER architecture; simplify it to | S | + | C | forward encoding process and | S | × | C | lightweight combination calculation in the TRI-ENCODER architecture; extend and combine the BI-ENCODER architecture and the TRI-ENCODER architecture, extend and combine the cross encoder and the dual encoder, and use the dual encoder to retrieve the t most similar sentences; calculate the combined similarity score of the query and the selected sentence through the cross encoder, rearrange the t most similar sentences, and obtain a more optimized similar sentence arrangement; such as Figure 1 In: Similarity score represents the similarity score; Encoder f represents the encoder, and f(c) is the input-output function; ) represents w; Transformer block represents the Transformer block; represents the vector ks; represents the vector qc; AVG represents the AVG function, which is used to calculate the average value; the framework structure of the present invention significantly improves the recognition accuracy of sentence semantic representation
[0066] In one embodiment, S200 includes:
[0067] S201, extracting the query vector of the common language standard word token in the last layer of the sentence encoder F, and performing subsequent input and output operations;
[0068] S202, inputting the sentence S to be recognized into the same sentence encoder F;
[0069] Query vector qc∈Rdc; subsequent input and output operations include: qc = f (c) function input and output.
[0070] The principle and effect of the above technical solution are: extracting the query vector of the common language standard word token in the last layer of the sentence encoder F, and performing subsequent input and output operations; inputting the sentence S to be recognized into the same sentence encoder F; query vector qc∈Rdc; Rdc represents the query vector set; subsequent input and output operations include: qc = f (c) function input and output; f (c) function is the basic operation function of the Transformer encoder; routers are only added in the last few layers, that is, t→ T; routers are only added in the t = T-1 layer; there is no direct interaction between the sentences and conditions in the encoder, and routers are only added in the last few layers. An embodiment includes setting t to T layer and adding condition-related routers only in the t = T-1 layer, reducing performance degradation, improving the trade-off between performance and computing efficiency, effectively integrating the advantages of the two architectures, improving the performance of TRI-ENCODER, and maintaining efficient computing.
[0071] In one embodiment, S300 includes:
[0072] S301, select the tth layer of the sentence encoder F;
[0073] S302, constructing a conditional correlation router based on the multi-head attention hidden state;
[0074] S303, starting from the tth layer of the sentence encoder F, a conditional correlation router is introduced to perform semantic representation operations.
[0075] The principle and effect of the above technical solution are as follows: select the tth layer of the sentence encoder F; construct a condition-related router according to the multi-head attention hidden state; start from the tth layer of the sentence encoder F, introduce the condition-related router to perform semantic representation operation; construct the condition-related router including: for the tth layer of the sentence encoder F, set the query vector q of the condition C to query each word in the sentence to be recognized S, and obtain the routing weight of each word, which is calculated by multiplying the query vector of the condition and the key value vector k of each word in the sentence; the multi-head attention hidden state h of the sentence to be recognized S at the tth layer is expressed as:
[0076] ; where h' is the original multi-head attention hidden state of the t-th Transformer block without the routing mechanism, and w is the weight after normalization of the routing weight.
[0077] In one embodiment, S400 includes:
[0078] S401, calculating a weight for each word in the sentence S to be recognized, determining the relevance of each word to the set condition C according to the weight, selecting the most relevant word in the sentence S to be recognized with the highest relevance to the set condition C to reflect the semantics emphasized by the set condition C; normalizing the weight to obtain a normalized routing weight; the normalized routing weight includes: a first normalized routing weight and a second normalized routing weight, which are used to respectively perform heavy attention and light attention;
[0079] S402, the most relevant word performs heavy attention by multiplying the word value vector by the first normalized routing weight; the remaining words other than the most relevant word perform light attention by multiplying the word value vector by the second normalized routing weight;
[0080] S403, calculating different weight distributions for sentences according to different conditions, generating vectorized representations of multi-conditional specific sentences; dynamically modifying sentence representations according to the influence of conditions of another text, reflecting the semantic information of the multi-conditional text.
[0081] The principle and effect of the above technical solution are: calculate the weight for each word in the sentence S to be recognized, determine the relevance of each word to the set condition C according to the weight, select the most relevant word in the sentence S to be recognized with the highest relevance to the set condition C to reflect the semantics emphasized by the set condition C; normalize the weight to obtain the normalized routing weight; the normalized routing weight includes: a first normalized routing weight and a second normalized routing weight, which are used to perform heavy attention and light attention respectively; the most relevant word performs heavy attention by multiplying the word value vector by the first normalized routing weight; the remaining words other than the most relevant word perform light attention by multiplying the word value vector by the second normalized routing weight; calculate different weight distributions for sentences according to different conditions, and generate vectorized representations of multi-condition specific sentences; according to another The conditional influence of a text dynamically modifies the sentence representation to reflect the semantic information of the multi-conditional text; different weight distributions are calculated for sentences according to different conditions to generate a multi-conditional specific sentence vectorized representation, including: the multi-head attention hidden state h is passed to the t+1th transformer block after the tth transformer block, and continues to advance to subsequent transformer blocks; from the tth layer to the last Tth layer of the sentence encoder F, the hidden state of each layer is affected by the condition-related router; the marked hidden states in the last layer are average pooled to obtain the multi-conditional specific sentence vectorized representation; using the multi-conditional specific sentence vectorized representation, the sentence representation is dynamically modified according to the conditional influence of another text to reflect the semantic information of the multi-conditional text.
[0082] The present invention provides a multi-conditional statement vectorized semantic representation system, comprising:
[0083] The backbone frame condition subsystem sets the Transformer-based sentence encoder F as the frame backbone and obtains the embedding of the set condition C;
[0084] The query vector extraction subsystem extracts the query vector of the common language standard word token in the last layer of the sentence encoder F, and inputs the sentence S to be recognized into the same sentence encoder F;
[0085] The conditional router introduces a subsystem, selects the tth layer of the sentence encoder F, builds a conditional-related router, and begins to introduce the conditional-related router for semantic representation operations;
[0086] The multi-conditional text vectorization subsystem calculates the weight for each word in the sentence S to be recognized, determines the relevance of each word to the set condition C based on the weight, selects and sets the most relevant word with the highest relevance to condition C to perform heavy attention and the non-most relevant word to perform light attention dynamic adjustment mechanism, generates a vectorized representation of a multi-conditional specific sentence, and reflects the semantic information of the multi-conditional text.
[0087] The principle and effect of the above technical solution are as follows: the present invention provides a multi-conditional sentence vectorization semantic representation system, including: a backbone framework condition subsystem, setting a sentence encoder F based on Transformer as a framework backbone, and obtaining the embedding of the set condition C; a query vector extraction subsystem, extracting the query vector of the common language standard word token at the last layer of the sentence encoder F, and inputting the sentence S to be recognized into the same sentence encoder F; a condition router introduction subsystem, selecting the tth layer of the sentence encoder F, constructing a condition-related router, and starting to introduce the condition-related router for semantic representation operations; a multi-conditional text vectorization subsystem, calculating the weight for each word in the sentence S to be recognized, determining the relevance of each word to the set condition C according to the weight, selecting and setting the most relevant word with the highest relevance to the condition C to perform heavy attention and the non-most relevant word to perform light attention dynamic adjustment mechanism, generating a multi-conditional specific sentence vectorization representation, reflecting the semantic information of the multi-conditional text;
[0088] Given a set of sentences ,in, Represent sentences s1 and s2 respectively, set the condition C = ci, ci represents the conditions, and aggregate them to obtain each possible conditional sentence representation; in the BI-ENCODER architecture, a |S| × |C| forward encoding process is performed; in the TRI-ENCODER architecture, it is simplified to an |S| + |C| forward encoding process, and a |S| × |C| lightweight combination calculation; the computational efficiency of TRI-ENCODER is improved; there is no direct interaction between the sentences and conditions in the encoder, and routers are only added in the last few layers. An embodiment includes setting t to T layers and adding condition-related routers only in the t = T-1 layer, reducing performance degradation, improving the trade-off between performance and computational efficiency, effectively integrating the advantages of the two architectures, improving the performance of TRI-ENCODER, and maintaining efficient computing; the change curve proves that the framework of the present invention has significant superiority; the present invention simultaneously passes multiple sentences to Transformer The network model generates an output value between the set range interval to reflect the similarity of the input sentence group; maps words to real vector space; each word is represented as a real vector of fixed length, obtains the position of the word vector in the abstract space, and represents the semantic information of the word in the high-dimensional vector space; and maps the discrete word vector to a continuous word embedding vector; the embedding layer of the Transformer network model is set as the first layer of the model; the word embedding vector is input into the first layer of the Transformer network model, and the output of the first layer of the Transformer network model is passed to the subsequent layers of the model; the word embedding vector is learned through the training process; it can be more adapted to the task context; it understands the semantic structure more accurately; some advantages and technical effects: no additional parameters are introduced; all vectors qc and vectors Ks used in the router mechanism are directly derived from the original backbone encoder; the selected condition-related tokens are directly enhanced by multiplying the word value vector by the standardized router weight, with a higher representation of the router weight; process training: given a training sample (s1, s2, ci, y*), the mean square error target training framework formula is:
[0089]
[0090] Where: φ represents the cosine distance function; They represent the vector of sentence s1 under condition C and the vector of sentence s2 under condition C respectively; y* represents the basic true label similarity score between sentence s1 and sentence s2 under condition C; the cosine distance function is calculated as The dot product of two vectors is divided by the product of the lengths of the two vectors to calculate the cosine similarity. Calculate the cosine similarity of the sentence pair (s1, s2) and condition c: first calculate the similarity of a single text; based on the similarity of a single text, perform h conversion, convert the dimension from two dimensions to one dimension, and calculate the cosine similarity;
[0091] The CSR framework for C-STS tasks is evaluated with different backbone models; the backbone models include: SimCSE backbone model and DiffCSE backbone model; CSR framework is short for Conditioned Sentence Representation framework; the multi-conditional sentence representation framework adopted by the present invention has the same basic architecture, dataset segmentation, hyperparameters and evaluation indicators as the baselines of Deshpan et al., and the evaluation indicators are Spearman and Pearson correlation, and pre-order settings are performed; according to the performance of the validation set, the specific hyperparameter t and the best model checkpoint are selected; the CSR framework is designed for the TRI-ENCODER architecture, but it can be extended to the BI-ENCODER architecture by using the conditional common language specification word token CLS and the attention weights of the sentence tags as the router score w to calculate the sentence hidden state calculation; the effectiveness of the router mechanism of the present invention in multiple architectures is proved; the addition results are averaged over three runs;
[0092] The experimental results of the CSR framework of the present invention in the C-STS task have achieved significant improvements compared with the C-STS baseline, with the Spearman and Pearson correlation coefficients increased by 6.7% and 7.1% respectively; without adding any additional parameters, the number of parameters of HyperCL has been doubled; combining the router mechanism of the present invention with the BI-ENCODER architecture also shows significant advantages over Deshpande et al.
[0093] In one embodiment, the backbone framework condition subsystem includes:
[0094] The framework backbone encoding module sets the Transformer-based sentence encoder F as the framework backbone;
[0095] The conditional embedding module is set to obtain the embedding of the set condition C according to the sentence encoder F.
[0096] The principle and effect of the above technical solution are as follows: the backbone frame condition subsystem includes: a frame backbone encoding module, which sets a sentence encoder F based on Transformer as the frame backbone; a conditional embedding module, which obtains the embedding of the set condition C according to the sentence encoder F; and a given sentence set is set. ,in, Represent sentences s1 and s2 respectively, set the condition C = ci, ci represents the conditions, and aggregate them to obtain the representation of each possible conditional sentence; the BI-ENCODER architecture and the TRI-ENCODER architecture are extended and combined, and the cross encoder and the dual encoder are extended and combined to retrieve the t most similar sentences through the dual encoder; the cross encoder is used to calculate the combined similarity score of the query and the selected sentence, and the t most similar sentences are rearranged to obtain a more optimized arrangement of similar sentences; Figure 1 In: Similarity score represents the similarity score; Encoder f represents the encoder, and f(c) is the input-output function; ) represents w; Transformer block represents the Transformer block; represents the vector ks; represents the vector qc; AVG represents the AVG function, which is used to calculate the average value; the framework structure of the present invention significantly improves the recognition accuracy of the sentence semantic representation.
[0097] In one embodiment, the query vector extraction subsystem includes:
[0098] The query vector acquisition module extracts the query vector of the common language standard word token in the last layer of the sentence encoder F for subsequent input and output operations;
[0099] The encoder sentence input module inputs the sentence to be recognized S into the same sentence encoder F;
[0100] Query vector qc∈Rdc; subsequent input and output operations include: qc = f (c) function input and output.
[0101] The principle and effect of the above technical solution are: a query vector extraction subsystem, including: a query vector acquisition module, which extracts the query vector of the common language standard word token in the last layer of the sentence encoder F, and performs subsequent input and output operations; an encoder sentence input module, which inputs the sentence S to be recognized into the same sentence encoder F; a query vector qc∈Rdc; subsequent input and output operations include: qc = f (c) function input and output; the f (c) function is a basic operation function of the Transformer encoder; there is no direct interaction between the sentences and conditions in the encoder, and routers are only added in the last few layers. An embodiment includes setting t to T layers to add condition-related routers only in the t = T-1 layer, reducing performance degradation, improving the trade-off between performance and computing efficiency, effectively integrating the advantages of the two architectures, and improving the performance of TRI-ENCODER while maintaining efficient computing.
[0102] In one embodiment, the conditional router introduces a subsystem, including:
[0103] The encoder layer selection module selects the tth layer of the sentence encoder F;
[0104] The attention mechanism router module builds a conditional correlation router based on the multi-head attention hidden state;
[0105] The semantic representation module is introduced. Starting from the tth layer of the sentence encoder F, a conditional correlation router is introduced to perform semantic representation operations.
[0106] The principle and effect of the above technical solution are as follows: the conditional router introduces a subsystem, including: an encoder level selection module, which selects the tth layer of the sentence encoder F; an attention mechanism router module, which constructs a condition-related router according to the multi-head attention hidden state; an introduction of a semantic representation module, which starts from the tth layer of the sentence encoder F and introduces a condition-related router for semantic representation operations; the construction of a condition-related router includes:
[0107] For the tth layer of the sentence encoder F, the query vector q of the condition C is set to query each word in the sentence S to be recognized, and the routing weight of each word is obtained. The routing weight is calculated by multiplying the query vector of the condition and the key value vector k of each word in the sentence; the multi-head attention hidden state h of the sentence S to be recognized at the tth layer is expressed as: ; where h' is the original multi-head attention hidden state of the t-th Transformer block without the routing mechanism, and w is the weight after normalization of the routing weight.
[0108] In one embodiment, the multi-conditional text vectorization subsystem includes:
[0109] The semantically related word selection module calculates the weight for each word in the sentence S to be recognized, determines the relevance of each word to the set condition C according to the weight, and selects the most relevant word with the highest relevance to the set condition C in the sentence S to be recognized to reflect the semantics emphasized by the set condition C; the weight is normalized to obtain the normalized routing weight; the normalized routing weight includes: a first normalized routing weight and a second normalized routing weight, which are used to respectively perform heavy attention and light attention;
[0110] In the heavy-light attention execution module, the most relevant words are subjected to heavy attention by multiplying the word value vector by the first normalized routing weight; the remaining words other than the most relevant words are subjected to light attention by multiplying the word value vector by the second normalized routing weight;
[0111] The weight distribution vectorization module calculates different weight distributions for sentences according to different conditions and generates vectorized representations of multi-conditional specific sentences. It dynamically modifies the sentence representation according to the conditional influence of another text to reflect the semantic information of the multi-conditional text.
[0112] The principle and effect of the above technical solution are as follows: a multi-conditional text vectorization subsystem, including: a semantically related word selection module, which calculates the weight for each word in the sentence S to be identified, determines the relevance of each word to the set condition C according to the weight, and selects the most relevant word with the highest relevance to the set condition C in the sentence S to be identified to reflect the semantics emphasized by the set condition C; normalizes the weight to obtain the normalized routing weight; the normalized routing weight includes: a first normalized routing weight and a second normalized routing weight, which are used to perform heavy attention and light attention respectively; a heavy and light attention execution module, in which the most relevant word performs heavy attention by multiplying the word value vector by the first normalized routing weight; the remaining words other than the most relevant word perform light attention by multiplying the word value vector by the second normalized routing weight; a weight distribution vectorization module, which calculates different weights for sentences according to different conditions Redistribute to generate multi-condition specific sentence vectorized representation; dynamically modify the sentence representation according to the conditional influence of another text to reflect the semantic information of the multi-condition text; calculate different weight distributions for sentences according to different conditions to generate multi-condition specific sentence vectorized representation including: the multi-head attention hidden state h is passed to the t+1th transformer block after the tth transformer block, and continues to advance to subsequent transformer blocks; from the tth layer to the last Tth layer of the sentence encoder F, the hidden state of each layer is affected by the condition-related router; average pooling is performed on the marked hidden states in the last layer to obtain the multi-condition specific sentence vectorized representation; using the multi-condition specific sentence vectorized representation, dynamically modify the sentence representation according to the conditional influence of another text to reflect the semantic information of the multi-condition text.
[0113] Although the embodiments of the present invention have been disclosed as above, they are not limited to the applications listed in the specification and the implementation methods. They can be fully applied to various fields suitable for the present invention. For those familiar with the art, additional modifications can be easily implemented. Therefore, without departing from the general concept defined by the claims and the scope of equivalents, the present invention is not limited to the specific details and the illustrations shown and described herein.
Claims
1. A method for vectorizing semantic representation of multiple conditional statements, characterized in that: include: S100, setting a Transformer-based sentence encoder F as a framework backbone to obtain an embedding of a set condition C; S200, extracting the query vector of the common language standard word token in the last layer of the sentence encoder F, and inputting the sentence S to be recognized into the same sentence encoder F; S300, selecting the tth layer of the sentence encoder F, constructing a conditional-related router, and starting to introduce the conditional-related router to perform semantic representation operations; S400, calculating a weight for each word in the sentence S to be recognized, determining the relevance of each word to the set condition C according to the weight, selecting and setting the most relevant word with the highest relevance to the condition C to perform heavy attention and the non-most relevant word to perform light attention dynamic adjustment mechanism, generating a vectorized representation of the multi-condition setting sentence, reflecting the semantic information of the multi-condition text; S400 includes: S401, calculating a weight for each word in the sentence S to be recognized, determining the relevance of each word to the set condition C according to the weight, selecting the most relevant word in the sentence S to be recognized with the highest relevance to the set condition C to reflect the semantics emphasized by the set condition C; normalizing the weight to obtain a normalized routing weight; the normalized routing weight includes: a first normalized routing weight and a second normalized routing weight, which are used to respectively perform heavy attention and light attention; S402, the most relevant word performs heavy attention by multiplying the word value vector by the first normalized routing weight; the remaining words other than the most relevant word perform light attention by multiplying the word value vector by the second normalized routing weight; S403, calculating different weight distributions for sentences according to different conditions, generating vectorized representations of multi-conditional sentences; dynamically modifying sentence representations according to the influence of conditions of another text, reflecting the semantic information of the multi-conditional text.
2. A method for vectorizing semantic representation of multiple conditional statements according to claim 1, characterized in that: S100 includes: S101, setting the Transformer-based sentence encoder F as the framework backbone; S102, according to the sentence encoder F, obtain the embedding of the set condition C.
3. A method for vectorizing semantic representation of multiple conditional statements according to claim 1, characterized in that: S200 includes: S201, extracting the query vector of the common language standard word token in the last layer of the sentence encoder F, and performing subsequent input and output operations; S202, inputting the sentence S to be recognized into the same sentence encoder F; Query vector qc∈Rdc; subsequent input and output operations include: qc = f (c) function input and output.
4. A method for vectorizing semantic representation of multiple conditional statements according to claim 1, characterized in that: S300 includes: S301, select the tth layer of the sentence encoder F; S302, constructing a conditional correlation router based on the multi-head attention hidden state; S303, starting from the tth layer of the sentence encoder F, a conditional correlation router is introduced to perform semantic representation operations.
5. A multi-conditional statement vectorized semantic representation system, characterized in that: include: The backbone frame condition subsystem sets the Transformer-based sentence encoder F as the frame backbone and obtains the embedding of the set condition C; The query vector extraction subsystem extracts the query vector of the common language standard word token in the last layer of the sentence encoder F, and inputs the sentence S to be recognized into the same sentence encoder F; The conditional router introduces a subsystem, selects the tth layer of the sentence encoder F, builds a conditional-related router, and begins to introduce the conditional-related router for semantic representation operations; The multi-condition text vectorization subsystem calculates the weight for each word in the sentence S to be recognized, determines the relevance of each word to the set condition C based on the weight, selects and sets the most relevant word with the highest relevance to condition C to perform heavy attention and the non-most relevant word to perform light attention dynamic adjustment mechanism, generates a vectorized representation of the multi-condition setting sentence, and reflects the semantic information of the multi-condition text; Multi-conditional text vectorization subsystem, including: The semantically related word selection module calculates the weight for each word in the sentence S to be recognized, determines the relevance of each word to the set condition C according to the weight, and selects the most relevant word with the highest relevance to the set condition C in the sentence S to be recognized to reflect the semantics emphasized by the set condition C; the weight is normalized to obtain the normalized routing weight; the normalized routing weight includes: a first normalized routing weight and a second normalized routing weight, which are used to respectively perform heavy attention and light attention; In the heavy-light attention execution module, the most relevant words are subjected to heavy attention by multiplying the word value vector by the first normalized routing weight; the remaining words other than the most relevant words are subjected to light attention by multiplying the word value vector by the second normalized routing weight; The weight distribution vectorization module calculates different weight distributions for sentences according to different conditions and generates vectorized representations of sentences with multiple condition settings. It dynamically modifies the sentence representation according to the conditional influence of another text to reflect the semantic information of the multi-conditional text.
6. A multi-conditional sentence vectorization semantic representation system according to claim 5, characterized in that: The main framework condition subsystem includes: The framework backbone encoding module sets the Transformer-based sentence encoder F as the framework backbone; The conditional embedding module is set to obtain the embedding of the set condition C according to the sentence encoder F.
7. A multi-conditional sentence vectorization semantic representation system according to claim 5, characterized in that: The query vector extraction subsystem includes: The query vector acquisition module extracts the query vector of the common language standard word token in the last layer of the sentence encoder F for subsequent input and output operations; The encoder sentence input module inputs the sentence to be recognized S into the same sentence encoder F; Query vector qc∈Rdc; subsequent input and output operations include: qc = f (c) function input and output.
8. A multi-conditional sentence vectorization semantic representation system according to claim 5, characterized in that: The conditional router introduces a subsystem, including: The encoder layer selection module selects the tth layer of the sentence encoder F; The attention mechanism router module builds a conditional correlation router based on the multi-head attention hidden state; The semantic representation module is introduced. Starting from the tth layer of the sentence encoder F, a conditional correlation router is introduced to perform semantic representation operations.
Citation Information
Patent Citations
Method and device for extracting chapter-level event based on multi-granularity entity heterogeneous graph
CN114742016A
Tapter-level neural machine translation method fusing topic information
CN115048946A