Answer generation method, apparatus and device

By segmenting the reference text and calculating its relevance, the segmentation segment that is suitable for the large model is selected, which solves the problem of inaccurate answers in long text question answering and improves the accuracy of the answers and the processing power of the large model.

WO2026016339A1PCT designated stage Publication Date: 2026-01-22SHENZHEN INTELLIFUSION TECHNOLOGIES CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/129863
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-07-15
Filing Date
2024-11-05
Publication Date
2026-01-22

AI Technical Summary

Technical Problem

Large models suffer from inaccurate answers when processing long text question-and-answer sessions because the reference text exceeds the input window.

Method used

The reference text is segmented, and the relevance value of each segment is calculated using a retrieval model. The target segment that fits the input window of the large model is selected, and the answer to the question is obtained through the large model.

Benefits of technology

It improves the accuracy of answers, reduces noise interference, and enhances the processing power and performance of large models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024129863_22012026_PF_FP_ABST
    Figure CN2024129863_22012026_PF_FP_ABST
Patent Text Reader

Abstract

The present application provides an answer generation method, apparatus and device. The method provided by the present application comprises: in response to a question input by a user and a reference text related to the question, when the length of the reference text is greater than a first length of an input window of a large model, segmenting the reference text to obtain a plurality of segmented fragments corresponding to the reference text, the length of each segmented fragment is less than a second length of an input window of a retrieval model; for each segmented fragment, using the retrieval model to calculate a correlation value of each segmented fragment relative to the problem; selecting a plurality of target segmented fragments from among the plurality of segmented fragments on the basis of the correlation value of each segmented fragment relative to the problem, the total length of the plurality of target segmented fragments is less than or equal to the difference between the first length and a third length of the problem; and on the basis of the plurality of target segmented fragments, using the large model to obtain an answer to the question. The answer generation method, apparatus and device provided by the present application can accurately generate answers corresponding to questions.
Need to check novelty before this filing date? Find Prior Art

Description

An answer generation method, device and equipment TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence, and in particular to an answer generation method, device and equipment.

[0002] The present application claims priority to the Chinese patent application No. 202410946966.8, filed on July 15, 2024, and entitled "An answer generation method, device and equipment", the whole content of which is incorporated herein by reference. BACKGROUND

[0003] In recent years, the technology of generating answers based on large models has rapidly emerged as an important trend in the field of artificial intelligence. Large models can understand and generate natural language text, with high semantic understanding and context processing capabilities, and can provide accurate, detailed and coherent answers on various topics.

[0004] In order to accurately obtain the answer to a question, the large model is generally provided with reference text related to the question. When the reference text related to the question exceeds the input window of the large model, the large model will perform truncation processing on the reference text to adapt to the size of the input window. This can easily cause deviation in the understanding of the large model, resulting in inaccurate answers. TECHNICAL PROBLEM

[0005] The present application provides an answer generation method, device and equipment to generate accurate answers in long text question answering.

[0006] Specifically, the present application is implemented by the following technical solutions:

[0007] The first aspect of the present application provides an answer method, the method comprising:

[0008] In response to a user input question and reference text related to the question, 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 divided to obtain a plurality of divided segments corresponding to the reference text; wherein the length of each divided segment in the plurality of divided segments is less than the second length of the input window of the pre-trained retrieval model;

[0009] For each divided segment, the relevance value of each divided segment relative to the question is calculated using the retrieval model;

[0010] According to the relevance value of each divided segment relative to the question, a plurality of target divided segments are selected from the plurality of divided segments; wherein the total length of the plurality of target divided segments is less than or equal to the difference between the first length and the third length of the question.

[0011] According to the plurality of target split segments, an answer to the question is obtained by using the large model.

[0012] The second aspect of the present application provides an answer device, the device comprising a splitting module, a calculation module, a selection module and an output module; wherein,

[0013] The splitting module is configured to, in response to a question input by a user and reference text related to the question, split the reference text when the length of the reference text is greater than a first length of an input window of a large model, to obtain a plurality of split segments corresponding to the reference text; wherein the length of each split segment in the plurality of split segments is less than a second length of an input window of a pre-trained retrieval model.

[0014] The calculation module is configured to, for each split segment, calculate a relevance value of the each split segment with respect to the question by using the retrieval model.

