Answer generation method based on pre-training language model, product, medium and equipment

By calculating the semantic and keyword similarity between user problems and documents, combined with pre-trained language models, the problem of searching non-related documents in the prior art is solved, and more accurate answer search and higher user satisfaction are achieved.

CN120353903AInactive Publication Date: 2025-07-22INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510828623.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-19
Publication Date
2025-07-22
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In the prior art, the search-enhanced generation method based on large-scale pre-trained language models may retrieve documents that are not wanted by users as answers, resulting in poor user experience.

Method used

By obtaining user questions, document names, document keywords and text blocks, calculate semantic similarity and keyword similarity, determine the target document, and generate answers using pre-trained language models to ensure that the retrieved documents are highly relevant to user questions.

Benefits of technology

It improves the effectiveness of the pre-trained language model answering content, improves the user experience, ensures that the search results are more relevant to user questions, and reduces the search time for irrelevant content.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120353903A_ABST
    Figure CN120353903A_ABST
Patent Text Reader

Abstract

The invention discloses an answer generation method based on a pre-training language model, a product, a medium and equipment. The method comprises the steps of obtaining a target question proposed by a user, document names corresponding to a plurality of pre-stored documents, keywords corresponding to each document and text blocks correspondingly divided by each document; determining a target similarity corresponding to each document based on the target problem, the text block, the document name and the keyword; and determining a target document based on the target similarity, and determining a target answer based on the target document and a pre-training language model. According to the method, the finally retrieved document can be more related to the question input by the user, so that the effectiveness of the answer content of the pre-training language model is improved, and the user experience is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of natural language processing, and in particular, to a method, product, medium, and device for answer generation based on a pre-trained language model. Background Art

[0002] Currently, the retrieval-augmented generation technology based on large-scale pre-trained language models (referred to as large models for short) has become a research hotspot in the field of natural language processing. This technology combines external knowledge base retrieval with traditional generation-based large models, and uses the existing document knowledge within individuals, enterprises, etc. to solve the inherent defects of large models in terms of timeliness, domain specialization, and factual accuracy.

[0003] Generally, for the retrieval-augmented generation business process on a large model application development platform, first, users need to create a knowledge base and upload enterprise-internal documents to the knowledge base; when a user asks a question to the large model, it first passes through a retriever, and uses a corresponding retrieval method (such as semantic retrieval or keyword retrieval) to retrieve documents related to the question, and finally sends the retrieved content to the large model together. The large model will answer the question asked by the user based on this input knowledge.

[0004] However, the above method may retrieve answers from some documents with similar texts but actually not what the user wants as context information for the question and feed them to the large model. In this way, there will be a certain gap between the answer finally given by the large model and what the user actually wants, affecting the user experience. Summary of the Invention

[0005] This application provides a method, product, medium, and device for answer generation based on a pre-trained language model, which at least solves the problem in related technologies that when directly looking for relevant content among numerous vectorized text blocks, some answers from documents with similar texts but actually not what the user wants may be retrieved as context information for the question and fed to the large model. It can make the finally retrieved documents more relevant to the question input by the user, thereby improving the effectiveness of the answer content of the pre-trained language model and enhancing the user experience.

[0006] This application provides a method for answer generation based on a pre-trained language model, including: Obtaining a target question proposed by a user, document names corresponding to multiple pre-stored documents, keywords corresponding to each document, and text blocks divided for each document; Determining a target similarity corresponding to each document based on the target question, the text blocks, the document names, and the keywords; Determining a target document based on the target similarity, and determining a target answer based on the target document and the pre-trained language model.

[0007] The present application also provides a computer program product, including a computer program / instructions, which, when executed by a processor, implement the above-mentioned answer generation method based on a pre-trained language model.

[0008] The present application also provides a computer-readable storage medium, on which a program is stored, and when the program is executed by a processor, it implements the above-mentioned answer generation method based on a pre-trained language model.

[0009] The present application also provides an electronic device, including a memory, a processor, and a program stored on the memory and executable on the processor. When the processor executes the program, it implements the above-mentioned answer generation method based on a pre-trained language model.

[0010] Through the present application, a target question proposed by a user, document names corresponding to a plurality of pre-stored documents, keywords corresponding to each document, and text blocks divided for each document are obtained. Based on the target question and the text blocks, document names, and keywords, a target similarity corresponding to each document is determined. Based on the target similarity, a target document is determined, and based on the target document and a pre-trained language model, a target answer is determined. Thus, this method can make the finally retrieved document more relevant to the question input by the user, thereby improving the effectiveness of the answer content of the pre-trained language model and enhancing the user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] To more clearly illustrate the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0012] Figure 1 It is a flowchart of an answer generation method based on a pre-trained language model according to an embodiment of the present application; Figure 2 It is a flowchart of an answer generation method based on a pre-trained language model according to a specific example of the present application; Figure 3 It is a block diagram of an electronic device according to an embodiment of the present application.

[0013] Reference numerals: 200 - electronic device, 210 - memory, 220 - processor. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0014] Embodiments of the present application will be described in detail below. Examples of the embodiments are shown in the accompanying drawings, where the same or similar reference numerals represent the same or similar elements or elements with the same or similar functions throughout. The embodiments described below by referring to the accompanying drawings are exemplary and are intended to explain the present application and should not be construed as a limitation to the present application.

[0015] The method for generating answers based on a pre-trained language model, computer program product, computer-readable storage medium, and electronic device proposed in the embodiments of the present application will be described below with reference to the accompanying drawings.

[0016] Figure 1 It is a flowchart of the method for generating answers based on a pre-trained language model according to an embodiment of the present application.

[0017] As Figure 1 shown, the method for generating answers based on a pre-trained language model in the embodiments of the present application may include the following steps: S1, obtain the target question proposed by the user, the document names corresponding to multiple pre-stored documents, the keywords corresponding to each document, and the text blocks divided from each document.

[0018] S2, determine the target similarity corresponding to each document based on the target question, text blocks, document names, and keywords.

[0019] S3, determine the target document based on the target similarity, and determine the target answer based on the target document and the pre-trained language model.

[0020] Specifically, when generating the answer desired by the user through the pre-trained language model, the target question proposed by the user, the document names corresponding to multiple pre-stored documents, the keywords corresponding to each document, and the text blocks divided from each document may be obtained first. Among them, the target question is the question input by the user, and the most relevant answer needs to be found through the retrieval-enhanced generation application. The document name is the title of the pre-stored document, which is used to identify the theme of the document content. The keyword is the keyword defined by the user for each document, which is used to quickly locate the core content of the document. The text block is a small paragraph or sentence divided from the document content, which is convenient for subsequent vectorization and similarity calculation.

