Question and answer method and device, computer equipment and storage medium

CN119377366APending Publication Date: 2025-01-28PING AN TECH (SHENZHEN) CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411504972.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-24
Publication Date
2025-01-28

Smart Images

  • Figure CN119377366A_ABST
    Figure CN119377366A_ABST
Patent Text Reader

Abstract

The embodiment of the invention belongs to the field of artificial intelligence, and relates to a question and answer method which comprises the following steps: performing topic classification based on named entities in a user query statement to obtain a topic to which the user query statement belongs; obtaining all documents under the theme, and calculating a correlation score between the user query statement and all paragraphs in all the documents; target paragraphs are selected from all paragraphs according to the obtained correlation scores, all the target paragraphs are combined with user query statements and then input into a question and answer model, and initial reply results corresponding to all the target paragraphs are obtained; calculating a first score of the initial reply result corresponding to each target paragraph based on a character string matching algorithm, and calculating a second score of the initial reply result corresponding to each target paragraph according to the correlation score corresponding to each target paragraph and the first score; and determining a reply result corresponding to the user query statement from the initial reply results according to the obtained second score. The user question answering accuracy is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a question-answering method, apparatus, computer device, and storage medium. Background Art

[0002] Existing question-answering systems are mainly divided into two types: knowledge-based question-answering and generative model-based question-answering. Knowledge-based question-answering systems rely on pre-built question-answer pairs and provide answers through similarity matching. This method is relatively direct, but there are problems such as high cost of knowledge base construction and limited coverage. Many questions raised by users may not be matched in the knowledge base. With the rapid update of knowledge, such as the update and iteration of knowledge in the fields of finance and medicine, maintaining the knowledge base also requires a lot of resources.

[0003] The question-answering system based on the generative model generates answers through a large amount of training data, breaking away from the limitations of the knowledge base. However, this question-answering system lacks controllability, and the generated answers are sometimes not directly related to the questions, and may even deviate from the questions. The generative model tends to generate safe but meaningless answers, such as "OK". In addition, the generative model also needs to be updated and retrained frequently, with high maintenance costs and limited adaptability to the latest knowledge. It can be seen that the existing question-answering system has shortcomings in accuracy. Summary of the invention

[0004] The purpose of the embodiments of the present application is to provide a question-answering method, apparatus, computer device, and storage medium to solve the problem of low accuracy of the question-answering system.

[0005] In order to solve the above technical problems, the embodiment of the present application provides a question-answering method, which adopts the following technical solution:

[0006] Get the user query statement;

[0007] Classifying the user query statement by subject based on the named entities in the user query statement to obtain the subject to which the user query statement belongs;

[0008] Obtain all documents under the topic, and calculate the relevance scores between the user query statement and all paragraphs in all the documents;

[0009] Selecting target paragraphs from all the paragraphs according to the obtained relevance scores, and combining each target paragraph with the user query sentence and inputting the result into the question-answering model to obtain the initial answer result corresponding to each target paragraph;

[0010] Calculate a first score of the initial response result corresponding to each target paragraph based on a string matching algorithm, and calculate a second score of the initial response result corresponding to each target paragraph according to the relevance score corresponding to each target paragraph and the first score;

[0011] The answer result corresponding to the user query statement is determined from each initial answer result according to the obtained second score.

[0012] In order to solve the above technical problems, the embodiment of the present application further provides a question-answering device, which adopts the following technical solution:

[0013] A statement acquisition module is used to acquire user query statements;

[0014] A topic classification module, used to classify the user query statement based on the named entities in the user query statement to obtain the topic to which the user query statement belongs;

[0015] A score calculation module, used to obtain all documents under the topic and calculate the relevance score between the user query statement and all paragraphs in all the documents;

[0016] A question-answering input module, used to select a target paragraph from all the paragraphs according to the obtained relevance score, and combine each target paragraph with the user query sentence and input the result into the question-answering model to obtain an initial answer result corresponding to each target paragraph;

[0017] A score calculation module, used to calculate a first score of the initial reply result corresponding to each target paragraph based on a string matching algorithm, and calculate a second score of the initial reply result corresponding to each target paragraph according to the relevance score corresponding to each target paragraph and the first score;

[0018] A result determination module is used to determine the response result corresponding to the user query statement from each initial response result according to the obtained second score.

[0019] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:

[0020] Get the user query statement;

[0021] Classifying the user query statement by subject based on the named entities in the user query statement to obtain the subject to which the user query statement belongs;

[0022] Obtain all documents under the topic, and calculate the relevance scores between the user query statement and all paragraphs in all the documents;

[0023] Selecting target paragraphs from all the paragraphs according to the obtained relevance scores, and combining each target paragraph with the user query sentence and inputting the result into the question-answering model to obtain the initial answer result corresponding to each target paragraph;