[0015] The selection module is configured to select a plurality of target split segments from the plurality of split segments according to the relevance value of each split segment with respect to the question; wherein the total length of the plurality of target split segments is less than or equal to the difference between the first length and a third length of the question.

[0016] The output module is configured to obtain an answer to the question by using the large model according to the plurality of target split segments.

[0017] The third aspect of the present application provides an answer generation device, comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor executes the program to implement the steps of any one of the methods provided in the first aspect of the present application.

[0018] The fourth aspect of the present application provides a computer readable storage medium having a computer program stored thereon, wherein the program is executed by a processor to implement the steps of any one of the methods provided in the first aspect of the present application.

[0019] The answer generation method, device and equipment provided in the application, in response to a question input by a user and reference text related to the question, obtain a plurality of segmented fragments corresponding to the reference text by performing segmentation processing on the reference text, and then calculate a relevance value of each segmented fragment relative to the question by using a retrieval model. In this way, the plurality of target segmented fragments with an input window size adapted to the large model can be selected from the plurality of segmented fragments according to the relevance value of each segmented fragment relative to the question, and then the large model obtains the answer to the question according to the plurality of target segmented fragments. In this way, by screening the target segmented fragments, not only irrelevant information can be filtered out and noise interference can be reduced, but also the most relevant fragments can be selected to input the large model, so that the large model can perform reasoning based on the fragments most relevant to the question, and the accuracy of the answer can be improved. In addition, by screening the target segmented fragments, unnecessary calculation can be reduced, and the processing capacity and performance of the large model can be improved. BRIEF DESCRIPTION OF DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.

[0021] Fig. 1 is a flowchart of an answer generation method embodiment provided by the present application;

[0022] Fig. 2 is a flowchart of an answer generation method embodiment provided by the present application;

[0023] Fig. 3 is a flowchart of an answer generation method embodiment provided by the present application;

[0024] Fig. 4 is a flowchart of an answer generation method embodiment provided by the present application;

[0025] Fig. 5 is a hardware structure diagram of an answer generation device provided by the present application;

[0026] Fig. 6 is a structural schematic diagram of an answer generation device embodiment provided by the present application. Embodiments of the present application

[0027] The exemplary embodiments will be described in detail here, and examples are shown in the drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application.

[0028] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting. As used in this application, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "and / or," as used herein, refers to and encompasses any and all possible combinations of one or more of the associated listed items.

[0029] It should be understood that, although the terms first, second, third, etc. can be used herein to describe various information, these terms are not intended to denote a particular order or hierarchy. These terms are used only to distinguish one from another. For example, a first information can be termed a second information, and, similarly, a second information can be termed a first information, without departing from the scope of the application. As used herein, the term "if' can be interpreted to mean "when" or "upon" or "in response to determining" taking into account the context in which the term is used.

[0030] The specific embodiments are given as follows to introduce the technical scheme of the application in detail.

[0031] FIG. 1 is a flowchart of an embodiment of the answer generation method provided by the application. Referring to FIG. 1, the method provided by the embodiment can include:

[0032] S101, in response to a question input by a user and reference text related to the question, when the length of the reference text is greater than a first length of an input window of a large model, the reference text is segmented to obtain a plurality of segmented fragments corresponding to the reference text; wherein the length of each segmented fragment in the plurality of segmented fragments is less than a second length of an input window of a pre-trained retrieval model.

[0033] It should be noted that the reference text related to the question can be background information, data, literature or materials provided for generating an answer to the question, which is not limited in the embodiment.

[0034] Further, the length of the reference text can be represented by the number of characters, the number of words, the number of sentences, the number of word fragments, the number of paragraphs, or the file size of the reference text, which is not limited in the embodiment. In addition, the first length of the input window of the large model refers to the maximum input text length that the large model can process at a time; the second length of the input window of the retrieval model refers to the maximum input text length that the retrieval model can process at a time. It should be noted that similarly, the maximum input text length can be represented by the number of characters, the number of words, the number of sentences, the number of word fragments, the number of paragraphs, or the file size of the text.