[0021] For example, the user submits a question through the display interface of the terminal device, such as the user inputs "Applications of artificial intelligence in the medical field". The user can pre-store multiple documents in the knowledge base, each document has a unique identifier, and the user can manually add keywords to each document in advance. Natural language processing tools can be used to automatically extract keywords. In addition, the document content can be divided into text blocks according to paragraphs, sentences, or fixed lengths, etc., to match the user's question at a finer granularity, thereby improving the accuracy of retrieval. Thus, the user's question and information of all relevant documents in the knowledge base can be obtained, providing a basis for subsequent similarity calculation.

[0022] After obtaining the target question proposed by the user, the document names corresponding to multiple pre-stored documents, the keywords corresponding to each document, and the text blocks divided for each document, the target similarity corresponding to each document can be determined according to the target question, the text blocks, the document names, and the keywords. For example, when determining the target similarity, it can be determined by calculating the keyword similarity, or by calculating the semantic similarity, or by calculating according to the keyword similarity and the semantic similarity. For example, taking the keyword similarity as an example, the keywords of the target question can be extracted, and the matching degree between the keywords of the target question and the document keywords can be calculated. If the keywords of the target question are "artificial intelligence" and "medical treatment", and the document keywords are "artificial intelligence" and "medical diagnosis", then the matching degree is 2 / 2 = 1. Similarly, calculate the matching degree between the keywords of the target question and the document names and keywords. Finally, the matching degrees can be accumulated and summed according to the corresponding ratio, so as to determine the keyword similarity according to the corresponding relationship between the final matching degree and the similarity, and use this keyword similarity as the target similarity.

[0023] After determining the target similarity, the target document can be determined according to the target similarity, and the target answer can be determined based on the target document and the pre-trained language model. For example, the document with the highest target similarity can be selected as the target document. Input the target question and the target document as context information into the pre-trained language model (such as GPT (Generative Pre-trained Transformer, generative pre-trained transformer), BERT (Bidirectional Encoder Representations from Transformers, bidirectional encoder representation)), and the pre-trained language model can generate an answer according to the input context information. For example, input "The application of artificial intelligence in the medical field", and the relevant document is "The application of artificial intelligence technology in medical diagnosis...", and the generated answer is "Artificial intelligence is mainly used in the medical field for disease diagnosis and optimization of treatment plans...". In addition, the generated answer can also be optimized by grammar checking, fact verification, etc.

[0024] Thus, for the large model application development platform of the present application, when the user creates a retrieval-augmented generation application, the vectorization of the content such as the names of the documents uploaded by the user and the user-defined keywords is increased, and in the retrieval process, the above content is integrated into the problem similarity retrieval process. The difference between the present application and the conventional retrieval-augmented generation application is that in the text similarity retrieval process, not only the text block content after document segmentation is considered, but the document names and document keywords are vectorized and expressed by using the same embedding model as that used for vectorizing the text block content, so that the finally retrieved document is more relevant to the question input by the user, thereby improving the effectiveness of the answer content of the large model and enhancing the user experience.

[0025] According to an embodiment of the present application, determining the target similarity corresponding to each document based on the target problem, text blocks, document names, and keywords includes: determining the semantic similarity based on the target problem, text blocks, document names, and keywords; determining the keyword similarity based on the target problem, text blocks, document names, and keywords; and determining the target similarity corresponding to each document based on the semantic similarity and the keyword similarity.

[0026] Specifically, when determining the target similarity corresponding to each document based on the target problem, text blocks, document names, and keywords, first, the semantic similarity can be determined according to the target problem, text blocks, document names, and keywords. That is, the semantic similarity refers to the semantic relevance between texts, whether they express similar meanings semantically. To calculate the semantic similarity, a pre-trained language model (such as BERT (Bidirectional Encoder Representations from Transformers), RoBERTa (Robustly Optimized BERT Approach), etc.) can be used to convert the texts into vectors, and then the similarity between the vectors can be calculated. The keyword similarity refers to the matching degree of keywords between the target problem and the text blocks, document names, and keywords. For example, after extracting keywords from the target problem, text blocks, document names, and keywords using NLP (Natural Language Processing) tools (such as jieba (a Chinese word segmentation tool), TF-IDF (Term Frequency-Inverse Document Frequency), TextRank (a text ranking algorithm)), the matching degree between the target problem keywords and the text blocks, document names, and keywords can be calculated.

[0027] After obtaining the semantic similarity and the keyword similarity, the target similarity corresponding to each document can be determined according to the semantic similarity and the keyword similarity. For example, the target similarity corresponding to each document can be determined according to the sum of the semantic similarity and the keyword similarity, or the target similarity corresponding to each document can be obtained by weighted summation of the semantic similarity and the keyword similarity according to their respective preset ratios. Thus, by comprehensively considering the semantic similarity and the keyword similarity, the relevance between the document and the user's problem can be evaluated more comprehensively, thereby improving the accuracy of the retrieval.

[0028] Thus, by determining the semantic similarity and keyword similarity based on the target question, text blocks, document names, and keywords, and comprehensively considering both to determine the target similarity of each document, the accuracy and efficiency of retrieval can be significantly improved. This method can not only capture the deep semantic relationships in the text but also quickly screen out the documents most relevant to the user's question, thereby enhancing the user experience and the overall performance of the system. More accurate retrieval results can provide users with more valuable information, reducing the time users spend searching in irrelevant content and improving the user experience.

[0029] Further, according to an embodiment of the present application, determining the semantic similarity based on the target question, text blocks, document names, and keywords includes: calculating the vectors corresponding to the target question and each text block based on the cosine similarity algorithm to obtain the first semantic similarity; calculating the vectors corresponding to the target question and each document name based on the cosine similarity algorithm to obtain the second semantic similarity; calculating the vectors corresponding to the target question and each keyword based on the cosine similarity algorithm to obtain the third semantic similarity; and determining the semantic similarity based on the sum of the first semantic similarity, the second semantic similarity, and the third semantic similarity.

[0030] Specifically, when determining the semantic similarity based on the target question, text blocks, document names, and keywords, a pre-trained language model (such as BERT, RoBERTa, etc.) can first be used to convert the target question and each text block into vector representations. These vectors can capture the semantic information of the text and map the text into a high-dimensional vector space. Assume the vector of the user question is Q, the vector of the text block content is Ti, the vector of the document name is Di, and the vector of the document keyword is Ki. For the vector Q corresponding to the target question and the vector Ti corresponding to each text block, calculate the cosine similarity between them, such as cosine similarity = (Q·Ti) / (|Q| * |Ti|). This cosine similarity is used as the first semantic similarity, where Q·Ti represents the dot product of vector Q and vector Ti, and |Q| and |Ti| represent the norms of vector Q and vector Ti, respectively. The value range of the cosine similarity is between -1 and 1. The closer the value is to 1, the more similar the two vectors are, that is, the more similar the semantics of the target question and the text block are.

