Text generation method and device, electronic equipment and readable storage medium

By vectorizing question text and selecting relevant documents for background text, the method enhances the accuracy and professionalism of large language model-generated answers, addressing the inaccuracy of existing text generation methods.

CN119226455APending Publication Date: 2024-12-31BEIJING LONGZHI DIGITAL TECH CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411140527.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-19
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

Existing text generation methods using large language models are inaccurate due to insufficient attention to questions, leading to irrelevant and unprofessional answer generation when faced with large amounts of information.

Method used

A method involving vectorization of question text to obtain a question vector, selecting relevant documents based on similarity scores, sorting and concatenating these documents to form background text, and generating prompt words to guide the large language model for accurate answer generation.

Benefits of technology

Improves the professionalism and accuracy of answer text by ensuring relevance to the question, reducing irrelevant information, and enhancing the relevance and clarity of the generated responses.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119226455A_ABST
    Figure CN119226455A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of artificial intelligence, and provides a text generation method and device, electronic equipment and a readable storage medium. The method comprises the following steps: receiving a question text, and vectorizing the question text to obtain a question vector; obtaining each document vector in a preset document vector library of a field corresponding to the question text, calculating a similarity score between each document vector and the question vector, and obtaining a related document based on the similarity; matching degree scores of semantic matching degrees of the related documents and the question text are obtained, the related documents are sorted according to the sequence of the matching degree scores from high to low, the related documents are spliced according to the sorting sequence, and a background text is obtained; and generating cue words based on the background text and the question text, and inputting the cue words to the large language model, so that the large language model generates an answer text. Vector similarity calculation and the semantic matching degree are combined, the retrieval precision is improved, and then the accuracy of the answer text generated by the large language model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method, device, electronic device and readable storage medium for generating text. Background Art

[0002] With the popularization of the Internet, the amount of information is growing exponentially, and it is becoming increasingly difficult for users to find the answers they need in the massive amount of information. The existing way to search for corresponding answers is usually to locate the corresponding answers by performing keyword matching and text analysis based on the questions entered by the user. However, keyword matching methods often rely on literal matching and cannot fully understand the true intention and context behind the query. In addition, as the amount of information grows, using keyword matching to find a large number of relevant documents still makes users face the challenge of filtering valid information from these documents.

[0003] In this regard, the existing technology uses natural language processing technology to solve the above problems. By using deep learning models to understand the semantics of retrieved relevant documents, and generating summaries or directly generating answers to corresponding questions, the accuracy of the answer content is improved and the acquisition of repeated text is reduced. However, when a large language model is used directly to generate answers, there are often too many relevant documents, which leads to inaccurate answer generation due to insufficient attention to the questions when the large language model generates summaries or directly generates corresponding questions.

[0004] Therefore, a text generation method is urgently needed to solve the problem that the generation of answer text in the prior art cannot meet user needs. Summary of the invention

[0005] In view of this, embodiments of the present application provide a text generation method, device, electronic device and readable storage medium to solve the problem of inaccurate answer text generation in the prior art.

[0006] A first aspect of an embodiment of the present application provides a text generation method, comprising:

[0007] Receive the question text, and vectorize the question text to obtain a question vector corresponding to the question text;

[0008] Obtain each document vector in a preset document vector library corresponding to the field of the question text, calculate the similarity score between each document vector and the question vector, and based on the similarity score of each document vector, select text information corresponding to a preset number of document vectors with the highest similarity scores as relevant documents;

[0009] Obtaining a matching score of the semantic matching degree between each relevant document and the question text, sorting each relevant document in descending order according to the matching score, and concatenating all sorted relevant documents in the sorted order to obtain background text related to the question text;

[0010] Prompt words are generated based on the background text and the question text, and the prompt words are input into the large language model so that the large language model generates answer text corresponding to the question text according to the background text.

[0011] A second aspect of the embodiments of the present application provides a device for generating text, including:

[0012] An extraction module is used to receive a question text and perform vectorization on the question text to obtain a question vector corresponding to the question text;

[0013] A screening module is used to obtain each document vector in a preset document vector library corresponding to the field of the question text, calculate the similarity score between each document vector and the question vector, and based on the similarity score of each document vector, select the text information corresponding to a preset number of document vectors with the highest similarity scores as relevant documents;

[0014] A rearrangement module is used to obtain a matching score of the semantic matching degree between each relevant document and the question text, sort each relevant document in descending order according to the matching score, and splice all sorted relevant documents in the sorted order to obtain background text related to the question text;

[0015] The execution module is used to generate prompt words based on the background text and the question text, and input the prompt words into the large language model so that the large language model generates an answer text corresponding to the question text according to the background text.

[0016] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.

[0017] According to a fourth aspect of an embodiment of the present application, a readable storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.

[0018] Compared with the prior art, the embodiments of the present application have the following beneficial effects: by receiving a question text, in order to quickly locate relevant documents, the question text is vectorized to obtain a corresponding question vector, and then in order to achieve efficient and professional information retrieval, each document vector in a preset document vector library in the field corresponding to the question text is obtained, and the similarity score between each document vector and the question vector is calculated, and then the correlation between the question vector and the document vector is obtained according to the similarity score, and the text information corresponding to a preset number of document vectors with the highest similarity score is selected as the relevant document, and then the matching score of the semantic matching degree between each relevant document and the question text is obtained, and each relevant document is sorted in order from high to low according to the matching score, and all sorted relevant documents are spliced ​​in the sorting order to obtain background text related to the question text, and then a logically clear and information-dense data is provided for the large language model, and then a prompt word is generated based on the background text and the question text, and the prompt word is input into the large language model, so that the large language model generates an answer text corresponding to the question text according to the background text, so that the content of the answer text is more in line with the relevant document, and the professionalism and accuracy of the answer text are improved, thereby solving the needs of users. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0020] Figure 1 is a schematic diagram of an application scenario of an embodiment of the present application;

