A method and device for training a text embedding module of a large language model

By specifying a second model to construct a training data set and independently training the text embedding module of the large language model, the problems of high training cost and low efficiency in the existing technology are solved, and regular updates and efficiency improvements are achieved.

CN118504714BActive Publication Date: 2024-09-24BEIJING DP TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410961481.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-18
Publication Date
2024-09-24
Estimated Expiration
2044-07-18

AI Technical Summary

Technical Problem

The existing training methods for large language models require regular training of the entire model, resulting in high cost and low efficiency of updated and intensive training of text embedding modules, making it difficult to achieve independent training.

Method used

By specifying a large language model as the second model, building a training data set based on preset data generation task configurations, independently training the text embedding module, and using the verification platform to verify performance, regular updates and efficiency improvements are achieved.

Benefits of technology

It achieves independent training of large language model text embedding modules, shortens training preparation time, reduces data collection and training costs, and improves the training efficiency and performance of the module.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118504714B
    Figure CN118504714B
Patent Text Reader

Abstract

The embodiment of the present invention relates to a method and device for training a text embedding module of a large language model, the method comprising: recording the large language model where the text embedding module to be trained is located as the corresponding first model; and specifying another large language model as the corresponding second model; and using the preset data generation task configuration as the corresponding first configuration; constructing a training data set according to the first configuration and the second model to obtain the corresponding first data set; and training the text embedding module of the first model based on the first data set. Through the present invention, the text embedding module can be trained separately, the module training efficiency can be improved, and the module training cost can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a method and device for training a text embedding module of a large language model. Background Art

[0002] The Text Embedding module is a key benchmark module for large language models (LLMs). It is used to convert various types of text information involved in the LLM model reasoning process into text embedding encoding vectors. The encoding quality of the Text Embedding module is closely related to the task processing quality of the LLM model. For example, when the LLM model processes a certain type of model task (such as retrieval, question and answer, etc.), it needs to first perform a semantic comparison between the task text information input to the model and various types of data information connected to the model inside or outside, and then extract highly similar or related data information to form the corresponding task context according to the corresponding task context encapsulation rules, and finally assemble the output text according to the task context according to the model task type (such as retrieval, question and answer, etc.); and in the above semantic comparison process, the LLM model will use the text embedding module to convert the task text information and data information into text embedding coding vectors respectively, and then calculate the semantic similarity or correlation based on the text embedding coding vector and filter the data information based on the calculation results; it is not difficult to see that in the above model task processing process, if the encoding quality of the text embedding module is higher, the filtered data information will be more matched and the model task completion quality will be higher. Conversely, if the encoding quality of the text embedding module is lower, the corresponding model task completion quality will be lower.

[0003] In principle, if you want to keep the encoding quality of the text embedding module at a high quality level, you need to regularly update and strengthen the text embedding module. However, the current training methods of the LLM model all belong to the integrated training method. If you want to regularly train the text embedding module, you need to regularly train the entire LLM model, which is unacceptable in terms of training time and training cost. To solve this problem, it is necessary to provide a processing mechanism that can train the text embedding module separately, which is also the technical problem to be solved by the present invention. Summary of the invention

[0004] The purpose of the present invention is to provide a method, device, electronic device and computer-readable storage medium for training the text embedding module of a large language model in view of the defects of the prior art. The present invention records the large language model where the text embedding module to be trained is located as the corresponding first model, and designates another large language model as the corresponding second model; and constructs a training data set based on the preset data generation task configuration and the second model to obtain the corresponding first data set; and trains the text embedding module of the first model based on the first data set; and after the training, uses the specified text embedding verification platform to verify the text embedding performance of the text embedding module. Through the present invention, on the one hand, the text embedding module of the LLM model can be independently trained to achieve the purpose of regularly updating and strengthening the training of the text embedding module; on the other hand, other LLM models can be used to quickly construct a training data set, so as to shorten the training preparation time, reduce the data acquisition cost, improve the module training efficiency and reduce the module training cost.

[0005] To achieve the above object, a first aspect of an embodiment of the present invention provides a method for training a text embedding module of a large language model, the method comprising:

[0006] The large language model where the text embedding module to be trained is located is recorded as the corresponding first model; another large language model is designated as the corresponding second model; and the preset data generation task configuration is designated as the corresponding first configuration;

[0007] Constructing a training data set according to the first configuration and the second model to obtain a corresponding first data set;

[0008] The text embedding module of the first model is trained based on the first data set.

[0009] Preferably, the second model includes at least a Wenxinyiyan series model and a GPT series model.

[0010] Preferably, the first configuration includes a knowledge domain set, a language type set, a total number of knowledge domains A, a total number of data records B, a total number of single-domain task pools C, a total number of single-record negative samples D, a minimum sample text length E, a maximum sample text length F, a retrieval task pool creation instruction template, and a retrieval task execution instruction template;

[0011] The total number of knowledge domains A, the total number of data records B, the total number of single-domain task pools C, the total number of single-record negative samples D, the minimum sample text length E, and the maximum sample text length F are all positive integers; and the total number of data records B can be divided by the product of the total number of knowledge domains A and the total number of single-domain task pools C; the minimum sample text length E is less than the maximum sample text length F;

[0012] The knowledge domain set includes a plurality of knowledge domain texts; the total number of knowledge domains A is the total number of the knowledge domain texts;

[0013] The language type set includes multiple language types; the language types include at least Chinese, English, French, German, Russian, Japanese, Korean, and Spanish;

[0014] The retrieval task pool creation instruction template is a text template for prompting the second model to construct a specified number Y of retrieval task pools within the specified knowledge domain X, and to assign a unique task pool number to each constructed retrieval task pool; the specified knowledge domain X and the specified number Y are two replaceable text variables; the specified knowledge domain X is replaced by one of the knowledge domain texts in the knowledge domain set; the specified number Y is replaced by the total number C of the single-domain task pool;