[0031] For the vector Q corresponding to the target question and the vector Ki corresponding to each document name, calculate the cosine similarity between them. For example, cosine similarity = (Q·Di) / (|Q| * |Di|), and this cosine similarity is used as the second semantic similarity. Here, Q·Di represents the dot product of vector Q and vector Di, and |Q| and |Di| represent the norms of vector Q and vector Di respectively. The value range of the cosine similarity is between -1 and 1. The closer the value is to 1, the more similar the two vectors are, that is, the more similar the semantics of the target question and the document name are. For the vector Q corresponding to the target question and the vector Ki corresponding to the document keywords, calculate the cosine similarity between them. For example, cosine similarity = (Q·Ki) / (|Q| * |Ki|), and this cosine similarity is used as the third semantic similarity. Here, Q·Ki represents the dot product of vector Q and vector Ki, and |Q| and |Ki| represent the norms of vector Q and vector Ki respectively. The value range of the cosine similarity is between -1 and 1. The closer the value is to 1, the more similar the two vectors are, that is, the more similar the semantics of the target question and the document keywords are.

[0032] After obtaining the first semantic similarity, the second semantic similarity, and the third semantic similarity, the semantic similarity can be determined according to the sum of the first semantic similarity, the second semantic similarity, and the third semantic similarity, that is, the first semantic similarity plus the second semantic similarity plus the third semantic similarity to obtain the semantic similarity. Thus, by comprehensively considering the semantic similarities of the text block, the document name, and the keywords, the relevance between the document and the user's question can be evaluated more comprehensively, which can better reflect the overall relevance of the document than relying solely on the similarity of the text block or the document name. In addition, the cosine similarity algorithm can effectively capture the semantic relationship between texts. Even if the keywords do not exactly match, it can identify semantically related content. By combining the similarities in multiple dimensions, the retrieval accuracy can be further improved. Thus, the retrieval accuracy and efficiency can be effectively improved, the user experience can be enhanced, and it can adapt to various document structures and application scenarios.

[0033] Further, according to an embodiment of the present application, determining the keyword similarity based on the target question, the text block, the document name, and the keywords includes: determining the question keywords corresponding to the target question, the text keywords corresponding to the text block, and the document name keywords corresponding to the document name based on a preset keyword extraction algorithm; determining the first keyword similarity based on the ratio of the number of keywords that match between the question keywords and the text keywords to the question keywords; determining the second keyword similarity based on the ratio of the number of keywords that match between the question keywords and the document name keywords to the question keywords; determining the third keyword similarity based on the ratio of the number of keywords that match between the question keywords and the keywords to the question keywords; determining the keyword similarity based on the sum of the first keyword similarity, the second keyword similarity, and the third keyword similarity.

[0034] Specifically, when determining the keyword similarity based on the target question, text blocks, document name, and keywords, first, the question keywords corresponding to the target question, the text keywords corresponding to the text blocks, and the document name keywords corresponding to the document name can be determined based on a preset keyword extraction algorithm. For example, the preset keyword algorithms can be TF-IDF and TextRank, etc. The purpose of extracting keywords is for subsequent matching calculations.

[0035] For example, extract keywords from the question raised by the user. If the question is "The application of artificial intelligence in the medical field", the extracted keywords may be "artificial intelligence", "medical", and "application". Extract keywords from each text block respectively. For example, if a text block is "The application of artificial intelligence technology in medical diagnosis", the extracted keywords may be "artificial intelligence", "medical diagnosis", and "application". Extract keywords from the document name. For example, if the document name is "Artificial Intelligence and Medicine", the extracted keywords may be "artificial intelligence" and "medical". These keywords are the keywords predefined by the user or the system to identify the core content of the document. For example, "artificial intelligence", "medical", "application", etc.

[0036] Next, calculate the matching degrees between the target question keywords and the text block keywords, document name keywords, and keywords. The matching degree is determined by calculating the ratio of the number of matching keywords to the total number of target question keywords. That is, the first keyword similarity can be determined according to the ratio of the number of keywords matching between the question keywords and the text keywords and the total number of question keywords. For example, if the target question keywords are "artificial intelligence", "medical", and "application", and the text block keywords are "artificial intelligence", "medical diagnosis", and "application", the number of matching keywords is 2 ("artificial intelligence" and "application"), so calculate the ratio of the matching degree: the number of matching keywords / the total number of target question keywords = 2 / 3 ≈ 0.67. The second keyword similarity can be determined according to the ratio of the number of keywords matching between the question keywords and the document name keywords and the total number of question keywords. For example, if the target question keywords are "artificial intelligence", "medical", and "application", and the document name keywords are "artificial intelligence" and "medical", the number of matching keywords is 2 ("artificial intelligence" and "medical"), calculate the ratio of the matching degree: the number of matching keywords / the total number of target question keywords = 2 / 3 ≈ 0.67. The third keyword similarity can be determined according to the ratio of the number of keywords matching between the question keywords and the keywords and the total number of question keywords. For example, if the target question keywords are "artificial intelligence", "medical", and "application", and the keywords are "artificial intelligence", "medical", and "application", the number of matching keywords is 3, calculate the ratio of the matching degree: the number of matching keywords / the total number of target question keywords = 3 / 3 = 1.

[0037] Finally, add the similarities of the first keyword, the second keyword, and the third keyword to obtain the keyword similarity of each document. For example, for a certain document: the similarity of the first keyword = 0.67, the similarity of the second keyword = 0.67, the similarity of the third keyword = 1.00, and the comprehensive keyword similarity = 0.67 + 0.67 + 1.00 = 2.34. Additionally, to keep the value of the comprehensive keyword similarity within a reasonable range (such as 0 to 1), the result can be normalized. For example, normalize by dividing the comprehensive keyword similarity of each document by the maximum value.

[0038] Thus, by comprehensively considering the keyword similarities of the text block, the document name, and the keywords, the relevance between the document and the user's question can be evaluated more comprehensively, which can better reflect the overall relevance of the document than relying solely on the keyword similarities of the text block or the document name. Additionally, the calculation of the keyword matching degree can quickly identify the documents highly relevant to the user's question keywords. By combining the similarities in multiple dimensions, the accuracy of the retrieval can be further improved.

