Question and answer method and device based on multi-modal knowledge fusion enhancement

By converting multi-modal document data into HTML format and combining text, tables, and pictures, and using the contextual analysis of large language models, the problem of existing technology being unable to process non-txt format documents has been solved, and multi-modal processing has been achieved. Accurate understanding of dynamic documents and ability to answer questions.

CN118689979APending Publication Date: 2024-09-24ASIAINFO TECH CHINA INC

Patent Information

Application Number
CN202410760150.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-13
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

Existing large language model document question and answer methods cannot correctly understand and process documents in non-txt formats, such as PDF, Word, Excel, etc., resulting in the inability to correctly answer questions in documents containing multi-modal data.

Method used

Convert the input multi-modal document data into Hypertext Markup Language (HTML) format, parse and combine text, tables, and image data, use large language models to identify contextual information, split it into text chunks, and perform vectorization processing. Deposit into document vector database for Q&A.

Benefits of technology

It enables large language models to correctly understand and process multi-modal document data, thereby accurately answering user questions and solving the problem of incomplete and inaccurate document content.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118689979A
    Figure CN118689979A
Patent Text Reader

Abstract

The invention discloses a question and answer method and device based on multi-modal knowledge fusion enhancement, and the method comprises the steps: converting input first document data into second document data in a hypertext markup language format, the first document data and the second document data having different formats, the first document data comprises at least two kinds of data in text data, picture data and table data; analyzing the second document data to obtain third text data; identifying context association information of the third text data by using a large language model, and splitting the third text data into a plurality of third context blocks according to the context association information; and performing vectorization processing on the plurality of third context blocks to obtain a third text vector corresponding to the third text data, and storing the third text vector and the third text data into a document vector database so as to perform document question and answer by using the third text data and the third text vector stored in the document vector database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of question answering technology, and in particular to a question answering method and device based on multimodal knowledge fusion enhancement. Background Art

[0002] Document Question Answering is an important application of large language models, which enables computer programs to understand and answer questions asked by humans using natural language. The significance of this technology is that it allows computer programs to communicate with humans more conveniently and makes it easier for people to obtain information from a large amount of knowledge documents.

[0003] When used for document question answering, the large language model can receive questions input by users, and then retrieve and output documents suitable for answering the questions from a database storing a large number of documents based on the questions.

[0004] When inputting documents into the database, the existing large language model document question answering methods need to input the documents in txt format to facilitate direct reading of their text content. However, in real production life, common document formats are PDF, Word, Excel, etc., and the existing document answering methods cannot reasonably parse these documents, which results in the large language model being unable to correctly understand the documents input into the database, and thus unable to correctly answer questions input by users based on these documents. Summary of the invention

[0005] To this end, this application discloses the following technical solutions:

[0006] The first aspect of the present application provides a question-answering method based on multimodal knowledge fusion enhancement, comprising:

[0007] Converting the input first document data into second document data in a hypertext markup language format, wherein the first document data and the second document data have different formats, and the first document data includes at least two types of data selected from text data, image data, and table data;

[0008] Parsing the second document data to obtain third text data;

[0009] Using a large language model to identify context-related information of the third text data, and splitting the third text data into a plurality of third context blocks according to the context-related information;

[0010] Vectorization processing is performed on the plurality of third context blocks to obtain third text vectors corresponding to the third text data, and the third text vectors and the third text data are stored in a document vector database, so as to perform document question and answer using the third text data and the third text vectors stored in the document vector database.

[0011] Optionally, parsing the second document data to obtain third text data includes:

[0012] identifying table data, text data, and image data of the second document data;

[0013] Parsing the header text content and the table text content of the table data in the second document data, and combining the header text content and the table text content according to a preset format to obtain table text data corresponding to the table data;

[0014] Parsing the picture data in the second document data to obtain picture text data for describing the picture data;

[0015] The text data in the second document data, the table text data and the picture text data are combined to obtain third text data.

[0016] Optionally, the identifying the context-related information of the third text data by using a large language model includes:

[0017] Determine each sentence included in the third text data according to the text separation mark of the third text data;

[0018] Using a large language model to identify keywords for each of the sentences;

[0019] The correlation between different sentences is determined according to the keywords of the sentences, and the correlation between different sentences in the third text data constitutes the context association information of the third text data.

[0020] Optionally, also include:

[0021] Get the target question;

[0022] Searching the document vector database for the third text data that matches the target question;

[0023] The target answer corresponding to the target question is output according to the found third text data.

[0024] Optionally, storing the third text vector and the third text data in a document vector database includes:

[0025] Storing the third text vector, the third text data, and the source tracing data of the third text data in a document vector database;

[0026] After outputting the target answer corresponding to the target question according to the found third text data, the method further includes:

[0027] The traceability data and annotation information corresponding to the third text data found are output, wherein the annotation information is used to indicate the association relationship between the target answer and the traceability data.

[0028] The second aspect of the present application provides a question-answering device based on multimodal knowledge fusion enhancement, comprising:

[0029] A conversion unit, configured to convert the input first document data into second document data in a hypertext markup language format, wherein the first document data and the second document data have different formats, and the first document data includes at least two types of data selected from the group consisting of text data, image data, and table data;

[0030] A parsing unit, used for parsing the second document data to obtain third text data;

[0031] a splitting unit, configured to identify context-related information of the third text data by using a large language model, and split the third text data into a plurality of third context blocks according to the context-related information;