[0015] The retrieval task execution instruction template is a text template for prompting the second model to create a data generation task in the specified retrieval task pool T and generate a question-answering retrieval information group consisting of a question text, a positive sample retrieval text and a specified number Z of negative sample retrieval texts according to a preset data generation rule; the specified retrieval task pool T and the specified number Z are two replaceable text variables; the specified retrieval task pool T is replaced by a task pool number; the specified number Z is replaced by the total number D of single-record negative samples;

[0016] The data generation rule is used to limit the language type of the question-answer retrieval information group to a specified language L; and to limit the comparison relationship between the text string length of the question text and the positive sample retrieval text to satisfy any one of the three comparison relationships of less than, equal to or greater than; and to limit the comparison relationship between the text string length of the question text and any one of the negative sample retrieval texts to satisfy any one of the three comparison relationships of less than, equal to or greater than, and the Z comparison relationships corresponding to the Z negative sample retrieval texts must fully cover the three comparison relationships of less than, equal to and greater than, otherwise they will be regenerated; and to limit the length range of the text string length of the positive sample retrieval text and each of the negative sample retrieval texts to a minimum length s min and the maximum length s max The value range of the specified language L, the minimum length s min and the maximum length s max are three replaceable text variables; the specified language L is replaced by one of the language types in the language type set; the minimum length s min and the maximum length s maxare replaced by the corresponding minimum sample text length E and the maximum sample text length F respectively;

[0017] The first data set includes multiple first data records; the first data record includes a first question text, a first positive sample text and a first negative sample text set; the first negative sample text set consists of the first negative sample text of the total number D of single-record negative samples.

[0018] Preferably, constructing a training data set according to the first configuration and the second model to obtain a corresponding first data set specifically includes:

[0019] Step 401: The quotient of the total number of data records B of the first configuration divided by the total number of knowledge domains A is taken as the corresponding total number of single-domain records; and the quotient of the total number of single-domain records divided by the total number of single-domain task pools C is taken as the corresponding total number of single-task pool records;

[0020] Step 402, taking the first knowledge domain text in the knowledge domain set as the corresponding current knowledge domain;

[0021] Step 403, replace the specified knowledge domain X in the retrieval task pool creation instruction template with the corresponding current knowledge domain, and replace the specified quantity Y with the corresponding total number C of the single-domain task pool; and use the replaced retrieval task pool creation instruction template as the corresponding current-domain task pool creation instruction text;

[0022] Step 404, input the current domain task pool creation instruction text into the second model to retrieve the task pool creation, and receive the C task pool numbers fed back by the second model and the task pool description text corresponding to each task pool number; and the C task pool numbers obtained this time form the corresponding current domain task collection;

[0023] Step 405, taking the first task pool number of the current domain task collection as the corresponding current task pool number; and initializing the first counter to 1;

[0024] Step 406: replace the specified search task pool T in the search task execution instruction template with the current task pool number, replace the specified number Z with the corresponding total number of single-record negative samples D, and randomly select a language from the language set to replace the specified language L, and replace the minimum length s min and the maximum length s max Replace the minimum sample text length E and the maximum sample text length F with the corresponding ones; and use the search task execution instruction template that has completed the replacement as the corresponding current task execution instruction text;

[0025] Step 407, inputting the current task execution instruction text into the second model to perform data generation task processing, and receiving one of the question-and-answer retrieval information groups fed back by the second model as the corresponding current retrieval information group;

[0026] Step 408: the question text of the current search information group is taken as a corresponding first question text; the positive sample search text of the current search information group is taken as a corresponding first positive sample text; each negative sample search text of the current search information group is taken as a corresponding first negative sample text, and the D first negative sample texts obtained this time are formed into a corresponding first negative sample text set; and the first question text, the first positive sample text and the first negative sample text set obtained this time are formed into a corresponding first data record;

[0027] Step 409, whether the first counter is less than the total number of records in the single task pool is identified; if the first counter is less than the total number of records in the single task pool, then the first counter is increased by 1, and a language type is randomly selected from the language type set to replace the specified language L in the current task execution instruction text to obtain a new current task execution instruction text, and then the process returns to step 407; if the first counter is greater than or equal to the total number of records in the single task pool, then the first counter is reset to 1, and whether the current task pool number is the last task pool number in the current domain task collection is identified, if so, then the process goes to step 410, if not, the next task pool number in the current domain task collection is used as the new current task pool number and then the process returns to step 406;

[0028] Step 410, identifying whether the current knowledge domain is the last knowledge domain text in the knowledge domain set; if so, going to step 411; if not, taking the next knowledge domain text in the knowledge domain set as the new current knowledge domain and returning to step 403;

[0029] Step 411: The B first data records obtained this time are used to form the corresponding first data set.

[0030] Preferably, the training of the text embedding module of the first model based on the first data set specifically includes:

[0031] Step 51, taking the first first data record of the first data set as the corresponding current data record;

[0032] Step 52: input the first question text of the current data record into the text embedding module for text embedding coding vector conversion to obtain the corresponding first vector q; input the first positive sample text of the current data record into the text embedding module for text embedding coding vector conversion to obtain the corresponding second vector d; and input each of the first negative sample texts of the current data record into the text embedding module for text embedding coding vector conversion to obtain the corresponding third vector n i , 1≤negative sample index i≤D;

[0033] Step 53: The first vector q, the second vector d and all the third vectors n obtained this time are i Bring in the preset model loss function L M Calculate and obtain the corresponding first loss value;

[0034] in,

[0035] ,

[0036] ,

[0037] ,

[0038] F() is the temperature scale cosine similarity function, cos() is the cosine similarity function, and τ is the preset temperature scale constant;