[0039] Thus, by determining the keyword similarities of the target question, the text block, the document name, and the keywords based on a preset keyword extraction algorithm and combining these similarity values, a more comprehensive and accurate comprehensive keyword similarity can be obtained. This method can effectively improve the accuracy and efficiency of the retrieval, enhance the user experience, and adapt to various document structures and application scenarios.

[0040] According to an embodiment of the present application, determining the target similarity corresponding to each document based on semantic similarity and keyword similarity includes: determining a first similarity score based on the product of the semantic similarity and the first weight coefficient, and determining a second similarity score based on the product of the keyword similarity and the second weight coefficient; determining the target similarity based on the sum of the first similarity score and the second similarity score. Among them, the first weight coefficient and the second weight coefficient can be determined according to the actual situation.

[0041] Specifically, when determining the target similarity corresponding to each document based on semantic similarity and keyword similarity, first determine the first similarity score based on the product of the semantic similarity and the first weight coefficient. That is, the semantic similarity is obtained by calculating the semantic relevance between the target question and the text block, the document name, and the keywords. The first weight coefficient is a preset weight value used to adjust the importance of the semantic similarity in the comprehensive similarity. Assume that the semantic similarity between the target question and each document has been calculated and denoted as semantic similarity. For example, for a certain document, the semantic similarity is 0.75. Assume the first weight coefficient is a. For example, a = 0.6. Calculate the first similarity score, that is, the first similarity score = semantic similarity × first weight coefficient. For example, the first similarity score = 0.75 × 0.6 = 0.45.

[0042] Then, determine the second similarity score based on the product of the keyword similarity and the second weight coefficient. That is, the keyword similarity is obtained by calculating the matching degree between the keywords of the target question and the keywords of the text block, the document name, and the keywords. The second weight coefficient is a preset weight value used to adjust the importance of the keyword similarity in the comprehensive similarity. Assume that the keyword similarity between the target question and each document has been calculated and denoted as the keyword similarity. For example, for a certain document, the keyword similarity is 0.80. Assume the second weight coefficient is b, for example, b = 0.4. Calculate the second similarity score, that is, the second similarity score = keyword similarity × second weight coefficient. For example, the second similarity score = 0.80 × 0.4 = 0.32.

[0043] Finally, the target similarity can be determined based on the sum of the first similarity score and the second similarity score. That is, the target similarity = first similarity score + second similarity score. For example, the target similarity = 0.45 + 0.32 = 0.77.

[0044] As a specific example, assume the following data: Target question: The application of artificial intelligence in the medical field. For Document 1, the text block is the application of artificial intelligence technology in medical diagnosis, the document name is Artificial Intelligence and Medicine, and the keywords are artificial intelligence, medicine, application. Semantic similarity calculation results: Semantic similarity of the text block: 0.75, semantic similarity of the document name: 0.65, semantic similarity of the keywords: 0.70, comprehensive semantic similarity: (0.75 + 0.65 + 0.70) / 3 = 0.70. Keyword similarity calculation results: Keyword similarity of the text block: 0.80, keyword similarity of the document name: 0.70, keyword similarity of the keywords: 0.90, comprehensive keyword similarity: (0.80 + 0.70 + 0.90) / 3 = 0.80. If the first weight coefficient a = 0.6 and the second weight coefficient b = 0.4, that is, the first similarity score = semantic similarity × first weight coefficient = 0.70 × 0.6 = 0.42, the second similarity score = keyword similarity × second weight coefficient = 0.80 × 0.4 = 0.32. Thus, the target similarity can be determined as the first similarity score + the second similarity score = 0.42 + 0.32 = 0.74.

[0045] Thus, by combining semantic similarity and keyword similarity, the relevance between the document and the user's question can be evaluated more comprehensively. Semantic similarity captures deep semantic relationships, while keyword similarity quickly identifies keyword matches. The combination of the two improves the accuracy of retrieval. Additionally, the weight coefficients a and b can be adjusted according to actual needs. For example, if semantic similarity is more important, the value of a can be increased; if keyword similarity is more important, the value of b can be increased. This method is applicable to different types of document structures. Whether it is a long paper, a news report, or an internal corporate document, the relevance to the user's question can be determined by comprehensively evaluating semantic and keyword similarities.

[0046] According to an embodiment of the present application, determining a target document based on a target similarity includes: sorting multiple target similarities according to a preset sorting rule; and determining the target document based on the sorted target similarities.

[0047] Specifically, when determining the target document based on the target similarity, multiple target similarities can be sorted according to a preset sorting rule. That is, the preset sorting rule refers to sorting the documents according to the numerical values of the target similarities. For example, the higher the target similarity, the stronger the relevance between the document and the user's question. After sorting the target similarities, the target document can be determined based on the sorted target similarities. That is, the target document refers to the document most relevant to the user's question. For example, the document with the highest target similarity can be selected from the sorted document list. Thus, through the process of determining the target document based on the target similarity, the accuracy and efficiency of retrieval can be effectively improved. This method ensures that the selected document is the most relevant to the user's question by sorting and selecting the document with the highest target similarity, thereby enhancing the user experience and adapting to various document structures and application scenarios. Moreover, the sorting process is simple and efficient, capable of quickly determining the target document and improving the system's response speed.

[0048] Furthermore, according to an embodiment of the present application, the preset sorting rule includes ascending sorting or descending sorting. Determining the target document based on the sorted target similarities includes: in the case where the sorting rule is ascending sorting, taking the documents corresponding to the last preset number of target similarities as the target documents; in the case where the sorting rule is descending sorting, taking the documents corresponding to the first preset number of target similarities as the target documents. The preset number can be determined according to the actual situation.

[0049] Specifically, the preset sorting rule may include ascending sorting or descending sorting. Ascending sorting means sorting the documents in ascending order of the target similarity, and descending sorting means sorting the documents in descending order of the target similarity. When determining the target document based on the sorted target similarity, the current sorting rule is judged. In the case where the sorting rule is ascending sorting, the documents corresponding to the last preset number of target similarities can be used as the target documents. For example, there are three documents with target similarities as follows: the target similarity of Document 1 is 0.68, the target similarity of Document 2 is 0.74, and the target similarity of Document 3 is 0.80. After sorting all the documents in ascending order of the target similarity, Document 1: 0.68, Document 2: 0.74, Document 3: 0.80. Thus, the target documents can be selected according to the preset number. Assuming the preset number is 2, the last two sorted documents can be selected as the target documents. That is, in the case of ascending sorting, the last two documents, namely Document 2 and Document 3, are selected.