[0021] Figure 2 It is a flowchart of a method for generating text provided in an embodiment of the present application;

[0022] Figure 3 It is a schematic diagram of an embodiment of a method for text generation provided by the present application;

[0023] Figure 4 It is a structural schematic diagram of a text generation device provided in an embodiment of the present application;

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

[0025] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.

[0026] Figure 1 1 is a schematic diagram of an application scenario of an embodiment of the present application. The application scenario may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a server 104, and a network 105.

[0027] The first terminal device 101, the second terminal device 102, and the third terminal device 103 can be hardware or software. When the first terminal device 101, the second terminal device 102, and the third terminal device 103 are hardware, they can be various electronic devices with display screens and supporting communication with the server 104, including but not limited to smart phones, tablet computers, laptop portable computers, and desktop computers; when the first terminal device 101, the second terminal device 102, and the third terminal device 103 are software, they can be installed in the electronic devices described above. The first terminal device 101, the second terminal device 102, and the third terminal device 103 can be implemented as multiple software or software modules, or as a single software or software module, which is not limited in the embodiment of the present application. Further, various applications can be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as data processing applications, instant messaging tools, social platform software, search applications, shopping applications, etc.

[0028] The server 104 may be a server that provides various services, for example, a background server that receives a request sent by a terminal device that establishes a communication connection with the server, and the background server may receive and analyze the request sent by the terminal device, and generate a processing result. The server 104 may be a single server, or a server cluster composed of several servers, or a cloud computing service center, which is not limited in the present embodiment of the application.

[0029] It should be noted that the server 104 can be hardware or software. When the server 104 is hardware, it can be various electronic devices that provide various services for the first terminal device 101, the second terminal device 102, and the third terminal device 103. When the server 104 is software, it can be multiple software or software modules that provide various services for the first terminal device 101, the second terminal device 102, and the third terminal device 103, or it can be a single software or software module that provides various services for the first terminal device 101, the second terminal device 102, and the third terminal device 103, and the embodiment of the present application does not limit this.

[0030] The network 105 can be a wired network connected by coaxial cable, twisted pair and optical fiber, or it can be a wireless network that can interconnect various communication devices without wiring, such as Bluetooth, Near Field Communication (NFC), infrared, etc., which is not limited in the embodiments of the present application.

[0031] The user can establish a communication connection with the server 104 via the network 105 through the first terminal device 101, the second terminal device 102 and the third terminal device 103 to receive or send information, etc. Specifically, after the user inputs the question text information into the server 104, the server 104 receives the question text, performs vectorization processing on the question text to obtain the question vector corresponding to the question text; obtains each document vector in the preset document vector library of the field corresponding to the question text, calculates the similarity score between each document vector and the question vector, and selects the text information corresponding to the preset number of document vectors with the highest similarity score based on the similarity score of each document vector to determine as the relevant document; obtains the matching score of the semantic matching degree between each relevant document and the question text, sorts each relevant document in the order of matching score from high to low, and splices all sorted relevant documents in the sorting order to obtain the background text related to the question text; generates prompt words based on the background text and the question text, and inputs the prompt words into the large language model, so that the large language model generates the answer text corresponding to the question text according to the background text.

[0032] It should be noted that the specific types, quantities and combinations of the first terminal device 101, the second terminal device 102 and the third terminal device 103, the server 104 and the network 105 can be adjusted according to the actual needs of the application scenario, and the embodiments of the present application do not limit this.

[0033] Figure 2 It is a flowchart of a method for text generation provided in an embodiment of the present application. Figure 2 The text generation method can be done by Figure 1 The terminal device or server executes. Figure 2 As shown, the text generation method includes:

[0034] S201, receiving a question text, and performing vectorization processing on the question text to obtain a question vector corresponding to the question text;

[0035] S202, obtaining each document vector in a preset document vector library corresponding to the field of the question text, calculating the similarity score between each document vector and the question vector, and based on the similarity score of each document vector, selecting text information corresponding to a preset number of document vectors with the highest similarity scores as relevant documents;

[0036] S203, obtaining a matching score of the semantic matching degree between each relevant document and the question text, sorting each relevant document in descending order according to the matching score, and concatenating all sorted relevant documents in the sorting order to obtain background text related to the question text;

[0037] S204, generating prompt words based on the background text and the question text, and inputting the prompt words into the large language model, so that the large language model generates an answer text corresponding to the question text according to the background text.

[0038] By receiving the question text and converting it into a question vector, a preset number of related documents are screened out in a preset document vector library based on the similarity score between each document vector and the question vector, and then all the related documents are rearranged according to the semantic matching degree, and the background text is obtained by splicing according to the rearrangement order. Finally, the prompt words generated based on the question text and the background text are output to the large language model. When generating the answer text, the large language model will consider the content of the background text as much as possible. Since the background text is a related document that has been calculated by similarity and semantically rearranged, the accuracy of the generated answer text is improved by improving the relevance of the background technology.

[0039] In S201, a question text is received, and the question text is vectorized to obtain a question vector corresponding to the question text.