[0039] Step 54, identifying whether the first loss value satisfies a preset first loss value range; if the first loss value does not satisfy the first loss value range, moving toward making the model loss function L M A round of modulation is performed on the model parameters of the text embedding module in the direction of reaching the minimum value, and the step 52 is returned at the end of this round of modulation; if the first loss value satisfies the first loss value range, it is identified whether the current data record is the last one of the first data record of the first data set, if not, the next one of the first data record of the first data set is used as the new current data record and the step 52 is returned, if so, the training is stopped and it is confirmed that the training of the text embedding module of the first model is completed.

[0040] Preferably, the method further comprises:

[0041] After the training of the text embedding module of the first model is completed, the text embedding performance of the text embedding module is verified using a specified text embedding verification platform; the specified text embedding verification platform includes a text embedding verification platform based on the BEIR benchmark and a text embedding verification platform based on the MTEB benchmark.

[0042] A second aspect of an embodiment of the present invention provides a device for implementing the method for training a text embedding module of a large language model described in the first aspect, the device comprising: a data preparation module, a training data set construction module, a text embedding training module, and a text embedding verification module;

[0043] The data preparation module is used to record the large language model where the text embedding module to be trained is located as the corresponding first model; and designate another large language model as the corresponding second model; and use the preset data generation task configuration as the corresponding first configuration;

[0044] The training data set construction module is used to construct a training data set according to the first configuration and the second model to obtain a corresponding first data set;

[0045] The text embedding training module is used to train the text embedding module of the first model based on the first data set;

[0046] The text embedding verification module is used to verify the text embedding performance of the text embedding module using a specified text embedding verification platform after the training of the text embedding module of the first model is completed; the specified text embedding verification platform includes a text embedding verification platform based on the BEIR benchmark and a text embedding verification platform based on the MTEB benchmark.

[0047] A third aspect of an embodiment of the present invention provides an electronic device, including: a memory, a processor, and a transceiver;

[0048] The processor is used to be coupled to the memory, read and execute instructions in the memory, so as to implement the method steps described in the first aspect above;

[0049] The transceiver is coupled to the processor, and the processor controls the transceiver to send and receive messages.

[0050] A fourth aspect of an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions. When the computer instructions are executed by a computer, the computer executes the instructions of the method described in the first aspect above.

[0051] The embodiment of the present invention provides a method, device, electronic device and computer-readable storage medium for training a text embedding module of a large language model. As can be seen from the above content, the embodiment of the present invention records the large language model where the text embedding module to be trained is located as the corresponding first model, and designates another large language model as the corresponding second model; and constructs a training data set based on the preset data generation task configuration and the second model to obtain the corresponding first data set; and trains the text embedding module of the first model based on the first data set; and after the training, uses the specified text embedding verification platform to verify the text embedding performance of the text embedding module. Through the embodiment of the present invention, on the one hand, the text embedding module of the LLM model can be independently trained to achieve the purpose of regularly updating and strengthening the training of the text embedding module; on the other hand, other LLM models can be used to quickly construct training data sets, shortening the training preparation time, reducing the data collection cost, improving the module training efficiency, and reducing the module training cost. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Figure 1 A schematic diagram of a method for training a text embedding module of a large language model provided in Embodiment 1 of the present invention;

[0053] Figure 2 A module structure diagram of a device for training a text embedding module of a large language model provided in Embodiment 2 of the present invention;

[0054] Figure 3 A schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present invention. DETAILED DESCRIPTION

[0055] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0056] Embodiment 1 of the present invention provides a method for training a text embedding module of a large language model, such as Figure 1 As shown in a schematic diagram of a method for training a text embedding module of a large language model provided in Embodiment 1 of the present invention, the method mainly includes the following steps:

[0057] Step 1: record the large language model where the text embedding module to be trained is located as the corresponding first model; and designate another large language model as the corresponding second model; and use the preset data generation task configuration as the corresponding first configuration.

[0058] Here, the first and second models of the embodiment of the present invention are both large language models; the first model can be an LLM model such as Mistral or LLaMA, or any other known LLM model; the second model can be an LLM model such as the Wenxin Yiyan series or the GPT series, or any other known LLM model.

[0059] In addition, the first configuration includes a knowledge domain set, a language type set, a total number of knowledge domains A, a total number of data records B, a total number of single-domain task pools C, a total number of single-record negative samples D, a minimum sample text length E, a maximum sample text length F, a retrieval task pool creation instruction template, and a retrieval task execution instruction template; wherein,

[0060] 1) The total number of knowledge domains A, the total number of data records B, the total number of single-domain task pools C, the total number of single-record negative samples D, the minimum sample text length E, and the maximum sample text length F are all positive integers; the total number of data records B can be divided by the product of the total number of knowledge domains A and the total number of single-domain task pools C; the minimum sample text length E is less than the maximum sample text length F;

[0061] 2) The knowledge domain set includes multiple knowledge domain texts; the total number of knowledge domains A is the total number of knowledge domain texts;

[0062] Here, each knowledge domain text can be any knowledge domain, such as legal knowledge domain, medical knowledge domain, computer knowledge domain, architectural knowledge domain, art knowledge domain, etc.;

[0063] 3) The language type set includes multiple language types; here, the language types in the embodiment of the present invention include at least Chinese, English, French, German, Russian, Japanese, Korean, and Spanish; more languages ​​may be added to the language types or some languages ​​may be deleted from the language types according to actual application requirements;

[0064] 4) The retrieval task pool creation instruction template is a text template for prompting the second model to construct a specified number Y of retrieval task pools within the specified knowledge domain X, and to assign a unique task pool number to each constructed retrieval task pool;

[0065] Here, the specified knowledge domain X and the specified quantity Y in the template are two replaceable text variables; the specified knowledge domain X is replaced by a knowledge domain text in the knowledge domain set; the specified quantity Y is replaced by the total number C of the single-domain task pool;

