Target data generation method and device based on large model and text matching method
By building a Prompt prompt engineering and iterative generation mechanism, the problems of low efficiency and imbalance in the generation of large model data sets are solved, efficient and diverse target data generation is achieved, and the performance of downstream models is improved.
Patent Information
- Application Number
- CN202411327010.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-23
- Publication Date
- 2024-12-20
AI Technical Summary
Existing large models are inefficient in generating data sets, and lack of unified input formats for data generation and labeling, resulting in low data generation efficiency and unbalanced data, affecting the performance of downstream tasks.
By constructing the first and second Prompt prompt projects, target data is generated in combination with preset examples, and target data with iterative generation using large models to ensure data diversity and label balance. Round generation and sampling screening mechanisms are adopted. Generate target data that matches preset formats and scales.
It improves the efficiency and diversity of data generation, ensures the richness of target data and the balance of labels, reduces the cost and time of manual labeling, and improves the performance and generalization capabilities of downstream models.
Smart Images

Figure CN119168070A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a target data generation method and device based on a large model and a text matching method. Background Art
[0002] A large model is a deep learning model with a large number of parameters, a large number of neurons and a hierarchical structure, and is powerful. However, due to its large size, large models are generally not directly applied to specific downstream tasks. In practical applications, a data set is generally generated based on the large model first, and then a relatively small model is trained using the data set to enable the relatively small model to perform downstream tasks.
[0003] The steps for a large model to generate a data set generally include two stages: data annotation and supervised data generation. In the data annotation stage, the input is usually unlabeled raw data, such as text, images, etc., and the output is the label corresponding to the raw data, such as the sentiment classification label (positive, negative, neutral). In the data generation stage, the input is usually a prompt that includes a label and can clarify the semantics of the label, which is used to guide the large model to generate relevant text; the output is the unlabeled text generated by the large model, which is associated with the input label but does not contain label information.
[0004] It can be seen that in the existing solutions for generating datasets, large models cannot directly output labeled text. In addition, since there is no unified input format for data generation and data annotation, different input contents need to be manually constructed before generating datasets, which affects the efficiency of generating datasets. Summary of the invention
[0005] The embodiments of the present application provide a target data generation method, device and text matching method based on a large model to solve the problem of low generation efficiency of traditional data generation methods.
[0006] In a first aspect, an embodiment of the present application provides a method for generating target data based on a large model, wherein the target data is used to train a target model after being generated, so that the target model is used to perform a target task, wherein the target task is a classification task;
[0007] The target data generation method includes: constructing a first Prompt prompt project and a second Prompt prompt project; wherein the first Prompt prompt project includes task information related to the target task, and the first Prompt prompt project is used to prompt the large model to generate target data according to the task information; the second Prompt prompt project is used to limit the data composition of the target data; the first Prompt prompt project and the second Prompt prompt project are spliced and merged to obtain a Prompt template; the preset example and the Prompt template are input into the large model so that the large model generates multiple target data; wherein the preset example is any example in the original data set, and the preset example and the target data at least include a first label, and the first label is used to represent the category of the preset example and the target data.
[0008] In an achievable manner, when the target task is a classification task of determining whether the semantics of two paragraphs of text match, the task information includes question-and-answer content determined based on the target task, the question-and-answer content includes a question-and-answer pair, an answer selection space, and a text format of the target data, the question-and-answer pair includes a question and an answer, the question is whether the semantics of the two paragraphs of text match, the answer is one of the answer selection spaces, the answer selection space includes matching and non-matching, the data composition means that different target data generated by the large model have the same and / or different target features, the target features at least include answer content, text content, and a preset data format; the step of inputting preset examples and Prompt templates into the large model so that the large model generates multiple target data includes: using the large model to generate two paragraphs of target text and a target answer according to rounds; wherein the target answer is determined based on the question-and-answer pair and the answer selection space, and the target answer includes a result of whether it matches; for each round, determining the first label corresponding to the two paragraphs of target text based on the target answer, wherein different target answers correspond to first labels of different categories; determining the two paragraphs of target text and the first label as process data; sampling and screening the process data to obtain the target data.
[0009] In one feasible method, in the step of using a large model to generate two target texts and a target answer in rounds, the large model is used to generate process data based on input data and a prompt template in each round; wherein, for the first round, the input data of the large model is a preset example; the step of sampling and screening the process data to obtain target data includes: for the i-th round, after the large model generates the process data, sampling the process data to obtain sampled data, i≥1; screening the sampled data to obtain target data for the current round; and inputting the target data into the large model as input data for the i+1-th round.
[0010] In one feasible method, after the step of screening the sampled data to obtain the target data of the current round, it also includes: collecting all the target data generated from the 1st to the i-th rounds, and when the number of all the target data is greater than or equal to a preset threshold, the large model stops generating data.
[0011] In one feasible manner, the step of screening the sampled data to obtain the target data of the current round includes: for the sampled data, removing the data that does not conform to the preset data format and removing the data that lacks the target field to obtain the first subset data, wherein the target field is determined by the preset data format, and the preset data format is the json format; determining whether the proportion of the first labels of different categories in the first subset data is equal to the preset proportion; when the proportion of the first labels of different categories is equal to the preset proportion, determining the first subset data as the target data of the current round.
[0012] In one achievable method, after the step of determining whether the proportion of first labels of different categories in the first subset data is equal to a preset proportion, the method further includes: when the proportion of first labels of different categories is not equal to the preset proportion, removing one or more first subset data so that the proportion of first labels of different categories in the remaining first subset data is equal to the preset proportion; and determining the first subset data as the target data for the current round.
[0013] In an achievable manner, the sampled data includes one or more of first sampled data, second sampled data and third sampled data, wherein the first sampled data is any one or more of the process data; the method further includes: calculating a first embedding vector corresponding to two paragraphs of text in a preset example, and calculating a second embedding vector corresponding to a first label in the preset example; for each process data, calculating a third embedding vector corresponding to two paragraphs of target text, and calculating the consin similarity between the third embedding vector and the first embedding vector to obtain a first similarity; and calculating a fourth embedding vector corresponding to the first label in the process data, and calculating the consin similarity between the fourth embedding vector and the second embedding vector to obtain a second similarity; for each process data, calculating the sum of the first similarity and the second similarity to obtain a total similarity; determining one or more process data as the second sampled data in descending order of the total similarity; and determining one or more process data as the third sampled data in descending order of the total similarity.
[0014] In one achievable manner, the second Prompt prompt project includes at least: the text contents of the two paragraphs of text in the target data are different; the answer contents of each target data are different from each other, and the text contents are different from each other; and the target data and the preset example have the same preset data format and answer selection space.
[0015] In a second aspect, an embodiment of the present application also provides a text matching method, comprising: obtaining a first text and a second text; inputting the first text and the second text into a target model, and using the target model to determine whether the semantics of the first text and the second text match; wherein the target model is a lightweight model, and the target model has been trained with target data, and the target data is generated based on the large model-based target data generation method in the aforementioned first aspect and its various implementation methods.
[0016] In a third aspect, an embodiment of the present application further provides a target data generation device based on a large model. After the target data is generated, it is used to train the target model so that the target model can be used to perform the target task, which is a classification task; the target data generation device includes: a construction module, used to construct a first Prompt prompt project and a second Prompt prompt project; wherein the first Prompt prompt project includes task information related to the target task, and the first Prompt prompt project is used to prompt the large model to generate target data according to the task information; the second Prompt prompt project is used to limit the data composition of the target data; a merging module, used to splice and merge the first Prompt prompt project and the second Prompt prompt project to obtain a Prompt template; a generating module, used to input a preset example and a Prompt template into the large model, so that the large model generates multiple target data; wherein the preset example is any example in the original data set, and the preset example and the target data include at least a first label, and the first label is used to represent the category of the preset example and the target data.
[0017] From the above content, it can be seen that the embodiment of the present application provides a method, device and text matching method for generating target data based on a large model, and the data generation method includes: constructing a first Prompt prompt project and a second Prompt prompt project; wherein the first Prompt prompt project includes task information related to the target task, and the first Prompt prompt project is used to prompt the large model to generate target data according to the task information; the second Prompt prompt project is used to limit the data composition of the target data; the first Prompt prompt project and the second Prompt prompt project are spliced and merged to obtain a Prompt template; the preset example and the Prompt template are input into the large model so that the large model generates multiple target data; wherein the preset example is any example in the original data set, and the preset example and the target data include at least a first label, and the first label is used to represent the category of the preset example and the target data. This method can iteratively generate rich labeled data using only one example, and can ensure the diversity of data and the balance of labels, and has high generation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 An application scenario diagram of generating data based on a large model provided in an embodiment of the present application;
[0019] Figure 2 A schematic diagram of the overall process of the target data generation method based on a large model provided in an embodiment of the present application;
[0020] Figure 3 A schematic diagram of a first process for generating target data provided in an embodiment of the present application;
[0021] Figure 4 A second flow chart of generating target data provided in an embodiment of the present application;
[0022] Figure 5 A schematic diagram of a process for determining input data for each round of a large model provided in an embodiment of the present application;
[0023] Figure 6 A schematic diagram of a data screening process provided in an embodiment of the present application;
[0024] Figure 7 A flowchart of a text matching method provided in an embodiment of the present application;
[0025] Figure 8 A schematic diagram of the structure of a target data generation device based on a large model provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the technical solutions in the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work should fall within the scope of protection of the present application.
[0027] Before introducing the technical solutions of the embodiments of the present application, the terms involved in the embodiments of the present application are first introduced by way of example.
[0028] Prompt Engineering: Prompt Engineering is also called contextual prompts. It is widely used in the fields of artificial intelligence and natural language processing (NLP). Specifically, Prompt Engineering is a method to guide the behavior of a large model (LLM) towards a specific result without updating the weights / parameters of the model. The core of Prompt Engineering is to involve and write prompt texts, that is, Prompt Engineering is used to generate, process and verify multiple prompts. These prompts usually include multiple steps and rules, thereby guiding the model to generate language output that meets specific requirements and ensure that the generated data meets specific format and quality requirements.
[0029] A prompt is usually a short text snippet, which can be a question, a descriptive statement, or a set of instructions, designed to prompt the model to make corresponding outputs in specific tasks or scenarios. As part of the input data, the prompt can help the model understand the requirements and generate outputs that match them. For example, in a question-and-answer system, a prompt can be a question that requires the model to give an answer. In a text generation task, a prompt can be a descriptive statement that guides the model to generate text related to it. For example, in content creation, you can input a prompt such as "write a press release about artificial intelligence" to enable the large model to automatically complete a news release with a complete structure and fluent language.
[0030] A large model is a deep learning model with a large number of parameters, a large number of neurons and a hierarchical structure, and has powerful features. However, due to the large size of the large model, it is generally not directly applied to specific downstream tasks. Figure 1 As shown in the figure, in practical applications, a data set is usually generated based on a large model first, and then a relatively small model is trained using the data set to enable the relatively small model to be able to perform downstream tasks. In this way, the computing resource requirements can be reduced while ensuring performance, which is suitable for downstream tasks in resource-constrained environments such as mobile devices.
[0031] The steps for a large model to generate a data set generally include two stages: data annotation and supervised data generation. In the data annotation stage, the input is usually unlabeled raw data, such as text, images, etc., and the output is the label corresponding to the raw data, such as the sentiment classification label (positive, negative, neutral). In the data generation stage, the input is usually a prompt that includes a label and can clarify the semantics of the label, which is used to guide the large model to generate relevant text; the output is the unlabeled text generated by the large model, which is associated with the input label but does not contain label information.
[0032] The following is a specific step of data annotation and data generation in the actual application process. In the data annotation stage, a large amount of unlabeled raw data is first determined. This data can be obtained from a public data set or unprocessed data collected from actual application scenarios. For text data, the annotation process generally involves manual annotation or semi-automatic methods to ensure that each data sample has the correct label. For example, in a sentiment classification task, the annotator may need to read each text and decide its sentiment category. After the data annotation is completed, the next step is the data generation stage. In this stage, large models are usually used to generate unlabeled data associated with labels. During the generation process, clear prompts or conditions need to be defined to ensure that the generated text is semantically related to the label. For example, for each sentiment category, a specific prompt can be designed to guide the model to generate text with the corresponding sentiment.
[0033] It can be seen that in the existing schemes for generating data sets, large models cannot directly output labeled text, and because there is no unified input format for data generation and data annotation, different input content needs to be designed for large models before generating data sets, which affects the efficiency of generating data sets. In addition, data imbalance may also occur during the data annotation and data generation stages. For example, in the legal field, data imbalance is specifically manifested in that in the generated data sets, data with matching case types account for the majority, while data with mismatched case types are relatively small, which makes it difficult to reflect the true distribution in actual application scenarios. Especially when the amount of data is large, data imbalance will increase, causing data confusion, and data diversity cannot be guaranteed.
[0034] Figure 1 An application scenario diagram for generating data based on a large model provided in an embodiment of the present application.
[0035] like Figure 1As shown, an embodiment of the present application provides a target data generation method based on a large model, which can be used to generate target data. After that, the data set composed of the target data can be used to train the target model. The target model is a lightweight model with a smaller scale and lower computing resource requirements relative to the large model. The target model can have a faster reasoning speed and lower memory consumption, and is suitable for running in resource-constrained environments, such as mobile devices or embedded systems. In this way, the target model can perform a target task, which is a type of downstream task, and can specifically be a classification task (Classification). The classification task refers to assigning input data to predefined categories, each of which has a unique label. The classification task can include a text classification task or an image classification task, and the target task can specifically be the above two types, which are not limited in this application.
[0036] Exemplarily, the target task may be a text matching task, wherein the text matching task belongs to a text classification task, specifically determining whether the semantics of two texts match. In some implementations, the target task may also be other classification tasks involved in the natural language processing (NLP) process, such as real-time sentiment analysis, news classification, face recognition or object recognition, etc., which are not specifically limited in the embodiments of the present application.
[0037] Figure 2 A schematic diagram of the overall process of the target data generation method based on a large model provided in an embodiment of the present application.
[0038] like Figure 2 As shown, the target data generation method based on the large model provided in the embodiment of the present application may include the following steps S100-S300.
[0039] S100: Constructing a first Prompt project W_f and a second Prompt project W_I.
[0040] The embodiment of the present application can establish two Prompt projects to guide the large model to generate the target data required for training the target model.
[0041] Among them, the first Prompt prompt project W_f includes task information related to the target task to guide the large model to generate target data related to the target task. In other words, the first Prompt prompt project W_f is used to prompt the large model to generate target data according to the task information. Task information is, for example, task description and content requirements. When the target task is a classification task to determine whether the semantics of two paragraphs of text match, the task information includes question and answer content determined based on the target task, and the question and answer content includes question and answer pairs, answer selection space, and text format of the target data.
[0042] Specifically, the question in the question-answer pair may be "Do the semantics of the following two paragraphs of text match?" The answer selection space may include "match, mismatch." In some implementations, the answer selection space may also be referred to as "options" or "answer space." The answer selection space may also include "unable to determine," which is not specifically limited in the embodiments of the present application. The answer may be "match" or "mismatch." It is understandable that the answer is determined from the answer selection space, specifically one of the answers in the answer selection space. Based on the target task, it can be determined that the answer selection space is "match, mismatch."
[0043] The text format is, for example, "text 1, text 2". For example, text 1 may be "a husband suddenly got emotional in the community and physically attacked his wife", and text 2 may be "a wife of a certain family had an argument with her husband in a public area in the community".
[0044] In some implementations, the first prompt project W_f is in json format, and further, the target data generated based on the first prompt project W_f is also in json format. The json format is a lightweight data exchange format. The content in the following quotation marks is the json format representation of the first prompt project.
[0045] "{
[0046] "options": ["match", "do not match"],
[0047] "Answer": "Match",
[0048] "Question": "Do the following two pieces of text match each other semantically?",
[0049] "text": [text1, text2]
[0050] }".
[0051] In the embodiment of the present application, the first Prompt prompt project W_f can be used to prompt the large model to generate target data according to the question and answer content, and the target data can also be called a text sample. In practical applications, the first Prompt prompt project W_f can be adaptively adjusted based on the different requirements of the target task, for example, modifying the specific content of the answer selection space (options), or modifying the questions and corresponding answers in the question and answer pair, etc., which is not specifically limited in the embodiment of the present application.
[0052] Furthermore, the second Prompt prompt project W_I is used to limit the data composition of the target data. When the target task is a classification task to determine whether the semantics of two paragraphs of text match, the data composition means that the target data generated by the large model has the same and / or different target features, and the target features include at least the answer content, text content and preset data format. It can be seen that the second Prompt prompt project W_I can prompt the large model to generate diverse target data, and at the same time restrict the format of the target data to facilitate subsequent data processing. The second Prompt prompt project W_I also further limits how to select answers during the generation process to ensure the rigor of the output samples.
[0053] The second prompt for project W_I is as follows:
[0054] "##instruction
[0055] ##Based on the provided example, create {number_of_examples} examples with the same structure as the example, but with different text content. number is the example number.
[0056] ##The examples created **must** have different answers and different texts.
[0057] ##The output format **must** be the same json structure as the example.
[0058] ##The created examples **must** have the same answer space as the provided examples. ".
[0059] Among them, "the text content must be different" specifically means that the text content of the two paragraphs of text in the target data is different. "The answers of the created samples must be different and the texts must be different" specifically means that the answer content of each target data generated by the guidance model is different, and the text content is different. "The output format must be the same json structure as the example" can be understood as limiting the target data and the preset example to have the same preset data format, that is, json format. "The created samples must have the same answer space as the provided examples" means that the target data and the preset examples have the same answer selection space.
[0060] It can be understood that the sample number number is equivalent to the ID of the sample. Adding an ID to the sample can also enhance the diversity of generated data.
[0061] S200: The first Prompt project W_f and the second Prompt project W_I are concatenated and merged to obtain a Prompt template.
[0062] In the embodiment of the present application, after W_f and W_I are concatenated and merged, [W_I, W_f] can be obtained, that is, the Prompt template. It can be understood that the Prompt template is a text list.
[0063] S300: Inputting the preset examples and the Prompt template into the large model so that the large model generates a plurality of target data.
[0064] The preset example is any example in the original data set, which can be determined by random sampling. When the target model is applied to different target tasks, the preset examples input into the large model should be different.
[0065] The embodiment of the present application can pre-establish an original data set based on the target task, and the original data set can include multiple examples. For example, when the target task is to classify legal cases based on text matching, the original data set can be established based on the legal official document text recorded by the recorder. Specifically, the official document texts of the same case and different cases can be manually extracted, and text 1 and text 2 with the same case are determined as matches, and text 1 and text 2 with different case are determined as mismatches, to complete data cleaning and manual labeling.
[0066] The preset example (X_f, Y_f) may include two texts and a first label, wherein X_f represents two texts, namely text 1 and text 2, and Y_f represents the first label. Specifically, the first label is used to represent the category of the preset example and the target data, which is specifically determined based on whether the semantics of the two texts match. Exemplarily, when the semantics of the two texts match, the first label is "matched", and when the semantics of the two texts do not match, the first label is "unmatched".
[0067] It is worth noting that the Prompt template can prompt the large model to generate multiple target data, and based on the output characteristics of the large model, the target data is large and rich. The target data has the same structure as the preset example, and also has two paragraphs of text and a first label. Furthermore, the target data can be used to train the target model so that the target model has the ability to perform downstream tasks (such as text matching tasks).
[0068] In some implementations, the large model may be a QWEN1.5-7B model, and the target model may be a Sentence-BERT model. This is only an exemplary introduction. This application does not limit the specific structures of the large model and the target model. The weights and parameters of the large model may be determined based on actual needs.
[0069] It is worth noting that in the actual application process of the embodiment of the present application, the second prompt project W can be constructed first. I, and then build the first Prompt prompt project W_f, and combine the first Prompt prompt project W_f with the second Prompt prompt project W I Combine to get [W_I, W_f]. After the prompt project is constructed, data can be generated through iteration, and then the data can be applied to the downstream model training process. In addition, since different target tasks can limit the data composition of the same target data, and the same target task can also limit the data composition of different target data, the first Prompt prompt project and the second Prompt prompt project are constructed separately and then spliced and merged, which can make the prompt project more flexible to construct and effectively save manpower. For example, multiple first Prompt prompt projects corresponding to different target tasks and multiple second Prompt prompt projects that limit different data structures can be constructed separately, and then the first Prompt prompt project and the second Prompt prompt project can be spliced and merged as needed.
[0070] From the above content, it can be seen that the embodiment of the present application provides a method for generating target data based on a large model. The method only needs to determine a formatted input example, that is, a preset example, so that the large model can generate diverse and rich labeled data, that is, target data. Compared with manually annotated data, the amount of data generated by the large model is large and rich, which can save manpower and significantly improve efficiency. For specific fields, such as legal case classification, when there is only a small amount of specific case data, the use of manually annotated data to train downstream models will result in a single case distribution. The process of generating data from a large model provided in the present application can overcome the problem of a single case distribution, which can not only ensure the diversity of case types, but also generate rich data for downstream model training.
[0071] The method provided in the embodiment of the present application can be applied to the text matching project of case classification, and the generated data can be used to train the downstream text matching task model, and the downstream text matching task model can have higher efficiency and the ability to adapt to specific downstream tasks. It can be seen that the embodiment of the present application uses a large model to generate a data set, which can significantly reduce the cost and time of manual annotation, and at the same time can expand the scale and diversity of the data set, thereby improving the performance and generalization ability of the machine learning model in practical applications.
[0072] Figure 3 A schematic diagram of a first process for generating target data provided in an embodiment of the present application.
[0073] Figure 4 A second flow chart of generating target data provided in an embodiment of the present application.
[0074] like Figure 3 and Figure 4 As shown, step S300 may include the following steps S301-S304.
[0075] S301: Generate two target texts and a target answer in rounds using a large model; wherein the target answer is determined based on the question-answer pair and the answer selection space, and the target answer includes a matching result.
[0076] It can be understood that the large model can generate target data based on the prompts of the first Prompt prompt project W_f and the second Prompt prompt project W_I, that is, the large model can generate two target texts and target answers based on the format of the question and answer content prompted by the first Prompt prompt project W_f. In addition, the large model generates data in rounds, and in each round, the large model can generate a certain amount of data.
[0077] Specifically, the large model is used to generate process data based on input data and prompt templates in each round. Further, the embodiment of the present application can also sample and filter the process data to obtain the final target data. The sampling and filtering steps will be described in detail below and will not be repeated here.
[0078] In the process of generating target texts and target answers by round, for the first round, the input data of the large model is the preset example. In the preset example (X_f, Y_f), X_f is text 1: A husband suddenly became emotional in the community and physically attacked his wife, and text 2: A wife and her husband had an argument in the public area of the community. Y_f is a match. Under the prompts of the first Prompt prompt project W_f and the second Prompt prompt project W_I, the large model can generate the following two target texts: text 1a: In a residential area, a man lost control of his emotions and committed violence against his spouse, and text 2a: A couple had a fierce verbal conflict in the public space of the community due to a dispute, and the target answer is a match. It can be seen that the text content of text 1a and text 1b generated by the large model is different, which meets the prompt of the second Prompt prompt project W_I.
[0079] For example, the large model can also generate the following two target texts: Text 1b: Mr. A's emotions suddenly lost control in the community and he physically abused his spouse; Text 2b: Wang verbally threatened a passerby in the community and then stabbed the passerby with a knife. The target answer is mismatch. It can be seen that the answers of Text 1a and Text 2a generated by the large model are different from those of Text 1b and Text 2b. The texts are different and have the same answer space, which meets the prompt of the second Prompt prompt project W_I.
[0080] S302: For each round, first labels corresponding to two target texts are determined based on the target answer, wherein different target answers correspond to first labels of different categories.
[0081] It is understandable that after the large model generates the target answer, the first label can be determined. The categories of the first label specifically include match and mismatch.
[0082] S303: Determine the two target texts and the first label as process data.
[0083] It can be understood that, based on the prompts of the first Prompt prompt project W_f and the second Prompt prompt project W_I, the process data has a json format and has a sample number number.
[0084] It can be understood that in each round, several process data can be obtained.
[0085] S304: Sampling and screening the process data to obtain target data.
[0086] It is understandable that step S304 may be executed after each round of process data generation. The steps of sampling and filtering process data are introduced below with reference to the accompanying drawings.
[0087] Figure 5 A schematic diagram of a process for determining input data for each round of a large model provided in an embodiment of the present application.
[0088] like Figure 5 As shown, step S304 may include the following steps S3041-S3043.
[0089] S3041: For the i-th round, after the large model generates process data, the process data is sampled to obtain sampled data, i≥1.
[0090] The sampling step occurs after the process data is generated in each round, and a portion of the samples can be extracted from the large amount of data generated for further analysis or as training data for downstream tasks. The embodiment of the present application can provide a self-referenced sampling method. Specifically, the data generated in the i-th round is f_i = (X_fi, Y_fi), which can be obtained by sampling the data f of the i-1th round. i -1=(X_(fi-1),Y_(fi-1)). The specific sampling process will be described in detail below and will not be repeated here.
[0091] S3042: Filter the sampled data to obtain the target data of the current round.
[0092] The process of filtering the sampled data to obtain the target data can remove the unbalanced data in the sampled data to ensure the balance of the target data. It can also remove the data that does not meet the data specifications, such as data with too long text or too short text. The specific filtering process will be described in detail below and will not be repeated here.
[0093] S3043: Input the target data into the large model as the input data of the i+1th round.
[0094] It is worth mentioning that Figure 3 The case where i>1 is exemplarily shown in FIG.
[0095] In this way, the large model can further generate data based on the target data generated in the i-th round, and expand the data volume through data iteration.
[0096] Furthermore, step S3042 may further include S3044: collecting all target data generated from the 1st to the i-th rounds, and when the number of all target data is greater than or equal to a preset threshold, the large model stops generating data.
[0097] Accordingly, when the number of target data is not greater than the preset threshold, the large model can continue to generate data. Exemplarily, the preset threshold can be 2000, which is not specifically limited in the embodiment of the present application. In practical applications, k rounds can be iterated until the amount of data generated meets the requirements and then the iteration is stopped. In this way, all target data generated in each round can form a data set for training the target model.
[0098] In some implementations, the data set may also be used for testing or verifying the model, which is not specifically limited in the embodiments of the present application.
[0099] Furthermore, the embodiments of the present application provide three sampling methods, namely, random sampling method, semantic farthest sampling method and semantic closest sampling method, wherein the sampling data obtained by the random sampling method can be referred to as the first sampling data, the sampling data obtained by the semantic closest sampling method can be referred to as the second sampling data, and the sampling data obtained by the semantic farthest sampling method can be referred to as the third sampling data. In practical applications, the three sampling methods can be combined for sampling, or one or two of the sampling methods can be selected for sampling. The embodiments of the present application do not specifically limit this. In other words, the sampling data can include one or more of the first sampling data, the second sampling data and the third sampling data.
[0100] The specific sampling process of the random sampling method is as follows: randomly sample a number of data from the process data generated in the i-th round as sampling data, i≥1, and the specific sampling number can be 10 or 20, which is not specifically limited in the embodiment of the present application.
[0101] The semantic farthest sampling method and the specific sampling process of the semantic farthest sampling method include the following S30411-S30415.
[0102] S30411: Calculate the first embedding vector corresponding to the two paragraphs of text in the preset example, and calculate the second embedding vector corresponding to the first label in the preset example.
[0103] Among them, the first embedding vector is a vector representation of the two paragraphs of text in the preset example, which can also be called the embedding representation of the two paragraphs of text; the second embedding vector is a vector representation of the first label in the preset example, which can also be called the embedding representation of the first label.
[0104] The embodiment of the present application can call the public sentence embedding extraction interface to calculate the first embedding vector and the second embedding vector. It can be understood that the step of calculating the first embedding vector corresponding to the two paragraphs of text is the step of calculating the embedding vector representation corresponding to the "text", and the step of calculating the second embedding vector corresponding to the first label is the step of calculating the embedding vector representation corresponding to the "answer".
[0105] S30412: For each process data, calculate the third embedding vector corresponding to the two target texts, and calculate the consin similarity between the third embedding vector and the first embedding vector to obtain a first similarity; and calculate the fourth embedding vector corresponding to the first label in the process data, and calculate the consin similarity between the fourth embedding vector and the second embedding vector to obtain a second similarity.
[0106] Among them, the third embedding vector is a vector representation of the two texts in the process data, which can also be called the embedding representation of the two texts; the fourth embedding vector is a vector representation of the first label in the process data, which can also be called the embedding representation of the first label.
[0107] The embodiment of the present application can also use the sentence embedding extraction interface provided by the online open source model to calculate the third embedding vector and the fourth embedding vector. Online open source models are usually pre-trained on large-scale data sets to capture high-level semantic information and features. The embodiment of the present application can directly use the trained model to extract the embedding vector of the text without the need to train the model by itself. Through these pre-trained models, embedding vectors can be extracted quickly, which can save time and computing resources. It can be understood that the step of calculating the embedding vectors corresponding to the two target texts in the process data is the step of calculating the embedding vector representation corresponding to the "text", and the step of calculating the embedding vector corresponding to the first label in the process data is the step of calculating the embedding vector representation corresponding to the "answer".
[0108] Further, the first similarity is calculated, that is, the similarity between the target text and the text of the preset example, that is, the similarity (gap) of "text". The second similarity is calculated, that is, the similarity between the first label of the calculation process data and the first label of the preset example, that is, the similarity (gap) of "answer".
[0109] S30413: For each process data, calculate the sum of the first similarity and the second similarity to obtain the total similarity.
[0110] It can be understood that calculating the sum of the first similarity and the second similarity is to calculate the sum of the “answer” gap and the “text” gap.
[0111] S30414: Determine one or more process data as the second sampling data in descending order of total similarity.
[0112] It is understandable that in this step, a number of process data with the smallest difference (maximum similarity) can be sampled as the second sampled data. The specific number of samples can be 10 or 20, which is not specifically limited in the embodiment of the present application.
[0113] S30415: Determine one or more process data as the third sampling data in order of total similarity from small to large.
[0114] It is understandable that in this step, several process data with the largest difference (smallest similarity) can be sampled as the third sampled data. The specific number of samples can be 10 or 20, which is not specifically limited in the embodiment of the present application.
[0115] The diversity of data can be ensured by using random sampling, semantically furthest sampling and / or semantically closest sampling.
[0116] Figure 6A schematic diagram of the data screening process provided for an embodiment of the present application.
[0117] like Figure 6 As shown, S3042 may also include the following steps S30421-S30425.
[0118] S30421: For the sampled data, remove data that does not conform to a preset data format and remove data that lacks a target field to obtain a first subset of data, where the target field is determined by the preset data format.
[0119] The preset data format is json format, and the basic structure and fields of json format may include object, array, value, key, string, number, Boolean and null, and the target field may be one or more of them, which is not specifically limited in the embodiment of the present application. When an abnormal value or null value appears in the target field of the sampled data, it can be determined that the sampled data lacks the target field.
[0120] In some implementations, data that does not conform to data specifications may be removed from the sampled data, for example, only one paragraph of text, text that is too long or too short, or the length difference between two paragraphs of text is too large. In practical applications, such data may be removed.
[0121] S30422: Determine whether the proportion of first labels of different categories in the first subset data is equal to a preset proportion.
[0122] For example, the first subset data may include 3 data with matching first labels and 2 data with mismatching first labels, and the ratio of first labels of different categories is 3:2. Alternatively, the first subset data may include 3 data with matching first labels and 3 data with mismatching first labels, and the ratio of first labels of different categories is 1:1.
[0123] S30423: When the proportion of first labels of different categories is equal to a preset proportion, the first subset data is determined as the target data of the current round.
[0124] The preset ratio may be 1: 1. When the ratio of first labels of different categories is 1: 1, it may indicate that the ratio of first labels of different categories is equal to the preset ratio, and at this time, the screening may be terminated and the first subset data may be directly determined as the target data.
[0125] S30424: When the proportion of first labels of different categories is not equal to the preset proportion, remove one or more first subset data so that the proportion of first labels of different categories in the remaining first subset data is equal to the preset proportion.
[0126] Exemplarily, when the ratio of first labels of different categories is 3:2, the ratio is not equal to the preset ratio. In this case, one or more data with matching first labels can be removed to make the ratio of first labels of different categories become 1:1 to ensure balance. For example, when the first subset data includes 3 data with matching first labels and 2 data with unmatched first labels, in the step of removing data, any one of the 3 data with matching first labels can be removed.
[0127] S30425: Determine the first subset data as the target data for the current round.
[0128] In this way, the target data for the i-th round can be obtained, and further, the target data can be input into the large model as input data for the i+1-th round.
[0129] It can be seen that by sampling and screening the process data generated by the large model, the diversity of the target data and the balance of the labels can be ensured.
[0130] From the above content, it can be seen that the target data generation method based on the large model provided in the embodiment of the present application can iteratively generate rich labeled text data using only one example, and can ensure the diversity of data and the balance of labels, without lack of data in specific fields. Then, using the target data training model generated by the large model can also make the model run better, with better accuracy than the model trained with manual hand-labeled data, and has good comprehensive performance.
[0131] Figure 7 A flowchart of a text matching method provided in an embodiment of the present application.
[0132] like Figure 7 As shown, an embodiment of the present application provides a text matching method, including the following steps S400-S500.
[0133] S400: Acquire a first text and a second text;
[0134] S500: Input the first text and the second text into the target model, and use the target model to determine whether the semantics of the first text and the second text match; wherein the target model is a lightweight model, and the target model has been trained with target data, and the target data is generated based on the aforementioned target data generation method.
[0135] It is understandable that in the embodiment of the present application, the target model is the downstream model that performs the downstream task, and the target model can be, for example, the sentence-BERT model. Using the QWEN1.5-7B large model to generate the required data and then train the downstream text matching model Sentence-BERT is a supervised learning classification task.
[0136] Furthermore, the specific application scenario of the text matching method provided in the embodiment of the present application can be a text matching task for case classification in the legal field. Exemplarily, the first text can be text data of the case category to be determined, for example, the first text can be a sentence in the case complaint. The second text can be any piece of data in the target model training data. After determining through the target model that there is a semantic matching relationship between the first text and the second text, the case category of the first text can be determined to be the same as the case category of the second text.
[0137] Figure 8 A schematic diagram of the structure of a target data generation device based on a large model provided in an embodiment of the present application.
[0138] like Figure 8 As shown, the embodiment of the present application also provides a target data generation device based on a large model, wherein the target data is used to train the target model after being generated, so that the target model is used to perform a target task, and the target task is a classification task;
[0139] The target data generating device comprises:
[0140] Construction module 1001 is used to construct a first Prompt prompt project and a second Prompt prompt project; wherein the first Prompt prompt project includes task information related to the target task, and the first Prompt prompt project is used to prompt the large model to generate target data according to the task information; the second Prompt prompt project is used to limit the data composition of the target data;
[0141] A merging module 1002 is used to merge the first Prompt prompt project and the second Prompt prompt project to obtain a Prompt template;
[0142] The generation module 1003 is used to input the preset example and the Prompt template into the large model so that the large model generates multiple target data; wherein the preset example is any example in the original data set, and the preset example and the target data include at least a first label, and the first label is used to represent the category of the preset example and the target data.
[0143] In some implementations, when the target task is a classification task of determining whether the semantics of two texts match, the task information includes question-answer content determined based on the target task, the question-answer content includes a question-answer pair, an answer selection space, and a text format of the target data, the question-answer pair includes a question and an answer, the question is whether the semantics of the two texts match, the answer is one of the answer selection spaces, the answer selection space includes matches and mismatches, and the data composition refers to different target data generated by the large model having the same and / or different target features, and the target features at least include answer content, text content, and a preset data format;
[0144] The generation module 1003 is specifically used for: using the large model to generate two target texts and target answers according to rounds; wherein the target answers are determined based on the question-answer pairs and the answer selection space, and the target answers include whether they match; for each round, the first labels corresponding to the two target texts are determined based on the target answers, wherein different target answers correspond to first labels of different categories; the two target texts and the first labels are determined as process data; the process data is sampled and screened to obtain the target data.
[0145] In some implementations, the large model is used to generate process data based on input data and prompt templates in each round; wherein, for the first round, the input data of the large model is a preset example;
[0146] The generation module 1003 is also used for: for the i-th round, after the large model generates process data, sampling the process data to obtain sampled data, i≥1; screening the sampled data to obtain target data for the current round; and inputting the target data into the large model as input data for the i+1-th round.
[0147] In some implementations, the generation module 1003 is also used to: collect all target data generated from the 1st to the i-th rounds, and when the number of all target data is greater than or equal to a preset threshold, the large model stops generating data.
[0148] In some implementations, the generation module 1003 is also used to: for the sampled data, remove data that does not conform to a preset data format and remove data that lacks a target field to obtain a first subset of data, where the target field is determined by a preset data format, and the preset data format is a json format; determine whether the proportion of first labels of different categories in the first subset of data is equal to a preset proportion; when the proportion of first labels of different categories is equal to the preset proportion, determine the first subset of data as the target data for the current round.
[0149] In some implementations, the generation module 1003 is also used to: when the proportion of first labels of different categories is not equal to a preset proportion, remove one or more first subset data so that the proportion of first labels of different categories in the remaining first subset data is equal to the preset proportion; and determine the first subset data as the target data for the current round.
[0150] In some implementations, the sampled data includes one or more of first sampled data, second sampled data, and third sampled data, wherein the first sampled data is any one or more of the process data;
[0151] The generation module 1003 is also used to: calculate the first embedding vector corresponding to the two paragraphs of text in the preset example, and calculate the second embedding vector corresponding to the first label in the preset example; for each process data, calculate the third embedding vector corresponding to the two paragraphs of target text, and calculate the consin similarity between the third embedding vector and the first embedding vector to obtain the first similarity; and calculate the fourth embedding vector corresponding to the first label in the process data, and calculate the consin similarity between the fourth embedding vector and the second embedding vector to obtain the second similarity; for each process data, calculate the sum of the first similarity and the second similarity to obtain the total similarity; determine one or more process data as the second sampling data in the order of the total similarity from large to small; determine one or more process data as the third sampling data in the order of the total similarity from small to large.
[0152] In some implementations, the second Prompt prompt project includes at least: the text contents of two paragraphs of text in the target data are different; the answer contents of each target data are different from each other, and the text contents are different from each other; and the target data and the preset example have the same preset data format and answer selection space.
[0153] In a specific implementation, the present invention further provides a computer storage medium, wherein the computer storage medium may store a program, and when the program is executed, the program may include some or all of the steps in each embodiment of the target data generation method based on a large model provided by the present invention. The storage medium may be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).
[0154] It is easy to understand that those skilled in the art can combine, split, reorganize, etc. the embodiments of the present application to obtain other embodiments based on the several embodiments provided in the present application, and these embodiments do not exceed the protection scope of the present application.
[0155] The above specific implementation methods further explain in detail the purpose, technical solutions and beneficial effects of the embodiments of the present application. It should be understood that the above are only specific implementation methods of the embodiments of the present application and are not used to limit the protection scope of the embodiments of the present application. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solutions of the embodiments of the present application should be included in the protection scope of the embodiments of the present application.
Claims
1. A method for generating target data based on a large model, It is characterized in that The target data is used to train a target model after being generated, so that the target model is used to perform a target task, wherein the target task is a classification task; The target data generating method comprises: Constructing a first Prompt prompt project and a second Prompt prompt project; wherein the first Prompt prompt project includes task information related to the target task, and the first Prompt prompt project is used to prompt the large model to generate the target data according to the task information; the second Prompt prompt project is used to limit the data composition of the target data; The first Prompt prompt project and the second Prompt prompt project are combined to obtain a Prompt template; Input a preset example and the Prompt template into the large model so that the large model generates a plurality of target data; wherein the preset example is any example in the original data set, and the preset example and the target data include at least a first label, and the first label is used to represent the category of the preset example and the target data.
2. The target data generation method based on a large model according to claim 1, It is characterized in that When the target task is a classification task of determining whether the semantics of two paragraphs of text match, the task information includes question-answer content determined based on the target task, the question-answer content includes a question-answer pair, an answer selection space, and a text format of the target data, the question-answer pair includes a question and an answer, the question is whether the semantics of the two paragraphs of text match, the answer is one of the answer selection space, the answer selection space includes a match and a mismatch, the data composition means that different target data generated by the large model have the same and / or different target features, and the target features include at least the answer content, the text content, and a preset data format; The step of inputting the preset example and the Prompt template into the large model so that the large model generates a plurality of target data comprises: Using the large model to generate two target texts and a target answer in rounds; wherein the target answer is determined based on the question-answer pair and the answer selection space, and the target answer includes a result of whether it matches; For each round, determining the first labels corresponding to the two target texts based on the target answer, wherein different target answers correspond to different categories of the first labels; determining the two target texts and the first label as process data; The process data is sampled and screened to obtain the target data.
3. The target data generation method based on a large model according to claim 2, It is characterized in that In the step of using the large model to generate two target texts and a target answer in rounds, the large model is used to generate the process data based on the input data and the Prompt template in each round; wherein, for the first round, the input data of the large model is the preset example; The steps of sampling and screening the process data to obtain the target data include: For the i-th round, after the large model generates the process data, the process data is sampled to obtain sampled data, i≥1; Screening the sampled data to obtain the target data of the current round; The target data is input into the large model as the input data of the (i+1)th round.
4. The target data generation method based on a large model according to claim 3, It is characterized in that After the step of screening the sampled data to obtain the target data of the current round, the method further includes: All the target data generated from the 1st to the i-th rounds are collected, and when the number of all the target data is greater than or equal to a preset threshold, the large model stops generating data.
5. The method for generating target data based on a large model according to claim 3, It is characterized in that The step of screening the sampled data to obtain the target data of the current round includes: For the sampled data, remove data that does not conform to the preset data format and remove data that lacks a target field to obtain a first subset of data, where the target field is determined by the preset data format, and the preset data format is a json format; Determining whether the proportion of the first labels of different categories in the first subset data is equal to a preset proportion; When the proportion of the first labels of different categories is equal to a preset proportion, the first subset data is determined as the target data of the current round.
6. The target data generation method based on a large model according to claim 5, It is characterized in that After the step of determining whether the proportion of the first labels of different categories in the first subset data is equal to a preset proportion, the method further includes: When the proportion of the first labels of different categories is not equal to the preset proportion, removing one or more first subset data so that the proportion of the first labels of different categories in the remaining first subset data is equal to the preset proportion; The first subset data is determined as the target data of the current round.
7. The method for generating target data based on a large model according to claim 3, It is characterized in that The sampled data includes one or more of first sampled data, second sampled data and third sampled data, wherein the first sampled data is any one or more of the process data; The method further comprises: Calculate the first embedding vector corresponding to the two paragraphs of text in the preset example, and calculate the second embedding vector corresponding to the first label in the preset example; For each of the process data, a third embedding vector corresponding to the two target texts is calculated, and a cons similarity between the third embedding vector and the first embedding vector is calculated to obtain a first similarity; and a fourth embedding vector corresponding to the first label in the process data is calculated, and a cons similarity between the fourth embedding vector and the second embedding vector is calculated to obtain a second similarity; For each of the process data, calculating the sum of the first similarity and the second similarity to obtain a total similarity; Determine, in descending order of the total similarity, one or more of the process data as the second sampling data; According to the order of the total similarity from small to large, one or more of the process data are determined as the third sampling data.
8. The method for generating target data based on a large model according to any one of claims 2 to 7, It is characterized in that The second Prompt prompt project includes at least: the text contents of the two paragraphs of the target data are different; the answer contents of each target data are different from each other, and the text contents are different from each other; and the target data and the preset example have the same preset data format and the answer selection space.
9. A text matching method, It is characterized in that include: Obtaining a first text and a second text; The first text and the second text are input into a target model, and the target model is used to determine whether the semantics of the first text and the second text match; wherein the target model is a lightweight model, and the target model has been trained with target data, and the target data is generated based on the large model-based target data generation method described in any one of claims 1-8.
10. A target data generation device based on a large model, It is characterized in that The target data is used to train a target model after being generated, so that the target model is used to perform a target task, wherein the target task is a classification task; The target data generating device comprises: A construction module is used to construct a first Prompt prompt project and a second Prompt prompt project; wherein the first Prompt prompt project includes task information related to the target task, and the first Prompt prompt project is used to prompt the large model to generate the target data according to the task information; the second Prompt prompt project is used to limit the data composition of the target data; A merging module, used for combining the first Prompt prompt project and the second Prompt prompt project to obtain a Prompt template; A generation module is used to input a preset example and the Prompt template into the large model so that the large model generates a plurality of target data; wherein the preset example is any example in the original data set, and the preset example and the target data include at least a first label, and the first label is used to represent the category of the preset example and the target data.
Citation Information
Cited By
Large model data set generation method and device, electronic equipment and storage medium
CN120974180A