[0032] A processing unit is used to perform vectorization processing on the multiple third context blocks to obtain a third text vector corresponding to the third text data, and store the third text vector and the third text data in a document vector database, so as to perform document question and answer using the third text data and the third text vector stored in the document vector database.

[0033] Optionally, when the parsing unit parses the second document data to obtain the third text data, it is specifically used to:

[0034] identifying table data, text data, and image data of the second document data;

[0035] Parsing the header text content and the table text content of the table data in the second document data, and combining the header text content and the table text content according to a preset format to obtain table text data corresponding to the table data;

[0036] Parsing the picture data in the second document data to obtain picture text data for describing the picture data;

[0037] The text data in the second document data, the table text data and the picture text data are combined to obtain third text data.

[0038] Optionally, when the splitting unit uses the large language model to identify the contextual association information of the third text data, it is specifically used to:

[0039] Determine each sentence included in the third text data according to the text separation mark of the third text data;

[0040] Using a large language model to identify keywords for each of the sentences;

[0041] The correlation between different sentences is determined according to the keywords of the sentences, and the correlation between different sentences in the third text data constitutes the context association information of the third text data.

[0042] Optionally, the device further comprises a question-answering unit, configured to:

[0043] Get the target question;

[0044] Searching the document vector database for the third text data that matches the target question;

[0045] The target answer corresponding to the target question is output according to the found third text data.

[0046] Optionally, when the processing unit stores the third text vector and the third text data in a document vector database, it is specifically used to:

[0047] Storing the third text vector, the third text data, and the source tracing data of the third text data in a document vector database;

[0048] After the question-answering unit outputs the target answer corresponding to the target question according to the found third text data, the question-answering unit is further used to:

[0049] Output the traceability data and annotation information corresponding to the third text data found, wherein the annotation information is used to indicate the association relationship between the target answer and the traceability data.

[0050] The beneficial effect of this solution is that document data including multimodal data such as text, pictures and tables are converted into hypertext markup language format, and then all multimodal document data are converted into text data that can be recognized and processed by a large language model by parsing the hypertext markup language, so that the large language model can correctly understand the documents containing multimodal data input into the database, and thus can use these documents to correctly answer users' questions. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0052] Figure 1 It is a flow chart of a question-answering method based on multimodal knowledge fusion enhancement provided in an embodiment of the present application;

[0053] Figure 2 It is a method flow chart of a parsing process provided by an embodiment of the present application;

[0054] Figure 3 It is a flow chart of a method for answering questions using a large language model chain provided in an embodiment of the present application;

[0055] Figure 4 It is a structural schematic diagram of a question-answering device based on multimodal knowledge fusion enhancement provided in an embodiment of the present application;

[0056] Figure 5 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0057] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0058] First, some terms that may be involved in this application are explained.

[0059] Document format conversion: For common document types such as PDF, Word, Excel, etc., there are many ways to convert them into HTML documents. In addition to converting within the software, using conversion tools, and using OCR technology, it can also be achieved entirely using programming languages.

[0060] For example, for PDF, you can use Python's pdfminer, PyPDF2, or pdf2htmlEX libraries for conversion; for Word, you can use PyDocX, python-docx, etc.; for Excel, you can use the python pandas library to read and then convert the read content into HTML document content.

[0061] Multimodal technology is a technology that combines multiple different data modes, such as images, voice, and text, for comprehensive analysis and processing. It can handle image description generation, video understanding and annotation, sentiment analysis, etc. In the process of describing images using multimodal technology, the core steps are feature extraction and text generation. A typical model is CNN-RNN, where the convolutional neural network (CNN) is used to extract image features and the recurrent neural network (RNN) is used to generate text descriptions. In addition, the Transformer model is also widely used in multimodal image-to-text technology. By taking image features and text sequences as input and using the Transformer architecture for encoding and decoding, this model can establish a strong association between images and text. In addition, the attention mechanism can be introduced to enable the model to dynamically focus on the most critical areas or features in the image and associate them with the text description to improve the model's generation ability and description accuracy.

[0062] In-context learning: The main idea of ​​in-context learning is to learn from analogies. It enables large language models to learn and reason in a specific context, capturing contextual relationships, including context, background knowledge, interaction history, etc., to improve the understanding and prediction of input, so that the model can better understand and adapt to the current situation.

[0063] A common method for contextual learning is Chain of Thought (COT). In the COT training method, in addition to pairing prompts in a "question-answer" manner, it also includes the intermediate steps of derivation. The large language model uses the intermediate steps in the training set as a reference to learn the derivation process by analogy. By correcting the derivation process, the accuracy of the large language model's answer can be improved.

[0064] The underlying technologies involved in the contextual learning method are attention mechanism and converter.

[0065] The attention mechanism enables the model to focus on different parts of the input data and perform weighted processing based on contextual information to improve the expressiveness and accuracy of the model.

[0066] Transformer, Transformer is a neural network model based on the self-attention mechanism, which can process sequence data and capture contextual information without relying on the recurrent structure.

[0067] Vector library retrieval, the vector library is a database specially suitable for storing vectors, supporting functions such as adding, deleting, modifying, and searching for vectors. In addition to storing each vector itself, it can also store other information related to each vector, such as the source of the vector, etc. This other information is used as metadata.

