Intelligent question and answer method and related device

By using multi-grained slicing and multi-label search technology in the intelligent question and answer system, vectors of questions and document fragments are determined and answered, the problem of poor answer accuracy and reliability in the existing intelligent question and answer methods is solved, and more efficient information retrieval and answer generation are achieved.

CN119577095APending Publication Date: 2025-03-07IFLYTEK CO LTD +2
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202411703340.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-26
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

The existing intelligent question-and-answer method based on search enhanced generation (RAG) technology has poor accuracy and reliability of generated answers due to various reasons.

Method used

By obtaining the user-entered question and target documents, determine the vectors of the question and document fragments, determine the candidate text fragments based on the vector similarity, and generate the answers. This method adopts a multi-grained slicing strategy based on document structure, combining multi-label search and long text fusion search to enhance generation technology.

Benefits of technology

Without losing the completeness of the original document information, we can achieve more efficient analysis and analysis of the target document and improve the accuracy and reliability of the answers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119577095A_ABST
    Figure CN119577095A_ABST
Patent Text Reader

Abstract

The invention discloses an intelligent question and answer method and a related device, and relates to the technical field of natural language processing, and the method comprises the steps: obtaining a question input by a user and a target document corresponding to the question; the method comprises the following steps: firstly, determining a vector of a problem and vectors of a plurality of text fragments corresponding to a target document, wherein the plurality of text fragments corresponding to the target document are obtained by segmenting the target document from a plurality of granularities based on a document structure; on the basis of the similarity between the vector of the problem and vectors of a plurality of text segments corresponding to the target document, candidate text segments are determined; and finally, based on the candidate text fragments, generating answers corresponding to the questions. According to the method and the device, through the multi-granularity segmentation strategy based on the document structure, the target document can be more efficiently analyzed and analyzed in the subsequent steps on the premise that the integrity of original text information of the target document is not lost, so that information related to the question can be more accurately retrieved, and the accuracy and the reliability of answers are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of natural language processing technology, and in particular to an intelligent question-answering method and related devices. Background Art

[0002] Intelligent question and answer usually refers to users inputting questions into intelligent devices, which then generate and output answers corresponding to the user's questions. Intelligent question and answer based on document libraries is a common task scenario in the field of intelligent question and answer. In this scenario, document libraries are built for different fields, and users can ask questions. The artificial intelligence model retrieves information related to the questions from the document library, and then uses the retrieved information to generate answers corresponding to the questions. Intelligent question and answer based on documents is another common task scenario in the field of intelligent question and answer. In this scenario, users input documents into the artificial intelligence model, and then input questions about the documents. The artificial intelligence model needs to parse the documents input by the user, extract information used to answer the user's questions, and then generate answers corresponding to the user's questions based on the extracted information.

[0003] Regardless of the scenario, considering the hallucination problem and input length limit of the artificial intelligence model, the retrieval-augmented generation (RAG) technology is often used to implement intelligent question and answer. The way to implement intelligent question and answer using retrieval-augmented generation technology is to have the artificial intelligence model retrieve information related to the question from the document library or the documents provided by the user, and then use the retrieved information to generate the answer corresponding to the question. However, the current method of implementing intelligent question and answer based on retrieval-augmented generation (RAG) technology has poor accuracy and reliability in generating answers due to various reasons.

[0004] Therefore, how to provide an intelligent question-answering method to improve the accuracy and reliability of answers has become a technical problem that needs to be urgently solved by technical personnel in this field. Summary of the invention

[0005] In view of the above problems, this application provides an intelligent question-answering method and related devices to achieve the purpose of improving the accuracy and reliability of answers. The specific scheme is as follows:

[0006] The first aspect of the present application provides an intelligent question-answering method, comprising:

[0007] Obtain the question input by the user and the target document corresponding to the question;

[0008] Determine a vector of the question and vectors of a plurality of text segments corresponding to the target document, wherein the plurality of text segments corresponding to the target document are obtained by segmenting the target document at a plurality of granularities based on the document structure;

[0009] Determining candidate text segments based on the similarity between the vector of the question and the vectors of the plurality of text segments corresponding to the target document;

[0010] Based on the candidate text segments, an answer corresponding to the question is generated.

[0011] In a possible implementation, the method of generating vectors of the multiple text segments corresponding to the target document includes:

[0012] Segmenting the target document at multiple granularities based on the document structure to obtain multiple text segments, each of which includes a segmentation granularity label;

[0013] For each text fragment, the text fragment is input into a pre-trained vector representation model to generate a vector of the text fragment. The vector representation model is obtained by contrasting and learning an initial vector representation model with multiple training data triplets. Each of the training data triplet includes a problem sample, a positive example of a text fragment sample corresponding to the problem sample, and a negative example of a text fragment sample corresponding to the problem sample.

[0014] In a possible implementation, the target document is segmented at multiple granularities based on the document structure to obtain multiple text segments, including:

[0015] Performing information extraction and chapter recognition processing on the target document to obtain a processed target document;