[0066] For example, let the Chinese retrieval task pool creation instruction template be: "Build a specified number Y of retrieval task pools within the specified knowledge domain X range, and assign a unique task pool number to each built retrieval task pool";

[0067] Known knowledge domain X = "medical knowledge domain", specified quantity Y = 5;

[0068] Then, based on this template, a corresponding task pool creation instruction text can be obtained: "Construct 5 retrieval task pools within the scope of medical knowledge domain, and assign a unique task pool number to each constructed retrieval task pool";

[0069] 5) The retrieval task execution instruction template is a text template for prompting the second model to create a data generation task in the specified retrieval task pool T and generate a question-answering retrieval information group consisting of a question text, a positive sample retrieval text and a specified number Z of negative sample retrieval texts according to the preset data generation rules;

[0070] Here, the specified retrieval task pool T and the specified quantity Z in the template are two replaceable text variables; the specified retrieval task pool T is replaced by a task pool number; the specified quantity Z is replaced by the total number of single-record negative samples D;

[0071] The data generation rules given in the template are used to limit the language type of the question-answer retrieval information group to the specified language L; and limit the comparison relationship between the text string length of the question text and the positive sample retrieval text to satisfy any of the three comparison relationships of less than, equal to or greater than; and limit the comparison relationship between the text string length of the question text and any negative sample retrieval text to satisfy any of the three comparison relationships of less than, equal to or greater than, and the Z comparison relationships corresponding to the Z negative sample retrieval texts must fully cover the three comparison relationships of less than, equal to and greater than, otherwise they will be regenerated; and limit the length range of the text string length of the positive sample retrieval text and each negative sample retrieval text to a minimum length s min and the maximum length s max The value range of the specified language L and the minimum length s min and the maximum length s max are three replaceable text variables; the specified language L is replaced by a language in the language set; the minimum length is s min and the maximum length s max They are replaced by the corresponding minimum sample text length E and maximum sample text length F respectively;

[0072] For example, suppose the Chinese search task execution instruction template is:

[0073] "Create a data generation task in the task pool numbered as the specified retrieval task pool T and generate a question-answering retrieval information group consisting of a question text, a positive sample retrieval text and a specified number Z of negative sample retrieval texts according to the data generation rule;

[0074] The data generation rules are as follows: the language type of the question-answer retrieval information group is limited to the specified language L; the comparison relationship between the text string length of the question text and the positive sample retrieval text is limited to satisfy any one of the three comparison relationships of less than, equal to or greater than; the comparison relationship between the text string length of the question text and each negative sample retrieval text is limited to satisfy any one of the three comparison relationships of less than, equal to or greater than, and the specified number Z comparison relationships corresponding to the specified number Z negative sample retrieval texts must fully cover the three comparison relationships of less than, equal to and greater than, otherwise they will be regenerated; the value range of the text string length of the positive sample retrieval text and each negative sample retrieval text is limited to [minimum length s min , maximum length s max ]",

[0075] Given that the specified search task pool T = Medicine 5, the specified number Z = 20, the specified language L = Chinese, and the minimum length s min =10, maximum length s max =100;

[0076] Then, based on this template, a corresponding task execution instruction text can be obtained: "Create a data generation task in the task pool numbered as medicine 5 and generate a question-answering retrieval information group consisting of a question text, a positive sample retrieval text and 20 negative sample retrieval texts according to the data generation rules;

[0077] The data generation rules are as follows: the language type of the question-answer retrieval information group is limited to Chinese; the comparison relationship between the text string length of the question text and the positive sample retrieval text is limited to satisfy any one of the three comparison relationships of less than, equal to or greater than; the comparison relationship between the text string length of the question text and each negative sample retrieval text is limited to satisfy any one of the three comparison relationships of less than, equal to or greater than, and the 20 comparison relationships corresponding to the 20 negative sample retrieval texts must fully cover the three comparison relationships of less than, equal to and greater than, otherwise they will be regenerated; the value range of the text string length of the positive sample retrieval text and each negative sample retrieval text is limited to [10,100]".

[0078] Step 2, constructing a training data set according to the first configuration and the second model to obtain a corresponding first data set;

[0079] The first data set includes a plurality of first data records; the first data record includes a first question text, a first positive sample text and a first negative sample text set; the first negative sample text set consists of the first negative sample text with a total number of single-record negative samples D;

[0080] Specifically comprising: step 2-1, taking the quotient of the total number of data records B of the first configuration divided by the total number of knowledge domains A as the corresponding total number of single-domain records; and taking the quotient of the total number of single-domain records divided by the total number of single-domain task pools C as the corresponding total number of single-task pool records;

[0081] For example, the parameters of the first configuration are known to be as follows:

[0082] The knowledge domain set is {legal knowledge domain, medical knowledge domain, computer knowledge domain, architectural knowledge domain, and artistic knowledge domain}.

[0083] The language set is {Chinese, English, French, German},

[0084] The total number of knowledge areas A=5,

[0085] The total number of data records B = 1000,

[0086] The total number of single-domain task pools C=20,

[0087] The total number of single-record negative samples is D=4,

[0088] Minimum sample text length E=10,

[0089] Maximum sample text length F=100,

[0090] The retrieval task pool creation instruction template is "build a specified number of Y retrieval task pools within the specified knowledge domain X range, and assign a unique task pool number to each constructed retrieval task pool".

[0091] The retrieval task execution instruction template is "create a data generation task in the task pool numbered as the specified retrieval task pool T and generate a question-answering retrieval information group consisting of a question text, a positive sample retrieval text and a specified number Z of negative sample retrieval texts according to the data generation rule by the current data generation task;