[0024] Calculate a first score of the initial response result corresponding to each target paragraph based on a string matching algorithm, and calculate a second score of the initial response result corresponding to each target paragraph according to the relevance score corresponding to each target paragraph and the first score;

[0025] The answer result corresponding to the user query statement is determined from each initial answer result according to the obtained second score.

[0026] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:

[0027] Get the user query statement;

[0028] Classifying the user query statement by subject based on the named entities in the user query statement to obtain the subject to which the user query statement belongs;

[0029] Obtain all documents under the topic, and calculate the relevance scores between the user query statement and all paragraphs in all the documents;

[0030] Selecting target paragraphs from all the paragraphs according to the obtained relevance scores, and combining each target paragraph with the user query sentence and inputting the result into the question-answering model to obtain the initial answer result corresponding to each target paragraph;

[0031] Calculate a first score of the initial response result corresponding to each target paragraph based on a string matching algorithm, and calculate a second score of the initial response result corresponding to each target paragraph according to the relevance score corresponding to each target paragraph and the first score;

[0032] The answer result corresponding to the user query statement is determined from each initial answer result according to the obtained second score.

[0033] Compared with the prior art, the embodiments of the present application mainly have the following beneficial effects: through the topic classification based on named entities, the core topic of the user query is accurately locked, the search space is reduced, and the retrieval accuracy of related documents is improved; then the correlation between the user query statement and the document paragraphs of all documents under the topic is calculated, and several paragraphs that best match the user query are accurately selected from the massive information; these target paragraphs are combined with the user query statement and input into the question-answering model to generate targeted initial reply results; the score optimization mechanism based on the string matching algorithm can add a first score to the initial reply result, and then combined with the relevance score of each target paragraph and the generated first score, it can effectively filter out low-quality answers, ensure that the final selected reply result is the most relevant to the user query statement, and improve the accuracy of questions and answers. The application of topic classification and knowledge base also effectively reduces the phenomenon of answer deviation problems that are common in generative question-answering models. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0035] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;

[0036] Figure 2 is a flow chart of an embodiment of the question-answering method according to the present application;

[0037] Figure 3 is a schematic structural diagram of an embodiment of a question-answering device according to the present application;

[0038] Figure 4 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION

[0039] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.

[0040] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0041] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.

[0042] like Figure 1 As shown, the system architecture 100 may include a terminal device 101, a network 102 and a server 103. The terminal device 101 may be a laptop 1011, a tablet computer 1012 or a mobile phone 1013. The network 102 is used to provide a medium for a communication link between the terminal device 101 and the server 103. The network 102 may include various connection types, such as wired, wireless communication links or optical fiber cables.

[0043] The user can use the terminal device 101 to interact with the server 103 through the network 102 to receive or send messages, etc. Various communication client applications can be installed on the terminal device 101, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0044] The terminal device 101 can be any electronic device with a display screen and supporting web browsing. In addition to a laptop computer 1011, a tablet computer 1012 or a mobile phone 1013, the terminal device 101 can also be an e-book reader, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV), a laptop computer, a desktop computer, etc.

[0045] The server 103 may be a server that provides various services, such as a background server that provides support for a web page displayed on the terminal device 101 .

[0046] It should be noted that the question-and-answer method provided in the embodiment of the present application is generally executed by a server, and accordingly, the question-and-answer device is generally arranged in the server.

[0047] It should be understood that Figure 1The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to the implementation requirements.

[0048] Continue to refer Figure 2 , shows a flow chart of an embodiment of a question-answering method according to the present application. The question-answering method comprises the following steps:

[0049] Step S201, obtaining a user query statement.

[0050] In this embodiment, the electronic device (eg Figure 1 The server shown in the figure) can communicate with the terminal device through a wired connection or a wireless connection. It should be noted that the above wireless connection method may include but is not limited to 3G / 4G / 5G connection, WiFi connection, Bluetooth connection, WiMAX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.

[0051] Specifically, the server obtains a user query statement input by the user through the terminal device.

[0052] Step S202: subject-classify the user query statement based on the named entities in the user query statement to obtain the subject to which the user query statement belongs.

[0053] Specifically, the named entities in the user's query are identified, and then the core topics involved in the user's query are determined based on the named entities. Named entities refer to certain key proper nouns, such as names of people, places, medical terms, etc. Through named entity recognition, the question-answering system can extract these key entities and use them to classify topics, ensuring that the system calls the correct document set based on the query topic.

[0054] Step S203, obtaining all documents under the topic, and calculating the relevance scores between the user query statement and all paragraphs in all documents.