[0016] The processed target document is segmented at multiple granularities based on the document structure to obtain multiple text segments.

[0017] In a possible implementation, the vector representation model is trained as follows:

[0018] Obtain a pre-constructed training data set; the training data set includes a plurality of training data triplets, each training data triplet includes a problem sample, a positive example of a text segment sample corresponding to the problem sample, and a negative example of a text segment sample corresponding to the problem sample;

[0019] With the training objectives of shortening the distance between the vector of the problem sample and the vector of the positive text fragment sample corresponding to the problem sample, and increasing the distance between the vector of the problem sample and the vector of the negative text fragment sample corresponding to the problem sample, the initial vector representation model is trained by comparative learning to obtain a trained vector representation model.

[0020] In a possible implementation, the multiple granularities include at least two granularities of page-level granularity, chapter-level granularity, paragraph-level granularity, and fixed-length-level granularity.

[0021] In a possible implementation, determining the vector of the problem includes:

[0022] The question is input into the vector representation model to generate a vector of the question.

[0023] In a possible implementation, generating an answer corresponding to the question based on the candidate text segment includes:

[0024] Inputting the question and the candidate text fragment into a first answer generation model to generate an answer corresponding to the question, wherein the first answer generation model is a large language model fine-tuned based on the first training data;

[0025] Alternatively, the question, the target document and the candidate text fragment are input into a second answer generation model to generate an answer corresponding to the question, and the second answer generation model is a large language model obtained by fine-tuning based on the second training data.

[0026] A second aspect of the present application provides an intelligent question-answering device, comprising:

[0027] An acquisition unit, used to acquire a question input by a user and a target document corresponding to the question;

[0028] A vector determination unit, used to determine the vector of the question and the vectors of a plurality of text segments corresponding to the target document, wherein the plurality of text segments corresponding to the target document are obtained by segmenting the target document at a plurality of granularities based on the document structure;

[0029] A candidate text segment determination unit, configured to determine a candidate text segment based on the vector of the question and the similarity between the vectors of the plurality of text segments corresponding to the target document;

[0030] An answer generation unit is used to generate an answer corresponding to the question based on the candidate text segment.

[0031] In a possible implementation, the device further includes a text segment vector generating unit; the text segment vector generating unit includes:

[0032] A document segmentation unit, used for segmenting the target document at multiple granularities based on the document structure to obtain multiple text segments, each of which contains a segmentation granularity label;

[0033] The text fragment vector generation subunit is used to input each text fragment into a pre-trained vector representation model to generate a vector of the text fragment, wherein the vector representation model is obtained by performing comparative learning and training on an initial vector representation model through multiple training data triples, and each of the training data triples includes a problem sample, a positive example of a text fragment sample corresponding to the problem sample, and a negative example of a text fragment sample corresponding to the problem sample.

[0034] In a possible implementation, the document segmentation unit is specifically used to:

[0035] Performing information extraction and chapter recognition processing on the target document to obtain a processed target document;

[0036] The processed target document is segmented at multiple granularities based on the document structure to obtain multiple text segments.

[0037] In a possible implementation, the apparatus further includes: a vector representation model training unit, wherein the vector representation model training unit is specifically configured to:

[0038] Obtain a pre-constructed training data set; the training data set includes a plurality of training data triplets, each training data triplet includes a problem sample, a positive example of a text segment sample corresponding to the problem sample, and a negative example of a text segment sample corresponding to the problem sample;

[0039] With the training objectives of shortening the distance between the vector of the problem sample and the vector of the positive text fragment sample corresponding to the problem sample, and increasing the distance between the vector of the problem sample and the vector of the negative text fragment sample corresponding to the problem sample, the initial vector representation model is trained by comparative learning to obtain a trained vector representation model.

[0040] In a possible implementation, the multiple granularities include at least two granularities of page-level granularity, chapter-level granularity, paragraph-level granularity, and fixed-length-level granularity.

[0041] In a possible implementation, the vector determination unit is specifically configured to:

[0042] The question is input into the vector representation model to generate a vector of the question.

[0043] In a possible implementation, the answer generating unit includes:

[0044] Inputting the question and the candidate text fragment into a first answer generation model to generate an answer corresponding to the question, wherein the first answer generation model is a large language model fine-tuned based on the first training data;

[0045] Alternatively, the question, the target document and the candidate text fragment are input into a second answer generation model to generate an answer corresponding to the question, and the second answer generation model is a large language model obtained by fine-tuning based on the second training data.

[0046] The third aspect of the present application provides a computer program product, including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the intelligent question-answering method of the first aspect or any implementation method of the first aspect.

[0047] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:

[0048] The memory is used to store computer programs;

[0049] The processor is used to execute the computer program so that the electronic device can implement the intelligent question and answer method of the above-mentioned first aspect or any implementation method of the first aspect.

[0050] A fifth aspect of the present application provides a computer-readable storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the intelligent question-answering method of the above-mentioned first aspect or any implementation method of the first aspect.