[0040] Specifically, the question text refers to the content of the question that the user needs help to answer. This embodiment does not limit the input method of the question text. It can come directly from the query text entered by the user or the question description submitted, or it can be text information converted from the question voice raised by the user through voice interaction through voice recognition. Vectorization is a technology that converts text information into numerical vectors. Through vectorization, the originally unstructured text data is converted into structured numerical vectors that can be directly understood and processed by computers, so that machine learning models and algorithms can directly use these numerical inputs for subsequent processing.

[0041] Vectorization can be performed through the one-hot model, bag-of-words model, word frequency inverse document frequency, N-gram model, word vector model, etc. The one-hot model is called one-bit effective encoding. For each word, a very sparse vector is created, in which most elements are 0 and only one element is 1, which is used to mark the position of the word. The bag-of-words model regards the text as an unordered collection of words, ignores the position information of the words in the text, and constructs the vector by counting the frequency of each word or using word frequency normalization. On the basis of the bag-of-words model, the word frequency inverse document frequency introduces the inverse document frequency to adjust the word frequency, so as to reduce the weight of common words and increase the weight of unique or important words in the document. The N-gram model takes into account the word sequence and constructs the vector by counting the frequency of N adjacent words. The word vector model learns the distributed representation of words through a neural network. Each word is mapped to a continuous vector space of a fixed length. The distance between vectors can reflect the similarity of word meaning.

[0042] By receiving the question text and vectorizing the question text into a question vector, the text data is converted into numerical data, so that different text information can be compared and analyzed in the same mathematical space. The vectorized data can be directly used as input for various machine learning and deep learning models, which is convenient for computer processing and understanding. In addition, the operations between the vectorized numerical vectors are more efficient than the original text strings, thereby improving the processing speed of the search and matching process.

[0043] S202, obtaining each document vector in a preset document vector library corresponding to the field of the question text, calculating the similarity score between each document vector and the question vector, and based on the similarity score of each document vector, selecting text information corresponding to a preset number of document vectors with the highest similarity scores as relevant documents.

[0044] Specifically, the field corresponding to the question text can refer to the subject and category involved in the question text. For example, the question text involves different subjects such as science and technology, medicine, history, literature, etc., or also includes special categories, such as artificial intelligence, neuroscience, ancient Roman history, modern poetry, etc. In addition, the field corresponding to the question text can also be the corresponding enterprise data, which can be specifically divided into internal data and external data, which can be data information used within the enterprise. Internal data refers to information and documents used only within the enterprise, such as internal policies, work processes, training materials, project plans, internal research reports, etc. External data includes information such as publicity materials, product manuals, official statements, customer service guides, etc. for the public or customers of the enterprise. The document vector library refers to the database part that stores document vectors. The database includes a document database, a relationship library, and a document vector library. The document database stores the original document text used to record and manage a single field; the relationship library stores the association information between each document in the document database, including but not limited to reference relationships, author relationships, and version information; the document vector library stores the vector data of all documents in the document database.

[0045] Methods for calculating the similarity scores of each document vector and the question vector include but are not limited to cosine similarity, Euclidean distance, and Pearson correlation coefficient, wherein cosine similarity is an indicator for measuring the similarity in the direction of two non-zero vectors, regardless of length or size, and the similarity of two objects is quantified by the numerical value of cosine similarity. The larger the cosine similarity, the higher the similarity; Euclidean distance is a method for measuring the straight-line distance between two points in multidimensional space. In data analysis, it can measure the difference between two data. The smaller the value, the closer the two data are; Pearson correlation coefficient is a statistical indicator for measuring the linear correlation between two variables. Its value ranges from -1 to 1. When the coefficient is close to 1, it indicates that there is a strong positive correlation between the two variables, that is, the higher the similarity between the two data. Each document vector and the question vector are quantified by cosine similarity, Euclidean distance, Pearson correlation coefficient, etc., and the high or low similarity score corresponds to the correlation between the document vector and the question vector, so that the text information corresponding to the preset number of document vectors with the highest similarity score is selected as the relevant documents.

[0046] In addition, the method of obtaining relevant documents can also directly adopt existing vector indexing technologies, such as Weaviate database and Elasticsearch. Weaviate database is an open source vector search engine and knowledge graph platform based on GraphQL protocol, which allows users to store, retrieve and link data in a semantic way. When users make a query request through GraphQL, specify the query vector or query condition, Weaviate database calculates the similarity between the stored vector and the query vector in the background, where GraphQL is an API query language. Elasticsearch is a distributed search engine and analysis platform that allows real-time and complex data search and analysis operations on large amounts of data. Elasticsearch provides a variety of similarity calculation methods for measuring the similarity between question vectors and document vectors. For example, the cosine_similarity function is used in Elasticsearch to calculate the cosine similarity between question vectors and document vectors. Weaviate database and Elasticsearch calculate and output multiple documents through internal similarity, and then select a preset number of documents with the highest similarity scores as relevant documents.

[0047] Furthermore, the methods for determining the field to which the question text belongs include direct user input and automatic classification. Among them, direct user input refers to the user directly inputting or selecting a field label from the provided drop-down menu when asking a question, such as "technology", "medicine", "education", etc., which helps to quickly locate the corresponding document vector library. Automatic classification refers to the use of machine learning or deep learning text classification algorithms to automatically analyze the question content and classify it into the appropriate field when the user does not clearly specify the field. It can be used as an auxiliary tool to correct or supplement when the user does not specify or misspecifies the field, thereby improving the flexibility and accuracy of field matching.

