Toxicity text acquisition method and system based on search enhancement generation

By combining a large language model with a retrieval-based augmentation method, the problems of low efficiency, high cost, and poor consistency in traditional toxic text annotation are solved. This method achieves high-quality, fine-grained toxic text annotation and constructs a self-iterative and optimized data augmentation closed-loop system, thereby improving the accuracy of annotation results and system performance.

CN121071167BActive Publication Date: 2026-03-03JIANGXI UNIVERSITY OF FINANCE AND ECONOMICS
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511625143.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-11-07
Publication Date
2026-03-03
Estimated Expiration
2045-11-07

AI Technical Summary

Technical Problem

Existing technologies struggle to achieve high-quality, fine-grained, and consistent toxic text annotation while maintaining efficiency. Traditional manual annotation is inefficient and costly, while automatic model annotation is prone to error propagation and bias amplification, lacking the ability to discriminate fine-grained information.

Method used

We adopt a retrieval-enhanced generation method, which combines a large language model and a retrieval tool. We build an initial dataset through cold start, generate toxic labels using semantically similar examples and a multi-round debate mechanism, and achieve high-quality, fine-grained labeling by iteratively optimizing the retrieval tool performance.

Benefits of technology

Automated generation of high-quality tags reduces the cost of manual annotation, improves the accuracy and consistency of annotation results, generates fine-grained tags that are difficult to achieve with traditional methods, constructs a self-iterative and optimized data augmentation closed-loop system, and enhances the semantic discrimination ability of the retrieval machine.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121071167B_ABST
    Figure CN121071167B_ABST
Patent Text Reader

Abstract

The present application relates to a kind of based on retrieval enhancement generation's toxicity text acquisition method and system, first by obtaining target text data through crawling platform, and using cold start mode artificial construction small-scale initial data set, inject knowledge base as basic data. The semantic retrieval is carried out to each batch target text, obtain the semantic similarity from knowledge base k text, combine these texts by thought chain reasoning using multiple large language model reasoning, generate toxicity label, and mark the target text to be marked in current batch. The target text after marking is injected into the knowledge base, and the data is continuously collected and labeled in an iterative manner, and the performance of the retriever is continuously optimized through incremental learning mechanism during the iteration process to achieve toxicity text acquisition. The present application can efficiently accumulate large-scale, fine-grained, high-consistency toxicity text labeling corpus, significantly alleviate the problems of high labeling cost, inconsistent quality and poor scalability in traditional toxicity text data collection.
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, and in particular to a method and system for collecting toxic text based on retrieval enhancement. Background Technology

[0002] Network content security governance is a core research topic in the fields of natural language processing and cyberspace security. Constructing high-quality toxic text annotation datasets—data resources that accurately label language expressions containing harmful content such as attacks, insults, hate speech, or incitement to violence—is not only crucial foundational work in this field but also a key link in promoting the intelligent development of network ecosystem governance. The core value of such datasets lies in providing high-quality training samples for toxic content detection models, providing annotation benchmarks for online speech analysis, and offering reliable data support for content security governance systems. Accurate toxic text annotation directly determines the performance ceiling of models in tasks such as harmful content identification, classification, and governance, playing a crucial technical supporting role in building a clean and healthy cyberspace.

[0003] The construction of current toxic text datasets faces multiple technical bottlenecks: the original data mostly comes from public social media platforms, inherently suffering from high noise and uneven distribution; in the annotation stage, existing methods mainly rely on two paradigms: manual annotation and automatic model annotation. While manual annotation can ensure quality, it suffers from low efficiency, high cost, and poor subjective consistency; automatic model annotation, while improving efficiency, heavily relies on the performance of the baseline model, easily leading to error propagation and bias amplification, and only supports coarse-grained classification, lacking the ability to discriminate fine-grained information such as attack targets and intensity. Overall, existing technologies struggle to simultaneously meet the requirements of scalability, high quality, fine granularity, and consistency, severely restricting the development of high-performance toxicity detection models. Therefore, there is an urgent need in this field for an innovative solution that can achieve high-quality, fine-grained, and highly consistent toxicity text annotation while ensuring efficiency, thereby systematically overcoming the limitations of existing technologies. Summary of the Invention

[0004] In view of the above, the main objective of this invention is to propose a method for collecting toxic text based on retrieval enhancement, so as to solve the above-mentioned technical problems.

[0005] This invention provides a method for collecting toxic text based on retrieval enhancement, the method comprising the following steps:

[0006] Step 1: Obtain and clean the text data on the platform to obtain the data to be labeled;