[0055] Specifically, all documents related to the topic are obtained from the predefined knowledge base (KB), and the relevance analysis is performed on the user query and each paragraph in the document. The question-answering system determines the relevance of each paragraph to the user query by calculating the similarity between the words in the user query and the words in the paragraph, and combining the TF-IDF (term frequency-inverse document frequency) score of the words in the paragraph.

[0056] Step S204, select target paragraphs from all paragraphs according to the obtained relevance scores, and combine each target paragraph with the user query sentence and input it into the question-answering model to obtain the initial answer result corresponding to each target paragraph.

[0057] Specifically, the question-answering system will select the paragraphs that are most relevant to the user's query based on the calculated relevance score. It can be assumed that the higher the relevance score, the more relevant the user's query is to the paragraph. The K paragraphs with the highest relevance scores can be selected, and the paragraphs corresponding to the selected relevance scores can be used as target paragraphs. The selected target paragraphs can be combined with the user's query and input into the question-answering model to generate the initial response results for each target paragraph.

[0058] The question-answering model is a generative question-answering model that can be built based on various large-scale pre-trained language models.

[0059] Step S205, calculating the first score of the initial response result corresponding to each target paragraph based on the string matching algorithm, and calculating the second score of the initial response result corresponding to each target paragraph according to the relevance score corresponding to each target paragraph and the first score.

[0060] Specifically, the question-answering system further evaluates the initial answer results corresponding to each target paragraph through a string matching algorithm, for example, by comparing similar parts (such as the longest common substring) in each initial answer result to give a first score. Then, the question-answering system combines the relevance score between the paragraph and the user's query statement and the first score to calculate a second score for each initial answer result, so as to more accurately evaluate each initial answer result.

[0061] Step S206, determining the response result corresponding to the user query statement from each initial response result according to the obtained second score.

[0062] Specifically, the question-answering system selects the second highest score from all initial answer results as the final answer result, and sends the answer result to the terminal device held by the user.

[0063] In this embodiment, through the topic classification based on named entities, the core topic of the user query is accurately locked, the search space is reduced, and the retrieval accuracy of related documents is improved; then the correlation between the user query statement and the document paragraphs of all documents under the topic is calculated, and several paragraphs that best match the user query are accurately selected from the massive information; these target paragraphs are combined with the user query statement and input into the question-answering model to generate targeted initial reply results; the score optimization mechanism based on the string matching algorithm can add a first score to the initial reply result, and then combined with the relevance score of each target paragraph and the generated first score, low-quality answers can be effectively filtered out to ensure that the final selected reply result is the most relevant to the user query statement, thereby improving the accuracy of questions and answers. The application of topic classification and knowledge base also effectively reduces the phenomenon of answer deviation problems that are common in generative question-answering models.

[0064] Furthermore, the above step S202 may include: performing entity extraction on the user query statement to obtain named entities in the user query statement; converting the user query statement into a sentence vector, and converting each named entity into an entity vector respectively; performing an average pooling operation on the entity vector of each named entity to obtain an average feature vector; concatenating the sentence vector and the average feature vector to obtain a concatenated vector; and inputting the concatenated vector into a topic classifier to obtain the topic to which the user query statement belongs.

[0065] Specifically, the user query is segmented, and then the named entity recognition model is used to extract entities to identify key named entities in the query (such as names of people, places, organizations, medical terms, etc.). Named entity extraction helps to identify the core information in the user query.

[0066] The user query is converted into a sentence vector representation, and each identified named entity is converted into an entity vector. The sentence vector is a global semantic representation of the query, and the entity vector reflects the specific semantic information of the named entity. In one embodiment, the user query and each named entity can be input into a pre-trained language model to obtain a sentence vector and an entity vector.

[0067] Perform average pooling on all entity vectors. Average pooling takes the average value of each entity vector to generate a comprehensive feature representation, and obtains an average feature vector, which is used to represent the overall information of the named entity in the query statement.

[0068] The sentence vector is concatenated with the average feature vector to combine the global semantic information with the named entity information to form a more comprehensive semantic representation and obtain the concatenated vector. The concatenated vector contains both the overall semantics of the user query and the information of important named entities in the user query.

[0069] The concatenated vector is input into a topic classifier. The topic classifier classifies the concatenated vector through a pre-trained model and outputs the topic category to which the user query statement belongs. In another embodiment, the topic classifier can be an MLP layer, and the MLP layer can be a 1536*c matrix, where c is the number of topics. The topic classifier predicts which topic the user query statement belongs to based on the concatenated vector.

[0070] In this embodiment, named entities in user query statements are identified through entity extraction, providing support for topic classification; entity vectors ensure that the semantic information of named entities is accurately captured, and the use of sentence vectors retains the contextual information of the entire user query statement; after splicing the average feature vector of the named entity with the sentence vector, the multi-dimensional semantic features of the user query statement can be better expressed. This multi-level semantic fusion method makes the system more accurate in topic classification; the spliced ​​vector is input into the topic classifier to quickly and efficiently classify the user query statement, providing precise guidance for subsequent document retrieval.