[0048] In the field to which the question text belongs, we first locate the pre-built document vector library in the field, which contains the data representation of the documents in the field after vectorization. Then, we calculate the similarity score between the question vector and each document vector in the document vector library. The similarity score evaluates the similarity in the direction of the two vectors, and then obtains the relevance between the document content and the question. Finally, according to the pre-set quantity threshold and based on all the calculated similarity scores, we select the text information corresponding to the document vector with the highest score. The text information corresponding to the document vector is the actual document content. The text information corresponding to the vector of these selected documents, that is, the actual document content, is confirmed as a document collection closely related to the question, and the document collection is determined as relevant documents.

[0049] S203, obtaining a matching score of the semantic matching degree between each relevant document and the question text, sorting each relevant document in descending order according to the matching score, and concatenating all sorted relevant documents in the sorting order to obtain background text related to the question text.

[0050] Specifically, semantic matching is a quantitative evaluation of the overlap between two texts at the semantic level, aiming to deeply understand that the texts are not only similar in vocabulary, but also include the matching of concepts, intentions and contexts. The matching score and ranking can be obtained through the reranking model, including the online model accessed through the API and bge-reranker-base and bge-reranker-large, where the online model refers to a mature model that has been trained and used directly through the API interface, which is deployed in the cloud and exposed through the API service. Both bge-reranker-base and bge-reranker-large represent pre-trained models optimized for document reranking tasks. The "base" and "large" versions represent model architectures of different sizes, respectively. The specific model can be selected according to the computing power of the model, and this embodiment does not impose any restrictions on this.

[0051] In addition, the method of obtaining the matching score also includes obtaining the matching score through the language model and re-arranging the documents according to the matching score. When the number of related documents is greater than the amount of data processed by the speech model at a single time, the language model can also introduce a sliding window method to obtain the matching score, follow the bubble sort, only sort the first N texts, and then move the window to sort the subsequent N texts. After traversing the entire text, the re-ordering of the related documents is completed, wherein the bubble sort is a sorting method, by repeatedly traversing the sequence to be sorted, comparing each pair of adjacent elements, if the order of adjacent elements is wrong, the positions of the two elements are exchanged, and the sorting is completed through continuous repetition. N is a hyperparameter inside the language model, which can be set according to actual conditions. This embodiment does not limit the setting of the hyperparameter.

[0052] By obtaining the semantic matching score between each relevant document and the question text, the relevance between the relevant document and the question text is refined through the semantic matching, thereby optimizing the inaccuracy of the sorting of relevant documents, and splicing the relevant documents to obtain the background text, so that the documents in the background text that are related to the question text are ranked higher, further improving the relevance between the background text and the question text, thereby making the answer based on the question text more accurate.

[0053] S204, generating prompt words based on the background text and the question text, and inputting the prompt words into the large language model, so that the large language model generates an answer text corresponding to the question text according to the background text.

[0054] Specifically, prompt words are instructive pieces of information. The prompt words generated based on the background text and the question text can be directly spliced ​​together so that the large language model can directly and clearly convey the required information scope and query focus to the model when generating answer questions, including direct connection, use of separators, and formatting prompts. Among them, direct connection is to directly connect the background information and the question without any separation; the use of separators is to add specific separators between the question text and the background text, so that the large language model can understand the question and background technology more accurately; formatting prompts further clarify the difference between the question text and the background technology. As an example, the formatting prompt can be "background: background text; question: question text". The prompt words generated by the background text and the question text are clarified through formatting prompts, so that the large language model can quickly locate and understand the task requirements. The background text and the question text can also be summarized and then spliced ​​to generate prompt words.

[0055] In addition, the method of generating prompt words based on background text and question text also includes cleaning the background text based on the question text, and splicing the cleaned background text with the question text to obtain prompt words. Since the background text is obtained by splicing related documents according to the degree of relevance to the question text, and the text information of the screened related documents may exist in the text with low relevance to the question text, the background technology is summarized and refined by text cleaning, and concentrated on the text information related to the question text. The purpose of text cleaning is to extract information related to the question from the background text, while removing redundant, repeated or irrelevant details. The text cleaning method includes removing stop words, punctuation marks, numbers, and simplifying long sentences into key concepts, etc., and also includes identifying and retaining key information related to the question text through grammatical analysis and entity recognition technology.

[0056] According to the technical solution provided by the embodiment of the present application, by receiving the question text, in order to quickly locate the text information related to the question text, the question text is vectorized to obtain the question vector corresponding to the question text, the text information is converted into numerical information, and then each document vector in the preset document vector library of the field corresponding to the question text is obtained. Through the preset document vector library, the document vector of the document vector library can be directly used to calculate the similarity with the question vector to improve the calculation speed, and then the similarity score between each document vector and the question vector is calculated, and the correlation between the document vector and the question vector is scored through the similarity score, and then based on the similarity score of each document vector, The text information corresponding to a preset number of document vectors with the highest similarity score is selected as the relevant documents, and then the matching score of the semantic matching between each relevant document and the question text is obtained, and all the sorted relevant documents are spliced ​​in the sorted order to obtain the background text related to the question text, and the weight of the relevant documents that contain the keywords of the question text but have a low relevance to the question is reduced. Finally, prompt words are generated based on the background text and the question text, and the prompt words are input into the large language model, so that the large language model generates an answer text corresponding to the question text according to the background text, so that the large language model generates an answer text that is highly relevant to the background text, thereby improving the professionalism and accuracy of the answer text.