[0051] By means of the above technical scheme, the intelligent question-answering method and related devices provided by the present application, after obtaining the question input by the user and the target document corresponding to the question; first determine the vector of the question and the vectors of multiple text fragments corresponding to the target document, the multiple text fragments corresponding to the target document are obtained by segmenting the target document from multiple granularities based on the document structure; then determine the candidate text fragments based on the similarity between the vector of the question and the vectors of multiple text fragments corresponding to the target document; finally, generate the answer corresponding to the question based on the candidate text fragments. In the present application, through the multi-granularity segmentation strategy based on the document structure, it is possible to achieve more efficient parsing and analysis of the target document in subsequent steps without losing the integrity of the original information of the target document, so as to more accurately retrieve information related to the question, thereby improving the accuracy and reliability of the answer. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.

[0053] Figure 1A flowchart of an intelligent question-answering method provided in an embodiment of the present application;

[0054] Figure 2 An example schematic diagram of a candidate text segment provided in an embodiment of the present application;

[0055] Figure 3 A schematic diagram of a flow chart of a method for generating vectors of multiple text segments corresponding to a target document provided in an embodiment of the present application;

[0056] Figure 4 A document segmentation schematic diagram provided for an embodiment of the present application;

[0057] Figure 5 A schematic diagram of the structure of an intelligent question-answering device provided in an embodiment of the present application;

[0058] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0059] The embodiments of the present application are described below in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation mode of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application. It is known to those skilled in the art that with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0060] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0061] To facilitate understanding, we first introduce the existing intelligent question-answering technology based on question-answering, as follows:

[0062] Intelligent question and answer usually refers to users inputting questions into smart devices, and the smart devices generating and outputting answers corresponding to the user's questions.

[0063] Intelligent question answering based on document libraries is a common task scenario in the field of intelligent question answering. In this scenario, document libraries are built for different fields, and users can ask questions. The artificial intelligence model retrieves information related to the question from the document library, and then uses the retrieved information to generate answers corresponding to the question.

[0064] Document-based intelligent question answering is another common task scenario in the field of intelligent question answering. In this scenario, the user inputs a document to the artificial intelligence model, and then inputs a question about the document. The artificial intelligence model needs to parse the document input by the user, extract information used to answer the user's question, and then generate an answer corresponding to the user's question based on the extracted information.

[0065] Exemplarily, the above-mentioned smart device can be any terminal device such as a smart handheld terminal, a server, a smart wearable device, a smart computer, a smart customer service terminal, etc. that is installed with the above-mentioned artificial intelligence model, can receive user input and generate and output information.

[0066] The above-mentioned artificial intelligence model can be a model trained based on any neural network model for performing intelligent question-answering tasks. Alternatively, the above-mentioned artificial intelligence model can also be a large language model (Large Language Model, LLM).

[0067] Regardless of the scenario, considering the hallucination problem and input length limitation of the artificial intelligence model, retrieval-augmented generation (RAG) technology is often used to achieve intelligent question and answer. The way to achieve intelligent question and answer using retrieval-augmented generation technology is that the artificial intelligence model retrieves information related to the question from the document library or documents provided by the user, and then uses the retrieved information to generate an answer corresponding to the question.

[0068] At present, the method of implementing intelligent question answering using retrieval-augmented generation (RAG) technology usually adopts a fixed-block method to cut documents into fixed-length segments for retrieval and processing. Although this method is simple and easy to implement, it is prone to semantic incompleteness and information loss. Since the fixed-block method ignores the sentence and paragraph boundaries in natural language, it may separate related information, resulting in the inability to fully capture the key information in the document when generating answers. In addition, important contextual information may be cut into different segments and cannot be fully utilized in the answer generation stage, which ultimately affects the accuracy and reliability of the generated answers.

[0069] In addition, the current method of implementing intelligent question answering using retrieval-augmented generation (RAG) technology usually uses a unified semantic vector to represent questions and documents. Although this approach simplifies the calculation and implementation of the model to a certain extent, it also has significant limitations. Especially when dealing with different types of questions, due to the lack of careful consideration of the question type, the model cannot flexibly adjust the vector representation to adapt to different question requirements, which may lead to inaccurate capture of question details and intent, and ultimately affect the accuracy and reliability of the generated answers.

[0070] In addition, the current method of using retrieval-augmented generation (RAG) technology to implement intelligent question and answer usually only splices the question and retrieval results into a large model for answer generation. The retrieval results usually have problems with redundant, missing, and incoherent information. Directly splicing all retrieval results into the artificial intelligence model may cause the generated answers to contain irrelevant information or even erroneous information, thus affecting the accuracy and reliability of the answers.

[0071] It can be seen that the current method of using retrieval-augmented generation (RAG) technology to achieve intelligent question answering has poor accuracy and reliability in generating answers due to the above reasons.

[0072] In order to solve the above problems, an embodiment of the present application provides an intelligent question-answering method.

