Text question and answer method and device, equipment, storage medium and program product
By using the text search model in the text question and answer system to extract semantic information and entity relationships, and using the knowledge graph to retrieve candidate text fragments, the problems of low answer accuracy and delayed answers in the prior art are solved, and more efficient and accurate text fragment retrieval and answer generation are achieved.
Patent Information
- Application Number
- CN202510095529.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-21
- Publication Date
- 2025-05-16
AI Technical Summary
The answer accuracy of the existing extracted text question and answer method is low, and there are too many text fragments retrieved, it takes a long time and resources to analyze and integrate, resulting in delayed answers and affecting the user experience.
By receiving the first text input by the user, input it into the text search model, extracting semantic information and entity relationships, using the pre-constructed knowledge graph to retrieve candidate text fragments in the text library, and filtering out the target text fragments based on similarity, and finally entering them into the question and answer model to generate an answer.
It improves the accuracy and efficiency of text fragment retrieval, reduces the number of text fragments retrieved, reduces the time for analysis and integration, reduces the delay in answering, and improves the user experience.
Smart Images

Figure CN120011515A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of data processing, and in particular, to a text question and answer method, apparatus, device, storage medium, and program product. Background Art
[0002] At present, in order to improve the accuracy of large models in specific domain knowledge question answering, existing technologies usually use extractive text question answering in large models to generate answers corresponding to questions. Extractive text question answering is a question answering system technology that directly extracts answers from given text. The core idea of extractive text question answering is to retrieve the most relevant text fragments from a large amount of text data through algorithms and models, and extract them as answers.
[0003] However, the current extractive text question-answering methods do not require complex semantic understanding and reasoning of the text, resulting in low accuracy of the answers provided. In addition, if too many text fragments are retrieved, it will take a long time and resources to analyze and integrate them, which may cause delayed answers and affect the user experience. Summary of the invention
[0004] The embodiments of the present invention provide a text question-answering method, apparatus, device, storage medium and program product, which solve the technical problem of low answer accuracy of the extractive text question-answering method in the prior art.
[0005] In a first aspect, an embodiment of the present invention provides a text question answering method, the method comprising:
[0006] receiving a first text;
[0007] Inputting the first text into a preset text retrieval model, for the text retrieval model to determine semantic information of the first text, a first entity, and a first association relationship between the first entities, and searching the text library for a plurality of candidate text segments associated with the first text based on the semantic information, the first entity, the first association relationship, and a knowledge graph pre-constructed with text segments in a text library as objects, wherein the knowledge graph includes different entities and association relationships between different entities;
[0008] Determine the similarity between the first text and each of the candidate text segments, and select at least one target text segment from the candidate text segments according to the similarity;
[0009] The first text and the target text segment are input into a preset question-answering model so that the question-answering model outputs an answer text corresponding to the first text.
[0010] The step of retrieving multiple candidate text segments associated with the first text in the text library according to the semantic information, the first entity, the first association relationship, and a knowledge graph pre-constructed with text segments in the text library as objects includes:
[0011] Constructing a first query statement according to the first entity and the first association relationship, and searching for a second entity associated with the first entity through the first association relationship in a knowledge graph pre-constructed with text fragments in a text library as objects according to the first query statement;
[0012] Determine a derived association relationship according to the first association relationship, construct a second query statement according to the first entity and the derived association relationship, and query the knowledge graph for a third entity associated with the first entity through the derived association relationship according to the second query statement;
[0013] According to the first entity, the second entity and the third entity, acquiring a plurality of related first text segments in the text library;
[0014] A plurality of candidate text segments are screened out from the plurality of first text segments according to the semantic information.
[0015] The matching of a plurality of corresponding candidate text segments among a plurality of the first text segments according to the semantic information includes:
[0016] A keyword is determined according to the semantic information, and a plurality of corresponding candidate text segments are matched among the plurality of first text segments according to the keyword.
[0017] The text retrieval model is obtained by fine-tuning a preset large language model, wherein a LoRA layer is inserted into the attention layer of the large language model, and the LoRA layer includes two low-rank matrices. The fine-tuning process includes:
[0018] Acquire at least one tag information corresponding to each text segment in the text library, wherein each tag information includes two entities in the corresponding text segment, an association relationship between the two entities, and position index information of the corresponding text segment in the text library, and the two entities in different tag information are different;
[0019] In each round of fine-tuning, the original parameters of the large language model are fixed, and the tag information is input into the large language model so that the large language model learns the association relationship between the entities corresponding to each of the text fragments in the text library according to the tag information, and updates and optimizes the low-rank matrix of the LoRA layer according to the back-propagation algorithm by receiving the gradient information from the loss function until the recognition accuracy of the large language model for the association relationship between the entities reaches a preset threshold.
[0020] The determining of the similarity between the first text and each of the candidate text segments, and selecting at least one target text segment from the candidate text segments according to the similarity, includes:
[0021] Convert the first text into a first vector, and convert each of the candidate text segments into a corresponding second vector;
[0022] determining a similarity between the first vector and each of the second vectors;
[0023] At least one target text segment is selected from the candidate texts based on the similarity.
[0024] Wherein, determining the similarity between the first vector and each of the second vectors includes:
[0025] A cosine similarity between the first vector and each of the second vectors is determined.
[0026] In a second aspect, an embodiment of the present invention provides a text question-answering device, the text question-answering device comprising:
[0027] A text receiving module, used for receiving a first text;
[0028] a fragment retrieval module, used to input the first text into a preset text retrieval model, and use the text retrieval model to determine semantic information of the first text, a first entity, and a first association relationship between the first entities, and retrieve multiple candidate text fragments associated with the first text in the text library based on the semantic information, the first entity, the first association relationship, and a knowledge graph pre-constructed with text fragments in a text library as objects, wherein the knowledge graph includes different entities and association relationships between different entities;
[0029] A segment screening module, used to determine the similarity between the first text and each of the candidate text segments, and screen out at least one target text segment from the candidate text segments according to the similarity;
[0030] An answer output module is used to input the first text and the target text segment into a preset question-answering model so that the question-answering model outputs an answer text corresponding to the first text.
[0031] In a third aspect, an embodiment of the present invention provides a text question-answering device, the text question-answering device comprising a processor and a memory;
[0032] The memory is used to store a computer program and transmit the computer program to the processor;
[0033] The processor is used to execute the text question answering method as described in the first aspect according to the instructions in the computer program.
[0034] In a fourth aspect, an embodiment of the present invention provides a storage medium storing computer executable instructions, which, when executed by a computer processor, are used to execute the text question answering method as described in the first aspect.
[0035] In a fifth aspect, an embodiment of the present invention provides a computer program product, including a computer program, which, when executed by a processor, implements the text question and answer method described in the first aspect.
[0036] As described above, the embodiment of the present invention provides a text question-answering method, device, equipment, storage medium and program product. After receiving the first text input by the user, the embodiment of the present invention inputs the first text into the text retrieval model, so that the text retrieval model extracts the semantic information of the first text and the first association relationship between the first entity, and then retrieves multiple candidate text fragments in the text library according to the pre-constructed knowledge graph, so as to facilitate the subsequent inference of the answer text related to the first text based on the candidate text fragments. The embodiment of the present invention extracts the semantic information and entity relationship of the first text through the text retrieval model, and retrieves the relevant candidate text fragments in the database according to the semantic information and entity relationship. It can provide more comprehensive and accurate text fragment retrieval results, improve the accuracy of the subsequent inference of the answer text related to the first text, improve the user experience, and solve the technical problem of low answer accuracy of the extractive text question-answering method in the prior art. At the same time, it can also reduce the number of retrieved text fragments, reduce the time for analyzing and integrating text fragments, and further reduce answer delays. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 A flowchart of a text question-answering method provided by an embodiment of the present invention.
[0038] Figure 2 A schematic diagram of a process for outputting an answer text provided in an embodiment of the present invention.
[0039] Figure 3 A structural diagram of a text question-answering device provided by an embodiment of the present invention.
[0040] Figure 4 A structural diagram of a text question-answering device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0041] The following description and accompanying drawings fully illustrate the specific embodiments of the present application so that those skilled in the art can practice them. The examples represent possible variations only. Unless explicitly required, separate components and functions are optional, and the order of operation can vary. The parts and features of some embodiments may be included in or replace the parts and features of other embodiments. The scope of the embodiments of the present application includes the entire scope of the claims, and all available equivalents of the claims. In this article, each embodiment may be represented individually or generally by the term "invention", which is only for convenience, and if more than one invention is disclosed in fact, it is not intended to automatically limit the scope of the application to any single invention or inventive concept. In this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, without requiring or implying any actual relationship or order between these entities or operations. Moreover, the term "include", "comprise" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method or device including a series of elements includes not only those elements, but also other elements that are not explicitly listed. The various embodiments are described in a progressive manner herein, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other. As for the structures, products, etc. disclosed in the embodiments, since they correspond to the parts disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method part.
[0042] At present, in order to improve the accuracy of large models in specific domain knowledge question answering, existing technologies usually use extractive text question answering in large models to generate answers corresponding to questions. The existing extractive text question answering method generally includes the following steps:
[0043] First, the documents in the knowledge base are preprocessed and divided into document fragments of fixed length. The document fragments are then converted into vector form and stored in the vector database for efficient retrieval. When a user asks a question, the user's question is converted into a vector form, and the question vector corresponding to the user's question is compared with the document vector in the vector database to find the text fragment with the highest similarity. Finally, the text fragment with the highest similarity is used as input to the large language model for summarization and answer generation.
[0044] However, the existing extractive text question answering methods have the following defects:
[0045] 1. Splitting documents into fixed-length document fragments may cause sentences or paragraphs to be cut off, destroying the original structure and semantic continuity of the document, affecting the subsequent large language model's understanding and interpretation of the document content. It will also cause the loss of contextual information in the document, especially when the answer to the question depends on the context across fragments. The lack of full-text association makes it difficult for the large language model to capture the overall meaning of the document, resulting in inaccurate generated answers.
[0046] 2. If too many document fragments are retrieved, the complexity and computational cost of model processing will increase, affecting query performance. At the same time, a large number of fragments require more time and resources to analyze and integrate, resulting in delayed answers and affecting user experience.
[0047] Based on this, in order to solve the above technical problems, an embodiment of the present invention provides a text question-answering method. After receiving a first text input by a user, the embodiment of the present invention inputs the first text into a text retrieval model, so that the text retrieval model extracts the semantic information of the first text and the first association relationship between the first entity, and then retrieves multiple candidate text fragments in the text library in a pre-constructed knowledge graph, so as to facilitate the subsequent inference of answer texts related to the first text based on the candidate text fragments. The embodiment of the present invention determines the semantic information and entity relationship of the first text through a text retrieval model, and then retrieves relevant candidate text fragments in the database, which can provide more accurate text fragment retrieval results, improve the accuracy of the subsequent inference of the answer text related to the first text, and improve the user experience. At the same time, it can also reduce the number of retrieved text fragments, further reducing the answer delay.
[0048] like Figure 1 As shown, Figure 1 A flowchart of a text question-answering method provided in an embodiment of the present invention. The text question-answering method provided in an embodiment of the present invention can be executed by a text question-answering device, which can be implemented by software and / or hardware. The text question-answering device can be composed of two or more physical entities, or can be composed of one physical entity. For example, the text question-answering device can be a computer, a server, a tablet, or other device. The text question-answering method includes the following steps:
[0049] Step 101: Receive a first text.
[0050] In this embodiment, when the user needs to ask a question, the user needs to input a first text related to the question into the text question-answering device. For example, the text content of the first text may include "What classmates and courses does Xiaolan have in Hongqi Primary School?".
[0051] Step 102: input the first text into a preset text retrieval model, which is used for the text retrieval model to determine semantic information of the first text, a first entity, and a first association relationship between the first entities; based on the semantic information, the first entity, the first association relationship, and a knowledge graph pre-constructed with text segments in a text library as objects, retrieve multiple candidate text segments associated with the first text in the text library, wherein the knowledge graph includes different entities and association relationships between different entities.
[0052] After receiving the first text input by the user, the text question and answer device can input the first text into a preset text retrieval model. In this embodiment, the text retrieval model is used to retrieve text fragments associated with the text content in the first text in the database according to the first text input by the user. Specifically, the text retrieval model first needs to determine the semantic information of the first text, multiple first entities of the first text, and the first association relationship between the first entities. Exemplarily, when the text content of the first text is "What classmates and courses does Xiaolan have in Hongqi Primary School?", the first entity extracted from the first text by the text retrieval model includes Xiaolan and Hongqi Primary School, the association relationship between the first entities is to study, and the semantic information of the first text is "What classmates and courses does Xiaolan have". After that, the text retrieval model needs to further retrieve multiple candidate text fragments associated with the first text in the text library based on the semantic information, the first entity, the first association relationship, and the knowledge graph pre-constructed with the text fragments in the text library as the object. The knowledge graph is pre-constructed with the text fragments in the text library as the object, and the knowledge graph includes multiple entities and the association relationship between different entities. The entities and the association relationship are extracted from the text fragments in the text library. The construction of the knowledge graph involves multiple links such as knowledge extraction, knowledge fusion, and knowledge processing. It is necessary to extract entities, associations, attributes, and other information from the text fragments of the text library and integrate them into a structured graph data model. For example, when building a knowledge graph of historical figures, it is necessary to extract the name, life story, relationship with other characters, and other information from the text fragments of the text library, and then organize and associate them. The construction method of the knowledge graph can refer to the prior art and is not specifically limited in this embodiment. Exemplary, for example, the database includes text fragments about Xiaolan studying at Hongqi Primary School, text fragments about Xiaoming studying at Hongqi Primary School, and text fragments about Xiaolan and Xiaoming playing together. At this time, the knowledge graph includes the association relationship between Xiaolan and Hongqi Primary School as studying, the association relationship between Xiaoming and Hongqi Primary School as studying, and the association relationship between Xiaolan and Xiaoming as classmates. In one embodiment, when retrieving multiple candidate text fragments associated with a first text in a text library, the other entities and relationship chains connected to the first entity through the first association relationship can be queried in the knowledge graph based on the first entity and the first association relationship. After obtaining the text fragments associated with the first entity and the text fragments associated with other entities in the text library, the candidate text fragments that may be related to the first text are further screened in the text fragments based on semantic information.
[0053] On the basis of the above embodiment, according to the semantic information, the first entity, the first association relationship and the knowledge graph pre-built with the text segments in the text library as objects, multiple candidate text segments associated with the first text are retrieved in the text library, including:
[0054] Step 1021: construct a first query statement based on the first entity and the first association relationship, and query a second entity associated with the first entity through the first association relationship in a knowledge graph pre-constructed with text fragments in a text library as objects based on the first query statement.
[0055] In this embodiment, it is first necessary to construct a query statement for the knowledge graph. When constructing a query statement, it is first necessary to normalize the first entity and the first association relationship to ensure subsequent accurate queries. For example, the names of the two first entities "Xiao Lan" and "Hongqi Primary School" are standardized to ensure that they are consistent with the expressions in the knowledge graph and the text library. For example, if the school is mentioned in the text library using the full name "Hongqi Primary School" and there is no abbreviation, it is necessary to ensure that the entity name matches it; for the first association relationship of "studying", it is also standardized according to the established relationship representation method of the knowledge graph, such as using the standardized English expression "is_studying_at" to facilitate subsequent accurate queries.
[0056] After normalizing the first entity and the first relationship, starting from "Xiao Lan", based on the first relationship "Study", we use the query language supported by the knowledge graph (such as SPARQL) to build a query statement to find the second entity and relationship chain connected to "Xiao Lan" through the "Study" relationship in the knowledge graph. For example, we can build a query like "SELECT?classmate WHERE{<Xiao Lan><is_studying_at> <Hongqi Primary School>.<Hongqi Primary School><has_student> classmate}" is used to find other classmates who study in Hongqi Primary School, that is, Xiaolan's classmates.
[0057] Step 1022: determine a derived association relationship based on the first association relationship, construct a second query statement based on the first entity and the derived association relationship, and query the knowledge graph for a third entity associated with the first entity through the derived association relationship based on the second query statement.
[0058] In addition to considering the first association, it is also necessary to further consider the derived association corresponding to the first association. For example, considering that we need to find information related to a course, in addition to the direct "enrollment" relationship, we also need to explore the derived relationship inferred from "enrollment". For example, classmates will participate in course learning together, and there is a "opening" relationship between courses and schools. Based on the derived relationship, we can further expand the query scope, for example, construct a query statement to find courses offered by Hongqi Primary School, such as "SELECT?course WHERE{<Hongqi Primary School> <offers>? course}", the purpose is to find out the course entities offered in Hongqi Primary School to build a richer relationship network in the knowledge graph.
[0059] Step 1023: Acquire multiple related first text segments in the text library according to the first entity, the second entity, and the third entity.
[0060] Afterwards, based on the first entity, the second entity and the third entity, a text segment including the first entity, a text segment including the second entity and a text segment including multiple third entities can be obtained in the text library to obtain multiple first text segments.
[0061] Step 1024: Filter out multiple candidate text segments from the multiple first text segments according to the semantic information.
[0062] After determining multiple first text segments, it is necessary to further screen multiple candidate text segments from the multiple first text segments based on semantic information. In one embodiment, the first semantic information of each first text segment can be extracted, and multiple candidate text segments with higher semantic similarity can be screened out based on the semantic similarity between each first semantic information and the semantic information of the first text. In another embodiment, keywords can be determined based on the semantic information, and multiple corresponding candidate text segments can be matched in multiple first text segments based on the keywords. For example, the keywords "Xiao Lan", "classmates" and "courses" are extracted from the semantic information "What classmates and courses does Xiao Lan have", and then a text search tool (such as Elasticsearch, etc.) is used to perform keyword matching retrieval in the first text segment. Search for text segments in which these keywords or some of the keywords appear at the same time in the first text segment, so as to preliminarily screen out a batch of multiple candidate text segments that may be related to the first text.
[0063] In one embodiment, the text retrieval model is obtained by fine-tuning a preset large language model, wherein a LoRA layer is inserted into the attention layer of the large language model, and the LoRA layer includes two low-rank matrices. LoRA (Low-Rank Adaptation of Large Language Models) is the low-rank adaptation of the large language model. Its main function is to freeze the parameters of the pre-trained model and only train a small number of trainable parameters when fine-tuning the large language model, that is, insert a trainable low-rank matrix into the large language model to simulate the effect of full parameter fine-tuning, so as to efficiently personalize the large language model and enable the large language model to better adapt to specific tasks or fields. It can be understood that the large language model in this embodiment is able to realize all the functions of the text retrieval model. The embodiment of the present invention further fine-tunes the large language model in order to improve the recognition accuracy of the large language model for the association relationship between entities in the text fragments in the database. Specifically, the fine-tuning process includes:
[0064] Step 201: Obtain at least one tag information corresponding to each text segment in a text library, wherein each tag information includes two entities in the corresponding text segment, an association relationship between the two entities, and position index information of the corresponding text segment in the text library, and the two entities in different tag information are different.
[0065] In this embodiment, it is first necessary to determine and obtain the tag information corresponding to each text segment in the text library, and the tag information can be edited and generated by the user in advance. In this embodiment, the tag information includes the entity of each text segment, the association relationship between entities, and the position index information of each text segment in the text library. For example, assume that there is a text segment A in the database, and the content of text segment A is "Xiao Ming and Xiao Hong are in the first grade of Hongqi Primary School. The daily courses include Chinese, mathematics, and physical education. Xiao Ming studies very hard and has won the title of "Three Good Students". First, it is necessary to extract the entities "Xiao Ming", "Xiao Hong" and "Hongqi Primary School" in text segment A, and then determine the relationship between each entity and text segment A, as shown below:
[0066]
[0067] At the same time, summary information of text segment A can be generated, and the summary information is: recording the school information of Xiaohong and Xiaoming.
[0068] Afterwards, the corpus information tag information can be generated. For example, the tag information in text segment A is:
[0069] The tag information is 1: entity (Xiao Ming, Hongqi Primary School), association relationship (attending), summary information (recording Xiao Hong and Xiao Ming’s school information), fragment index (XXX document, XXX chapter).
[0070] The tag information is 2: entity (Xiaohong, Hongqi Primary School), association relationship (attending), summary information (recording Xiaohong and Xiaoming’s school information), fragment index (XXX document, XXX chapter).
[0071] The tag information is 3: entity (Xiao Ming, Xiao Hong), association relationship (classmate), summary information (recording Xiao Hong and Xiao Ming’s school information), fragment index (XXX document, XXX chapter).
[0072] Step 202: In each round of fine-tuning, the original parameters of the large language model are fixed, and the tag information is input into the large language model so that the large language model learns the association relationship between entities corresponding to each text segment in the text library according to the tag information, and updates and optimizes the low-rank matrix of the LoRA layer according to the gradient information received from the loss function according to the back propagation algorithm, until the recognition accuracy of the large language model for the association relationship between entities reaches a preset threshold.
[0073] In each round of fine-tuning, the original parameters of the large language model are first fixed to ensure that the general language knowledge and patterns originally learned by the large language model will not be easily destroyed. Then, the multiple tag information obtained previously is input into the large language model. At this time, the large language model will learn the association between the entities corresponding to each text segment in the text library based on the tag information. For example, for the content describing the relationship between characters, the logic of event development, etc. in different text segments, the large language model will try to understand and summarize the rules.
[0074] While the large language model is learning, the gradient information from the loss function can be received according to the back-propagation algorithm, and the low-rank matrix of the LoRA layer can be updated and optimized. The loss function measures the difference between the output of the large language model and the expected output. The gradient information generated by this difference can be passed back to the LoRA layer through the back-propagation algorithm, so that the parameters of the low-rank matrix are adjusted in the direction of accurately extracting the relationship between entities. When the accuracy of the large language model in extracting the relationship between entities reaches the preset threshold, the fine-tuning process can be stopped. The preset threshold is a standard set in advance to measure whether the model performance meets the standard. When the large language model can accurately identify the entity relationship in the text fragment and meets the set requirements, it can be considered that the fine-tuning process is completed and the text retrieval model is obtained.
[0075] In addition, when a new text segment is added to the text library, after determining the tag information of the new text segment, the text retrieval model can be further fine-tuned according to step 201 and step 202.
[0076] Step 103: determine the similarity between the first text and each candidate text segment, and select at least one target text segment from the candidate text segments according to the similarity.
[0077] After screening out multiple candidate text segments, the similarity between the first text and each candidate text segment can be further determined. Specifically, first convert the first text into a first vector, and convert each candidate text segment into a corresponding second vector; then, determine the similarity between the first vector and each second vector, for example, determine the cosine similarity between the first vector and each second vector, or determine the Euclidean distance similarity between the first vector and each second vector. Finally, based on the similarity, screen out at least one target text segment from the candidate texts. For example, the 5 (or more, set according to actual needs) most relevant target text segments with the highest similarity can be selected by sorting by similarity.
[0078] Step 104: input the first text and the target text segment into a preset question-answering model, so that the question-answering model outputs an answer text corresponding to the first text.
[0079] After the target text segment is screened, the first text and the target text segment can be input into a preset question-answering model, so that the question-answering model can infer and summarize according to the target text segment, thereby outputting an answer text corresponding to the first text, wherein the question-answering model can use an existing question-answering model. Figure 2 As shown, Figure 2 A schematic diagram of a process for outputting an answer text provided in an embodiment of the present invention.
[0080] As described above, an embodiment of the present invention provides a text question-answering method. After receiving a first text input by a user, the embodiment of the present invention inputs the first text into a text retrieval model, so that the text retrieval model extracts the semantic information of the first text and the first association relationship between the first entity, and then retrieves multiple candidate text fragments in the text library according to a pre-constructed knowledge graph, so as to facilitate the subsequent inference of answer texts related to the first text based on the candidate text fragments. The embodiment of the present invention extracts the semantic information and entity relationships of the first text through a text retrieval model, and retrieves related candidate text fragments in the database based on the semantic information and entity relationships. This can provide more comprehensive and accurate text fragment retrieval results, improve the accuracy of subsequent inference of answer texts related to the first text, and improve the user experience. At the same time, it can also reduce the number of retrieved text fragments, reduce the time for analyzing and integrating text fragments, and further reduce answer delays.
[0081] In addition, in the embodiment of the present invention, the method of fine-tuning the large language model through the LoRA method to obtain the text retrieval model only needs to adjust a small number of parameters, which greatly reduces the consumption of computing and storage resources. At the same time, since the text retrieval model is built based on the large language model, it has strong generalization ability and adaptability, and can flexibly respond to various new knowledge and needs. When new text fragments are added to the text library, the LoRA method can be used to further fine-tune the text retrieval model without retraining the entire text retrieval model, so as to achieve continuous learning and seamless updating.
[0082] The embodiment of the present invention also provides a text question-answering device, such as Figure 3 As shown, Figure 3 A structural diagram of a text question-answering device provided by an embodiment of the present invention is shown in FIG. Figure 3 As shown, the text question answering device includes:
[0083] The text receiving module 301 is used to receive a first text;
[0084] A fragment retrieval module 302 is used to input the first text into a preset text retrieval model, and the text retrieval model is used to determine semantic information of the first text, a first entity, and a first association relationship between the first entities, and retrieve multiple candidate text fragments associated with the first text in the text library according to the semantic information, the first entity, the first association relationship, and a knowledge graph pre-constructed with text fragments in the text library as objects, wherein the knowledge graph includes different entities and association relationships between different entities;
[0085] A segment screening module 303 is used to determine the similarity between the first text and each candidate text segment, and screen out at least one target text segment from the candidate text segments according to the similarity;
[0086] The answer output module 304 is used to input the first text and the target text segment into a preset question-answering model so that the question-answering model outputs an answer text corresponding to the first text.
[0087] Among them, the text retrieval model constructs a first query statement according to the first entity and the first association relationship, and searches for a second entity associated with the first entity through the first association relationship in a knowledge graph pre-constructed with text fragments in the text library according to the first query statement; determines a derived association relationship according to the first association relationship, constructs a second query statement according to the first entity and the derived association relationship, and searches for a third entity associated with the first entity through the derived association relationship in the knowledge graph according to the second query statement; obtains multiple related first text fragments in the text library according to the first entity, the second entity and the third entity; and screens out multiple candidate text fragments from the multiple first text fragments according to semantic information.
[0088] The text retrieval model determines keywords based on semantic information, and matches multiple corresponding candidate text segments in multiple first text segments based on the keywords.
[0089] The text retrieval model is obtained by fine-tuning a preset large language model. A LoRA layer is inserted into the attention layer of the large language model. The LoRA layer includes two low-rank matrices. The text question-answering device also includes:
[0090] a tag information acquisition module, used to acquire at least one tag information corresponding to each text segment in the text library, each tag information includes two entities in the corresponding text segment, an association relationship between the two entities, and position index information of the corresponding text segment in the text library, and the two entities in different tag information are different;
[0091] The model fine-tuning module is used to fix the original parameters of the large language model in each round of fine-tuning, input the tag information into the large language model, so that the large language model learns the association relationship between entities corresponding to each text fragment in the text library according to the tag information, and updates and optimizes the low-rank matrix of the LoRA layer according to the gradient information received from the loss function according to the back-propagation algorithm, until the recognition accuracy of the large language model for the association relationship between entities reaches a preset threshold.
[0092] Among them, the fragment screening module includes:
[0093] A vector conversion submodule, used to convert the first text into a first vector, and convert each candidate text segment into a corresponding second vector;
[0094] A similarity determination submodule, used to determine the similarity between the first vector and each second vector;
[0095] The target segment determination module is used to select at least one target text segment from the candidate texts based on similarity.
[0096] The similarity determination submodule is specifically used to determine the cosine similarity between the first vector and each second vector.
[0097] The text question and answer apparatus provided in the embodiment of the present invention is included in a text question and answer device, and can be used to execute the text question and answer method provided in the above embodiment, and has corresponding functions and beneficial effects.
[0098] It is worth noting that in the embodiment of the above-mentioned text question and answer device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0099] This embodiment also provides a text question-answering device, such as Figure 4 As shown, Figure 4 A structural diagram of a text question-answering device provided in an embodiment of the present invention, wherein the text question-answering device 40 includes a processor 400 and a memory 401;
[0100] The memory 401 is used to store the computer program 402 and transmit the computer program 402 to the processor 400;
[0101] The processor 400 is used to execute the steps in the above-mentioned text question answering method embodiment according to the instructions in the computer program 402.
[0102] Exemplarily, the computer program 402 may be divided into one or more modules / units, one or more modules / units are stored in the memory 401, and are executed by the processor 400 to complete the present application. One or more modules / units may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program 402 in the text question answering device 40.
[0103] The text question answering device 40 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The text question answering device 40 may include, but is not limited to, a processor 400 and a memory 401. Those skilled in the art will appreciate that Figure 4 This is only an example of the text question and answer device 40 and does not constitute a limitation of the text question and answer device 40. The text question and answer device 40 may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the text question and answer device 40 may also include input and output devices, network access devices, buses, etc.
[0104] The processor 400 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0105] The memory 401 may be an internal storage unit of the text question and answer device 40, such as a hard disk or memory of the text question and answer device 40. The memory 401 may also be an external storage device of the text question and answer device 40, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the text question and answer device 40. Further, the memory 401 may also include both an internal storage unit and an external storage device of the text question and answer device 40. The memory 401 is used to store computer programs and other programs and data required by the text question and answer device 40. The memory 401 may also be used to temporarily store data that has been output or is to be output.
[0106] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0107] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0108] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0109] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0110] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store computer programs.
[0111] An embodiment of the present invention further provides a storage medium containing computer executable instructions. When the computer executable instructions are executed by a computer processor, they are used to perform a text question answering method. The method includes the following steps:
[0112] receiving a first text;
[0113] Inputting the first text into a preset text retrieval model, using the text retrieval model to determine semantic information of the first text, a first entity, and a first association relationship between the first entities, and searching the text library for multiple candidate text segments associated with the first text based on the semantic information, the first entity, the first association relationship, and a knowledge graph pre-constructed with text segments in the text library as objects, wherein the knowledge graph includes different entities and association relationships between different entities;
[0114] Determine the similarity between the first text and each candidate text segment, and select at least one target text segment from the candidate text segments according to the similarity;
[0115] The first text and the target text segment are input into a preset question-answering model so that the question-answering model outputs an answer text corresponding to the first text.
[0116] In some possible implementations, various aspects of the method provided in this application may also be implemented in the form of a program product, which includes a program code. When the program product is run on a computer device, the program code is configured to enable the computer device to execute the steps of the method according to various exemplary embodiments of the present application described above in this specification. For example, the computer device may execute the text question answering method described in the embodiment of this application. The program product may be implemented in any combination of one or more readable media.
[0117] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the embodiments of the present invention are not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the protection scope of the embodiments of the present invention. Therefore, although the embodiments of the present invention are described in more detail through the above embodiments, the embodiments of the present invention are not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the embodiments of the present invention, and the scope of the embodiments of the present invention is determined by the scope of the appended claims.< / offers>
Claims
1. A text question answering method, characterized in that: The method comprises: receiving a first text; Inputting the first text into a preset text retrieval model, for the text retrieval model to determine semantic information of the first text, a first entity, and a first association relationship between the first entities, and searching the text library for a plurality of candidate text segments associated with the first text based on the semantic information, the first entity, the first association relationship, and a knowledge graph pre-constructed with text segments in a text library as objects, wherein the knowledge graph includes different entities and association relationships between different entities; Determine the similarity between the first text and each of the candidate text segments, and select at least one target text segment from the candidate text segments according to the similarity; The first text and the target text segment are input into a preset question-answering model so that the question-answering model outputs an answer text corresponding to the first text.
2. The text question answering method according to claim 1, characterized in that: The step of retrieving a plurality of candidate text segments associated with the first text in the text library according to the semantic information, the first entity, the first association relationship, and a knowledge graph pre-constructed with text segments in the text library as objects includes: Constructing a first query statement according to the first entity and the first association relationship, and searching for a second entity associated with the first entity through the first association relationship in a knowledge graph pre-constructed with text fragments in a text library as objects according to the first query statement; Determine a derived association relationship according to the first association relationship, construct a second query statement according to the first entity and the derived association relationship, and query the knowledge graph for a third entity associated with the first entity through the derived association relationship according to the second query statement; According to the first entity, the second entity and the third entity, acquiring a plurality of related first text segments in the text library; A plurality of candidate text segments are screened out from the plurality of first text segments according to the semantic information.
3. The text question answering method according to claim 2, characterized in that: The matching of a plurality of corresponding candidate text segments among a plurality of the first text segments according to the semantic information includes: A keyword is determined according to the semantic information, and a plurality of corresponding candidate text segments are matched among the plurality of first text segments according to the keyword.
4. The text question answering method according to claim 1, characterized in that: The text retrieval model is obtained by fine-tuning a preset large language model, wherein a LoRA layer is inserted into the attention layer of the large language model, and the LoRA layer includes two low-rank matrices. The fine-tuning process includes: Acquire at least one tag information corresponding to each text segment in the text library, wherein each tag information includes two entities in the corresponding text segment, an association relationship between the two entities, and position index information of the corresponding text segment in the text library, and the two entities in different tag information are different; In each round of fine-tuning, the original parameters of the large language model are fixed, and the tag information is input into the large language model so that the large language model learns the association relationship between the entities corresponding to each of the text fragments in the text library according to the tag information, and updates and optimizes the low-rank matrix of the LoRA layer according to the back-propagation algorithm by receiving the gradient information from the loss function until the recognition accuracy of the large language model for the association relationship between the entities reaches a preset threshold.
5. The text question answering method according to claim 1, characterized in that: Determining the similarity between the first text and each of the candidate text segments, and selecting at least one target text segment from the candidate text segments according to the similarity, includes: Convert the first text into a first vector, and convert each of the candidate text segments into a corresponding second vector; determining a similarity between the first vector and each of the second vectors; At least one target text segment is selected from the candidate texts based on the similarity.
6. The text question answering method according to claim 5, characterized in that: The determining the similarity between the first vector and each of the second vectors comprises: A cosine similarity between the first vector and each of the second vectors is determined.
7. A text question-answering device, characterized in that: The text question-answering device comprises: A text receiving module, used for receiving a first text; a fragment retrieval module, used to input the first text into a preset text retrieval model, and use the text retrieval model to determine semantic information of the first text, a first entity, and a first association relationship between the first entities, and retrieve multiple candidate text fragments associated with the first text in the text library based on the semantic information, the first entity, the first association relationship, and a knowledge graph pre-constructed with text fragments in a text library as objects, wherein the knowledge graph includes different entities and association relationships between different entities; A segment screening module, used to determine the similarity between the first text and each of the candidate text segments, and screen out at least one target text segment from the candidate text segments according to the similarity; An answer output module is used to input the first text and the target text segment into a preset question-answering model so that the question-answering model outputs an answer text corresponding to the first text.
8. A text question-answering device, characterized in that: The text question answering device includes a processor and a memory; The memory is used to store a computer program and transmit the computer program to the processor; The processor is configured to execute the text question answering method according to any one of claims 1 to 6 according to the instructions in the computer program.
9. A storage medium storing computer executable instructions, characterized in that: When the computer executable instructions are executed by a computer processor, they are used to perform the text question answering method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the text question answering method according to any one of claims 1 to 6 is implemented.