[0057] In some embodiments, before obtaining each document vector in a preset document vector library corresponding to the field of the question text, the method further includes:

[0058] Obtain knowledge documents from a document database, split the knowledge documents according to a preset splitting method after text preprocessing, and obtain split texts corresponding to each knowledge document;

[0059] Each split text is vectorized separately to obtain the document vector corresponding to each split text;

[0060] Store each document vector into a preset document vector library.

[0061] Specifically, the document database stores the original document text used to record and manage a single field, and stores the knowledge documents of the corresponding field. The knowledge documents contain various types of file materials of specific field information and professional knowledge, such as academic papers and research reports, technical documents, policies, regulations and standards documents, and internal corporate documents. The formats of knowledge documents include but are not limited to TXT, DOC, PDF and HTML formats. Since the stored knowledge documents are large documents, and large documents contain multiple topics or sub-topics, directly processing them as a whole may lead to information overload and make it difficult to focus on specific issues. Therefore, the knowledge documents are split after text preprocessing, and the resulting split texts can be independently correlated with the problem text, thereby improving the speed and accuracy of vector calculations. Text preprocessing includes but is not limited to document parsing and text extraction, unified encoding, noise removal, text cleaning, word segmentation, stop word removal, and morphological restoration; unified encoding converts the extracted text data into a unified encoding format to avoid garbled characters and character compatibility issues; noise removal refers to deleting irrelevant content in the text, such as special characters and comments, thereby reducing interference with similarity calculations; text cleaning further processes the text to remove redundant, erroneous or unnecessary information; word segmentation divides a continuous text sequence into independent vocabulary units; stop word removal removes frequently occurring words from the text that are not helpful for understanding the text content; morphological restoration restores different forms of words to their basic forms to simplify vocabulary diversity.

[0062] Splitting refers to the subdivision of long documents, splitting the original document into easy-to-analyze split texts; splitting methods include but are not limited to splitting the cleaned text information based on chapters and paragraphs, fixed-length splitting, keyword or topic boundary recognition, and single-sentence splitting. Splitting based on chapters and paragraphs directly divides the document according to the original chapters or paragraphs; fixed-length splitting divides the document into multiple segments according to a fixed number of words or character lengths; keyword or topic boundary recognition uses keyword extraction or topic models to identify topic transition points in the document and splits based on this boundary; single-sentence splitting splits the document into individual sentences. The preset splitting methods include a single splitting method and a splitting method determined according to the type of document. Different types of documents have different structural and content characteristics. Therefore, determining the splitting method according to the type of document can provide the accuracy of the text answering the question. As an example, when the document type is an academic paper or research report, the document theme is clear, the content of the chapters and paragraphs is unified, and it follows a logical structure. Therefore, it can be split according to the original chapters of the document; technical documents contain multiple parts, each chapter describes different subject content, and can be split according to chapters; policies, regulations and standards documents have a clear structure, usually arranged by clauses and chapters, and splitting according to chapters maintains the logical structure of the regulations; internal corporate documents usually include operating manuals and training materials, which have clear chapter divisions, that is, document splitting is based on chapters.

[0063] In addition, the preset splitting method can directly use keywords or topic boundary recognition to split documents. Keywords or topic recognition can split according to the turning points or different topics of the article. It can split according to the changes in the subject of the document content, maintain the consistency of the subject of each split text, and more accurately reflect the changes in the subject of the document content, thereby obtaining a splitting result that better meets actual needs.

[0064] According to the technical solution provided by the embodiment of the present application, after obtaining the knowledge documents in the document database, the text is first preprocessed, and then split according to the preset splitting method to ensure that each document is divided into meaningful fragments, and the split texts corresponding to each knowledge document are obtained. The split texts are vectorized separately to generate document vectors corresponding to each split text, and these document vectors are used to numerically represent each split text, and each document vector is stored in a preset document vector library, so that when screening related documents, each document vector in the preset document vector library can be directly used, thereby significantly improving the processing speed. In addition, the preset document vector library constructed by the split text information can not only significantly improve the efficiency of similarity calculation and reduce unnecessary document text acquisition, but also ensure that the large language model is more accurate in understanding the background text, thereby ensuring the processing speed while improving the accuracy of question text generation.

[0065] Furthermore, before obtaining knowledge documents from a document database and splitting the knowledge documents according to a preset splitting method after text preprocessing to obtain the split texts corresponding to each knowledge document, the method further includes:

[0066] At every preset time period, knowledge documents in the corresponding field of the document database are obtained through a network connection, and the knowledge documents are stored in the document database.

[0067] Specifically, the preset time period refers to the preset document library update cycle. As an example, the preset time period can be set to 24 hours. The knowledge documents are obtained and stored in the document database during the preset time period, ensuring the real-time nature of the document database. The way to obtain knowledge documents through network connection includes online databases and the use of web crawler technology to integrate document information from authoritative institutions, government departments, industry associations, etc. Online databases include public databases. Online databases usually refer to database services that are accessible through the Internet and store structured or unstructured data; web crawler technology can automatically capture web page content and integrate it into the document database after processing, thereby enhancing the breadth and depth of the knowledge base.

[0068] According to the technical solution provided in the embodiment of the present application, knowledge documents in a specific field are automatically obtained through a network connection during a preset time period, and these documents are effectively stored back in the document database to ensure the continuous updating and availability of knowledge.

