Method, system and equipment for extracting relation triple in text content

By using a clustering-aligned context learning method, the relation triplet extraction task is decomposed into multiple subtasks. By using a large language model for stepwise reasoning, the problem of insufficient model generalization ability in existing technologies is solved, and efficient and reliable relation triplet extraction is achieved.

CN121808031APending Publication Date: 2026-04-07UNIV OF SCI & TECH BEIJING
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-16
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

Existing relation triple extraction methods based on large language models ignore the inherent logical connection between entity recognition and relation extraction, resulting in a lack of systematic reasoning. Furthermore, the example retrieval strategy fails to fully utilize the deep semantic clustering structure between the training and test sets, affecting the model's generalization ability and reliability in complex contexts.

Method used

High-dimensional vectors are generated through semantic encoding, clustering and alignment are performed, and the task of extracting relation triples is decomposed into multiple sequential subtasks. Structured prompts guide the large language model to reason step by step. By combining clustering and alignment retrieval mechanisms and quantization techniques, dynamic semantic matching and fast retrieval between the training and test sets are achieved.

Benefits of technology

It significantly improves the model's generalization ability in complex contexts, supports efficient knowledge transfer across domains and out-of-distribution scenarios, reduces computational resource consumption, and improves the reliability and practicality of the output results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121808031A_ABST
    Figure CN121808031A_ABST
Patent Text Reader

Abstract

The invention provides a method, system and equipment for extracting relation triads in text content, and the method comprises the steps: carrying out semantic coding on texts of a training sample set and a test sample set, and generating a high-dimensional vector; carrying out independent clustering on the coded high-dimensional vector and dividing samples; calculating a clustering center and realizing clustering alignment of the training set and the test set; decomposing a relation triple extraction task into a plurality of sequential sub-tasks, and guiding large language model reasoning through a structured cue word; similar samples are retrieved from the aligned training clusters of the test samples, and thinking chain examples are generated; a test sample, a relation label set and a clustering example embedding cue word template are input into a large model for reasoning; and analyzing the output and verifying the logic consistency. According to the scheme, the accuracy, the recall rate and the generalization ability of relation triple extraction are remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of natural language processing technology, and in particular to a method, system, and apparatus for extracting relation triples from text content based on clustering-aligned context learning. Background Technology

[0002] Relation triple extraction (RTE) is a core technology for building knowledge graphs and supporting intelligent question-answering systems. It aims to extract structured knowledge in the form of (entity, relation, entity) from text. Current methods based on large language models suffer from several bottlenecks. First, existing methods treat RTE as a single text generation task, ignoring the inherent logical connection between entity recognition and relation extraction. This results in a lack of systematic reasoning and makes it easy to miss entities and misjudge relations.

[0003] Secondly, traditional example retrieval strategies rely on simple vector similarity matching, which fails to fully utilize the deep semantic clustering structure between the training and test sets, resulting in low-quality retrieved examples and affecting the model's generalization ability in complex contexts.

[0004] In addition, existing methods generally suffer from problems such as opaque reasoning processes and low reliability of results, which limit their reliability in practical applications. Summary of the Invention

[0005] To address at least some of the problems existing in the prior art, this invention provides a method, system, and apparatus for extracting relation triples from text content based on clustering alignment context learning, and specifically provides the following technical solutions: In a first aspect, the present invention provides a method for extracting relation triples from text content, the method comprising: Step 1: Semantically encode the text in the training and test sample sets to generate high-dimensional training and test sample vectors. Step 2: Perform independent clustering on the training sample vector and the test sample vector, dividing the samples into M clusters to obtain the training cluster and the test cluster; Step 3: Calculate the center vector of each cluster, and align the training clusters and test clusters through average pooling to establish a one-to-one mapping relationship between the training clusters and test clusters; Step 4: Decompose the relation triple extraction task into multiple sequential subtasks, and guide the large language model to reason step by step through structured prompts; the subtasks include entity extraction, relation extraction and triple construction; Step 5: For the current test sample, retrieve the Top-K similar samples from its aligned training clusters and generate a thought chain example; Step 6: Embed the test samples, relation tag set, and thought chain examples into the constructed prompt word template to obtain prompt words; input the prompt words into the Big Prophecy model for inference to obtain the model output; Step 7: Perform structured parsing on the model output, extract the data corresponding to the entity, relation, and triple fields, and perform logical consistency verification.