[0007] Step 2: Manually construct a small-scale initial dataset using a cold start approach and inject the initial dataset into the knowledge base;

[0008] Step 3: Divide the data to be labeled into batches to obtain several batches of target text to be labeled. Use a retrieval tool to obtain the top k semantically similar examples from the knowledge base that are similar to the target text to be labeled in the current batch, and obtain semantically similar examples.

[0009] Step 4: Combine the target text to be labeled in the current batch with semantically similar examples to construct prompt words, and use at least two large language models with different architectures to independently generate at least two toxic labels through thought chain reasoning, and give the evaluation results of semantically similar examples;

[0010] Step 5: If the generated toxicity labels are consistent, then directly use the toxicity label to label the target text to be labeled in the current batch;

[0011] When the generated toxicity labels are inconsistent, a debate mechanism is initiated, which allows all large language models to interact and debate in multiple rounds to determine the final toxicity label. Then, the target text to be labeled in the current batch is labeled to obtain the labeled target text.

[0012] Step 6: Inject the labeled target text into the knowledge base, continuously collect and label data in an iterative manner, and dynamically adjust the retrieval strategy of the retrieval machine based on the evaluation results of semantically similar examples during the iteration process. At the same time, continuously optimize the performance of the retrieval machine through an incremental learning mechanism to achieve the collection of toxic text.

[0013] This invention also proposes a toxic text collection system based on retrieval enhancement, the system comprising:

[0014] The data acquisition and processing module is used for:

[0015] Obtain and clean the text data from the platform to obtain the data to be labeled;

[0016] The initial dataset building module is used for:

[0017] A small-scale initial dataset was manually constructed using a cold start approach;

[0018] The knowledge base management module is used for:

[0019] Store and manage labeled data, including the initial dataset and the labeled target text injected in subsequent iterations;

[0020] The search module is used for:

[0021] The data to be labeled is divided into batches to obtain several batches of target text to be labeled. The retrieval tool is used to retrieve the top k semantically similar examples from the knowledge base that are similar to the target text to be labeled in the current batch, thus obtaining semantically similar examples.

[0022] The generator module, equipped with at least two large language models of different architectures, is used for:

[0023] Combine the target text to be labeled in the current batch with semantically similar examples to construct prompt words, and use at least two large language models with different architectures to independently generate at least two toxic labels through thought chain reasoning, and give the evaluation results of semantically similar examples;

[0024] If the generated toxicity labels are consistent, then the toxicity label is directly used to label the target text to be labeled in the current batch;

[0025] When the generated toxicity labels are inconsistent, a debate mechanism is initiated, which allows all large language models to interact and debate in multiple rounds to determine the final toxicity label. Then, the target text to be labeled in the current batch is labeled to obtain the labeled target text.

[0026] The iteration and optimization module is used for:

[0027] The labeled target text is injected into the knowledge base, and data is continuously collected and labeled in an iterative manner. During the iteration process, the retrieval strategy of the retrieval machine is dynamically adjusted based on the evaluation results of semantically similar examples. At the same time, the performance of the retrieval machine is continuously optimized through an incremental learning mechanism to achieve the collection of toxic text.

[0028] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0029] 1. This invention leverages the powerful semantic understanding and reasoning capabilities of large language models, combined with a retrieval-enhanced generation framework, to achieve automated generation of high-quality tags. Compared to traditional manual annotation, this method liberates humans from tedious, subjective, and potentially harmful annotation work, significantly reducing annotation costs and time consumption through automation, and avoiding the psychological harm caused by annotators' exposure to toxic content.

[0030] 2. This invention provides accurate labeling basis for large language models through a retrieval-enhanced generation mechanism, effectively overcoming their "illusion" and bias problems. Unlike methods that directly use existing flawed models to generate pseudo-labels, this invention does not rely on the inherent, potentially biased knowledge within the large language model for judgment. The retrieval-enhanced generation mechanism retrieves relevant examples in real time from a self-constructed dedicated knowledge base, using them as reliable context and constraints for the large language model to generate labels, thereby significantly improving the accuracy, consistency, and fairness of the output results and effectively preventing the propagation and amplification of inaccurate labels in subsequent processing.

[0031] 3. This invention can generate fine-grained, structured labels that are difficult to achieve with traditional automated methods. Existing automatic labeling methods can usually only output binary or coarse-grained classification results, while this invention, by leveraging the excellent contextual understanding and reasoning capabilities of large models and combining standard information provided by retrieval, can accurately identify multi-dimensional labels such as toxicity type and attack target, greatly improving the richness and usability of the labeling information and providing a key data foundation for training high-performance detection models.

