Knowledge question and answer method and device and storage medium
By sharding the original knowledge text and extracting multiple content abstracts, and generating feature vectors for matching, the problem of sensitive sentence length and difficulty in capturing long-distance information in the existing technology is solved, and efficient knowledge retrieval and stronger semantic understanding capabilities are achieved.
Patent Information
- Application Number
- CN202311387277.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-24
- Publication Date
- 2025-04-29
AI Technical Summary
In the knowledge retrieval, the prior art has problems such as being sensitive to sentence length and being difficult to capture the relationship between long-distance information.
By sharding the original knowledge text and extracting multiple contents during content summary, multi-level text fragments are obtained, and feature extraction is performed on these fragments, keyword feature vectors, problem feature vectors, and text fragment feature vectors are generated, and key-value pairs between the feature vectors and text fragments are created to match the question and answer data.
The matching based on multiple feature vectors is realized, the universality of multimodal retrieval and search extension is enhanced, the ability to understand text knowledge with different semantic correlations and expression methods is improved, and the retrieval accuracy is significantly improved.
Smart Images

Figure CN119903135A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of knowledge retrieval and natural language processing (NLP), and in particular to a knowledge question answering method, device and storage medium. Background Art
[0002] In related technologies, with the rapid development of deep learning and large pre-trained models, researchers have begun to focus on how to introduce external knowledge into these models. Related academic papers and research projects involve multiple fields such as knowledge retrieval, information extraction, and knowledge graphs. In the industrial world, large Internet companies are actively exploring the application of knowledge retrieval in applications such as search, intelligent assistants, and intelligent question and answer. However, related technologies have problems such as being sensitive to sentence length and difficulty in capturing relationships between long-distance information. Summary of the invention
[0003] In order to overcome the problems existing in the related art, the present disclosure provides a knowledge question answering method, device and storage medium.
[0004] According to a first aspect of an embodiment of the present disclosure, a knowledge question answering method is provided, comprising:
[0005] Acquire the original knowledge text and question-and-answer data input by the user; extract the content summary in the original knowledge text to obtain a first text segment; perform feature extraction on the first text segment to obtain a feature vector, wherein the feature vector includes a keyword feature vector, a question feature vector, and a text segment feature vector; create a key-value pair between the feature vector and the first text segment;
[0006] Based on the key-value pair and the question and answer data, answer data for the question and answer data is determined.
[0007] In one implementation, the extracting and processing the content summary in the original knowledge text to obtain the first text segment includes:
[0008] The original knowledge text is segmented to obtain a second text segment; based on a preset large language model, a content summary of the second text segment is extracted to obtain the first text segment.
[0009] In one implementation, the extracting of the content summary of the second text segment includes:
[0010] Performing the i-th extraction process on the content summaries of each adjacent k second text segments among the m second text segments to obtain p i-th level segments, the text length of the i-th level segment is the length of a second text segment, m and i are positive integers, and p and k are positive integers less than m; performing the i+1-th extraction process on the content summaries of each adjacent k i-th level segments among the p i-th level segments to obtain q i+1-th level segments, the text length of the i+1-th level segment is the length of a second text segment, q is a positive integer less than p; repeating the above process until performing the n-th extraction process to obtain a predefined number of n-th level segments, and taking the n-th level segment as the first text segment, where n is a positive integer.
[0011] In one implementation, obtaining a feature vector based on the first text segment includes:
[0012] The first text segment is segmented using a period as a separator to obtain a third text segment; keywords and questions in the first text segment are extracted based on the large language model; and the feature vector is obtained based on the third text segment, the keywords and the questions.
[0013] In one implementation, determining the answer data of the question and answer data based on the key-value pair and the question and answer data includes:
[0014] Based on the question and answer data, determine the j feature vectors with the highest similarity in a feature vector database, the feature vector database containing the key-value pairs, and j is a positive integer; based on the j feature vectors and the key-value pairs, determine x first text fragments, and x is a positive integer less than or equal to j; based on the preset weights of the j feature vectors, reorder the x first text fragments; input the first y first text fragments after reordering and the question and answer data as prompt information into a preset large language model, and obtain the reply data of the question and answer data to obtain the model reply content.
[0015] According to a second aspect of an embodiment of the present disclosure, a knowledge question answering device is provided, comprising:
[0016] A receiving unit is used to obtain original knowledge text and question and answer data input by a user; a processing unit is used to extract and process the content summary in the original knowledge text to obtain a first text fragment; the processing unit is also used to extract features from the first text fragment to obtain a feature vector, wherein the feature vector includes a keyword feature vector, a question feature vector and a text fragment feature vector; a creating unit is used to create a key-value pair between the feature vector and the first text fragment; and a reply unit is used to determine reply data for the question and answer data based on the key-value pair and the question and answer data.
[0017] In one implementation, the processing unit extracts the content summary in the original knowledge text in the following manner to obtain the first text segment:
[0018] The original knowledge text is segmented to obtain a second text segment; based on a preset large language model, a content summary of the second text segment is extracted to obtain the first text segment.
[0019] In one implementation, the processing unit extracts the content summary of the second text segment in the following manner to obtain the first text segment:
[0020] Performing the i-th extraction process on the content summaries of each adjacent k second text segments among the m second text segments to obtain p i-th level segments, wherein the text length of the i-th level segment is the length of one second text segment, wherein m and i are positive integers, and p and k are positive integers less than m; performing the i+1-th extraction process on the content summaries of each adjacent k i-th level segments among the p i-th level segments to obtain q i+1-th level segments, wherein the text length of the i+1-th level segment is the length of one second text segment, wherein q is a positive integer less than p; repeating the above process until performing the n-th extraction process to obtain a predefined number of n-th level segments, and taking the n-th level segments as the first text segments.
[0021] In one implementation, the processing unit obtains a feature vector based on the first text segment in the following manner:
[0022] The first text segment is segmented using a period as a separator to obtain a third text segment; keywords and questions in the first text segment are extracted based on the large language model; and the feature vector is obtained based on the third text segment, the keywords and the questions.
[0023] In one implementation, determining the answer data of the question and answer data based on the key-value pair and the question and answer data includes:
[0024] Based on the question and answer data, determine the j feature vectors with the highest similarity in a feature vector database, the feature vector database containing the key-value pairs, and j is a positive integer; based on the j feature vectors and the key-value pairs, determine x first text fragments, and x is a positive integer less than or equal to j; based on the preset weights of the j feature vectors, reorder the x first text fragments; input the first y first text fragments after reordering and the question and answer data as prompt information into a preset large language model, and obtain the reply data of the question and answer data to obtain the model reply content.
[0025] According to a third aspect of an embodiment of the present disclosure, there is provided an audio control device, including:
[0026] A processor; a memory for storing processor executable instructions; wherein the processor is configured to: execute the function control method described in the first aspect or any one of the embodiments of the first aspect.
[0027] According to a fourth aspect of an embodiment of the present disclosure, a storage medium is provided, in which instructions are stored. When the instructions in the storage medium are executed by a processor of a terminal, the terminal can perform the method described in the first aspect or any one of the implementations of the first aspect.
[0028] The technical solution provided by the embodiments of the present disclosure may include the following beneficial effects: by retrieving the first text fragment and question and answer data in the form of a feature vector, wherein the feature vector includes a keyword feature vector, a question feature vector and a text fragment feature vector, matching based on multiple feature vectors is achieved, and the performance of multimodal retrieval, retrieval extension and the like is enhanced. The present disclosure has a stronger understanding ability for text knowledge that is semantically related and expressed in different ways, and can greatly improve the retrieval accuracy.
[0029] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0031] Figure 1 It is a schematic diagram of a knowledge question and answer according to the related technology.
[0032] Figure 2 It is a schematic diagram of a feature vector acquisition process according to the related technology.
[0033] Figure 3 The figure is a flow chart of a knowledge question answering method according to an exemplary embodiment.
[0034] Figure 4 The figure is a flowchart of a method for obtaining a first text segment according to an exemplary embodiment.
[0035] Figure 5 The figure is a flowchart showing a content summary extraction operation according to an exemplary embodiment.
[0036] Figure 6 The figure is a flow chart of a method for acquiring a feature vector according to an exemplary embodiment.
[0037] Figure 7 The figure is a flow chart of a knowledge question answering method according to an exemplary embodiment.
[0038] Figure 8 It is a schematic diagram of a method for obtaining a first text segment according to an exemplary embodiment.
[0039] Fig. 9 It is a schematic diagram of a knowledge question and answer according to an exemplary embodiment.
[0040] Fig.10 It is a block diagram of a knowledge question and answer device according to an exemplary embodiment.
[0041] Fig.11 It is a block diagram of a device for knowledge question answering according to an exemplary embodiment. DETAILED DESCRIPTION
[0042] Here, exemplary embodiments will be described in detail, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present disclosure.
[0043] In the accompanying drawings, the same or similar reference numerals throughout represent the same or similar elements or elements with the same or similar functions. The described embodiments are part of the embodiments of the present disclosure, rather than all of the embodiments. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present disclosure, and should not be construed as limitations on the present disclosure. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present disclosure. The embodiments of the present disclosure are described in detail below in conjunction with the accompanying drawings.
[0044] The knowledge question-answering method provided in the embodiments of the present disclosure can be applied to application scenarios such as text similarity calculation, question-answering system, and intelligent customer service. By using technologies such as Faiss search library, sentence encoding, and large language model (LLM) reply generation, accurate knowledge retrieval and reliable reply generation are provided through a hierarchical retrieval strategy. Problems such as sensitivity to matching content length, differences in expression, and dispersed information distribution are solved.
[0045] Figure 1 It is a schematic diagram of a knowledge question and answer according to the related technology.
[0046] In the related art, a local file containing text information is identified by a data loader to obtain information such as the original knowledge text, encoding method, language, and file size in the file, and a slicing operation is used to obtain multiple text fragments of the original knowledge text. Finally, the feature vector corresponding to each text fragment is extracted and stored in a vector database (VectorStore). The vector information corresponding to the question and answer data input by the user is extracted, and the text fragments related to the question content are retrieved through similarity comparison analysis, and one or more text fragments with the highest similarity are obtained. The one or more text fragments with the highest similarity and the question and answer data input by the user are added to the prompt template (Prompt Template) to obtain prompt information (Prompt), and the prompt information is input into the large language model, and finally the answer to the user input question based on the local file is obtained.
[0047] Figure 2 It is a schematic diagram of a feature vector acquisition process according to the related technology.
[0048] In the related technology, the user uploads the original file and extracts the original knowledge text through the data loader, wherein the original file may contain one or more text files containing original text information, the original knowledge text is segmented through a text splitter to obtain multiple text fragments, and the vector information corresponding to the multiple text fragments is extracted by calling the embedding interface, and the vector information and the corresponding text fragments are stored in the vector database in the form of key-value pairs, wherein the key (Key) of the key-value pair can be the vector information, and the corresponding value (Value) can be the text fragment corresponding to the vector information.
[0049] However, the related technology only performs segmentation and word embedding operations on the acquired plain text content in the preparation stage, which has disadvantages such as sensitivity to the length of text sentences, differences in descriptions, and inability to answer questions based on a single paragraph with scattered information.
[0050] In view of this, an embodiment of the present disclosure provides a knowledge question and answer method. In a knowledge question and answer method provided by the present disclosure, by using a large language model and a segmentation operation multiple times, the plain text content corresponding to the original text data is summarized and concluded to obtain one or more text fragments. Based on one or more text fragments, a multidimensional text element corresponding to each fragment is obtained. It should be understood that the multidimensional basic elements refer to a variety of different types of text information extracted from the same text fragment. For example, for the text obtained by the same summary, the keywords appearing in the text can be extracted through a large language model, and the questions that can be answered based on the text content can be listed. Each sentence in the fragment can also be obtained through a segmentation operation. The keywords, questions, and sentences in the above content all belong to basic elements of different dimensions.
[0051] Figure 3is a flow chart of a knowledge question answering method according to an exemplary embodiment. Figure 3 As shown, the knowledge question answering method includes the following steps.
[0052] In step S11, the original knowledge text and question-answer data input by the user are obtained.
[0053] In the embodiments of the present disclosure, the original knowledge text may be various types of files, for example, the original knowledge text may be one or more books or entries uploaded by a user. The question and answer data may be natural language containing questions or search contents raised by a user. It should be understood that the question and answer data should be content related to the original knowledge text data, for example, the question and answer data may be a command to summarize the content of the original knowledge text or a question raised based on the content in the original knowledge text.
[0054] In step S12, the content summary in the original knowledge text is extracted to obtain a first text segment.
[0055] In step S13, feature extraction is performed on the first text segment to obtain a feature vector.
[0056] In the disclosed embodiment, the first text segment is obtained by the original knowledge text through the segmentation operation. It should be understood that the segmentation operation can adjust the length range, segmentation symbol, priority of the segmentation symbol, overlap ratio of the text segment, etc. corresponding to the text segment obtained by the setting. The feature vector includes a keyword feature vector, a question feature vector, and a text segment feature vector. The keyword feature vector is obtained by extracting keywords in the first text segment using LLM and converting the keywords into feature vectors. The question feature vector is obtained by extracting relevant questions in the first text segment using LLM and converting the relevant questions into feature vectors. The text segment feature vector obtains the sentence corresponding to the first text segment through the segmentation operation and converts the sentence into a feature vector. For example, if the first text segment is "Xiao Ming is 8 years old this year" and "Xiao Hong likes blue", the corresponding feature vector is extracted based on the semantic information of the content of the two first text segments, wherein the feature vector represents the content of the first text segment in the form of a vector. It should be understood that feature extraction of a first text segment can obtain the values of multiple corresponding feature vectors.
[0057] In step S14, a key-value pair between the feature vector and the first text segment is created.
[0058] In the disclosed embodiment, by extracting the feature vector corresponding to the first text fragment, it should be understood that since the feature vector includes a keyword feature vector and a question feature vector, relevant keywords and related questions can be retrieved during the information retrieval process, thereby enhancing the ability to understand text knowledge that is semantically related and expressed in different ways during information retrieval.
[0059] In the disclosed embodiment, the key-value pair between the created feature vector and the first text segment can be stored in a database. For example, a vector database can be set up, and the feature vector is used as a key (Key) and the first text segment is used as a value (Value) and stored in the vector database. It should be understood that a first text segment may correspond to multiple feature vectors, and therefore, there may be a situation where multiple Keys correspond to the same Value.
[0060] In step S15, based on the key-value pair and the question and answer data, answer data for the question and answer data is determined.
[0061] In the disclosed embodiment, a similarity search can be performed between the question feature vector and the acquired key-value pair, and the answer data can be obtained based on one or more first text segments corresponding to one or more feature vectors with the highest similarity.
[0062] In an embodiment of the present disclosure, a first text segment related to question and answer data is retrieved in the form of a feature vector, wherein the feature vector includes a keyword feature vector, a question feature vector, and a text segment feature vector, thereby achieving matching based on multiple feature vectors, enhancing multimodal retrieval, retrieval extension versatility and other performances. The present disclosure has a stronger understanding of text knowledge that is semantically related and expressed in different ways, and can greatly improve retrieval accuracy.
[0063] In the disclosed embodiment, before extracting the feature vector of the first text segment, the original knowledge text may be refined and summarized by using LLM and segmentation operations multiple times to obtain one or more summarized text segments and use them as the first text segment.
[0064] Figure 4 is a flowchart of a method for obtaining a first text segment according to an exemplary embodiment. Figure 4 As shown, the first text segment acquisition method includes the following steps.
[0065] In step S21, the original knowledge text is segmented to obtain second text segments.
[0066] In the disclosed embodiment, the content summary extraction operation includes a fragmentation operation and an LLM processing operation. By performing the extraction operation multiple times and performing multiple important operations on the text segments, multi-level feature extraction is achieved. This operation can capture semantics at different levels, capture long-distance information, and summarize potential information. It should be understood that the number of content summary extraction operations can be set according to actual user needs.
[0067] In step S22, based on a preset large language model, the content summary of the second text segment is extracted to obtain a first text segment.
[0068] In the disclosed embodiment, n is a positive integer. By performing content summary extraction operations on the original text n times, the first text fragment finally obtained has a higher information concentration than the original knowledge text and can provide higher retrieval efficiency.
[0069] In the disclosed embodiment, by performing segmentation and content summary extraction operations on the original text, the query performance and processing capability can be significantly improved, and the problem of excessive information dispersion caused by the original text content being too long can be solved to a great extent.
[0070] In the disclosed embodiment, each extraction operation includes performing a segmentation operation on the text segments extracted from the previous summary, and performing summary extraction on the segmented text segments through LLM.
[0071] Figure 5 is a flowchart showing a content summary extraction operation according to an exemplary embodiment. Figure 5 As shown, the summary extraction operation includes the following steps.
[0072] In step S31, the content summaries of each of the k adjacent second text segments among the m second text segments are extracted for the i-th time to obtain p i-th level segments, where the text length of the i-th level segment is the length of one second text segment.
[0073] In the disclosed embodiment, i is a positive integer, and p and k are positive integers less than m. By extracting content summaries from m second text segments, an i-th level segment having a length of the second text segment after the summary extraction is obtained. For example, assuming that m is 10 and k is 5, content summaries are extracted from 5 adjacent second text contents, thereby obtaining 2 i-th level segments.
[0074] In step S32, the content summary of each adjacent k i-th level segments among the p i-th level segments is subjected to the i+1th content summary extraction process to obtain q i+1th level segments.
[0075] In the embodiment of the present disclosure, based on the i-th level segment obtained in step S31, the content summary extraction operation is performed on the k adjacent second text segments through LLM to obtain a text segment with the same length as the second text content, i.e., the i+1-th level segment. The same operation is performed on the other k adjacent i-th level segments in the i-th level segment, and finally q i+1-th level segments are obtained.
[0076] In step S33, the above process is repeated until the nth extraction process is performed to obtain a predefined number of nth-level segments, and the nth-level segments are used as the first text segments.
[0077] In the disclosed embodiment, the content summary extraction operation is repeated until a predefined number of content summary extraction operations are completed, and the obtained n-th level segment is used as the first text segment to complete n content summary extractions.
[0078] In an exemplary embodiment, if it is necessary to perform content summary extraction five times on 32 second text segments to obtain the first text segment, then 16 first-level segments can be obtained by first performing content summary extraction on every two adjacent second text segments in the 32 second text segments. Similarly, content summary extraction is performed on every two adjacent first-level segments in the 16 first-level segments to obtain eight second-level segments. Repeat the above operation to obtain four third-level segments, two fourth-level segments and one fifth-level segment in turn. Finally, the fifth-level segment is the first text segment.
[0079] In the disclosed embodiment, by extracting the content summaries of the adjacent k second text segments, the problems of poor information integrity and poor global understanding caused by the fragmentation operation can be avoided. Moreover, by extracting the content summaries of the adjacent k second text segments multiple times, it is possible to extract m second text segments into a target number of first text segments, and the key content information contained in the first text segment is the same as the key content information contained in the second text segment.
[0080] In the disclosed embodiment, multiple text features such as keywords, related questions, and sentences contained in the first text segment may be obtained, and feature vectors corresponding to the multiple text features may be extracted and saved.
[0081] Figure 6 is a flow chart of a method for obtaining a feature vector according to an exemplary embodiment. Figure 6 As shown, the feature vector acquisition method includes the following steps.
[0082] In step S41, a segmentation operation is performed on the first text segment using a period as a separator to obtain a third text segment.
[0083] In the embodiment of the present disclosure, by performing a segmentation operation using a period as a separator, each sentence in the first text segment can be divided. Therefore, the third text segment in the first text segment is a sentence in the first text segment.
[0084] In step S42, keywords and questions in the first text segment are extracted based on the large language model.
[0085] In the disclosed embodiment, keyword information contained in the first text segment can be extracted through a large language model, and relevant questions that can be answered by the first text segment content can be obtained based on the first text segment content.
[0086] In step S43, a feature vector is obtained based on the third text segment, the keywords and the question.
[0087] In the disclosed embodiment, the corresponding third text segment, keywords and related questions extracted from the first text segment are mapped into a feature vector.
[0088] In the disclosed embodiment, by extracting three types of features, namely, the third text segment, keywords and questions in the first text segment, and extracting the three types of features respectively to obtain feature vectors, a stronger understanding ability is achieved for text knowledge that is semantically related and expressed in different ways.
[0089] In the disclosed embodiment, the extracted feature vector and the corresponding first text segment may be stored in a vector database in the form of a key-value pair, and the reply data may be obtained based on the question and answer data and the content in the vector database.
[0090] Figure 7 is a flow chart of a knowledge question answering method according to an exemplary embodiment. Figure 7 As shown, the knowledge question answering method includes the following steps.
[0091] In step S51, based on the question-answer data, j feature vectors with the highest similarity are determined in the feature vector database.
[0092] In the disclosed embodiment, the feature vector database stores a key-value pair (Key-Value) obtained based on the first text segment, wherein the key (Key) is the feature vector and the value (Value) is the first text segment. The question-answer vector corresponding to the question-answer data is extracted, and the question-answer vector is searched for similarity with the feature vector database, for example, using the k-nearest neighbor algorithm (k-NN) to perform a similarity search to obtain the j feature vectors with the highest similarity.
[0093] In step S52, x first text segments are determined based on the j feature vectors and key-value pairs.
[0094] In the disclosed embodiment, based on the j feature vectors with the highest similarity to the question-answer vector and the key-value pairs stored in the feature vector database, x first text fragments corresponding to the j feature vectors are obtained, where x is a positive integer less than j because one text fragment may correspond to multiple feature vectors.
[0095] In step S53, the x first text segments are reordered based on the preset weights of the j feature vectors.
[0096] In the disclosed embodiment, the preset weights can be modified by the user according to his / her own needs to indicate the importance of the feature vector.
[0097] In step S54, the first y reordered first text segments and the question and answer data are input into a preset large language model as prompt information to obtain reply data of the question and answer data.
[0098] In the disclosed embodiment, the prompt information is a natural language containing the first y first text segments and question and answer data. The prompt information can be obtained by setting a prompt template and placing the first y first text segments after reordering and the question and answer data into the prompt template. The prompt information is placed into a large language model to obtain the answer data generated by the large language model based on the first y first text segments in the prompt information for the question and answer data.
[0099] In an exemplary embodiment, the feature vector includes a keyword feature vector, a question feature vector and a text segment feature vector, and the weight of the keyword feature vector is set to 1, the weight of the question feature vector is set to 2, and the weight of the text segment feature vector is set to 3. If a first text segment that is most similar to the question and answer data is to be obtained, multiple feature vectors with the highest similarity are obtained based on the question and answer data, including keyword feature vectors a1 and c1, question feature vectors a2, b2 and c2, and text segment feature vectors a3 and b3. Feature vectors a1, a2 and a3 correspond to the first text segment A, feature vectors b2 and b3 correspond to the first text segment B, and feature vectors c1 and c2 correspond to the first text segment C. Assuming that the sum of the weights of the feature vectors corresponding to the first text segment is used for reordering in this example, the sum of the weights of the feature vectors of the first text segment A is 6, the sum of the weights of the feature vectors of the first text segment B is 4, and the sum of the weights of the feature vectors of the first text segment C is 3. After reordering, the result of reordering the first text segments according to the weight sum from large to small is ABC. Therefore, the first text segment that is most similar to the question and answer data is the first text segment A. The first text segment A and the question and answer data are input into the prompt template to obtain prompt information, and the prompt information is input into the large language model to finally obtain the reply data of the question and answer data.
[0100] In the disclosed embodiment, by obtaining one or more feature vectors with the highest similarity to the question-answer vector, and obtaining the corresponding one or more first text features based on the key-value pairs stored in the feature vector database, the obtained one or more first text features and the question-answer data are combined into prompt information, which is sent to the LLM, so that the LLM gives an answer based on the content in the prompt information. The recall rate of content information can be improved, that is, the comprehensiveness and coverage in terms of retrieving and identifying relevant knowledge points. And giving an answer to the question-answer data based on the first text fragment that has been extracted for content summary can improve the accuracy of the answer and reduce the negative effects caused by length sensitivity.
[0101] Figure 8 It is a schematic diagram of a method for obtaining a first text segment according to an exemplary embodiment.
[0102] exist Figure 8 Before executing the steps in the above, you need to build the environment. For example, you can use the open source application container engine Docker to build a similarity retrieval library, or directly use the existing large language model programming framework to implement it in the data preparation stage, such as LangChain. In addition, you need to build a sentence embedding API to convert sentences into feature vectors. Finally, you need to build an LLM interface to realize content extraction, keyword and question extraction through LLM.
[0103] It should be understood that the original knowledge text may be referred to as plain text.
[0104] The user uploads the original file, which can be one or more books or entries. Through the data loader, the plain text is obtained. The plain text content passes through the text splitter to obtain multiple second text fragments. The same as the commonly used segmentation method, it is necessary to set the length range of the Section, the segmentation symbol, the priority of the segmentation symbol, the overlap ratio of the Section, etc., which can be adjusted according to needs. The second text fragment will be submitted to LLM, and LLM will extract the content summary of the adjacent k second text fragments and process them into the length of a second text fragment. The first-level fragment is obtained here. Similarly, LLM will extract the content summary of the adjacent k first-level fragments and obtain the second-level fragment, and so on, until the n-th level text fragment is obtained, and the n-th level text fragment is used as the first text fragment. The following is an example of obtaining the first text fragment:
[0105] If the plain text content contained in the document entered by the user is "In the early 20th century, the concept of computer science had not yet been formed, and computing technology was mainly based on mechanical principles. Person A's difference engine and analytical engine were outstanding examples of early attempts to automate computing, although they were never fully realized. Although the mechanical computers of this period were primitive, they laid the foundation for the later development of electronic computers.
[0106] With the advancement of electronic technology, the first generation of electronic computers was born in the late 1940s. The Computer 1 (Electronic Numerical Integrator and Computer) is the most famous example, which was used for complex calculations. Although the design of the Computer 1 was very rudimentary, it opened a new era of high-speed computing using electronic devices. After that, computer technology developed rapidly, and the second generation of computers based on transistors appeared, which greatly improved computing efficiency and reliability.
[0107] The 1970s saw the beginning of the personal computer revolution. The launch of the Enterprise 1 and Enterprise 2 brought computer technology into ordinary households for the first time, completely changing the way people work and play. The popularity of personal computers also promoted innovation in software development and digital media, laying the foundation for the subsequent Internet revolution.
[0108] The origins of the Internet can be traced back to computers in the late 1960s, which were originally designed to facilitate communication between research institutions. However, over time, the Internet has gradually developed into a global information network that has not only changed the way information is disseminated, but also spawned new social interaction patterns and business models. From early text-based services such as email and forums to today's social media, online commerce and cloud computing, the Internet has become an indispensable part of modern life. " The following second text segment can be obtained by summarizing and extracting the above content through content summary extraction and segmentation operations: "In the early 20th century, the concept of computer science had not yet been formed. Early computing technology was based on mechanical principles, such as the difference engine and analytical engine of character A. Although they were not fully realized, they laid the foundation for the development of electronic computers. In the late 1940s, with the advancement of electronic technology, the first generation of electronic computers was born, such as Computer 1, which was used for complex calculations and opened a new era of electronic high-speed computing. Subsequently, computer technology quickly evolved to the more efficient and reliable second-generation computers based on transistors. In the 1970s, personal computers brought technology into the home, driving innovation in software and digital media, and paving the way for the Internet revolution. The Internet, which began with computers in the 1960s, has evolved into a global information network, reshaping information dissemination, social interaction, and business models, and has become the core of modern life. " The second text segment is summarized and extracted through content summarization and segmentation operations, and the following first text segment can be obtained: "In the early 20th century, computing technology based on mechanical principles, such as the design of character A, paved the way for the development of electronic computers. By the end of the 1940s, the first generation of electronic computers, such as Computer 1, was born, ushering in a new era of electronic computing. The popularization of personal computers in the 1970s promoted software innovation and the development of the Internet. The Internet evolved from Computer 2 in the 1960s to a global information network, reshaping many aspects of modern society." Based on the first text segment summarized above, the word segmenter can be used to segment the segment with a period as a separator to obtain multiple sentences in the segment. Multiple keywords in the text segment can also be extracted through a large language model, such as "early 20th century, mechanical principles, person A, difference engine, parsing engine, first generation electronic computer, computer 1, electronic computing, transistor, second generation computer, 1970s, personal computer, software innovation, Internet revolution, computer 2, global information network", etc. Questions that may involve the content of the text segment can also be extracted through a large language model, such as "Which two mechanical computers designed by person A laid the foundation for the development of electronic computers in the early 20th century? What type of calculations were the first generation of electronic computers mainly used for? In the late 1940s, which technological advances led to the birth of the first generation of electronic computers? What are the significant improvements of the second generation of computers compared to the first generation of computers? In which decade did computer 2 begin and what did it eventually evolve into?", etc. The sentences, keywords and questions extracted from the text segment are collectively referred to as keys, and the text segment is referred to as value. The word embedding interface (Embedding API) submitted by the Key obtains the feature information, and the feature information and the Value are combined into a key-value pair and the Key-Value pair is submitted to the retrieval library.
[0109] In an exemplary embodiment, taking the Faiss search library provided by Langchain as an example, the following code is an example of a simple storage + search:
[0110]
[0111]
[0112] In the above code, the FAISS, OpenAIEmbeddings, and Document classes in the langchain package are imported respectively. A OurEmbeddings class is defined, which contains three methods: The __init__ method is a constructor method that is called when a new instance of the class is created. In this method, no operation is performed. The embed_document method is used to convert plain text into feature vectors. It accepts a text list (texts) and returns a two-dimensional list, in which each element is a list of random floating-point numbers of length 4, which is used to represent the feature vector. The embed_query method is used to convert the question issued by the user into a feature vector. It accepts a text (text) and returns a list of random floating-point numbers of length 4 to represent the feature vector corresponding to the question. A list of Document objects is created, each of which contains a text (page_content) and a metadata dictionary (metadata) containing an index value. A vector_store object is created using the FAISS.from_documents method. This method accepts a document list and an embedding class (OurEmbeddings in this case) and returns a vector storage object. This object may be used to store and retrieve vector representations of documents. A retriever object is created using the vector_store.as_retriever() method. This object may be used to retrieve documents relevant to a given query. The retriever.get_relevant_documents('basketball') method is used to retrieve documents relevant to the query "basketball". This method may return a list of documents that are relevant to the query "basketball". Therefore, the above code will return the document "soccer" that has the greatest similarity to "basketball".
[0113] Fig. 9 It is a schematic diagram of a knowledge question and answer according to an exemplary embodiment.
[0114] The search is performed as follows: the user submits the question and answer data, and the question and answer vector is obtained after the vector is extracted through the embedding interface. The relevant vector value is retrieved in the vector database, and the score can be calculated by cosine distance, and the number of searches can be limited according to different types. Different weights are assigned to the Key according to different types. For example, the higher the level of the Key, the lower its weight coefficient. Then, different weights are assigned to different Keys according to the weighted results. Since there are many different Keys for the same Value, it is necessary to reorder the Values according to the number of the same Value and the weight of the corresponding Key, and obtain one or more Values with the highest weight as the first text segment; at the same time, the retrieved Values may have overlapping parts, and optimization can be considered. The first text segment and the question and answer data are embedded in the Prompt Template to obtain the Prompt. Exemplarily, the Prompt Template can be "prompt = 'Please answer the question according to the following information. If you don't know, answer that you don't know. Don't try to fabricate the answer. \n\n{context}\n\nQuestion: {question}\nAnswer:'". It should be understood that the Prompt Template is for reference only and depends on the different LLMs. Input the prompt into the large language model interface to get the model response. After certain processing, the model response is returned to the user.
[0115] Based on the same concept, the embodiment of the present disclosure also provides a knowledge question and answer device.
[0116] It is understandable that the knowledge question and answer device provided by the embodiment of the present disclosure includes hardware structures and / or software modules corresponding to the execution of each function in order to realize the above functions. In combination with the units and algorithm steps of each example disclosed in the embodiment of the present disclosure, the embodiment of the present disclosure can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the technical solution of the embodiment of the present disclosure.
[0117] Fig.10 is a block diagram of a knowledge question answering device 100 according to an exemplary embodiment. Fig.10 The device includes a receiving unit 101, a processing unit 102, a creating unit 103 and a replying unit 104.
[0118] The receiving unit 101 is used to obtain the original knowledge text and question-answer data input by the user.
[0119] The processing unit 102 is used to extract the content summary in the original knowledge text to obtain a first text segment and to extract features from the first text segment to obtain a feature vector, which includes a keyword feature vector, a question feature vector and a text segment feature vector.
[0120] The creating unit 103 is used to create a key-value pair between the feature vector and the first text segment.
[0121] The reply unit 104 is used to determine reply data of the question and answer data based on the key-value pair and the question and answer data.
[0122] In one embodiment, the processing unit 102 extracts and processes the content summary in the original knowledge text to obtain a first text segment by: segmenting the original knowledge text to obtain a second text segment; and extracts and processes the content summary of the second text segment to obtain a first text segment.
[0123] In one embodiment, the processing unit 102 extracts the content summary of the second text segment in the following manner to obtain the first text segment: perform the i-th extraction process on the content summary of each adjacent k second text segments among the m second text segments to obtain p i-th level segments, the text length of the i-th level segment is the length of one second text segment, m and i are positive integers, and p and k are positive integers less than m; perform the i+1-th content summary extraction on each adjacent k i-th level segments among the p i-th level segments to obtain q i+1-th level segments, the text length of the i+1-th level segment is the length of one second text segment, q is a positive integer less than p; repeat the above process until the n-th extraction process is performed to obtain a predefined number of n-th level segments, and take the n-th level segment as the first text segment, where n is a positive integer.
[0124] In one embodiment, the processing unit obtains a feature vector based on the first text segment in the following manner: the first text segment is segmented using a period as a separator to obtain a third text segment; keywords and questions in the first text segment are extracted based on a large language model; and a feature vector is obtained based on the third text segment, keywords and questions.
[0125] In one embodiment, based on the key-value pairs and the question and answer data, reply data for the question and answer data is determined, including: based on the question and answer data, determining j feature vectors with the highest similarity in a feature vector database, the feature vector database containing key-value pairs, j being a positive integer; based on the j feature vectors and the key-value pairs, determining x first text segments, x being a positive integer less than or equal to j; based on the preset weights of the j feature vectors, reordering the x first text segments; inputting the first y first text segments after reordering and the question and answer data as prompt information into a preset large language model, and obtaining the reply data for the question and answer data to obtain the model reply content.
[0126] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0127] Fig.11 2 is a block diagram of a device 200 for knowledge question answering according to an exemplary embodiment. For example, the device 200 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0128] Reference Fig.11 , the device 200 may include one or more of the following components: a processing component 202 , a memory 204 , a power component 206 , a multimedia component 208 , an audio component 210 , an input / output (I / O) interface 212 , a sensor component 214 , and a communication component 216 .
[0129] The processing component 202 generally controls the overall operation of the device 200, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 202 may include one or more processors 220 to execute instructions to perform all or part of the steps of the above-described method. In addition, the processing component 202 may include one or more modules to facilitate interaction between the processing component 202 and other components. For example, the processing component 202 may include a multimedia module to facilitate interaction between the multimedia component 208 and the processing component 202.
[0130] The memory 204 is configured to store various types of data to support operations on the device 200. Examples of such data include instructions for any application or method operating on the device 200, contact data, phone book data, messages, pictures, videos, etc. The memory 204 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0131] The power component 206 provides power to the various components of the device 200. The power component 206 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device 200.
[0132] The multimedia component 208 includes a screen that provides an output interface between the device 200 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 208 includes a front camera and / or a rear camera. When the device 200 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0133] The audio component 210 is configured to output and / or input audio signals. For example, the audio component 210 includes a microphone (MIC), and when the device 200 is in an operation mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 204 or sent via the communication component 216. In some embodiments, the audio component 210 also includes a speaker for outputting audio signals.
[0134] I / O interface 212 provides an interface between processing component 202 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0135] The sensor assembly 214 includes one or more sensors for providing various aspects of the status assessment of the device 200. For example, the sensor assembly 214 can detect the open / closed state of the device 200, the relative positioning of components, such as the display and keypad of the device 200, the sensor assembly 214 can also detect the position change of the device 200 or a component of the device 200, the presence or absence of user contact with the device 200, the orientation or acceleration / deceleration of the device 200 and the temperature change of the device 200. The sensor assembly 214 can include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 214 can also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 214 can also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor or a temperature sensor.
[0136] The communication component 216 is configured to facilitate wired or wireless communication between the device 200 and other devices. The device 200 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 216 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 216 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0137] In an exemplary embodiment, the apparatus 200 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above method.
[0138] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 204 including instructions, and the instructions can be executed by the processor 220 of the device 200 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0139] It is to be understood that in the present disclosure, "plurality" refers to two or more than two, and other quantifiers are similar. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. The singular forms "a", "the" and "the" are also intended to include plural forms, unless the context clearly indicates other meanings.
[0140] It is further understood that the terms "first", "second", etc. are used to describe various information, but such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other, and do not indicate a specific order or degree of importance. In fact, the expressions "first", "second", etc. can be used interchangeably. For example, without departing from the scope of the present disclosure, the first information can also be referred to as the second information, and similarly, the second information can also be referred to as the first information.
[0141] It can be further understood that, unless otherwise specified, “connection” includes a direct connection without other components between the two, and also includes an indirect connection with other components between the two.
[0142] It is further understood that, although the operations are described in a specific order in the drawings in the embodiments of the present disclosure, it should not be understood as requiring the operations to be performed in the specific order shown or in a serial order, or requiring the execution of all the operations shown to obtain the desired results. In certain environments, multitasking and parallel processing may be advantageous.
[0143] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any modifications, uses or adaptations of the present disclosure, which follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure.
[0144] It should be understood that the present disclosure is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the scope of the appended claims.
Claims
1. A knowledge question answering method, characterized in that: include: Obtain the original knowledge text and question-answer data input by the user; Extracting the content summary in the original knowledge text to obtain a first text segment; Extracting features from the first text segment to obtain a feature vector, wherein the feature vector includes a keyword feature vector, a question feature vector, and a text segment feature vector; Creating a key-value pair between the feature vector and the first text segment; Based on the key-value pair and the question and answer data, answer data for the question and answer data is determined.
2. The knowledge question answering method according to claim 1, characterized in that: The extracting process of the content summary in the original knowledge text to obtain the first text segment includes: Performing a segmentation operation on the original knowledge text to obtain a second text segment; Based on a preset large language model, the content summary of the second text segment is extracted to obtain the first text segment.
3. The knowledge question answering method according to claim 2, characterized in that: The extracting process of the content summary of the second text segment includes: Performing an i-th extraction process on the content summaries of each of the k adjacent second text segments among the m second text segments to obtain p i-th level segments, wherein the text length of the i-th level segment is the length of one second text segment, m and i are positive integers, and p and k are positive integers less than m; Performing an i+1th extraction process on the content summaries of each of the k adjacent i-th level segments among the p i-th level segments to obtain q i+1-th level segments, wherein the text length of the i+1-th level segment is the length of a second text segment, and q is a positive integer less than p; The above process is repeated until the nth extraction process is performed to obtain a predefined number of nth-level segments, and the nth-level segments are used as the first text segment, where n is a positive integer.
4. The knowledge question answering method according to any one of claims 1 to 3, characterized in that: The obtaining of a feature vector based on the first text segment includes: The first text segment is segmented using a period as a separator to obtain a third text segment; Extracting keywords and questions from the first text segment based on a large language model; The feature vector is obtained based on the third text segment, the keyword and the question.
5. The knowledge question answering method according to any one of claims 1 to 4, characterized in that: The step of determining the answer data of the question and answer data based on the key-value pair and the question and answer data includes: Based on the question and answer data, determine j feature vectors with the highest similarity in a feature vector database, the feature vector database contains the key-value pairs, and j is a positive integer; Based on the j feature vectors and key-value pairs, determine x first text segments, where x is a positive integer less than or equal to j; Reordering the x first text segments based on the weights of the j feature vectors; The first y reordered text segments and the question and answer data are input into a preset large language model as prompt information to obtain reply data for the question and answer data, where y is a positive integer less than or equal to x.
6. A knowledge question-answering device, characterized in that: include: A receiving unit, used to obtain original knowledge text and question-answer data input by the user; A processing unit, configured to extract the content summary in the original knowledge text to obtain a first text segment; The processing unit is further used to extract features from the first text segment to obtain a feature vector, wherein the feature vector includes a keyword feature vector, a question feature vector, and a text segment feature vector; A creating unit, used for creating a key-value pair between the feature vector and the first text segment; A reply unit is used to determine reply data of the question and answer data based on the key-value pair and the question and answer data.
7. The knowledge question-answering device according to claim 6, characterized in that: The processing unit extracts the content summary in the original knowledge text in the following manner to obtain a first text segment: Performing a segmentation operation on the original knowledge text to obtain a second text segment; Based on a preset large language model, the content summary of the second text segment is extracted to obtain the first text segment.
8. The knowledge question-answering device according to claim 7, characterized in that: The processing unit extracts the content summary of the second text segment in the following manner: Performing an i-th extraction process on the content summaries of each of the k adjacent second text segments among the m second text segments to obtain p i-th level segments, wherein the text length of the i-th level segment is the length of one second text segment, m and i are positive integers, and p and k are positive integers less than m; Performing an i+1th extraction process on the content summaries of each of the k adjacent i-th level segments among the p i-th level segments to obtain q i+1-th level segments, wherein the text length of the i+1-th level segment is the length of a second text segment, and q is a positive integer less than p; The above process is repeated until the nth extraction process is performed to obtain a predefined number of nth-level segments, and the nth-level segments are used as the first text segment, where n is a positive integer.
9. The knowledge question answering device according to any one of claims 6 to 8, characterized in that: The processing unit obtains a feature vector based on the first text segment in the following manner: The first text segment is segmented using a period as a separator to obtain a third text segment; Extracting keywords and questions from the first text segment based on a large language model; The feature vector is obtained based on the third text segment, the keyword and the question.
10. The knowledge question answering device according to any one of claims 6 to 9, characterized in that: The step of determining the answer data of the question and answer data based on the key-value pair and the question and answer data includes: Based on the question and answer data, determine j feature vectors with the highest similarity in a feature vector database, the feature vector database contains the key-value pairs, and j is a positive integer; Based on the j feature vectors and key-value pairs, determine x first text segments, where x is a positive integer less than or equal to j; Reordering the x first text segments based on the preset weights of the j feature vectors; The first y reordered text segments and the question and answer data are input into a preset large language model as prompt information to obtain the model reply content by obtaining the reply data of the question and answer data, where y is a positive integer less than or equal to x.
11. A knowledge question-answering device, characterized in that: include: processor; a memory for storing processor-executable instructions; Wherein, the processor is configured to: execute the method described in any one of claims 1 to 5.
12. A storage medium, characterized in that: The storage medium stores instructions, and when the instructions in the storage medium are executed by a processor of the terminal, the terminal is enabled to execute the method according to any one of claims 1 to 5.
Citation Information
Cited By
Method and system for multi-dimensionally summarizing classroom live-recorded texts
CN120319248A
A method and system for multi-dimensional summarization of classroom transcripts
CN120319248B