[0006] Preferably, in step 1, the semantic encoding method is as follows: the text is converted into a high-dimensional vector using a pre-trained semantic text encoding model; the time and resources consumed in vector generation are recorded. The generated vectors are normalized; the normalized vectors are then dimensionality-reduced, and an index is created for the dimensionality-reduced vectors to obtain the training sample vectors and test sample vectors.

[0007] Preferably, step 2 specifically includes: Step 21: Initialize cluster centers and determine the number of clusters M: Calculate the sum of intra-cluster variances for different M values, and select the inflection point as the optimal M value; Step 22: Perform clustering on the training set vector and the test set vector respectively, record the center coordinates, number of samples and index of each cluster, and obtain the cluster label; Step 23: Serialize the clustering results into JSON format to obtain training clusters and test clusters; the training clusters and test clusters should include at least cluster labels, cluster center vectors and sample mapping tables.

[0008] Preferably, step 3 further includes: Step 31: Perform average pooling on the vectors within each cluster. For coefficient clusters with a small number of samples, use the median of the samples instead of the average vector. Step 32: Calculate the Euclidean distance matrix D between each cluster center of the training cluster and each cluster center of the test cluster. ij , where i is the training cluster index and j is the test cluster index; set a distance threshold to delete cluster pairs whose distance is greater than the distance threshold; Step 33: Solve for the minimum total distance matching, establish a one-to-one mapping relationship between the training cluster and the test cluster, and store the matching results as an alignment mapping table; Step 34: Serialize the alignment mapping table into JSON format.

[0009] Preferably, in step 32, the distance threshold is determined as follows: the mean μ and standard deviation σ of all M×M distance values ​​are calculated, and the dynamic distance threshold is set as: d max =μ+ k·σ, where k is an adjustable coefficient.

[0010] Preferably, in step 4, the entity extraction method is as follows: the large language model obtains the entity list using boundary detection based on the prompt word template; The relation extraction method is as follows: based on the entity list, combined with the prompt word template, the relation is extracted from the predefined relation tag set through the attention mechanism to obtain the relation list; The method for constructing triples is to integrate the entity list and the relation list to generate a structured list of triples.

[0011] Preferably, step 4 further includes: verifying entity overlap and relationship legitimacy through a consistency check.

[0012] Preferably, step 5 specifically includes: Step 51: Calculate the cosine similarity between the test sample vector and each sample in the aligned training cluster corresponding to the mapping. Step 52: Select the Top-K most similar samples from the aligned training clusters and filter out the unaligned samples; Step 53: Generate an example for each retrieved similar training sample. The example includes a list of entities, a list of relations, and a list of triples corresponding to the sample. Step 54: Group the examples according to their clustering source, add labels, and insert cluster-aware statements to form a mind chain example.

[0013] Preferably, step 6 specifically includes: Step 61: Build a prompt word template; Step 62: Insert the thought chain example into the prompt word template by clustering, and add cluster-aware statements to provide contextual information. The prompt words are now complete. Step 63: Configure the large language model; Step 64: Input the completed prompt words into the large language model, perform three-step reasoning, and obtain the model output.

[0014] Preferably, step 7 further includes: Step 71: Use regular expressions to match the entity list and the triple list; Step 72: Check the consistency of entities and relationships; Step 73: Filter out low-confidence prediction results to obtain the parsed triples; Step 74: Generate a verification report based on the parsed triples.

[0015] Preferably, after step 7, the model output result is evaluated, specifically as follows: The model was evaluated on multiple datasets to test the impact of different parameters, including the number of clusters M and the number of examples K. Evaluation metrics include: Accuracy = Number of correct predictions / Total number of predictions; Recall = Number of correctly predicted items / Total number of labeled items; F1 score = 2 × precision × recall / (precision + recall); Accuracy = Number of correct predictions / Total number of samples; The evaluation criteria are as follows: for exact matches, the triples must be completely identical to the annotations; for partial matches or partially overlapping relationships, the Jaccard similarity threshold is used for determination.

[0016] Secondly, the present invention also provides a system for extracting relation triples from text content, the system comprising: The semantic encoding module performs semantic encoding on the text in the training and test sample sets to generate high-dimensional training and test sample vectors. The clustering module performs independent clustering on the training sample vector and the test sample vector, dividing the samples into M clusters to obtain the training cluster and the test cluster; The alignment module calculates the center vector of each cluster and aligns the training clusters and test clusters through average pooling, establishing a one-to-one mapping relationship between the training clusters and test clusters; The extraction module decomposes the relation triple extraction task into multiple sequential subtasks and guides the large language model to reason step by step through structured prompts; the subtasks include entity extraction, relation extraction and triple construction. The prompt word construction module retrieves the Top-K similar samples from the aligned training clusters mapped to the current test sample and generates a thought chain example. And by embedding test samples, relationship tag sets, and thought chain examples into the constructed prompt word template, prompt words are obtained; The large language model module performs inference based on the prompt words obtained from the prompt word construction module to obtain the model output; The structured parsing module performs structured parsing on the model output, extracts the data corresponding to entity, relation, and triple fields, and performs logical consistency verification.