[0092] The data generation rules are as follows: the language type of the question-answer retrieval information group is limited to the specified language L; the comparison relationship between the text string length of the question text and the positive sample retrieval text is limited to satisfy any one of the three comparison relationships of less than, equal to or greater than; the comparison relationship between the text string length of the question text and each negative sample retrieval text is limited to satisfy any one of the three comparison relationships of less than, equal to or greater than, and the specified number Z comparison relationships corresponding to the specified number Z negative sample retrieval texts must fully cover the three comparison relationships of less than, equal to and greater than, otherwise they will be regenerated; the value range of the text string length of the positive sample retrieval text and each negative sample retrieval text is limited to [minimum length s min , maximum length s max ]”;

[0093] Then, the total number of single-domain records = B / A = 1000 / 5 = 200, the total number of single-task pool records = the total number of single-domain records / the total number of single-domain task pools C = 200 / 20 = 10;

[0094] Step 2-2, taking the first knowledge domain text in the knowledge domain set as the corresponding current knowledge domain;

[0095] For example, given that the set of knowledge domains is {legal knowledge domain, medical knowledge domain, computer knowledge domain, architectural knowledge domain, and art knowledge domain}, then the first knowledge domain text is the legal knowledge domain;

[0096] Step 2-3, replace the specified knowledge domain X in the retrieval task pool creation instruction template with the corresponding current knowledge domain, and replace the specified quantity Y with the corresponding single-domain task pool total number C; and use the replaced retrieval task pool creation instruction template as the corresponding current domain task pool creation instruction text;

[0097] Here, it is known that the current knowledge domain = legal knowledge domain, the specified quantity Y = the total number of single-domain task pools C = 20, then the current domain task pool creation instruction text is: "Construct 20 retrieval task pools within the scope of the legal knowledge domain, and assign a unique task pool number to each constructed retrieval task pool";

[0098] Step 2-4, input the current domain task pool creation instruction text into the second model to retrieve the task pool creation, and receive the C task pool numbers fed back by the second model and the task pool description text corresponding to each task pool number; and the C task pool numbers obtained this time form the corresponding current domain task collection;

[0099] For example, let the Wenxinyiyan model be used as the second model. After the current domain task pool creation instruction text "construct 20 retrieval task pools within the scope of the legal knowledge domain and assign a unique task pool number to each constructed retrieval task pool" is input into the Wenxinyiyan model, the Wenxinyiyan model will feedback the successful creation information of the 20 retrieval task pools, and use Law 1-20 as the task pool numbers of the 20 retrieval task pools, and give a corresponding brief description of the retrieval function of each retrieval task pool, i.e., the task pool description text;

[0100] Step 2-5, taking the first task pool number of the current domain task collection as the corresponding current task pool number; and initializing the first counter to 1;

[0101] Step 2-6: Replace the specified retrieval task pool T in the retrieval task execution instruction template with the current task pool number, replace the specified number Z with the corresponding total number of single-record negative samples D, and randomly select a language from the language set to replace the specified language L, and replace the minimum length s min and the maximum length s max Replace with the corresponding minimum sample text length E and maximum sample text length F; and use the replaced retrieval task execution instruction template as the corresponding current task execution instruction text;

[0102] Here, let the current task pool number be Law 1, let the language type randomly selected from the language type set this time be English, then the specified retrieval task pool T = Law 1, the specified language L = English; in addition, it is also known that the specified number Z = the total number of single record negative samples D = 4, the minimum length s min = minimum sample text length E = 10, maximum length s max = Maximum sample text length F = 100, then the current task execution instruction text is obtained as follows:

[0103] "Create a data generation task in the task pool numbered as Law 1 and generate a question-answering retrieval information group consisting of a question text, a positive sample retrieval text and four negative sample retrieval texts according to the data generation rule;

[0104] The data generation rules are as follows: the language of the question-answer retrieval information group is limited to English; the comparison relationship between the text string length of the question text and the positive sample retrieval text is limited to satisfy any of the three comparison relationships of less than, equal to or greater than; the comparison relationship between the text string length of the question text and each negative sample retrieval text is limited to satisfy any of the three comparison relationships of less than, equal to or greater than, and the four comparison relationships corresponding to the four negative sample retrieval texts must fully cover the three comparison relationships of less than, equal to and greater than, otherwise they will be regenerated; the value range of the text string length of the positive sample retrieval text and each negative sample retrieval text is limited to [10,100]".

[0105] Step 2-7, inputting the current task execution instruction text into the second model for data generation task processing, and receiving a question-and-answer retrieval information group fed back by the second model as the corresponding current retrieval information group;

[0106] For example, let the Wenxinyiyan model be used as the second model. After the current task execution instruction text is input into the Wenxinyiyan model, the Wenxinyiyan model will feedback an English question-answering retrieval information group, and the question text, positive sample retrieval text and four negative sample retrieval texts of the question-answering retrieval information group all meet the corresponding clauses in the data generation rules;

[0107] Step 2-8, the question text of the current search information group is used as a corresponding first question text; the positive sample search text of the current search information group is used as a corresponding first positive sample text; each negative sample search text of the current search information group is used as a corresponding first negative sample text, and the D first negative sample texts obtained this time form a corresponding first negative sample text set; and the first question text, the first positive sample text and the first negative sample text set obtained this time form a corresponding first data record;

[0108] Here, it can be seen that the embodiment of the present invention actually utilizes the language processing capability of the LLM model to automatically generate a training data set. This process can be completed automatically and quickly without consuming any human search resources, and can provide diversity and complexity requirements for the generated data through the configuration of the instruction template;