[0068] Commonly used methods for vector library retrieval include cosine similarity, graph-based algorithms such as shortest path, and nearest neighbor search.

[0069] Among them, cosine similarity is one of the most widely used methods. This method measures whether the directions of two vectors are the same by calculating the cosine value between two vectors in the inner product space, thereby judging the similarity of the two vectors. The cosine similarity Sim(A, B) between two vectors A and B can be calculated using the following formula (1).

[0070]

[0071] Where n represents the dimension of vectors A and B, Ak represents the kth component of vector A, and Bk represents the kth component of vector B.

[0072] When the directions of two vectors are exactly the same, their cosine similarity is 1, and when the directions are completely opposite, their cosine similarity is -1. Therefore, the cosine similarity between vectors is between -1 and 1. The larger the value, the more similar the two vectors are.

[0073] In addition to plain text txt documents, knowledge documents are also available in PDF, Word, Excel, etc. The content of these documents is often multimodal, including text, tables, and pictures. The current document question-and-answer technology based on large language models mainly focuses on plain text knowledge question-and-answer, which is not conducive to multimodal question-and-answer.

[0074] In addition, the existing question-answering methods based on large language models have the following problems.

[0075] 1. The existing answering methods are difficult to reasonably parse other forms of content other than text, such as tables and pictures. This will make the large language model in document question answering unable to understand the content of tables and pictures, or completely lose their content, resulting in incomplete and inaccurate answers.

[0076] 2. Existing question-answering methods cannot flexibly segment document content. Although existing methods can segment according to specified characters and text length, there are still cases where irrelevant content is merged into the same part and mixed with each other, causing the model to answer inaccurate questions.

[0077] 3. The existing question-answering methods mainly return answers in the form of text content. As mentioned above, this is not suitable for documents containing multiple content forms. It loses information and is not very readable.

[0078] In view of the problems existing in the above-mentioned prior art, the present application embodiment provides a question-answering method based on multimodal knowledge fusion enhancement, please refer to Figure 1 , is a flow chart of the method, and the method may include the following steps.

[0079] S101, converting input first document data into second document data in a hypertext markup language format, the first document data and the second document data have different formats, and the first document data includes at least two types of data among text data, image data and table data.

[0080] Hypertext Markup Language, also known as Hyper TextMarkup Language, abbreviated as HTML.

[0081] Data in HTML format has the characteristics of order and clear tags. That is, you can determine whether the content is text, picture, table or other content by reading HTML tags, which facilitates subsequent analysis.

[0082] Among them, the HTML tag corresponding to the image can be , the HTML tags corresponding to the table can include <tb>.

[0083] The first document data is original document data that needs to be input into the document vector database. The first document data may be document data in any one of the doc format, docx format and pdf format.

[0084] In step S101, the format of the first document data may be identified first, and then a corresponding format conversion tool may be called according to the format to process the first document data, thereby converting the first document data into second document data in HTML format.

[0085] The format conversion tool used may be any existing format conversion tool, and this embodiment does not limit its specific working principle and conversion process.

[0086] As an example, when the first document data is document data in doc format or docx format, it can be converted into second document data using PyDocX or python-docx; when the first document data is document data in pdf format, it can be converted into second document data using Python-based pdfminer, PyPDF2 or pdf2htmlEX tools.

[0087] The first document data may include data in any of a variety of different modalities among text data, image data and table data, that is, it may include text data and image data, may include text data and table data, may include image data and table data, or may include text data, table data and image data.

[0088] After conversion by the aforementioned format conversion tool, the data in the above different modes can all be converted into HTML format.

[0089] As an example, the first document data may include table data as shown in Table 1 and Table 2 below.

[0090] Table 1

[0091]

[0092] Table 2

[0093]

[0094] Assuming that the first document data is in docx format, after conversion by PyDocX, the table data shown in Table 1 can be converted into the following HTML data.

[0095] <tableborder="1">< / tb> , and 2017 2018 2019 2020 2021 2022 Internet broadband access service revenue 164.7 billion 178.4 billion 185.5 billion 202.7 billion 224.3 billion 240.2 billion Internet broadband access business revenue growth rate 8.3% 6.6% 4.0% 9.3% 10.6% 7.1% .

[0096] S102: Parse the second document data to obtain third text data.

[0097] See also Figure 2 , the parsing method of the second document data may include the following steps.

[0098] S201, identifying table data, text data, and image data of second document data.

[0099] In step S201, table data, image data and text data may be distinguished by identifying HTML tags in the second document data.

[0100] Specifically, for those not included in <style>、<script>、<head>等特殊标签,并且不包含在前述表格和图片对应的标签中的数据,可以确定属于文本数据;对于包含在表格对应的标签中的数据,可以确定属于表格数据;对于包含在图片对应的标签中的数据可以确定属于图片数据。

[0101] S202a,解析第二文档数据中表格数据的表头文本内容和表格文本内容。

[0102] S202b,将表头文本内容和表格文本内容按预设格式组合得到表格数据对应的表格文本数据。

[0103] 在步骤S202a和S202b中,可以通过标签和<tb>标签来确定表格的行和列,进行表格解析。

[0104] 在步骤S202a中,可以先识别、处理各列表头,然后在解析除表头外的具体表格内容。

[0105] 表头可能存在非常复杂的情况,如包含多层、存在合并单元格等。因此,在识别处理各列表头时,本实施例以每列出现的第一个宽度为1(单位宽度)的单元格作为该列的表头结束位置。若该宽度为1的单元格之上还存在其他单元格,则其他单元格的内容会被合并进该格的内容中。