[0069] In addition, after the knowledge document is acquired, the associated information of the acquired knowledge document and each knowledge document in the document database is stored in the relationship database; the acquired knowledge document is stored in the document database according to the associated information, and the update of the document database is completed.

[0070] The associated information includes reference relationships, author relationships, and version information. Based on the associated information, different versions of documents can be automatically identified and recorded, avoiding duplicate storage and thus improving the accuracy of knowledge documents in the document database.

[0071] Furthermore, after generating prompt words based on the background text and the question text, and inputting the prompt words into the large language model so that the large language model generates an answer text corresponding to the question text according to the background text, the method further includes:

[0072] receiving feedback instructions generated based on user feedback;

[0073] When the feedback instruction is a negative feedback instruction, an improved splitting method is obtained from a preset splitting template library, and the preset splitting method is updated according to the improved splitting method.

[0074] Among them, after receiving the answer text generated by the large language model, the user gives feedback information based on the satisfaction and accuracy of the answer text. The feedback instruction can be an adjustment instruction generated directly based on the feedback information sent by the user to guide the modification of the model parameters; the feedback instruction can also be an adjustment instruction generated by the cumulative feedback of the user's feedback information. The accumulated feedback helps to build a more comprehensive optimization strategy, which is not limited to the limitations of a single interaction. Feedback instructions include positive feedback instructions and negative feedback instructions. Positive feedback instructions indicate that the user is satisfied with the generated answer text, and negative feedback instructions indicate that the generated answer text does not meet the user's expectations or there are errors in the answer text. The preset split template library stores multiple splitting methods, including chapter and paragraph splitting, fixed-length splitting, keyword or topic boundary recognition, and single sentence splitting.

[0075] When the negative feedback instruction includes an indication of a splitting method, the improved splitting method obtained from the preset splitting template library adopts the splitting method indicated by the negative feedback instruction; and when the negative feedback instruction does not include an indication of a splitting method, a splitting method that is different from the current splitting method is sequentially obtained from the preset splitting template library as an improved splitting method.

[0076] According to the technical solution provided in the embodiment of the present application, by adjusting the splitting method of each knowledge document in the document vector library, the background text required for the large language model to generate the answer text is adjusted, thereby improving the quality of the answer text generated by the large language model and its relevance to the question text.

[0077] In addition, after the preset splitting method is updated according to the improved splitting method, the method further includes: completing the update of the document vector database based on the improved splitting method, obtaining relevant documents based on the updated document vector database, and then rearranging the relevant documents, generating background text according to the rearranged relevant documents, generating prompt words according to the background text and the question text, and inputting the prompt words into the large language model so that the large language model updates the answer text. This cycle is continued through a new round of user feedback until an answer text that satisfies the user is output.

[0078] In some embodiments, receiving a question text and vectorizing the question text to obtain a question vector corresponding to the question text includes:

[0079] Receiving a question text, and inputting the question text into an intention recognition model, so that the intention recognition model performs semantic analysis on the question text to obtain a semantic text corresponding to the question text;

[0080] The semantic text is vectorized to obtain the question vector corresponding to the semantic text.

[0081] Specifically, the intent recognition model is based on machine learning or deep learning algorithms and can understand the intent behind the question text; semantic analysis refers to the process of extracting and understanding meaning from the question text; semantic text refers to the textual description of the type of operation the user wants to perform. As an example, when the user enters the question text "I want to find a book about artificial intelligence that was published last year"; the intent recognition model analyzes the question text and finds that the operation the user wants to perform is "query for books", so the output semantic text can be "books with the theme of artificial intelligence and the publication year of 2022".

[0082] According to the technical solution provided in the embodiment of the present application, the question text is structured by performing semantic analysis on the question text to obtain a semantic text, thereby improving the efficiency and accuracy of similarity calculation when screening related documents, and improving the efficiency and accuracy of prompt word generation, thereby making the generated answer question more accurate and improving user satisfaction with the question text.

[0083] In some embodiments, generating prompt words based on background text and question text includes:

[0084] The demand scenario corresponding to the question text is determined based on the question text, and the question text and relevant documents are integrated to obtain the prompt word according to the preset prompt word structure corresponding to the demand scenario.

[0085] Specifically, the prompt word architecture refers to a set of predefined rules or templates that are used to guide the extraction of relevant and inspiring prompt words from the background text according to the demand scenario of the problem text. The demand scenarios include but are not limited to information query, operation guide, comparative evaluation, troubleshooting, and education and learning. The architectural elements of information query can be to clarify the focus of the problem and emphasize keywords. It may contain specific information such as time, place, and people. As an example, the generated prompt word is "Based on the background text, query the precise value / definition / occurrence time of [keyword]." The architectural elements of the operation guide can be to highlight the sequence of steps, mention the necessary tools or conditions, and ensure clear logic. As an example, the generated prompt word is "Refer to the background text, please follow the steps to explain how to [complete a specific task], including necessary preparatory steps and precautions." The architectural elements of comparative evaluation can be to set comparison standards and list the comparison objects. , it may be required to highlight the advantages and disadvantages. As an example, the generated prompt words are "Based on the background text, compare [object A] and [object B], and analyze their respective advantages and disadvantages in terms of performance, price, user experience, etc." The architectural elements of troubleshooting can be to describe the specific problem phenomenon and ask about possible causes and solutions. As an example, the generated prompt words are "Based on the background questions obtained, and for [specific fault phenomenon], analyze the possible causes and provide detailed solution steps." The architectural elements of educational learning can be to focus on academic concepts or theories, require clear explanations, and attach examples. As an example, the generated prompt words are "Based on the given background text, explain [academic concept] in detail and provide practical application cases."