[0071] Furthermore, the above step of calculating the relevance score between the user query statement and all paragraphs in all documents may include: obtaining all words in all documents and the TF-IDF score of each word in the corresponding paragraph from a preset knowledge base; for each first participle in the user query statement, calculating the similarity between the first participle and all words; taking each paragraph in all documents as a unit, calculating the participle score of the first participle in the paragraph according to the similarity between the first participle and each word in the paragraph and the TF-IDF score of each word in the paragraph; and calculating the relevance score between the user query statement and the paragraph according to the participle score of each first participle in the user query statement in the paragraph.

[0072] Specifically, after topic prediction, all documents under the current topic can be retrieved through the preset knowledge base, narrowing the search scope to search only in documents under the current topic to ensure relevance to the user's query statement.

[0073] The knowledge base adopts a tree-like storage structure, with its root node as the topic, the first-level leaf nodes as the document names of all documents under the current topic, the second-level leaf nodes as all the words under the current document, and the third level as the paragraph number of the document corresponding to each word, as well as the TF-IDF score of the current word in the paragraph to which it belongs; the TF-IDF score reflects the importance of the word in the paragraph to which it belongs. When storing the knowledge base, in order to speed up retrieval efficiency, the root node and all the words in the first and second layers are stored as word vectors, which are also obtained through pre-trained language models.

[0074] Get all the words in all documents under the topic from the knowledge base, as well as the TF-IDF score of each word in the paragraph to which it belongs. The TF-IDF score reflects the importance of the word in the paragraph to which it belongs. A high TF-IDF score means that the word is more important to the paragraph.

[0075] In the present application, after the user query is segmented, multiple first segmentations are obtained. For each first segmentation, the similarity between the first segmentation and all the words obtained from the knowledge base is calculated. The similarity can be implemented based on the word vector model to calculate the semantic similarity between the first segmentation and the words.

[0076] The documents under a topic have multiple paragraphs. Taking each paragraph as a unit, the semantic similarity between the first participle and each word in the paragraph is obtained. Based on the similarity between each first participle and the words in the paragraph and the TF-IDF scores of these words, the participle score of the first participle in the paragraph is calculated.

[0077] For each first participle in the user query, the participle score of the first participle in a certain paragraph can be calculated in the above manner, and the participle scores of the first participles in the user query are accumulated to obtain the relevance score of the user query and the paragraph.

[0078] The calculation process in this embodiment ensures that it not only relies on the frequency of occurrence of words (TF-IDF), but also adds the calculation of semantic similarity, which improves the matching accuracy between user query sentences and paragraphs. Words with high similarity and high TF-IDF scores contribute more to the overall relevance.

[0079] In this embodiment, the similarity between the first word in the user query statement and the vocabulary in the document, as well as the TF-IDF score of the vocabulary, is combined to improve the accuracy of the calculation of the correlation score between the user query statement and the document paragraphs, and better identify the paragraphs that match the surface vocabulary and are closely related to the user query statement semantically; avoid the problem of ignoring semantic associations when using only TF-IDF, and avoid the shortcoming of ignoring the importance of vocabulary when calculating the similarity alone; combine the two to achieve more accurate paragraph matching, ensuring the accuracy of the question-answering system.

[0080] Furthermore, the step of calculating the word segmentation score of the first participle in the paragraph based on the similarity between the first participle and each word in the paragraph and the TF-IDF score of each word in the paragraph may include: for each word in the paragraph, obtaining a first weight corresponding to the similarity between the first participle and the word, and obtaining a second weight corresponding to the TF-IDF score of the word in the paragraph; performing weighted summation of the similarity between the first participle and the word and the TF-IDF score of the word in the paragraph based on the first weight and the second weight to obtain a weighted score of the first participle and the word; and adding the weighted scores of the first participle and each word in the paragraph to obtain a word segmentation score of the first participle in the paragraph.

[0081] Specifically, for each word in the paragraph, the similarity between the first participle and the word, as well as the TF-IDF score of the word in the paragraph, have been obtained. The similarity and TF-IDF score have a pre-set first weight and second weight, respectively. The first weight emphasizes the semantic relationship between the first participle and the word, while the second weight emphasizes the amount of information about the word in the paragraph.

[0082] According to the first weight and the second weight, the similarity between the first participle and the vocabulary and the TF-IDF score of the vocabulary in the paragraph are weighted and summed to obtain the weighted score of the first participle and the vocabulary. The weighted score comprehensively considers the similarity between the first participle and the vocabulary and the importance of the vocabulary in the paragraph. Then, the weighted scores of the first participle and each vocabulary in the paragraph are accumulated to obtain the participle score of the first participle in the paragraph. This score reflects the importance of the first participle in the entire paragraph and provides basic data for the overall relevance score of the user query.