[0073] The intelligent question-answering method provided in this application also adopts the retrieval enhancement generation (RAG) technology. The retrieval enhancement generation technology of this application is mainly divided into three parts: dynamic multi-granularity segmentation, multi-label retrieval, and long text fusion retrieval enhancement generation. Among them, dynamic multi-granularity segmentation flexibly divides the original document into page level, chapter level, paragraph level, and fixed length level according to the structure of the document content. This segmentation method not only takes into account the natural hierarchical structure of the document, but also retains the coherence and integrity of the information at each granularity level. Multi-label retrieval assigns different labels to each text fragment. When the user asks a question, the retrieval system can match the question more finely based on these labels, ensuring that not only the main topic of the question can be captured, but also its context and multi-level needs can be taken into account, thereby improving the relevance and accuracy of the retrieval results, so that the user's question can better match the corresponding knowledge. Long text fusion retrieval enhancement generation inputs the original document, retrieval fragments and user questions into the large model together, so that the generated content of the large model is more focused. Based on the above, the intelligent question-answering method provided in this application can ensure the accuracy and reliability of the generated answers.

[0074] The intelligent question and answer method provided in this application can be applied to the above-mentioned smart devices so that the smart devices can respond to intelligent questions and answers more quickly and accurately. Alternatively, the above-mentioned scheme can also be applied to any other intelligent question and answer scenarios based on the above-mentioned artificial intelligence model, so that the artificial intelligence model can respond to intelligent questions and answers more efficiently.

[0075] In the subsequent embodiments of this specification, the intelligent question and answer scenario based on a large language model is taken as an example to exemplify the intelligent question and answer solution proposed in this application. When the intelligent question and answer solution proposed in this application is applied to intelligent question and answer scenarios of other types of artificial intelligence models or to other intelligent question and answer devices, its specific processing process can be executed with reference to the introduction of each embodiment of this specification.

[0076] The intelligent question-answering method of the embodiment of the present application is described in detail below with reference to the accompanying drawings.

[0077] Reference Figure 1 , Figure 1 A flowchart of an intelligent question-answering method provided in an embodiment of the present application is shown in FIG. Figure 1 As shown, an intelligent question-answering method provided in an embodiment of the present application may include the following steps, which are described in detail below.

[0078] S101: Acquire a question input by a user and a target document corresponding to the question;

[0079] In a possible implementation, in this application, the target document refers to a document input by a user in a document-based intelligent question-answering scenario, and the document can be a document of any length, any content, any format, and any number. The question corresponding to the target document refers to the question that the user hopes to answer based on the target document. The question can be the first question raised in the corresponding target document, or it can be the Nth question, where N is greater than or equal to 2.

[0080] For ease of understanding, for example, in a document-based intelligent question-answering scenario, the user can enter multiple academic papers by author A and the question "Please summarize the academic research results of author A based on the above papers." Then, the above academic papers correspond to the above target documents, and the question "Please summarize the academic research results of author A based on the above papers" corresponds to the above target document.

[0081] Generally speaking, in document-based intelligent question answering, which is another common task scenario in the field of intelligent question answering, in the intelligent question answering scenario, the user interacts with the large language model through a conversation window, that is, the user inputs information in the conversation window, and at the same time, the large language model also outputs response information in the conversation window, and the user and the large language model realize question and answer through dialogue in the conversation window.

[0082] In the above conversation window, the user can choose to input one or more documents at any time when inputting information, and at the same time input the question that needs to be answered by the large language model, and then instruct the large language model to answer the input question based on the input one or more documents.

[0083] In another possible implementation, in the present application, the target document refers to all or part of the documents in the document library in the intelligent question-answering scenario based on the document library.

[0084] Correspondingly, the processor or controller used to control the large language model for intelligent question answering first obtains the question input by the user and the target document corresponding to the question, and then performs subsequent processing based on the question input by the user and the target document corresponding to the question.

[0085] S102: Determine a vector of the question and vectors of a plurality of text segments corresponding to the target document, wherein the plurality of text segments corresponding to the target document are obtained by segmenting the target document at a plurality of granularities based on the document structure;

[0086] In this application, if the intelligent question-answering scenario is a document-based intelligent question-answering scenario, and the question is the first question asked by the user, it is necessary to generate the vector of the question and the vectors of multiple text fragments corresponding to the target document in real time. In this application, if the intelligent question-answering scenario is a document library-based intelligent question-answering scenario, or if the intelligent question-answering scenario is a document-based intelligent question-answering scenario, but the question is not the first question asked by the user, the vectors of multiple text fragments corresponding to the target document generated and stored first can be directly obtained, and it is only necessary to generate the vector of the question in real time. This application does not impose any restrictions on this.

[0087] In a possible implementation, the multiple granularities may include at least two granularities of page-level granularity, chapter-level granularity, paragraph-level granularity, and fixed-length-level granularity.

[0088] In a possible implementation, each text segment contains a segmentation granularity label corresponding to the text segment. In a possible implementation, in a possible implementation, you can use <page> 、 <para> 、 <section> 、 <chunk>It represents "page level granularity", "paragraph level granularity", "chapter level granularity", and "fixed length level granularity". In this application, the vector of the text segment can represent the segmentation granularity and semantic information of the text segment.