[0050] In the case where the sorting rule is descending sorting, the documents corresponding to the first preset number of target similarities can be used as the target documents. For example, there are three documents with target similarities as follows: the target similarity of Document 1 is 0.68, the target similarity of Document 2 is 0.74, and the target similarity of Document 3 is 0.80. After sorting all the documents in descending order of the target similarity, Document 3: 0.80, Document 2: 0.74, Document 1: 0.68. The target documents are selected according to the preset number. Assuming the preset number is 2, the first two sorted documents can be selected as the target documents. In the case of descending sorting, the first two documents, namely Document 3 and Document 2, are selected.

[0051] Thus, by choosing ascending sorting or descending sorting, the target documents can be selected according to different requirements, and the sorting process is simple and efficient, which can quickly determine the target documents, improving the system's response speed and user experience. In addition, the preset number can be adjusted according to actual needs, and one or more target documents can be selected. This provides higher flexibility and controllability for the system.

[0052] According to an embodiment of the present application, before obtaining the target question proposed by the user, the document names corresponding to the pre-stored multiple documents, the keywords corresponding to each document, and the text blocks divided for each document, the answer generation method based on the pre-trained language model further includes: vectorizing and encoding the document names, keywords, and text blocks based on the pre-trained embedding model to determine the vectors corresponding to the document names, keywords, and text blocks, and saving them to the vector database for calculating the target similarity corresponding to each document.

[0053] Specifically, in the application of large model retrieval-augmented generation, the vectorization of text data is to convert unstructured text information into a structured vector representation. The purpose of vectorization is to efficiently calculate the similarity between texts in the vector space. By vectorizing and encoding document names, keywords, and text chunks and saving them in a vector database, when a user inputs a question, the relevance between the user's input question and each text chunk in the knowledge base can be quickly calculated, thereby finding the most relevant text content.

[0054] That is, after a user creates a knowledge base on the large model application development platform, they need to upload local document data. During the upload process, the platform will perform the following operations: Document chunking: According to the chunking strategy set by the user, each document is sliced into multiple text chunks. For example, it can be sliced by paragraph, sentence, or fixed length. Extracting document names and keywords: The platform will automatically extract the name of each document and allow the user to add custom keywords to each document, which are used to indicate the core content of the document.

[0055] In the text data vectorization stage, the platform will use a pre-trained embedding model to vectorize and encode the following: Convert each text chunk into a vector, convert the name of each document into a vector, and convert the keywords added by the user to each document into a vector. These vectorized data will be saved in a vector database for subsequent similarity calculations. That is, a text chunk is a text fragment extracted from a document, such as "The application of artificial intelligence technology in medical diagnosis". The document name is the title of the document, such as "Artificial Intelligence and Medicine". Keywords are the keywords of the document, such as "artificial intelligence", "medicine", "application". To perform vectorization using a pre-trained embedding model, select a pre-trained embedding model suitable for the task. For example, BERT or RoBERTa is suitable for Chinese text processing. Use the tokenizer of the pre-trained model to split the text into subwords or words, input the split text into the pre-trained model, and obtain the corresponding vector representation. Suppose the BERT model is used. Use the BERT tokenizer to split the text into subwords, input the split subwords into the BERT model, obtain the vector representation of each subword, and average the vector representations of all subwords to obtain the vector representation of the entire text.

[0056] Perform vectorization encoding on each text chunk to obtain its vector representation. For example, the text chunk "The application of artificial intelligence technology in medical diagnosis" is converted into vector Ti. Perform vectorization encoding on each document name to obtain its vector representation. For example, the document name "Artificial Intelligence and Medicine" is converted into vector Di. Perform vectorization encoding on each keyword to obtain its vector representation. For example, the keyword "artificial intelligence" is converted into vector Ki.

[0057] Thus, by pre-vectorizing and encoding the document name, keywords, and text chunks and saving them in a vector database, the present application can make full use of this information during the retrieval process to improve the accuracy and relevance of the retrieval results. This optimized retrieval method is particularly suitable for scenarios where there are a large number of documents in the knowledge base and a high degree of content similarity, and can significantly improve the quality of the answers generated by the pre-trained language model.

[0058] According to an embodiment of the present application, before determining the target similarity corresponding to each document, the answer generation method based on the pre-trained language model further includes: vectorizing and encoding the target question proposed by the user based on the pre-trained embedding model to determine the vector corresponding to the target question.

[0059] Specifically, before determining the target similarity corresponding to each document, the target question proposed by the user can also be vectorized and encoded based on the pre-trained embedding model to determine the vector corresponding to the target question. That is, the pre-trained embedding model is a deep learning model that can convert the question text into a high-dimensional vector representation. These models learn the semantic information of the text by training on a large-scale corpus. For example, the pre-trained embedding models include BERT and RoBERTa, etc.

[0060] Vectorizing and encoding is the process of converting text into a vector representation. The target question is the question proposed by the user, such as "The application of artificial intelligence in the medical field". For vectorization using the pre-trained embedding model, a pre-trained embedding model suitable for the task is selected. For example, BERT or RoBERTa is suitable for Chinese text processing. The text is segmented into sub-words or words using the tokenizer of the pre-trained model, and the segmented text is input into the pre-trained model to obtain the corresponding vector representation. Assuming the BERT model is used, the text is segmented into sub-words using the BERT tokenizer, the segmented sub-words are input into the BERT model to obtain the vector representation of each sub-word, and the vector representations of all sub-words are averaged to obtain the vector representation of the entire text. Thus, the target question text can be input into the pre-trained model to obtain its vector representation. For example, the target question "The application of artificial intelligence in the medical field" is converted into vector Q. This can ensure that the question vector and the text chunk vectors, document name vectors, and keyword vectors in the vector database are in the same vector space, enabling effective similarity calculation.

[0061] Therefore, before determining the target similarity corresponding to each document, using the pre-trained embedding model to vectorize and encode the target question is a crucial step. This step converts the question text into a high-dimensional vector representation, providing a basis for subsequent semantic similarity and keyword similarity calculations. By using the pre-trained model, the semantic information of the text can be captured, ensuring the consistency and efficiency of the vector representation, thereby improving the overall performance of the system and the user experience.

[0062] According to an embodiment of the present application, the answer generation method based on a pre-trained language model further includes: screening text chunks based on a target question, so as to use the screened text chunks for calculating a target similarity.

[0063] Specifically, in the answer generation based on a pre-trained language model, screening text chunks is an important preprocessing step. That is to say, through screening, text chunks irrelevant to the target question can be removed, thereby improving the efficiency and accuracy of subsequent similarity calculation. Thus, text chunks can be screened according to the target question, so as to use the screened text chunks for calculating the target similarity, that is, removing text chunks irrelevant to the target question and retaining text chunks relevant to the target question, to improve the efficiency and accuracy of subsequent similarity calculation.