[0083] In one embodiment, the weight of the similarity between the first participle and the vocabulary is 75%, the weight of the TF-IDF score of the vocabulary is 25%, and the participle score of the first participle in the paragraph is obtained based on the weighted sum.

[0084] In this embodiment, by combining similarity and TF-IDF score with weights, not only the semantic relationship of word segmentation is considered, but also the actual contribution of vocabulary in the paragraph is quantified. This weighting method makes the model more comprehensive and detailed when evaluating the importance of word segmentation.

[0085] Furthermore, the above-mentioned step of combining each target paragraph with the user query statement and then inputting the result into the question-answering model may include: obtaining a preset question template; for each target paragraph, filling the target paragraph into the question template as prompt information, and filling the user query statement into the question template as the target statement; and inputting the filled-in question template into the question-answering model.

[0086] Specifically, the question template, as the skeleton structure of the model input, usually contains a fixed question format and placeholders for inserting the target paragraph and user query statement. The design of the template can vary according to the actual application requirements, and may include the common format of question-answering dialogues, such as: "Based on the following information, answer the following questions:".

[0087] The target paragraph is a text segment that is highly relevant to the user's query. As additional context information, it can help the question-answering model provide more accurate answers. When filling in the question template, the target paragraph is placed in the prompt position to ensure that it is relevant to the user's query.

[0088] The user query is the question that the model needs to answer, and it is filled into the question template as the core content. Through this operation, the question-answering model can receive both the question itself and the corresponding background information (target paragraph) at the same time, so as to generate answers in a richer context.

[0089] In one embodiment, the completed question template is as follows: Referring to the content of [target paragraph], what is the answer corresponding to [user query statement]?

[0090] The completed question template is input into the question-answering model, which generates answers relevant to the question based on the provided target paragraph and user query.

[0091] In this embodiment, by using a preset question template, the target paragraph and the user query statement are filled into the template respectively and then input into the question-answering model, thereby improving the accuracy and contextual relevance of the answer; by adding the target paragraph to the question template, the question-answering model can better understand the background of the question and avoid vague or inaccurate answers that may be caused by relying solely on the user query statement; the question template standardizes and structures the question-answering process, helps to improve the controllability and output quality of the question-answering model, and enhances the overall performance and user experience of the question-answering system.

[0092] Furthermore, the above-mentioned step of calculating the first score of the initial reply result corresponding to each target paragraph based on the string matching algorithm may include: combining the initial reply results corresponding to each target paragraph in pairs to obtain multiple reply result pairs; for each reply result pair, calculating the maximum common substring length of the two initial reply results in the reply result according to the string matching algorithm; calculating the first candidate score of the reply result pair according to the result length of the two initial reply results in the reply result pair and the maximum common substring length; for each initial reply result, selecting the largest first candidate score from the first candidate scores corresponding to the initial reply result as the first score of the initial reply result.

[0093] Specifically, for the initial answer results generated for each target paragraph, all the initial answer results are combined in pairs to form multiple answer result pairs, each of which represents two different initial answer results.

[0094] For each pair of reply results, a string matching algorithm (such as dynamic programming or the longest common subsequence algorithm) is used to calculate the length of the maximum common substring of the two initial reply results. The maximum common substring is the longest identical character sequence in the two strings, which can intuitively reflect the similarity between the two initial reply results.

[0095] The first candidate score of the answer result pair is generated based on the total length of the two initial answer results in the answer result pair (the total length is obtained by adding the text lengths of the two initial answer results) and the calculated maximum common substring length. A higher score indicates that the two initial answer results have more similarities in content.

[0096] For each initial reply result, the largest first candidate score is selected from all reply result pairs it participates in as the first score of the initial reply result, ensuring that each initial reply result can obtain the most favorable matching score compared with other results, thereby reflecting its similarity with other answers.

[0097] Through this scoring mechanism, the question-answering system can measure the reliability of the initial response results based on the similarities between the initial response results, providing a basis for subsequent comprehensive scoring and final result selection.

[0098] Furthermore, the first score is expressed as:

[0099]

[0100] Among them, S is the first candidate score of the answer result pair, l P is the maximum common substring length, l A is the result length of the first initial response result in the response result pair, l B The result length of the second initial reply result in a reply result pair.

[0101] In this embodiment, the first candidate score of the reply result pair is accurately calculated based on the maximum common substring length and the result lengths of the two initial reply results in the reply result pair.