[0086] According to the technical solution provided in the embodiment of the present application, the question text is classified into one or more preset demand scenarios according to its content. For each demand scenario, a corresponding prompt word structure is generated, and the prompt word is generated based on the corresponding prompt word structure to integrate the information of the question text and related documents. By controlling the information input to the language model, the answer generation process is optimized to ensure that the output is both consistent with the original question and fully utilizes the rich context provided by the related documents, thereby improving the accuracy of the answer text.

[0087] Furthermore, in some embodiments, after generating prompt words based on the background text and the question text, and inputting the prompt words into the large language model so that the large language model generates an answer text corresponding to the question text according to the background text, the method further includes:

[0088] receiving feedback instructions generated based on user feedback;

[0089] When the feedback instruction is a negative feedback instruction, an improved prompt word structure is obtained from a preset prompt word template library and the preset prompt word structure is updated according to the improved prompt word structure.

[0090] Specifically, feedback instructions include positive feedback instructions and negative feedback instructions. Positive feedback instructions indicate that the user is satisfied with the answer text generated by the model, indicating that the performance of the model meets or exceeds the user's expectations; negative feedback instructions indicate that the user is dissatisfied with the generated answer text. In the preset prompt word template library, multiple prompt word structures are stored for each demand scenario, corresponding to the expression of the question. For example, when the demand scenario is education and learning, the generated prompt word can be "Explain [academic concept] in detail based on the given background text, and give practical application cases." The updated prompt word structure adjusts "explain [academic concept] in detail" to "explain [academic concept] in plain language and provide analogies in life."

[0091] According to the technical solution provided by the embodiment of the present application, the feedback instruction automatically generated according to the user feedback, when the feedback instruction is a negative feedback instruction, obtains the improved prompt word architecture in the preset prompt word template library, and updates the existing preset prompt word architecture based on this architecture. By optimizing the prompt word architecture, the quality of the answer text generated by the large language model is improved, and user satisfaction is improved.

[0092] Figure 3 is an embodiment of a method for generating text provided by the present application, such as Figure 3 As shown, a method for text generation includes:

[0093] Acquire knowledge documents, extract text, clean and split the knowledge documents to obtain corresponding split texts, then vectorize the split texts to obtain corresponding document vectors, and store the document vectors in the document vector library. Receive question texts, vectorize the question texts to obtain question vectors, then calculate the similarity between the question vectors and the document vectors in the document vector library, filter out a preset number of related documents, semantically rearrange the preset number of related documents, and splice them to obtain background texts, then generate prompt words based on the background texts and question texts, and finally input the prompt words into the large language model so that the large language model generates answer texts.

[0094] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0095] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.

[0096] The following are device embodiments of the present application, which can be used to execute the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.

[0097] Figure 4 Schematic diagram of a text generation device provided in an embodiment of the present application. Figure 4 As shown, the device for generating the text includes:

[0098] The extraction module 401 is used to receive the question text and perform vectorization processing on the question text to obtain a question vector corresponding to the question text;

[0099] A screening module 402 is used to obtain each document vector in a preset document vector library corresponding to the field of the question text, calculate the similarity score between each document vector and the question vector, and based on the similarity score of each document vector, select text information corresponding to a preset number of document vectors with the highest similarity scores as relevant documents;

[0100] The rearrangement module 403 is used to obtain the matching score of the semantic matching degree between each relevant document and the question text, sort the relevant documents in descending order according to the matching score, and splice all the sorted relevant documents in the sorting order to obtain the background text related to the question text;

[0101] The execution module 404 is used to generate prompt words based on the background text and the question text, and input the prompt words into the large language model so that the large language model generates an answer text corresponding to the question text according to the background text.

[0102] In some embodiments, a splitting module is included before the screening module, and the splitting module is used to

[0103] Obtain knowledge documents from a document database, split the knowledge documents according to a preset splitting method after text preprocessing, and obtain split texts corresponding to each knowledge document; vectorize each split text separately to obtain a document vector corresponding to each split text; and store each document vector in a preset document vector library.

[0104] Furthermore, an updating module is included before the screening module. The updating module is used to obtain knowledge documents of the corresponding field of the document database through a network connection every preset time period, and store the knowledge documents in the document database.

[0105] Furthermore, the execution module also includes a splitting improvement module, which is used to receive feedback instructions generated based on user feedback; when the feedback instruction is a negative feedback instruction, an improved splitting method is obtained from the preset splitting template library, and the preset splitting method is updated according to the improved splitting method.

[0106] In some embodiments, the extraction module is specifically used to receive question text, input the question text into the intention recognition model, so that the intention recognition model performs semantic analysis on the question text to obtain a semantic text corresponding to the question text; and vectorize the semantic text to obtain a question vector corresponding to the semantic text.

[0107] In some embodiments, the execution module is further specifically used to determine a demand scenario corresponding to the question text based on the question text, and integrate the question text with relevant documents to obtain prompt words according to a preset prompt word structure corresponding to the demand scenario.

[0108] In addition, in some embodiments, a prompt word update module is also included after the execution module, and the prompt word update module is used to receive feedback instructions generated based on user feedback; when the feedback instruction is a negative feedback instruction, an improved prompt word architecture is obtained from the preset prompt word template library and the preset prompt word architecture is updated according to the improved prompt word architecture.