[0035] For example, in a possible implementation, the reference text is "How are you.", and the length of the reference text is 10 characters when the number of characters is used to represent the length of the reference text; for another example, in a possible implementation, the reference text is "How are you.", and the length of the reference text is 3 words when the number of words is used to represent the length of the reference text; for another example, in a possible implementation, the reference text is "Hello world! How are you? I'm fine.", and the length of the reference text is 3 sentences when the number of sentences is used to represent the length of the reference text.

[0036] 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 at one time, and in this application, the reference text is first segmented.

[0037] Specifically, the reference text can be segmented using at least one of a space segmentation method, a punctuation segmentation method, a regular segmentation method, and a model segmentation method. For example, in an embodiment, the reference text can be segmented using one segmentation method; for another example, in another embodiment, the reference text can be segmented using a combination of multiple segmentation methods.

[0038] In a specific implementation, for example, in a possible implementation, the reference text can be continuously segmented using the space segmentation method.

[0039] For another example, in a possible implementation, the reference text can be segmented using the space segmentation method for the first half of the reference text, and the punctuation segmentation method for the second half of the reference text.

[0040] It should be noted that after the reference text is segmented, the length of each segmented segment in the plurality of segmented segments is less than the second length of the input window of the retrieval model.

[0041] In addition, in this application, the large model refers to a model that usually has a large number of parameters and a complex structure. Further, the large model in this application is a natural language processing (NPL) model. For example, in an embodiment, the large model can be a GPT (Generative Pre-trained Transformer, GPT for short), a BERT (Bidirectional Encoder Representations from Transformers, BERT for short), etc.

[0042] S102, for each segmented segment, calculating a relevance value of each segmented segment relative to the question by using the retrieval model.

[0043] 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.

[0044] 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.

[0045] 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.

[0046] 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.

[0047] 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.

[0048] 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.

[0049] S104. Based on the multiple target segmentation segments, use the large model to obtain the answer to the question.

[0050] 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.

[0051] 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.

[0052] In a specific implementation, the target split segments and the question can be spliced by using a line feed character to obtain a splicing result.

[0053] The answer generation method provided in this embodiment responds to a question input by a user and reference text related to the question, performs split processing on the reference text to obtain a plurality of split segments corresponding to the reference text, and then calculates a relevance value of each split segment relative to the question by using a retrieval model. In this way, the plurality of target split segments that adapt to the input window size of the large model can be selected from the plurality of split segments according to the relevance value of each split segment relative to the question, and the large model can then obtain an answer to the question according to the plurality of target split segments. In this way, by screening the target split segments, irrelevant information can be filtered out and noise interference can be reduced, and the most relevant segments can be selected to input the large model, so that the large model can perform reasoning based on the segments most relevant to the question, and the accuracy of the answer can be improved. In addition, by screening the target split segments, unnecessary calculations can be reduced, and the processing capability and processing performance of the large model can be improved.

[0054] FIG. 2 is a flowchart of an embodiment two of the answer generation method provided in the present application. Referring to FIG. 2, the method provided in this embodiment is based on the above-mentioned embodiments, and the split processing on the reference text to obtain a plurality of split segments corresponding to the reference text includes the following steps.

[0055] S201. Split the reference text according to a preset regular expression to obtain a plurality of paragraph texts corresponding to the reference text.

[0056] Specifically, the regular expression can split the reference text according to a sentence (a sentence ending punctuation), a paragraph, a specific keyword, a phrase, and a predefined regular expression pattern. It should be noted that the predefined regular expression pattern is used to define a search pattern, a matching rule or a replacement rule of a string, and it is a string expression used to describe a text pattern, which includes normal characters (such as letters, numbers, and punctuation marks) and special characters (meta characters).

[0057] The preset regular expression is set according to actual needs, and in this embodiment, it is not limited. For example, in one possible implementation, the predefined regular expression can include “\n\n” and “\n”.

[0058] In combination with the above example, in implementation, the reference text can be segmented by using "\n\n" and "\n" as delimiters to obtain multiple paragraph texts corresponding to the reference text. That is, the reference text is first segmented by using "\n\n" as a delimiter to obtain multiple segmented paragraph texts; and then, for each segmented paragraph text, the segmented paragraph text is further segmented by using "\n" as a delimiter when the length of the segmented paragraph text is greater than the second length of the input window of the retrieval model.