[0102] In this embodiment, the similarity between each initial reply result is calculated to generate a first score, thereby improving the accuracy of the assessment of the quality of the initial reply result; the string matching algorithm provides an objective similarity measurement standard, which can quickly identify reply results with similar content, avoiding the potential bias of relying solely on model-generated results; when the reply results are relatively consistent, a high similarity score can confirm the accuracy of the generated answer; this similarity-based scoring mechanism can enhance the robustness of reply screening and make the final selected reply result more accurate.

[0103] It should be emphasized that in order to further ensure the privacy and security of the above documents, the above documents can also be stored in a blockchain node.

[0104] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.

[0105] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0106] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0107] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).

[0108] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0109] Further references Figure 3 , as a response to the above Figure 2 In order to realize the method shown in the figure, the present application provides an embodiment of a question-answering device, and the embodiment of the device is Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.

[0110] like Figure 3 As shown, the question-answering device 300 described in this embodiment includes: a sentence acquisition module 301, a topic classification module 302, a score calculation module 303, a question-answering input module 304, a score calculation module 305 and a result determination module 306, wherein:

[0111] The statement acquisition module 301 is used to acquire the user query statement.

[0112] The topic classification module 302 is used to perform topic classification on the user query sentence based on the named entities in the user query sentence to obtain the topic to which the user query sentence belongs.

[0113] The score calculation module 303 is used to obtain all documents under the topic and calculate the relevance scores between the user query statement and all paragraphs in all documents.

[0114] The question-answer input module 304 is used to select target paragraphs from all paragraphs according to the obtained relevance scores, and combine each target paragraph with the user query statement and input it into the question-answer model to obtain the initial response result corresponding to each target paragraph.

[0115] The score calculation module 305 is used to calculate the first score of the initial response result corresponding to each target paragraph based on the string matching algorithm, and calculate the second score of the initial response result corresponding to each target paragraph according to the relevance score corresponding to each target paragraph and the first score.

[0116] The result determination module 306 is used to determine the response result corresponding to the user query statement from each initial response result according to the obtained second score.

[0117] In this embodiment, through the topic classification based on named entities, the core topic of the user query is accurately locked, the search space is reduced, and the retrieval accuracy of related documents is improved; then the correlation between the user query statement and the document paragraphs of all documents under the topic is calculated, and several paragraphs that best match the user query are accurately selected from the massive information; these target paragraphs are combined with the user query statement and input into the question-answering model to generate targeted initial reply results; the score optimization mechanism based on the string matching algorithm can add a first score to the initial reply result, and then combined with the relevance score of each target paragraph and the generated first score, low-quality answers can be effectively filtered out to ensure that the final selected reply result is the most relevant to the user query statement, thereby improving the accuracy of questions and answers. The application of topic classification and knowledge base also effectively reduces the phenomenon of answer deviation problems that are common in generative question-answering models.

[0118] In some optional implementations of this embodiment, the topic classification module 302 may include:

[0119] The entity extraction submodule is used to extract entities from user query statements to obtain named entities in user query statements.

[0120] The conversion submodule is used to convert the user query sentence into a sentence vector and convert each named entity into an entity vector.

[0121] The average pooling submodule is used to perform an average pooling operation on the entity vectors of each named entity to obtain an average feature vector.

[0122] The vector concatenation submodule is used to concatenate the sentence vector and the average feature vector to obtain a concatenated vector.

[0123] The vector input submodule is used to input the concatenated vector into the topic classifier to obtain the topic to which the user query statement belongs.

[0124] In some optional implementations of this embodiment, the score calculation module 303 may include:

[0125] The vocabulary acquisition submodule is used to obtain all the words in all documents from the preset knowledge base, as well as the TF-IDF score of each word in its corresponding paragraph.

[0126] The similarity calculation submodule is used to calculate the similarity between each first word in the user query sentence and all the words.

[0127] The score calculation submodule is used to calculate the segmentation score of the first segmentation word in the paragraph based on the similarity between the first segmentation word and each word in the paragraph and the TF-IDF score of each word in the paragraph, taking each paragraph in all documents as a unit.

[0128] The score calculation submodule is used to calculate the relevance score between the user query statement and the paragraph according to the segmentation score of each first segmentation word in the paragraph in the user query statement.

[0129] In some optional implementations of this embodiment, the score calculation submodule may include:

[0130] The weight acquisition unit is used to acquire, for each word in the paragraph, a first weight corresponding to the similarity between the first word segment and the word, and to acquire a second weight corresponding to the TF-IDF score of the word in the paragraph.

[0131] The weighted summing unit is used to perform weighted summing of the similarity between the first participle and the vocabulary and the TF-IDF score of the vocabulary in the paragraph according to the first weight and the second weight, so as to obtain the weighted score of the first participle and the vocabulary.

