A method, apparatus, and device for generating answers
Patent Information
- Application Number
- CN202410946966.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2026-09-01
- Estimated Expiration
- 2044-07-15
AI Technical Summary
[0003]为了准确的获取问题的答案,一般会向大模型提供问题相关的参考文本,当问题相关的参考文本超出大模型的输入窗口时,大模型会对参考文本进行截断处理,以适配器输入窗口的大小,这样,容易造成大模型理解上的偏差,使得输出的答案不准确
[0018] The answer generation method, apparatus, and device provided in this application, in response to a user-input question and related reference text, segment the reference text to obtain multiple segmented fragments. Then, a retrieval model is used to calculate the relevance value of each segmented fragment relative to the question. This allows for the selection of multiple target segmented fragments from the multiple segmented fragments, tailored to the input window size of a large model. The large model then uses these target segmented fragments to obtain the answer to the question. By filtering the target segmented fragments, irrelevant information is removed, noise interference is reduced, and the most relevant fragments are input into the large model. This allows the large model to perform reasoning based on the most relevant fragments, improving the accuracy of the answer. Furthermore, filtering the target segmented fragments reduces unnecessary computation, enhancing the processing power and performance of the large model.
Smart Images

Figure CN118861244B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a method, apparatus and device for generating answers. Background Technology
[0002] In recent years, the technology of generating answers based on large models has rapidly emerged and become an important trend in the field of artificial intelligence. Large models are capable of understanding and generating natural language text, possessing a high degree of semantic understanding and context processing capabilities, and can provide accurate, detailed, and coherent answers on various topics.
[0003] To accurately obtain the answer to the question, reference text related to the question is usually provided to the large model. When the reference text related to the question exceeds the input window of the large model, the large model will truncate the reference text to fit the size of the input window. This can easily cause the large model to have a misunderstanding, resulting in an inaccurate answer output. Summary of the Invention
[0004] In view of this, this application provides an answer generation method, apparatus, and device for generating accurate answers in long text question-and-answer sessions.
[0005] Specifically, this application is implemented through the following technical solution:
[0006] The first aspect of this application provides a method for providing an answer, the method comprising:
[0007] In response to a user-inputted question and related reference text, when the length of the reference text is greater than the first length of the input window of the large model, the reference text is segmented to obtain multiple segmented fragments corresponding to the reference text; wherein the length of each segmented fragment is less than the second length of the input window of the pre-trained retrieval model;
[0008] For each segment, the relevance value of each segment to the question is calculated using the retrieval model.
[0009] Based on the relevance value of each segment to the problem, multiple target segments are selected from the multiple segment segments; wherein the total length of the multiple target segments is less than or equal to the difference between the first length and the third length of the problem;
[0010] Based on the multiple target segmentation segments, the answer to the question is obtained using the large model.
[0011] A second aspect of this application provides an answer-providing device, the device comprising a segmentation module, a calculation module, a selection module, and an output module; wherein...
[0012] The segmentation module is used to respond to a user-inputted question and related reference text. When the length of the reference text is greater than the first length of the input window of the large model, the module segments the reference text to obtain multiple segmented fragments corresponding to the reference text. The length of each segmented fragment is less than the second length of the input window of the pre-trained retrieval model.
[0013] The calculation module is used to calculate the relevance value of each segment relative to the question using the retrieval model for each segment.
[0014] The selection module is used to select multiple target segments from the multiple segments based on the relevance value of each segment to the problem; wherein the total length of the multiple target segments is less than or equal to the difference between the first length and the third length of the problem;
[0015] The output module is used to obtain the answer to the question based on the multiple target segmentation segments and the large model.
[0016] A third aspect of this application provides an answer generation device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of any of the methods provided in the first aspect of this application.
[0017] A fourth aspect of this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the methods provided in the first aspect of this application.
[0018] The answer generation method, apparatus, and device provided in this application, in response to a user-input question and related reference text, segment the reference text to obtain multiple segmented fragments. Then, a retrieval model is used to calculate the relevance value of each segmented fragment relative to the question. This allows for the selection of multiple target segmented fragments from the multiple segmented fragments, tailored to the input window size of a large model. The large model then uses these target segmented fragments to obtain the answer to the question. By filtering the target segmented fragments, irrelevant information is removed, noise interference is reduced, and the most relevant fragments are input into the large model. This allows the large model to perform reasoning based on the most relevant fragments, improving the accuracy of the answer. Furthermore, filtering the target segmented fragments reduces unnecessary computation, enhancing the processing power and performance of the large model. Attached Figure Description
[0019] Figure 1A flowchart of Embodiment 1 of the answer generation method provided in this application;
[0020] Figure 2 A flowchart of Embodiment 2 of the answer generation method provided in this application;
[0021] Figure 3 A flowchart of Embodiment 3 of the answer generation method provided in this application;
[0022] Figure 4 A flowchart of Embodiment 4 of the answer generation method provided in this application;
[0023] Figure 5 A hardware structure diagram of the answer generation device provided in this application;
[0024] Figure 6 This is a schematic diagram of the structure of the answer generation device provided in this application, according to Embodiment 1. Detailed Implementation
[0025] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application.
[0026] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used herein are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
[0027] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0028] The following specific embodiments are given to illustrate the technical solution of this application in detail.
[0029] Figure 1 The flowchart is for Embodiment 1 of the answer generation method provided in this application. Please refer to... Figure 1 The method provided in this embodiment may include:
[0030] S101. In response to a user-inputted question and related reference text, when the length of the reference text is greater than the first length of the input window of the large model, the reference text is segmented to obtain multiple segmented fragments corresponding to the reference text; wherein, the length of each segmented fragment is less than the second length of the input window of the pre-trained retrieval model.
[0031] It should be noted that the reference texts related to the question can be background information, data, documents or materials provided to generate the answer to the question, and this embodiment does not limit them.
[0032] Furthermore, the length of the reference text can be characterized by the number of characters, words, sentences, word segments, paragraphs, or the file size of the reference text; however, this embodiment does not limit it. Additionally, the first length of the input window of the large model refers to the maximum length of input text that the large model can process at one time; the second length of the input window of the retrieval model refers to the maximum length of input text that the retrieval model can process at one time. It should be noted that, similarly, the maximum input text length can be characterized by the number of characters, words, sentences, word segments, paragraphs, or the file size of the text.
[0033] For example, in one possible implementation, the reference text is "How are you.", and when the length of the reference text is represented by the number of characters, the length of the reference text is 10 characters; as another example, in one possible implementation, the reference text is "How are you.", and when the length of the reference text is represented by the number of words, the length of the reference text is 3 words; as yet another example, in one possible implementation, the reference text is "Hello world! How are you? I'm fine.", and when the length of the reference text is represented by the number of sentences, the length of the reference text is 3 sentences.
[0034] It should be noted that when the length of the reference text is greater than the first length of the input window of the large model, the large model cannot process the reference text in one go. In this application, the reference text is first segmented.
[0035] Specifically, at least one of the following segmentation methods can be used to segment the reference text: space segmentation, punctuation segmentation, regular expression segmentation, and model segmentation. For example, in one embodiment, one segmentation method can be used to segment the reference text; in another embodiment, multiple segmentation methods can be combined to segment the reference text.
[0036] In a practical implementation, for example, one possible approach is to use space segmentation to continuously segment the reference text.
[0037] For example, in one possible implementation, the first half of the references can be segmented using spaces, and the second half of the reference text can be segmented using punctuation.
[0038] It should be noted that after segmenting the reference text, the length of each segment in the resulting multiple segments is less than the second length of the input window of the retrieval model.
[0039] Furthermore, in this application, "large model" generally refers to a model with a large number of parameters and a complex structure. More specifically, the large model in this application is a Natural Language Processing (NPL) model. For example, in one embodiment, the large model may be GPT (Generative Pre-trained Transformer), BERT (Bidirectional Encoder Representations from Transformers), etc.
[0040] S102. For each segment, the relevance value of each segment to the question is calculated using the retrieval model.
[0041] It should be noted that the retrieval model is a pre-trained model. The specific training process of the retrieval model can be found in the relevant technical descriptions, and will not be repeated here. Furthermore, the retrieval model is a model used to calculate relevance values. The input to this model is the segmentation fragment and the question, and the output is the relevance value between the segmentation fragment and the question; that is, the output is the relevance value of the segmentation fragment relative to the question.
[0042] In this step, for each segment, the segment and the question can be simultaneously input into the retrieval model, and then the retrieval model will output the relevance value of the segment relative to the question.
[0043] In specific implementation, for example, for the segment t i The segment t is calculated using a retrieval model. i When considering the relevance value relative to the problem, the problem and the segment t are compared. i The input is fed into the retrieval model, and the retrieval model outputs the segmented fragment t. i The relevance value relative to the problem.
[0044] S103. Based on the relevance value of each segment to the problem, select multiple target segments from the multiple segments; wherein the total length of the multiple target segments is less than or equal to the difference between the first length and the third length of the problem.
[0045] For example, in one possible implementation, the segmented pieces can be sorted according to their relevance to the problem, and multiple target segmented pieces can be selected from high to low.
[0046] It should be noted that the number of target segment segments contained in multiple target segment segments is determined according to actual needs, and is not limited in this embodiment. In specific implementation, it is only necessary to ensure that the total length of the multiple target segment segments is less than or equal to the difference between the first length and the third length of the problem.
[0047] S104. Based on the multiple target segmentation segments, use the large model to obtain the answer to the question.
[0048] In practice, multiple target segments and questions can be input into a large model, which then performs reasoning based on the inputs and outputs the answer to the question.
[0049] Optionally, in one possible implementation, the multiple target segments and the question can be concatenated to obtain a concatenated result, which can then be input into a large model for inference and outputting the answer to the question.
[0050] In practice, newline characters can be used to concatenate multiple target segments and questions to obtain the concatenated result.
[0051] The answer generation method provided in this embodiment responds to a user-inputted question and related reference text. By segmenting the reference text, multiple segmented fragments are obtained. A retrieval model is then used to calculate the relevance value of each segmented fragment to the question. This allows for the selection of multiple target segmented fragments from the multiple fragments, tailored to the input window size of a large model. The large model then uses these target segmented fragments to obtain the answer to the question. By filtering target segmented fragments, irrelevant information is removed, reducing noise interference, and the most relevant fragments are input into the large model. This allows the large model to perform reasoning based on the most relevant fragments, improving the accuracy of the answer. Furthermore, filtering target segmented fragments reduces unnecessary computation, enhancing the processing power and performance of the large model.
[0052] Figure 2 The flowchart for Embodiment 2 of the answer generation method provided in this application is shown below. Please refer to... Figure 2The method provided in this embodiment, based on the above embodiments, involves segmenting the reference text to obtain multiple segmented fragments corresponding to the reference text, including:
[0053] S201. The reference text is segmented according to a preset regular expression to obtain multiple paragraph texts corresponding to the reference text.
[0054] Specifically, regular expressions can segment reference text according to sentences (ending punctuation), paragraphs, specific keywords, phrases, and predefined regular expression patterns. It should be noted that predefined regular expression patterns are used to define search patterns, matching rules, or replacement rules for strings. They are string expressions used to describe text patterns and include ordinary characters (such as letters, numbers, and punctuation marks) and special characters (metacharacters).
[0055] The preset regular expressions are set according to actual needs, and are not limited in this embodiment. For example, in one possible implementation, the predefined regular expressions may include "\n\n" and "\n".
[0056] Based on the example above, in practical implementation, we can recursively use "\n\n" and "\n" as delimiters to segment the reference text, obtaining multiple paragraph texts corresponding to the reference text. That is, first use "\n\n" as a delimiter to segment the reference text, obtaining multiple segmented paragraph texts; further, for each segmented paragraph text, if the length of the segmented paragraph text is greater than the second length of the input window of the retrieval model, then use "\n" as a delimiter to segment the segmented paragraph text again.
[0057] S202. For the target paragraph text among the multiple paragraph texts, the target paragraph text is segmented using a pre-trained segmentation model to obtain the sentence text corresponding to the target paragraph text; wherein, the target paragraph text is the paragraph text among the multiple paragraph texts whose length is greater than the second length.
[0058] It should be noted that the target paragraph text refers to the paragraph text whose length is greater than the second length. For example, after the reference text is segmented according to the preset regular expression, M paragraph texts are obtained. For ease of explanation, these M paragraph texts are denoted as paragraph text 1, paragraph text 2, ..., paragraph text M. For example, if the length of paragraph text 2, paragraph text 7, and paragraph text M is greater than the second length, then paragraph text 2, paragraph text 7, and paragraph text M are the target paragraph texts.
[0059] Specifically, the pre-trained segmentation model is used to segment long text into smaller semantic units. For example, in one possible implementation, the pre-trained segmentation model can identify the boundaries of semantic units through predefined rules, and then perform text segmentation based on the identification results; in another embodiment, the pre-trained segmentation model can model the text sequence and capture long-distance dependencies through a self-attention mechanism to achieve the purpose of text segmentation.
[0060] In this step, for target paragraph texts with a length greater than the second length, a pre-trained segmentation model can be used to segment them again to obtain the sentence text corresponding to the target paragraph text.
[0061] S203. For each statement text, when the length of the statement text is greater than the second length, the statement text is recursively segmented according to a plurality of pre-set punctuation marks until the length of the segmented character fragment is less than or equal to the second length.
[0062] It should be noted that the pre-defined punctuation marks are set according to actual needs, and are not limited in this embodiment. For example, in one possible implementation, the pre-defined punctuation marks include a period, comma, semicolon, exclamation mark, question mark, space, and null character.
[0063] Based on the example above, in practical implementation, for text statements longer than the second length, the text is first segmented using periods. It should be noted that after segmenting the text using periods, the length of the resulting character segments may be less than or equal to the second length, or it may be greater than the second length. Character segments shorter than or equal to the second length are considered acceptable; those longer than the second length are not, and are further segmented using commas, and so on, until all segmented character segments are shorter than or equal to the second length.
[0064] S204. The paragraph texts with a length less than or equal to the second length in the plurality of paragraph texts, the statement texts with a length less than or equal to the second length in the statement texts, and the segmented character fragments are determined as the plurality of segmented fragments corresponding to the reference text.
[0065] Referring to the preceding description, it is understandable that after segmenting the reference text according to the preset regular expression in step S201, some of the resulting paragraph texts have a length less than or equal to the second length, while others have a length greater than the second length. For paragraph texts with a length less than or equal to the second length, they can be directly used as the segmented fragments corresponding to the reference text. For paragraph texts with a length greater than the second length, step S202 is used to further segment them using the segmentation model to obtain multiple sentence texts. Similarly, it is understandable that among the multiple sentence texts, there are also sentence texts with a length less than or equal to the second length, as well as sentence texts with a length greater than the second length. For sentence texts with a length less than or equal to the second length, they can be directly used as the segmented fragments corresponding to the reference text. For sentence texts with a length greater than the second length, step S203 is used to recursively segment them according to a preset set of punctuation marks in sequence to obtain multiple character fragments. Referring to the description in step S203, it can be understood that when the text of a sentence is recursively segmented according to multiple punctuation marks, and the length of the character segments obtained after segmentation is less than or equal to the second length, the character segments can be directly used as the segmented segments corresponding to the reference text.
[0066] In summary, in this step, paragraph texts with a length less than or equal to the second length, sentence texts with a length less than or equal to the second length, and segmented character fragments are identified as multiple segmented fragments corresponding to the reference text.
[0067] Understandably, regular expression segmentation is suitable for text with a fixed format. For text from different sources, which typically have different formats, separate regular expressions need to be designed for each source, which is not only time-consuming and laborious but also unlikely to achieve ideal results. While model-based segmentation is suitable for long text segmentation, it requires a large amount of data for training, and its segmentation effect depends on the quality and quantity of the dataset. The method provided in this embodiment combines regular expression segmentation and model-based segmentation when segmenting reference text. It can adapt to the length of the input window of the retrieval model and the input window of the large model, dynamically adjusting the segmentation results to suit reference text from different sources.
[0068] Figure 3 For the flowchart of Embodiment 3 of the answer generation method provided in this application, please refer to... Figure 3 The method provided in this embodiment, based on the above embodiments, further includes selecting multiple target segments from the multiple segmented segments according to the relevance value of each segmented segment to the problem, comprising:
[0069] S301. Sort the multiple segmented segments in descending order of their correlation values to obtain the sorting result.
[0070] For example, in one possible implementation, the reference text corresponds to multiple segmented segments, including 10 segmented segments. For ease of explanation, these 10 segmented segments are denoted as segmented segment 1, segmented segment 2, segmented segment 3, segmented segment 4, ..., segmented segment 10. The lengths of these 10 segmented segments and their relevance values to the corresponding questions are shown in Table 1.
[0071] Table 1. Length of segmented data and their corresponding relevance values to the problem.
[0072]
[0073]
[0074] Referring to the example shown in Table 1, in this step, the 10 segments are sorted in descending order of their relevance values. The sorting results are as follows: segment 8 (0.92), segment 3 (0.9), segment 9 (0.88), segment 1 (0.85), segment 6 (0.77), segment 2 (0.7), segment 7 (0.65), segment 10 (0.6), segment 4 (0.55), and segment 5 (0.42).
[0075] S302. Select N segmentation segments from the sorting results in order from front to back as the plurality of target segmentation segments; wherein, N is the maximum value j that satisfies a preset condition, the preset condition being that the sum of the lengths of all segmentation segments from the first segmentation segment to the j-th segmentation segment is less than or equal to the difference.
[0076] It should be noted that N is the maximum value j that satisfies the preset condition, and N is an integer. Furthermore, the preset condition is that the sum of the lengths of all segments from the first segment to the j-th segment is less than or equal to the difference between the first length of the input port of the large model and the third length of the problem.
[0077] In other words, N can be expressed by the following formula:
[0078]
[0079] Where len(t) i ) represents the length of the i-th segment;
[0080] L2 is the first length of the input window for the large model;
[0081] len(Q) is the third length of the problem.
[0082] In specific implementation, referring to the example in step S301, in this step, following the order from front to back, first, segment 8 is taken from the sorting result. It is then determined whether the length of segment 8 is greater than the difference between the first length of the large model's input window and the third length of the problem. If not, segment 3 is taken from the sorting result again, until the total length of all taken segment segments is greater than the difference between the first length of the large model's input window and the third length of the problem. It should be noted that when the total length of all taken segment segments is greater than the difference between the first length of the large model's input window and the third length of the problem, the last taken segment is removed, and the remaining segment segments are the multiple target segment segments.
[0083] For example, referring to the examples shown in Table 1, in one possible implementation, the sum of the lengths of all segments from the first segment to the fifth segment is less than the difference. After taking the sixth segment, the sum of the lengths of all segments from the first segment to the sixth segment is greater than the difference. At this time, N equals 5, and the first segment to the fifth segment is the target segment.
[0084] The method provided in this embodiment sorts the multiple segmented segments in descending order of relevance value to obtain a sorting result. Then, it finds the maximum value j of the sum of the lengths of all segmented segments from the first segmented segment to the j-th segment, which is less than or equal to the difference. These j segmented segments are then used as target segmented segments. This ensures that the segmented segments relevant to the question are selected to the greatest extent possible, maximizing the use of relevant information in the reference text, reducing information loss and redundancy, and enabling the large model to reason and generate answers from more complete and relevant reference content, thereby further improving the accuracy of reasoning.
[0085] Figure 4 For the flowchart of the answer generation method embodiment four provided in this application, please refer to... Figure 4 The method provided in this embodiment, based on the above embodiments, further includes selecting multiple target segments from the multiple segmented segments according to the relevance value of each segmented segment to the problem, comprising:
[0086] S401. Find multiple candidate segmentation segments from the multiple segmentation segments whose correlation value is greater than a preset threshold.
[0087] Specifically, the preset threshold is set according to actual needs, and is not limited in this embodiment. For example, in one possible implementation, the preset threshold is 0.8.
[0088] Based on the example above, in this step, we search for segment segments with a relevance value greater than 0.8 from multiple segment segments. The segment segments found are the candidate segment segments.
[0089] Based on the examples shown in Table 1, the multiple candidate segmentation segments found in this step are: segmentation segment 8 (0.92), segmentation segment 3 (0.9), segmentation segment 9 (0.88), and segmentation segment 1 (0.85).
[0090] S402. When the total length of the plurality of candidate segmentation segments is less than or equal to the difference, the plurality of candidate segmentation segments are determined as the plurality of target segmentation segments.
[0091] Referring to the previous description, the total length of multiple target segment segments needs to be less than or equal to the difference between the first length of the input window of the large model and the third length of the problem. In this step, if the total length of multiple candidate segment segments is less than the above difference, then the multiple candidate segment segments can be directly used as multiple target segment segments to be input into the large model.
[0092] S403. When the total length of the plurality of candidate segmentation segments is greater than the difference, select the plurality of target segmentation segments from the plurality of candidate segmentation segments.
[0093] It should be noted that when the total length of multiple candidate segment segments is greater than the difference, it means that these multiple candidate segment segments are still beyond the range that the large model can process at one time. In this case, it is necessary to select the multiple target segment segments from the multiple candidate segment segments.
[0094] For example, in one possible implementation, one candidate segment can be randomly removed, and then it can be determined whether the total length of the remaining candidate segments is greater than the difference. If the total length of the remaining candidate segments is not greater than the difference, the remaining candidate segments are determined as the plurality of target segments. If the total length of the remaining candidate segments is greater than the difference, one more candidate segment is randomly removed until the total length of the remaining candidate segments is less than the difference.
[0095] For example, in another possible implementation, multiple candidate segment segments can be removed sequentially in ascending order of relevance value until the total length of the remaining candidate segment segments is less than the difference. The remaining candidate segment segment is then the target segment. For instance, in another possible implementation, if the total length of multiple candidate segment segments is greater than the difference, the segment with the lowest relevance value among the candidate segment segments is removed. It is then determined whether the total length of the remaining multiple candidate segment segments is greater than the difference. If not, the remaining candidate segment segment is taken as the target segment segment; if so, the process continues until the total length of the remaining candidate segment segments is less than the difference.
[0096] For example, in another possible implementation, one of the candidate segments can be removed sequentially from multiple candidate segments in ascending order of length until the total length of the remaining candidate segments is less than the difference.
[0097] The method provided in this embodiment selects target segments by searching for multiple candidate segments with relevance values greater than a preset threshold from the multiple segmented segments. Then, when the total length of the multiple candidate segmented segments is less than or equal to the difference, the multiple candidate segmented segments are determined as the multiple target segmented segments. When the total length of the multiple candidate segmented segments is greater than the difference, the multiple target segmented segments are selected from the multiple candidate segmented segments. This ensures that the selected target segmented segments are all relevant to the problem, avoiding interference from irrelevant information in the reasoning process. It effectively reduces redundant information and invalid reasoning in the reasoning process, allowing the large model to focus on processing key content and improving the accuracy and efficiency of reasoning.
[0098] Corresponding to the aforementioned embodiment of the answer generation method, this application also provides an embodiment of an answer generation apparatus.
[0099] An embodiment of the answer generation device provided in this application can be applied to an answer generation device. The device embodiment can be implemented through software, hardware, or a combination of both. Taking software implementation as an example, as a logical device, it is formed by the processor of the answer generation device loading the corresponding computer program instructions from non-volatile memory into memory for execution. From a hardware perspective, such as... Figure 5 The diagram shown is a hardware structure diagram of the answer generation device provided in this application, except for... Figure 5In addition to the processor, memory, network interface, and non-volatile memory shown, the answer generation device in the embodiment may also include other hardware depending on the actual function of the answer generation device, which will not be described in detail here.
[0100] Figure 6 This is a schematic diagram of the structure of the answer generation device provided in Embodiment 1 of this application. Please refer to... Figure 6 The apparatus provided in this embodiment includes a segmentation module 610, a calculation module 620, a selection module 630, and an output module 640; wherein,
[0101] The segmentation module 610 is used to respond to a user-inputted question and related reference text. When the length of the reference text is greater than the first length of the input window of the large model, the reference text is segmented to obtain multiple segmented fragments corresponding to the reference text. The length of each segmented fragment is less than the second length of the input window of the pre-trained retrieval model.
[0102] The calculation module 620 is used to calculate the relevance value of each segment relative to the question using the retrieval model for each segment.
[0103] The selection module 630 is used to select multiple target segments from the multiple segments based on the relevance value of each segment to the problem; wherein the total length of the multiple target segments is less than or equal to the difference between the first length and the third length of the problem;
[0104] The output module 640 is used to obtain the answer to the question based on the multiple target segmentation segments and the large model.
[0105] The apparatus of this embodiment can be used to perform... Figure 1 The steps of the method embodiment shown are similar in principle and process, and will not be repeated here.
[0106] The segmentation module 610 is specifically used for:
[0107] The reference text is segmented according to a preset regular expression to obtain multiple paragraph texts corresponding to the reference text;
[0108] For the target paragraph text among the multiple paragraph texts, the target paragraph text is segmented using a pre-trained segmentation model to obtain the sentence text corresponding to the target paragraph text; wherein, the target paragraph text is the paragraph text among the multiple paragraph texts whose length is greater than the second length;
[0109] For each statement text, when the length of the statement text is greater than the second length, the statement text is recursively segmented according to a set number of punctuation marks until the length of the segmented character fragment is less than or equal to the second length.
[0110] The paragraph texts with a length less than or equal to the second length in the plurality of paragraph texts, the statement texts with a length less than or equal to the second length in the statement texts, and the segmented character fragments are identified as the plurality of segmented fragments corresponding to the reference text.
[0111] The selection module 630 is specifically used for:
[0112] The multiple segmented segments are sorted in descending order of their relevance values to obtain the sorting result;
[0113] In order from front to back, N segments are selected from the sorting results as the plurality of target segments; wherein, N is the maximum value j that satisfies a preset condition, the preset condition being that the sum of the lengths of all segments from the first segment to the j-th segment is less than or equal to the difference.
[0114] The selection module 630 is specifically used for:
[0115] From the plurality of segmented segments, find multiple candidate segmented segments whose relevance values are greater than a preset threshold;
[0116] When the total length of the plurality of candidate segmentation segments is less than or equal to the difference, the plurality of candidate segmentation segments are determined as the plurality of target segmentation segments;
[0117] When the total length of the plurality of candidate segmentation segments is greater than the difference, the plurality of target segmentation segments are selected from the plurality of candidate segmentation segments.
[0118] The output module 640 is specifically used to splice the multiple target segmentation fragments and the question to obtain a splicing result, and input the splicing result into the large model so that the large model can perform reasoning and output the answer to the question.
[0119] The output module 640 is specifically used to concatenate the multiple target segmentation fragments and the question using newline characters to obtain a concatenation result.
[0120] Optionally, the pre-defined punctuation marks include period, comma, semicolon, exclamation mark, question mark, space, and null character.
[0121] Please continue to refer to Figure 5This application also provides an answer generation device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of any of the methods provided in the first aspect of this application.
[0122] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the methods provided in this application.
[0123] The specific implementation process of the functions and roles of each unit in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0124] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this application according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0125] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A method for generating answers, characterized in that, The method includes: In response to a user-inputted question and related reference text, when the length of the reference text is greater than the first length of the input window of the large model, the reference text is segmented to obtain multiple segmented fragments corresponding to the reference text; wherein the length of each segmented fragment is less than the second length of the input window of the pre-trained retrieval model; For each segment, the relevance value of each segment to the question is calculated using the retrieval model. Based on the relevance value of each segment to the problem, multiple target segments are selected from the multiple segment segments; wherein the total length of the multiple target segments is less than or equal to the difference between the first length and the third length of the problem; Based on the multiple target segmentation segments, the answer to the question is obtained using the large model.
2. The method according to claim 1, characterized in that, The step of segmenting the reference text to obtain multiple segmented fragments corresponding to the reference text includes: The reference text is segmented according to a preset regular expression to obtain multiple paragraph texts corresponding to the reference text; For the target paragraph text among the multiple paragraph texts, the target paragraph text is segmented using a pre-trained segmentation model to obtain the sentence text corresponding to the target paragraph text; wherein, the target paragraph text is the paragraph text among the multiple paragraph texts whose length is greater than the second length; For each statement text, when the length of the statement text is greater than the second length, the statement text is recursively segmented according to a set number of punctuation marks until the length of the segmented character fragment is less than or equal to the second length. The paragraph texts with a length less than or equal to the second length in the plurality of paragraph texts, the statement texts with a length less than or equal to the second length in the statement texts, and the segmented character fragments are identified as the plurality of segmented fragments corresponding to the reference text.
3. The method according to claim 1, characterized in that, The step of selecting multiple target segments from the plurality of segments based on the relevance value of each segment to the problem includes: The multiple segmented segments are sorted in descending order of their relevance values to obtain the sorting result; In order from front to back, N segments are selected from the sorting results as the plurality of target segments; wherein, N is the maximum value j that satisfies a preset condition, the preset condition being that the sum of the lengths of all segments from the first segment to the j-th segment is less than or equal to the difference.
4. The method according to claim 1, characterized in that, The step of selecting multiple target segments from the plurality of segments based on the relevance value of each segment to the problem includes: From the plurality of segmented segments, find multiple candidate segmented segments whose relevance values are greater than a preset threshold; When the total length of the plurality of candidate segmentation segments is less than or equal to the difference, the plurality of candidate segmentation segments are determined as the plurality of target segmentation segments; When the total length of the plurality of candidate segmentation segments is greater than the difference, the plurality of target segmentation segments are selected from the plurality of candidate segmentation segments.
5. The method according to claim 1, characterized in that, The step of obtaining the answer to the question using the large model based on the multiple target segmentation segments includes: By splicing the multiple target segmentation fragments and the problem, a splicing result is obtained; The splicing result is input into the large model, which then performs reasoning to output the answer to the question.
6. The method according to claim 5, characterized in that, The process of splicing the multiple target segmented fragments and the problem yields a splicing result, including: The multiple target segments and the question are concatenated using newline characters to obtain the concatenation result.
7. The method according to claim 2, characterized in that, The pre-defined punctuation marks include period, comma, semicolon, exclamation mark, question mark, space, and null character.
8. An answer generation device, characterized in that, The device includes a segmentation module, a calculation module, a selection module, and an output module; wherein, The segmentation module is used to respond to a user-inputted question and related reference text. When the length of the reference text is greater than the first length of the input window of the large model, the module segments the reference text to obtain multiple segmented fragments corresponding to the reference text. The length of each segmented fragment is less than the second length of the input window of the pre-trained retrieval model. The calculation module is used to calculate the relevance value of each segment relative to the question using the retrieval model for each segment. The selection module is used to select multiple target segments from the multiple segments based on the relevance value of each segment to the problem; wherein the total length of the multiple target segments is less than or equal to the difference between the first length and the third length of the problem; The output module is used to obtain the answer to the question based on the multiple target segmentation segments and the large model.
9. An answer generation device, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor executes the program to implement the steps of the method according to any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by a processor, it implements the steps of the method according to any one of claims 1-7.
Citation Information
Patent Citations
Answer generation method and device, equipment and storage medium
CN117669512A
Traditional Chinese medicine question and answer method and device based on long document retrieval enhancement generation and medium
CN117828050A