[0106] 下面以表3为示例对上述识别处理各列表头的过程进行说明。

[0107] 表3

[0108]

[0109] 表3中表格的表头会被确定为"A”,"BD”,"BE”,"CF”和"CG”。而"H”,"I”,"J”,"K”和"L”为除表头外的具体表格内容。

[0110] 当列表头确定后,开始表格内具体内容的解析。每当通过标签读取到新的一行时,该行最先出现的内容为该行的表头,若出现纵向合并单元格的情况,为了保证信息完整性,该单元格的内容也会在其占有的行上重复出现,参考上述对于列表头中合并单元格情况的处理。

[0111] 在步骤S202b中,对于非表头的单元格,假设其所在位置为(x,y),其中x表示行数,y表示列数,假设其内容为a,那么该单元格对应的表格文本数据可以按如下格式组合得到。

[0112] 单元格(x,y)对应的表格文本数据为:y列对应列表头内容+x行对应行表头内容+"是”+a。

[0113] 以表3为示例,当读取到内容为I的单元格时,该单元格对应的表格文本数据为:"BDH是I”。

[0114] 通过上述方式逐一将每一非表头的单元格的内容和对应的表头进行组合,就可以得到表格数据中每一非表头的单元格的表格文本数据。

[0115] 合并单元格的情况同上述处理相同,其内容会在每一个被其覆盖的位置上重复出现。

[0116] 按上述方式生成表格数据对应的表格文本数据,可以使输出的文本数据接近生活口语表达,可以被人工智能模型理解,且整体解析过程按HTML文件内容顺序进行,保留原文件中表格内容的相对位置。

[0117] 在一些可选的实施例中,解析得到表格文本数据的同时,可以保存第二文档数据中表格对应的HTML数据作为源数据。

[0118] S203,解析第二文档数据中图片数据,得到用于描述图片数据的图片文本数据。

[0119] 当读取到标签时,可以通过该标签对应的"src”参数得到对应图片的base64编码,从而通过base64编码提取到具体图片。

[0120] 获得具体图片后,可以将该图片输入可解析图片内容的模型,输出图片内容的文本形式解析,即可得到符合生活口语表达的图片内容描述,以用于后续大语言模型对文档中图片内容进行理解。

[0121] 通过这种方式获得的符合生活口语表达的图片内容描述,就是S203中的图片文本数据。

[0122] 在输出解析结果时,为方便后续文档问答中原图片展示,除了输出解析后得到的文本,还会输出该图片的base64编码作为源数据。

[0123] 其中,可解析图片内容的模型,可以预先通过多模态技术训练得到。该模型可以采用transformer模型架构实现,也可以采用其他模型架构实现。

[0124] S204,将第二文档数据中文本数据、表格文本数据和图片文本数据组合,得到第三文本数据。

[0125] 在步骤S204中,可以将第二文档数据原有的文本数据,通过前述步骤解析的表格文本数据和图片文本数据,按原顺序组合到一起,形成完全由文本组成的第三文本数据。

[0126] 文本数据、表格文本数据和图片文本数据在第三文本数据中的排列顺序,和第二文档数据中对应的文本、表格和图片的排列顺序一致。

[0127] 需要说明,图2所示的实施例是以第二文档数据同时包括文本、图片和表格为例进行说明的解析过程,当第二文档数据仅包含其中两者时,可以仅执行上述过程中对应步骤。

[0128] 例如,第二文档数据仅包含文本和图片,则解析得到第三文本数据时,可以仅执行S201,S203和S204。

[0129] 结合前述示例,表1对应的HTML数据经过S102的解析后,可以转换成如下的表1对应的文本数据。

[0130] 2017年互联网宽带接入业务收入是1647亿元;2018年互联网宽带接入业务收入是1784亿元,2019年互联网宽带接入业务收入是1855亿元,2020年互联网宽带接入业务收入是2027亿元,2021年互联网宽带接入业务收入是2243亿元,2022年互联网宽带接入业务收入是2402亿元;2017年互联网宽带接入业务收入增速是8.3%;2018年互联网宽带接入业务收入增速是6.6%,2019年互联网宽带接入业务收入增速是4.0%,2020年互联网宽带接入业务收入增速是9.3%,2021年互联网宽带接入业务收入增速是10.3%,2022年互联网宽带接入业务收入增速是7.1%。

[0131] S103,利用大语言模型识别第三文本数据的上下文关联信息,并根据上下文关联信息将第三文本数据拆分为多个第三上下文分块。

[0132] 可选的,利用大语言模型识别第三文本数据的上下文关联信息的方式可以是:

[0133] 根据第三文本数据的文本分隔标识确定出第三文本数据包含的每一语句;

[0134] 利用大语言模型识别每一语句的关键词;

[0135] 根据语句的关键词确定不同语句之间的关联性,第三文本数据中不同语句之间的关联性组成第三文本数据的上下文关联信息。

[0136] 文本分隔标识,可以是预先的标点符号以及其他的特殊符号,作为一个示例,句号、逗号、问号、分号和换行符都可以属于文本分隔标识,在确定语句时,可以将第三文本数据中,每两个相邻的文本分隔标识之间的字符串识别为一个语句。