[0132] The score adding unit is used to add the weighted scores of the first participle and each word in the paragraph to obtain the participle score of the first participle in the paragraph.

[0133] In some optional implementations of this embodiment, the question and answer input module 304 may include:

[0134] The template acquisition submodule is used to obtain the preset question template.

[0135] The template filling submodule is used to fill the target paragraph as prompt information into the question template for each target paragraph, and fill the user query sentence as the target sentence into the question template.

[0136] The template input submodule is used to input the filled question template into the question-answering model.

[0137] In some optional implementations of this embodiment, the score calculation module 305 may include:

[0138] The result combination submodule is used to combine the initial response results corresponding to each target paragraph in pairs to obtain multiple response result pairs.

[0139] The length calculation submodule is used to calculate the maximum common substring length of two initial response results in the response result for each response result pair according to the string matching algorithm.

[0140] The first calculation submodule is used to calculate the first candidate score of the reply result pair according to the result lengths of the two initial reply results in the reply result pair and the maximum common substring length.

[0141] The result selection submodule is used to select, for each initial reply result, the largest first candidate score from the first candidate scores corresponding to the initial reply result as the first score of the initial reply result.

[0142] In some optional implementations of this embodiment, the first score is expressed as:

[0143]

[0144] Among them, S is the first candidate score of the answer result pair, l P is the maximum common substring length, l A is the result length of the first initial response result in the response result pair, l B The result length of the second initial reply result in a reply result pair.

[0145] To solve the above technical problems, the present application also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.

[0146] The computer device 4 includes a memory 41, a processor 42, and a network interface 43 that are interconnected and communicated through a system bus. It should be noted that the figure only shows a computer device 4 with a memory 41, a processor 42, and a network interface 43, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.

[0147] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.

[0148] The memory 41 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 41 can be an internal storage unit of the computer device 4, such as a hard disk or memory of the computer device 4. In other embodiments, the memory 41 can also be an external storage device of the computer device 4, such as a plug-in hard disk equipped on the computer device 4, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Of course, the memory 41 can also include both the internal storage unit of the computer device 4 and its external storage device. In this embodiment, the memory 41 is generally used to store the operating system and various application software installed on the computer device 4, such as computer-readable instructions of the question-answering method, etc. In addition, the memory 41 can also be used to temporarily store various types of data that have been output or are to be output.

[0149] The processor 42 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip in some embodiments. The processor 42 is generally used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is used to run computer-readable instructions stored in the memory 41 or process data, such as computer-readable instructions for running the question-answering method.

[0150] The network interface 43 may include a wireless network interface or a wired network interface. The network interface 43 is generally used to establish a communication connection between the computer device 4 and other electronic devices.

[0151] The computer device provided in this embodiment can execute the above question-answering method. The question-answering method here can be the question-answering method of each of the above embodiments.

[0152] In this embodiment, through the topic classification based on named entities, the core topic of the user query is accurately locked, the search space is reduced, and the retrieval accuracy of related documents is improved; then the correlation between the user query statement and the document paragraphs of all documents under the topic is calculated, and several paragraphs that best match the user query are accurately selected from the massive information; these target paragraphs are combined with the user query statement and input into the question-answering model to generate targeted initial reply results; the score optimization mechanism based on the string matching algorithm can add a first score to the initial reply result, and then combined with the relevance score of each target paragraph and the generated first score, low-quality answers can be effectively filtered out to ensure that the final selected reply result is the most relevant to the user query statement, thereby improving the accuracy of questions and answers. The application of topic classification and knowledge base also effectively reduces the phenomenon of answer deviation problems that are common in generative question-answering models.

[0153] The present application also provides another implementation, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the question-and-answer method as described above.

[0154] In this embodiment, through the topic classification based on named entities, the core topic of the user query is accurately locked, the search space is reduced, and the retrieval accuracy of related documents is improved; then the correlation between the user query statement and the document paragraphs of all documents under the topic is calculated, and several paragraphs that best match the user query are accurately selected from the massive information; these target paragraphs are combined with the user query statement and input into the question-answering model to generate targeted initial reply results; the score optimization mechanism based on the string matching algorithm can add a first score to the initial reply result, and then combined with the relevance score of each target paragraph and the generated first score, low-quality answers can be effectively filtered out to ensure that the final selected reply result is the most relevant to the user query statement, thereby improving the accuracy of questions and answers. The application of topic classification and knowledge base also effectively reduces the phenomenon of answer deviation problems that are common in generative question-answering models.

[0155] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0156] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.

Claims

