Label matching model training method and device, computer equipment and storage medium
By using a tag matching model generated through data distillation and training with a low-rank matrix, the problem of insufficient accuracy in vector retrieval was solved, resulting in an efficient legal question-and-answer system that improves user experience and system efficiency.
Patent Information
- Application Number
- CN202510759806.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-06
- Publication Date
- 2025-10-31
AI Technical Summary
Among existing question-answering methods, vector retrieval is not very accurate, especially when the user question is short and the legal provision is long, the matching effect is poor, and the user question and the legal provision are very different, resulting in unsatisfactory matching results.
By acquiring question-and-answer data from a predefined domain, extracting questions and answers, performing data distillation to streamline the label set, forming a training dataset, and then training the initial transformer model with labels, adjusting the weights using a low-rank matrix to generate a label matching model.
It significantly improved the accuracy of matching questions with regulatory tags, achieved an efficient question-and-answer system, and enhanced user experience and system efficiency.
Smart Images

Figure CN120873115A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of model training technology, and more particularly to the training of a label matching model. Background Technology
[0002] Currently, most commonly used question-answering methods employ the Retrieval Augmented Generation (RAG) model. The specific process is as follows: First, a vector library is constructed based on regulations and related tags. Each legal provision is broken down and vectorized using a vector model, then stored in the vector database. When a user inputs a question, the question is vectorized, and the legal provision with the highest similarity to the user's question is retrieved from the existing vector library based on vector similarity. Finally, the retrieved list of legal provisions is used as reference material, concatenated with the user's question and prompts, and input into a large language model to obtain the answer.
[0003] However, existing technologies have significant drawbacks. On the one hand, vector retrieval is not very accurate; when the user question is relatively short while the legal provisions in the vector library are long, the matching effect is difficult to achieve the expected results. On the other hand, there are significant differences between the wording of the user question and the legal provisions, making it difficult to obtain ideal results by relying solely on vector matching. Summary of the Invention
[0004] Therefore, it is necessary to address the training problem of existing label matching models and propose a training method for label matching models.
[0005] A method for training a label matching model, the method comprising:
[0006] Acquire multiple sets of question-and-answer data within a preset domain;
[0007] Extract the questions and answers from each set of question-and-answer data, as well as the preset domain tag set from each set of question-and-answer data;
[0008] The preset domain tag set is simplified by using a preset data distillation technique to obtain a simplified preset domain tag set, thereby obtaining multiple sets of target question and answer data; one set of target question and answer data includes the question and the simplified preset domain tag set.
[0009] A training dataset is formed based on multiple sets of the target question-and-answer data;
[0010] The data in the training dataset are sequentially input into the preset initial transformer model, and trained in a labeled manner to obtain the label matching model.
[0011] Furthermore, before the step of extracting the questions and answers from each group of question-and-answer data, and the preset domain tag set from each group of question-and-answer data, the method further includes:
[0012] Remove the Hypertext Markup Language tags from each of the question-and-answer data to obtain the corresponding temporary question-and-answer data;
[0013] Each set of temporary question-and-answer data is organized into a preset data format to obtain labeled question-and-answer data.
[0014] Furthermore, the step of acquiring multiple sets of question-and-answer data in a preset domain includes:
[0015] The rules of the preset domain are sent to the preset language model to obtain multiple domain questions of the preset domain;
[0016] The questions in each of the aforementioned fields are sent to a designated terminal, and the answers are obtained from the designated terminal.
[0017] The question-and-answer data is composed of questions from various fields and their corresponding answers.
[0018] Furthermore, the step of forming a training dataset based on multiple sets of the target question-answering data includes:
[0019] The number of target question-and-answer data corresponding to each preset domain label in the simplified preset domain label set of multiple sets of target question-and-answer data is lower than a preset value;
[0020] Record the preset domain labels that are lower than the preset values as the target preset domain labels;
[0021] The target question-and-answer data for each target preset domain label is supplemented until the target question-and-answer data corresponding to each target preset domain label reaches the preset value. The training dataset is obtained by combining the question-and-answer data of each target.
[0022] Further, the step of sequentially inputting the data from the training dataset into a preset initial transformer model and training it in a labeled manner to obtain a label matching model includes:
[0023] A low-rank matrix is added to the original weight matrix of each layer of the preset initial transformer model;
[0024] The data in the training dataset are sequentially input into the preset initial transformer model, and training is performed in a labeled manner. During the training process, the original matrix is frozen and the parameters in the low-rank matrix are updated.
[0025] After training, a label matching model is obtained.
[0026] Further, after the step of sequentially inputting the data from the training dataset into a preset initial transformer model and training it in a labeled manner to obtain a label matching model, the method further includes:
[0027] Obtain the current question and input it into the label matching model to obtain the current label set corresponding to the current question;
[0028] Based on the current tag set, retrieve the current dataset corresponding to the preset domain tags from the database;
[0029] Search for answers from the current dataset based on the current question.
[0030] Furthermore, the step of forming a training dataset based on multiple sets of the target question-answering data includes:
[0031] The number of target question-and-answer data corresponding to each preset domain label in the simplified preset domain label set of multiple sets of target question-and-answer data is higher than a threshold.
[0032] Record the preset domain labels that are higher than the threshold as temporary preset domain labels;
[0033] The target question-and-answer data corresponding to each temporarily preset domain label is downsampled until the target question-and-answer data corresponding to each temporarily preset domain label is lower than or equal to the threshold, thereby obtaining the training dataset.
[0034] A training apparatus for a label matching model, the apparatus comprising:
[0035] The acquisition module is used to acquire multiple sets of question-and-answer data in a preset domain;
[0036] The extraction module is used to extract the questions and answers from each set of question-and-answer data, as well as the preset domain tag set from each set of question-and-answer data;
[0037] The processing module is used to simplify the preset domain tag set using a preset data distillation technique to obtain a simplified preset domain tag set, thereby obtaining multiple sets of target question and answer data; one set of target question and answer data includes a question and a simplified preset domain tag set.
[0038] A forming module is used to form a training dataset based on multiple sets of the target question-and-answer data;
[0039] The training module is used to sequentially input the data in the training dataset into a preset initial transformer model, and train it in a labeled manner to obtain a label matching model.
[0040] A computer device includes a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the following steps:
[0041] Acquire multiple sets of question-and-answer data within a preset domain;
[0042] Extract the questions and answers from each set of question-and-answer data, as well as the preset domain tag set from each set of question-and-answer data;
[0043] The preset domain tag set is simplified by using a preset data distillation technique to obtain a simplified preset domain tag set, thereby obtaining multiple sets of target question and answer data; one set of target question and answer data includes the question and the simplified preset domain tag set.
[0044] A training dataset is formed based on multiple sets of the target question-and-answer data;
[0045] The data in the training dataset are sequentially input into the preset initial transformer model, and trained in a labeled manner to obtain the label matching model.
[0046] A computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to perform the following steps:
[0047] Acquire multiple sets of question-and-answer data within a preset domain;
[0048] Extract the questions and answers from each set of question-and-answer data, as well as the preset domain tag set from each set of question-and-answer data;
[0049] The preset domain tag set is simplified by using a preset data distillation technique to obtain a simplified preset domain tag set, thereby obtaining multiple sets of target question and answer data; one set of target question and answer data includes the question and the simplified preset domain tag set.
[0050] A training dataset is formed based on multiple sets of the target question-and-answer data;
[0051] The data in the training dataset are sequentially input into the preset initial transformer model, and trained in a labeled manner to obtain the label matching model.
[0052] The beneficial effects of this invention are: it significantly improves the accuracy of matching questions with legal tags, effectively solves the matching problem caused by the difference between user questions and legal provisions, and enables the generated tag matching model to automatically match user questions with corresponding domain tags, thereby realizing an efficient question-and-answer system in practical applications and significantly improving user experience and system efficiency. Attached Figure Description
[0053] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0054] in:
[0055] Figure 1 This is a diagram illustrating the application environment of a training method for a label matching model in one embodiment.
[0056] Figure 2 This is a flowchart of a training method for a label matching model in one embodiment;
[0057] Figure 3 This is a structural block diagram of a training device for a label matching model in one embodiment;
[0058] Figure 4 This is a structural block diagram of a computer device in one embodiment. Detailed Implementation
[0059] 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.
[0060] Figure 1 This is a diagram illustrating the training application environment of a label matching model in one embodiment. (Refer to...) Figure 1 The training method for this label matching model is applied to a training system for the label matching model. This training system includes a terminal 110 and a server 120. The terminal 110 and server 120 are connected via a network. The terminal 110 can be a desktop terminal or a mobile terminal; a mobile terminal can be at least one of a mobile phone, tablet, or laptop. The server 120 can be a standalone server or a server cluster consisting of multiple servers. The terminal 110 is used to acquire multiple sets of question-and-answer data in a preset domain, and the server 120 is used to train the label matching model.
[0061] like Figure 2 As shown, in one embodiment, a method for training a label matching model is provided. This method can be applied to both terminals and servers; this embodiment uses server application as an example. The training method for the label matching model specifically includes the following steps:
[0062] S1: Obtain multiple sets of question-and-answer data in a preset domain;
[0063] S2: Extract the questions and answers from each group of question-and-answer data, as well as the preset domain tag set from each group of question-and-answer data;
[0064] S3: The preset domain tag set is simplified by a preset data distillation technique to obtain a simplified preset domain tag set, thereby obtaining multiple sets of target question and answer data; one set of target question and answer data includes the question and the simplified preset domain tag set.
[0065] S4: Form a training dataset based on multiple sets of target question-and-answer data;
[0066] S5: Input the data in the training dataset into the preset initial transformer model in sequence, and train it in a labeled manner to obtain the label matching model.
[0067] As described in step S1 above, acquire multiple sets of question-and-answer data for a preset domain. It is necessary to clearly define the application domain for tag matching, such as finance, healthcare, and law. Based on the selected domain, collect relevant question-and-answer datasets. This data can come from various channels, such as customer service records, online chat content, social media Q&A, and professional literature. Furthermore, it should be ensured that the acquired data is representative; multiple sets of question-and-answer data should cover various question types and answer structures to form a comprehensive data foundation. Of course, during the data collection process, it is essential to ensure compliance with relevant data protection laws and privacy policies.
[0068] As described in step S2 above, questions and answers, as well as a preset domain tag set, are extracted from each set of question-and-answer data. After collecting multiple sets of question-and-answer data, the "questions" and "answers," along with their associated "preset domain tag sets," are extracted. The extraction of questions should focus on key points of interest to users, while answers should contain valid information. These tag sets should reflect the main themes or domain-related concepts involved in the question-and-answer data. Data extraction can be automated using natural language processing techniques, such as entity recognition and keyword extraction, to ensure that the generated tags effectively represent the core content of each set of questions and answers. It should be noted that the preset domain tag set includes at least one or more preset domain tags, which are manually set in advance based on preset domains.
[0069] As described in step S3 above, the preset domain label set is simplified using a preset data distillation technique to obtain a simplified preset domain label set, thereby obtaining multiple sets of target question-and-answer data. The purpose of data distillation is to simplify the preset domain label set to improve the usability and effectiveness of the labels. Data distillation techniques can be implemented in various ways, such as using clustering algorithms to identify the similarity between labels and merging similar labels, or using dimensionality reduction techniques to reduce the complexity of the label space, or calculating the correlation between labels and questions using cosine similarity and deleting labels with a correlation lower than a preset threshold. In a specific embodiment, since the preset domain label set generally includes multiple preset domain labels, here the preset domain labels with low correlation to the questions are deleted to obtain simplified preset domain labels. The correlation can be calculated by calculating the cosine similarity between the preset domain labels and the question-and-answer data, or by calculating the Pearson correlation coefficient, etc. A threshold is set, and preset domain labels with a correlation lower than the threshold are deleted, making the model trained based on the above data more accurate and responsive in practical applications.
[0070] As described in step S4 above, a training dataset is formed based on multiple sets of target question-and-answer data. After data simplification, the multiple sets of target question-and-answer data are integrated into a single training dataset. During the integration process, the data can be organized, standardized, and formatted to ensure that the input data meets the requirements for model training. Generally, the training dataset should contain questions and corresponding labels, enabling the model to learn the relationship between questions and labels. Furthermore, the dataset needs to be divided into training, validation, and test sets for model performance evaluation during subsequent training. Data preprocessing may also involve noise removal, handling missing values, and data augmentation to improve the model's generalization ability. After this series of processing steps, the resulting training dataset will lay the foundation for effective learning of the model.
[0071] As described in step S5 above, the data in the training dataset are sequentially input into the preset initial transformer model for training using a labeled approach, resulting in a label matching model. The constructed training dataset is then input into the preset initial transformer model for training. The model receives each set of input questions and their corresponding labels, learning through a labeled approach. Because the transformer model has powerful expressive capabilities, it can learn complex patterns and relationships in the input data. The model training process involves adjusting hyperparameters and optimizing the loss function to improve the model's accuracy and robustness. The training effect can be evaluated using a validation set. During optimization, the model's performance on the validation set needs to be observed to avoid overfitting and ensure good generalization ability on new data. Finally, after multiple iterations of training, the generated label matching model can automatically match user questions with corresponding domain labels, thereby achieving an efficient question-answering system in practical applications.
[0072] In one embodiment, before step S2 of extracting the questions and answers from each set of question-and-answer data, and the preset domain tag set from each set of question-and-answer data, the method further includes:
[0073] S101: Remove the Hypertext Markup Language tags from each of the question-and-answer data to obtain the corresponding temporary question-and-answer data;
[0074] S102: Organize each group of temporary question and answer data into a preset data format to obtain labeled question and answer data.
[0075] As described in steps S101-S102 above, when processing raw question-and-answer data, text containing Hypertext Markup Language (HTML) tags is often encountered. These tags are used for webpage layout and formatting, such as headings, paragraphs, links, and images. While they provide a good user display in browsers, these tags have no practical meaning for data analysis and natural language processing, and may even affect the quality of model learning. Therefore, it is necessary to first remove these HTML tags to obtain clean text data. The process of removing HTML tags can be achieved using various tools and programming languages, such as Python's BeautifulSoup library and regular expressions. After removing tags, the resulting text content will be more concise. Furthermore, the cleanliness of the data helps reduce noise in subsequent analysis, improves data quality, and provides a more accurate foundation for later model training and inference. By eliminating potentially redundant information and ensuring that only the actual user input (questions) and corresponding answers are considered, the data's processability is greatly improved, laying a solid foundation for the next step of data preparation. After removing Hypertext Markup Language (HTML) tags, the temporary question-and-answer (Q&A) data is formatted into a standardized format to ensure the dataset conforms to the necessary structure for subsequent processing and analysis. Annotated Q&A data not only improves readability but also facilitates subsequent machine learning model training. The standardization process typically involves defining each field of the data; for example, the format of Q&A data might include the question, answer, and their corresponding tags. The order and structure of these fields need to be consistent with the expected format in subsequent steps. Formats such as JSON, CSV, or database tables are commonly used to manage the annotated data. This standardization ensures that the data is stored in a consistent and easily manageable manner, enabling subsequent algorithms and processing to access and manipulate this data efficiently and smoothly. Furthermore, a certain degree of data validation can be performed during the formatting process, such as checking data integrity, verifying tag consistency, and ensuring no key information is missing. The goal of this stage is to clearly define the content of each data set, enabling the system to effectively utilize this information for tag matching and model training in subsequent steps.
[0076] In one embodiment, step S1 of acquiring multiple sets of question-and-answer data in a preset domain includes:
[0077] S101: Send the rules of the preset domain to the preset language model to obtain multiple domain questions of the preset domain;
[0078] S102: Send the questions in each of the aforementioned domains to the designated terminal and obtain the answers from the designated terminal;
[0079] S103: The question-and-answer data is composed of questions from various fields and the corresponding answers.
[0080] As described in steps S101-S103 above, the question-and-answer data is acquired. Specifically, regulations or related document information from a predefined domain are input into a predefined language model. The purpose is to leverage the language model's understanding and reasoning capabilities to extract domain questions with potential practical application value from professional regulatory documents. First, the input regulations can include provisions, laws and regulations, industry standards, guidelines, etc., typically covering various aspects of the domain. The language model analyzes these texts using Natural Language Processing (NLP) technology, identifying important concepts, wording, and logical relationships, and then generates related domain questions. These questions may involve discussions of specific regulatory requirements, implementation details, compliance risks, etc. The language model can be common models such as OpenAIGPT-4 or Deepseek. The acquired domain questions are sent to a designated terminal, which then presents them to personnel with expertise in that specific domain (such as compliance officers, legal experts, industry analysts, etc.) to obtain corresponding answers. Ensuring the quality and accuracy of the question-and-answer process is crucial, as domain experts can provide more precise and in-depth answers based on their experience and knowledge. First, for each domain-specific question, designated personnel will provide professional answers based on relevant regulations, business practices, and industry standards. This step can take the form of one-on-one interviews, questionnaires, or online discussions to ensure that the answers are comprehensive and detailed. Expert responses typically involve compliance analysis, case studies, and clause interpretations, helping to generate high-quality question-and-answer data. The answers obtained from the designated terminal are combined with the previously generated domain-specific questions to formally construct the initial question-and-answer data. This process is a crucial step in the entire data preparation phase, and its results will provide necessary data support for subsequent model training.
[0081] In one embodiment, step S4, which involves forming a training dataset based on multiple sets of the target question-answering data, includes:
[0082] S401: Detect whether the number of target question and answer data corresponding to each preset domain label in the simplified preset domain label set of multiple sets of target question and answer data is lower than a preset value;
[0083] S402: Record the preset domain label that is lower than the preset value as the target preset domain label;
[0084] S403: Supplement the target question-and-answer data for each target preset domain label until the target question-and-answer data corresponding to each target preset domain label reaches the preset value, and combine the target question-and-answer data to obtain the training dataset.
[0085] As described in steps S401-S403 above, the first step is to perform statistical analysis on the simplified preset domain labels corresponding to multiple sets of target question-and-answer data. Specifically, the number of questions and answers under each preset domain label is checked to determine whether the question-and-answer data under that label meets the minimum requirements for training the model. This minimum requirement is defined by a preset value, which is usually set based on prior experience in the domain, model complexity, and actual application scenarios. Through this detection, the system can clearly identify which preset domain labels have insufficient sample quantities. These preset domain labels may cause the model to be unable to effectively extract sufficient features during learning, thereby affecting the model's performance and generalization ability. If there is only limited question-and-answer data for a certain label, the model may overfit or even be unable to adapt to new data. In addition, this process also helps to discover the problem of data imbalance, providing an information basis for subsequent steps and making the model's training dataset richer and more diverse. After completing the quantity detection of the target question-and-answer data, those domain labels with sample quantities lower than the preset value need to be marked as "target preset domain labels". This process is to clarify the goal of subsequent data supplementation work and ensure that resources are concentrated on the datasets that most need enhancement. The significance of identifying target predefined domain labels lies in the fact that the insufficiency of these labels may directly affect the model's performance in practical applications. Identifying these labels allows for the priority consideration of remedial measures to ensure sufficient question-and-answer samples for each label to train the model. This step may also involve recording information such as the label names, current sample counts, and the target number to be achieved, for subsequent data supplementation. By marking labels below the preset value, it helps to develop an effective data supplementation plan, making subsequent steps such as data collection or data generation targeted. The ultimate goal is to ensure an increase in the number of data samples under each domain label, thereby achieving higher dataset quality and usability. For samples identified as target predefined domain labels, specific supplementary measures need to be taken to ensure that the number of question-and-answer data under each label reaches the preset value. This process typically involves various methods, such as increasing data collection, expanding data generation, or performing transfer learning. Specific methods may include finding new question-and-answer sources, such as obtaining new data through questionnaires, user feedback, or other online platforms. New samples are generated using data augmentation techniques. This can be achieved by rewriting questions, adding synonyms, and modifying answers to preserve the original semantics. Transfer learning is then used to generate question-and-answer content related to the target label using a pre-trained model, thus enriching the sample. After this augmentation, the target question-and-answer data for each preset domain label will reach the preset value, allowing the model to be trained in a more balanced data environment. This not only improves the model's training performance but also enhances its adaptability to new question-and-answer scenarios. Finally, these target question-and-answer data are combined to form a complete training dataset for subsequent machine learning training.Ensuring that the training dataset has sufficient sample representativeness is a key factor in improving model performance. Ensuring that each domain label is fully represented in the dataset will enhance the model's performance and robustness, providing good support for question answering systems in real-world application scenarios.
[0086] In one embodiment, step S5, which involves sequentially inputting data from the training dataset into a preset initial transformer model and training it using a labeled method to obtain a label matching model, includes:
[0087] S501: Add a low-rank matrix to the original weight matrix of each layer of the preset initial transformer model;
[0088] S502: Input the data in the training dataset into the preset initial transformer model in sequence, and train it in a labeled manner. During the training process, freeze the original matrix and update the parameters in the low-rank matrix.
[0089] S503: After training, a label matching model is obtained.
[0090] As described in steps S501-S503 above, parameter tuning is required for each layer of the initial transformer model. Specifically, a low-rank matrix is added to the original weight matrix. A low-rank matrix is a matrix with a lower degree of parameterization, characterized by having fewer free parameters. By introducing a low-rank matrix into the weight matrix of each layer, efficient parameter tuning can be achieved while maintaining the model's expressive power. Specifically, let the low-rank matrix be ΔW, and ΔW = BA, and the original weight matrix be W. Here, A is a dimension reduction matrix, mapping the input features to a low-dimensional space; B is a dimension increase matrix, mapping the features from the low-dimensional space back to the original feature space. The ranks of A and B are much smaller than the rank of W. During training, only the parameters of A and B are trained, while the original weight matrix W remains unchanged. The low-rank matrix essentially complements the original weights. It contains fewer parameters and, compared to a complete weight update, focuses more on capturing features most relevant to the current task (e.g., label matching), allowing the model to be fine-tuned for a specific task without significantly altering the overall structure or function of the model. The design and updating method of the low-rank matrix ensures that the original model retains the broad features learned during training, while introducing flexible adjustment capabilities for specific tasks. Since the original weights are frozen and remain unchanged, updating the low-rank matrix does not negatively impact the performance of the original model; on the contrary, it helps enhance the model's adaptability and effectiveness in new application domains. Through this mechanism, the model can maintain high levels of performance and accuracy when facing different label matching tasks. The advantages are reduced model complexity and storage requirements, while also allowing for rapid adaptation to new tasks during training. The introduction of the low-rank matrix allows the model to be fine-tuned based on specific question-and-answer label data while maintaining the original weights, achieving better model performance. Compared to the traditional method of updating all weights, this approach not only improves computational efficiency but also facilitates rapid adaptation to new tasks. Furthermore, the use of the low-rank matrix often helps prevent overfitting because its fewer parameters make the model more concise, thereby improving generalization ability on new samples. The first step of training is to input each data point from the previously prepared training dataset into the adjusted initial transformer model one by one, using a labeled learning approach for training. In this process, the original weight matrix is "frozen," meaning these weights will not change during training. This design aims to avoid disrupting existing weights while preserving the knowledge the model has learned from previous tasks. In contrast, the parameters of the low-rank matrix can be updated. The significance of updating the low-rank matrix lies in the fact that these parameters are responsible for adjusting the model's adaptability to the current task (i.e., label matching). By learning from the low-rank matrix, the model can effectively identify and adapt to the features of new datasets. In practice, the backpropagation algorithm is often used during training to update the parameters of the low-rank matrix, continuously optimizing the model's loss function.This training method enhances the model's flexibility, providing possibilities for task-specific optimization. Simultaneously, this design helps reduce computational overhead and improve training speed. After training is complete, the resulting label matching model is trained. The key task at this stage is to verify the model's effectiveness, ensuring it can accurately match labels to input data. Each weight update during training aims to improve the model's performance on a specific task; therefore, the model needs to be evaluated after training to assess its performance. Evaluation typically uses various metrics, including accuracy, recall, and F1 score, to comprehensively understand the model's performance. These metrics reflect the model's ability to predict new data, ensuring it not only performs well on the training dataset but also maintains high performance levels on unseen test sets. If the model's performance meets the expected standards, the training process is considered successful, and the resulting label matching model is ready for practical application.
[0091] In one embodiment, after step S5, which involves sequentially inputting data from the training dataset into a preset initial transformer model and training it using a labeled method to obtain a label matching model, the method further includes:
[0092] S601: Obtain the current question and input the current question into the label matching model to obtain the current label set corresponding to the current question;
[0093] S602: Obtain the current dataset with corresponding preset domain labels from the database based on the current label set;
[0094] S603: Search for an answer from the current dataset based on the current question.
[0095] As described in steps S601-S603 above, it is necessary to obtain the "current question" raised by the user. This question can come from user input or any query that the system needs to process. After obtaining the current question, it is passed as input to the previously trained label matching model, so that the model can analyze and process the question. After being input into the model, the label matching model will output a "current label set" based on the knowledge learned during its training. This label set contains one or more preset domain labels that are most relevant to the current question, indicating the model's understanding and classification of the question. Through the model's reasoning ability, the user's natural language question is mapped to a concise domain label, thereby making subsequent processing more efficient and accurate. For the system, the quality of the current label set directly affects the effectiveness of subsequent data retrieval and question answering. Excellent label matching can greatly improve the system's response speed and user satisfaction. Then, based on these labels, the "current dataset" with the corresponding preset domain labels is retrieved from the database. The label set provides clear search conditions for subsequent data retrieval. By using the current label set, the system can access a predefined database that stores datasets related to various domain labels. These datasets may include previous question-and-answer sessions, professional knowledge documents, and other information related to the user's question. During a query, the system retrieves the most relevant data entries based on the degree of tag matching. This retrieval process aims to ensure that the system can quickly locate the required information when answering user questions, reducing search time and computational resource consumption, and improving the overall efficiency of the system. Obtaining the current dataset based on the current tag set makes answer searching and extraction more efficient and accurate. After acquiring the current dataset based on the current tag set, the system searches for the answer to the current question within this dataset. This process typically involves Natural Language Processing (NLP) techniques, which can perform precise matching within the dataset based on the semantics and context of the current question. The system may employ various strategies to search for answers. For example, it may extract keywords from the current question and then match them with document content in the current dataset. In addition, similarity calculations (such as cosine similarity) can be used to assess the similarity between the current question and the content of each entry in the dataset, thereby selecting the most relevant answer. The core goal is to ensure that the selected answers are not only accurate but also consistent with the user's query intent, avoiding misleading the user. If a suitable answer is found in the current dataset, the system will return it to the user; if no suitable answer is found, the system may need to provide appropriate prompts, inform the user, or guide the user to ask a more targeted question.
[0096] In one embodiment, step S4, which involves forming a training dataset based on multiple sets of the target question-answering data, includes:
[0097] S411: Detect whether the number of target question and answer data corresponding to each preset domain label in the simplified preset domain label set of multiple sets of target question and answer data is higher than a threshold;
[0098] S412: Record the preset domain labels that are higher than the threshold as temporary preset domain labels;
[0099] S413: Downsample the target question-and-answer data corresponding to each temporarily preset domain label until the target question-and-answer data corresponding to each temporarily preset domain label is lower than or equal to the threshold, thereby obtaining the training dataset.
[0100] As described in steps S411-S413 above, the collected target question-and-answer data is analyzed to check the number of questions and answers under each simplified preset domain label. Specifically, the system will count the target question-and-answer data corresponding to each label and verify whether their quantity exceeds a preset threshold. This threshold is set based on experience or domain knowledge, and its purpose is to assess whether the data under each label is too redundant. Through this detection, it is possible to identify which labels have excessive data samples. Excessive data samples can lead to data redundancy to some extent, resulting in unbalanced model training. During training, it may be easier to overfit the samples of some labels while ignoring the learning of other labels. This helps to better understand the distribution of data and provide a data foundation for subsequent processing steps. By counting the sample size of each label, it is possible to provide a basis for subsequent sampling decisions, which helps to ensure that each label is well representative in the training set. After completing the detection of the number of target question-and-answer data, the domain labels with the number of target question-and-answer data exceeding the threshold are marked as "temporarily preset domain labels". The purpose of this marking process is to clearly identify the labels that need data processing and adjustment, thereby preparing for the formulation of subsequent sampling plans and providing specific targets for data balancing and sample equalization. The labeling process typically involves storing these labels in a list or database for easy retrieval in subsequent steps. For the target question-and-answer data already labeled with temporary predefined domain labels, downsampling is performed. The purpose of downsampling is to reduce the number of data samples corresponding to each label until their number reaches or falls below a set threshold. This process is crucial for ensuring dataset balance, because if the amount of data for some labels far exceeds that of others, the model will be biased towards labels with a large amount of data during training, thus reducing the learning effect on other labels. Downsampling can be achieved through various techniques, such as random sampling or systematic sampling. In random sampling, the system usually randomly selects a subset of samples to ensure sample diversity and reduce redundancy; while systematic sampling may select samples according to a specific logical order, thus ensuring the representativeness of the resulting samples. After the question-and-answer data corresponding to each temporary predefined domain label is downsampled, the final training dataset will have higher balance, which helps improve the model's learning effect and generalization ability.
[0101] Reference Figure 3 The present invention also provides a training apparatus for a label matching model, the apparatus comprising:
[0102] Module 902 is used to acquire multiple sets of question-and-answer data in a preset domain.
[0103] The extraction module 904 is used to extract the questions and answers in each group of question and answer data, as well as the preset domain tag set in each group of question and answer data;
[0104] Processing module 906 is used to simplify the preset domain tag set using a preset data distillation technique to obtain a simplified preset domain tag set, thereby obtaining multiple sets of target question and answer data; one set of target question and answer data includes a question and a simplified preset domain tag set;
[0105] The forming module 908 is used to form a training dataset based on multiple sets of the target question-and-answer data;
[0106] The training module 910 is used to sequentially input the data in the training dataset into a preset initial transformer model, and train it in a labeled manner to obtain a label matching model.
[0107] In one embodiment, the training apparatus for the label matching model further includes:
[0108] The removal module is used to remove Hypertext Markup Language tags from each of the question-and-answer data to obtain the corresponding temporary question-and-answer data;
[0109] The sorting module is used to sort each group of temporary question and answer data into a preset data format, thereby obtaining labeled question and answer data.
[0110] In one embodiment, the acquisition module 902 includes:
[0111] The rule sending submodule is used to send rules from a preset domain to a preset language model in order to obtain multiple domain questions from the preset domain;
[0112] The domain question sending submodule is used to send each of the domain questions to a designated terminal and obtain the answer from the designated terminal.
[0113] The question-and-answer data composition submodule is used to compose the question-and-answer data by combining questions from various fields and the corresponding answers.
[0114] In one embodiment, forming module 908 includes:
[0115] The quantity detection submodule is used to detect whether the number of target question and answer data corresponding to each preset domain label in the simplified preset domain label set of multiple sets of target question and answer data is lower than a preset value;
[0116] The target preset domain label marking submodule is used to mark preset domain labels that are lower than preset values as target preset domain labels;
[0117] The supplementary submodule is used to supplement the target question and answer data for each target preset domain label until the target question and answer data corresponding to each target preset domain label reaches the preset value, and the training dataset is obtained by combining the target question and answer data.
[0118] In one embodiment, the training module 910 includes:
[0119] Add a submodule to add a low-rank matrix to each layer of the original weight matrix of the preset initial transformer model;
[0120] The data input submodule is used to sequentially input the data in the training dataset into the preset initial transformer model, and to train it in a labeled manner. During the training process, the original matrix is frozen and the parameters in the low-rank matrix are updated.
[0121] The training submodule is used to obtain the label matching model after training.
[0122] In one embodiment, the training apparatus for the label matching model further includes:
[0123] The current problem acquisition module is used to acquire the current problem and input the current problem into the tag matching model to obtain the current tag set corresponding to the current problem;
[0124] The current dataset acquisition module is used to acquire the current dataset with corresponding preset domain labels from the database based on the current label set;
[0125] The answer search module is used to search for answers from the current dataset based on the current question.
[0126] In one embodiment, forming module 908 includes:
[0127] The target question and answer data quantity detection submodule is used to detect whether the number of target question and answer data corresponding to each preset domain label in the simplified preset domain label set of multiple sets of target question and answer data is higher than a threshold.
[0128] The temporary preset domain label marking submodule is used to mark preset domain labels that are higher than the threshold as temporary preset domain labels;
[0129] The downsampling submodule is used to downsample the target question-and-answer data corresponding to each temporarily preset domain label until the target question-and-answer data corresponding to each temporarily preset domain label is lower than or equal to the threshold, thereby obtaining the training dataset.
[0130] Figure 4 An internal structural diagram of a computer device in one embodiment is shown. This computer device can specifically be a terminal or a server. Figure 4As shown, the computer device includes a processor, memory, and a network interface connected via a system bus. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and may also store a computer program. When executed by the processor, this computer program enables the processor to implement a method for training a label matching model. The internal memory may also store a computer program, which, when executed by the processor, enables the processor to implement a method for training a label matching model. Those skilled in the art will understand that... Figure 4 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0131] In one embodiment, a computer device is provided, including a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the following steps:
[0132] Acquire multiple sets of question-and-answer data within a preset domain;
[0133] Extract the questions and answers from each set of question-and-answer data, as well as the preset domain tag set from each set of question-and-answer data;
[0134] The preset domain tag set is simplified by using a preset data distillation technique to obtain a simplified preset domain tag set, thereby obtaining multiple sets of target question and answer data; one set of target question and answer data includes the question and the simplified preset domain tag set.
[0135] A training dataset is formed based on multiple sets of the target question-and-answer data;
[0136] The data in the training dataset are sequentially input into the preset initial transformer model, and trained in a labeled manner to obtain the label matching model.
[0137] It significantly improves the accuracy of matching questions with legal tags, effectively solves the matching problem caused by the difference between user questions and legal provisions, and enables the generated tag matching model to automatically match user questions with corresponding domain tags. This results in an efficient question-and-answer system in practical applications, significantly improving user experience and system efficiency.
[0138] In one embodiment, a computer-readable storage medium is provided storing a computer program that, when executed by a processor, causes the processor to perform the following steps:
[0139] Acquire multiple sets of question-and-answer data within a preset domain;
[0140] Extract the questions and answers from each set of question-and-answer data, as well as the preset domain tag set from each set of question-and-answer data;
[0141] The preset domain tag set is simplified by using a preset data distillation technique to obtain a simplified preset domain tag set, thereby obtaining multiple sets of target question and answer data; one set of target question and answer data includes the question and the simplified preset domain tag set.
[0142] A training dataset is formed based on multiple sets of the target question-and-answer data;
[0143] The data in the training dataset are sequentially input into the preset initial transformer model, and trained in a labeled manner to obtain the label matching model.
[0144] It significantly improves the accuracy of matching questions with legal tags, effectively solves the matching problem caused by the difference between user questions and legal provisions, and enables the generated tag matching model to automatically match user questions with corresponding domain tags. This results in an efficient question-and-answer system in practical applications, significantly improving user experience and system efficiency.
[0145] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0146] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0147] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
Claims
1. A training method for a label matching model, characterized in that, The method includes: Acquire multiple sets of question-and-answer data within a preset domain; Extract the questions and answers from each set of question-and-answer data, as well as the preset domain tag set from each set of question-and-answer data; The preset domain tag set is simplified by using a preset data distillation technique to obtain a simplified preset domain tag set, thereby obtaining multiple sets of target question and answer data; one set of target question and answer data includes the question and the simplified preset domain tag set. A training dataset is formed based on multiple sets of the target question-and-answer data; The data in the training dataset are sequentially input into the preset initial transformer model, and trained in a labeled manner to obtain the label matching model.
2. The training method for the label matching model according to claim 1, characterized in that, Before the step of extracting the questions and answers from each group of question-and-answer data, and the preset domain tag set from each group of question-and-answer data, the method further includes: Remove the Hypertext Markup Language tags from each of the question-and-answer data to obtain the corresponding temporary question-and-answer data; Each set of temporary question-and-answer data is organized into a preset data format to obtain labeled question-and-answer data.
3. The training method for the label matching model according to claim 1, characterized in that, The step of acquiring multiple sets of question-and-answer data in a preset domain includes: The rules of the preset domain are sent to the preset language model to obtain multiple domain questions of the preset domain; The questions in each of the aforementioned fields are sent to a designated terminal, and the answers are obtained from the designated terminal. The question-and-answer data is composed of questions from various fields and their corresponding answers.
4. The training method for the label matching model according to claim 1, characterized in that, The step of forming a training dataset based on multiple sets of target question-answering data includes: The number of target question-and-answer data corresponding to each preset domain label in the simplified preset domain label set of multiple sets of target question-and-answer data is lower than a preset value; Record the preset domain labels that are lower than the preset values as the target preset domain labels; The target question-and-answer data for each target preset domain label is supplemented until the target question-and-answer data corresponding to each target preset domain label reaches the preset value. The training dataset is obtained by combining the question-and-answer data of each target.
5. The training method for the label matching model according to claim 1, characterized in that, The step of sequentially inputting the data from the training dataset into a preset initial transformer model and training it in a labeled manner to obtain a label matching model includes: A low-rank matrix is added to the original weight matrix of each layer of the preset initial transformer model; The data in the training dataset are sequentially input into the preset initial transformer model, and training is performed in a labeled manner. During the training process, the original matrix is frozen and the parameters in the low-rank matrix are updated. After training, a label matching model is obtained.
6. The training method for the label matching model according to claim 1, characterized in that, After the step of sequentially inputting the data from the training dataset into a preset initial transformer model and training it in a labeled manner to obtain a label matching model, the method further includes: Obtain the current question and input it into the label matching model to obtain the current label set corresponding to the current question; Based on the current tag set, retrieve the current dataset corresponding to the preset domain tags from the database; Search for answers from the current dataset based on the current question.
7. The training method for the label matching model according to claim 1, characterized in that, The step of forming a training dataset based on multiple sets of target question-answering data includes: The number of target question-and-answer data corresponding to each preset domain label in the simplified preset domain label set of multiple sets of target question-and-answer data is higher than a threshold. Record the preset domain labels that are higher than the threshold as temporary preset domain labels; The target question-and-answer data corresponding to each temporarily preset domain label is downsampled until the target question-and-answer data corresponding to each temporarily preset domain label is lower than or equal to the threshold, thereby obtaining the training dataset.
8. A training device for a label matching model, characterized in that, The device includes: The acquisition module is used to acquire multiple sets of question-and-answer data in a preset domain; The extraction module is used to extract the questions and answers from each set of question-and-answer data, as well as the preset domain tag set from each set of question-and-answer data; The processing module is used to simplify the preset domain tag set using a preset data distillation technique to obtain a simplified preset domain tag set, thereby obtaining multiple sets of target question and answer data; one set of target question and answer data includes a question and a simplified preset domain tag set. A forming module is used to form a training dataset based on multiple sets of the target question-and-answer data; The training module is used to sequentially input the data in the training dataset into a preset initial transformer model, and train it in a labeled manner to obtain a label matching model.
9. A computer-readable storage medium, characterized in that, The system contains a computer program that, when executed by a processor, causes the processor to perform the steps of the training method for the label matching model as described in any one of claims 1 to 7.
10. A computer device, characterized in that, The device includes a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the training method for the label matching model as described in any one of claims 1 to 7.