[0017] Preferably, the system further includes an evaluation module for evaluating the model on multiple datasets and testing the impact of different parameters, including the number of clusters M and the number of examples K.

[0018] Thirdly, the present invention also provides an apparatus for extracting relation triples from text content, the apparatus including a processor, a memory and a bus; the processor calls instructions in the memory to execute the method for extracting relation triples from text content as described above.

[0019] By adopting the above technical solution, the present invention has the following beneficial effects: This solution structures complex tasks through Task Decomposition-CoT (TD-CoT), guiding large language models through step-by-step reasoning and effectively avoiding entity omissions and relationship misjudgments. Combined with Cluster Alignment Retrieval (CARD) mechanism, it dynamically adapts semantic associations, enhancing the semantic relevance and diversity of example samples and significantly improving the model's generalization ability in complex contexts. The cluster alignment mechanism enables dynamic semantic matching between the training and test sets, supporting efficient knowledge transfer across domains and out-of-distribution (OOD) scenarios. Finally, by combining quantization techniques and Faiss indexing, it achieves rapid retrieval and processing of large-scale vector data. This solution significantly reduces computational resource consumption and supports the efficient deployment of models with hundreds of billions of parameters. Through structured prompt word templates and step-by-step inference paths, it clearly displays the intermediate results of entity extraction, relation extraction, and triple construction, supporting error tracing and logical verification. Post-processing rules and consistency checking mechanisms effectively filter low-confidence predictions, improving the reliability and usability of the output results. This solution can be adapted to various large language models (such as Llama and Qwen series) without training, supports multilingual and cross-domain text processing, and can be widely applied to natural language processing scenarios such as knowledge graph construction, intelligent question answering, and semantic search. Attached Figure Description

[0020] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0021] Figure 1 A flowchart of a relation triple extraction system based on clustering alignment context learning is provided in this embodiment of the invention; Figure 2 This is a flowchart of step 1 in an embodiment of the present invention; Figure 3 This is a flowchart illustrating step 2 in an embodiment of the present invention. Figure 4 This is a flowchart illustrating step 3 in an embodiment of the present invention. Figure 5 This is a flowchart illustrating step 4 in an embodiment of the present invention. Figure 6 This is a flowchart of step 5 in an embodiment of the present invention; Figure 7 This is a flowchart illustrating step 6 in an embodiment of the present invention. Figure 8 This is a flowchart illustrating step 7 in an embodiment of the present invention. Figure 9 This is a flowchart illustrating step 8 in an embodiment of the present invention. Figure 10 This is a diagram of a relation triplet extraction system based on clustering alignment context learning, provided in an embodiment of the present invention. Detailed Implementation

[0022] The technical solution of the present invention will now be clearly and completely described with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0023] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0024] Those skilled in the art should understand that the following specific embodiments or implementation methods are a series of optimized configurations listed to further explain the specific content of the invention. These configuration methods can be combined or used in conjunction with each other, unless the invention explicitly states that some or a specific embodiment or implementation method cannot be associated with or used in conjunction with other embodiments or implementation methods. Furthermore, the following specific embodiments or implementation methods are merely optimized configurations and are not intended to limit the scope of protection of the invention.

[0025] Existing relation triple extraction methods based on large-scale language models often treat the task as a single text generation process, neglecting the sub-task structure of entity extraction and relation extraction. Furthermore, their example retrieval strategies are static and simple, failing to fully utilize the semantic clustering associations between training and test samples, resulting in low inference accuracy and poor generalization ability. To address these shortcomings, this invention provides a method, system, and apparatus for extracting relation triples from text content in natural language processing based on clustering-aligned context learning. The following detailed explanation of specific implementation methods further illustrates this invention.

[0026] Example 1: like Figure 1As shown, this embodiment details a method for extracting relation triples based on clustering alignment context learning. This method achieves efficient and accurate relation triple extraction through core steps such as semantic encoding, clustering alignment, Task Decomposition-CoT (TD-CoT), and Cluster Alignment Retrieval (CARD), including the following steps: Step 1: Use the Sentence-BERT model to semantically encode the text in the training and test sample sets, generating high-dimensional vector representations, i.e., generating high-dimensional training and test sample vectors. This step ensures the richness and consistency of semantic information, providing a foundation for subsequent clustering and retrieval.