[0032] 4. Evaluation results of semantically similar examples are generated using a large language model. In subsequent iterations, the retrieval strategy of the retrieval machine is dynamically adjusted based on these evaluation results. This dynamic adjustment can improve retrieval quality without significantly increasing computational costs. Since optimization is based on feedback from the actual reasoning process, the retrieval machine will know which examples the generation module needs during iterations, thereby reducing interference from irrelevant examples and improving the reasoning efficiency and accuracy of the generation module.

[0033] 5. This invention constructs a data augmentation closed-loop system with retrieval optimization at its core, capable of continuous self-iteration. Automatically generated high-quality labeled data is used to optimize the contrastive learning-based semantic retrieval system, improving its retrieval accuracy and robustness. Through contrastive learning, the system can shorten the distance between similar samples and widen the distance between different samples in the vector space, thereby effectively improving the retrieval system's ability to discriminate semantic similarity. The performance-enhanced retrieval system can further provide more accurate contextual references for large language models, generating more accurate labels. This system continuously improves itself, achieving the co-evolution of the knowledge base and labeling quality, fundamentally breaking through the technical limitations of traditional labeling methods in terms of scalability, fine-grainedness, and consistency.

[0034] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by means of embodiments of the invention. Attached Figure Description

[0035] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0036] Figure 1 This is a flowchart of the toxic text collection method based on retrieval enhancement proposed in this invention;

[0037] Figure 2 This is a schematic diagram illustrating the data acquisition and preprocessing process of the present invention;

[0038] Figure 3This is a schematic diagram illustrating the basic data and knowledge base management of this invention;

[0039] Figure 4 This is a schematic diagram illustrating the semantic retrieval of a knowledge base using a retrieval tool according to the present invention;

[0040] Figure 5 This is a schematic diagram illustrating the invention's use of two large language models with different architectures to generate toxicity tags through reasoning.

[0041] Figure 6 This is a schematic diagram of the retrieval optimization process of the present invention;

[0042] Figure 7 This is a framework diagram of the toxic text collection system based on retrieval enhancement proposed in this invention. Detailed Implementation

[0043] Embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.

[0044] These and other aspects of the embodiments of the present invention will become clear from the following description and accompanying drawings. In these descriptions and drawings, some specific embodiments of the present invention are specifically disclosed to illustrate some ways of implementing the principles of the embodiments of the present invention; however, it should be understood that the scope of the embodiments of the present invention is not limited thereto.

[0045] Please see Figure 1 This invention provides a method for collecting toxic text based on retrieval enhancement, the method comprising the following steps:

[0046] Step 1: Obtain and clean the text data on the platform to obtain the data to be labeled;

[0047] Please see Figure 2 In this step, raw text data is first obtained from the target social media platform (e.g., Weibo) using automated data collection tools (e.g., scripts based on SeleniumWebDriver). Data sources include, but are not limited to, trending topics and search results based on preset keywords. The raw data is then cleaned, including at least: removing non-target text noise such as URLs, @usernames, hashtags, and emojis / control characters; language and length filtering; and generating a fingerprint for each text using SimHash to identify and remove duplicate or highly similar text, resulting in the dataset to be labeled.

[0048] Step 2: Manually construct a small-scale initial dataset using a cold start approach and inject the initial dataset into the knowledge base;

[0049] Please see Figure 3 In this step, a cold start approach is used to build the initial knowledge base of the model. First, a portion of data is randomly sampled from the text set to be labeled, and trained annotators perform multi-person labeling and cross-validation according to fine-grained toxicity labeling specifications. To quantify consistency, the Kappa coefficient is preferred in the case of multiple annotators.

[0050] ;

[0051] in, It is the sum of the number of samples correctly classified in each category divided by the total number of samples. The number of real samples for each category are respectively The number of real samples in each class are respectively Once the annotation is complete, the data (text and corresponding labels) that pass the consistency threshold will be written into the knowledge base as an initial reference for subsequent automated annotation.

[0052] Step 3: Divide the data to be labeled into batches to obtain several batches of target text to be labeled. Use a retrieval tool to obtain the top k semantically similar examples from the knowledge base that are similar to the target text to be labeled in the current batch, and obtain semantically similar examples.