[0137] 在识别关键词是,可以预设一个关键词库,然后用大语言模型将每个语句和该关键词库进行匹配,从而识别出语句中出现的每一关键词。

[0138] 在根据关键词确定关联性时,可以设置一个重复度阈值,该阈值可以是一个整数。如果一个关键词在两个语句中都出现,那么该关键词记为一个重复关键词,对于任意两个语句,如果这两个语句之间重复关键词的数量大于或等于重复度阈值,则可以认为两者的关联性为强关联,如果这两个语句之间重复关键词的数量小于重复度阈值,可以认为两者的关联性为弱关联。

[0139] 作为一个示例,重复度阈值设置为4,"2017年互联网宽带接入业务收入是1647亿元”和"2018年互联网宽带接入业务收入是1784亿元”之间有5个重复关键词,即"互联网”,"宽带”,"接入”,"业务”,"收入”,大于重复度阈值,于是确定两者的关联性为强关联。

[0140] "2022年互联网宽带接入业务收入增速是7.1%”和"2017-2022年移动数据流量业务收入发展情况”之间有2个重复关键词,为"业务”,"收入”,数量小于重复度阈值,于是确定两者的关联性为弱关联。

[0141] 除上述方式以外,还可以通过其他方式确定语句之间的关联性,例如,可以通过上下文学习预先训练适用于文本分块的大语言模型,然后用该模型逐一计算每一语句对应的语句向量,对每两个语句,如果这两个语句的语句向量的余弦相似度大于预设的关联阈值,则认为两者的关联性为强关联,如果两者的余弦相似度小于或等于关联阈值,则认为两者的关联性为弱关联。

[0142] 作为一个示例,该关联阈值可以是50%。

[0143] 根据上下文关联信息将第三文本数据拆分为多个第三上下文分块的方式可以是,对每两个相邻的语句,如果这两个相邻的语句之间属于强关联,则认为这两个相邻的语句属于同一第三上下文分块,如果这两个相邻的语句之间属于弱关联,则认为这两个相邻的语句属于不同第三上下文分块,按此规则逐一识别第三文本数据的每一语句,就可以确定哪些语句属于一个第三上下文分块。

[0144] S104,对多个第三上下文分块进行向量化处理,得到第三文本数据对应的第三文本向量,并将第三文本向量和第三文本数据存入文档向量数据库,以利用文档向量数据库存储的第三文本数据和第三文本向量进行文档问答。

[0145] 步骤S104中,用于进行向量化处理的算法可以是任意一种现有的将文本转换成向量的算法,例如可以是HuggingFaceEmbedding算法,或者可以是OpenAIEmbedding。

[0146] 文档向量数据库可以使用langchain的向量数据库chroma或其他支持增删改查和metadata存储的数据库。

[0147] 在步骤S104中,可以将每一第三上下文分块输入到用于进行向量化处理的算法,得到每一分块对应的第三文本向量,在存入文档向量数据库时,第三文本数据可以分块存储,每一分块对应一个第三文本向量。

[0148] 例如,第三文本数据被分为第三上下文分块A和第三上下文分块B,其中分块A经过算法处理得到第三文本向量A,分块B经过算法处理得到第三文本向量B,在存入数据库时,分块A和向量A对应,分块B和向量B对应。

[0149] 本实施例的有益效果在于,将包括文本、图片和表格等多模态数据的文档数据转换成超文本标记语言格式,进而通过解析超文本标记语言的方式多模态的文档数据全部转换成大语言模型能够识别和处理的文本数据,使得大语言模型能够正确理解输入数据库的包含多模态数据的文档,从而能够利用这些文档正确回答用户的问题。

[0150] 通过上述方式将第三文本数据和第三文本向量存入文档向量数据库后,就可以通过大语言模型链(Large Language Model Chain),利用文档向量数据库存储的第三文本数据和第三文本向量对用户输入的目标问题进行回答。

[0151] 其中,大语言模型链包含三个主要部分:适于文档问答的大语言模型、文档向量数据库、提示模块。其中提示模块又可以称为prompt提示。

[0152] 对于大语言模型,与上文类似,需要先通过上下文学习提高模型对于文档问答相关业务的熟悉度,提高模型对于用户问题的回答准确性和专业性。

[0153] 文档向量数据库,其检索得到的内容会作为大语言模型回答用户问题的文档依据。

[0154] 而对于prompt提示,其会要求大语言模型根据文档向量数据库检索得到的内容回答用户问题,对文档原内容进行简单摘要一方便用户后续阅读等。prompt提示的调整可提高模型回答的准确性,控制回答内容的具体程度、简要程度等。

[0155] 利用文档向量数据库进行问答的过程可以参见图3,该过程可以包括如下步骤。

[0156] S301,获得目标问题。

[0157] 目标问题是指用户输入的需要回答的问题,该问题可以是文本形式。

[0158] S302,在文档向量数据库中查找和目标问题匹配的第三文本数据。

[0159] 查找的方式可以是,将目标问题转换成问题向量,然后,计算文档向量数据库中存储的每一第三上下文向量和该问题向量之间的余弦相似度,筛选出其中余弦相似度大于预设的相似度阈值的第三上下文向量,将这些第三上下文向量对应的第三上下文分块,确定为和目标问题匹配的第三文本数据。

[0160] 其中,相似度阈值可以是预先定义的0至1中间的合理数值,例如0.6。