[0027] Furthermore, such as Figure 2 As shown, step 1 specifically includes: Step 11: Clean and standardize the input text (including training and test samples). Use regular expressions (e.g., Python's `re.sub(r'[^\w\s]', '', text)`) to remove special characters, redundant spaces, and irrelevant symbols. Use UTF-8 encoding to avoid encoding errors. For mixed Chinese and English text, use natural word segmentation with spaces for English and the jieba word segmentation tool (configured with precise mode and a custom dictionary, including domain terms such as "entity" and "relationship") for Chinese. When processing long texts, use a sliding window mechanism (window size 512 tokens, 10% overlap) to segment the text and prevent information loss.

[0028] Step 12: Load the Sentence-BERT pre-trained model (e.g., all-mpnet-base-v2), which is based on the Transformer architecture and has an output dimension of 768. Configure the batch size to 32, utilize GPU (e.g., NVIDIA A40) for accelerated computation, implemented using PyTorch or the Hugging Face library, and set device='cuda' to optimize efficiency. Fix the model parameters and use pre-trained weights to ensure the stability of the semantic representation. Verify input-output dimension matching during initialization (e.g., limit the input text length to ≤512 tokens).

[0029] Step 13: Input the preprocessed text in batches into a pre-trained semantic text encoding model (also known as a text encoder, such as Sentence-BERT) to generate 768-dimensional floating-point vectors. The "optimization of cosine similarity calculation" here is reflected in the model's design goals and subsequent vector processing, as detailed below: 1. Model-level optimization (semantic space construction): The selected model (such as Sentence-BERT) can employ objective functions such as contrastive learning or natural language inference (NLI) during the training phase. The core of these training methods is to directly optimize the vector space structure, ensuring that the cosine similarity of semantically similar sentence pairs (e.g., "Beijing is the capital of China" and "The capital of China is Beijing") approaches 1, while the cosine similarity of semantically unrelated sentence pairs approaches -1. Therefore, the model parameters themselves internalize the semantic metric based on cosine similarity.

[0030] 2. Vector Post-processing Optimization (Normalization): Immediately after the text encoding model generates the original vectors, L2 normalization is performed. This process is a key step in optimizing cosine similarity calculation, and its calculation is as follows: For any generated vector... First, calculate its L2 norm (i.e., modulus): Then divide the vector by its magnitude to obtain the normalized vector. : After L2 normalization, the magnitude of all vectors is scaled to 1. At this point, any two normalized vectors... and The calculation of cosine similarity simplifies to their dot product: , where A and B represent two original high-dimensional vectors to be compared. This greatly simplifies the calculation and eliminates the interference of the absolute length of the vectors (which may be affected by the text length or word frequency) on the similarity measurement, ensuring that the similarity result purely reflects the difference in vector direction, that is, the difference in semantics.

[0031] Step 14: Optionally, use PCA dimensionality reduction to reduce the dimension of the normalized vector, for example, from 768 dimensions to 256 dimensions, to save storage and computational resources. The processed vector is stored in HDF5 format and a Faiss index is created to support fast retrieval.

[0032] Step 2: Use the K-Means algorithm to independently cluster the encoded training sample vectors and test sample vectors, dividing the training set samples into M training clusters and the test set samples into M test clusters, with M dynamically adjusted according to the characteristics of the dataset. Furthermore, such as Figure 3 As shown, step 2 specifically includes: Step 21: Initialize cluster centers using the k-means++ method to avoid local optima. Set the maximum number of iterations to 100, the tolerance to 1e-4, and the distance metric to Euclidean distance. The number of clusters M is determined by calculating the sum of the intra-cluster variances of the training and test sets under different M values, and selecting the inflection point of each as the optimal M value.

[0033] Step 22: Using the KMeans class from the Scikit-learn library, set n_init=10 to increase initial diversity. Perform clustering on the training and test set vectors respectively, recording the center coordinates, number of samples, and index of each cluster. The clustering process minimizes the within-cluster variance based on Euclidean distance, and outputs the cluster labels.

[0034] Step 23: Serialize the training clustering results and test clustering results into JSON format, including cluster labels and center vectors, to generate a cluster distribution report (such as cluster size statistics) for visualization analysis.

[0035] Step 3: Calculate the center vector of each cluster and align the training and test clusters based on Euclidean distance using average pooling to establish a one-to-one mapping relationship between the training and test clusters.

[0036] Furthermore, such as Figure 4 As shown, step 3 specifically includes: Step 31: Perform average pooling on all vectors within each cluster. In this embodiment, the pooling method is as follows: Where n represents the total number of sample vectors contained in the cluster. The vector representing the i-th sample belonging to the cluster (i.e., the normalized high-dimensional vector generated in step 1) is called `center`, which is the calculated center vector (or centroid vector) of the cluster. For sparse clusters with fewer than 5 samples, the median is used instead of the mean to enhance robustness.

[0037] Step 32: Calculate the Euclidean distance matrix D between all training cluster centers and test cluster centers. ij , where i is the training cluster index and j is the test cluster index. To filter irrelevant cluster pairs, a dynamic distance threshold is used. In this embodiment, the threshold d... max The distance matrix D is automatically calculated based on its statistical properties. The specific method is as follows: Calculate the mean μ and standard deviation σ of all M×M distance values. The dynamic distance threshold is set as: d max = μ + k·σ, where k is an adjustable coefficient, typically ranging from 0.5 to 1.5. In this embodiment, k = 1.0 is chosen; traversing the distance matrix D, the following will satisfy D ij >d maxCluster pairs (i,j) are removed from the subsequent matching candidate set.

[0038] Step 33: Use the Hungarian algorithm to solve for the minimum total distance matching, establishing a one-to-one mapping relationship between the training cluster and the test cluster. The matching results are stored as an alignment mapping table. In this embodiment, the mapping table format is: {train_cluster_i: test_cluster_j}. Specifically, firstly, the Euclidean distance matrix D obtained in step 32, which may have undergone threshold filtering, is... ij As the cost matrix, the following steps are then performed: 1) Row and column reduction: Subtract the minimum value from each row and column of the matrix to ensure that each row and column contains at least one zero element. This step aims to initially find potential matching pairs; 2) Trial assignment and matrix adjustment: Cover all zero elements with the minimum number of lines. If the number of lines is less than the number of clusters M, find the minimum value among the uncovered elements, perform addition and subtraction operations to add new zero elements, and repeat this process until a complete match is found; 3) Determine the optimal mapping: Finally, select M zero elements located in different rows and columns from the matrix. Their coordinates (i,j) constitute the optimal one-to-one mapping from training cluster i to test cluster j. This mapping ensures that the sum of the cumulative distances of all matching pairs is minimized.