[0064] For example, keywords of the target question can be extracted, each text chunk can be checked whether it contains these keywords, text chunks containing the keywords are retained, and text chunks not containing the keywords are removed. Target question: Applications of artificial intelligence in the medical field, extracted keywords: artificial intelligence, medical, application, text chunk 1: Applications of artificial intelligence technology in medical diagnosis (contains keywords, retained), text chunk 2: Applications of artificial intelligence in the financial field (does not contain the keyword "medical", removed). After screening, text chunks relevant to the target question are retained. Then, semantic similarity and keyword similarity of the screened text chunks are calculated, and finally the target similarity of each document is determined.

[0065] Thus, by screening to remove irrelevant text chunks, the amount of data for subsequent similarity calculation is reduced, and the retrieval efficiency is improved. For example, there are 100 text chunks in the original document, and only 20 relevant text chunks may be left after screening, significantly reducing the amount of calculation. In addition, the screened text chunks are more likely to be relevant to the target question, thereby improving the accuracy of subsequent similarity calculation. For example, by screening through keyword matching, text chunks completely irrelevant to the target question can be removed, avoiding the interference of noise data.

[0066] According to an embodiment of the present application, screening text chunks based on a target question includes: obtaining the number of keywords that at least one question keyword in the target question matches the text keyword of the text chunk; determining a keyword matching degree based on the number of keywords and the number of question keywords; and using the text chunk corresponding to the keyword matching degree greater than a preset matching degree threshold as the text chunk for calculating the target similarity. Wherein, the preset matching threshold can be determined according to the actual situation.

[0067] Specifically, when screening text blocks according to the target question, obtain the number of keywords that match between at least one question keyword in the target question and the text keywords of the text block. That is, use a keyword extraction algorithm to extract keywords from the target question, and extract keywords for each text block, also using the keyword extraction algorithm. Then calculate the number of matches between the target question keywords and the keywords of each text block. For example, the target question keywords are "artificial intelligence", "medical", "application", and the text block keywords are "artificial intelligence", "medical diagnosis", "application", and the number of matching keywords is 2 ("artificial intelligence" and "application").

[0068] Determine the keyword matching degree according to the number of keywords and the number of question keywords, that is, the keyword matching degree is the ratio of the number of matching keywords to the total number of target question keywords. For example, the number of matching keywords is 2, and the total number of target question keywords is 3, and the keyword matching degree is 2 / 3. After obtaining the keyword matching degree, the size relationship between the keyword matching degree and the preset matching degree threshold can be compared, and the text block corresponding to the keyword matching degree greater than the preset matching degree threshold is used as the text block when calculating the target similarity. Among them, the preset matching degree threshold is used to screen text blocks. For example, the threshold can be set to 0.5, and this threshold can be adjusted according to actual needs to balance the strictness and flexibility of screening. If the keyword matching degree of a certain text block is greater than the preset threshold, then retain this text block for subsequent target similarity calculation. For example, the preset threshold is 0.5, the keyword matching degree of a certain text block is 0.67, retain this text block, and the keyword matching degree of another text block is 0.33, remove this text block.

[0069] For example, assume there is the following data. The target problem is the application of artificial intelligence in the medical field. The keywords of the target problem are artificial intelligence, medical, and application. The content of text block 1 is the application of artificial intelligence technology in medical diagnosis. The keywords of text block 1 are artificial intelligence, medical diagnosis, and application. The number of matching keywords determined: 2 (artificial intelligence, application). The calculated keyword matching degree is 2 / 3 ≈ 0.67. The content of text block 2 is the application of artificial intelligence in the financial field. The keywords of text block 2 are artificial intelligence, finance, and application. The number of matching keywords is 1 (artificial intelligence). The calculated keyword matching degree is 1 / 3 ≈ 0.33. The content of text block 3 is the latest progress of medical devices. The keywords of text block 3 are medical devices and progress. The number of matching keywords: 1 (medical). The calculated keyword matching degree: 1 / 3 ≈ 0.33. Assume the preset matching degree threshold is 0.5. The screening result can be determined: The keyword matching degree of text block 1 is 0.67, which is greater than the threshold 0.5, so it is retained. The keyword matching degree of text block 2 is 0.33, which is less than the threshold 0.5, so it is removed. The keyword matching degree of text block 3 is 0.33, which is less than the threshold 0.5, so it is removed. Finally, only text block 1 is retained for subsequent target similarity calculation.

[0070] Thus, by screening text blocks based on the target problem, text blocks irrelevant to the target problem can be effectively removed, improving the efficiency and accuracy of subsequent target similarity calculation. This method calculates the keyword matching degree to screen out the text blocks most relevant to the target problem, thereby enhancing the user experience and the overall performance of the system.

[0071] According to another embodiment of the present application, the answer generation method based on the pre-trained language model further includes: determining the distance between the vector of the target problem and the vector of the text block based on the nearest neighbor algorithm; using the text blocks corresponding to the distance less than the preset distance threshold as the text blocks for calculating the target similarity. The preset distance threshold can be determined according to the actual situation.

[0072] Specifically, in the answer generation based on the pre-trained language model, screening text blocks is an important preprocessing step. That is to say, through screening, text blocks irrelevant to the target problem can be removed, thereby improving the efficiency and accuracy of subsequent similarity calculation. First, the distance between the vector of the target problem and the vector of the text block can be determined based on the nearest neighbor algorithm. For example, the distance is the cosine distance, and the cosine distance = 1 - (Q·Ti) / (|Q| * |Ti|), where Q is the vector of the target problem, Ti is the vector of the text block, Q·Ti represents the dot product of vector Q and vector Ti, and |Q| and |Ti| respectively represent the norms of vector Q and vector Ti.

[0073] After determining the distance, the magnitude relationship between the distance and a preset distance threshold can be judged, and the text block corresponding to the distance less than the preset distance threshold is used as the text block for calculating the target similarity. That is, a distance threshold can be set according to the actual situation. This threshold is used to screen out text blocks that are close enough to the target problem. For example, if the preset cosine distance threshold is 0.2, it means that only text blocks with a cosine distance less than 0.2 will be retained. Calculate the distance between each text block and the target problem vector. If the distance of a certain text block is less than the preset threshold, then retain this text block for subsequent target similarity calculation. For example, the cosine distance of text block 1 is 0.15, which is less than the threshold 0.2, so it is retained; the cosine distance of text block 2 is 0.25, which is greater than the threshold 0.2, so it is removed. For example, assume there is the following data: the target problem is the application of artificial intelligence in the medical field, the target problem vector is Q, text block 1 is the application of artificial intelligence technology in medical diagnosis, the text block 1 vector is T1, text block 2: the application of artificial intelligence in the financial field, and the text block 2 vector is T2. If the cosine distance between the target problem vector and the text block 1 vector is calculated to be 0.15, and the cosine distance between the calculated target problem vector and the text block 2 vector is 0.25, and if the preset cosine distance threshold is 0.2, and the cosine distance of text block 1 is 0.15, which is less than the threshold 0.2, so it is retained, and the cosine distance of text block 2 is 0.25, which is greater than the threshold 0.2, so it is removed. Finally, it is determined that only text block 1 is retained for subsequent target similarity calculation.