[0161] S303,根据查找到的第三文本数据输出目标问题对应的目标答案。

[0162] S303中,一种输出目标答案的方式可以是,将找到的第三文本数据按照预设的答案模板组合到一起,由此得到的文本作为目标答案输出。或者,可以直接将找到的第三文本数据作为目标答案输出。

[0163] 在一些可选的实施例中,将第三文本向量和第三文本数据存入文档向量数据库,可以包括;

[0164] 将第三文本向量、第三文本数据和第三文本数据的溯源数据存入文档向量数据库。

[0165] 这里的溯源数据,可以包括前面解析过程中用于产生第三文本数据的源数据,以及包括查找到的第三文本数据的来源信息,源数据的类型等。

[0166] 其中,来源信息用于指示找到的第三文本数据来源于哪一份或者哪几份第一文档数据。

[0167] 源数据的类型用于指示metadata是文本、表格还是图片。

[0168] 结合前述示例,当S302中查找到的第三文本数据包括前述表1对应的文本数据时,该第三文本数据对应的溯源数据可以包括以下数据。

[0169] ‘metadata’:{‘type’::‘table’,

[0170] ‘source_data’:<table border="1">2017年2018年2019年2020年2021年2022年互联网宽带接入业务收入1647亿元1784亿元1855亿元2027亿元2243亿元2402亿元互联网宽带接入业务收入增速8.3%6.6%4.0%9.3%10.6%7.1%’,

[0171] ‘source_file’:‘2022年通信业务统计公报.docx’}。

[0172] 其中metadata表示溯源数据,type表示源数据的类型,source_data表示源数据,source_file表示来源信息。

[0173] 进一步可选的,溯源数据还可以包括第一文档数据中,源数据对应的原始数据。

[0174] 例如,源数据是表格对应的HTML数据的情况,对应的原始数据可以是转换前的原始表格;源数据是图片对应的base64编码的情况,对应的原始数据可以是原始的图片。

[0175] 结合前述表1的示例,源数据是表1对应的HTML数据的情况下,对应的原始数据可以是示例中的表1。

[0176] 可选的,溯源数据中也可以不存储上述原始数据,在需要输出原始数据时,直接根据源数据解析还原出对应的原始数据。例如,根据前述表1对应的HTML数据在网页上还原出表1,根据图片的base64编码还原出对应的图片。

[0177] 在存储溯源数据的情况下,本实施例的问答方法还可以包括如下步骤。

[0178] S304,输出查找到的第三文本数据对应的溯源数据和标注信息,标注信息用于指示目标答案和溯源数据关联关系。

[0179] 其中,针对第一文档数据中不同模态的数据,可以采用不同的输出方式。

[0180] 对于第一文档数据中的文本数据,可以按步骤S341的方式输出。

[0181] S341,直接输出文本数据。

[0182] 对于第一文档数据中的表格数据,可以按步骤S342的方式输出。

[0183] S342,输出表格对应的HTML数据。

[0184] 例如,可以输出前述示例中表1对应的HTML数据。

[0185] 对于第一文档数据中的图片数据,可以按步骤S343的方式输出。

[0186] S343,输出图片的base64编码。

[0187] 可选的,在输出溯源数据的情况下,还可以进一步输出溯源数据的摘要数据。

[0188] 其中,摘要数据可以在输出溯源数据的情况下默认输出,也可以根据用户的指示而输出或者不输出,例如,用户输入目标问题时还输入了提供相关信息摘要的指示,则输出溯源数据和对应的摘要数据,如果没有输入提供相关信息摘要的指示,则不输出摘要数据。

[0189] 用户的指示和目标问题都可以通过前述大语言模型链的提示模块输入。

[0190] 下面结合一个示例对图3所示的问答过程进行说明。

[0191] 假设S301获得的目标问题为"2018年互联网宽带接入业务收入是多少”,在S302中,可以查找到和这个目标问题匹配的第三文本数据,为前述示例中表1对应的文本数据,于是,将该文本数据作为目标答案进行输出,也就是输出如下的目标答案。

[0192] 2017年互联网宽带接入业务收入是1647亿元;2018年互联网宽带接入业务收入是1784亿元,2019年互联网宽带接入业务收入是1855亿元,2020年互联网宽带接入业务收入是2027亿元,2021年互联网宽带接入业务收入是2243亿元,2022年互联网宽带接入业务收入是2402亿元;2017年互联网宽带接入业务收入增速是8.3%;2018年互联网宽带接入业务收入增速是6.6%,2019年互联网宽带接入业务收入增速是4.0%,2020年互联网宽带接入业务收入增速是9.3%,2021年互联网宽带接入业务收入增速是10.3%,2022年互联网宽带接入业务收入增速是7.1%。

[0193] 进一步的,还可以输出如下的溯源数据。

[0194] 原文为表格内容,原文出自"2022年通信业务统计公报.docx”,以上答案对应的HTML是:

[0195] <table border="1">2017年2018年2019年2020年2021年2022年互联网宽带接入业务收入1647亿元1784亿元1855亿元2027亿元2243亿元2402亿元互联网宽带接入业务收入增速8.3%6.6%4.0%9.3%10.6%7.1%。

[0196] 进一步的,还可以显示输出前述表1,表1对应的摘要数据以及标注信息。

[0197] 其中表1对应的摘要数据可以是"这是一份统计2017至2022年互联网宽带接入业务收入和收入增速的数据”。