[0059] S202, for a target paragraph text in the multiple paragraph texts, the target paragraph text is segmented by using a pre-trained segmentation model to obtain a sentence text corresponding to the target paragraph text; wherein the target paragraph text is a paragraph text with a length greater than the second length.

[0060] It should be noted that the target paragraph text refers to a paragraph text with a length greater than the second length. For example, after the reference text is segmented according to a preset regular expression, M paragraph texts are obtained, which are denoted as paragraph text 1, paragraph text 2, …, and paragraph text M for convenience of description. For example, the lengths of the paragraph text 2, the paragraph text 7, and the paragraph text M are greater than the second length, and thus the paragraph text 2, the paragraph text 7, and the paragraph text M are target paragraph texts.

[0061] Specifically, the pre-trained segmentation model is used to segment a long text into smaller semantic units. For example, in a 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 result; for another example, in another embodiment, the pre-trained segmentation model can model a text sequence and capture long-distance dependencies through a self-attention mechanism to achieve the purpose of text segmentation.

[0062] In this step, for a target paragraph text with a length greater than the second length, the target paragraph text can be segmented again by using a pre-trained segmentation model to obtain a sentence text corresponding to the target paragraph text.

[0063] S203, for each sentence text, when the length of the sentence text is greater than the second length, the sentence text is recursively segmented in sequence according to a plurality of pre-set punctuation marks until the length of the segmented character segment is less than or equal to the second length.

[0064] It should be noted that the plurality of pre-set punctuation marks are set according to actual needs, and are not limited in this embodiment. For example, in a possible implementation, the plurality of pre-set punctuation marks include a period, a comma, a semicolon, an exclamation point, a question mark, a space, and a null character.

[0065] In combination with the above example, in actual implementation, for the sentence text with a length greater than the second length, the sentence text is first split by using a period. It should be noted that after the sentence text is split by using the period, the length of the obtained character segment can be less than or equal to the second length, or greater than the second length. The character segment less than or equal to the second length is a required character segment, and the character segment greater than the second length does not meet the requirement and is further split by using a comma. In this way, the character segments are split until all the split character segments are less than or equal to the second length.

[0066] S204, determining the paragraph text less than or equal to the second length in the plurality of paragraph texts, the sentence text less than or equal to the second length in the sentence texts, and the split character segment as the plurality of split segments corresponding to the reference text.

[0067] As introduced above, it can be understood that after the reference text is split according to the preset regular expression by using step S201, the plurality of paragraph texts obtained include paragraph texts less than or equal to the second length and paragraph texts greater than the second length. For the paragraph text less than or equal to the second length, the paragraph text can be directly used as a split segment corresponding to the reference text. For the paragraph text greater than the second length, the paragraph text is further split by using step S202 and a split model to obtain a plurality of sentence texts. It can be understood that similarly, the plurality of sentence texts include sentence texts less than or equal to the second length and sentence texts greater than the second length. For the sentence text less than or equal to the second length, the sentence text can be directly used as a split segment corresponding to the reference text. For the sentence text greater than the second length, the sentence text is further recursively split according to a plurality of punctuation marks in sequence by using step S203 to obtain a plurality of character segments. As introduced in step S203, the character segments obtained by recursively splitting the sentence text according to the plurality of punctuation marks are all less than or equal to the second length, and the character segments can be directly used as split segments corresponding to the reference text.

[0068] In summary, in this step, the paragraph text less than or equal to the second length in the plurality of paragraph texts, the sentence text less than or equal to the second length in the sentence texts, and the split character segment are determined as the plurality of split segments corresponding to the reference text.

[0069] It can be understood that the regular segmentation method is suitable for text with fixed format, and for different sources of text, since they usually have different formats, independent regular expressions need to be designed for different sources of text, which is not only time-consuming and laborious, but also difficult to achieve ideal results. Although the model segmentation method is suitable for long text segmentation, the model segmentation method needs a large amount of data for training, and the segmentation effect depends on the quality and quantity of the data set. The method provided in the embodiment combines the two segmentation methods of regular segmentation and model segmentation when segmenting the reference text, and can be adapted according to the length of the input window of the retrieval model and the length of the input window of the large model, dynamically adjusting the segmentation result, and adapting to reference texts of different sources.

[0070] FIG. 3 is a flowchart of an embodiment of the answer generation method provided in the present application. Referring to FIG. 3, the method provided in the present embodiment, on the basis of the above embodiments, comprises:

[0071] S301, sorting the plurality of segmentation fragments in descending order of the relevance values, to obtain a sorting result.

[0072] For example, in a possible implementation, the plurality of segmentation fragments corresponding to the reference text includes 10 segmentation fragments, for the convenience of description, the 10 segmentation fragments are respectively denoted as segmentation fragment 1, segmentation fragment 2, segmentation fragment 3, segmentation fragment 4, …, segmentation fragment 10, the lengths of the 10 segmentation fragments and the relevance values corresponding to the question are shown in Table 1: Table 1 Lengths of segmentation fragments and relevance values corresponding to questions Segmentation fragment Length of segmentation fragment Relevance value corresponding to question Segmentation fragment 1 A10.85 Segmentation fragment 2 A20.7 Segmentation fragment 3 A30.9 Segmentation fragment 4 A40.55 Segmentation fragment 5 A50.42 Segmentation fragment 6 A60.77 Segmentation fragment 7 A70.65 Segmentation fragment 8 A80.92 Segmentation fragment 9 A90.88 Segmentation fragment 10 A100.6

[0073] In combination with the example shown in Table 1, in this step, the 10 segmentation fragments are sorted in descending order of the relevance values, and the sorting result obtained is: segmentation fragment 8 (0.92), segmentation fragment 3 (0.9), segmentation fragment 9 (0.88), segmentation fragment 1 (0.85), segmentation fragment 6 (0.77), segmentation fragment 2 (0.7), segmentation fragment 7 (0.65), segmentation fragment 10 (0.6), segmentation fragment 4 (0.55), segmentation fragment 5 (0.42).

[0074] S302, select N split segments as the plurality of target split segments from the sorting result in the order from front to back; wherein the N is the maximum value j that meets the preset condition, and the preset condition is that the sum of the lengths of all split segments from the first split segment to the jth split segment is less than or equal to the difference value.

[0075] It should be noted that N is the maximum value j that meets the preset condition, and N is an integer, and further, the preset condition is that the sum of the lengths of all split segments from the first split segment to the jth split 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 question.

[0076] In other words, N can be represented by the following formula:

[0077] Wherein, len(t i ) is the length of the ith split segment;

[0078] L2 is the first length of the input window of the large model;

[0079] len(Q) is the third length of the question.

[0080] In a specific implementation, in combination with the example in step S301, in this step, the split segment 8 is first taken out from the sorting result in the order from front to back, and it is judged whether the length of the split segment 8 is greater than the difference between the first length of the input port of the large model and the third length of the question, if not, the split segment 3 is taken out from the sorting result again, until the total length of all taken out split segments is greater than the difference between the first length of the input window of the large model and the third length of the question. It should be noted that when the total length of all taken out split segments is greater than the difference between the first length of the input window of the large model and the third length of the question, the last taken out split segment is removed, and the remaining split segments are the plurality of target split segments.

[0081] For example, in combination with the example shown in Table 1, in a possible implementation, the sum of the lengths of all split segments from the first split segment to the fifth split segment is less than the difference value, and after the sixth split segment is taken out, the sum of the lengths of all split segments from the first split segment to the sixth split segment is greater than the difference value, at this time, N is equal to 5, and the first split segment to the fifth split segment is the target split segment.

[0082] The method provided in this embodiment can ensure that the split segments most related to the question are selected to the greatest extent, maximize the use of relevant information in the reference text, reduce information loss and redundancy, enable the large model to reason and generate answers from more complete and relevant reference content, and further improve the accuracy of reasoning.

[0083] FIG. 4 is a flowchart of an embodiment four of the answer generation method provided in the application. Referring to FIG. 4, the method provided in this embodiment, on the basis of the above embodiments, comprises:

[0084] S401. Find a plurality of candidate split segments with a relevance value greater than a preset threshold from the plurality of split segments.

[0085] Specifically, the preset threshold is set according to actual needs, which is not limited in this embodiment. For example, in one possible implementation, the preset threshold is 0.8.

[0086] In combination with the above example, in this step, the split segments with a relevance value greater than 0.8 are found from the plurality of split segments, and the found split segments are the candidate split segments.