[0089] In traditional solutions, a fixed block method is usually used to cut documents into fixed-length segments for retrieval and processing. Although this method is simple and easy to implement, it is prone to semantic incompleteness and information loss. Since the fixed block method ignores the sentence and paragraph boundaries in natural language, it may separate related information, resulting in the inability to fully capture the key information in the document when generating answers. In addition, important contextual information may be cut into different segments and cannot be fully utilized in the answer generation stage, ultimately affecting the accuracy and reliability of the generated answers.

[0090] In the present application, through this multi-granularity segmentation strategy based on document structure, the target document can be parsed and analyzed more efficiently in subsequent steps without losing the integrity of the original information of the target document, so as to more accurately retrieve information related to the question, thereby improving the accuracy and reliability of the answer.

[0091] S103: Determine candidate text segments based on the similarity between the vector of the question and the vectors of the plurality of text segments corresponding to the target document;

[0092] In the present application, the similarity can be any similarity, such as cosine similarity, Euclidean distance, Manhattan distance, etc., and the present application does not impose any limitation on this. The candidate text segment can be a text segment whose vector similarity with the vector of the question satisfies a preset condition among the multiple text segments corresponding to the target document, such as TopK, where K is an integer greater than or equal to 1, and for example, greater than a preset threshold, and the present application does not impose any limitation on this.

[0093] For ease of understanding, refer to Figure 2 , Figure 2 This is a schematic diagram of an example of a candidate text segment provided in an embodiment of the present application. Figure 2 As shown in the figure, the candidate text fragments corresponding to the question query "What is the main content of the paper" are shown on the right side of the figure, and different candidate text fragments correspond to different segmentation granularity labels.

[0094] S104: Generate an answer corresponding to the question based on the candidate text segments.

[0095] In one possible implementation, the answer corresponding to the question can be generated based on the question and the candidate text fragments. Considering that generating the answer corresponding to the question based only on the question and the candidate text fragments may cause the generated answer to contain irrelevant information, or even erroneous information, thereby affecting the accuracy and reliability of the answer. Therefore, in the present application, in another achievable manner, the answer corresponding to the question can be generated based on the question, the target document, and the candidate text fragments. In this implementation, the answer can be made more focused while the information is complete, thereby ensuring the accuracy and reliability of the answer.

[0096] In another embodiment of the present application, a method for generating vectors of multiple text segments corresponding to a target document is described in detail. Figure 3 , Figure 3 A schematic flow chart of a method for generating vectors of multiple text segments corresponding to a target document provided in an embodiment of the present application, the method may include the following steps:

[0097] S201: Segment the target document at multiple granularities based on the document structure to obtain multiple text segments, each of which includes a segmentation granularity label;

[0098] In a preferred implementation, the multiple granularities may include four granularities: page-level granularity, chapter-level granularity, paragraph-level granularity, and fixed-length-level granularity.

[0099] It should be noted that segmenting the target document based on page-level granularity can retain the overall layout and paging information of the target document, making the subsequent processing process closer to the presentation of the original target document. Segmenting the target document based on chapter-level granularity helps to centrally process related content according to the logical structure of the target document, making it easy for the subsequent processing process to identify and extract chapter titles and their corresponding content. Segmenting the target document based on paragraph-level granularity can further refine the content organization of the target document, allowing the subsequent processing process to better understand the semantic relationship between paragraphs and the hierarchical structure of the content. Segmenting the target document based on fixed-length granularity is a general method suitable for processing documents without clear structural identifiers, ensuring that the size of text fragments is relatively uniform in all cases, thereby optimizing the processing effect of the subsequent processing process.

[0100] In order to improve the reliability of each text fragment, in this application, the target document is not segmented directly from multiple granularities based on the document structure. Instead, the target document is first subjected to information extraction and chapter recognition processing to obtain a processed target document, and then the processed target document is segmented from multiple granularities based on the document structure to obtain multiple text fragments.

[0101] For ease of understanding, taking the target document in PDF file format as an example, the information extraction and chapter recognition processing are as follows:

[0102] PDF files usually contain complex text layouts and multiple encoding methods. They contain not only text but also images, tables and other non-text elements. Therefore, parsing PDF files is a complex task. PDF files can be divided into ordinary text PDFs and scanned PDFs. The text content of ordinary text PDFs is stored in editable text form, while the text content of scanned PDFs is embedded in the PDF file in the form of pictures. Therefore, this application uses a combination of methods to extract information:

[0103] ① Text information extraction: For ordinary text PDFs, use the fitz tool to extract text, fonts, font sizes and other information from PDFs; for scanned PDFs, use OCR technology to convert text in images into editable text.

[0104] ②Chart information extraction: Use OCR technology to extract chart information.

[0105] The chapter and structure information in PDF files are usually not explicitly marked, especially in academic papers, books or reports, where chapter titles and content may be presented in different formats or styles. Therefore, in order to ensure the semantic integrity of text information, it is necessary to use chapter recognition technology to accurately divide documents into chapters. In a possible implementation, a sequence labeling model can be used in this application to perform chapter recognition, thereby effectively capturing the text structure and chapter information in the document.

