Large language model training method, question and answer method, equipment, medium and product
By obtaining long text training data and increasing the rotation angle base of the rotation position encoding, the length of the input text sequence of the large language model is expanded, which solves the problem of incomplete answers of the large language model when comparing long text and multiple documents, and improves the accuracy of the answer. Completeness and accuracy.
Patent Information
- Application Number
- CN202411282695.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-13
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2044-09-13
AI Technical Summary
When existing large language models handle long texts and multi-document comparisons, the input text sequence length limit results in incomplete and inaccurate answers.
By obtaining long text training data and increasing the rotation angle base of the rotation position encoding of the pre-trained large language model, the length of the input text sequence of the large language model is expanded so that it can process longer sequences, thereby improving the completeness and accuracy of the answer. accuracy.
It achieves an improvement in the completeness and accuracy of the large language model's answers to long text and multi-document dependency questions, simplifies the system structure, and improves the accuracy of the answers.
Smart Images

Figure CN118798303A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a large language model training method, question-answering method, device, medium and product. Background Art
[0002] Retrieval-Augmented Generation (RAG) technology is a widely used application of large language models. It retrieves and recalls relevant information, assembles it according to preset instructions, and inputs it into the large language model for understanding, and finally answers the user's question. It is often used in various knowledge question-answering assistants. Compared with direct answers from large language models, RAG answers utilize searched knowledge, which can ensure the timeliness of knowledge and reduce the problem of inaccurate results caused by self-fabrication of large language models.
[0003] The RAG solution in the related art is to split the collected documents into multiple text chunks according to a specific block method, and store them in databases such as vector libraries and search engine libraries (for example, Elasticsearch libraries). After obtaining the questions raised by the user, the most relevant text chunks are retrieved through parallel queries of multiple libraries, and the sorting model is called to sort the multi-way recalled text chunks. The top-ranked text chunks are input into the large language model, and the answer to the question is obtained based on the reasoning of the large language model. However, since the length of the text sequence input into the large language model is limited, the reasoning effect of questions that require the summary of long documents or the comparison and summary of multiple documents to answer is not good. Summary of the invention
[0004] The embodiments of the present application provide a large language model training method, question-answering method, device, medium and product to expand the maximum text sequence length of the input large language model and improve the completeness and accuracy of the large language model's answers to questions with long text dependencies and multi-document comparison dependencies.
[0005] In a first aspect, an embodiment of the present application provides a method for training a large language model, comprising: obtaining long text training data, wherein the sequence length of the long text training data is greater than the maximum length of the input text sequence of the pre-trained large language model; increasing the rotation angle base of the rotation position encoding of the pre-trained large language model to obtain a modified pre-trained large language model; and using the long text training data to train the modified pre-trained large language model to obtain a trained large language model.
[0006] In a second aspect, an embodiment of the present application provides a question-answering method based on a large language model, including: obtaining question information and task instructions, and querying multiple text blocks related to the question information; splicing the question information, task instructions and multiple text blocks to obtain a spliced text; the sequence length of the spliced text is greater than the maximum length of the input text sequence of the pre-trained large language model; inputting the spliced text into the trained large language model to obtain reply information output by the trained large language model; wherein the trained large language model is trained using the training method in the embodiment of the present application.
[0007] In a third aspect, an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory, wherein the processor implements any of the above methods when executing the computer program.
[0008] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, any of the above methods is implemented.
[0009] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, it implements any of the above methods.
[0010] Compared with the prior art, this application has the following advantages: The present application provides a training method, a question-answering method, a device, a medium and a product for a large language model, wherein long text training data is obtained, and the sequence length of the long text training data is greater than the maximum length of the input text sequence of the pre-trained large language model; the rotation angle base of the rotation position coding of the pre-trained large language model is increased to obtain a modified pre-trained large language model; the modified pre-trained large language model is trained using the long text training data to obtain a trained large language model. In this embodiment, the pre-trained large language model is trained by obtaining long text training data and increasing the rotation angle base of the rotation position coding. Since the rotation position coding generates a position coding vector through mathematical transformation, increasing the rotation angle base of the rotation position coding can change the mathematical transformation method, thereby affecting the generation of the position coding vector, so that the trained large language model can still effectively capture the position information when processing a longer sequence, thereby allowing the large language model to process a longer input text sequence, realizing the length expansion of the input text sequence, and improving the completeness and accuracy of the large language model's answers to questions of long text dependency and multi-document comparison dependency.
[0011] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In the accompanying drawings, unless otherwise specified, the same reference numerals throughout the multiple drawings represent the same or similar parts or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings only depict some embodiments according to the present application and should not be regarded as limiting the scope of the present application.
[0013] Figure 1 A schematic diagram of splicing input text blocks of a large language model in the related art.
[0014] Figure 2 A schematic diagram of splicing input text blocks of a large language model according to an embodiment of the present application.
[0015] Figure 3 This is a flowchart of a method for training a large language model according to an embodiment of the present application.
[0016] Figure 4 This is a flowchart of a method for training a large language model according to an embodiment of the present application.
[0017] Figure 5 This is a flowchart of a question-answering method based on a large language model according to an embodiment of the present application.
[0018] Figure 6 This is a flowchart of a question-answering method based on a large language model according to an embodiment of the present application.
[0019] Figure 7 This is a structural block diagram of a large language model training device according to an embodiment of the present application.
[0020] Figure 8 This is a structural block diagram of a question-answering device based on a large language model according to an embodiment of the present application.
[0021] Fig. 9 A block diagram of an electronic device used to implement an embodiment of the present application. DETAILED DESCRIPTION
[0022] In the following, only some exemplary embodiments are briefly described. As those skilled in the art will appreciate, the described embodiments may be modified in various ways without departing from the concept or scope of the present application. Therefore, the drawings and descriptions are considered to be exemplary in nature and not restrictive.
[0023] To facilitate understanding of the technical solutions of the embodiments of the present application, the following describes the related technologies of the embodiments of the present application. The following related technologies can be combined with the technical solutions of the embodiments of the present application as optional solutions, and they all belong to the protection scope of the embodiments of the present application.
[0024] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0025] In the related art, RAG technology retrieves multiple text blocks related to the questions input by the user through the retrieval component. Since the input text (also called input context) sequence length of the open source large language model is limited, generally 8k-32k, where k=1024, that is, the length of the input text sequence is at most 32×1024 tokens. When the sequence length of multiple text blocks exceeds 32k, they cannot be input into the large language model. Therefore, the sorting model is used to sort the multiple text blocks, and the top-ranked text blocks are selected and spliced with the task instructions and question information and then input into the large language model for processing.
[0026] Figure 1 The figure is a schematic diagram of the splicing of the input text blocks of the large language model in the related technology. Among them, E-text block 1, E-text block 2...E-text block N represent N text blocks related to the question information input by the user obtained by querying in a text keyword recall mode. V-text block 1, V-text block 2...V-text block M represent M text blocks related to the question information input by the user obtained by querying in a vector recall mode. The text blocks are sorted by using a sorting model, and the top three text blocks, R-text block 1, R-text block 2 and R-text block 3, are selected. The selected text blocks are spliced with the task instructions and the question information input by the user, and are input into the large language model for processing to obtain the reply information. Among them, the task instruction (Instruction) refers to the guidance or command required for the large language model to perform a specific task, indicating the specific task that the user of the large language model wants to complete or the required output type. For example, if you are an xxx expert, please answer the user question xxx according to the xxx requirements based on the xxx you have queried.
[0027] Since the length of the text sequence input into the large language model is limited, the related technology can only select a few text blocks with the highest ranking. For questions that require summarization of long documents or comparative summary of multiple documents to answer, the reasoning results of the large language model are not complete and accurate.
[0028] In an embodiment of the present application, first, long text training data is obtained, and the sequence length of the long text training data is greater than the maximum length of the input text sequence of the pre-trained large language model. Specifically, a training corpus with a long context is collected, for example, data from a network data set or book document data, and then cleaned to a preset length, such as 128k (k=1024). Then, the rotation angle base of the rotation position encoding of the pre-trained large language model is increased to obtain a modified pre-trained large language model. Specifically, the rotation angle base of the rotation position encoding (i.e., the base value of the rotation position encoding) is modified. The rotation angle base generally defaults to 10000 (ten thousand) and can be modified to 1000000 (one million). Since the rotation position encoding generates a position encoding vector through mathematical transformation, increasing the rotation angle base of the rotation position encoding can change the method of mathematical transformation, thereby affecting the generation of the position encoding vector, so that the trained large language model can still effectively capture the position information when processing longer sequences, thereby allowing the large language model to process longer input text sequences. The modified pre-trained large language model is trained using the long text training data to obtain a trained large language model, that is, a universal large language model.
[0029] Then, the general large language model is fine-tuned, long text training data of the preset field is obtained, and the trained large language model is trained using the long text training data of the preset field to obtain the large language model corresponding to the preset field. Finally, position expansion is performed. Specifically, in the configuration file of the large language model corresponding to the preset domain (i.e., the first large language model), the maximum number of positions of the large language model is increased (the maximum number of positions indicates the maximum text sequence length that the large language model can handle), and the large language model after position expansion is obtained (i.e., the second large language model). For example, using the rotational position encoding expansion method YaRN (Yet another RoPE extension) method, the code of the model inference framework vllm, in the configuration file, if the maximum length of the large language model context (original_max_position_embeddings) is 32k, the position expansion is performed by length extrapolation, and the extrapolation factor is set to 8 times, that is, the maximum length of the modified large language model input text sequence is 32k*8=256k.
[0030] Since the large language model in the embodiment of the present application is trained using long text data, and the rotation angle base of the rotation position encoding is increased, and the input text sequence length of the large language model is expanded, there is no need for a sorting model, and the text blocks can be sorted according to the relevance score. Since the large language model is more sensitive to the text that is closer to the task instruction and the part close to the question information, and since the text blocks obtained according to the vector recall method are more accurate than the text obtained according to the text keyword recall method, the text blocks E-text block 1, E-text block 2...E-text block N obtained according to the text keyword recall method are sorted from high to low according to the relevance score with the question information, and the text blocks V-text block 1, V-text block 2...V-text block M obtained according to the vector recall method are sorted from low to high according to the relevance score with the question information. The text blocks E-text block 1, E-text block 2...E-text block N are spliced after the task instruction, and the text blocks V-text block 1, V-text block 2...V-text block M are spliced before the question information. Figure 2 This is a schematic diagram of the splicing of input text blocks of a large language model of an embodiment of the present application. In addition, in order to make it easier for the large language model to distinguish the content in different locations (task instructions, text blocks, question information), prefix tokens Pre-Tokens and suffix tokens Post-Tokens are inserted as the first placeholder and the second placeholder, respectively. Different large language models have different numbers of placeholders. For example, Pre-Tokens can be 400 and Post-Tokens can be 100. Finally, the spliced text is input into a large language model with a long context (for example, supporting a maximum of 256k) to obtain a reply message. In this example, the two recall methods can each take 30 text blocks, for a total of 60 text blocks, which greatly increases the number of input text blocks.
[0031] In this embodiment, long text data is used for training, the rotation angle base of the rotation position encoding is increased, and the position of the input text sequence length of the large language model is expanded, thereby increasing the input text sequence length of the large language model and improving the completeness and accuracy of the large language model's answers to questions that are dependent on long texts and multi-document comparisons. Furthermore, text splicing is performed using a multi-way recall positive and reverse sorting method, and the sorting model is removed, making the RAG system more concise, efficient, and more accurate. In addition, by inserting placeholders, it is easier for the large language model to distinguish content in different positions, thereby improving the accuracy of the large language model's answers.
[0032] An embodiment of the present application provides a training method for a large language model. The method in this embodiment can be applied to servers, terminal devices, platforms, devices, etc. with computing and processing capabilities, wherein the server can be a server cluster or a single server, a server deployed in the cloud, or a local server.
[0033] like Figure 3 The flowchart of the method for training a large language model according to an embodiment of the present application is shown, including: Step S301, obtaining long text training data, wherein the sequence length of the long text training data is greater than the maximum length of the input text sequence of the pre-trained large language model.
[0034] Among them, a large language model (LLM) refers to a deep learning model trained with a large amount of text data, which can generate natural language text or understand the meaning of language text. The specific structure of the large language model can be based on the structure of the transformer model.
[0035] At present, the sequence length of input text (the number of input word tokens) of open source pre-trained large language models is generally 8k-32k. Collect training corpus of long texts, such as data from network datasets or book document data, including data from multiple fields, and then clean it to a preset length, such as 128k (k=1024).
[0036] Step S302: Increase the rotation angle base of the rotation position encoding of the pre-trained large language model to obtain a modified pre-trained large language model.
[0037] Modify the rotation angle base of the pre-trained large language model's rotation position encoding, that is, the base value of the rotation position encoding, which is a hyperparameter of the large language model. The rotation position encoding generates the position encoding vector through mathematical transformation. Increasing the rotation angle base of the rotation position encoding can change the way of mathematical transformation, thereby affecting the generation of the position encoding vector, so that the trained large language model can still effectively capture the position information when processing longer sequences, thereby allowing the large language model to process longer input text sequences. For example, change the base value of the rotation position encoding from 10000 to 1000000.
[0038] Step S303: Use the long text training data to train the modified pre-trained large language model to obtain a trained large language model.
[0039] The modified pre-trained large language model is trained using the long text training data. Optionally, the training can be performed in an unsupervised manner until the training end conditions are met to obtain a trained large language model. At this time, the maximum length of the input text sequence of the obtained large language model is greater than the maximum length of the input text sequence of the open source pre-trained large language model.
[0040] The training method of the large language model provided in the embodiment of the present application obtains long text training data, and the sequence length of the long text training data is greater than the maximum length of the input text sequence of the pre-trained large language model; increases the rotation angle base of the rotation position coding of the pre-trained large language model to obtain a modified pre-trained large language model; uses the long text training data to train the modified pre-trained large language model to obtain a trained large language model. In this embodiment, the pre-trained large language model is trained by obtaining long text training data and increasing the rotation angle base of the rotation position coding. Since the rotation position coding generates the position coding vector through mathematical transformation, increasing the rotation angle base of the rotation position coding can change the mathematical transformation method, thereby affecting the generation of the position coding vector, so that the trained large language model can still effectively capture the position information when processing longer sequences, thereby allowing the large language model to process longer input text sequences, realizing the length expansion of the input text sequence, and improving the completeness and accuracy of the large language model's answers to questions of long text dependency and multi-document comparison dependency.
[0041] In one implementation, the large language model training method further includes: obtaining long text training data of a preset domain, training the trained large language model using the long text training data of the preset domain, and obtaining a first large language model corresponding to the preset domain.
[0042] In practical applications, the large language model trained using data from multiple fields is a universal large language model. The universal large language model learns the general rules and extensive knowledge of language. In order to improve the accuracy of the large language model in processing information in the preset field, the long text data in the preset field is used to fine-tune the large language model.
[0043] Among them, the preset field can be determined according to the specific field of application of the large language model.
[0044] In this embodiment, the large language model is fine-tuned using the long text training data in the preset field, which can improve the completeness and accuracy of the large language model in processing the long text data in the preset field.
[0045] In one implementation, the training method of the large language model also includes: in a configuration file of the first large language model corresponding to a preset domain, increasing the maximum number of positions of the first large language model to obtain a second large language model, wherein the maximum length of the input text sequence of the second large language model is greater than the maximum length of the input text sequence of the first large language model.
[0046] In practical applications, before using the language model for reasoning, the sequence length of the input data of the large language model can be further expanded. Specifically, in the configuration file of the large language model corresponding to the preset domain, the maximum number of positions of the large language model is increased (the maximum number of positions indicates the maximum text sequence length that the large language model can process), that is, the value of the parameter original_max_position_embeddings, and the value of the parameter is increased to a preset multiple, for example, from 32k to 32k*8=256k.
[0047] In this embodiment, by positionally expanding the length of the input text sequence of the large language model in the configuration file, the maximum length of the input text sequence of the large language model is further increased, thereby improving the completeness and accuracy of the large language model's answers to questions related to long text dependency and multi-document comparison dependency.
[0048] An embodiment of the present application provides a training method for a large language model. The method in this embodiment can be applied to servers, terminal devices, platforms, devices, etc. with computing and processing capabilities, wherein the server can be a server cluster or a single server, a server deployed in the cloud, or a local server.
[0049] like Figure 4 The flowchart of the method for training a large language model according to an embodiment of the present application is shown, including: Step S401, obtaining long text training data, wherein the sequence length of the long text training data is greater than the maximum length of the input text sequence of the pre-trained large language model.
[0050] At present, the sequence length of input text (the number of input word tokens) of open source pre-trained large language models is generally 8k-32k. Collect training corpus of long texts, such as data from network datasets or book document data, including data from multiple fields, and then clean it to a preset length, such as 128k (k=1024).
[0051] Step S402: increasing the rotation angle base of the rotation position encoding of the pre-trained large language model to obtain a modified pre-trained large language model.
[0052] Modify the rotation angle base of the rotation position encoding of the pre-trained large language model, that is, the base value of the rotation position encoding. It is a hyperparameter of the large language model. Increasing the base value of the rotation position encoding can increase the input text sequence length of the large language model.
[0053] Step S403: Use the long text training data to train the modified pre-trained large language model to obtain a trained large language model.
[0054] The modified pre-trained large language model is trained using the long text training data. Optionally, the training can be performed in an unsupervised manner until the training end condition is met, thereby obtaining a trained large language model.
[0055] Step S404, obtaining long text training data of a preset domain, and using the long text training data of the preset domain to train the trained large language model, to obtain a first large language model corresponding to the preset domain.
[0056] The large language model trained using data from multiple fields is a universal large language model. The universal large language model learns the universal rules and extensive knowledge of language. In order to improve the accuracy of the large language model in processing information in the preset field, the long text data in the preset field is used to fine-tune the large language model.
[0057] Step S405: In the configuration file of the first largest language model corresponding to the preset domain, the maximum number of positions of the first largest language model is increased to obtain a second largest language model.
[0058] The maximum length of the input text sequence of the second largest language model is greater than the maximum length of the input text sequence of the first largest language model.
[0059] In this embodiment, by obtaining long text training data and increasing the rotation angle base of the rotation position encoding, the pre-trained large language model is trained to achieve the length expansion of the input text sequence, so that the trained large language model can process long text sequences and improve the completeness and accuracy of the large language model's answers to questions related to long text dependency and multi-document comparison dependency. In addition, by fine-tuning the large language model using long text training data in a preset field, the completeness and accuracy of the large language model in processing long text data in a preset field can be improved.
[0060] An embodiment of the present application provides a question-answering method based on a large language model. The method in this embodiment can be applied to servers, terminal devices, platforms, apparatuses, etc. with computing and processing capabilities, wherein the server can be a server cluster or a single server, a server deployed in the cloud or a local server.
[0061] like Figure 5 The flowchart of the question-answering method based on a large language model according to an embodiment of the present application is shown, including: Step S501, obtaining problem information and task instructions, and searching for multiple text blocks related to the problem information.
[0062] The question information may be a question input by a user or may be question information called from a preset storage area. The large language model needs to perform reasoning on the question information to obtain response information corresponding to the question information.
[0063] Task instructions are instructions or commands required to perform specific tasks for the large language model, indicating the specific tasks that the large language model user wants to complete or the type of output required. For example, if you are an expert in xxx, please answer the user's question xxx according to the xxx requirements based on the xxx you have queried.
[0064] Multiple text blocks related to the question information can be queried in different databases through various recall methods. Each text block corresponds to a relevance score, which represents the degree of relevance to the question information. The higher the score, the higher the relevance.
[0065] Among them, the relevance calculation can use the term frequency-inverse document frequency (TF-IDF) method, text matching algorithm bm25, etc., to segment the text and then calculate the relevance score.
[0066] Step S502, concatenating the question information, the task instruction and the multiple text blocks to obtain a concatenated text.
[0067] Among them, the length of the concatenated text is greater than the maximum length of the input text sequence of the open source pre-trained large language model.
[0068] Step S503: input the concatenated text into the trained large language model to obtain reply information output by the trained large language model.
[0069] The trained large language model is obtained by training using the training method in the above embodiment. Since the large language model in this embodiment is obtained by obtaining long text training data, increasing the rotation angle base of the rotation position encoding, and expanding the position of the input text sequence length of the large language model, the trained large language model can process long text data.
[0070] The question-answering method based on the large language model provided in the embodiment of the present application obtains question information and task instructions, queries multiple text blocks related to the question information; splices the question information, task instructions and multiple text blocks to obtain spliced text; inputs the spliced text into the trained large language model to obtain the reply information output by the trained large language model; wherein the trained large language model is trained using the training method in the embodiment of the present application. In this embodiment, the trained large language model is obtained by obtaining long text training data and increasing the rotation angle base of the rotation position encoding for training, which can achieve the length expansion of the input text sequence and improve the completeness and accuracy of the large language model's answers to questions of long text dependency and multi-document comparison dependency.
[0071] In one implementation, question information, task instructions, and multiple text blocks are spliced to obtain spliced text, including: sorting the multiple text blocks according to the relevance scores with the question information, and adding the sorted multiple text blocks between the task instructions and the question information to obtain the spliced text.
[0072] Among them, each text block corresponds to a relevance score, which represents the degree of relevance to the question information. The text blocks are sorted in descending order according to the relevance scores, and the sorted text blocks are spliced with the task instructions and question information. The splicing is carried out in the order of task execution, sorted text blocks, and question information to obtain the spliced text, which is input into the large language model to obtain the reply information.
[0073] In this embodiment, when constructing the concatenated text, multiple text blocks are sorted, which can improve the accuracy of the output results of the large language model. Moreover, compared with the related art, the sorting is performed according to the relevance score, which does not require a sorting model and can simplify the system structure.
[0074] In one implementation, multiple text blocks are sorted according to their relevance scores to the question information, and the sorted multiple text blocks are added between the task instruction and the question information to obtain a spliced text, including: the multiple text blocks include multiple first text blocks obtained by querying according to a text keyword recall method and multiple second text blocks obtained by querying according to a vector recall method, the multiple first text blocks are sorted from high to low according to their relevance scores to the question information, and the multiple second text blocks are sorted from low to high according to their relevance scores to the question information; the sorted multiple first text blocks and the sorted multiple second text blocks are added between the task instruction and the question information to obtain a spliced text.
[0075] Multiple text blocks are obtained by querying in a vector recall mode (querying in a vector library), and multiple text blocks are obtained by querying in a text keyword recall mode (querying using a search engine library, such as an Elasticsearch library).
[0076] Since the large language model is more sensitive to text that is closer to the task instructions and the question information, and since the text blocks obtained by the vector recall method are more accurate than the text obtained by the text keyword recall method, the text blocks obtained by the text keyword recall method are sorted from high to low according to the relevance score with the question information, and the text blocks obtained by the vector recall method are sorted from low to high according to the relevance score with the question information. Then, the text blocks obtained by the text keyword recall method are spliced after the task instructions, and the text blocks obtained by the vector recall method are spliced before the question information to obtain the spliced text. After the spliced text obtained in this way is input into the large language model, the accuracy of the output result can be improved.
[0077] In one implementation, after concatenating question information, task instructions, and multiple text blocks to obtain a concatenated text, the question-answering method based on a large language model further includes: adding a first placeholder after the task instruction in the concatenated text, and adding a second placeholder before the question information in the concatenated text to obtain a processed concatenated text, wherein the first placeholder is used to indicate a position corresponding to the task instruction, and the second placeholder is used to indicate a position corresponding to the question information.
[0078] In order to make it easier for the large language model to distinguish the content in different positions (task instructions, text blocks, question information), the first placeholder Pre-Tokens and the second placeholder Post-Tokens are inserted respectively. The number of placeholders varies for different large language models, for example, Pre-Tokens can be 400 and Post-Tokens can be 100. Finally, the concatenated text is input to the large language model with a long context (for example, supporting a maximum of 256k) to obtain the reply information.
[0079] In this embodiment, by inserting placeholders, the large language model can more easily distinguish the content in different positions, thereby improving the accuracy of the large language model's answers.
[0080] An embodiment of the present application provides a question-answering method based on a large language model. The method in this embodiment can be applied to servers, terminal devices, platforms, apparatuses, etc. with computing and processing capabilities, wherein the server can be a server cluster or a single server, a server deployed in the cloud or a local server.
[0081] like Figure 6 The flowchart of the question-answering method based on a large language model according to an embodiment of the present application is shown, including: Step S601, obtaining problem information and task instructions.
[0082] Step S602: query multiple first text blocks related to the question information in a text keyword recall manner.
[0083] Step S603: query multiple second text blocks related to the question information in a vector recall manner.
[0084] Step S604: sort the plurality of first text blocks from high to low according to the relevance scores to the question information, and sort the plurality of second text blocks from low to high according to the relevance scores to the question information.
[0085] Step S605: Add the sorted multiple first text blocks and the sorted multiple second text blocks between the task instruction and the question information to obtain a concatenated text.
[0086] Among them, the sequence length of the concatenated text is greater than the maximum length of the input text sequence of the pre-trained large language model.
[0087] Step S606, adding a first placeholder after the task instruction in the spliced text, and adding a second placeholder before the question information in the spliced text, to obtain a processed spliced text.
[0088] The first placeholder is used to indicate the position corresponding to the task instruction, and the second placeholder is used to indicate the position corresponding to the question information.
[0089] Step S607: input the processed concatenated text into the trained large language model to obtain the reply information output by the trained large language model.
[0090] The trained large language model is obtained by training using the training method in the above embodiment.
[0091] In this embodiment, the trained large language model is obtained by acquiring long text training data, increasing the rotation angle base of the rotation position encoding for training, and the input text sequence length of the trained large language model is positionally expanded, which can achieve the length expansion of the input text sequence and improve the completeness and accuracy of the large language model's answers to questions of long text dependency and multi-document comparison dependency.
[0092] Corresponding to the application scenario and method of the method provided in the embodiment of the present application, the embodiment of the present application also provides a training device for a large language model. Figure 7 The structure block diagram of a large language model training device according to an embodiment of the present application is shown, and the device includes: The data acquisition module 701 is used to acquire long text training data, where the sequence length of the long text training data is greater than the maximum length of the input text sequence of the pre-trained large language model.
[0093] The parameter modification module 702 is used to increase the rotation angle base of the rotation position encoding of the pre-trained large language model to obtain a modified pre-trained large language model.
[0094] The model training module 703 is used to train the modified pre-trained large language model using the long text training data to obtain a trained large language model.
[0095] The training device of the large language model provided in the embodiment of the present application obtains long text training data, and the sequence length of the long text training data is greater than the maximum length of the input text sequence of the pre-trained large language model; increases the rotation angle base of the rotation position coding of the pre-trained large language model to obtain a modified pre-trained large language model; uses the long text training data to train the modified pre-trained large language model to obtain a trained large language model. In this embodiment, the pre-trained large language model is trained by obtaining long text training data and increasing the rotation angle base of the rotation position coding. Since the rotation position coding generates the position coding vector through mathematical transformation, increasing the rotation angle base of the rotation position coding can change the mathematical transformation method, thereby affecting the generation of the position coding vector, so that the trained large language model can still effectively capture the position information when processing longer sequences, thereby allowing the large language model to process longer input text sequences, realizing the length expansion of the input text sequence, and improving the completeness and accuracy of the large language model's answers to questions of long text dependency and multi-document comparison dependency.
[0096] In one implementation, the large language model training device is also used to: obtain long text training data of a preset field, use the long text training data of the preset field to train the trained large language model, and obtain a first large language model corresponding to the preset field.
[0097] In one implementation, the training device for the large language model is also used to: in a configuration file of the first large language model corresponding to a preset domain, increase the maximum number of positions of the first large language model to obtain a second large language model, wherein the maximum length of the input text sequence of the second large language model is greater than the maximum length of the input text sequence of the first large language model.
[0098] The functions of each module in the embodiment of the present application can be referred to the corresponding description in the above method, and have corresponding beneficial effects, which will not be repeated here.
[0099] Corresponding to the application scenario and method of the method provided in the embodiment of the present application, the embodiment of the present application also provides a question-answering device based on a large language model. Figure 8 The structure block diagram of a question-answering device based on a large language model according to an embodiment of the present application is shown, and the device includes: The information acquisition module 801 is used to acquire problem information and task instructions, and query multiple text blocks related to the problem information.
[0100] The text concatenation module 802 is used to concatenate question information, task instructions and multiple text blocks to obtain a concatenated text; the sequence length of the concatenated text is greater than the maximum length of the input text sequence of the pre-trained large language model.
[0101] The information processing module 803 is used to input the concatenated text into the trained large language model to obtain the reply information output by the trained large language model; wherein the trained large language model is trained using the training method in the embodiment of the present application.
[0102] The question-answering device based on the large language model provided in the embodiment of the present application obtains question information and task instructions, queries multiple text blocks related to the question information; splices the question information, task instructions and multiple text blocks to obtain a spliced text; the sequence length of the spliced text is greater than the maximum length of the input text sequence of the pre-trained large language model; the spliced text is input into the trained large language model to obtain the reply information output by the trained large language model; wherein the trained large language model is trained using the training method in the embodiment of the present application. In this embodiment, the trained large language model is obtained by obtaining long text training data and increasing the rotation angle base of the rotation position encoding for training, which can achieve the length expansion of the input text sequence and improve the completeness and accuracy of the large language model's answers to questions of long text dependency and multi-document comparison dependency.
[0103] In one implementation, the text concatenation module 802 is used to sort the multiple text blocks according to the relevance scores with the question information, and add the sorted multiple text blocks between the task instruction and the question information to obtain the concatenated text.
[0104] In one implementation, the text splicing module 802 is specifically used to: sort the multiple text blocks including multiple first text blocks obtained by querying according to a text keyword recall method and multiple second text blocks obtained by querying according to a vector recall method, sort the multiple first text blocks from high to low according to the relevance scores with the question information, and sort the multiple second text blocks from low to high according to the relevance scores with the question information; add the sorted multiple first text blocks and the sorted multiple second text blocks between the task instruction and the question information to obtain a spliced text.
[0105] In one implementation, the question-answering device based on a large language model is also used to: after splicing question information, task instructions and multiple text blocks to obtain a spliced text, add a first placeholder after the task instruction in the spliced text, and add a second placeholder before the question information in the spliced text to obtain a processed spliced text, wherein the first placeholder is used to indicate the position corresponding to the task instruction, and the second placeholder is used to indicate the position corresponding to the question information.
[0106] The functions of each module in the embodiment of the present application can be referred to the corresponding description in the above method, and have corresponding beneficial effects, which will not be repeated here.
[0107] Fig. 9 FIG. 1 is a block diagram of an electronic device used to implement an embodiment of the present application. Fig. 9 As shown, the electronic device includes: a memory 910 and a processor 920. The memory 910 stores a computer program that can be run on the processor 920. When the processor 920 executes the computer program, the method in the above embodiment is implemented. The number of the memory 910 and the processor 920 can be one or more.
[0108] The electronic device also includes: The communication interface 930 is used to communicate with external devices and perform data exchange transmission.
[0109] If the memory 910, the processor 920 and the communication interface 930 are implemented independently, the memory 910, the processor 920 and the communication interface 930 can be connected to each other through a bus and communicate with each other. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig. 9 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0110] Optionally, in a specific implementation, if the memory 910, the processor 920 and the communication interface 930 are integrated on a chip, the memory 910, the processor 920 and the communication interface 930 can communicate with each other through an internal interface.
[0111] An embodiment of the present application provides a computer-readable storage medium storing a computer program, which implements the method provided in the embodiment of the present application when the program is executed by a processor.
[0112] An embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the method provided in the embodiment of the present application is implemented.
[0113] An embodiment of the present application also provides a chip, which includes a processor for calling and executing instructions stored in the memory from the memory, so that a communication device equipped with the chip executes the method provided by the embodiment of the present application.
[0114] An embodiment of the present application also provides a chip, including: an input interface, an output interface, a processor and a memory, wherein the input interface, the output interface, the processor and the memory are connected via an internal connection path, and the processor is used to execute the code in the memory. When the code is executed, the processor is used to execute the method provided in the embodiment of the application.
[0115] It should be understood that the above processor may be a central processing unit (CPU), or other general-purpose processors, 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, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. It is worth noting that the processor may be a processor that supports the Advanced RISC Machines (ARM) architecture.
[0116] Further, optionally, the above-mentioned memory may include a read-only memory and a random access memory. The memory may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memory. Among them, the non-volatile memory may include a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may include a random access memory (RAM), which is used as an external cache. By way of exemplary but not limiting description, many forms of RAM are available. For example, static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM) and direct memory bus random access memory (DR RAM).
[0117] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part 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, the process or function according to the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The 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.
[0118] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine different embodiments or examples described in this specification and the features of different embodiments or examples, unless they are contradictory.
[0119] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0120] Any process or method described in the flow chart or otherwise described herein can be understood as a module, fragment or portion of a code representing one or more executable instructions for implementing the steps of a specific logical function or process. And the scope of the preferred embodiment of the present application includes other implementations, in which the functions may not be performed in the order shown or discussed, including in a substantially simultaneous manner or in a reverse order according to the functions involved.
[0121] The logic and / or steps described in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, which can be embodied in any computer-readable medium for use by an instruction execution system, apparatus or device (such as a computer-based system, a system including a processor or other system that can fetch instructions from an instruction execution system, apparatus or device and execute instructions), or used in combination with these instruction execution systems, apparatuses or devices.
[0122] It should be understood that the various parts of the present application can be implemented with hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented with software or firmware stored in a memory and executed by a suitable instruction execution system. All or part of the steps of the above embodiment method can be completed by instructing the relevant hardware through a program, which can be stored in a computer-readable storage medium, and when the program is executed, it includes one of the steps of the method embodiment or a combination thereof.
[0123] In addition, each functional unit in each embodiment of the present application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into one module. The above-mentioned integrated module can be implemented in the form of hardware or in the form of a software functional module. If the above-mentioned integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. The storage medium can be a read-only memory, a disk or an optical disk, etc.
[0124] The above is only an exemplary embodiment of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various changes or substitutions within the technical scope recorded in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A method for training a large language model, characterized in that: include: Acquire long text training data, where the sequence length of the long text training data is greater than the maximum length of an input text sequence of a pre-trained large language model; Increasing the rotation angle base of the rotation position encoding of the pre-trained large language model to obtain a modified pre-trained large language model; The modified pre-trained large language model is trained using the long text training data to obtain a trained large language model.
2. The method according to claim 1, characterized in that The method further comprises: The long text training data of the preset field is obtained, and the trained large language model is trained using the long text training data of the preset field to obtain a first large language model corresponding to the preset field.
3. The method according to claim 2, characterized in that The method further comprises: In a configuration file of a first language model corresponding to the preset domain, a maximum number of positions of the first language model is increased to obtain a second language model, wherein a maximum length of an input text sequence of the second language model is greater than the maximum length of an input text sequence of the first language model.
4. A question-answering method based on a large language model, characterized in that: include: Obtaining problem information and task instructions, and searching for multiple text blocks related to the problem information; splicing the question information, the task instruction, and the multiple text blocks to obtain a spliced text; wherein the sequence length of the spliced text is greater than the maximum length of the input text sequence of the pre-trained large language model; Inputting the concatenated text into the trained large language model to obtain reply information output by the trained large language model; The trained large language model is obtained by training using the training method according to any one of claims 1 to 3.
5. The method according to claim 4, characterized in that The step of splicing the question information, the task instruction, and the multiple text blocks to obtain a spliced text includes: The multiple text blocks are sorted according to the relevance scores with the question information, and the sorted multiple text blocks are added between the task instruction and the question information to obtain a spliced text.
6. The method according to claim 5, characterized in that The step of sorting the plurality of text blocks according to the relevance scores with the question information and adding the sorted plurality of text blocks between the task instruction and the question information to obtain a concatenated text includes: The plurality of text blocks include a plurality of first text blocks obtained by querying using a text keyword recall method and a plurality of second text blocks obtained by querying using a vector recall method, and the plurality of first text blocks are sorted from high to low according to their relevance scores to the question information, and the plurality of second text blocks are sorted from low to high according to their relevance scores to the question information; The sorted multiple first text blocks and the sorted multiple second text blocks are added between the task instruction and the question information to obtain a spliced text.
7. The method according to any one of claims 4 to 6, characterized in that After splicing the question information, the task instruction, and the multiple text blocks to obtain a spliced text, the method further includes: A first placeholder is added after the task instruction in the spliced text, and a second placeholder is added before the question information in the spliced text to obtain a processed spliced text, wherein the first placeholder is used to indicate the position corresponding to the task instruction, and the second placeholder is used to indicate the position corresponding to the question information.
8. An electronic device, characterized in that: The electronic device includes a memory, a processor, and a computer program stored in the memory, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Problem generation model training method, problem generation method and related equipment thereof
CN111639163A
Retrieval question and answer method, system and equipment and medium
CN117708309A
Structured query language generation method and device, electronic equipment and storage medium
CN118093621A
Information retrieval method and device, electronic equipment and storage medium
CN118394916A
Cited By
Text recognition method and device for large language model and electronic equipment
CN119830900A
Long text generalization method and device based on Fourier position coding
CN121212126A
Large language model training method, question answering method, device, medium, and product
WO2026056531A1