[0074] Thus, by determining the distance between the vector of the target problem and the vector of the text block based on the nearest neighbor algorithm and screening out relevant text blocks according to the preset distance threshold, the efficiency and accuracy of retrieval can be effectively improved. This method screens out the text blocks most relevant to the target problem through the distance threshold, thereby enhancing the user experience and the overall performance of the system.

[0075] According to an embodiment of the present application, the answer generation method based on a pre-trained language model further includes: dividing each document into text blocks based on a preset chunking strategy.

[0076] Specifically, in the answer generation method based on a pre-trained language model, each document can be divided into text blocks, that is, completed through a preset chunking strategy, aiming to split a long document into smaller and manageable text units for subsequent processing and analysis. The preset chunking strategy refers to predefined rules or methods for dividing a document into text blocks. These strategies can be designed according to the structure of the document, the type of content, or other features.

[0077] For example, each paragraph is treated as an independent text block, which is suitable for cases where the document structure is clear and paragraphs are distinct. For example, the application of artificial intelligence technology in the medical field is very extensive. It can not only be used for disease diagnosis, but also for optimizing treatment plans. In addition, artificial intelligence can also assist in medical management and improve the efficiency of medical services. The chunking results are text block 1: The application of artificial intelligence technology in the medical field is very extensive, text block 2: It can not only be used for disease diagnosis, but also for optimizing treatment plans, and text block 3: In addition, artificial intelligence can also assist in medical management and improve the efficiency of medical services. Alternatively, the document can also be divided into text blocks according to a fixed length (such as the number of characters or words).

[0078] Thus, after dividing the long document into text blocks, each text block can be processed and analyzed separately, reducing the computational amount and improving the retrieval efficiency. If the document has 1000 sentences, after chunking by sentence, each sentence can be vectorized and its similarity calculated separately, rather than processing the entire document. This preprocessing step is an important link in the answer generation method based on the pre-trained language model, which can significantly improve the performance of the system and the user experience.

[0079] The following combines Figure 2 to describe the method of this application.

[0080] As a specific example, the answer generation method based on the pre-trained language model of this application may include the following steps: S101, Obtain the target question proposed by the user, the document names corresponding to multiple pre-stored documents, the keywords corresponding to each document, and the text blocks into which each document is divided.

[0081] S102, Determine the semantic similarity based on the target question and the text blocks, document names, and keywords, and determine the keyword similarity based on the target question and the text blocks, document names, and keywords.

[0082] S103, Determine the first similarity score based on the product of the semantic similarity and the first weight coefficient, and determine the second similarity score based on the product of the keyword similarity and the second weight coefficient.

[0083] S104, Determine the target similarity based on the sum of the first similarity score and the second similarity score.

[0084] S105, Sort the multiple target similarities according to the descending sorting rule to use the documents corresponding to the top preset number of target similarities as the target documents.

[0085] S106, Determine the target answer based on the target documents and the pre-trained language model.

[0086] In summary, according to the answer generation method based on a pre-trained language model in the embodiments of the present application, the target question proposed by the user, the document names corresponding to multiple pre-stored documents, the keywords corresponding to each document, and the text blocks divided for each document are obtained. Based on the target question, the text blocks, the document names, and the keywords, the target similarity corresponding to each document is determined. Based on the target similarity, the target document is determined, and based on the target document and the pre-trained language model, the target answer is determined. Thus, this method can make the finally retrieved document more relevant to the question input by the user, thereby improving the effectiveness of the answer content of the pre-trained language model and enhancing the user experience.

[0087] Corresponding to the above embodiments, the present application also proposes a computer program product.

[0088] The computer program product of the embodiments of the present application includes computer programs / instructions, and when the computer programs / instructions are executed by a processor, the above-mentioned answer generation method based on a pre-trained language model is implemented.

[0089] According to the computer program product of the embodiments of the present application, by executing the above-mentioned answer generation method based on a pre-trained language model, the finally retrieved document can be made more relevant to the question input by the user, thereby improving the effectiveness of the answer content of the pre-trained language model and enhancing the user experience.

[0090] Corresponding to the above embodiments, the present application also proposes a computer-readable storage medium.

[0091] The computer-readable storage medium of the embodiments of the present application stores a program thereon, and when the program is executed by a processor, the above-mentioned answer generation method based on a pre-trained language model is implemented.

[0092] According to the computer-readable storage medium of the embodiments of the present application, by executing the above-mentioned answer generation method based on a pre-trained language model, the finally retrieved document can be made more relevant to the question input by the user, thereby improving the effectiveness of the answer content of the pre-trained language model and enhancing the user experience.

[0093] Corresponding to the above embodiments, the present application also proposes an electronic device.

[0094] As Figure 3 shown, the electronic device 200 of the embodiments of the present application may include: a memory 210, a processor 220, and a program stored on the memory 210 and executable on the processor 220. When the processor 220 executes the program, the above-mentioned answer generation method based on a pre-trained language model is implemented.

[0095] An electronic device according to an embodiment of the present application, by executing the above-mentioned answer generation method based on a pre-trained language model, can make the finally retrieved document more relevant to the question input by the user, thereby improving the effectiveness of the answer content of the pre-trained language model and enhancing the user experience.