[0106] For easier understanding, please refer to Figure 4 , Figure 4 A document segmentation diagram provided in an embodiment of the present application is as follows: Figure 4 As shown, after the document is segmented, multiple text fragments corresponding to different granularities are obtained.

[0107] S202: For each text fragment, input the text fragment into a pre-trained vector representation model to generate a vector for the text fragment, wherein the vector representation model is obtained by performing comparative learning and training on an initial vector representation model through multiple training data triples, and each of the training data triples includes a problem sample, a positive example of a text fragment sample corresponding to the problem sample, and a negative example of a text fragment sample corresponding to the problem sample.

[0108] In this application, the vector of the text fragment can represent the segmentation granularity and semantic information of the text fragment. In traditional solutions, a unified semantic vector is usually used to represent the text fragment. Although this approach simplifies the calculation and implementation of the model to a certain extent, it also has significant limitations, which may result in the inability to better match the user's question to the corresponding text fragment during retrieval, ultimately affecting the accuracy and reliability of the generated answer.

[0109] In the present application, since each text fragment contains a segmentation granularity label, the vector of the text fragment can well characterize the segmentation granularity and semantic information of the text fragment. Based on the vector of the text fragment, the user's questions can be more finely matched with each text fragment during retrieval, ensuring that not only the main topic of the question can be captured, but also its context and multi-level needs can be taken into account, so that the user's questions can be better matched with the corresponding text fragments, thereby improving the accuracy and reliability of the generated answers.

[0110] In the present application, for a document input by a user, or for each document in a document library, vectors of multiple text segments corresponding to the document can be generated and stored in the above manner.

[0111] In another embodiment of the present application, a training method of the vector representation model is described in detail, and the method may include the following steps:

[0112] S301: Acquire a pre-constructed training data set; the training data set includes a plurality of training data triplets, each training data triplet includes a problem sample, a positive example of a text segment sample corresponding to the problem sample, and a negative example of a text segment sample corresponding to the problem sample;

[0113] In order to train the vector representation model, you first need to construct a training dataset.

[0114] With the powerful semantic understanding and generation capabilities of the large language model, we first ask questions to document samples based on the large language model to generate multiple question samples; then we segment the document samples at multiple granularities based on the document structure to obtain multiple text fragment samples, each of which contains a segmentation granularity label. Finally, for each question sample, we search through the large language model to obtain the positive text fragment sample corresponding to the question sample and the negative text fragment sample corresponding to the question sample.

[0115] Based on the above, multiple training data can be constructed, and each training data can be represented by a triple: (question sample, text segment sample positive example, text segment sample negative example). The training data set can be obtained by combining various training data.

[0116] It should be noted that the specific implementation method of segmenting the document sample at multiple granularities based on the document structure to obtain multiple text segment samples can refer to the processing method of the target document, which will not be repeated here.

[0117] It should be noted that the number of positive examples of text segment samples and the number of negative examples of text segment samples can be determined based on scenario requirements and are not limited in this application. For example, the number of positive examples of text segment samples can be 1, and the number of negative examples of text segment samples can be 8.

[0118] S302: With the training objectives of shortening the distance between the vector of the problem sample and the vector of the positive text fragment sample corresponding to the problem sample, and increasing the distance between the vector of the problem sample and the vector of the negative text fragment sample corresponding to the problem sample, the initial vector representation model is subjected to comparative learning training to obtain a trained vector representation model.

[0119] For ease of understanding, shortening the distance between the vector of the problem sample and the vector of the positive text segment sample corresponding to the problem sample, and increasing the distance between the vector of the problem sample and the vector of the negative text segment sample corresponding to the problem sample are training goals, which can be expressed as the following loss function:

[0120]

[0121] in, and P′ represent the positive and negative examples of the text fragment samples of question q, and s(·) represents the similarity of the semantic vectors of two sentences.

[0122] Based on the above-mentioned vector representation model, determining the vector of the problem includes: inputting the problem into the vector representation model to generate the vector of the problem.

[0123] In another embodiment of the present application, a specific implementation method of generating an answer corresponding to the question based on the candidate text segment is described:

[0124] In a possible implementation, the question and the candidate text fragments may be input into a first answer generation model to generate an answer corresponding to the question, where the first answer generation model is a large language model fine-tuned based on first training data.

[0125] In this application, any large language model can be selected as the large language model, such as the iFlytek Spark large model. The fine-tuning method can be full-parameter fine-tuning or LoRA fine-tuning. The first training data includes question samples, candidate text segment samples, and corresponding answer labels. The first training data can be constructed by self-instruct, manual annotation, Internet crawling, etc. Taking self-instruct as an example, the steps to construct the first training data are as follows:

[0126] 1. Input document samples and construct document-related question samples using the self-instruct method;

[0127] 2. For each question sample, a candidate text segment sample is retrieved from the document sample;