[0087] In combination with the example shown in Table 1, in this step, the plurality of candidate split segments found are: split segment 8 (0.92), split segment 3 (0.9), split segment 9 (0.88), and split segment 1 (0.85).

[0088] S402. When the total length of the plurality of candidate split segments is less than or equal to the difference value, determine the plurality of candidate split segments as the plurality of target split segments.

[0089] Referring to the foregoing description, the total length of the plurality of target split 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 question. In this step, if the total length of the plurality of candidate split segments found is less than the above difference, the plurality of candidate split segments can be directly used as the plurality of target split segments to be input into the large model.

[0090] S403. When the total length of the plurality of candidate split segments is greater than the difference value, select the plurality of target split segments from the plurality of candidate split segments.

[0091] It should be noted that when the total length of the plurality of alternative segmented segments is greater than the difference value, it indicates that the plurality of alternative segmented segments still exceeds the range that can be processed by the large model at one time, at this time, the plurality of target segmented segments need to be selected from the plurality of alternative segmented segments.

[0092] For example, in a possible implementation, one alternative segmented segment can be randomly removed, and then it is judged whether the total length of the remaining alternative segmented segments is greater than the difference value. When the total length of the remaining alternative segmented segments is not greater than the difference value, the remaining alternative segmented segments are determined as the plurality of target segmented segments. When the total length of the remaining alternative segmented segments is greater than the difference value, one alternative segmented segment is continuously removed until the total length of the remaining alternative segmented segments is less than the difference value.

[0093] For another example, in another possible implementation, a certain alternative segmented segment of the plurality of alternative segmented segments can be removed in order of the relevance value from small to large until the total length of the remaining alternative segmented segments is less than the difference value. In this way, the remaining alternative segmented segments are the target segmented segments. For example, in another possible implementation, when the total length of the plurality of alternative segmented segments is greater than the difference value, the alternative segmented segment with the smallest relevance value in the plurality of alternative segmented segments is removed. It is judged whether the total length of the remaining plurality of alternative segmented segments is greater than the difference value. If not, the remaining alternative segmented segments are the target segmented segments. If yes, the alternative segmented segment with the smallest relevance value in the remaining plurality of alternative segmented segments is continuously removed until the total length of the remaining alternative segmented segments is less than the difference value.

[0094] For another example, in another possible implementation, a certain alternative segmented segment of the plurality of alternative segmented segments can be removed in order of the length from small to large until the total length of the remaining alternative segmented segments is less than the difference value.

[0095] The method provided in this embodiment can ensure that the selected target segmented segments are all segmented segments related to the question, avoid the interference of irrelevant information on reasoning, effectively reduce redundant information and invalid reasoning in the reasoning process, and enable the large model to concentrate on processing key content, thereby improving the accuracy and efficiency of reasoning.

[0096] Corresponding to the foregoing embodiment of the answer generation method, the present application also provides an embodiment of an answer generation device.

[0097] The embodiment of the answer generation device provided by the present application can be applied to an answer generation equipment. The device embodiment can be realized by software, or realized by hardware or a combination of software and hardware. Taking software realization as an example, as a logical device, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory for running by the processor of the answer generation equipment where the device is located. From the hardware level, as shown in FIG. 5, it is a hardware structure diagram of the answer generation equipment where the answer generation device provided by the present application is located. In addition to the processor, memory, network interface, and non-volatile memory shown in FIG. 5, the answer generation equipment where the device is located in the embodiment can also include other hardware according to the actual function of the answer generation device, and details are not repeated here.

[0098] FIG. 6 is a structural schematic diagram of an embodiment of the answer generation device provided by the present application. Please refer to FIG. 6, the device provided by the present embodiment includes a segmentation module 610, a calculation module 620, a selection module 630, and an output module 640; wherein,

[0099] The segmentation module 610 is configured to, in response to a question input by a user and reference text related to the question, segment the reference text when the length of the reference text is greater than a first length of an input window of a large model, to obtain a plurality of segmented segments corresponding to the reference text; wherein the length of each segmented segment in the plurality of segmented segments is less than a second length of an input window of a pre-trained retrieval model.

[0100] The calculation module 620 is configured to, for each segmented segment, calculate a relevance value of the each segmented segment with respect to the question by using the retrieval model.