[0039] Step 34: Serialize the alignment mapping table into a JSON file and integrate it into the retrieval module to support dynamic access. Preferably, the specific serialization steps in this step are as follows: The alignment mapping table is usually represented in memory as a dictionary or similar structure, where the key is the index of the training cluster (in integer or string form), and the value is the index of the mapped test cluster. For example: {0: 2, 1: 5, 2: 0, ...} indicates that training cluster 0 is aligned with test cluster 2, training cluster 1 is aligned with test cluster 5, and so on; use a built-in library of the programming language (such as Python's json library) to write the above dictionary object into a text file. The generated file content is shown below, and this format is easy for humans to read and machines to parse: {"0": "2", "1": "5", "2": "0"} The above integration process aims to enable the retrieval module (responsible for similar sample retrieval in step 5) to dynamically read and use alignment mapping information. During retrieval module initialization, or before performing a retrieval operation, the module loads the aforementioned JSON file from a specified path and parses it back into a dictionary object in memory.

[0040] During integration, the retrieval module expects the JSON file to be a simple key-value pair object. The keys and values ​​are typically strings of numbers, representing indices for the training and test clusters, respectively. Internally, the module ensures correct index type conversions (e.g., from string to integer) for subsequent queries. When a test sample needs to be processed, the retrieval module first determines the test cluster index j to which the sample belongs via step 2. Then, by querying the loaded dictionary, it finds the corresponding training cluster index i = map[j]. Finally, the module performs Top-K similar sample retrieval only within the training cluster with index i. This achieves dynamic and precise retrieval based on cluster alignment relationships.

[0041] Step 4: Decompose the relation triple extraction task into three sequential sub-tasks, and guide the large language model to reason step by step using structured cue words.

[0042] Furthermore, such as Figure 5 As shown, step 4 specifically includes: Step 41, Entity Extraction: The prompt template is: "First step: Identify all entities in the sentence. Output in the form [Entity1, Entity2,...]". For example, for the sentence "Parishosted the 2024 Summit", the model outputs a list of entities ["Paris", "2024Summit"] guided by the prompt. In this process, refined prompt instructions guide the large language model to simulate boundary detection, ensuring the completeness and accuracy of entities. Specifically, the prompt explicitly requires the model to identify entities that are continuous word sequences in the original text, preventing the model from generating words not present in the text or breaking up a complete entity. BIO annotation is a classic method for encoding the start (B-Begin), inside (I-Inside), and outside (O-Outside) positions of entities in sequence labeling tasks. This solution guides the model to reason in a precise manner similar to "BIO" by specifying structured output requirements (such as specifying the output format [Entity1, Entity2,...]). That is, first locate the start boundary (B) of the entity, and then confirm its end boundary, so as to output a complete entity mention, rather than a fragment. The "without omission" instruction in the prompt word is intended to reduce entity omissions and guide the model to perform exhaustive recognition. Step 42, Relation Extraction: Based on the entity list, extract relations from a predefined relation label set (e.g., ["capital_of", "hosted_by"] from the NYT dataset). This predefined label set is a closed set of relation types obtained in advance during task initialization. The prompt word template is: "Second step: Extract all relations from the predefined relation label set." Output a relation list, such as ["hosted_by"], and focus on the semantics between entities through an attention mechanism. Step 43, Triple Construction: Integrate the entity list and relation list to generate structured triples. The prompt template is: "Third step: Form triplets as (Subject, Relation, Object)". For example, output [("2024 Summit", "hosted_by", "Paris")] to force the model to reason step by step. Step 44, Consistency Check: Set output format constraints (such as JSON structure) and verify entity overlap and relationship validity. If the model output is incorrect, prompt for correction again.

[0043] Step 5: For the current test sample, retrieve the Top-K similar samples from its aligned training clusters and automatically generate a thought chain example.

[0044] Furthermore, such as Figure 6 As shown, step 5 includes: Step 51: Calculate the cosine similarity between the test sample vector and each sample in the corresponding aligned training cluster: .

[0045] Step 52: Based on the alignment mapping table obtained in Step 3, limit the search scope to the training cluster that matches the test cluster to which the current test sample belongs. Within this aligned training cluster, select the Top-K samples with the highest cosine similarity to the current test sample. The parameter K is dynamically adjusted according to the task complexity, and can typically be set to 24, 48, or 72.

[0046] Step 53: Automatically generate a TD-CoT format example for each similar training sample retrieved from the training set in Step 52. This example includes a list of entities, a list of relations, and a list of triples. For example: First step: [Entity1,Entity2,...]; Second step: [Relation1, Relation2,...]; Third step: [(Subject1,Relation1, Object1), ...].

[0047] Step 54: Group the examples by cluster origin, add labels such as "Cluster A demonstrations", and insert cluster-aware statements (such as "These demonstrations are from cluster A aligned with the test sample") to form a chain of thought examples.

[0048] Step 6: Embed the test samples, relation tag set (which is a closed set of relation types obtained in advance during the task initialization phase), and thought chain examples into the constructed prompt word template, input them into the large language model for reasoning, and obtain the model output.

[0049] Furthermore, such as Figure 7 As shown, step 6 specifically includes: Step 61: Construct a comprehensive prompt template, including a fixed header (such as "### Your task is relationtriplet extraction.###") and dynamic placeholders, combining the task description, relation tag set, TD-CoT instructions, and the constructed mind chain example.

[0050] Step 62: Insert the thought chain examples into the prompt word template by clustering. At this point, the prompt words for inputting into the large language model are complete.

[0051] Step 63: Use a large language model (e.g., Llama-3.1-70B) and configure the generation parameters: temperature=0.1 to reduce randomness, max_tokens=500 to control the output length. Apply quantization techniques (e.g., 4-bit INT4) to optimize memory usage.

[0052] Step 64: Input the completed prompt words, and the large language model generates output containing the three-step inference path. Monitor the output format to ensure the output data is structured (e.g., parsed as JSON).

[0053] Step 7: Perform structured parsing on the model output, extract entity, relation and triple fields, and verify logical consistency through post-processing rules.

[0054] Furthermore, such as Figure 8 As shown, step 7 specifically includes: Step 71: Use regular expressions (such as re.findall(r'\[.*?\]', output)) to match the list of entities and the list of triples.

[0055] Step 72: Check if the entity boundaries match the original text (e.g., exact string match) and if the relationship belongs to a predefined tag set. If conflicts exist, such as multiple relationships for the same entity pair, select the one with the highest confidence.

[0056] Step 73: Filter low-confidence predictions (such as "uncertain" content marked by LLM) and correct similar-looking errors by dictionary matching (such as "Darfur" being misspelled as "Darfur region").

[0057] Step 74: Store the parsed triples in JSON or CSV format and generate a verification report (such as error type statistics).

[0058] Furthermore, such as Figure 9 As shown, step 7 also includes evaluating the model calculations, specifically: Step 81, Evaluation Criteria: Exact matching requires the triples to be completely identical to the annotations (100% matching of entities and relations). Partial matching allows for partial overlap of entities or relations, with a Jaccard similarity threshold > 0.8. The similarity calculation method here is as follows: .

[0059] Step 82, Calculate the metrics: Precision = Number of correctly predicted predictions / Total number of predicted predictions; Recall = Number of correctly predicted predictions / Total number of labeled samples; F1 score = 2 × Precision × Recall / (Precision + Recall); Accuracy = Number of correctly predicted predictions / Total number of samples. Use a confusion matrix to analyze error types (e.g., false positives, false negatives).

[0060] Step 83, Cross-dataset testing: Perform evaluations on multiple datasets (such as NYT, WebNLG, FewRel) to test the impact of different parameters (such as the number of clusters M and the number of examples K).

[0061] Step 84, Report Generation: Generate an evaluation report, including indicator comparisons and optimization suggestions, for iterative improvement.

[0062] Example 2: like Figure 10 As shown, this embodiment provides a relation triple extraction system based on clustering alignment context learning. The system includes: The semantic encoding module performs semantic encoding on the text in the training and test sample sets to generate high-dimensional training and test sample vectors. The clustering module performs independent clustering on the training sample vector and the test sample vector, dividing the samples into M clusters to obtain the training cluster and the test cluster; The alignment module calculates the center vector of each cluster and aligns the training clusters and test clusters through average pooling, establishing a one-to-one mapping relationship between the training clusters and test clusters; The extraction module decomposes the relation triple extraction task into multiple sequential subtasks and guides the large language model to reason step by step through structured prompts; the subtasks include entity extraction, relation extraction and triple construction. The prompt word construction module retrieves the Top-K similar samples from the aligned training clusters mapped to the current test sample and generates a thought chain example. And by embedding test samples, relationship tag sets, and thought chain examples into the constructed prompt word template, prompt words are obtained; The large language model module performs inference based on the prompt words obtained from the prompt word construction module to obtain the model output; The structured parsing module performs structured parsing on the model output, extracts the data corresponding to entity, relation, and triple fields, and performs logical consistency verification.

[0063] Preferably, the system further includes: an evaluation module for evaluating the model on multiple datasets and testing the impact of different parameters, including the number of clusters M and the number of instances K. The system also includes a result generation module that outputs parsed triples, supporting API interface or file export.

[0064] Example 3: This embodiment provides a device including a processor, a memory, and a bus. The processor calls instructions from the memory to execute the method provided in the above embodiment, supporting parallel computing (such as multi-GPU deployment). The memory stores data such as model weights, clustering mapping tables, and evaluation reports, and uses distributed storage to optimize access speed. The bus connects the various components, transmits data and control signals, and ensures low-latency communication.

[0065] The above are the various technical solutions provided by the present invention. It should be further noted that any process or method description in the flowcharts or otherwise described herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a specific logical function or process. Furthermore, the scope of the preferred embodiments of this solution includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as should be understood by those skilled in the art to which the embodiments of this solution pertain.

[0066] The logic and / or steps represented in the flowchart or otherwise described herein may be specifically implemented in any readable storage medium for use by, or in conjunction with, an instruction execution system, apparatus or device (such as a computer-based system, a processor-based system or other system that can fetch and execute instructions from, an instruction execution system, apparatus or device).

[0067] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method for extracting relation triples from text content, characterized in that, The method includes: Step 1: Semantically encode the text in the training and test sample sets to generate high-dimensional training and test sample vectors. Step 2: Perform independent clustering on the training sample vector and the test sample vector respectively, dividing the training set samples into M training clusters and the test set samples into M test clusters; Step 3: Calculate the center vector of each cluster, and align the training clusters and test clusters through average pooling to establish a one-to-one mapping relationship between the training clusters and test clusters; Step 4: Decompose the relation triple extraction task into multiple sequential subtasks, and guide the large language model to reason step by step through structured prompts; the subtasks include entity extraction, relation extraction and triple construction; Step 5: For the current test sample, retrieve the Top-K similar samples from its aligned training clusters and generate a thought chain example; Step 6: Embed the test samples, relation tag set, and thought chain examples into the constructed prompt word template to obtain prompt words; input the prompt words into the Big Prophecy model for inference to obtain the model output; Step 7: Perform structured parsing on the model output, extract the data corresponding to the entity, relation, and triple fields, and perform logical consistency verification.

2. The method according to claim 1, characterized in that, In step 1, the semantic encoding method is as follows: the text is converted into a high-dimensional vector using a pre-trained semantic text encoding model; the time and resources consumed in vector generation are recorded. The generated vectors are normalized; the normalized vectors are then dimensionality-reduced, and an index is created for the dimensionality-reduced vectors to obtain the training sample vectors and test sample vectors.

3. The method according to claim 1, characterized in that, Step 2 specifically includes: Step 21: Initialize cluster centers and determine the number of clusters M: Calculate the sum of intra-cluster variances for different M values, and select the inflection point as the optimal M value; Step 22: Perform clustering on the training set vector and the test set vector respectively, record the center coordinates, number of samples and index of each cluster, and obtain the cluster label; Step 23: Serialize the clustering results into JSON format to obtain training clusters and test clusters; the training clusters and test clusters should include at least cluster labels, cluster center vectors and sample mapping tables.

4. The method according to claim 1, characterized in that, Step 3 further includes: Step 31: Perform average pooling on the vectors within each cluster. For coefficient clusters with a small number of samples, use the median of the samples instead of the average vector. Step 32: Calculate the Euclidean distance matrix D between each cluster center of the training cluster and each cluster center of the test cluster. ij , where i is the training cluster index and j is the test cluster index; set a distance threshold to delete cluster pairs whose distance is greater than the distance threshold; Step 33: Solve for the minimum total distance matching, establish a one-to-one mapping relationship between the training cluster and the test cluster, and store the matching results as an alignment mapping table; Step 34: Serialize the alignment mapping table into JSON format.

5. The method according to claim 1, characterized in that, In step 4, the entity extraction method is as follows: the large language model obtains the entity list by using the prompt word template and boundary detection. The relation extraction method is as follows: based on the entity list, combined with the prompt word template, the relation is extracted from the predefined relation tag set through the attention mechanism to obtain the relation list; The method for constructing triples is to integrate the entity list and the relation list to generate a structured list of triples.

6. The method according to claim 1, characterized in that, Step 5 specifically includes: Step 51: Calculate the cosine similarity between the test sample vector and each sample in the aligned training cluster corresponding to the mapping. Step 52: Select the Top-K most similar samples from the aligned training clusters and filter out unaligned samples; Step 53: Generate an example for each retrieved similar training sample. The example includes a list of entities, a list of relations, and a list of triples corresponding to the sample. Step 54: Group the examples according to their clustering source, add labels, and insert cluster-aware statements to form a mind chain example.

7. The method according to claim 1, characterized in that, Step 6 specifically includes: Step 61: Build a prompt word template; Step 62: Insert the thought chain example into the prompt word template by clustering, and add cluster-aware statements to provide contextual information. The prompt words are now complete. Step 63: Configure the large language model; Step 64: Input the completed prompt words into the large language model, perform three-step reasoning, and obtain the model output.

8. The method according to claim 1, characterized in that, Step 7 further includes: Step 71: Use regular expressions to match the entity list and the triple list; Step 72: Check the consistency of entities and relationships; Step 73: Filter out low-confidence prediction results to obtain the parsed triples; Step 74: Generate a verification report based on the parsed triples.

9. A system for extracting relation triples from text content, characterized in that, The system includes: The semantic encoding module performs semantic encoding on the text in the training and test sample sets to generate high-dimensional training and test sample vectors. The clustering module performs independent clustering on the training sample vector and the test sample vector, dividing the samples into M clusters to obtain the training cluster and the test cluster; The alignment module calculates the center vector of each cluster and aligns the training clusters and test clusters through average pooling, establishing a one-to-one mapping relationship between the training clusters and test clusters; The extraction module decomposes the relation triple extraction task into multiple sequential subtasks and guides the large language model to reason step by step through structured prompts; the subtasks include entity extraction, relation extraction and triple construction. The prompt word construction module retrieves the Top-K similar samples from the aligned training clusters mapped to the current test sample and generates a thought chain example. And by embedding test samples, relationship tag sets, and thought chain examples into the constructed prompt word template, prompt words are obtained; The large language model module performs inference based on the prompt words obtained from the prompt word construction module to obtain the model output; The structured parsing module performs structured parsing on the model output, extracts the data corresponding to entity, relation, and triple fields, and performs logical consistency verification.

10. A device for extracting relation triples from text content, characterized in that, The device includes a processor, a memory, and a bus; the processor invokes instructions in the memory to execute the method for extracting relation triples from text content as described in any one of claims 1-8.