[0128] 3. Input the question sample + candidate text fragment sample into the large language model to obtain the corresponding answer label.

[0129] Considering that only the question and search results are spliced ​​and input into a large model for answer generation, the search results usually have problems such as redundant, missing, and incoherent information. Directly splicing all search results into the artificial intelligence model may cause the generated answers to contain irrelevant information or even wrong information, thus affecting the accuracy and reliability of the answers.

[0130] Therefore, in the present application, in another achievable method, the question, the target document and the candidate text fragment can be input into a second answer generation model to generate an answer corresponding to the question, and the second answer generation model is a large language model obtained by fine-tuning based on the second training data.

[0131] In this implementation, the original document, search fragments and user questions are input into the big model together. Compared with inputting only questions and search results, the generated content of the big model can be more focused while the information is complete, thereby ensuring the correctness of the generated results.

[0132] In this implementation, any large language model can be selected as the large language model, such as the iFlytek Spark large model. The fine-tuning method can be full-parameter fine-tuning or LoRA fine-tuning. The second training data includes question samples, document samples, candidate text fragment samples, and corresponding answer labels. The second training data can be constructed by self-instruct, manual annotation, Internet crawling, etc. Taking self-instruct as an example, the steps to construct the second training data are as follows:

[0133] 1. Input document samples and construct document-related question samples using the self-instruct method;

[0134] 2. For each question sample, a candidate text segment sample is retrieved from the document sample;

[0135] 3. Input the question sample + document sample + candidate text fragment sample into the large language model to obtain the corresponding answer label.

[0136] In this application, a prompt can be generated using the question, the target document, and the candidate text segment, and the prompt is input into the second answer generation model to obtain the answer corresponding to the question. The prompt example is as follows:

[0137] This is a paper reading task, which requires answering corresponding questions based on the given paper and retrieval enhanced knowledge, giving priority to the content in the retrieval enhanced knowledge.

[0138] Given the following paper: [target document here]

[0139] The retrieval-enhanced knowledge is: [candidate text fragment here]

[0140] The question to be answered is: [question here]

[0141] The above introduces an intelligent question-answering method provided by an embodiment of the present application, and the following will introduce a device for executing the above-mentioned intelligent question-answering method.

[0142] See also Figure 5 , Figure 5 This is a schematic diagram of the structure of an intelligent question-answering device provided in an embodiment of the present application. Figure 5 As shown, the intelligent question-answering device comprises:

[0143] An acquisition unit 11 is used to acquire a question input by a user and a target document corresponding to the question;

[0144] A vector determination unit 12, used to determine the vector of the question and the vectors of multiple text segments corresponding to the target document, wherein the multiple text segments corresponding to the target document are obtained by segmenting the target document at multiple granularities based on the document structure;

[0145] A candidate text segment determination unit 13, configured to determine a candidate text segment based on the vector of the question and the similarity between the vectors of the plurality of text segments corresponding to the target document;

[0146] The answer generating unit 14 is used to generate an answer corresponding to the question based on the candidate text segment.

[0147] In a possible implementation, the device further includes a text segment vector generating unit; the text segment vector generating unit includes:

[0148] A document segmentation unit, used for segmenting the target document at multiple granularities based on the document structure to obtain multiple text segments, each of which contains a segmentation granularity label;

[0149] The text fragment vector generation subunit is used to input each text fragment into a pre-trained vector representation model to generate a vector of the text fragment, wherein the vector representation model is obtained by performing comparative learning and training on an initial vector representation model through multiple training data triples, and each of the training data triples includes a problem sample, a positive example of a text fragment sample corresponding to the problem sample, and a negative example of a text fragment sample corresponding to the problem sample.

[0150] In a possible implementation, the document segmentation unit is specifically used to:

[0151] Performing information extraction and chapter recognition processing on the target document to obtain a processed target document;

[0152] The processed target document is segmented at multiple granularities based on the document structure to obtain multiple text segments.

[0153] In a possible implementation, the apparatus further includes: a vector representation model training unit, wherein the vector representation model training unit is specifically configured to:

[0154] Obtain a pre-constructed training data set; the training data set includes a plurality of training data triplets, each training data triplet includes a problem sample, a positive example of a text segment sample corresponding to the problem sample, and a negative example of a text segment sample corresponding to the problem sample;

[0155] With the training objectives of shortening the distance between the vector of the problem sample and the vector of the positive text fragment sample corresponding to the problem sample, and increasing the distance between the vector of the problem sample and the vector of the negative text fragment sample corresponding to the problem sample, the initial vector representation model is trained by comparative learning to obtain a trained vector representation model.

[0156] In a possible implementation, the multiple granularities include at least two granularities of page-level granularity, chapter-level granularity, paragraph-level granularity, and fixed-length-level granularity.

[0157] In a possible implementation, the vector determination unit is specifically configured to:

[0158] The question is input into the vector representation model to generate a vector of the question.

[0159] In a possible implementation, the answer generating unit includes:

[0160] Inputting the question and the candidate text fragment into a first answer generation model to generate an answer corresponding to the question, wherein the first answer generation model is a large language model fine-tuned based on the first training data;

[0161] Alternatively, the question, the target document and the candidate text fragment are input into a second answer generation model to generate an answer corresponding to the question, and the second answer generation model is a large language model obtained by fine-tuning based on the second training data.

[0162] The present application also provides an electronic device in an embodiment. Figure 6 As shown, it shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiment of the present application. The electronic device in the embodiment of the present application may include but is not limited to fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 6 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0163] like Figure 6 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 to a random access memory (RAM) 603. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in the RAM 603. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0164] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a memory card, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0165] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements any one of the intelligent question-answering methods provided in the embodiments of the present application.

[0166] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any intelligent question-and-answer method provided in the embodiment of the present application.

[0167] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.

[0168] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0169] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0170] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.< / chunk> < / section> < / para> < / page>

Claims

1. An intelligent question-answering method, characterized in that: include: Obtain the question input by the user and the target document corresponding to the question; Determine a vector of the question and vectors of a plurality of text segments corresponding to the target document, wherein the plurality of text segments corresponding to the target document are obtained by segmenting the target document at a plurality of granularities based on the document structure; Determining candidate text segments based on the similarity between the vector of the question and the vectors of the plurality of text segments corresponding to the target document; Based on the candidate text segments, an answer corresponding to the question is generated.

2. The method according to claim 1, characterized in that The method for generating vectors of the plurality of text segments corresponding to the target document includes: Segmenting the target document at multiple granularities based on the document structure to obtain multiple text segments, each of which includes a segmentation granularity label; For each text fragment, the text fragment is input into a pre-trained vector representation model to generate a vector of the text fragment. The vector representation model is obtained by contrasting and learning an initial vector representation model with multiple training data triplets. Each of the training data triplet includes a problem sample, a positive example of a text fragment sample corresponding to the problem sample, and a negative example of a text fragment sample corresponding to the problem sample.

3. The method according to claim 2, characterized in that The target document is segmented at multiple granularities based on the document structure to obtain multiple text segments, including: Performing information extraction and chapter recognition processing on the target document to obtain a processed target document; The processed target document is segmented at multiple granularities based on the document structure to obtain multiple text segments.

4. The method according to claim 2, characterized in that: The vector representation model is trained as follows: Obtain a pre-constructed training data set; the training data set includes a plurality of training data triplets, each training data triplet includes a problem sample, a positive example of a text segment sample corresponding to the problem sample, and a negative example of a text segment sample corresponding to the problem sample; With the training objectives of shortening the distance between the vector of the problem sample and the vector of the positive text fragment sample corresponding to the problem sample, and increasing the distance between the vector of the problem sample and the vector of the negative text fragment sample corresponding to the problem sample, the initial vector representation model is trained by comparative learning to obtain a trained vector representation model.

5. The method according to any one of claims 1 to 4, characterized in that: The multiple granularities include at least two granularities of page level granularity, chapter level granularity, paragraph level granularity, and fixed length level granularity.

6. The method according to any one of claims 2 to 4, characterized in that The determining of the vector of the problem comprises: The question is input into the vector representation model to generate a vector of the question.

7. The method according to claim 1, characterized in that Generating an answer corresponding to the question based on the candidate text segment includes: Inputting the question and the candidate text fragment into a first answer generation model to generate an answer corresponding to the question, wherein the first answer generation model is a large language model fine-tuned based on the first training data; Alternatively, the question, the target document and the candidate text fragment are input into a second answer generation model to generate an answer corresponding to the question, and the second answer generation model is a large language model obtained by fine-tuning based on the second training data.

8. An intelligent question-answering device, characterized in that: include: An acquisition unit, used to acquire a question input by a user and a target document corresponding to the question; A vector determination unit, used to determine the vector of the question and the vectors of a plurality of text segments corresponding to the target document, wherein the plurality of text segments corresponding to the target document are obtained by segmenting the target document at a plurality of granularities based on the document structure; A candidate text segment determination unit, configured to determine a candidate text segment based on the vector of the question and the similarity between the vectors of the plurality of text segments corresponding to the target document; An answer generation unit is used to generate an answer corresponding to the question based on the candidate text segment.

9. A computer program product, characterized in that It includes computer-readable instructions, and when the computer-readable instructions are executed on an electronic device, the electronic device implements the intelligent question-answering method as described in any one of claims 1 to 7.

10. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the intelligent question and answer method as described in any one of claims 1 to 7.

11. A computer-readable storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the intelligent question-answering method as described in any one of claims 1 to 7.

Citation Information

Cited By

  • Question and answer information processing method and device based on intelligent knowledge base and electronic equipment

    CN120123484A

  • Question and answer information processing method and device based on intelligent knowledge base and electronic equipment

    CN120123484B

  • RAG enhanced small-scale language model question and answer accuracy improving method and system

    CN120162415A

  • Document question and answer method and device, electronic equipment and computer storage medium

    CN120821819A