[0198] 标注信息可以有多种输出方式,一种输出标注信息的方式是,在输出表1的同时,将表1中和目标问题相关的部分高亮显示,例如在本示例中,可以将表1中2018年互联网宽带接入业务收入,以及2018年互联网宽带接入业务收入增速两项数据高亮显示。

[0199] 本实施例提供的基于多模态知识融合增强的问答方法,还具有如下有益效果。

[0200] 第一,本实施例的方法采用先将输入文档(即第一文档数据)转换为HTML文档(即第二文档数据)的方法,解决了不同格式文档解析方式不同,解析方法可移植性差的问题。利用了HTML文档内容顺序书写、标签清晰易读的特点,增加了文档内容解析的简易性和可读性。

[0201] 第二,本实施例的方法在解析表格数据时,采用了行、列表头加具体表格内容的表格内容解析方法,该方法具有线性时间复杂度,在保留信息原意、和保留文档上下文位置关系的前提下,实现了表格结构化内容向生活用语话文本内容的解析。

[0202] 第三,本实施例的方法采用多模态技术解析文档中的图片,在保留信息原意、和保留文档上下文位置关系的前提下,实现了对图片内容的文本化表达,满足LLM的输入。

[0203] 第四,本实施例的方法利用大语言模型对文档内容上下文关联性进行分析,基于确定出的语句之间的关联性对上下文进行灵活化分块,使后续对文本进行向量化和向量存储更为准确合理,进而使后续的相似度检验和模型问答更为准确合理。

[0204] 第五,本实施例提出在存储向量和文本数据的同时,以metadata的形式存入原文档内容相关信息,在问题回答时根据原文档内容文本 / 表格 / 图片的不同形式做不同处理,以最大程度上还原答案相关信息的原文档内容,使用户可以更直观、更具体地得到所需信息。

[0205] 本申请实施例还提供一种基于多模态知识融合增强的问答装置,请参见图4,为该装置的结构示意图,该装置可以包括如下单元。

[0206] 转换单元401,用于将输入的第一文档数据转换成超文本标记语言格式的第二文档数据,第一文档数据和第二文档数据具有不同格式,第一文档数据包括文本数据、图片数据和表格数据中至少两种数据;

[0207] 解析单元402,用于解析第二文档数据,得到第三文本数据;

[0208] 拆分单元403,用于利用大语言模型识别第三文本数据的上下文关联信息,并根据上下文关联信息将第三文本数据拆分为多个第三上下文分块;

[0209] 处理单元404,用于对多个第三上下文分块进行向量化处理,得到第三文本数据对应的第三文本向量,并将第三文本向量和第三文本数据存入文档向量数据库,以利用文档向量数据库存储的第三文本数据和第三文本向量进行文档问答。

[0210] 可选的,解析单元402解析第二文档数据,得到第三文本数据时,具体用于:

[0211] 解析第二文档数据中表格数据的表头文本内容和表格文本内容,并将表头文本内容和表格文本内容按预设格式组合得到表格数据对应的表格文本数据;

[0212] 解析第二文档数据中图片数据,得到用于描述图片数据的图片文本数据;

[0213] 将第二文档数据中文本数据、表格文本数据和图片文本数据组合,得到第三文本数据。

[0214] 可选的,拆分单元403利用大语言模型识别第三文本数据的上下文关联信息时,具体用于:

[0215] 根据第三文本数据的文本分隔标识确定出第三文本数据包含的每一语句;

[0216] 利用大语言模型识别每一语句的关键词;

[0217] 根据语句的关键词确定不同语句之间的关联性,第三文本数据中不同语句之间的关联性组成第三文本数据的上下文关联信息。

[0218] 可选的,装置还包括问答单元405,用于:

[0219] 获得目标问题;

[0220] 在文档向量数据库中查找和目标问题匹配的第三文本数据;

[0221] 根据查找到的第三文本数据输出目标问题对应的目标答案。

[0222] 可选的,处理单元404将第三文本向量和第三文本数据存入文档向量数据库时,具体用于;

[0223] 将第三文本向量、第三文本数据和第三文本数据的溯源数据存入文档向量数据库;

[0224] 问答单元405根据查找到的第三文本数据输出目标问题对应的目标答案之后,还用于:

[0225] 输出查找到的第三文本数据对应的溯源数据和标注信息,标注信息用于指示目标答案和溯源数据的关联关系。

[0226] 本申请实施例提供一种基于多模态知识融合增强的问答装置,其工作原理和有益效果可以参见本申请其他实施例提供的一种基于多模态知识融合增强的问答方法的相关步骤和有益效果,不再赘述。

[0227] 本申请实施例还提供一种电子设备,请参见图5,为该电子设备的结构示意图,该电子设备可以包括存储器501和处理器502。

[0228] 其中,存储器501用于存储计算机程序;

[0229] 处理器502用于执行该计算机程序,具体用于实现本申请任一实施例所提供的基于多模态知识融合增强的问答方法。

[0230] 需要说明的是,本说明书中的各个实施例均采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似的部分互相参见即可。

[0231] 为了描述的方便,描述以上系统或装置时以功能分为各种模块或单元分别描述。当然,在实施本申请时可以把各单元的功能在同一个或多个软件和 / 或硬件中实现。