[0053] Please see Figure 4 In this step, the retrieval is implemented based on a semantic embedding model. The semantic embedding model adopts a hierarchical semantic aggregation network structure to map text to a low-dimensional dense vector space. During the mapping process, the semantic encoding layer in the hierarchical semantic aggregation network structure extracts semantic information of different levels of text. The dimensions of the semantic information of different levels are aligned by a linear layer, then concatenated and input into a self-attention aggregation layer. Learnable attention weights are used to dynamically fuse semantic information of different levels to generate a global semantic representation vector. By calculating the similarity between the global semantic representation vectors, the top k examples that are semantically similar to the target text are retrieved from the knowledge base.

[0054] First, the data to be labeled is organized in batches. Then, for each target text to be labeled, a retrieval tool is used to search the knowledge base for the k most semantically similar labeled samples (preferably k=5 in this embodiment). These samples contain their original text content and corresponding label tags. The retrieval tool maps the text into a low-dimensional dense vector based on a semantic embedding model (the semantic embedding model is the e5 model in this embodiment), and calculates semantic similarity using cosine similarity, which is defined as:

[0055] ;

[0056] in, Indicates the angle between two text embeddings. This indicates the embedding of the target text to be annotated. This indicates the embedding of sample text that has been annotated in the knowledge base. Indicates the size of spatial dimensions. For vectors In the Dimension value, For vectors In the The value of the dimension, the larger the cosine similarity value, the greater the similarity between the texts. After sorting, the first k samples are selected to obtain semantically similar samples.

[0057] Step 4: Combine the target text to be labeled in the current batch with semantically similar examples to construct prompt words, and use at least two large language models with different architectures to independently generate at least two toxic labels through thought chain reasoning, and give the evaluation results of semantically similar examples;

[0058] Please see Figure 5 In this step, the large language model adopts a hybrid expert model structure, which includes several lightweight adapter (LoRA / Adapter) experts set up by the large language model for different toxicity label categories, as well as a gating network.

[0059] The large language model is used to: generate contextual feature representations based on prompt words; prompt words include the target text to be labeled in the current batch, similar examples and their corresponding labels, the category definition and judgment rules of toxicity labels, and instruction information to guide the large language model to analyze in a chain reasoning manner;

[0060] Gated networks are used to: generate gating weights based on input semantics to dynamically activate lightweight adapter experts for corresponding toxicity label categories;

[0061] Lightweight adapter experts are used to: activate a corresponding number of lightweight adapter experts in response to the activation command of the gating network, generate at least one classification output based on the context feature representation, and weight the at least one classification output with the gating weights to generate a toxicity label.

[0062] First, the retrieved high-similarity samples are combined with the target text to be labeled in the current batch to construct prompt words containing contextual examples. The prompt word template includes the following: the target text content, i.e., the target text to be labeled in the current batch; similar samples returned by the retrieval module and their corresponding tags; the category definition and judgment rules of toxicity tags; and instruction information to guide the large language model to analyze in a chain-like reasoning manner.

[0063] In this embodiment, two large language models are used, and the prompt word template is shown below:

[0064] Role Setting and Task Instructions: You are a toxic comment moderator, capable of identifying different types of inappropriate content. Your classification tags can only be selected from the following seven categories: 1. Toxic; 2. Severely Toxic; 3. Hateful to a Specific Identity; 4. Insulting; 5. Threatening; 6. Obscene; 7. Normal. Please refer to the provided similar cases, combine them with the category definitions, and reason step by step to provide the classification result, confidence level, and brief reasoning for the comment.

[0065] Please note: Your final output must strictly adhere to the following format, returning only a single tuple that Python can parse, without any additional prefixes or explanations:

[0066] (<Label>, <Target Audience>, <Confidence Level>, <Reason>)

[0067] Tags: Must be one of the seven categories mentioned above;

[0068] Target: Indicates the specific identity or object attacked in the comment (such as "race", "gender", "region", etc.). If no specific object is specified, output "None".

[0069] Confidence level: Your level of confidence in this judgment, please express it as a percentage (e.g., "85%").

[0070] Reason: Briefly explain your reasoning, based on annotation rules and reference cases;

[0071] The aforementioned prompts are input into two different large language models (GPT-4 and Qwen-plus in this embodiment), and each model independently generates toxicity label prediction results for the target text based on chain reasoning.

[0072] Step 5: If the generated toxicity labels are consistent, then directly use the toxicity label to label the target text to be labeled in the current batch;

[0073] When the generated toxicity labels are inconsistent, a debate mechanism is initiated, which allows all large language models to interact and debate in multiple rounds to determine the final toxicity label. Then, the target text to be labeled in the current batch is labeled to obtain the labeled target text.