1. A question-answering method, characterized in that: The steps include: Get the user query statement; Classifying the user query statement by subject based on the named entities in the user query statement to obtain the subject to which the user query statement belongs; Obtain all documents under the topic, and calculate the relevance scores between the user query statement and all paragraphs in all the documents; Selecting target paragraphs from all the paragraphs according to the obtained relevance scores, and combining each target paragraph with the user query sentence and inputting the result into the question-answering model to obtain the initial answer result corresponding to each target paragraph; Calculate a first score of the initial response result corresponding to each target paragraph based on a string matching algorithm, and calculate a second score of the initial response result corresponding to each target paragraph according to the relevance score corresponding to each target paragraph and the first score; The answer result corresponding to the user query statement is determined from each initial answer result according to the obtained second score.

2. The question-answering method according to claim 1, characterized in that: The step of subject-classifying the user query based on the named entities in the user query to obtain the subject to which the user query belongs comprises: Performing entity extraction on the user query statement to obtain named entities in the user query statement; Convert the user query sentence into a sentence vector, and convert each named entity into an entity vector; Performing an average pooling operation on the entity vectors of each named entity to obtain an average feature vector; Concatenating the sentence vector and the average feature vector to obtain a concatenated vector; The concatenated vector is input into a topic classifier to obtain the topic to which the user query statement belongs.

3. The question-answering method according to claim 1, characterized in that: The step of calculating the relevance score between the user query statement and all paragraphs in all documents comprises: Obtain all the words in all the documents and the TF-IDF score of each word in the corresponding paragraph from the preset knowledge base; For each first participle in the user query, calculating the similarity between the first participle and the entire vocabulary; Taking each paragraph in all the documents as a unit, calculating the segmentation score of the first segmentation word in the paragraph according to the similarity between the first segmentation word and each word in the paragraph and the TF-IDF score of each word in the paragraph; A relevance score between the user query statement and the paragraph is calculated according to the segmentation score of each first segmentation word in the paragraph.

4. The question-answering method according to claim 3, characterized in that: The step of calculating the segmentation score of the first segmentation word in the paragraph according to the similarity between the first segmentation word and each word in the paragraph and the TF-IDF score of each word in the paragraph comprises: For each word in the paragraph, obtain a first weight corresponding to the similarity between the first word segment and the word, and obtain a second weight corresponding to the TF-IDF score of the word in the paragraph; According to the first weight and the second weight, weighted sum is performed on the similarity between the first participle and the vocabulary and the TF-IDF score of the vocabulary in the paragraph to obtain a weighted score of the first participle and the vocabulary; The first participle is added to the weighted score of each word in the paragraph to obtain the participle score of the first participle in the paragraph.

5. The question-answering method according to claim 1, characterized in that: The step of combining each target paragraph with the user query sentence and inputting the result into the question-answering model comprises: Get the preset question template; For each target paragraph, fill the target paragraph into the question template as prompt information, and fill the user query sentence into the question template as the target sentence; Input the completed question template into the question-answering model.

6. The question-answering method according to claim 1, characterized in that: The step of calculating the first score of the initial response result corresponding to each target paragraph based on the string matching algorithm comprises: Combining the initial response results corresponding to the target paragraphs in pairs to obtain multiple response result pairs; For each reply result pair, calculating the maximum common substring length of two initial reply results in the reply result according to the string matching algorithm; Calculate a first candidate score of the reply result pair according to the result lengths of the two initial reply results in the reply result pair and the maximum common substring length; For each initial reply result, the largest first candidate score is selected from the first candidate scores corresponding to the initial reply result as the first score of the initial reply result.

7. The question-answering method according to claim 1, characterized in that: The first score is expressed as: Among them, S is the first candidate score of the answer result pair, l P is the maximum common substring length, l A is the result length of the first initial response result in the response result pair, l B The result length of the second initial reply result in a reply result pair.

8. A question-answering device, characterized in that: include: A statement acquisition module is used to acquire user query statements; A topic classification module, used to classify the user query statement based on the named entities in the user query statement to obtain the topic to which the user query statement belongs; A score calculation module, used to obtain all documents under the topic and calculate the relevance score between the user query statement and all paragraphs in all the documents; A question-answering input module, used to select a target paragraph from all the paragraphs according to the obtained relevance score, and combine each target paragraph with the user query sentence and input the result into the question-answering model to obtain an initial answer result corresponding to each target paragraph; A score calculation module, used to calculate a first score of the initial reply result corresponding to each target paragraph based on a string matching algorithm, and calculate a second score of the initial reply result corresponding to each target paragraph according to the relevance score corresponding to each target paragraph and the first score; A result determination module is used to determine the response result corresponding to the user query statement from each initial response result according to the obtained second score.

9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the question-answering method according to any one of claims 1 to 7 when executing the computer-readable instructions.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the question-answering method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Geology operator organization and question and answer mode retrieval method and device based on large language model and knowledge graph

    CN120234390A