Method, device, system and medium for constructing question-answer database using large language model
By using a large language model to convert unstructured documents into question-and-answer pairs, the problem of time-consuming and labor-consuming manual labeling of answers in the prior art is solved, and an efficient and fast question-and-answer library construction is achieved, reducing labor costs.
Patent Information
- Application Number
- CN202311078225.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-25
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2043-08-25
AI Technical Summary
The prior art requires manual labeling of answers when building a question-and-answer library, which is time-consuming and labor-intensive, affects processing efficiency, and has limitations.
The method of building a question-and-answer library using a large language model is used to obtain unstructured documents, convert them into titles and paragraph groups, and use prompt templates to guide the large language model to generate a question-and-answer pair to form a question-and-answer library.
It realizes efficient generation of Q&A libraries, improves processing efficiency, reduces labor costs, and does not require manual participation.
Smart Images

Figure CN117216205B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure generally relates to the field of natural language processing technology, and specifically relates to a method, device, system and medium for using a large language model to construct a question and answer database. Background Art
[0002] In daily life, the content of unstructured documents such as manuals and instructions is detailed and complicated, which brings great inconvenience to users in reading and locating, which leads to very low utilization rate of such documents and makes them useless. If unstructured documents can be provided to users in a question-and-answer format through reading comprehension technology, it will surely greatly improve the utilization rate of documents and the convenience of query.
[0003] At present, the patent with application number 201811398400.7 discloses a method and system for question and answer in instruction manuals, but the solution requires manual annotation of answers, which is time-consuming and labor-intensive, seriously affects processing efficiency, and has limitations. Summary of the invention
[0004] In view of the above-mentioned defects or deficiencies in the related art, it is desired to provide a method, device, system and medium for using a large language model to construct a question and answer library, which can efficiently generate a question and answer library, is convenient and fast, improves processing efficiency, and reduces labor costs.
[0005] In a first aspect, the present disclosure provides a method for using a large language model to construct a question-answer database, the method comprising:
[0006] Access unstructured documents;
[0007] According to a predefined question-answer data format, the unstructured document is converted into a title and paragraph group; the question-answer data format includes a title, a paragraph and a question-answer pair triple, the title refers to the title or title path of an independent subject module in the unstructured document, the paragraph refers to all texts under the title of each independent subject module, and the question-answer pair refers to a set of all valuable questions and answers within the paragraph;
[0008] According to the prompt template, the title and paragraph groups are input into the large language model in sequence to obtain question-answer pairs corresponding to each title and paragraph group, and a question-answer library is formed, wherein the prompt template is used to guide the large language model to generate a target text based on the context.
[0009] Optionally, in some embodiments of the present disclosure, the type of the prompt template includes at least one of a quantification type, a generalization type and a specified type.
[0010] Optionally, in some embodiments of the present disclosure, converting the unstructured document into a title and paragraph group includes:
[0011] Detecting the directory structure of the unstructured document;
[0012] If the unstructured document has a directory structure, the title and paragraph group corresponding to the unstructured document are respectively obtained according to the directory structure.
[0013] Optionally, in some embodiments of the present disclosure, the method further includes:
[0014] If the unstructured document does not have a directory structure, a title and a paragraph group corresponding to the unstructured document are obtained based on a separator of the unstructured document.
[0015] Optionally, in some embodiments of the present disclosure, the separator includes at least one of a paragraph, a punctuation mark, and a chapter.
[0016] In a second aspect, the present disclosure provides a device for using a large language model to construct a question-answer library, the device comprising:
[0017] An acquisition unit, used for acquiring unstructured documents;
[0018] A conversion unit, configured to convert the unstructured document into a title and paragraph group according to a predefined question-answer data format; the question-answer data format includes a title, a paragraph, and a question-answer pair triple, wherein the title refers to a title or a title path of an independent subject module in the unstructured document, the paragraph refers to all texts under the title of each independent subject module, and the question-answer pair refers to a set of all valuable questions and answers within the paragraph;
[0019] A construction unit is used to input the title and paragraph groups into the large language model in sequence according to the prompt template, obtain question-answer pairs corresponding to each title and paragraph group, and form a question-answer library, wherein the prompt template is used to guide the large language model to generate a target text based on the context.
[0020] Optionally, in some embodiments of the present disclosure, the type of the prompt template includes at least one of a quantification type, a generalization type and a specified type.
[0021] Optionally, in some embodiments of the present disclosure, the conversion unit is further used to detect the directory structure of the unstructured document;
[0022] If the unstructured document has a directory structure, the title and paragraph group corresponding to the unstructured document are respectively obtained according to the directory structure.
[0023] In a third aspect, the present disclosure provides a question-answering system, wherein a question-answering library of the question-answering system is obtained by the method for constructing a question-answering library described in any one of the first aspects.
[0024] In a fourth aspect, the present disclosure provides a computer-readable storage medium storing one or more programs, wherein the one or more programs can be executed by one or more processors to implement the steps of the method for constructing a question and answer database as described in any one of the first aspects.
[0025] It can be seen from the above technical solutions that the embodiments of the present disclosure have the following advantages:
[0026] The disclosed embodiments provide a method, device, system and medium for using a large language model to construct a question-and-answer database. The method converts an unstructured document into a title and paragraph group according to a predefined question-and-answer data format, and then uses a prompt template to guide the large language model to generate a target text based on the context. That is, the title and paragraph group are input into the large language model in sequence, and the question-and-answer pairs corresponding to each title and paragraph group are obtained. In this way, a question-and-answer database can be efficiently formed, which is convenient and fast, improves processing efficiency, and does not require human intervention, greatly reducing labor costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Other features, objects and advantages of the present disclosure will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0028] Figure 1 A flowchart of a method for using a large language model to construct a question-answer database provided in an embodiment of the present disclosure;
[0029] Figure 2 An example of a method for using a large language model to construct a question-answer database provided by an embodiment of the present disclosure;
[0030] Figure 3 A structural block diagram of an apparatus for constructing a question-answer database using a large language model provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0031] In order to enable those skilled in the art to better understand the disclosed solution, the technical solution in the disclosed embodiment will be clearly and completely described below in conjunction with the drawings in the disclosed embodiment. Obviously, the described embodiment is only a part of the disclosed embodiment, not all of the embodiments. Based on the embodiments in the disclosed embodiment, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the disclosed embodiment.
[0032] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described can be implemented in sequences other than those illustrated or described herein.
[0033] In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus that includes a series of steps or modules is not necessarily limited to those steps or modules explicitly listed, but may include other steps or modules not explicitly listed or inherent to these processes, methods, products, or apparatuses.
[0034] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present disclosure can be combined with each other. Figures 1 to 3 The method, device, system and medium for using the large language model provided by the embodiments of the present disclosure to construct a question and answer database are described in detail.
[0035] Please refer to Figure 1 , which is a flow chart of a method for using a large language model to construct a question-answer database provided by an embodiment of the present disclosure. The method specifically includes the following steps:
[0036] S101, obtaining an unstructured document.
[0037] Illustratively, in the embodiments of the present disclosure, unstructured documents may include but are not limited to instructions and manuals, etc. For example, the instructions are used to introduce the functions of the product, etc., while the manuals are used to guide users on how to better use the product, etc.
[0038] S102: Convert the unstructured document into a title and paragraph group according to a predefined question-answer data format.
[0039] For example, in the embodiment of the present disclosure, the question and answer data format may include but is not limited to a title, a paragraph, and a question and answer triple.<Title,Paragraph,QAs> Among them, Title refers to the title or title path of an independent subject module in an unstructured document; Paragraph refers to all the text under the title of each independent subject module, such as all subtitles, text content, icon index and image index belonging to Title; and QAs refer to all valuable questions and answers within the paragraph range, which can be obtained by<Question,Answer> It is composed of a set, where Question refers to the valuable questions within the paragraph, and Answer is the answer to the Question.
[0040] Optionally, Figure 2 As shown in the figure, in the process of converting an unstructured document into a title and paragraph group, the embodiment of the present disclosure first detects the directory structure of the unstructured document. If the unstructured document has a directory structure, the title and paragraph group corresponding to the unstructured document are obtained according to the directory structure.<Title,Paragraph> If the unstructured document does not have a directory structure, then the title and paragraph group corresponding to the unstructured document are obtained based on the delimiter of the unstructured document.<Title,Paragraph> For example, the separator may include but is not limited to at least one of paragraphs, punctuation and chapters, and the Title may be an empty value.
[0041] S103, according to the prompt template, input the title and paragraph group into the large language model in sequence, obtain the question and answer pairs corresponding to each title and paragraph group, and form a question and answer library, wherein the prompt template is used to guide the large language model to generate the target text based on the context.
[0042] It should be noted that in the embodiments of the present disclosure, large language models (LLM) refer to language models that are trained on large-scale text corpora and contain tens of billions (or more) of parameters. For example, large language models may include but are not limited to GPT-3, PaLM, and LLaMA.
[0043] For example, Figure 2 As shown in the figure, the type of the prompt template in the embodiment of the present disclosure may include but is not limited to at least one of a quantitative type, a generalized type and a specified type. For example, when the type of the prompt template is a quantitative type, that is,
[0044] Prompt template (the corresponding text starts with $): You are a question-answer pair extraction robot. Please extract possible question-answer pairs from the following text: the title is $Title, and the content is $Paragraph.
[0045] <Title,Paragraph> Right: <##Car Introduction, ##&&&The car is 4.88 meters long, 2 meters wide, and 2 meters high. It uses 92-grade gasoline or above. The hybrid version can be charged by itself. The fuel consumption is 5L / 100 kilometers. The price is 200,000 yuan. >
[0046] Furthermore, the large language model input is: You are a question-answer pair extraction robot, please extract possible question-answer pairs from the following text: the title is $Title, and the content is $Paragraph.
[0047] Large language model output:
[0048] Based on the given text, I can extract the following possible question-answer pairs:
[0049] 1. Question: What are the size parameters of a ##&&& car?
[0050] Answer: ##&&&The car is 4.88 meters long, 2 meters wide and 2 meters high.
[0051] 2. Question: What kind of fuel does the ##&&& car use?
[0052] Answer: ##&&&The car uses 92 or above gasoline.
[0053] 3. Question: Does the hybrid version of ##&&&car support self-charging?
[0054] Answer: Yes, the hybrid version of the ##&&& car can charge itself.
[0055] 4. Question: What is the fuel consumption of ##&&&'s car?
[0056] Answer: ##&&&The fuel consumption of the car is 5L / 100km.
[0057] 5. Question: ##&&&How much does the car cost?
[0058] Answer: ##&&&The car is sold for 200,000 yuan.
[0059] I hope these questions and answers can help you.
[0060] For example, when the prompt template type is generalized, the model can generate more diverse responses and avoid single questions.
[0061] Large language model input: The question-answer pairs are somewhat monotonous. Please generate more diverse question-answer pairs.
[0062] Large language model output:
[0063] OK, to better answer your question, I provide the following different ways of asking and corresponding answers:
[0064] 1. Question: What are the specifications of the ##&&& car?
[0065] Answer: ##&&&The car is 4.88 meters long, 2 meters wide and 2 meters high.
[0066] 2. Question: What kind of gasoline does ##&&&car need?
[0067] Answer: ##&&&The car needs to use 92 or above gasoline.
[0068] 3. Question: How is the hybrid version of ##&&&car charged?
[0069] Answer: ##&&&The hybrid version of the car can charge itself.
[0070] 4. Question: How is the fuel consumption of ##&&&'s car?
[0071] Answer: ##&&&The fuel consumption of the car is 5L / 100km.
[0072] 5. Question: ##&&&How much does the car cost?
[0073] Answer: ##&&&The car is sold for 200,000 yuan.
[0074] Hopefully these questions and answers can answer your question more fully.
[0075] For example, when the type of the prompt template is a specified type, the model can generate specified question-answer pairs, avoiding omissions caused by some question-answer pairs not being extracted, that is,
[0076] Large language model input: Based on the above topic and content, extract a question-answer pair about whether No. 95 gasoline can be used.
[0077] Large language model output:
[0078] Based on the questions you provided, I can give the following questions and answers:
[0079] Question: Can ##&&&&car use 95# gasoline?
[0080] Answer: According to the information provided, ##&&& cars need to use 92# gasoline or above, so 95# gasoline can be used in ##&&& cars.
[0081] Optionally, the disclosed embodiment may also manually review the question and answer pairs generated by the large language model according to the model effect and business accuracy requirements, and then add them to the question and answer library, thereby greatly improving the accuracy.
[0082] The method for using a large language model to construct a question-and-answer database provided in an embodiment of the present disclosure converts an unstructured document into a title and paragraph group according to a predefined question-and-answer data format, and then uses a prompt template to guide the large language model to generate a target text based on the context, that is, inputs the title and paragraph group into the large language model in sequence, and obtains the question-and-answer pairs corresponding to each title and paragraph group, thereby efficiently forming a question-and-answer database, which is convenient and fast, improves processing efficiency, and does not require human intervention, greatly reducing labor costs.
[0083] Based on the above embodiments, the present disclosure provides a device for using a large language model to construct a question-answer library. The device 100 for using a large language model to construct a question-answer library can be applied to Figure 1 to Figure 2 The large language model of the corresponding embodiment is used in the method for constructing a question-answer database. Figure 3 The device 100 for constructing a question-answer database using a large language model includes:
[0084] An acquisition unit 101 is used to acquire an unstructured document;
[0085] The conversion unit 102 is used to convert the unstructured document into a title and paragraph group according to a predefined question-answer data format; the question-answer data format includes a title, a paragraph, and a question-answer pair triple, wherein the title refers to the title or title path of an independent subject module in the unstructured document, the paragraph refers to all texts under the title of each independent subject module, and the question-answer pair refers to a set of all valuable questions and answers within the paragraph range;
[0086] The construction unit 103 is used to input titles and paragraph groups into the large language model in sequence according to the prompt template, obtain question-answer pairs corresponding to each title and paragraph group, and form a question-answer library, wherein the prompt template is used to guide the large language model to generate target text based on the context.
[0087] Optionally, in some embodiments of the present disclosure, the type of the prompt template includes at least one of a quantification type, a generalization type and a specified type.
[0088] Optionally, in some embodiments of the present disclosure, the conversion unit 102 is further configured to detect a directory structure of the unstructured document;
[0089] If the unstructured document has a directory structure, the title and paragraph groups corresponding to the unstructured document are obtained respectively according to the directory structure.
[0090] Optionally, in some embodiments of the present disclosure, the conversion unit 102 is further configured to obtain a title and a paragraph group corresponding to the unstructured document based on a separator of the unstructured document if the unstructured document does not have a directory structure.
[0091] Optionally, in some embodiments of the present disclosure, the separator includes at least one of a paragraph, a punctuation mark, and a chapter.
[0092] It should be noted that, for the description of the same steps and the same contents in this embodiment as those in other embodiments, reference can be made to the description in other embodiments and will not be repeated here.
[0093] The large language model provided in the embodiment of the present disclosure is used to construct a device for a question-and-answer library. The device converts an unstructured document into a title and paragraph group according to a predefined question-and-answer data format, and then uses a prompt template to guide the large language model to generate a target text based on the context, that is, the title and paragraph group are input into the large language model in sequence, and the question-and-answer pairs corresponding to each title and paragraph group are obtained. In this way, a question-and-answer library can be efficiently formed, which is convenient and fast, improves processing efficiency, and does not require human intervention, greatly reducing labor costs.
[0094] Based on the above embodiments, the present disclosure provides a question-answering system. Figure 1 to Figure 2 The method for constructing a question and answer database corresponding to the embodiment is obtained.
[0095] As another aspect, an embodiment of the present disclosure provides an electronic device, the electronic device comprising a processor and a memory. The memory stores at least one instruction, at least one program, code set or instruction set, and the instruction, program, code set or instruction set is loaded and executed by the processor to implement Figure 1 to Figure 2 The steps of the method for constructing a question and answer database of the corresponding embodiment.
[0096] As another aspect, the present disclosure provides a computer-readable storage medium for storing program code, the program code for executing the aforementioned Figure 1 to Figure 2 Any implementation manner of the method for constructing a question and answer database in the corresponding embodiment.
[0097] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and modules described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0098] In the several embodiments provided in the present disclosure, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms. The modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment.
[0099] In addition, each functional module in each embodiment of the present disclosure may be integrated into a processing unit, or each module may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit. If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it may be stored in a computer-readable storage medium.
[0100] Based on this understanding, the technical solution of the present disclosure, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method for constructing a question-and-answer library in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0101] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present disclosure, rather than to limit them. Although the present disclosure has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present disclosure.
Claims
1. A method for using a large language model to construct a question-answer database, characterized in that: The method comprises: Access unstructured documents; According to a predefined question-and-answer data format, the directory structure of the unstructured document is detected. If the unstructured document has a directory structure, the title and paragraph group corresponding to the unstructured document are obtained respectively according to the directory structure; if the unstructured document does not have a directory structure, the title and paragraph group corresponding to the unstructured document are obtained based on the separator of the unstructured document; the question-and-answer data format includes a triple of title, paragraph and question-and-answer pair, the title refers to the title or title path of an independent subject module in the unstructured document, the paragraph refers to all texts under the title of each independent subject module, and the question-and-answer pair refers to a set of all valuable questions and answers within the paragraph; According to the prompt template, the title and paragraph groups are input into the large language model in sequence to obtain question-answer pairs corresponding to each title and paragraph group, and a question-answer library is formed, wherein the prompt template is used to guide the large language model to generate a target text based on the context.
2. The method according to claim 1, characterized in that The type of the prompt template includes at least one of a quantitative type, a generalized type and a specified type.
3. The method according to claim 1, characterized in that The separator includes at least one of a paragraph, a punctuation mark, and a chapter.
4. A device for constructing a question-answer database using a large language model, characterized in that: The device comprises: An acquisition unit, used for acquiring unstructured documents; A conversion unit is used to detect the directory structure of the unstructured document according to a predefined question-and-answer data format. If the unstructured document has a directory structure, the title and paragraph group corresponding to the unstructured document are obtained according to the directory structure; if the unstructured document does not have a directory structure, the title and paragraph group corresponding to the unstructured document are obtained based on the delimiter of the unstructured document; the question-and-answer data format includes a triple of a title, a paragraph and a question-and-answer pair, the title refers to the title or title path of an independent subject module in the unstructured document, the paragraph refers to all texts under the title of each independent subject module, and the question-and-answer pair refers to a set of all valuable questions and answers within the paragraph range; A construction unit is used to input the title and paragraph groups into the large language model in sequence according to the prompt template, obtain question-answer pairs corresponding to each title and paragraph group, and form a question-answer library, wherein the prompt template is used to guide the large language model to generate a target text based on the context.
5. The device according to claim 4, characterized in that The type of the prompt template includes at least one of a quantitative type, a generalized type and a specified type.
6. A question-answering system, characterized in that: The question and answer library of the question and answer system is obtained by the method for using a large language model to construct a question and answer library as described in any one of claims 1 to 3.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the method for using a large language model to construct a question and answer database as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Specification manual question answering method and system
CN109739958A
FAQ knowledge base automatic generation method and device based on complex data types
CN112800177A
Method and system for realizing dialogue process by using large language model
CN116595148A