Input text processing method and device, storage medium and electronic device
By performing scene classification and keyword matching of the input text, generating prompt words and inputting into a large model to process it, the problem of single application scenarios of knowledge graphs in the existing technology is solved, and high-quality question-and-answer generation of large models in multiple application scenarios is achieved.
Patent Information
- Application Number
- CN202411754416.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-02
- Publication Date
- 2025-04-15
AI Technical Summary
In the prior art, the method of retrieval and enhanced generation is used as a source of knowledge for retrieval and enhanced generation. The application scenarios are relatively single, and there is a lack of technology for multiple application scenarios, making it difficult to support the precise reasoning and generation of large models in specific business scenarios.
By performing scene classification of the input text, determining its scene category, and keyword splitting the text, matching the target nodes in the knowledge graph based on the keywords, and generating a set of target nodes. Then, based on the input text, scene category and target node collection, the prompt word is generated, and input it into the big model for processing to generate reply text.
It improves the quality and accuracy of the content generated by big models in vertical fields, is suitable for a variety of application scenarios, reduces the error rate of content generated in specific fields, and improves the user experience.
Smart Images

Figure CN119831031A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular, to a method and device for processing input text, a storage medium, and an electronic device. Background Art
[0002] Question-answering tasks in vertical professional fields require specific scenario information and professional knowledge to give accurate answers. For this type of question-answering tasks, large language models trained on general corpora lack specific scenario knowledge, and the generated content is relatively broad, making it difficult to provide reference for practitioners in professional fields. Retrieval-Augmented Generation (RAG) is an important technical means to improve the performance of general large models in vertical field question-answering. By building a vertical field document vector database, word vector matching is used to retrieve the document fragment most relevant to the user's question from the database, and the fragment is merged with the user's question as the prompt word input of the large model, so that it can obtain vertical field document information and give more accurate answers. At present, there are related technologies that use documents, web pages, etc. as data sources for retrieval-augmented generation.
[0003] However, the retrieval enhancement generation method based on the document vector database has problems such as coarse document granularity, lack of semantic association between concepts, and difficulty in supporting multimodal data, which is not conducive to supporting the precise reasoning and generation of large models in specific business scenarios. As a representative technology of the symbolism school of artificial intelligence, the knowledge graph aims at a structured semantic knowledge base that connects entities and their attributes into a network with various relationships. It has the characteristics of accurate semantic modeling and strong interpretability. Using the knowledge graph as a knowledge source and combining it with the retrieval enhancement generation technology is an effective way to improve the question-answering effect of large models in vertical fields. At present, the existing technology has proposed attempts to enhance the retrieval generation based on the knowledge graph, but the application scenarios are relatively single and there is a lack of technology for multiple application scenarios.
[0004] Regarding the related technologies, the technical solutions that use knowledge graphs as knowledge sources for retrieval enhancement generation to improve the question-answering effect of large models in vertical fields have relatively single application scenarios and lack technologies for multiple application scenarios. No effective solutions have been proposed yet.
[0005] Therefore, it is necessary to improve the related technology to overcome the above-mentioned defects in the related technology. Summary of the invention
[0006] The embodiments of the present application provide a method and device for processing input text, a storage medium and an electronic device, so as to at least solve the problem that in the related technology, the technical solution of using knowledge graph as a knowledge source for retrieval enhancement generation to improve the question-answering effect of large models in vertical fields has a relatively single application scenario and lacks technology for multiple application scenarios.
[0007] According to one aspect of an embodiment of the present application, a method for processing input text is provided, comprising: performing scene classification on the input text q to obtain the scene category of the input text q; performing keyword splitting on the input text q, and matching target nodes in multiple entity nodes of a knowledge graph according to the obtained multiple keywords to obtain a target node set, wherein the target node set includes multiple target nodes; generating a prompt word corresponding to the input text q according to the input text q, the scene category and the target node set, and inputting the prompt word into a large model for processing to generate a reply text corresponding to the input text.
[0008] In an exemplary embodiment, scene classification is performed on the input text q to obtain the scene category of the input text q, including: text embedding is performed on the input text q with the training text to generate a text vector By formula Calculate the text vector With standard issue vector The cosine similarity of , and multiple cosine similarities are obtained, among which, is the cosine similarity, is the standard question vector corresponding to the i-th scene category; determining the maximum cosine similarity among the multiple cosine similarities, and determining the scene category corresponding to the maximum cosine similarity as the scene category of the input text q.
[0009] In an exemplary embodiment, the input text q is split into keywords, and target nodes are matched in multiple entity nodes of the knowledge graph according to the obtained multiple keywords to obtain a target node set, including: splitting the input text q into keywords by a word segmentation tool to obtain a keyword set Wherein, the keyword set includes the multiple keywords; determining the entity names e of the multiple entity nodes; and using the formula Generate the target node set, where: is the target node set, is the cosine similarity between the keyword and the entity name, and τ is the cosine similarity threshold.
[0010] In an exemplary embodiment, a prompt word corresponding to the input text q is generated according to the input text q, the scene category and the target node set, including: obtaining node attribute information and triplet data of multiple target nodes according to the scene category and the target node set, and obtaining monitoring data corresponding to multiple target nodes; generating the prompt word according to the node attribute information, the triplet data, the monitoring data and the scene category.
[0011] In an exemplary embodiment, node attribute information and triplet data of multiple target nodes are obtained according to the scene category and the target node set, and monitoring data corresponding to the multiple target nodes are obtained, including: determining an inference strategy according to the scene category, and obtaining the node attribute information and triplet data associated with the multiple target nodes in the knowledge graph according to the inference strategy, and obtaining the monitoring data corresponding to the multiple target nodes in a database according to the entity names of the multiple target nodes.
[0012] In an exemplary embodiment, generating the prompt word according to the node attribute information, the triple data, the monitoring data and the scene category includes: generating a subgraph according to the node attribute information and the triple data The node attribute information and the triple data are in the subgraph are all in string format; Combined with the monitoring data, the target string D is obtained. g ; Determine the general dispatch rule T corresponding to the input text q according to the scene category i ; The input text q, the target string D g And the general dispatch rule T i Perform splicing to obtain the prompt word.
[0013] According to another aspect of an embodiment of the present application, a device for processing input text is also provided, including: a scene classification module, used to perform scene classification on the input text q to obtain the scene category of the input text q; a matching module, used to perform keyword splitting on the input text q, and match target nodes in multiple entity nodes of the knowledge graph according to the obtained multiple keywords to obtain a target node set, wherein the target node set includes multiple target nodes; a generation module, used to generate a prompt word corresponding to the input text q according to the input text q, the scene category and the target node set, and input the prompt word into a large model for processing to generate a reply text corresponding to the input text.
[0014] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned input text processing method when running.
[0015] According to another aspect of an embodiment of the present application, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the input text processing method through the computer program.
[0016] According to another aspect of the embodiments of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps of the method described in each embodiment of the present application are implemented.
[0017] Through this application, the scene classification of the input text q is first performed to determine the scene category of the question corresponding to the input text q, and then the keyword splitting of the input text q is performed to obtain multiple keywords, and the target nodes are matched in multiple entity nodes of the knowledge graph according to the multiple keywords to obtain multiple target nodes and generate a target node set; finally, the prompt word corresponding to the input text q is generated according to the input text q, the scene category and the target node set, and the prompt word is processed by the large model to obtain the reply text corresponding to the input text q, and the processing process of the input text q is completed; the above scheme is adopted to classify the input text into scenes, so as to adopt corresponding reasoning strategies according to different scenes to obtain the corresponding target node information in the knowledge graph, and then the user question (input text), knowledge graph information and other data are spliced into prompt words and input into the large model for processing to improve the quality of the vertical field question and answer generated content; thereby solving the problem that the technical solution of using the knowledge graph as a knowledge source for retrieval enhancement generation to improve the large model in the vertical field question and answer effect is relatively single in the application scenario and lacks technology for multiple application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0019] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0020] Figure 1 It is a hardware structure block diagram of a computer terminal of a method for processing input text according to an embodiment of the present application;
[0021] Figure 2 is a flowchart of a method for processing input text according to an embodiment of the present application;
[0022] Figure 3 is an optional technical flow chart for processing input text according to an embodiment of the present application;
[0023] Figure 4 It is a structural block diagram of a device for processing input text according to an embodiment of the present application. DETAILED DESCRIPTION
[0024] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0025] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0026] The method embodiments provided in the embodiments of the present application can be executed in a computer terminal or a similar computing device. Taking running on a computer terminal as an example, Figure 1 1 is a hardware structure block diagram of a computer terminal of a method for processing input text according to an embodiment of the present application. Figure 1 As shown, the computer terminal may include one or more ( Figure 1Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor (Central Processing Unit, MCU) or a programmable logic device (Field Programmable Gate Array, FPGA)) and a memory 104 for storing data, wherein the above-mentioned computer terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above-mentioned computer terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0027] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for processing input text in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0028] A wireless network provided by a communication provider of a computer terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (Radio Frequency, referred to as RF) module, which is used to communicate with the Internet wirelessly.
[0029] In this embodiment, a method for processing input text is provided. Figure 2 is a flowchart of a method for processing input text according to an embodiment of the present application, such as Figure 2 As shown, the process includes the following steps S202-S206:
[0030] Step S202: performing scene classification on the input text q to obtain the scene category of the input text q;
[0031] Step S204: performing keyword splitting on the input text q, and matching target nodes in multiple entity nodes of the knowledge graph according to the obtained multiple keywords to obtain a target node set, wherein the target node set includes multiple target nodes;
[0032] Step S206: Generate prompt words corresponding to the input text q according to the input text q, the scene category and the target node set, and input the prompt words into the large model for processing to generate a reply text corresponding to the input text.
[0033] Through the above steps, the scene classification is first performed on the input text q to determine the scene category of the question corresponding to the input text q, and then the keyword splitting is performed on the input text q to obtain multiple keywords, and the target nodes are matched in multiple entity nodes of the knowledge graph according to the multiple keywords to obtain multiple target nodes and generate a target node set; finally, the prompt word corresponding to the input text q is generated according to the input text q, the scene category and the target node set, and the prompt word is processed by the large model to obtain the reply text corresponding to the input text q, and the processing process of the input text q is completed; the above scheme is adopted to classify the input text into scenes, so as to adopt corresponding reasoning strategies according to different scenes to obtain the corresponding target node information in the knowledge graph, and then the user question (input text), knowledge graph information and other data are spliced into prompt words and input into the large model for processing to improve the quality of the vertical field question and answer generated content; thereby solving the problem that the technical solution of using the knowledge graph as a knowledge source for retrieval enhancement generation to improve the large model in the vertical field question and answer effect is relatively single in the application scenario and lacks technology for multiple application scenarios.
[0034] In an exemplary embodiment, scene classification is performed on the input text q to obtain the scene category of the input text q, including: text embedding is performed on the input text q with the training text to generate a text vector By formula Calculate the text vector With standard issue vector The cosine similarity of , and multiple cosine similarities are obtained, among which, is the cosine similarity, is the standard question vector corresponding to the i-th scene category; determining the maximum cosine similarity among the multiple cosine similarities, and determining the scene category corresponding to the maximum cosine similarity as the scene category of the input text q.
[0035] For the text q input by the user, the pre-trained model is used to embed it, as shown in formula (1), where represents a text vector and PLM represents a pre-trained model for text embedding.
[0036]
[0037] Then, we calculate by formula (2) Standard problem vectors in the application scenario case library The cosine similarity of . Where i represents the scene category. The scene with the highest cosine similarity is selected as the scene category classification of the input text q. This classification will determine the algorithm rules for subsequent knowledge graph node retrieval, the type of database called, and the template of the prompt word, etc.
[0038]
[0039] Optionally, the input text q is split into keywords, and target nodes are matched in multiple entity nodes of the knowledge graph according to the obtained multiple keywords to obtain a target node set, including: splitting the input text q into keywords by a word segmentation tool to obtain a keyword set Wherein, the keyword set includes the multiple keywords; determining the entity names e of the multiple entity nodes; and using the formula Generate the target node set, where: is the target node set, is the cosine similarity between the keyword and the entity name, and τ is the cosine similarity threshold.
[0040] Use the word segmentation tool to split the text q (i.e. input text q) input by the user, extract the content words, and form a keyword set In this application, the knowledge graph is defined as Where ε represents the entity set in the knowledge graph, Represents the relationship set in the knowledge graph. Set the cosine similarity threshold to τ, and then use the cosine similarity to match each noun (keyword) in the keyword set with the entity name in ε. The matching formula is formula (3). Nodes with a similarity greater than τ are selected into the target node set. middle.
[0041]
[0042] Optionally, a prompt word corresponding to the input text q is generated according to the input text q, the scene category and the target node set, including: obtaining node attribute information and triplet data of multiple target nodes according to the scene category and the target node set, and obtaining monitoring data corresponding to multiple target nodes; generating the prompt word according to the node attribute information, the triplet data, the monitoring data and the scene category.
[0043] First, the algorithm rules for node retrieval in the knowledge graph are determined according to the scene category. According to the determined rules, the node attribute information and triple data of these multiple target nodes are searched in the knowledge graph based on the target node set. The entity name of the target node is used as the keyword to obtain the detection data related to the entity through the database interface of the entity attribute record. Finally, the required prompt words are generated according to the obtained node attribute information, triple data, detection data and the scene category.
[0044] Optionally, node attribute information and triplet data of multiple target nodes are obtained according to the scene category and the target node set, and monitoring data corresponding to the multiple target nodes are obtained, including: determining an inference strategy according to the scene category, and obtaining the node attribute information and triplet data associated with the multiple target nodes in the knowledge graph according to the inference strategy, and obtaining the monitoring data corresponding to the multiple target nodes in the database according to the entity names of the multiple target nodes.
[0045] Specifically, the specific process of obtaining node attribute information and triple data according to the scene category and the target node set includes: according to different scenes i, using the corresponding reasoning strategy R i Obtain relevant information of the target node e in the knowledge graph, including node attribute information, triple data, etc., to form a subgraph As shown in formula (4). In the example, the general expression of node attributes is (entity, attribute name, attribute value), and the template for converting it into a string is "{entity}'s {attribute name} is {attribute value}"; the general expression of triples is (entity 1, relationship name, entity 2), and the template for converting it into a string is "{entity 1}{relationship name}{entity 2}". The entity name in is the keyword, and the monitoring data related to the entity is obtained through the database interface recorded by the entity attribute.
[0046]
[0047] Optionally, generating the prompt word according to the node attribute information, the triple data, the monitoring data and the scene category includes: generating a subgraph according to the node attribute information and the triple data The node attribute information and the triple data are in the subgraph are all in string format; Combined with the monitoring data, the target string D is obtained. g ; Determine the general dispatch rule T corresponding to the input text q according to the scene category i; The input text q, the target string D g And the general dispatch rule T i Perform splicing to obtain the prompt word.
[0048] Based on the above steps, the process of generating prompt words according to node attribute information, triple data, monitoring data and scene category is as follows: The string obtained by concatenating all node attributes, triples, and monitoring data information in is defined as D g Under the defined scenario i, the general scheduling rule obtained from the document database is T i . The user's input text q, knowledge graph information (i.e. D g ) and the general scheduling rules are spliced into a complete prompt word Prompt(q) (i.e., prompt word). Its definition is shown in formula (5).
[0049]
[0050] It should be noted that general dispatch rules refer to predefined rules or processes for how to process and integrate information in specific scenarios. These rules are usually based on domain knowledge and experience, and are designed to guide the system on how to effectively splice and integrate user questions, information in the knowledge graph, and monitoring data when generating answers or texts to form a coherent and logically clear prompt word.
[0051] General dispatch rules may include the following:
[0052] 1. Information priority: Determine the relative importance between knowledge graph information, detection data, and user questions so that key information can be prioritized when stitching;
[0053] 2. Splicing order: define the splicing order of each part of the prompt word (such as user questions, entity attributes, triples, monitoring data) to ensure that the large model can understand and generate content according to the correct logical relationship;
[0054] 3. Information formatting: Convert knowledge graph information and monitoring data into a format that is easy for large models to understand and process, such as converting triples and attribute information into natural language descriptions through specific string templates;
[0055] 4. Information filtering: Filter the information extracted from the knowledge graph and monitoring data to ensure that only information directly related to or highly relevant to the user's question is included to avoid interference from irrelevant information;
[0056] 5. Logical connection: When splicing prompt words, use logical connecting words or sentences to build the relationship between information to ensure the coherence and logic of the prompt words.
[0057] The specific content of the general dispatch rules will vary according to different application scenarios and fields. For example, in the scenario of power system operation and maintenance, these rules may focus more on the integration of equipment status, failure mode and monitoring data; in the medical diagnosis scenario, they may focus more on the presentation of symptoms, diseases and their related knowledge. By following these rules, the system can provide structured and semantically rich input for the large model, thereby generating more accurate and professional content.
[0058] It should be noted that the data stored in the document database is mainly document information related to vertical fields. These documents may contain professional terms, concepts, cases, monitoring data, etc. After processing (such as text embedding, vectorization, etc.), these data are used to build a vertical field document vector database, so that in the process of retrieval enhancement generation, the document fragments most relevant to the user's questions can be quickly retrieved.
[0059] Specifically, the document database may store descriptions of entities and their attributes, relationship information between entities, monitoring data records, etc. This information is represented in the form of nodes and edges in the knowledge graph and can be extracted and utilized in the retrieval enhancement generation process.
[0060] The input text processing method provided by the above embodiment can more accurately understand the user's input intention, and provide richer and more relevant background knowledge for the large model through the retrieval enhancement function of the knowledge graph, thereby significantly improving the quality and accuracy of the generated content. In addition, this method can also effectively reduce the error rate of the large model in generating content in a specific field, improve user experience, and is suitable for application scenarios such as intelligent question and answer, text generation, etc. in various vertical fields.
[0061] In order to better understand the above-mentioned method for processing input text, the present application embodiment combines Figure 3 The method for processing the input text is further described, such as Figure 3 As shown, Figure 3 The technical flow chart for processing input text is shown, which specifically includes:
[0062] Step 1: For the text q input by the user, use the pre-trained model to embed it into the text, as shown in formula (1), and obtain the text vector
[0063] Step 2: Calculation Standard problem vectors in the application scenario case library The cosine similarity of is as shown in formula (2), where i represents the scene category. The scene with the highest pre-similarity is selected as the classification of the input text. This classification will determine the algorithm rules for subsequent knowledge graph node retrieval, the type of database to be called, and the template of the prompt word;
[0064] Step 3: Use the word segmentation tool to split the text q input by the user, extract the keywords, and form a keyword set (i.e. Figure 3 (Keyword list in Chinese) The knowledge graph is defined as Where ε represents the entity set in the knowledge graph, Represents the set of relations in the knowledge graph. Set the threshold of cosine similarity to τ, and then use cosine similarity to match each noun in list K with the entity name in ε. Nodes with similarity exceeding τ are selected into the target node set. In , the definition of the target node set is shown in formula (3);
[0065] Step 4: According to different scenarios i, use the corresponding reasoning strategy R i Obtain relevant information of the target node e in the knowledge graph, including node attribute information, triple data, etc., to form a subgraph As shown in formula (4). In the example, the general expression of node attributes is (entity, attribute name, attribute value), and the template for converting it into a string is "{entity}'s {attribute name} is {attribute value}"; the general expression of triples is (entity 1, relationship name, entity 2), and the template for converting it into a string is "{entity 1}{relationship name}{entity 2}". The entity name in is the keyword, and the monitoring data related to the entity is obtained through the database interface recorded by the entity attribute.
[0066] Step 5: Sub-graph The string obtained by concatenating all node attribute information, triple data and monitoring data information in is defined as D g Under the defined scenario i, the general scheduling rule obtained from the document database is T i The user question (i.e., input text q), knowledge graph information (node attribute information, triple data), and related text (general scheduling rules) are concatenated into a complete prompt word Prompt(q), which is defined as shown in formula (5). The prompt word is input into the large model to obtain the generated content (i.e., reply text) for the user input text q.
[0067] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.
[0068] In the present embodiment, a processing device for inputting text is also provided, and the device is used to implement the above-mentioned embodiment and preferred implementation mode, and the descriptions which have been made are omitted. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the equipment described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.
[0069] Figure 4 is a structural block diagram of a device for processing input text according to an embodiment of the present application, the device comprising:
[0070] A scene classification module 42, used to perform scene classification on the input text q to obtain the scene category of the input text q;
[0071] A matching module 44 is used to perform keyword splitting on the input text q, and match a target node in multiple entity nodes of the knowledge graph according to the obtained multiple keywords to obtain a target node set, wherein the target node set includes multiple target nodes;
[0072] The generation module 46 is used to generate a prompt word corresponding to the input text q according to the input text q, the scene category and the target node set, and input the prompt word into the large model for processing to generate a reply text corresponding to the input text.
[0073] Through the above device, the scene classification is first performed on the input text q to determine the scene category of the question corresponding to the input text q, and then the keyword splitting is performed on the input text q to obtain multiple keywords, and the target nodes are matched in multiple entity nodes of the knowledge graph according to the multiple keywords to obtain multiple target nodes and generate a target node set; finally, the prompt word corresponding to the input text q is generated according to the input text q, the scene category and the target node set, and the prompt word is processed by the large model to obtain the reply text corresponding to the input text q, and the processing process of the input text q is completed; the above scheme is adopted to classify the input text into scenes, so as to adopt corresponding reasoning strategies according to different scenes to obtain the corresponding target node information in the knowledge graph, and then the user question (input text), knowledge graph information and other data are spliced into prompt words and input into the large model for processing to improve the quality of the vertical field question and answer generated content; thereby solving the problem that the technical solution of using the knowledge graph as a knowledge source for retrieval enhancement generation to improve the large model in the vertical field question and answer effect is relatively single in the application scenario and lacks technology for multiple application scenarios.
[0074] Optionally, the scene classification module 42 is further configured to generate a text vector by embedding the input text q with the training text. By formula Calculate the text vector With standard issue vector The cosine similarity of , and multiple cosine similarities are obtained, among which, is the cosine similarity, is the standard question vector corresponding to the i-th scene category; determining the maximum cosine similarity among the multiple cosine similarities, and determining the scene category corresponding to the maximum cosine similarity as the scene category of the input text q.
[0075] Optionally, the matching module 44 is further configured to perform keyword segmentation on the input text q using a word segmentation tool to obtain a keyword set Wherein, the keyword set includes the multiple keywords; determining the entity names e of the multiple entity nodes; and using the formula Generate the target node set, where: is the target node set, is the cosine similarity between the keyword and the entity name, and τ is the cosine similarity threshold.
[0076] Optionally, the above-mentioned generation module 46 is also used to obtain node attribute information and triplet data of multiple target nodes according to the scene category and the target node set, and obtain monitoring data corresponding to multiple target nodes; generate the prompt word according to the node attribute information, the triplet data, the monitoring data and the scene category.
[0077] Optionally, the above-mentioned generation module 46 is also used to determine the reasoning strategy according to the scene category, and obtain the node attribute information and the triple data associated with the multiple target nodes in the knowledge graph according to the reasoning strategy, and obtain the monitoring data corresponding to the multiple target nodes in the database according to the entity names of the multiple target nodes.
[0078] Optionally, the generating module 46 is further configured to generate a subgraph according to the node attribute information and the triple data. The node attribute information and the triple data are in the subgraph are all in string format; Combined with the monitoring data, the target string D is obtained. g ; Determine the general dispatch rule T corresponding to the input text q according to the scene category i ; The input text q, the target string D g And the general dispatch rule T i Perform splicing to obtain the prompt word.
[0079] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0080] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps:
[0081] S1, performing scene classification on the input text q to obtain the scene category of the input text q;
[0082] S2, performing keyword splitting on the input text q, and matching target nodes in multiple entity nodes of the knowledge graph according to the obtained multiple keywords to obtain a target node set, wherein the target node set includes multiple target nodes;
[0083] S3, generating prompt words corresponding to the input text q according to the input text q, the scene category and the target node set, and inputting the prompt words into the large model for processing to generate a reply text corresponding to the input text.
[0084] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0085] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0086] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0087] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0088] S1, performing scene classification on the input text q to obtain the scene category of the input text q;
[0089] S2, performing keyword splitting on the input text q, and matching target nodes in multiple entity nodes of the knowledge graph according to the obtained multiple keywords to obtain a target node set, wherein the target node set includes multiple target nodes;
[0090] S3, generating prompt words corresponding to the input text q according to the input text q, the scene category and the target node set, and inputting the prompt words into the large model for processing to generate a reply text corresponding to the input text.
[0091] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0092] An embodiment of the present application further provides a computer program product, comprising a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program product, and when the computer program is executed by a processor, the steps of the method described in each embodiment of the present application are implemented.
[0093] Optionally, in this embodiment, the above computer program may be configured to implement the following steps when executed by a processor:
[0094] S1, performing scene classification on the input text q to obtain the scene category of the input text q;
[0095] S2, performing keyword splitting on the input text q, and matching target nodes in multiple entity nodes of the knowledge graph according to the obtained multiple keywords to obtain a target node set, wherein the target node set includes multiple target nodes;
[0096] S3, generating prompt words corresponding to the input text q according to the input text q, the scene category and the target node set, and inputting the prompt words into the large model for processing to generate a reply text corresponding to the input text.
[0097] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0098] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0099] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for processing input text, characterized in that: include: Performing scene classification on the input text q to obtain the scene category of the input text q; Perform keyword splitting on the input text q, and match target nodes in multiple entity nodes of the knowledge graph according to the obtained multiple keywords to obtain a target node set, wherein the target node set includes multiple target nodes; A prompt word corresponding to the input text q is generated according to the input text q, the scene category and the target node set, and the prompt word is input into the large model for processing to generate a reply text corresponding to the input text.
2. The method according to claim 1, characterized in that Performing scene classification on the input text q to obtain the scene category of the input text q includes: Generate a text vector by embedding the input text q with the training text By formula Calculate the text vector With standard issue vector The cosine similarity of , and multiple cosine similarities are obtained, among which, is the cosine similarity, is the standard question vector corresponding to the i-th scene category; A maximum cosine similarity among the multiple cosine similarities is determined, and a scene category corresponding to the maximum cosine similarity is determined as the scene category of the input text q.
3. The method according to claim 1, characterized in that: The input text q is split into keywords, and target nodes are matched in multiple entity nodes of the knowledge graph according to the obtained multiple keywords to obtain a target node set, including: The input text q is split into keywords by a word segmentation tool to obtain a keyword set Wherein, the keyword set includes the multiple keywords; Determine entity names e of the multiple entity nodes; By formula Generate the target node set, where: is the target node set, is the cosine similarity between the keyword and the entity name, and τ is the cosine similarity threshold.
4. The method according to claim 1, characterized in that Generating a prompt word corresponding to the input text q according to the input text q, the scene category and the target node set includes: Acquire node attribute information and triplet data of a plurality of the target nodes according to the scene category and the target node set, and acquire monitoring data corresponding to the plurality of the target nodes; The prompt word is generated according to the node attribute information, the triple data, the monitoring data and the scene category.
5. The method according to claim 4, characterized in that Acquiring node attribute information and triplet data of a plurality of target nodes according to the scene category and the target node set, and acquiring monitoring data corresponding to the plurality of target nodes, including: Determine an inference strategy according to the scenario category, obtain the node attribute information and the triple data associated with the multiple target nodes in the knowledge graph according to the inference strategy, and obtain the monitoring data corresponding to the multiple target nodes in the database according to the entity names of the multiple target nodes.
6. The method according to claim 4, characterized in that Generating the prompt word according to the node attribute information, the triplet data, the monitoring data and the scene category includes: Generate a subgraph according to the node attribute information and the triple data The node attribute information and the triple data are in the subgraph All are in string format; The sub-graph Combined with the monitoring data, the target string D is obtained. g ; Determine the general dispatch rule T corresponding to the input text q according to the scene category i ; The input text q, the target character string D g And the general dispatch rule T i Perform splicing to obtain the prompt word.
7. A device for processing input text, characterized in that: include: A scene classification module, used to perform scene classification on the input text q to obtain the scene category of the input text q; A matching module, used for performing keyword splitting on the input text q, and matching a target node in multiple entity nodes of the knowledge graph according to the obtained multiple keywords to obtain a target node set, wherein the target node set includes multiple target nodes; A generation module is used to generate a prompt word corresponding to the input text q according to the input text q, the scene category and the target node set, and input the prompt word into the large model for processing to generate a reply text corresponding to the input text.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method according to any one of claims 1 to 6 when executed.
9. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 6 through the computer program.
10. A computer program product, comprising 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 6 are implemented.