[0074] Please see Figure 5In this step, the prediction results of two large language models with different architectures are first compared. If the output labels are consistent, the label is directly adopted as the final annotation result for the target text; if the output results are inconsistent, a pre-set multi-round debate mechanism is triggered. This mechanism reconstructs debate prompts, inputs the target text, similar examples, category definitions and judgment rules, and two initially inconsistent labels into the two large language models, and guides them to speak alternately as "reviewer A" and "reviewer B," conducting multiple rounds of reasoning and argumentation based on annotation rules and reference cases in order to reach a consensus.

[0075] If no consensus is reached within the preset maximum number of debate rounds, the arbitration module will output a comprehensive judgment based on the debate process, or trigger a manual intervention process to determine the final label. The debate prompts include the following information: the target text content to be judged; the labeling rules, i.e., the category definition and judgment basis of each toxicity label; the reference cases and their labels returned by the retrieval module; the inconsistent label results output by the two large language models in the initial prediction stage; role settings and debate rules.

[0076] In this embodiment, the debate prompt template is shown below:

[0077] Role setting: You are two professional content moderation experts, referred to as "Moderator A" and "Moderator B" respectively.

[0078] Task Background: You have previously made judgments on the same target text, but your conclusions are inconsistent. Now, you need to conduct multiple rounds of alternating presentations, referencing annotation rules and case studies, in order to reach a unified conclusion.

[0079] Debate Rules:

[0080] Auditor A first stated the reasons, followed by Auditor B's response, and they alternated speaking until the end;

[0081] The content of the speech must be based on the annotation rules and reference cases, and subjective speculations must not be made without evidence;

[0082] The presentation should remain professional, focusing solely on the analysis of the text and tags.

[0083] The goal is to reach a consensus. If no consensus is reached within the pre-set number of rounds, the final label will be determined by an arbitration mechanism.

[0084] The aforementioned prompts are input into two large language models during system operation. The models will then engage in alternating reasoning and argumentation according to predefined roles and rules. The output of each round of debate is recorded in a structured format until a consensus is reached or arbitration is initiated.

[0085] Step 6: Inject the labeled target text into the knowledge base, continuously collect and label data in an iterative manner, and dynamically adjust the retrieval strategy of the retrieval machine based on the evaluation results of semantically similar examples during the iteration process. At the same time, continuously optimize the performance of the retrieval machine through an incremental learning mechanism to achieve the collection of toxic text.

[0086] Please see Figure 6 In this step, the target text successfully labeled via step 4 or 5 (i.e., high-confidence consensus labels or labels reached after debate) is first injected into the knowledge base, thereby expanding and updating the knowledge base. Simultaneously, the newly expanded labeled data is used as training samples, and the retrieval model is periodically incrementally trained based on contrastive learning techniques to improve its semantic representation capabilities. Furthermore, during inference, evaluation results for semantically similar examples are provided concurrently. These evaluation results reveal which examples are helpful for the generation module's inference and which are not. The retrieval engine can adjust its retrieval strategy based on this feedback, forming a complete "labeling → evaluation → optimization → relabeling" closed loop. The system can learn from its own labeling experience and continuously improve; with increasing iterations, the retrieval quality steadily improves. By adjusting the retrieval strategy based on real LLM evaluation feedback, rather than relying on preset rules or human intuition, the retrieval engine can learn which examples are most valuable for the toxicity labeling task, achieving task-specific optimization and reducing reliance on human intervention.

[0087] The dynamic adjustment of the retrieval strategy based on the evaluation results of semantic similarity examples includes the following steps:

[0088] The evaluation results of semantic similarity examples include an importance score for each example to the label generation and / or query text, where the query text is the type of example that needs to be supplemented based on the target text to be labeled;

[0089] If the evaluation results of semantic similarity examples include importance scores, the retrieval machine will perform weighted similarity retrieval based on the importance scores for the next batch of target text retrieval expressions to be labeled;

[0090] If the evaluation results of semantically similar examples contain the query text, then the query will be used as a new search vector and combined with the next batch of target texts to be labeled for example retrieval.

[0091] Optimizing the search engine's performance involves two stages, specifically:

[0092] Initial stage: Using the initial dataset as the training set, and based on the training set, the retrieval machine is optimized through contrastive learning methods to achieve initial fine-tuning;

[0093] Iteration phase: Utilize the expanded knowledge base after each round of new annotations, construct a training set using experience replay, and optimize the retrieval machine based on the training set through contrastive learning methods for incremental fine-tuning.