[0109] Step 2-9, identify whether the first counter is less than the total number of single task pool records; if the first counter is less than the total number of single task pool records, add 1 to the first counter, and randomly select a language type from the language type set to replace the specified language L in the current task execution instruction text to obtain a new current task execution instruction text, and return to step 2-7; if the first counter is greater than or equal to the total number of single task pool records, reset the first counter to 1, and identify whether the current task pool number is the last task pool number in the current domain task collection. If so, go to step 2-10, if not, use the next task pool number of the current domain task collection as the new current task pool number and return to step 2-6;

[0110] Step 2-10, identifying whether the current knowledge domain is the last knowledge domain text in the knowledge domain set; if so, go to step 2-11; if not, take the next knowledge domain text in the knowledge domain set as the new current knowledge domain and return to step 2-3;

[0111] Step 2-11, forming a corresponding first data set from the B first data records obtained this time.

[0112] Step 3, training the text embedding module of the first model based on the first data set;

[0113] Specifically comprising: step 31, taking the first first data record of the first data set as the corresponding current data record;

[0114] Step 32: Input the first question text of the current data record into the text embedding module for text embedding coding vector conversion to obtain the corresponding first vector q; input the first positive sample text of the current data record into the text embedding module for text embedding coding vector conversion to obtain the corresponding second vector d; and input each first negative sample text of the current data record into the text embedding module for text embedding coding vector conversion to obtain the corresponding third vector n i , 1≤negative sample index i≤D;

[0115] Step 33: The first vector q, the second vector d and all the third vectors n obtained this time are i Bring in the preset model loss function L M Calculate and obtain the corresponding first loss value;

[0116] Here, the model loss function L of the embodiment of the present invention is M It is implemented based on the InfoNCE loss function, specifically:

[0117] ,

[0118] ,

[0119] ;

[0120] Wherein, F() is the temperature scale cosine similarity function, cos() is the cosine similarity function, and τ is the preset temperature scale constant;

[0121] Step 34, identifying whether the first loss value satisfies a preset first loss value range; if the first loss value does not satisfy the first loss value range, moving in a direction that makes the model loss function L M A round of modulation is performed on the model parameters of the text embedding module in the direction of reaching the minimum value, and the step 32 is returned at the end of this round of modulation; if the first loss value satisfies the first loss value range, it is identified whether the current data record is the last first data record of the first data set, if not, the next first data record of the first data set is used as the new current data record and the step 32 is returned, if so, the training is stopped and it is confirmed that the training of the text embedding module of the first model is completed.

[0122] Here, the first loss value range is a preset loss value range.

[0123] Step 4: After the training of the text embedding module of the first model is completed, the text embedding performance of the text embedding module is verified using a specified text embedding verification platform.

[0124] Here, the text embedding verification platform specified in the embodiment of the present invention includes at least a text embedding verification platform implemented based on the BEIR benchmark (BEIRbenchmark) and a text embedding verification platform implemented based on the MTEB benchmark (MTEB benchmark). Both types of text embedding verification platforms of the benchmarks have public platform software and software instructions. Based on the public software instructions, it can be clearly understood how to verify the model or module to be verified on these two verification platforms, and how to use the data sets of these two platforms to verify the text embedding performance of the model or module to be verified. No repetitive details will be given here. Because the data sets and retrieval task types of the text embedding verification platforms of these two types of benchmarks are rich enough, the embodiment of the present invention will connect the text embedding module after training to the text embedding verification platform of these two types of benchmarks for text embedding performance verification. After completing the verification, if the verification effect reaches the expected goal, the operation can be stopped. If the verification effect does not reach the expected goal, it can continue to return to step 2 to build the data set and train the text embedding module again, or continue to return to step 3 to train the text embedding module again until the latest verification effect reaches the expected goal.

[0125] Figure 2 A module structure diagram of a device for training a text embedding module of a large language model provided in Embodiment 2 of the present invention, the device is a terminal device or server that implements the aforementioned method embodiment, and can also be a device that enables the aforementioned terminal device or server to implement the aforementioned method embodiment, for example, the device can be a device or chip system of the aforementioned terminal device or server. Figure 2 As shown, the device includes: a data preparation module 201, a training data set construction module 202, a text embedding training module 203 and a text embedding verification module 204.

[0126] The data preparation module 201 is used to record the large language model where the text embedding module to be trained is located as the corresponding first model; and designate another large language model as the corresponding second model; and use the preset data generation task configuration as the corresponding first configuration.

[0127] The training data set construction module 202 is used to construct a training data set according to the first configuration and the second model to obtain a corresponding first data set.

[0128] The text embedding training module 203 is used to train the text embedding module of the first model based on the first data set;

[0129] The text embedding verification module 204 is used to verify the text embedding performance of the text embedding module using a specified text embedding verification platform after the training of the text embedding module of the first model is completed; the specified text embedding verification platform includes a text embedding verification platform based on the BEIR benchmark and a text embedding verification platform based on the MTEB benchmark.

[0130] An embodiment of the present invention provides a device for training a text embedding module of a large language model, which can execute the method steps in the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here.

[0131] It should be noted that it should be understood that the division of the various modules of the above device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software called by processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software called by processing elements, and some modules can be implemented in the form of hardware. For example, the data preparation module can be a separately established processing element, or it can be integrated in a chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a processing element of the above device. The function of the above-mentioned module is determined. The implementation of other modules is similar. In addition, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element described here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or instructions in the form of software.

[0132] For example, the above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASIC), or one or more digital signal processors (DSP), or one or more field programmable gate arrays (FPGA). For another example, when a module above is implemented in the form of a processing element scheduling program code, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).

[0133] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the above method embodiments are generated. The above computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The above-mentioned computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the above-mentioned computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, Bluetooth, microwave, etc.) methods. The above-mentioned computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated. The above-mentioned available medium can be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)), etc.

