Hatred speech identification method and system
By combining multi-model fine-tuning and reinforcement learning, the problems of fine-grained identification and group segmentation in existing hate speech identification technologies are solved, achieving efficient and accurate identification and personalized response to hate speech, and improving the robustness and interpretability of the model.
Patent Information
- Application Number
- CN202511170454.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-20
- Publication Date
- 2026-01-06
AI Technical Summary
Existing hate speech identification technologies suffer from insufficient fragment-level fine-grained identification capabilities, neglect of the segmentation of hate target groups, lack of human feedback learning mechanisms, and insufficient multi-model collaborative capabilities, resulting in insufficient identification accuracy and personalized response capabilities.
By combining multi-model fine-tuning with reinforcement learning, and through data augmentation, structured supervision, and human feedback signals, a reward model and ensemble mechanism are constructed to achieve accurate identification of hate speech and group segmentation, thereby improving the robustness and interpretability of the model.
It significantly improves the accuracy and consistency of hate speech identification, can dynamically adapt to language changes, enhances the ability to identify complex speech and provide personalized responses, and reduces the false positive and false negative rates.
Smart Images

Figure CN121278092A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing technology, specifically to a method and system for identifying hate speech. Background Technology
[0002] With the rapid development of internet technology, social media platforms have become important channels for people to express their opinions and share information. However, these platforms have also gradually evolved into hotspots for the spread of hate speech. Hate speech not only harms the feelings of specific individuals or groups and undermines social fairness and inclusivity, but may also trigger cyberbullying, social division, and even real-world conflicts. Therefore, how to achieve efficient and accurate identification and governance of hate speech in the social media environment has become an important issue that urgently needs to be addressed in the fields of cyberspace governance and artificial intelligence ethics.
[0003] Existing methods for identifying hate speech are mostly based on keyword matching, dictionary rules, or sentiment vocabularies. While these rule-based detection methods are low-cost and simple to implement, their accuracy and recall drop significantly when faced with hate texts that are obscure, ambiguous, or use variant words. They suffer from insufficient identification capabilities and high false positive rates, making them difficult to adapt to the complex and diverse linguistic phenomena in social contexts.
[0004] With the development of natural language processing technology, more and more research is beginning to use deep learning models (such as CNN, LSTM, Transformer, etc.) to model hate speech. These models can automatically learn implicit semantic features from large amounts of text, significantly improving the ability to identify ordinary hate text. However, they still have limitations when dealing with fine-grained, fragment-level hate speech, such as fuzzy recognition, unclear target localization, and insufficient contextual understanding.
[0005] Furthermore, most existing methods adopt a text-level overall judgment approach, which makes it difficult to extract structured information from multiple comment subjects and multiple offensive arguments in the same comment, thus limiting the model's interpretability and targeted processing ability for complex hate speech.
[0006] Although some studies have attempted to introduce multi-label classification methods based on pre-trained language models such as BERT, or to extract attack fragments through sequence labeling, these methods still mainly rely on static supervision signals, cannot dynamically respond to human feedback and value preferences, and are unstable in low-resource or domain-transfer scenarios.
[0007] Overall, existing hate speech detection technologies have the following shortcomings: 1) Lack of segment-level fine-grained recognition capability: Most methods only determine whether there is hatred in the text as a whole, but cannot accurately identify multiple comment objects and their corresponding arguments in a sentence, making it difficult to support subsequent intervention, review and behavior attribution.
[0008] 2) Ignoring the segmentation of target groups for hate: Existing systems often fail to clearly distinguish the specific groups targeted by hate, such as gender, race, region, etc., making it difficult to respond to governance measures in a personalized manner and affecting the assessment of social justice.
[0009] 3) Lack of human feedback learning mechanism: Although deep learning models have strong expressive power, the lack of human feedback signals (such as annotation corrections, review comments, etc.) during training limits the model's performance optimization space and interpretability improvement.
[0010] 4) Insufficient multi-model collaboration capability: Current methods are mostly based on end-to-end training of a single model, lacking modular and task-based modeling ideas, making it difficult to form effective collaboration when facing task decomposition (such as extraction-classification-group recognition). Summary of the Invention
[0011] To address the shortcomings of existing technologies, this invention provides a method and system for identifying hate speech, which has advantages such as accurately identifying hate speech and solves the aforementioned technical problems.
[0012] To achieve the above objectives, the present invention provides the following technical solution: a method for identifying hate speech, comprising the following steps: S1: Obtain publicly posted comments and opinions from multiple online platforms and construct a dataset; S2: Augment and preprocess the dataset in S1, and divide it into training, validation and test sets in a 7:2:1 ratio; S3: Based on model resources provided by platforms such as Huggingface, select an appropriate open-source base model; S4: Pre-train the base model selected in S3 to obtain the pre-trained base model; S5: Fine-tune the pre-trained base model in S4 to obtain a set of fine-tuned models consisting of several fine-tuned models; S6: Validate several fine-tuned models from the fine-tuned model set on the validation set and select the optimal model; S7: Construct the reward dataset. Use the optimal model from S6 to infer the validation set and compare it with the standard results and the inference results of the optimal model in the validation set. Extract different data and combine them to construct the reward dataset. S8: Construct a reward model, using the base model selected in S3 as the base model of the reward model, and train it using the reward dataset obtained in S7 to obtain the reward model. S9: Train the best model from S6 based on human feedback using the reward model from S8 and the training set from S2; S10: Repeat S9 for different fine-tuned models in S5 to obtain different large models based on human feedback. Combine them together and use the test set in S2 to let the different large models based on human feedback infer on them. After obtaining the inference results of different models, integrate them and select the final prediction result.
[0013] As a preferred embodiment of the present invention, the pre-training of the base model in S4 specifically involves using the training set constructed in S2. Pre-training is performed to obtain the pre-trained base model. The base model output expression is as follows: in, This represents the pre-training sample dataset. For model parameters, Indicates the first Input text, where U represents the total number of texts. Indicates to The prediction results and the loss function expression during the pre-training process are as follows: in, This represents the objective function that needs to be minimized. To express summation, Represented as a task-related loss function, This represents the quadruple tag structure obtained after preprocessing, specifically as follows: in, This indicates the loss in identifying the object of the comment and the argument. Indicates the loss in target group classification. The binary classification loss, indicating whether a model represents hatred, yields the optimal model parameters after pre-training. The specific expression is as follows: in, This represents finding the parameters that minimize the loss function.
[0014] As a preferred embodiment of the present invention, S5 specifically involves: processing the pre-trained base model from S4... Using the full supervised training set Supervised fine-tuning of the pre-trained pedestal model with different configurations was performed to obtain model sets under multiple configurations. , And for the first The loss function expression for this configuration is as follows: in, This indicates the full supervised training set. Indicates the first Input text, Indicates the total number of texts. This represents the quadruple tag structure obtained after preprocessing. Indicates the first Fine-tuning model under this configuration Indicates the first Trainable parameters under this configuration Indicates the first The training loss function under this configuration Indicates the first The task loss is calculated under various configurations, and the optimal parameters are obtained by training independently for each configuration. The training parameters of the configuration are obtained after training. Optimal model parameters after training under a certain configuration The specific expression is as follows: in, : This indicates selecting the parameters that minimize the loss function, ultimately resulting in a set of fine-tuned models. as follows: in, These represent the k fine-tuned models obtained by using k configurations in the above text.
[0015] As a preferred embodiment of the present invention, the specific steps for selecting the optimal model in S6 are as follows: S6.1: Fine-tuning the set of models in S5 Use validation set , For each fine-tuned model in the fine-tuned model set, a prediction result is generated on the validation set. The specific expression is as follows: in, Indicates the first The model for the first The predicted output of the validation sample, Indicates the first The input text for the validation sample, Represents the first vertex of the validation set. A real label, This represents the k-th model obtained after fine-tuning in S5; S6.2: Evaluate the result using the evaluation function, the specific expression of which is as follows: in, Indicates the first The F1 score of each model on the validation set Indicates the F1 score; S6.3: Select the optimal model, the specific expression is as follows: in, This indicates that the maximum score is taken for a model with a total of k. The model with the highest score is represented. This represents the final selected optimal fine-tuning model.
[0016] As a preferred embodiment of the present invention, the step of constructing the reward model in S8 is as follows: S8.1: Construct the reward function as follows: in, Represents the reward function, This represents the j-th input to the reward dataset. This represents the output corresponding to the j-th input. This indicates that the possible scores for the output of the j-th item are: The specific expression is as follows: in, Represents the first vertex of the validation set. A real label, This refers to the SoftMatch function; S8.2: The base model selected in S3 is used as the base model for the reward model, and the reward dataset obtained in S7 is used to train it. The loss function during training is either the mean squared error loss function or the contrastive loss function, and the reward model is finally obtained. .
[0017] The present invention also provides a hate speech identification system, based on the above-mentioned hate speech identification method, including a data augmentation module, a model training and selection module, a reinforcement learning and human feedback large model module, and a model integration module.
[0018] Compared with existing technologies, the present invention provides a method and system for identifying hate speech, which has the following beneficial effects: (1) Improve the accuracy and consistency of quadruple structure recognition: By introducing structured supervision signals and a soft matching strategy based on the longest common subsequence (LCS), the model enhances the recognition accuracy of the four elements such as “comment object”, “argument”, “target group” and “hate label”, which is significantly better than traditional classification or labeling methods. (2) Enhance the robustness of the model to extreme expressions and ambiguous language: The reward model can simulate expert evaluation and identify ambiguous boundaries with similar expressions but different semantics, thereby effectively distinguishing between "non-hate attack language" and "systemic hatred against groups". (3) Possesses self-learning and transfer capabilities: By introducing a near-end strategy optimization reinforcement learning mechanism, the model can continuously optimize the generation strategy based on new data, user feedback or test set performance, thereby adapting to dynamic changes such as topic shifts and the emergence of new vocabulary. (4) The fusion decision-making mechanism ensures the reliability of prediction: By integrating the outputs of multiple large models optimized by reinforcement learning based on human feedback, and using a majority voting mechanism to screen the structured output results, the prediction output is both comprehensive and consistent in language expression. Attached Figure Description
[0019] Figure 1 This is a schematic diagram of the structure of the present invention; Figure 2 This is a schematic diagram of the structure of the present invention. Detailed Implementation
[0020] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. 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.
[0021] Please see Figures 1-2 A method for identifying hate speech includes the following steps: S1: Collect user comments from various online platforms and construct a dataset; S1.1: Crawling network data Web scraping technology was used to crawl comments posted by users on various platforms. To ensure data diversity, comments from large online platforms with a large number of users, such as Weibo and Douyin, were scraped. Comments that were too short or too long were removed. The standard for being too short was less than 10 characters, and the standard for being too long was more than 40 characters. This was done to make it easier for the model to learn the text features of the Chinese language.
[0022] S1.2: Find datasets on GitHub related to hate detection. To further ensure the validity of the data, we searched for hate detection datasets on the public platform GitHub. However, since there are too few Chinese hate detection datasets, we used datasets in other languages, such as Spanish and English, and used Google Translate to translate them into Chinese. Combined with the online speech data in S11, we obtained a preliminary dataset, which will then undergo further data processing. S2: Augment and preprocess the dataset in S1, and divide it into training, validation and test sets in a 7:2:1 ratio; S2.1: Manual processing For the initial dataset, manual annotation based on human feedback is performed. The annotation process involves two steps, and the specific method is as follows: S2.1.1: Identify the subject and argument of the comment. From the comments in the initial dataset, extract the comment subject and argument. The comment subject refers to the recipient of the comment, such as an individual or a group. Set to NULL if the instance has no specific target. An argument is a snippet of information containing key points relevant to the comment's target. The tagging format is: Comment Subject | Argument. If multiple arguments exist within a single statement, separate them with [SEP], such as Comment Subject | Argument [SEP] Comment Subject | Argument.
[0023] S2.1.2: Identify the target group and determine if there is hatred. Further annotate the original comments and labeled information in S2.1.1, adding the elements of target group and whether it is hate speech. Target group refers to the target group involved in the comment-argument pair containing hate speech. The labeled target groups include five categories: "Region," "Race," "Gender," "LGBTQ," and "Other." Whether it is hate speech refers to whether the comment-argument pair constitutes hate speech against certain groups.
[0024] The tag format is as follows: Target Group | Hate Status. If a statement contains multiple target groups, separate them with [SEP], such as Target Group | Hate Status [SEP]Target Group | Hate Status.
[0025] Finally, the two results are merged, and the final form is a four-tuple of: Comment Subject | Argument | Target Group | Whether there is hatred.
[0026] S2.2: Data Augmentation and Preprocessing The dataset after step S2.1 undergoes data augmentation and preprocessing, specifically following these steps: S2.2.1: Analyze the dataset To ensure that the model can evenly learn the features of hate speech categories during training, such as five target groups, hate and non-hate, etc., the dataset after step S2.1 is analyzed. The main analysis is on the quantity of each category in the target group and the quantity of hate and non-hate. For those with too little quantity, they are increased, and for those with too much quantity, they are decreased to achieve data volume balance, improve the effectiveness of model training, as well as the accuracy and robustness of hate speech recognition.
[0027] S2.2.2: Synonym replacement To enhance the data, a dataset for synonym replacement is searched online, such as datasets where "like" can be replaced with "seemingly", "as if", etc. Then, the dataset after step S221 is subjected to synonym replacement, aiming to improve the model's Chinese understanding ability and the robustness of hate recognition through data augmentation.
[0028] S2.2.3: Preprocessing To remove invalid data, the dataset obtained in S2.2.2 is preprocessed: for example, removing data that does not conform to the quadruple form such as comment object | argument | target group and data that does not conform to the five categories in the target group such as comment object | argument | target group (ethnic group) | whether it is hate.
[0029] S224: Divide the training set, validation set and test set To better train the model, the dataset in S223 is divided into a training set, a validation set and a test set according to the ratio of 7:2:1. Next is to select the base model; S3: Based on the model resources provided by platforms such as Huggingface, select a suitable open-source base model S3.1: Analyze the task content To enable the model to have better initial performance, the entire task is analyzed in detail, such as what capabilities are required, what requirements there are for input and output, etc., and which language has better understanding and output capabilities. Then, a model is selected based on the above analysis.
[0030] S3.2: Select the model After step S31, a suitable base model can be downloaded from Huggingface or the Magic Square Community. In this embodiment, GLM4-9b-chat is selected, and then the selected base model is subjected to preliminary pre-training; S4: Pre-train the base model selected in S3 to obtain the pre-trained base model; S4.1: Construct the pre-training objective function Let the base model be (where (For model parameters), let the training set constructed by S2 be... Take a portion for pre-training, and then define the target function for pre-training.
[0031] Pre-training objective function: Let the model output be Its loss function is set as follows: in: The pre-training sample dataset accounts for one-tenth of the entire training set, and its specific form is as follows: D1:(original comments, labeled information: comment subject | argument | target group | whether it is hateful); : for the first The specific format of the input text is the same as the original statement in D1; : For model pairs The prediction results; : The corresponding four-tuple tag structure is the same as the information labeled in D1 (such as the comment subject | argument | target group | whether it is hateful); : This is the task-related loss function. Since this task is a structured extraction task, multiple sub-task losses can be combined, with weights evenly distributed. ; : Loss for identifying comment subjects and arguments (sequence labeling tasks, such as using cross-entropy); Target group classification loss, such as the five categories of "region", "race", "gender", "LGBTQ" and "other"; : Binary classification loss based on whether there is hatred or no hatred. The entire formula represents the total pre-training loss function, which is the average loss of the model on the entire pre-training dataset, thus yielding the optimization objective. The optimization objective formula is as follows: ; Optimal model parameters after training; : indicates finding the parameters that minimize the loss function; : The objective function that needs to be minimized.
[0032] By minimizing the above pre-training, the base model is initially updated with parameters, enabling it to have a preliminary understanding of the hate quadruple structure and the structured output patterns in the hate speech identification task. This improves its ability to express and generalize targets, arguments, group types, and hate labels, laying the foundation for subsequent supervised fine-tuning and reinforcement learning training. S5: Fine-tune the pre-trained base model in S4 to obtain a set of fine-tuned models consisting of several fine-tuned models; Specifically, this refers to the pre-trained pedestal model in S4. Using the full supervised training set in S2 Supervised fine-tuning of the pre-trained pedestal model with different configurations was performed to obtain model sets under multiple configurations. , And for the first The loss function expression for this configuration is as follows: in, This indicates the full supervised training set. Indicates the first Input text, Indicates the total number of texts. This represents the quadruple tag structure obtained after preprocessing. Indicates the first Fine-tuning model under this configuration Indicates the first Trainable parameters under this configuration Indicates the first The training loss function under this configuration Indicates the first The task loss is calculated under various configurations, and the optimal parameters are obtained by training independently for each configuration. The training parameters of the configuration are obtained after training. Optimal model parameters after training under a certain configuration The specific expression is as follows: in, : This indicates selecting the parameters that minimize the loss function, ultimately resulting in a set of fine-tuned models. as follows: in, These represent the k fine-tuned models obtained by using k configurations in the above text. Depending on the configuration, different task losses (such as sequence labeling loss, classification loss, generation loss, etc.) can be combined. The configuration differences may be reflected in: optimizer parameters (such as learning rate), input format (such as Prompt style) or training strategy (such as Early Stopping, Reweighting, etc.). The optimization objective is to train independently for each configuration to obtain the corresponding optimal parameters, that is, to find the parameter combination that minimizes the loss. ; These models will be used in subsequent steps; S6: Validate several fine-tuned models from the fine-tuned model set on the validation set and select the optimal model; The specific steps for selecting the optimal model in S6 are as follows: S6.1: Fine-tuning the set of models in S5 Use validation set , For each fine-tuned model in the fine-tuned model set, a prediction result is generated on the validation set. The specific expression is as follows: in, Indicates the first The model for the first The predicted output of the validation sample, Indicates the first The input text for the validation sample, Represents the first vertex of the validation set. A real label, This represents the k-th model obtained after fine-tuning in S5; S6.2: Evaluate the result using the evaluation function, the specific expression of which is as follows: in, Indicates the first The F1 score of each model on the validation set Indicates the F1 score; The F1 score can be calculated based on the task requirements, including hard-match F1, soft-match F1, or their weighted average: in: : No. The F1 score of each model on the validation set; and and Take the average score, hard match, and soft match respectively; S6.3: Select the optimal model, the specific expression is as follows: in, This indicates that the maximum score is taken for a model with a total number of k. The model with the highest score is represented. This represents the final selected optimal fine-tuning model; S7: Construct the reward dataset. Use the optimal model from S6 to infer the validation set and compare it with the standard results and the inference results of the optimal model in the validation set. Extract different data and combine them to construct the reward dataset. S71: Definition of Optimal Model and Validation Set Let the optimal fine-tuning model selected in S6 be: The validation dataset is denoted as: in: : No. The input text for the validation sample; : Corresponding to the A true structured output; Total number of samples in the validation set; S72: Reasoning Stage For each validation sample, the optimal model is used for inference to obtain the prediction result: in The structured prediction output generated for the model.
[0033] S73: Definition of Differential Sample Screening Function To select samples with "inconsistent predictions", a difference judgment function is introduced. The definition is as follows: This function will be used to mark which samples should be included in the reward dataset.
[0034] S74: Formula for Constructing the Reward Dataset Based on the difference judgment function in S73, samples with incorrect predictions are selected from the validation set to construct the reward dataset: in: : Enter text; The predicted output generated by the model; Standard answer; This reward dataset Specifically designed for training reward models .
[0035] In this step, based on the optimal fine-tuned model selected in S6, inference is performed on the validation set, and the prediction results are compared with the standard answers. Samples with inconsistent predictions are then selected and used to train the reward model. This reward model will be used for reinforcement learning optimization (PPO) in subsequent steps. S8: Construct a reward model, using the base model selected in S3 as the base model of the reward model, and train it using the reward dataset obtained in S7 to obtain the reward model. The steps to build a reward model in S8 are as follows: S8.1: Construct the reward function as follows: in, Represents the reward function, This represents the j-th input to the reward dataset. This represents the output corresponding to the j-th input. This indicates that the possible scores for the output of the j-th item are: The specific expression is as follows: in, Represents the first vertex of the validation set. A real label, This refers to the SoftMatch function; The SoftMatch function is defined as follows: ; Where LCS represents the length of the longest common subsequence between the predicted result and the actual result; if SoftMatch ≥ 0.5, it is considered to be structurally similar and semantically similar, and a reward of 0.5 is given; otherwise, a penalty of -1 is given. S8.2: The base model selected in S3 is used as the base model for the reward model, and the reward dataset obtained in S7 is used to train it. The loss function during training is either the mean squared error loss function or the contrastive loss function, and the reward model is finally obtained. ; S8.3: Selection of Loss Function The training objective is to improve the reward value predicted by the model. This means learning to fit a score to the quality of the sample output, so the mean squared error (MSE) loss function is used: Alternatively, a function contrastive learning loss function can be used, referencing the answer. With predicted output Training can be performed by ranking positive and negative sample pairs, or contrastive loss can be used: ; The model's score for good answers minus the model's score for bad answers. Find the average value of the log-hyperbolic loss function, with the goal of making... .
[0036] Whether using regression or comparison methods, the ultimate goal of the reward model is: in: : The optimal reward model parameters obtained after training.
[0037] This step aims to train a reward model using the reward dataset built in S7. It is used to evaluate the quality of the results generated by large models and to provide high-quality reward signals for subsequent reinforcement learning (PPO); S9: Train the best model from S6 based on human feedback using the reward model from S8 and the training set from S2; S9.1: Participation in Model Definition The strategy model, specifically the optimal fine-tuning model in S6, has the following parameters: , as the initial model for PPO reinforcement learning; The reward model, i.e., the reward function trained in S8, serves as environmental feedback for evaluating the quality of generation. The reference model is a frozen old policy (or the original fine-tuned model itself) used to stabilize training and constrain policy updates. S9.2: Reinforcement Learning Training Data Generation Sample a batch of data from the input set of S2. The response (quadruple) is generated from the current policy model: Then, a reward model was used to score it: The training data obtained are: In the PPO algorithm, the goal is to maximize the weighted policy expected return while limiting the policy update magnitude to avoid training instability. Therefore, the objective function of PPO is defined as: in: The policy probability ratio; if it exceeds... If the new strategy has a much higher probability of taking this action than the old strategy, then it will be cut off. If it is lower than If the probability of the new strategy taking this action is much lower than that of the old strategy, then it will be cut off. . The advantage function represents how much better the generated action is than expected; it is typically estimated as follows: In; among them This indicates that the baseline (the average reward at the i-th time or the value head during training) is not a fixed hyperparameter, but is estimated by a separately trained neural network (often called the "value head" or "critic"). The shearing threshold controls the update magnitude of the strategy; in this embodiment, it is set to 0.1. PPO is a key operation to prevent excessive changes and improve training stability.
[0038] Other hyperparameters for PPO training were set as follows: learning rate of 5e-5, number of iterations of 4, and KL divergence penalty coefficient of 0.02. in: : Policy probability ratio; The advantage function represents how much better the generated action is than expected; it is typically estimated as follows: in , : Indicates baseline (such as reward average or valuehead during training); : Shearing threshold, controls the update magnitude of the strategy (e.g., 0.1); The key operation of PPO is to prevent the policy from going too far and improve training stability. The policy model parameters are updated by minimizing the PPO loss. : Specifically, the training dataset in S2 will be used first. Input to policy model The output is obtained using a reward model. The model is scored, and then the PPO algorithm is used to evaluate the strategy model based on the scores. Reference Model The algorithm is updated; if the score is positive, the PPO algorithm is used to positively optimize the policy model; if the score is negative, no update is performed. The final result is a large model that has been reinforced and optimized using reinforcement learning based on human feedback. ; S10: Repeat S9 for different fine-tuned models in S5 to obtain different large models based on human feedback. Combine them and use the test set in S2 to let different large models based on human feedback infer on them. After obtaining the inference results of different models, integrate them and select the final prediction result. The steps for building the ensemble model and generating the final results are as follows: Building an ensemble model and using a voting mechanism for inference results Suppose that K fine-tuning models with different configurations are obtained in S5: Execute S9 on each of these K fine-tuning models, using the reward model. Optimization based on human feedback (RLHF) is performed to obtain a set of enhanced policy models: Let the test set be: For each test sample Inference was performed using each RLHF model, and the following results were obtained: in Indicates the first The model for the first The structured prediction results of the sample are in the form of a sequence consisting of multiple hate quadruples.
[0039] Integration Mechanism: Voting Fusion for the First The test samples are used to create a set of four tuples output by all models: For each candidate quadruple Count the number of times it appears in different models: in It is an indicator function (1 if the quadruple is included, 0 otherwise). Set voting threshold This means that more than half of the models agree, so the quadruple is retained. The final output is: Write the final predicted quadruple set for each test sample into the results file to form the final output: Specifically, the first step is to fine-tune the model set in S5. Step S9 yields the model set. Using the test set Input to model set The output of the entire model set is The output results are counted to determine the frequency of occurrence, and the result with a frequency exceeding half of the total frequency is taken as the final model output. Finally, the output results are saved in the format of a quadruplet extraction task, and evaluated using the S6 evaluation function to obtain the final evaluation result. This invention provides an integrated method for large language models based on Human Feedback Reinforcement Learning (RLHF) and data augmentation, specifically addressing the problem of hate speech identification in Chinese social media. It is the first to organically combine fine-grained structure extraction, human feedback learning, reward modeling, and reinforcement learning. By dividing the hate speech identification task into two stages—structure recognition and attitude judgment—and introducing reward function modeling and PPO policy optimization, this invention significantly improves the model's ability to identify hidden hate intentions in complex speech. The RLHF training scheme of this invention introduces human feedback to simulate reward signals and uses reinforcement learning to optimize the generation strategy of the language model. This compensates for the semantic boundary ambiguities that traditional supervised learning cannot cover, enhancing controllability and interpretability while maintaining linguistic freedom. Especially when dealing with sensitive groups such as region, race, gender, and LGBTQ+, the model can learn from feedback how to more accurately distinguish between offensive and hate speech, thereby reducing false positive and false negative rates. This invention further introduces an integrated mechanism for multi-model parallel training and prediction output. Specifically, multiple models are fine-tuned under various prompt configurations, hyperparameters, and input templates, and RLHF optimization is performed on each model. Finally, a voting mechanism is used to fuse the inference results of multiple models, forming a more stable and robust final prediction output, which significantly improves the system's adaptability to different input styles and expression methods.
[0040] This invention also provides a hate speech identification system, based on the aforementioned hate speech identification method, comprising a data augmentation module, a model training and selection module, a reinforcement learning and human feedback large model module, and a model ensemble module. Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A method of hate speech recognition, characterized by: Comprise the following steps: S1: Obtain user public comments data from multiple network platforms, and form a data set; S2: Enhance and preprocess the data set in S1, and divide the training set, validation set and test set according to 7:2:1; S3: Select an open source base model based on the model resources provided by the Huggingface platform; S4: Pretrain the base model selected in S3 to obtain a pre-trained base model; S5: Fine-tune the pre-trained base model in S4 to obtain a fine-tuned model set consisting of several fine-tuned models; S6: Verify the several fine-tuned models in the fine-tuned model set on the validation set, and select the optimal model; S7: Construct a reward data set, infer the validation set by the optimal model in S6, and compare the standard results in the validation set with the inference results of the optimal model, put forward different data, and combine to construct the reward data set; S8: Construct a reward model, use the base model selected in S3 as the base model of the reward model, and train it using the reward data set obtained in S7 to obtain the reward model; S9: Use the reward model in S8 and the training set in S2 to train the optimal model in S6 based on human feedback; S10: Repeat S9 for different fine-tuned models in S5 to obtain different human feedback based large models, combine them together, use the test set in S2, let different human feedback based large models infer it, after obtaining the inference results of different models, integrate them, and select the final prediction result.
2. The method of claim 1, wherein: The pre-training of the base model in S4 is specifically: using the training set constructed in S2 The base model is pre-trained to obtain a pre-trained base model The output expression of the base model is as follows: wherein, denotes a pre-training sample dataset, is a model parameter, denotes the first input text, U denotes the total number of texts, denotes the prediction result of the loss function expression in the pre-training process is as follows: wherein, denotes an objective function to be minimized, denotes a summation, denotes a loss function associated with the task, denotes a quadruple label structure obtained after preprocessing, which is specifically represented as: wherein, represents the argument-object and argument-identification loss, represents the target group classification loss, represents the binary classification loss of whether hatred, and the trained optimal model parameters are obtained after pre-training is completed The specific expression is as follows: wherein, denotes the parameters that minimize the loss function.
3. The method of claim 2, wherein: The S5 is specifically: for the base model pre-trained in S4 Using a full amount of supervised training set , the pre-trained base model is supervised fine-tuned in different configurations to obtain a model set in multiple configurations , , and the loss function expression of the first configuration is as follows: wherein, represents a full amount of supervised training set, represents the first input text, represents the total number of texts, represents a quadruple label structure obtained after preprocessing, represents the first fine-tuning model under the configuration, represents the first trainable parameters under the configuration, represents the first training loss function under the configuration, represents the first task loss under the configuration, and each configuration is independently trained to obtain the corresponding optimal parameters, wherein the first trainable parameters under the configuration are trained to obtain the optimal model parameters after training under the first configuration , and the specific expression is as follows: wherein, : represents taking the parameters that minimize the loss function, resulting in a set of fine-tuned models as follows: wherein, respectively represent k fine-tuned models obtained by fine-tuning using k configurations.
4. The method of claim 3, wherein: The specific steps of selecting the optimal model in S6 are: S6.1: generating prediction results on the validation set for each fine-tuned model in the fine-tuned model set using the validation set , , generating prediction results on the validation set for each fine-tuned model in the fine-tuned model set, specifically expressed as follows: wherein, represents the prediction output of the kth model on the ith validation sample, represents the input text of the ith validation sample, represents the ith true label of the validation set, represents the kth model obtained by fine-tuning in S5; S6.2: Evaluate the results using the evaluation function, and the specific expression is as follows: wherein, denotes the F1 score of the denotes the F1 score; S6.3: Select the optimal model, and the specific expression is as follows: wherein, denotes the maximum value of the score of the models with a total number k, denotes the model with the highest score, denotes the final selected optimal fine-tuned model.
5. The method of claim 1, wherein: The steps of constructing the reward model in S8 are as follows: S8.1: Construct the reward function as follows: wherein, represents a reward function, represents the jth input of the reward dataset, represents the output corresponding to the jth input, represents the score for the jth output, and is expressed as follows: wherein, represents the first true label, represents the SoftMatch function; S8.2: using the base model selected in S3 as the base model of the reward model, and training it using the reward dataset obtained in S7, the loss function in the training process being a mean square error loss function or a contrastive loss function, and finally obtaining the reward model .
6. A hate speech recognition system characterized in that: A hate speech recognition method for executing any one of claims 1-5.