[0096] It should be noted that the logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a definite sequence list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, apparatus, or device (such as a computer-based system, a system including a processor, or other systems that can fetch and execute instructions from the instruction execution system, apparatus, or device), or in combination with these instruction execution systems, apparatus, or devices. For the purposes of this specification, a "computer-readable medium" can be any device that can contain, store, communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. More specific examples (non-exhaustive list) of computer-readable media include the following: an electrical connection portion with one or more wirings (electronic device), a portable computer diskette (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium can even be paper or other suitable media on which the program can be printed, because the program can be obtained electronically, for example, by optically scanning the paper or other media, followed by editing, interpretation, or otherwise processing as appropriate, and then storing it in a computer memory.

[0097] It should be understood that each part of the present application can be implemented by hardware, software, firmware, or a combination thereof. In the above-described embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one or a combination of the following techniques well known in the art can be used: discrete logic circuits having logic gate circuits for implementing logical functions on data signals, application specific integrated circuits having appropriate combinational logic gate circuits, programmable gate arrays (PGAs), field programmable gate arrays (FPGAs), etc.

[0098] In the description of this specification, the descriptions referring to terms such as "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" etc. mean that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of this application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples.

[0099] In addition, the terms "first" and "second" are used for descriptive purposes only and cannot be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include at least one of such features. In the description of this application, "a plurality of" means at least two, such as two, three, etc., unless otherwise specifically and clearly defined.

[0100] In this application, unless otherwise clearly stipulated and defined, terms such as "install", "connect", "be connected", "fix", etc. shall be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or integrated; it can be a mechanical connection or an electrical connection; it can be directly connected or indirectly connected through an intermediate medium, and it can be the communication inside two elements or the interaction relationship between two elements, unless otherwise clearly defined. For those of ordinary skill in the art, the specific meanings of the above terms in this application can be understood according to specific circumstances.

[0101] Although the embodiments of this application have been shown and described above, it can be understood that the above embodiments are exemplary and should not be construed as limiting this application. Those of ordinary skill in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of this application.

Claims

1. A method for generating answers based on a pre-trained language model, characterized in that, The method includes: obtaining a target question proposed by a user, document names corresponding to a plurality of pre-stored documents, keywords corresponding to each document, and text blocks into which each document is divided; determining a target similarity corresponding to each document based on the target question, the text blocks, the document names, and the keywords; determining a target document based on the target similarity, and determining a target answer based on the target document and a pre-trained language model.

2. The method for generating answers based on a pre-trained language model according to claim 1, wherein The determining the target similarity corresponding to each document based on the target question, the text blocks, the document names, and the keywords includes: determining a semantic similarity based on the target question, the text blocks, the document names, and the keywords; determining a keyword similarity based on the target question, the text blocks, the document names, and the keywords; determining the target similarity corresponding to each document based on the semantic similarity and the keyword similarity.

3. The method for generating an answer based on a pre-trained language model according to claim 2, wherein The determining the semantic similarity based on the target question, the text blocks, the document names, and the keywords includes: calculating a vector corresponding to the target question and vectors corresponding to each text block based on a cosine similarity algorithm to obtain a first semantic similarity; calculating a vector corresponding to the target question and vectors corresponding to each document name based on a cosine similarity algorithm to obtain a second semantic similarity; calculating a vector corresponding to the target question and vectors corresponding to each keyword based on a cosine similarity algorithm to obtain a third semantic similarity; determining the semantic similarity based on the sum of the first semantic similarity, the second semantic similarity, and the third semantic similarity.

4. The method for generating answers based on a pre-trained language model according to claim 2, wherein The determining the keyword similarity based on the target question, the text blocks, the document names, and the keywords includes: determining a question keyword corresponding to the target question, a text keyword corresponding to the text block, and a document name keyword corresponding to the document name based on a preset keyword extraction algorithm; determining a first keyword similarity based on a ratio of the number of keywords matched between the question keyword and the text keyword to the question keyword; determining a second keyword similarity based on a ratio of the number of keywords matched between the question keyword and the document name keyword to the question keyword; determining a third keyword similarity based on a ratio of the number of keywords matched between the question keyword and the keyword to the question keyword; determining the keyword similarity based on the sum of the first keyword similarity, the second keyword similarity, and the third keyword similarity.

5. The method for generating answers based on a pre-trained language model according to claim 2, wherein The determining the target similarity corresponding to each document based on the semantic similarity and the keyword similarity includes: determining a first similarity score based on a product of the semantic similarity and a first weight coefficient, and determining a second similarity score based on a product of the keyword similarity and a second weight coefficient; determining the target similarity based on the sum of the first similarity score and the second similarity score.

6. The method for generating an answer based on a pre-trained language model according to claim 5, wherein The determining the target document based on the target similarity includes: sorting the multiple target similarities according to a preset sorting rule; determining the target document based on the sorted target similarities.

7. The method for generating answers based on a pre-trained language model according to claim 1, wherein Before obtaining the target question raised by the user, the document names corresponding to multiple pre-stored documents, the keywords corresponding to each document, and the text blocks divided for each document, the method further includes: Performing vectorized encoding on the document names, the keywords, and the text blocks based on a pre-trained embedding model to determine the vectors corresponding to the document names, the keywords, and the text blocks, and saving them to a vector database for calculating the target similarity corresponding to each document.

8. The method for generating an answer based on a pre-trained language model according to claim 1, wherein Before determining the target similarity corresponding to each document, the method further includes: Performing vectorized encoding on the target question raised by the user based on a pre-trained embedding model to determine the vector corresponding to the target question.

9. The method for generating an answer based on a pre-trained language model according to claim 8, wherein The method further includes: Screening the text blocks based on the target question to use the screened text blocks for calculating the target similarity.

10. The method for generating answers based on a pre-trained language model according to claim 9, wherein, The screening the text blocks based on the target question includes: Obtaining the number of keywords that match between at least one question keyword in the target question and the text keywords of the text block; Determining the keyword matching degree based on the number of keywords and the number of question keywords; Using the text blocks with the keyword matching degree greater than a preset matching degree threshold as the text blocks when calculating the target similarity.

11. The method for generating an answer based on a pre-trained language model according to claim 8, wherein The method further includes: Determining the distance between the vector of the target question and the vector of the text block based on the nearest neighbor algorithm; Using the text blocks with the distance less than a preset distance threshold as the text blocks when calculating the target similarity.

12. The method for generating answers based on a pre-trained language model according to claim 1, wherein The method further includes: Dividing each document into text blocks based on a preset chunking strategy.

13. A computer program product, comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by a processor, the method for generating answers based on a pre-trained language model according to any one of claims 1-12 is implemented.

14. A computer-readable storage medium, characterized in that, Stored thereon is a program which, when executed by a processor, implements the method for generating answers based on a pre-trained language model according to any one of claims 1-12.

15. An electronic device, characterized in that, Including: A memory, a processor, and a program stored on the memory and executable on the processor. When the processor executes the program, the method for generating answers based on a pre-trained language model according to any one of claims 1-12 is implemented.

Citation Information

Patent Citations

  • Question and answer method and device, equipment and medium

    CN117236340A

  • Question and answer method and device based on keywords and semantic model and storage medium

    CN118520089A

  • Policy knowledge question and answer method and device and storage medium

    CN118797021A

  • Method, device and equipment for obtaining fine adjustment data of large model and storage medium

    CN119829718A

  • Method and apparatus for classifying document based on attention mechanism and semantic analysis

    US20230027526A1