[0101] The selection module 630 is configured to select a plurality of target segmented segments from the plurality of segmented segments according to the relevance value of each segmented segment with respect to the question; wherein the total length of the plurality of target segmented segments is less than or equal to the difference between the first length and a third length of the question.

[0102] The output module 640 is configured to obtain an answer to the question by using the large model according to the plurality of target segmented segments.

[0103] The device of the present embodiment can be used to execute the steps of the method embodiment shown in FIG. 1, and the specific implementation principle and implementation process are similar, which will not be repeated here.

[0104] The segmentation module 610 is specifically configured to:

[0105] split the reference text according to a preset regular expression to obtain a plurality of paragraph texts corresponding to the reference text;

[0106] For a target paragraph text in the plurality of paragraph texts, a pre-trained segmentation model is used to segment the target paragraph text to obtain a sentence text corresponding to the target paragraph text; wherein the target paragraph text is a paragraph text in the plurality of paragraph texts whose length is greater than the second length;

[0107] For each sentence text, when the length of the sentence text is greater than the second length, the sentence text is sequentially segmented according to a plurality of preset punctuation symbols until the length of the segmented character segment is less than or equal to the second length;

[0108] The paragraph texts in the plurality of paragraph texts whose length is less than or equal to the second length, the sentence texts in the plurality of sentence texts whose length is less than or equal to the second length, and the segmented character segments are determined as a plurality of segmentation segments corresponding to the reference text.

[0109] The selection module 630 is specifically configured to:

[0110] The plurality of segmentation segments are sorted according to the relevance values from large to small to obtain a sorting result;

[0111] According to the sorting result, N segmentation segments are selected as the plurality of target segmentation segments in the order from front to back; wherein the N is a maximum value j that satisfies a preset condition, and the preset condition is that the sum of the lengths of all segmentation segments from the first segmentation segment to the jth segmentation segment is less than or equal to the difference value.

[0112] The selection module 630 is specifically configured to:

[0113] From the plurality of segmentation segments, a plurality of candidate segmentation segments with a relevance value greater than a preset threshold value are searched;

[0114] When the total length of the plurality of candidate segmentation segments is less than or equal to the difference value, the plurality of candidate segmentation segments are determined as the plurality of target segmentation segments;

[0115] When the total length of the plurality of candidate segmentation segments is greater than the difference value, the plurality of target segmentation segments are selected from the plurality of candidate segmentation segments.

[0116] The output module 640 is specifically configured to splice the plurality of target segmentation segments and the question to obtain a splicing result, and input the splicing result into the large model to perform inference by the large model to output an answer to the question.

[0117] The output module 640 is specifically configured to concatenate the plurality of target split segments and the question by using a line break to obtain a concatenation result.

[0118] Optionally, the plurality of preset punctuation marks include a period, a comma, a semicolon, an exclamation mark, a question mark, a space, and a null character.

[0119] Please continue to refer to FIG. 5, the present application also provides an answer generation device, comprising a memory, a processor and a computer program stored on the memory and executable on the processor, when the processor executes the program, the steps of any method provided in the first aspect of the present application are implemented.

[0120] The present application also provides a computer readable storage medium, which stores a computer program, when the program is executed by a processor, the steps of any method provided in the present application are implemented.

[0121] The implementation process of the functions and roles of each unit in the above device is specifically described in the implementation process of the corresponding steps in the above method, which will not be repeated here.

[0122] For the device embodiment, since it basically corresponds to the method embodiment, the related parts are described in the part of the method embodiment. The above described device embodiment is only illustrative, and the units described as separate components can be or can not be physically separated, and the components displayed as units can be or can not be physical units, that is, they can be located in one place, or can be distributed on multiple network units. According to actual needs, part or all of the modules can be selected to achieve the purpose of the present application. Those skilled in the art can understand and implement without creative labor.

[0123] The above is only the preferred embodiment of the present application, and does not limit the present application. Any modification, equivalent replacement, improvement, etc. within the spirit and principles of the present application should be included in the scope of protection of the present application.

Claims