[0232] 通过以上的实施方式的描述可知,本领域的技术人员可以清楚地了解到本申请可借助软件加必需的通用硬件平台的方式来实现。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在存储介质中,如ROM / RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例或者实施例的某些部分所述的方法。

[0233] 最后,还需要说明的是,在本文中,诸如第一、第二、第三和第四等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语"包括”、"包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句"包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。

[0234] 以上所述仅是本申请的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本申请原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本申请的保护范围。< / style>

Claims

1. A question-answering method based on multimodal knowledge fusion enhancement, It is characterized in that include: Converting the input first document data into second document data in a hypertext markup language format, wherein the first document data and the second document data have different formats, and the first document data includes at least two types of data selected from text data, image data, and table data; Parsing the second document data to obtain third text data; Using a large language model to identify context-related information of the third text data, and splitting the third text data into a plurality of third context blocks according to the context-related information; Vectorization processing is performed on the multiple third context blocks to obtain third text vectors corresponding to the third text data, and the third text vectors and the third text data are stored in a document vector database, so as to perform document question and answer using the third text data and the third text vectors stored in the document vector database.

2. The method according to claim 1, It is characterized in that The parsing the second document data to obtain third text data includes: identifying table data, text data, and image data of the second document data; Parsing the header text content and the table text content of the table data in the second document data, and combining the header text content and the table text content according to a preset format to obtain table text data corresponding to the table data; Parsing the picture data in the second document data to obtain picture text data for describing the picture data; The text data in the second document data, the table text data and the picture text data are combined to obtain third text data.

3. The method according to claim 1, It is characterized in that The step of using a large language model to identify context-related information of the third text data includes: Determine each sentence included in the third text data according to the text separation mark of the third text data; Using a large language model to identify keywords for each of the sentences; The correlation between different sentences is determined according to the keywords of the sentences, and the correlation between different sentences in the third text data constitutes the context association information of the third text data.

4. The method according to claim 1, It is characterized in that Also includes: Get the target question; Searching the document vector database for the third text data that matches the target question; The target answer corresponding to the target question is output according to the found third text data.

5. The method according to claim 4, It is characterized in that The storing the third text vector and the third text data into a document vector database comprises: Storing the third text vector, the third text data, and the source tracing data of the third text data in a document vector database; After outputting the target answer corresponding to the target question according to the found third text data, the method further includes: The traceability data and annotation information corresponding to the third text data found are output, wherein the annotation information is used to indicate the association relationship between the target answer and the traceability data.

6. A question-answering device based on multimodal knowledge fusion enhancement, It is characterized in that include: A conversion unit, configured to convert the input first document data into second document data in a hypertext markup language format, wherein the first document data and the second document data have different formats, and the first document data includes at least two types of data selected from the group consisting of text data, image data, and table data; A parsing unit, used for parsing the second document data to obtain third text data; a splitting unit, configured to identify context-related information of the third text data by using a large language model, and split the third text data into a plurality of third context blocks according to the context-related information; A processing unit is used to perform vectorization processing on the multiple third context blocks to obtain a third text vector corresponding to the third text data, and store the third text vector and the third text data in a document vector database, so as to perform document question and answer using the third text data and the third text vector stored in the document vector database.

7. The device according to claim 6, It is characterized in that When the parsing unit parses the second document data to obtain the third text data, it is specifically used to: identifying table data, text data, and image data of the second document data; Parsing the header text content and the table text content of the table data in the second document data, and combining the header text content and the table text content according to a preset format to obtain table text data corresponding to the table data; Parsing the picture data in the second document data to obtain picture text data for describing the picture data; The text data in the second document data, the table text data and the picture text data are combined to obtain third text data.

8. The device according to claim 6, It is characterized in that When the splitting unit uses the large language model to identify the contextual association information of the third text data, it is specifically used to: Determine each sentence included in the third text data according to the text separation mark of the third text data; Using a large language model to identify keywords for each of the sentences; The correlation between different sentences is determined according to the keywords of the sentences, and the correlation between different sentences in the third text data constitutes the context association information of the third text data.

9. The device according to claim 6, It is characterized in that The device also includes a question-answering unit, which is used to: Get the target question; Searching the document vector database for the third text data that matches the target question; The target answer corresponding to the target question is output according to the found third text data.

10. The device according to claim 9, It is characterized in that When the processing unit stores the third text vector and the third text data into the document vector database, it is specifically used to: Storing the third text vector, the third text data, and the source tracing data of the third text data in a document vector database; After the question-answering unit outputs the target answer corresponding to the target question according to the found third text data, the question-answering unit is further used to: The traceability data and annotation information corresponding to the third text data found are output, wherein the annotation information is used to indicate the association relationship between the target answer and the traceability data.

Citation Information

Patent Citations

  • Interaction method and device of knowledge database, electronic equipment and computer readable storage medium

    CN117807210A

  • Large language model question and answer optimization method and device, electronic equipment and storage medium

    CN117851575A

  • Intelligent document question and answer method based on large model

    CN117932018A

  • Question and answer system based on large language model

    CN117951269A

  • Modality adaptive information retrieval

    US20220230061A1

Cited By

  • Visual question and answer method and device, equipment, storage medium and product

    CN118916471A

  • Method for structuring PDF file based on OCR and large model

    CN119003465A

  • Word document question and answer method and system based on large language model

    CN120470086A

  • Information processing device, information processing method, and program

    JP2026111970A

  • Information processing device, information processing method, and program

    JP7730111B1