[0109] Figure 5 Schematic diagram of an electronic device 5 provided in an embodiment of the present application. Figure 5 As shown, the electronic device 5 of this embodiment includes: a processor 501, a memory 502, and a computer program 503 stored in the memory 502 and executable on the processor 501. When the processor 501 executes the computer program 503, the steps in the above-mentioned method embodiments are implemented. Alternatively, when the processor 501 executes the computer program 503, the functions of the modules / units in the above-mentioned device embodiments are implemented.

[0110] The electronic device 5 may be a desktop computer, a notebook, a PDA, a cloud server, or other electronic device. The electronic device 5 may include, but is not limited to, a processor 501 and a memory 502. Those skilled in the art will appreciate that Figure 5 The electronic device 5 is merely an example and does not limit the electronic device 5 , and may include more or less components than those shown in the figure, or different components.

[0111] The processor 501 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0112] The memory 502 may be an internal storage unit of the electronic device 5, for example, a hard disk or memory of the electronic device 5. The memory 502 may also be an external storage device of the electronic device 5, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 5. The memory 502 may also include both an internal storage unit of the electronic device 5 and an external storage device. The memory 502 is used to store computer programs and other programs and data required by the electronic device.

[0113] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units.

[0114] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium (e.g., a computer-readable storage medium). Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. The computer program may include computer program code, which may be in source code form, object code form, executable file or some intermediate form. Computer-readable storage media may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc.

[0115] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A method for text generation, characterized in that: include: Receiving a question text, and performing vectorization processing on the question text to obtain a question vector corresponding to the question text; Obtaining each document vector in a preset document vector library corresponding to the field of the question text, calculating a similarity score between each document vector and the question vector, and based on the similarity scores of each document vector, selecting text information corresponding to a preset number of document vectors with the highest similarity scores as relevant documents; Obtaining a semantic matching score between each of the relevant documents and the question text, sorting the relevant documents in descending order according to the matching score, and concatenating all the sorted relevant documents in the sorted order to obtain background text related to the question text; Prompt words are generated based on the background text and the question text, and the prompt words are input into a large language model so that the large language model generates an answer text corresponding to the question text according to the background text.

2. The method for text generation according to claim 1, wherein: Before obtaining each document vector in a preset document vector library corresponding to the field of the question text, the method further includes: Acquire knowledge documents from a document database, and split the knowledge documents according to a preset splitting method after text preprocessing to obtain split texts corresponding to each knowledge document; Vectorize each of the split texts to obtain a document vector corresponding to each of the split texts; Each of the document vectors is stored in a preset document vector library.

3. The method for text generation according to claim 2, characterized in that: The step of obtaining knowledge documents from a document database, and splitting the knowledge documents according to a preset splitting method after text preprocessing to obtain the split texts corresponding to the knowledge documents further includes: At every preset time period, knowledge documents in the corresponding field of the document database are obtained through a network connection, and the knowledge documents are stored in the document database.

4. The method for text generation according to claim 2, wherein: After generating prompt words based on the background text and the question text, and inputting the prompt words into a large language model so that the large language model generates an answer text corresponding to the question text based on the background text, the method further includes: receiving feedback instructions generated based on user feedback; When the feedback instruction is a negative feedback instruction, an improved splitting method is obtained from a preset splitting template library, and the preset splitting method is updated according to the improved splitting method.

5. The method for text generation according to claim 1, wherein: The receiving of the question text and vectorizing the question text to obtain a question vector corresponding to the question text includes: Receive a question text, and input the question text into an intention recognition model so that the intention recognition model performs semantic analysis on the question text to obtain a semantic text corresponding to the question text; The semantic text is vectorized to obtain a question vector corresponding to the semantic text.

6. The method for text generation according to claim 1, wherein: The generating of prompt words based on the background text and the question text includes: A demand scenario corresponding to the question text is determined based on the question text, and prompt words are obtained by integrating the question text with each of the related documents according to a preset prompt word structure corresponding to the demand scenario.

7. The method for text generation according to claim 6, characterized in that: After generating prompt words based on the background text and the question text, and inputting the prompt words into a large language model so that the large language model generates an answer text corresponding to the question text based on the background text, the method further includes: receiving feedback instructions generated based on user feedback; When the feedback instruction is a negative feedback instruction, an improved prompt word structure is obtained from a preset prompt word template library and the preset prompt word structure is updated according to the improved prompt word structure.

8. A device for text generation, characterized in that: include: An extraction module is used to receive a question text and perform vectorization processing on the question text to obtain a question vector corresponding to the question text; a screening module configured to obtain document vectors from a preset document vector library corresponding to the field of the question text, calculate a similarity score between each document vector and the question vector, and select, based on the similarity scores of each document vector, text information corresponding to a preset number of document vectors having the highest similarity scores as relevant documents; a rearrangement module for obtaining a semantic matching score between each of the relevant documents and the question text, sorting the relevant documents in descending order according to the matching score, and concatenating all the sorted relevant documents in the sorted order to obtain background text related to the question text; An execution module is used to generate prompt words based on the background text and the question text, and input the prompt words into a large language model so that the large language model generates an answer text corresponding to the question text according to the background text.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Compression method, system and device of multi-modal weight file and storage medium

    CN119493778A

  • Medical text data synthesis method based on role driving

    CN119646164A

  • Information summarization method and device based on specific task, equipment and medium

    CN120633649A