1. An answer generation method, characterized by, The method comprises: in response to a question input by a user and reference text related to the question, when a length of the reference text is greater than a first length of an input window of a large model, the reference text is segmented to obtain a plurality of segmented segments corresponding to the reference text, wherein a length of each segmented segment in the plurality of segmented segments is less than a second length of an input window of a pre-trained retrieval model; for each segmented segment, a relevance value of the each segmented segment relative to the question is calculated using the retrieval model; according to the relevance value of each segmented segment relative to the question, a plurality of target segmented segments are selected from the plurality of segmented segments, wherein a total length of the plurality of target segmented segments is less than or equal to a difference between the first length and a third length of the question; an answer to the question is obtained using the large model according to the plurality of target segmented segments.

2. The method of claim 1, wherein, The segmentation of the reference text to obtain the plurality of segmented segments corresponding to the reference text comprises: segmenting the reference text according to a preset regular expression to obtain a plurality of paragraph texts corresponding to the reference text; for a target paragraph text in the plurality of paragraph texts, the target paragraph text is segmented using a pre-trained segmentation model to obtain a sentence text corresponding to the target paragraph text, wherein the target paragraph text is a paragraph text in the plurality of paragraph texts with a length greater than the second length; for each sentence text, when a length of the sentence text is greater than the second length, the sentence text is recursively segmented according to a plurality of preset punctuation symbols in sequence until a length of a segmented character segment is less than or equal to the second length; the paragraph texts in the plurality of paragraph texts with lengths less than or equal to the second length, the sentence texts in the plurality of sentence texts with lengths less than or equal to the second length, and the segmented character segments are determined as the plurality of segmented segments corresponding to the reference text.

3. The method of claim 1, wherein, The selection of the plurality of target segmented segments from the plurality of segmented segments according to the relevance value of each segmented segment relative to the question comprises: the plurality of segmented segments are sorted according to relevance values in descending order to obtain a sorting result; N segmented segments are selected from the sorting result as the plurality of target segmented segments in a front-to-back order, wherein N is a maximum value j that satisfies a preset condition, and the preset condition is that a sum of lengths of all segmented segments from a first segmented segment to the jth segmented segment is less than or equal to the difference.

4. The method of claim 1, wherein, The selection of the plurality of target segmented segments from the plurality of segmented segments according to the relevance value of each segmented segment relative to the question comprises: a plurality of candidate segmented segments with relevance values greater than a preset threshold value are searched from the plurality of segmented segments; when a total length of the plurality of candidate segmented segments is less than or equal to the difference, the plurality of candidate segmented segments are determined as the plurality of target segmented segments; When a total length of the plurality of candidate split segments is greater than the difference value, the plurality of target split segments are selected from the plurality of candidate split segments.

5. The method of claim 1, wherein, The obtaining of the answer to the question by using the large model according to the plurality of target split segments comprises: The plurality of target split segments and the question are spliced to obtain a splicing result. The splicing result is input into the large model to perform reasoning by the large model, and an answer to the question is output.

6. The method of claim 5, wherein, The splicing of the plurality of target split segments and the question to obtain a splicing result comprises: The plurality of target split segments and the question are spliced by using a line break to obtain a splicing result.

7. The method of claim 2, wherein, The plurality of preset punctuation symbols comprise a period, a comma, a semicolon, an exclamation mark, a question mark, a space, and a null character.

8. An answer generation apparatus characterized by comprising: The device comprises a splitting module, a calculating module, a selecting module, and an output module; wherein, The splitting module is configured to, in response to a question input by a user and a reference text related to the question, split the reference text when a length of the reference text is greater than a first length of an input window of a large model, to obtain a plurality of split segments corresponding to the reference text; wherein a length of each split segment in the plurality of split segments is less than a second length of an input window of a pre-trained retrieval model; The calculating module is configured to, for each split segment, calculate a relevance value of the each split segment with respect to the question by using the retrieval model; The selecting module is configured to select a plurality of target split segments from the plurality of split segments according to the relevance value of each split segment with respect to the question; wherein a total length of the plurality of target split segments is less than or equal to a difference value between the first length and a third length of the question; The output module is configured to obtain an answer to the question by using the large model according to the plurality of target split segments.

9. An answer generation apparatus characterized by comprising: A computer program product comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the method according to any one of claims 1-7 when executing the program.

10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the processor to implement 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

  • Paragraph segmentation method and question answering system and method for RAG model

    CN118153527A

  • Answer generation method, device and equipment

    CN118861244A

  • Answer generation method and apparatus based on artificial intelligence, and computer device and medium

    WO2022105122A1