[0134] Figure 3 This is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present invention. The electronic device may be a terminal device or a server for implementing the method of the aforementioned embodiment, or may be a terminal device or a server for implementing the method of the aforementioned embodiment connected to the aforementioned terminal device or server. Figure 3 As shown, the electronic device may include: a processor 301 (such as a CPU), a memory 302, and a transceiver 303; the transceiver 303 is coupled to the processor 301, and the processor 301 controls the transceiver 303. Various instructions may be stored in the memory 302 to complete various processing functions and implement the processing steps described in the aforementioned embodiment method. Preferably, the electronic device involved in the embodiment of the present invention also includes: a power supply 304, a system bus 305 and a communication port 306. The system bus 305 is used to realize the communication connection between components. The above-mentioned communication port 306 is used for connecting and communicating between the electronic device and other peripherals.

[0135] exist Figure 3The system bus 305 mentioned in the figure can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The system bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface is used to realize the communication between the database access device and other devices (such as clients, read-write libraries, and read-only libraries). The memory may include random access memory (RAM) and may also include non-volatile memory (Non-Volatile Memory), such as at least one disk storage.

[0136] The above-mentioned processors can be general-purpose processors, including central processing units (CPU), network processors (NP), graphics processing units (GPU), etc.; they can also be digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0137] It should be noted that an embodiment of the present invention further provides a computer-readable storage medium, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer executes the method and processing process provided in the above embodiments.

[0138] An embodiment of the present invention further provides a chip for executing instructions, wherein the chip is used to execute the processing steps described in the aforementioned method embodiment.

[0139] The embodiment of the present invention provides a method, device, electronic device and computer-readable storage medium for training a text embedding module of a large language model. As can be seen from the above content, the embodiment of the present invention records the large language model where the text embedding module to be trained is located as the corresponding first model, and designates another large language model as the corresponding second model; and constructs a training data set based on the preset data generation task configuration and the second model to obtain the corresponding first data set; and trains the text embedding module of the first model based on the first data set; and after the training, uses the specified text embedding verification platform to verify the text embedding performance of the text embedding module. Through the embodiment of the present invention, on the one hand, the text embedding module of the LLM model can be independently trained to achieve the purpose of regularly updating and strengthening the training of the text embedding module; on the other hand, other LLM models can be used to quickly construct training data sets, shortening the training preparation time, reducing the data collection cost, improving the module training efficiency, and reducing the module training cost.

[0140] The professionals should further realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to the function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0141] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0142] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for training a text embedding module of a large language model, characterized in that: The method comprises: The large language model where the text embedding module to be trained is located is recorded as the corresponding first model; another large language model is designated as the corresponding second model; and the preset data generation task configuration is designated as the corresponding first configuration; Constructing a training data set according to the first configuration and the second model to obtain a corresponding first data set; Training the text embedding module of the first model based on the first data set; Wherein, the second model includes at least a Wenxinyiyan series model and a GPT series model; The first configuration includes a knowledge domain set, a language type set, a total number of knowledge domains A, a total number of data records B, a total number of single-domain task pools C, a total number of single-record negative samples D, a minimum sample text length E, a maximum sample text length F, a retrieval task pool creation instruction template, and a retrieval task execution instruction template; The total number of knowledge domains A, the total number of data records B, the total number of single-domain task pools C, the total number of single-record negative samples D, the minimum sample text length E, and the maximum sample text length F are all positive integers; and the total number of data records B can be divided by the product of the total number of knowledge domains A and the total number of single-domain task pools C; the minimum sample text length E is less than the maximum sample text length F; The knowledge domain set includes a plurality of knowledge domain texts; the total number of knowledge domains A is the total number of the knowledge domain texts; The language type set includes multiple language types; the language types include at least Chinese, English, French, German, Russian, Japanese, Korean, and Spanish; The retrieval task pool creation instruction template is a text template for prompting the second model to construct a specified number Y of retrieval task pools within the specified knowledge domain X, and to assign a unique task pool number to each constructed retrieval task pool; the specified knowledge domain X and the specified number Y are two replaceable text variables; the specified knowledge domain X is replaced by one of the knowledge domain texts in the knowledge domain set; the specified number Y is replaced by the total number C of the single-domain task pool; The retrieval task execution instruction template is a text template for prompting the second model to create a data generation task in the specified retrieval task pool T and generate a question-answering retrieval information group consisting of a question text, a positive sample retrieval text and a specified number Z of negative sample retrieval texts according to a preset data generation rule; the specified retrieval task pool T and the specified number Z are two replaceable text variables; the specified retrieval task pool T is replaced by a task pool number; the specified number Z is replaced by the total number D of single-record negative samples; The data generation rule is used to limit the language type of the question-answer retrieval information group to a specified language L; and to limit the comparison relationship between the text string length of the question text and the positive sample retrieval text to satisfy any one of the three comparison relationships of less than, equal to or greater than; and to limit the comparison relationship between the text string length of the question text and any one of the negative sample retrieval texts to satisfy any one of the three comparison relationships of less than, equal to or greater than, and the Z comparison relationships corresponding to the Z negative sample retrieval texts must fully cover the three comparison relationships of less than, equal to and greater than, otherwise they will be regenerated; and to limit the length range of the text string length of the positive sample retrieval text and each of the negative sample retrieval texts to a minimum length s min and the maximum length s max The value range of the specified language L, the minimum length s min and the maximum length s max are three replaceable text variables; the specified language L is replaced by one of the language types in the language type set; the minimum length s min and the maximum length s max are replaced by the corresponding minimum sample text length E and the maximum sample text length F respectively; The first data set includes a plurality of first data records; the first data record includes a first question text, a first positive sample text and a first negative sample text set; the first negative sample text set is composed of the first negative sample text of the total number D of single-record negative samples; The step of constructing a training data set according to the first configuration and the second model to obtain a corresponding first data set specifically includes: Step 401: The quotient of the total number of data records B of the first configuration divided by the total number of knowledge domains A is taken as the corresponding total number of single-domain records; and the quotient of the total number of single-domain records divided by the total number of single-domain task pools C is taken as the corresponding total number of single-task pool records; Step 402, taking the first knowledge domain text in the knowledge domain set as the corresponding current knowledge domain; Step 403, replace the specified knowledge domain X in the retrieval task pool creation instruction template with the corresponding current knowledge domain, and replace the specified quantity Y with the corresponding total number C of the single-domain task pool; and use the replaced retrieval task pool creation instruction template as the corresponding current-domain task pool creation instruction text; Step 404, input the current domain task pool creation instruction text into the second model to retrieve the task pool creation, and receive the C task pool numbers fed back by the second model and the task pool description text corresponding to each task pool number; and the C task pool numbers obtained this time form the corresponding current domain task collection; Step 405, taking the first task pool number of the current domain task collection as the corresponding current task pool number; and initializing the first counter to 1; Step 406: replace the specified search task pool T in the search task execution instruction template with the current task pool number, replace the specified number Z with the corresponding total number of single-record negative samples D, and randomly select a language from the language set to replace the specified language L, and replace the minimum length s min and the maximum length s max Replace the minimum sample text length E and the maximum sample text length F with the corresponding ones; and use the search task execution instruction template that has completed the replacement as the corresponding current task execution instruction text; Step 407, inputting the current task execution instruction text into the second model to perform data generation task processing, and receiving one of the question-and-answer retrieval information groups fed back by the second model as the corresponding current retrieval information group; Step 408: the question text of the current search information group is used as a corresponding first question text; the positive sample search text of the current search information group is used as a corresponding first positive sample text; each negative sample search text of the current search information group is used as a corresponding first negative sample text, and the D first negative sample texts obtained this time form a corresponding first negative sample text set; and the first question text, the first positive sample text and the first negative sample text set obtained this time form a corresponding first data record; Step 409, whether the first counter is less than the total number of records in the single task pool is identified; if the first counter is less than the total number of records in the single task pool, then the first counter is increased by 1, and a language type is randomly selected from the language type set to replace the specified language L in the current task execution instruction text to obtain a new current task execution instruction text, and then the process returns to step 407; if the first counter is greater than or equal to the total number of records in the single task pool, then the first counter is reset to 1, and whether the current task pool number is the last task pool number in the current domain task collection is identified, if so, then the process goes to step 410, if not, the next task pool number in the current domain task collection is used as the new current task pool number and then the process returns to step 406; Step 410, identifying whether the current knowledge domain is the last knowledge domain text in the knowledge domain set; if so, going to step 411; if not, taking the next knowledge domain text in the knowledge domain set as the new current knowledge domain and returning to step 403; Step 411: The B first data records obtained this time are used to form the corresponding first data set.