[0094] Specifically, the contrastive learning optimization process is achieved by constructing positive and negative sample pairs and minimizing the contrastive loss function. Text pairs with the same label are treated as positive sample pairs, aiming to shorten their distance in the vector space; text pairs with different labels are treated as negative sample pairs, aiming to widen their distance in the vector space. The specific steps are as follows:

[0095] Training sample pairs are constructed based on the toxicity labels in the training set, and the training sample pairs are input into the retrieval system to calculate the cosine similarity of the sample pairs.

[0096] The sample pairs include positive sample pairs and negative sample pairs. Text pairs with the same toxicity label are considered positive sample pairs, and text pairs with different toxicity labels are considered negative sample pairs. Based on cosine similarity, a contrastive learning loss function is constructed using positive and negative sample pairs.

[0097] By minimizing the contrastive learning loss function, the distance between texts with the same toxicity label in the vector space is reduced, while the distance between texts with different toxicity labels is increased, thereby optimizing the retrieval mechanism. This optimization enables the retrieval mechanism to better distinguish the semantics of texts with different toxicity categories.

[0098] The formula for the contrastive learning loss function is as follows:

[0099] ;

[0100] in, Indicates the number of samples in the batch. Indicates sample The vector representation of , Representation and Sample Vector representation of positive samples with the same label. Indicates sample The set of positive samples Indicates sample The negative sample set, including the current batch excluding Other sample sets, Represents the negative sample set. The vector representation of , This represents the temperature coefficient. By minimizing this loss function, the retrieval engine can learn more discriminative text representations, thereby retrieving semantically relevant examples more accurately and improving the retrieval quality and annotation efficiency of subsequent batches. The system operates iteratively until all target text has been processed or a predetermined termination condition is met.

[0101] Please see Figure 7 This invention also provides a toxic text collection system based on retrieval enhancement, the system comprising:

[0102] The data acquisition and processing module is used for:

[0103] This module acquires and cleans text data from the platform to obtain data to be labeled. As the system's data source, this module uses web crawling technology to automatically collect raw text data from the Internet platform, and cleans, denoises, and formats the collected raw data to generate target text that can be labeled later.

[0104] The initial dataset building module is used for:

[0105] A small-scale initial dataset was manually constructed using a cold start approach;

[0106] The knowledge base management module is used for:

[0107] This module stores and manages labeled data, including the initial dataset and the labeled target text injected in subsequent iterations. As the core data hub of the system, this module is responsible for building, maintaining, and providing access to a structured knowledge base. By integrating vector databases and semantic indexing technology, this module achieves efficient storage of labeled toxic text and its multi-granularity tags, and automatically calls the embedding model to generate vector representations for each text, establishing a vector index. Furthermore, the knowledge base provides low-latency, high-precision similarity retrieval support for the retrieval module, ensuring the efficient execution of subsequent generation and labeling processes.

[0108] The search module is used for:

[0109] The data to be labeled is divided into batches, resulting in several batches of target text to be labeled. A retrieval tool is used to retrieve the top k semantically similar examples from the knowledge base that are similar to the target text in the current batch, thus obtaining semantically similar examples. This module receives the input unlabeled target text and calculates the semantic similarity between the target text and the samples in the knowledge base. Based on this similarity calculation result, this module returns the top k text examples that are most semantically similar to the target text, providing reference information for generating labels.

[0110] The generator module, equipped with at least two large language models of different architectures, is used for:

[0111] Combine the target text to be labeled in the current batch with semantically similar examples to construct prompt words, and use at least two large language models with different architectures to independently generate at least two toxic labels through thought chain reasoning, and give the evaluation results of semantically similar examples;

[0112] If the generated toxicity labels are consistent, then the toxicity label is directly used to label the target text to be labeled in the current batch;

[0113] When the generated toxicity labels are inconsistent, a debate mechanism is initiated, allowing all large language models to engage in multiple rounds of interaction and debate to determine the final toxicity label. This label is then used to annotate the target text in the current batch, resulting in the annotated target text. This module receives the target text and its similar examples and predicts toxicity labels for the target text using a built-in reasoning mechanism. This module is equipped with at least two different large language models, each generating fine-grained labels using a chain-of-thought reasoning approach. When the predicted labels from the two large language models are inconsistent, a multi-round debate mechanism is triggered, reaching a consensus through inter-model interaction and reasoning. If the debate mechanism fails to produce a consistent label, a manual intervention process is initiated to ensure the accuracy and consistency of the annotation results.

[0114] The iteration and optimization module is used for:

[0115] The labeled target text is injected into the knowledge base, and data is continuously collected and labeled iteratively. During the iteration process, the retrieval strategy of the retrieval machine is dynamically adjusted based on the evaluation results of semantically similar examples. At the same time, the retrieval machine performance is continuously optimized through an incremental learning mechanism to achieve the collection of toxic text. This module optimizes the encoder performance in the retrieval machine based on the labeled data output by the generator module. Through a supervised contrastive learning strategy, this module brings samples with the same label closer together and widens the distance between samples with different labels in the vector space, thereby improving the encoder's ability to discriminate semantic similarity, thus optimizing the retrieval effect and improving the labeling quality and stability of the system in subsequent batches.

[0116] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0117] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0118] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these modifications and improvements all fall within the scope of protection of the present invention. Therefore, the scope of protection of this patent should be determined by the appended claims.

Claims

1. A method for collecting toxic text based on retrieval enhancement, characterized in that, The method includes the following steps: Step 1: Obtain and clean the text data on the platform to obtain the data to be labeled; Step 2: Manually construct a small-scale initial dataset using a cold start approach and inject the initial dataset into the knowledge base; Step 3: Divide the data to be labeled into batches to obtain several batches of target text to be labeled. Use a retrieval tool to obtain the top k semantically similar examples from the knowledge base that are similar to the target text to be labeled in the current batch, and obtain semantically similar examples. Step 4: Combine the target text to be labeled in the current batch with semantically similar examples to construct prompt words, and use at least two large language models with different architectures to independently generate at least two toxic labels through thought chain reasoning, and give the evaluation results of semantically similar examples; Step 5: If the generated toxicity labels are consistent, then directly use the toxicity label to label the target text to be labeled in the current batch; When the generated toxicity labels are inconsistent, a debate mechanism is initiated, which allows all large language models to interact and debate in multiple rounds to determine the final toxicity label. Then, the target text to be labeled in the current batch is labeled to obtain the labeled target text. Step 6: Inject the labeled target text into the knowledge base, continuously collect and label data in an iterative manner, and dynamically adjust the retrieval strategy of the retrieval machine based on the evaluation results of semantic similarity examples during the iteration process. At the same time, continuously optimize the performance of the retrieval machine through an incremental learning mechanism to achieve the collection of toxic text. In step 3, the retrieval is implemented based on a semantic embedding model. The semantic embedding model adopts a hierarchical semantic aggregation network structure to map text to a low-dimensional dense vector space. During the mapping process, the semantic encoding layer in the hierarchical semantic aggregation network structure extracts semantic information of different levels of text. The dimensions of the semantic information of different levels are aligned by a linear layer, then concatenated and input into a self-attention aggregation layer. The semantic information of different levels is dynamically fused using learnable attention weights to generate a global semantic representation vector. By calculating the similarity between the global semantic representation vectors, the top k examples that are semantically similar to the target text are retrieved from the knowledge base. In step 6, dynamically adjusting the retrieval strategy of the retrieval machine based on the evaluation results of semantically similar examples specifically includes the following steps: The evaluation results of semantic similarity examples include an importance score for each example to the label generation and / or query text, where the query text is the type of example that needs to be supplemented based on the target text to be labeled; If the evaluation results of semantic similarity examples include importance scores, the retrieval machine will perform weighted similarity retrieval based on the importance scores for the next batch of target text retrieval expressions to be labeled; If the evaluation results of semantically similar examples contain the query text, then the query will be used as a new search vector and combined with the next batch of target texts to be labeled for example retrieval.

2. The method for collecting toxic text based on retrieval enhancement as described in claim 1, characterized in that, In step 1, the text data on the platform is obtained and cleaned to obtain the data to be labeled. Specifically, the dynamically loaded text content is crawled by simulating user behavior using a web crawler tool, and text deduplication, removal of duplicate characters, filtering of non-target language text, and length filtering are performed to obtain the data to be labeled.

3. The method for collecting toxic text based on retrieval enhancement according to claim 2, characterized in that, In step 2, manual annotation employs multi-person annotation and cross-validation, and uses the Kappa coefficient to quantify the degree of consistency among multiple annotators to ensure the quality of the initial dataset.

