A stance detection method based on a knowledge graph and text pair classification
Patent Information
- Application Number
- CN202310754775.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-25
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2043-06-25
AI Technical Summary
然而,如果要引入更多的知识,就不得不解决外部知识对句意的干扰问题,否则也会影响检测的准确性
[0058]首先,在创建备选知识池时,将立场检测目标和原始输入文本所包含的实体作为匹配的备选实体,并将备选实体任意组合构成实体对集合,通过知识图谱的信息,能提取获得原始文本所包含实体与立场检测目标所包含实体的联系,无论立场检测目标是否存在于原始文本中,均能保证原始文本所包含实体与立场检测目标所包含实体进行连接,并作为辅助立场检测的知识,丰富备选知识池,缓解了立场检测目标外置导致的检测性能损失;其次,通过实体对匹配,筛选知识图谱中的知识,获得备选知识池,提高了知识图谱中知识的利用率,有助于充分利用这些知识提高检测的准确性;其三,将备选知识池所包含的外部知识与立场检测目标结合,构成带有不同立场的辅助句,避免了将外部知识直接插入原始文本中,降低了外部知识对句意的影响。
Smart Images

Figure CN116932772B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of stance detection, and more specifically to a stance detection method based on knowledge graphs and text pair classification. Background Technology
[0002] The purpose of stance detection is to classify a text into three categories—support, opposition, and neutral—or further subdivided into multiple types based on a given stance detection target. A knowledge graph is a semantic network constructed using triples in the form of entity-relationship-entity as its basic units. Its network structure can be used to represent the complex relationships between entities in the real world, a characteristic that makes knowledge graphs widely used in various stance detection methods.
[0003] Currently, most knowledge graph-based stance detection schemes use triples from the knowledge graph as domain knowledge injected into sentences, leveraging the knowledge graph to enhance BERT for stance detection. However, they fail to integrate the knowledge graph with the stance detection target, resulting in an externalized stance detection target. The role of the knowledge graph is difficult to distinguish as either an auxiliary tool or an inefficient external answer database, thus sacrificing detection performance.
[0004] Furthermore, the massive data collection and entity and relation extraction work undertaken to build the knowledge graph for stance detection are largely discarded by the model and knowledge filtering algorithms during the stance detection process. Therefore, improving the utilization rate of the knowledge graph should also be a focus. However, if more knowledge is to be introduced, the problem of external knowledge interfering with sentence meaning must be addressed; otherwise, the accuracy of detection will also be affected. Summary of the Invention
[0005] The technical problem to be solved by this invention is to propose a stance detection method based on knowledge graph and text pair classification, with the aim of improving the utilization rate of knowledge graph, reducing the influence of external knowledge on sentence meaning, and mitigating the performance loss caused by externalizing the stance detection target.
[0006] The technical solution adopted by the present invention to solve the above-mentioned technical problems is as follows:
[0007] A stance detection method based on knowledge graphs and text pair classification includes the following steps:
[0008] S1. Given the target of position detection and the original input text, extract the entities contained in both and combine them in any pairwise to form a set of entity pairs.
[0009] S2. Match each entity pair in the entity pair set with the entity pairs in the knowledge graph to obtain the triples in the knowledge graph that match each entity pair in the entity pair set, and construct them as a candidate knowledge pool.
[0010] S3. Combine the given position detection target and the different position categories for that position detection target with all the triples in the candidate knowledge pool to construct auxiliary sentences representing different position categories;
[0011] S4. Combine the given original input text with the auxiliary sentences representing different stance categories constructed in step S3 to form input pairs, and input them into the text detection model respectively. The text detection model outputs the confidence level of the original input text belonging to different stance categories, and the stance category corresponding to the highest confidence level is used as the stance detection result of the original input text.
[0012] Furthermore, in step S2, each entity pair in the entity pair set is matched with an entity pair in the knowledge graph to obtain triples in the knowledge graph that match each entity pair in the entity pair set, and these triples are used to construct a candidate knowledge pool, including:
[0013] First, each entity pair in the entity pair set is directly matched with the entity pairs in the knowledge graph to obtain triples in the knowledge graph that match each entity pair in the entity pair set, thus constructing an initial candidate knowledge pool.
[0014] Then, the triples in the initial candidate knowledge pool are fuzzy matched with the triples in the knowledge graph, and the triples in the knowledge graph that meet the preset conditions are added to the candidate knowledge pool to obtain the candidate knowledge pool after the first expansion.
[0015] Next, the triples in the first expanded candidate knowledge pool are semantically similar to the triples in the knowledge graph. Triples in the knowledge graph that meet the preset conditions are added to the candidate knowledge pool to obtain the second expanded candidate knowledge pool.
[0016] Specifically, each entity pair in the entity pair set is directly matched with an entity pair in the knowledge graph to obtain triples in the knowledge graph that match each entity pair in the entity pair set. These triples form the initial candidate knowledge pool.
[0017] For entity pairs T = (t) in the entity pair set i ,t j When the following conditions are met:
[0018] T=(t i ,t j )∈K=(k m ,r,k n ), i≠j, m≠n
[0019] Add the triple K from the knowledge graph to the candidate knowledge pool;
[0020] Where, km k n r and r represent the head entity, tail entity, and relation in a triplet of a knowledge graph, respectively; t i ,t j These are entities from the given original input text.
[0021] Specifically, the triples in the initial candidate knowledge pool are fuzzily matched with the triples in the knowledge graph. Triples in the knowledge graph that meet the preset conditions are added to the candidate knowledge pool, resulting in the first expanded candidate knowledge pool.
[0022] Find the triples K in the knowledge graph that satisfy the following formula. f Add to the alternative knowledge pool:
[0023]
[0024] Where Fuzz() is the fuzzy matching function, m f L is the number of triples in the candidate knowledge pool after fuzzy matching, m is the number of triples in the candidate knowledge pool before fuzzy matching, and L is the number of triples in the candidate knowledge pool before fuzzy matching. f This is the maximum number of fuzzy matches set, S. f It is the fuzzy matching similarity threshold.
[0025] Specifically, the fuzzy matching similarity threshold S f The calculation method is as follows:
[0026]
[0027] Among them, l t It is the average length of triples in a knowledge graph, l e It is the average length of entities in a triplet in a knowledge graph, l r It is the average length of the relations in the triples of a knowledge graph.
[0028] Specifically, the triples in the first expanded candidate knowledge pool are semantically similar to the triples in the knowledge graph. Triples in the knowledge graph that meet the preset conditions are added to the candidate knowledge pool, resulting in the second expanded candidate knowledge pool.
[0029] Find the triples K in the knowledge graph that satisfy the following formula. s Add to the alternative knowledge pool:
[0030]
[0031] Where Similarity() is the semantic similarity matching function, m sL is the number of triples in the candidate knowledge pool after semantic similarity matching, m′ is the number of triples in the candidate knowledge pool before semantic similarity matching, and L is the number of triples in the candidate knowledge pool before semantic similarity matching. s This is the upper limit set for the number of semantic similarity matches; S se It is the set semantic similarity threshold.
[0032] Specifically, in step S3, the given stance detection target and the different stance categories for that target are combined with all the triples in the candidate knowledge pool to construct auxiliary sentences representing different stance categories, including:
[0033] First, consider the candidate knowledge pool K = {K1, K2, ..., K} n Perform serialization and add a descriptive prefix p. d Obtain the knowledge sequence K′:
[0034] K′=[p d ,h1,r1,t1,h2,r2,t2,…,h n ,r n ,t n ]
[0035] Among them, the descriptive prefix p d It is a preset prefix that makes the serialized triples of the candidate knowledge pool exist in the form of declarative statements. The h, r and t represent the head entity, relation and tail entity respectively, and the subscripts of h, r and t are the sequence numbers of the triples in the candidate knowledge pool.
[0036] The stance detection target and the different stance categories targeting that target are combined to obtain the stance text:
[0037] Sup l =tgt+sfx l
[0038] Where tgt is the text of the position detection target, and sfx l For the text of the l-th position category of the position detection target tgt, Sup l This represents the position text for the l-th position category of the position detection target tgt;
[0039] Then, the knowledge sequence K′ is combined with the text of each stance to construct auxiliary sentences representing different stance categories:
[0040] Supplementary l =Sup l +K′
[0041] Among them, Supplementary lThis is an auxiliary sentence representing the l-th position representation of the position detection target tgt.
[0042] Specifically, the different stance categories for the stance detection target include support, neutrality, and opposition, where support means holding a positive attitude towards the given stance detection target; neutrality means holding a neutral attitude towards the given stance detection target; and opposition means holding a negative attitude towards the given stance detection target.
[0043] The descriptive prefix p d A descriptive statement indicating that something is "known".
[0044] Specifically, in step S4, the given original input text is combined with auxiliary sentences representing different stance categories constructed in step S3 to form input pairs, specifically:
[0045] Input1=[CLS]+[OriginalText]+[SEP]
[0046] Input l =[CLS]+[Supplementary l [SEP]
[0047] Where Input1 is the input of the original text, and [OriginalText] represents the original text; Input l As input for the l-th position representation auxiliary sentence, [Supplementary] l [] indicates the auxiliary sentence representing the l-th position; [CLS] and [SEP] are the start and end markers, respectively.
[0048] Specifically, in step S4, the text detection model outputs the confidence level of the original input text belonging to different stance categories, and the stance category corresponding to the highest confidence level is used as the stance detection result of the original input text. This includes:
[0049] First, the text detection model uses an encoder to encode features for each input pair:
[0050] E l =Encoder(Input1, Input) l )
[0051] Then, the text detection model, using the feature encodings of each input pair as input, utilizes fully connected layers to output the matching degree (logits) of each input pair for each stance category. l :
[0052] logits l =WE l+b
[0053] Where W and b are the weight matrix and bias term of the fully connected layer;
[0054] Subsequently, the text detection model utilizes the matching degree (logits) of each input pair for each stance category. l A matching degree matrix logits is constructed, where the rows and columns represent the input pairs and stance categories, respectively, and the values represent the matching degree of each input pair for each stance category. Using the matching degree matrix as input, Softmax is applied for multi-class classification to obtain the final confidence matrix C.
[0055] C = Softmax(logits)
[0056] Finally, the largest element in the confidence matrix C is selected, and its corresponding stance category is used as the stance detection result for the original input text.
[0057] The beneficial effects of this invention are:
[0058] First, when creating the alternative knowledge pool, entities contained in the stance detection target and the original input text are used as matching alternative entities. These alternative entities are arbitrarily combined to form a set of entity pairs. Through the information in the knowledge graph, the relationship between entities contained in the original text and entities contained in the stance detection target can be extracted. Regardless of whether the stance detection target exists in the original text, the connection between entities contained in the original text and entities contained in the stance detection target can be guaranteed. This serves as auxiliary knowledge for stance detection, enriching the alternative knowledge pool and mitigating the performance loss caused by the externalization of the stance detection target. Second, by matching entity pairs, knowledge in the knowledge graph is filtered to obtain the alternative knowledge pool, improving the utilization rate of knowledge in the knowledge graph and helping to fully utilize this knowledge to improve detection accuracy. Third, the external knowledge contained in the alternative knowledge pool is combined with the stance detection target to form auxiliary sentences with different stances. This avoids directly inserting external knowledge into the original text and reduces the impact of external knowledge on sentence meaning.
[0059] Therefore, the stance detection method based on knowledge graph and text pair classification proposed in this invention improves the utilization rate of knowledge graph, reduces the influence of external knowledge on sentence meaning, and alleviates the performance loss caused by externalizing the stance detection target. Attached Figure Description
[0060] Figure 1 This is a flowchart of the stance detection method based on knowledge graph and text pair classification in an embodiment of the present invention. Detailed Implementation
[0061] This invention aims to propose a stance detection method based on knowledge graphs and text pair classification, with the goal of improving the utilization rate of knowledge graphs, reducing the influence of external knowledge on sentence meaning, and mitigating the performance loss caused by externalizing the stance detection target. The method includes the following steps:
[0062] S1. Given the target of position detection and the original input text, extract the entities contained in both and combine them in any pairwise to form a set of entity pairs.
[0063] S2. Match each entity pair in the entity pair set with the entity pairs in the knowledge graph to obtain the triples in the knowledge graph that match each entity pair in the entity pair set, and construct them as a candidate knowledge pool.
[0064] S3. Combine the given position detection target and the different position categories for that position detection target with all the triples in the candidate knowledge pool to construct auxiliary sentences representing different position categories;
[0065] S4. Combine the given original input text with the auxiliary sentences representing different stance categories constructed in step S3 to form input pairs, and input them into the text detection model respectively. The text detection model outputs the confidence level of the original input text belonging to different stance categories, and the stance category corresponding to the highest confidence level is used as the stance detection result of the original input text.
[0066] First, given a stance detection target and the original input text, the entities contained in both are arbitrarily combined to form entity pairs, which are then matched with knowledge in a knowledge graph to uncover potential relationships. The knowledge graph is used to extract internal connections between entities contained in the original text and between entities contained in the original text and entities contained in the stance detection target. Next, based on external knowledge in a candidate knowledge pool, the stance detection target, and stance categories, auxiliary sentences representing different stance categories are constructed. Finally, these auxiliary sentences representing different stances are combined with the original input text to form text pairs. A text detection model is then used to perform a text pair classification task, generating a confidence matrix to obtain the stance detection result for the original input text.
[0067] The above-mentioned matching of each entity pair in the entity pair set with entity pairs in the knowledge graph can be done using any existing method, such as semantic matching based on a pre-trained model. However, to further improve the utilization rate of knowledge in the knowledge graph, optimally, in step S2, each entity pair in the entity pair set is matched with entity pairs in the knowledge graph to obtain triples in the knowledge graph that match each entity pair in the entity pair set, and these triples are constructed as a candidate knowledge pool, including:
[0068] First, each entity pair in the entity pair set is directly matched with the entity pairs in the knowledge graph to obtain triples in the knowledge graph that match each entity pair in the entity pair set, thus constructing an initial candidate knowledge pool.
[0069] Then, the triples in the initial candidate knowledge pool are fuzzy matched with the triples in the knowledge graph, and the triples in the knowledge graph that meet the preset conditions are added to the candidate knowledge pool to obtain the candidate knowledge pool after the first expansion.
[0070] Next, the triples in the first expanded candidate knowledge pool are semantically similar to the triples in the knowledge graph. Triples in the knowledge graph that meet the preset conditions are added to the candidate knowledge pool to obtain the second expanded candidate knowledge pool.
[0071] The following examples further illustrate the stance detection method based on knowledge graphs and text pair classification of the present invention.
[0072] Example:
[0073] The stance detection method based on knowledge graphs and text pair classification in this embodiment has the following process: Figure 1 As shown, it includes the following implementation steps:
[0074] S1. Extract the set of entity pairs
[0075] In this step, for a given position detection target and the original input text, the entities contained in both are extracted and arbitrarily combined in pairs to form a set of entity pairs in the original input text.
[0076] Entity extraction can employ any existing algorithm. In this embodiment, the pkuseg word segmentation tool is specifically used to annotate entities from the original input text and the target of position detection, and the annotated entities are arbitrarily combined in pairs to form entity pairs.
[0077] S2. Constructing an alternative knowledge pool
[0078] In this step, each entity pair in the entity pair set is matched with the entity pairs in the knowledge graph to obtain triples in the knowledge graph that match each entity pair in the entity pair set, thus constructing a candidate knowledge pool.
[0079] The essence of this step lies in performing initial knowledge screening through entity pair matching, used to mine potential relationships from the original input and extract the internal connections between entities present in the original input. Therefore, in this embodiment, to improve the utilization rate of knowledge in the knowledge graph, it includes three stages:
[0080] In the first stage, the entity names are used to directly match the entities in the knowledge graph. That is, each entity pair in the entity pair set is directly matched with the entity pair in the knowledge graph to obtain triples in which the entity pair in the knowledge graph matches each entity pair in the entity pair set, and these triples are used to construct the initial candidate knowledge pool.
[0081] In the second stage, fuzzy matching is performed using fuzzy functions to expand the candidate knowledge pool for the first time. That is, the triples in the initial candidate knowledge pool are fuzzy matched with the triples in the knowledge graph, and the triples in the knowledge graph that meet the preset conditions are added to the candidate knowledge pool to obtain the candidate knowledge pool after the first expansion.
[0082] In the third stage, semantic similarity matching is performed through a pre-trained model to expand the candidate knowledge pool for the second time. This process involves mining usable knowledge that exists in the knowledge graph in a near-synonymous form. Specifically, the triples in the candidate knowledge pool after the first expansion are semantically similar to the triples in the knowledge graph. Triples in the knowledge graph that meet the preset conditions are added to the candidate knowledge pool to obtain the candidate knowledge pool after the second expansion.
[0083] Specifically, the above process involves directly matching each entity pair in the entity pair set with entity pairs in the knowledge graph to obtain triples in the knowledge graph that match each entity pair in the entity pair set. These triples form the initial candidate knowledge pool.
[0084] For entity pairs T = (t) in the entity pair set i ,t j When the following conditions are met:
[0085] T=(t i ,t j )∈K=(k m ,r,k n ), i≠j, m≠n
[0086] Add the triple K from the knowledge graph to the candidate knowledge pool;
[0087] Where, k m k n r and r represent the head entity, tail entity, and relation in a triplet of a knowledge graph, respectively; t i ,t j These are entities from the given original input text.
[0088] Specifically, the above involves performing fuzzy matching between the triples in the initial candidate knowledge pool and the triples in the knowledge graph. Triples from the knowledge graph that meet the preset conditions are added to the candidate knowledge pool, resulting in the first expanded candidate knowledge pool.
[0089] Find the triples K in the knowledge graph that satisfy the following formula. f Add to the alternative knowledge pool:
[0090]
[0091] Where Fuzz() is the fuzzy matching function, m f L is the number of triples in the candidate knowledge pool after fuzzy matching, m is the number of triples in the candidate knowledge pool before fuzzy matching, and L is the number of triples in the candidate knowledge pool before fuzzy matching. f This is the maximum number of fuzzy matches set, S. f It is the fuzzy matching similarity threshold.
[0092] Fuzzy matching similarity threshold S f The setting is affected by the knowledge graph parameters. In this embodiment, its calculation method is as follows:
[0093]
[0094] Among them, l t It is the average length of triples in a knowledge graph, l e It is the average length of entities in a triplet in a knowledge graph, l r It is the average length of the relations in the triples of a knowledge graph.
[0095] Specifically, the above-mentioned triples in the first expanded candidate knowledge pool are semantically similar to the triples in the knowledge graph. Triples in the knowledge graph that meet the preset conditions are added to the candidate knowledge pool to obtain the second expanded candidate knowledge pool, which is as follows:
[0096] Find the triples K in the knowledge graph that satisfy the following formula. s Add to the alternative knowledge pool:
[0097]
[0098] Where Similarity() is the semantic similarity matching function, m s L is the number of triples in the candidate knowledge pool after semantic similarity matching, m′ is the number of triples in the candidate knowledge pool before semantic similarity matching, and L is the number of triples in the candidate knowledge pool before semantic similarity matching. s This is the upper limit set for the number of semantic similarity matches; S se This is the set semantic similarity threshold, which can be any positive real number less than 1, with a default value of 0.8.
[0099] S3. Constructing auxiliary sentences
[0100] In this step, the given stance detection target and the different stance categories for that target are combined with all the triples in the candidate knowledge pool to construct auxiliary sentences representing different stance categories.
[0101] To elaborate further, this step includes:
[0102] First, consider the candidate knowledge pool K = {K1, K2, ..., K} n Perform serialization and add a descriptive prefix p. d Obtain the knowledge sequence K′:
[0103] K′=[p d ,h1,r1,t1,h2,r2,t2,…,h n ,r n ,t n ]
[0104] Among them, the descriptive prefix p d It is a preset prefix that makes the serialized triples of the candidate knowledge pool exist in the form of declarative statements. The h, r and t represent the head entity, relation and tail entity respectively, and the subscripts of h, r and t are the sequence numbers of the triples in the candidate knowledge pool.
[0105] The stance detection target and the different stance categories targeting that target are combined to obtain the stance text:
[0106] Sup l =tgt+sfx l
[0107] Where tgt is the text of the position detection target, and sfx l For the text of the l-th position category of the position detection target tgt, Sup l This represents the position text for the l-th position category of the position detection target tgt;
[0108] Then, the knowledge sequence K′ is combined with the text of each stance to construct auxiliary sentences representing different stance categories:
[0109] Supplementary l =Sup l +K′
[0110] Among them, Supplementary l This is an auxiliary sentence representing the l-th position representation of the position detection target tgt.
[0111] Different stance categories for the stance detection target typically include support, opposition, and neutrality, but can also be further subdivided into other types based on support, opposition, and neutrality. In this embodiment, the different stance categories for the stance detection target include support, neutrality, and opposition, where support refers to holding a positive attitude towards the given stance detection target; neutrality refers to holding a neutral attitude towards the given stance detection target; and opposition refers to holding a negative attitude towards the given stance detection target.
[0112] The above descriptive prefix p d The purpose is to make the knowledge sequence resemble a sentence; therefore, it can be configured according to specific needs, such as a descriptive prefix p. d A descriptive statement that indicates "known" can specifically include statements that express "to the best of our knowledge," "known conditions include," and similar meanings.
[0113] Therefore, specifically in this embodiment:
[0114] First, consider the candidate knowledge pool K = {K1, K2, ..., K} n Perform serialization and add a descriptive prefix p. d Obtain the knowledge sequence K′:
[0115] K′=[p d ,h1,r1,t1,h2,r2,t2,…,h n ,r n ,t n ]
[0116] Among them, the descriptive prefix p d As far as we know;
[0117] The stance detection target and the different stance categories targeting that target are combined to obtain the stance text:
[0118] Sup l =tgt+sfx l
[0119] Among them, sfx l Including sfx1, sfx2, and sfx3, which are suffixes indicating a supporting stance. F The suffix "Suffix" indicates a neutral stance. N The suffix "Suffix" indicates an opposing stance. A Sup lSup1, Sup2, and Sup3 represent the stance texts Favor (for those in favor), Neutral (for those in neutrality), and Against (for those in opposition), respectively. Therefore, the formula for the stance texts can also be expressed as:
[0120]
[0121] Then, the knowledge sequence K′ is combined with the text of each stance to construct auxiliary sentences representing different stance categories:
[0122] Supplementary l =Sup l +K′
[0123] Among them, Supplementaryi l This represents the auxiliary sentence for the l-th position representation of the position detection target tgt, and can be specifically represented as:
[0124]
[0125] Among them, Supplementary F Supplementary sentence sequence indicating a supporting stance; N Supplementary sentence sequence indicating a neutral stance; A A sequence of auxiliary sentences that express opposition.
[0126] S4, Stance Detection
[0127] In this step, firstly, the given original input text is combined with auxiliary sentences representing different stance categories constructed in step S3 to form input pairs; then, the input pairs are input to the text detection model, and the text detection model outputs the confidence level of the original input text belonging to different stance categories, and the stance category corresponding to the highest confidence level is used as the stance detection result of the original input text.
[0128] The above-mentioned combination of the given original input text with auxiliary sentences representing different stance categories constructed in step S3 to form input pairs is as follows:
[0129] Input1=[CLS]+[OriginalText]+[SEP]
[0130] Input l =[CLS]+[Supplementary l [SEP]
[0131] Where Input1 is the input of the original text, and [OriginalText] represents the original text; Input l As input for the l-th position representation auxiliary sentence, [Supplementary] l [] indicates the auxiliary sentence representing the l-th position; [CLS] and [SEP] are the start and end markers, respectively.
[0132] The text detection model described above can use any existing text classification and detection model, such as LSTM (Long Short-Term Memory Network Classifier), Transformer, etc.
[0133] In this embodiment, to simplify the network structure, a fully connected network is used. Specifically, the text detection model outputs the confidence scores of the original input text belonging to different stance categories, and the stance category corresponding to the highest confidence score is used as the stance detection result of the original input text. This includes:
[0134] First, the text detection model uses an encoder to encode features for each input pair:
[0135] E l =Encoder(Input1, Input) l )
[0136] Then, the text detection model, using the feature encodings of each input pair as input, utilizes fully connected layers to output the matching degree (logits) of each input pair for each stance category. l :
[0137] logits l =WE l +b
[0138] Where W and b are the weight matrix and bias term of the fully connected layer;
[0139] Subsequently, the text detection model utilizes the matching degree (logits) of each input pair for each stance category. l A matching degree matrix logits is constructed, where the rows and columns represent the input pairs and stance categories, respectively, and the values represent the matching degree of each input pair for each stance category. Using the matching degree matrix as input, Softmax is applied for multi-class classification to obtain the final confidence matrix C.
[0140] C = Softmax(logits)
[0141] Finally, the largest element in the confidence matrix C is selected, and its corresponding stance category is used as the stance detection result for the original input text.
[0142] Experimental verification:
[0143] Experimental verification was conducted to validate the detection performance of the present invention.
[0144] This experiment uses the method described in the above embodiment. In the experiment, the upper limit of the number of fuzzy matches is L. f The upper limit L of the number of semantic similarity matches s All values were set to 3. The learning rate was 1e-4, the batch size was 16, and the epochs number was 5. The baseline models for comparison were Roberta-wwm-large-ext from the Harbin Institute of Technology-iFlytek Lab, and K-Bert and K-Bert-MSD, which replaced Bert-base-Chinese. The dataset used was the NLPCC2016 Weibo stance detection dataset, and CnDbpedia from the Fudan University Knowledge Factory Lab was used as the knowledge graph. The training set included 3000 data points, and the test set contained 1000 data points. The stance detection targets were iPhone SE, setting off firecrackers during the Spring Festival, counter-terrorism operations, the two-child policy, and the Shenzhen ban on motorcycles and electric vehicles. Stances were divided into three categories: support, opposition, and neutral, with each stance category distributed in a 2:2:1 ratio in the dataset.
[0145] This experiment uses accuracy and F1-Score to measure the performance of stance detection. The performance comparison of stance detection on the NLPCC2016 Weibo stance detection dataset obtained through the experiment is shown in Table 1.
[0146] Table 1: Performance Comparison on the NLPCC2016 Weibo Stance Detection Dataset
[0147] Roberta-wwm-large-ext 0.838 0.822 K-Bert 0.851 0.831 K-Bert-MSD 0.867 0.845 This invention 0.891 0.873
[0148] Experimental results show that the method of the present invention outperforms Roberta-wwm-large-ext, K-Bert, and K-Bert-MSD by 9.73%, 5.72%, and 3.83% in accuracy, respectively; and by 12.98%, 7.61%, and 5.03% in F1-Score, respectively. Therefore, the method of the present invention has significant performance advantages in position detection.
[0149] Finally, it should be noted that the above embodiments are merely preferred embodiments and are not intended to limit the present invention. It should be pointed out that those skilled in the art can make various modifications, equivalent substitutions, and improvements without departing from the spirit and scope of the claims, and all such modifications, substitutions, and improvements should be included within the scope of protection of the present invention.
Claims
1. A position detection method based on knowledge graphs and text pair classification, characterized in that, Includes the following steps: S1. Given the target of position detection and the original input text, extract the entities contained in both and combine them in any pairwise to form a set of entity pairs. S2. Match each entity pair in the entity pair set with the entity pairs in the knowledge graph to obtain the triples in the knowledge graph that match each entity pair in the entity pair set, and construct them as a candidate knowledge pool. S3. Combine the given position detection target and the different position categories for that position detection target with all the triples in the candidate knowledge pool to construct auxiliary sentences representing different position categories; S4. Combine the given original input text with the auxiliary sentences representing different stance categories constructed in step S3 to form input pairs, and input them into the text detection model respectively. The text detection model outputs the confidence level of the original input text belonging to different stance categories, and the stance category corresponding to the highest confidence level is used as the stance detection result of the original input text. In step S3, the given stance detection target and the different stance categories for that target are combined with all the triples in the candidate knowledge pool to construct auxiliary sentences representing different stance categories, including: First, the alternative knowledge pool Perform serialization and add a descriptive prefix. Obtain knowledge sequence : Among them, descriptive prefixes It is a preset prefix that makes the serialized triples of the candidate knowledge pool exist in the form of declarative statements. The h, r and t represent the head entity, relation and tail entity respectively, and the subscripts of h, r and t are the sequence numbers of the triples in the candidate knowledge pool. The stance detection target and the different stance categories targeting that target are combined to obtain the stance text: in, The text for the purpose of position detection. To target the position detection objective The Text for each position category, Indicates the target of position detection The Position text for each position category; Then, the knowledge sequence By combining these sentences with texts representing different stances, auxiliary sentences representing different stance categories can be constructed: in, Indicates the target of position detection The An auxiliary sentence representing a stance.
2. The position detection method based on knowledge graph and text pair classification as described in claim 1, characterized in that, In step S2, each entity pair in the entity pair set is matched with an entity pair in the knowledge graph to obtain triples in the knowledge graph that match each entity pair in the entity pair set. These triples are then used to construct a candidate knowledge pool, including: First, each entity pair in the entity pair set is directly matched with the entity pairs in the knowledge graph to obtain triples in the knowledge graph that match each entity pair in the entity pair set, thus constructing an initial candidate knowledge pool. Then, the triples in the initial candidate knowledge pool are fuzzy matched with the triples in the knowledge graph, and the triples in the knowledge graph that meet the preset conditions are added to the candidate knowledge pool to obtain the candidate knowledge pool after the first expansion. Next, the triples in the first expanded candidate knowledge pool are semantically similar to the triples in the knowledge graph. Triples in the knowledge graph that meet the preset conditions are added to the candidate knowledge pool to obtain the second expanded candidate knowledge pool.
3. The position detection method based on knowledge graph and text pair classification as described in claim 2, characterized in that, Each entity pair in the entity pair set is directly matched with an entity pair in the knowledge graph to obtain triples in the knowledge graph that match each entity pair in the entity pair set. These triples form the initial candidate knowledge pool. For entity pairs in the entity pair set When the following conditions are met: Triples in knowledge graphs Add to the alternative knowledge pool; in, 、 、 These are the head entity, tail entity, and relation in a triplet of a knowledge graph. These are entities from the given original input text.
4. The position detection method based on knowledge graph and text pair classification as described in claim 2, characterized in that, The triples in the initial candidate knowledge pool are fuzzily matched with the triples in the knowledge graph. Triples in the knowledge graph that meet the preset conditions are added to the candidate knowledge pool to obtain the first expanded candidate knowledge pool, specifically: Find the triples in the knowledge graph that satisfy the following formula Add to the alternative knowledge pool: in, ( ) represents the fuzzy matching function. It represents the number of triples in the candidate knowledge pool after fuzzy matching. It represents the number of triples in the candidate knowledge pool before fuzzy matching. This is the maximum number of fuzzy matches that can be set. It is the fuzzy matching similarity threshold. It's a triplet. It is a knowledge graph.
5. The position detection method based on knowledge graph and text pair classification as described in claim 4, characterized in that, Fuzzy matching similarity threshold The calculation method is as follows: in, It is the average length of triples in a knowledge graph. It is the average length of entities in a triplet in a knowledge graph. It is the average length of the relations in the triples of a knowledge graph.
6. The position detection method based on knowledge graph and text pair classification as described in claim 2, characterized in that, The triples in the first expanded candidate knowledge pool are semantically similar to the triples in the knowledge graph. Triples in the knowledge graph that meet the preset conditions are added to the candidate knowledge pool to obtain the second expanded candidate knowledge pool, specifically: Find the triples in the knowledge graph that satisfy the following formula Add to the alternative knowledge pool: in, ( ) represents the semantic similarity matching function. It is the number of triples in the candidate knowledge pool after semantic similarity matching. It represents the number of triples in the candidate knowledge pool before semantic similarity matching. This is the upper limit set for the number of semantic similarity matches; It is a set semantic similarity threshold. It's a triplet. It is a knowledge graph.
7. A position detection method based on knowledge graphs and text pair classification as described in any one of claims 1 to 6, characterized in that, The different stance categories for the target of the stance detection include support, neutrality, and opposition, wherein support refers to holding a positive attitude towards the given target of the stance detection; neutrality refers to holding a neutral attitude towards the given target of the stance detection; and opposition refers to holding a negative attitude towards the given target of the stance detection. The descriptive prefix A descriptive statement indicating that something is "known".
8. A position detection method based on knowledge graph and text pair classification as described in any one of claims 1 to 6, characterized in that, In step S4, the given original input text is combined with the auxiliary sentences representing different stance categories constructed in step S3 to form input pairs, specifically: in, The input is the original text. Represents the original text; For the first Input of a position representation auxiliary sentence, Indicates the first A supporting sentence representing a stance; and These are the start and end markers, respectively.
9. The position detection method based on knowledge graph and text pair classification as described in claim 8, characterized in that, In step S4, the text detection model outputs the confidence scores of the original input text belonging to different stance categories, and the stance category corresponding to the highest confidence score is used as the stance detection result of the original input text. Specifically, this includes: First, the text detection model uses an encoder to encode features for each input pair: Then, the text detection model, using the feature encodings of each input pair as input, utilizes fully connected layers to output the matching degree of each input pair for each stance category. : in, and These are the weight matrix and bias terms for the fully connected layer; Next, the text detection model uses the matching degree of each input pair for each stance category. Construct a matching degree matrix The rows and columns of the matching degree matrix represent the input pairs and stance categories, respectively, and its value is the matching degree of each input pair for each stance category. Using the matching degree matrix as input, Softmax is applied for multi-class classification to obtain the final confidence matrix. : Finally, choose the confidence matrix. The largest element in the original input text is used as the position detection result, and its corresponding position category is taken as the position category of the original input text.