2. The method for training a text embedding module of a large language model according to claim 1, characterized in that: The training of the text embedding module of the first model based on the first data set specifically includes: Step 51, taking the first of the first data records in the first data set as the corresponding current data record; Step 52: input the first question text of the current data record into the text embedding module for text embedding coding vector conversion to obtain the corresponding first vector q; input the first positive sample text of the current data record into the text embedding module for text embedding coding vector conversion to obtain the corresponding second vector d; and input each of the first negative sample texts of the current data record into the text embedding module for text embedding coding vector conversion to obtain the corresponding third vector n i , 1≤negative sample index i≤D; Step 53: The first vector q, the second vector d and all the third vectors n obtained this time are i Bring in the preset model loss function L M Calculate and obtain the corresponding first loss value; in, F() is the temperature scale cosine similarity function, cos() is the cosine similarity function, and τ is the preset temperature scale constant; Step 54, identifying whether the first loss value satisfies a preset first loss value range; if the first loss value does not satisfy the first loss value range, moving toward making the model loss function L M A round of modulation is performed on the model parameters of the text embedding module in the direction of reaching the minimum value, and the step 52 is returned at the end of this round of modulation; if the first loss value satisfies the first loss value range, it is identified whether the current data record is the last one of the first data record of the first data set, if not, the next one of the first data record of the first data set is used as the new current data record and the step 52 is returned, if so, the training is stopped and it is confirmed that the training of the text embedding module of the first model is completed.

3. The method for training a text embedding module of a large language model according to claim 1, characterized in that: The method further comprises: After the training of the text embedding module of the first model is completed, the text embedding performance of the text embedding module is verified using a specified text embedding verification platform; the specified text embedding verification platform includes a text embedding verification platform based on the BEIR benchmark and a text embedding verification platform based on the MTEB benchmark.

4. A device for executing the method for training a text embedding module of a large language model according to any one of claims 1 to 3, characterized in that: The device comprises: a data preparation module, a training data set construction module, a text embedding training module and a text embedding verification module; The data preparation module is used to record the large language model where the text embedding module to be trained is located as the corresponding first model; and designate another large language model as the corresponding second model; and use the preset data generation task configuration as the corresponding first configuration; The training data set construction module is used to construct a training data set according to the first configuration and the second model to obtain a corresponding first data set; The text embedding training module is used to train the text embedding module of the first model based on the first data set; The text embedding verification module is used to verify the text embedding performance of the text embedding module using a specified text embedding verification platform after the training of the text embedding module of the first model is completed; the specified text embedding verification platform includes a text embedding verification platform based on the BEIR benchmark and a text embedding verification platform based on the MTEB benchmark.

5. An electronic device, characterized in that: include: memory, processors, and transceivers; The processor is used to couple with the memory, read and execute instructions in the memory, so as to implement the method according to any one of claims 1 to 3; The transceiver is coupled to the processor, and the processor controls the transceiver to send and receive messages.

6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a computer, the computer is enabled to execute the method according to any one of claims 1 to 3.