4. The method for collecting toxic text based on retrieval enhancement according to claim 3, characterized in that, In step 4, the large language model adopts a hybrid expert model structure, which includes several lightweight adapter experts set up by the large language model for different toxicity label categories and a gating network. Large language models are used to generate contextual feature representations based on prompt words. The prompts include the target text to be labeled in the current batch, similar examples and their corresponding labels, the category definition and judgment rules of toxicity labels, and the instruction information to guide the large language model to analyze in a chain reasoning manner; Gated networks are used to: generate gating weights based on input semantics to dynamically activate lightweight adapter experts for corresponding toxicity label categories; Lightweight adapter experts are used to: activate a corresponding number of lightweight adapter experts in response to the activation command of the gating network, generate at least one classification output based on the context feature representation, and weight the at least one classification output with the gating weights to generate a toxicity label.

5. The method for collecting toxic text based on retrieval enhancement according to claim 4, characterized in that, In step 5, when the generated toxicity labels are inconsistent, a debate mechanism is initiated, allowing all large language models to engage in multiple rounds of interaction and debate to determine the final toxicity label. This specifically includes the following steps: When the generated toxicity labels are inconsistent, a debate mechanism is initiated, using all large language models to present the reasoning basis and confidence level of their respective toxicity labels. Based on the reasoning and confidence level of their respective toxicity labels, identify and point out inconsistencies or biases in the other party's reasoning; All large language models revise their conclusions through multiple rounds of interaction until a consensus is reached or a termination condition is triggered. If all large language models still cannot reach a consensus when the termination condition is triggered, then manual intervention is introduced for final annotation.

6. The method for collecting toxic text based on retrieval enhancement according to claim 5, characterized in that, In step 6, the continuous optimization of the retrieval performance through the incremental learning mechanism includes the following stages: Initial stage: Using the initial dataset as the training set, and based on the training set, the retrieval machine is optimized through contrastive learning methods to achieve initial fine-tuning; Iteration phase: Utilizing the expanded knowledge base after each round of new annotations, a training set is constructed using experience replay, and the retrieval machine is optimized using a contrastive learning method based on the training set for incremental fine-tuning.

7. The method for collecting toxic text based on retrieval enhancement according to claim 6, characterized in that, The optimization of the retrieval system based on the training set using a contrastive learning method includes the following steps: Training sample pairs are constructed based on the toxicity labels in the training set, and the training sample pairs are input into the retrieval system to calculate the cosine similarity of the sample pairs. The sample pairs include positive sample pairs and negative sample pairs. Text pairs with the same toxicity label are considered positive sample pairs, and text pairs with different toxicity labels are considered negative sample pairs. Based on cosine similarity, a contrastive learning loss function is constructed using positive and negative sample pairs; By minimizing the contrastive learning loss function, the distance between texts with the same toxicity label in the vector space is reduced, while the distance between texts with different toxicity labels in the vector space is increased, thereby optimizing the retrieval system.

8. A toxic text collection system based on retrieval enhancement, characterized in that, The system employs the toxic text collection method based on retrieval enhancement as described in any one of claims 1 to 7 above, and the system comprises: The data acquisition and processing module is used for: Obtain and clean the text data from the platform to obtain the data to be labeled; The initial dataset building module is used for: A small-scale initial dataset was manually constructed using a cold start approach; The knowledge base management module is used for: Store and manage labeled data, including the initial dataset and the labeled target text injected in subsequent iterations; The search module is used for: The data to be labeled is divided into batches to obtain several batches of target text to be labeled. The retrieval tool is used to retrieve the top k semantically similar examples from the knowledge base that are similar to the target text to be labeled in the current batch, thus obtaining semantically similar examples. The generator module, equipped with at least two large language models of different architectures, is used for: Combine the target text to be labeled in the current batch with semantically similar examples to construct prompt words, and use at least two large language models with different architectures to independently generate at least two toxic labels through thought chain reasoning, and give the evaluation results of semantically similar examples; If the generated toxicity labels are consistent, then the toxicity label is directly used to label the target text to be labeled in the current batch; When the generated toxicity labels are inconsistent, a debate mechanism is initiated, which allows all large language models to interact and debate in multiple rounds to determine the final toxicity label. Then, the target text to be labeled in the current batch is labeled to obtain the labeled target text. The iteration and optimization module is used for: The labeled target text is injected into the knowledge base, and data is continuously collected and labeled in an iterative manner. During the iteration process, the retrieval strategy of the retrieval machine is dynamically adjusted based on the evaluation results of semantically similar examples. At the same time, the performance of the retrieval machine is continuously optimized through an incremental learning mechanism to achieve the collection of toxic text.

Citation Information

Patent Citations

  • Domain-adaptive retrieval enhancement generation method and system

    CN119669400A

  • Tor corpus efficient labeling method based on RAG and comparative learning

    CN120123516A