Prompt word optimization method and device, electronic equipment, storage medium and product
By constructing a knowledge graph and extracting contextual information to optimize prompt words, the problem of low accuracy of prompt words in open-domain dialogues is solved, thereby improving dialogue quality and user experience.
Patent Information
- Application Number
- CN202511199624.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-26
- Publication Date
- 2025-11-28
Smart Images

Figure CN121029941A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, and in particular to a prompt word optimization method and device, electronic equipment, storage medium and product. BACKGROUND
[0002] The existing mainstream prompt word optimization technology usually sets a specific prompt word template according to a specific closed domain pre-made task target, sets a specific slot, combines the prompt word according to a dialogue intent recognition template, inputs the prompt word into a large model, processes the large model output to obtain a final result returned to the user.
[0003] The existing large model prompt word optimization scheme based on a specific prompt word template can only solve the problem of a closed domain specified intent dialogue, and cannot solve the problem of accurate generation of prompt words in an open domain (no fixed theme) dialogue. SUMMARY
[0004] The present application provides a prompt word optimization method, device, electronic equipment, storage medium and product to solve the problem of low accuracy of prompt words in a no fixed theme dialogue in the prior art, and to improve the accuracy of prompt words in a no fixed theme dialogue.
[0005] In a first aspect, the present application provides a prompt word optimization method, comprising: obtaining a current round dialogue theme of a user and a language large model in a current round dialogue; extracting context information associated with the current round dialogue theme from a dialogue theme-based knowledge graph; the knowledge graph is constructed based on multiple rounds of historical dialogues of the user and the language large model; and optimizing the prompt word of the current round dialogue based on the context information.
[0006] In an embodiment, the knowledge graph includes a plurality of triple information, and each triple information includes a historical dialogue theme; the context information associated with the current round dialogue theme is extracted from the dialogue theme-based knowledge graph, including: selecting K candidate dialogue themes from the plurality of historical dialogue themes based on the word vector similarity between the current round dialogue theme and each historical dialogue theme; obtaining a similarity judgment result of the language large model on the current round dialogue theme and each candidate dialogue theme; and extracting the context information from the triple information of the candidate dialogue theme based on the similarity judgment result and the word vector similarity.
[0007] In an embodiment, the context information is extracted from the triple information of the candidate dialogue theme based on the similarity judgment result and the word vector similarity, including: determining the semantic similarity between the current round dialogue theme and each candidate dialogue theme according to the respective word vector similarity and the respective similarity judgment result; taking the candidate dialogue theme corresponding to the maximum semantic similarity as a similar theme of the current round dialogue theme; and taking the triple information of the similar theme as the context information.
[0008] In an embodiment, based on the word vector similarity between the current round of conversation topics and each historical conversation topic, K candidate conversation topics are selected from the plurality of historical conversation topics, including: the plurality of historical conversation topics with a word vector similarity greater than or equal to a set similarity are selected as the plurality of target historical conversation topics after the initial screening; all target historical conversation topics are sorted based on the word vector similarity; and K target historical conversation topics are selected as K candidate conversation topics according to the sorting result.
[0009] In an embodiment, the knowledge graph is constructed based on the following manner: obtaining a plurality of rounds of historical conversations between the user and the language large model; extracting a plurality of triple information from the plurality of rounds of historical conversations; any triple information includes a historical conversation topic, an entity, and a target relationship, the target relationship representing an association relationship between the historical conversation topic and the entity; and constructing the knowledge graph based on the triple information.
[0010] In an embodiment, after constructing the knowledge graph based on the triple information, the method further includes: merging the current round of conversation topics with similar topics in the context information, and merging the prompt words of the optimized current round of conversation with the triple information in the context information to obtain merged triple information; and updating the knowledge graph according to the merged triple information.
[0011] The application also provides a prompt word optimization device, including: a topic acquisition module configured to acquire a current round of conversation topic of a user in a current round of conversation with a language large model; a context extraction module configured to extract context information associated with the current round of conversation topic from a knowledge graph based on the conversation topic; the knowledge graph is constructed based on a plurality of rounds of historical conversations between the user and the language large model; and an optimization module configured to optimize prompt words of the current round of conversation based on the context information.
[0012] The application also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing any of the above prompt word optimization methods when executing the computer program.
[0013] The application also provides a non-transitory computer-readable storage medium having a computer program stored thereon, the computer program being executable by a processor to implement any of the above prompt word optimization methods.
[0014] The application also provides a computer program product, including a computer program, the computer program being executable by a processor to implement any of the above prompt word optimization methods.
[0015] The method, device, electronic equipment, storage medium and product for optimizing a prompt word provided by the present application obtain a current round of dialogue theme of a user and a language large model in a current round of dialogue; extract context information associated with the current round of dialogue theme from a knowledge graph based on the dialogue theme; the knowledge graph is constructed based on multiple rounds of historical dialogue of the user and the language large model; and optimize the prompt word of the current round of dialogue based on the context information. The present application realizes effective compression and extraction of the features of the dialogue of the user and the language large model based on the knowledge graph of the dialogue theme. The present application extracts the context information of the current round of dialogue theme through the knowledge graph, provides detailed associated information for understanding the current round of dialogue, and realizes accurate understanding of the current round of dialogue theme. At the same time, the prompt word of the current round of dialogue is optimized according to the context information, the background of the current round of dialogue with an unspecified theme is accurately understood with the help of the context information, and the accuracy of determining the prompt word of the current round of dialogue is improved. BRIEF DESCRIPTION OF DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without any creative effort on the basis of these drawings.
[0017] Figure 1 is one of the flowcharts of the method for optimizing a prompt word provided by the present application.
[0018] Figure 2 is the second flowchart of the method for optimizing a prompt word provided by the present application.
[0019] Figure 3 is the flowchart of updating the knowledge graph provided by the present application.
[0020] Figure 4 is the flowchart of obtaining context information provided by the present application.
[0021] Figure 5 is the schematic diagram of the knowledge graph provided by the present application.
[0022] Figure 6 is the schematic diagram of the updated knowledge graph provided by the present application.
[0023] Figure 7 is the structural schematic diagram of the prompt word optimization device provided by the present application.
[0024] Figure 8 is the structural schematic diagram of the electronic equipment provided by the present application. DETAILED DESCRIPTION
[0025] In order to make the purposes, technical solutions and advantages of the present application clearer, the technical solutions in the present application will be described clearly and completely below in combination with the drawings in the present application. Obviously, the described embodiments are some of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the protection scope of the present application.
[0026] The technical solutions of the present application will be described below in combination with the drawings. Figures 1-8 The prompt word optimization method, device and electronic equipment of the present application are described.
[0027] Figure 1 is one of the flowcharts of the prompt word optimization method provided by the present application, as shown in Figure 1 The prompt word optimization method includes steps S100 to S300, and each step is specifically as follows.
[0028] S100: Obtain the current round of dialogue theme of the user and the language large model in the current round of dialogue.
[0029] The execution subject of the present application includes a prompt word optimization device, which includes a knowledge graph construction module, a theme acquisition module, a context extraction module and an optimization module.
[0030] The language large model is a natural language processing model constructed based on deep learning technology, trained through massive text data, and has powerful language understanding, generation and reasoning capabilities.
[0031] The dialogue theme is the theme of the dialogue content of the user and the language large model.
[0032] Extract the dialogue record of the current round of the user and the language large model, and summarize the current round of dialogue theme by analyzing the main purpose of the dialogue record of the current round.
[0033] As shown in Figure 3 , summarize the theme in the current round of dialogue of the user and the language large model, and extract the current round of dialogue theme. For example, in the current round of dialogue, the user inputs the question of the language large model as: B place is very good, we want to see. Can you help us plan the itinerary? We have 3 to 7 days of time. Then the extracted current round of dialogue theme is "B place self-driving tour".
[0034] S200: Extract the context information associated with the current round of dialogue theme from the knowledge graph based on the dialogue theme.
[0035] The knowledge graph is constructed based on the multi-round historical dialogue of the user and the language large model.
[0036] A knowledge graph is a semantic representation method for organizing real-world knowledge in a graph structure. The core goal is to transform discrete information fragments into a "knowledge network" that can be understood by machines through explicit associations between entities, relationships, and attributes (e.g., topics), thereby supporting advanced cognitive tasks such as knowledge reasoning, intelligent question answering, and semantic search. The knowledge graph of the present application includes the detailed content of the multi-round historical dialogue in the simplest graph-text form.
[0037] Context information refers to background information or environmental information related to the current round of dialogue. Its core role is to provide necessary "background support" for understanding, inferring, or generating the current round of dialogue, helping to eliminate ambiguity, clarify semantic associations, or capture dynamic logic. Context information is a key element in achieving "semantic understanding" and "reasonable reasoning" in artificial intelligence, especially in natural language processing and multi-modal tasks.
[0038] The knowledge graph construction module constructs a knowledge graph of the user and the language large model based on the multi-round real-time dialogue (answer records) between the user and the language large model. The knowledge graph includes knowledge graphs of multiple historical dialogue topics.
[0039] As shown in Figure 2 For example, the knowledge graph construction module performs feature extraction (e.g., topic extraction, entity extraction, and relationship extraction) on the answer records (multi-round historical dialogue) for multiple historical dialogue topics, and performs standardization processing (e.g., entity disambiguation, attribute value construction, etc.) and merging on the extracted feature information set (e.g., triple information) for each historical dialogue topic to obtain a final integrated multiple feature information set. A real-time topic-based knowledge graph is constructed based on the final integrated multiple feature information set. After constructing the knowledge graph, the knowledge graph is stored.
[0040] As shown in Figure 2 The context extraction module extracts the feature information set with the highest association degree with the current round of dialogue topic as the context information of the current round of dialogue topic in the knowledge graph.
[0041] For example, the current round of dialogue topic is "B place self-driving tour". The historical dialogue topics in the knowledge graph include A province self-driving tour, C province self-driving tour, etc. Among them, because B place belongs to A province, it can be determined that "A province self-driving tour" and "B place self-driving tour" have the highest similarity. In the knowledge graph, the feature information set corresponding to "A province self-driving tour" is taken as the context information of "B place self-driving tour".
[0042] S300: Based on the context information, optimize the prompt word of the current round of dialogue.
[0043] The prompt word refers to the initial input text (or instruction) provided by the user or system to the language large model in artificial intelligence (for example, natural language processing), which is used to guide the language large model to understand the task target, constraint condition or expected output form, so as to generate a response meeting the requirements. The prompt word is the "bridge" of human-computer interaction, which directly affects the output quality and relevance of the language large model.
[0044] As shown in Figure 3 According to the record of the current round of dialogue, the current entity is extracted, the current relationship is extracted, and then the prompt word of the current round of dialogue is obtained. For example, the prompt word of the current round of dialogue is "3 to 7 days".
[0045] In the knowledge graph, the feature information set corresponding to "A province self-driving tour" is taken as the context information of "B place self-driving tour". The feature information set corresponding to "A province self-driving tour" includes "5 people" and "A city departure". Then "5 people" and "A city departure" are taken as the supplement of the prompt word of the current round of dialogue to optimize the prompt word of the current round of dialogue. The optimized prompt word of the current round of dialogue is "3 to 7 days", "5 people" and "A city departure".
[0046] The present application optimizes the prompt word of the current round of dialogue through context information, which can significantly improve the dialogue quality and user experience between the user and the language large model even in multi-round dialogue with changed topics.
[0047] The prompt word optimization method provided by the present application obtains the current round of dialogue theme of the user and the language large model in the current round of dialogue; extracts context information associated with the current round of dialogue theme from the knowledge graph based on the dialogue theme; the knowledge graph is constructed based on the multi-round historical dialogue between the user and the language large model; and the prompt word of the current round of dialogue is optimized based on the context information. The present application realizes effective compression and extraction of the characteristics of the dialogue between the user and the language large model based on the knowledge graph based on the dialogue theme. The present application extracts the context information of the current round of dialogue theme through the knowledge graph, which provides detailed associated information for understanding the current round of dialogue, and realizes accurate understanding of the current round of dialogue theme. At the same time, the prompt word of the current round of dialogue is optimized according to the context information, and the background of the current non-fixed theme dialogue is accurately understood with the help of the context information, thereby improving the accuracy of determining the prompt word of the current round of dialogue.
[0048] Based on the above embodiments, the knowledge graph is constructed based on the following way: Obtain the multi-round historical dialogue between the user and the language large model; Extract a plurality of triple information from the multi-round historical dialogue; any triple information includes a historical dialogue theme, an entity and a target relationship, and the target relationship represents the association relationship between the historical dialogue theme and the entity; Based on the triple information, the knowledge graph is constructed.
[0049] The triplet information in this application is a structured information unit with (entity-relationship-topic) as its core structure. Essentially, it transforms discrete information fragments into machine-understandable and computable semantic units through explicit "entity-relationship-topic" logic. The triplet information in this application forms the foundation for knowledge representation and reasoning.
[0050] For example, obtain the user's multi-turn historical dialogue with the language model, as shown in the following example.
[0051] User Input 1: We are a group of five people planning a road trip from city A. Can you recommend some tourist attractions in province A where city A is located? Language Model Answer 1: Hello! Province A boasts abundant tourism resources. Here are some popular tourist attractions: Province B: Famous for its colorful lakes and waterfalls. Province C: One of the four sacred Buddhist mountains, with beautiful natural scenery and cultural heritage. Province D: Ancient water conservancy projects showcasing the wisdom of ancient China. Province E: The world's largest stone-carved Buddha statue, possessing significant cultural value.
[0052] User Input 2: Location B looks great, we'd like to check it out. Could you help us plan our itinerary? We have 3 to 7 days.
[0053] The language model answers: Location B is located in Autonomous Prefecture A of Province A, and it takes approximately 7 to 8 hours to drive from City A. Here is a suggested itinerary for a 5-day trip: Day 1 to E, Day 2 to F, etc.
[0054] User input 3: I've been feeling a bit unwell lately, with a slight fever. Should I go to the hospital or what should I do?
[0055] For each round of real-time dialogue, the historical dialogue topics, entities, and target relationships are extracted to obtain the triplet information of the historical dialogue topics for each round. The triplet information is shown in Table 1.
[0056] Table 1
[0057] like Figure 5 As shown, an information link is constructed based on the triplet information of each round of historical dialogue topics. A knowledge graph is then obtained based on all the information links.
[0058] This application achieves efficient compression and feature extraction of multi-turn historical dialogues by extracting triple information from these dialogues. Simultaneously, extracting triple information simplifies the subsequent knowledge graph update process, thereby improving the efficiency of determining contextual information and prompts for the current dialogue turn.
[0059] Based on the above embodiment, the knowledge graph includes a plurality of triple information, and each triple information includes a historical dialogue topic.
[0060] From the knowledge graph based on the dialogue topic, context information associated with the current round dialogue topic is extracted, including the following steps: Based on the word vector similarity between the current round dialogue topic and each historical dialogue topic, K candidate dialogue topics are selected from the plurality of historical dialogue topics; Obtain the similarity judgment result of the current round dialogue topic and each candidate dialogue topic by the language large model; Based on the similarity judgment result and the word vector similarity, the context information is extracted from the triple information of the candidate dialogue topic.
[0061] The word vector similarity represents the overlap of the word vectors in the current dialogue topic and the historical dialogue topic. As shown in Figure 4 The word vector semantic rough recall algorithm is designed. The cosine similarity between the current round dialogue topic and each historical dialogue topic of the knowledge graph is obtained (for example, cosine similarity). For example, the cosine similarity between the current round dialogue topic and each historical dialogue topic is calculated.
[0062] ; Wherein, is the cosine similarity (word vector similarity) between the th historical dialogue topic B and the current round dialogue topic, is the word vector of the current round dialogue topic, is the word vector of the th historical dialogue topic.
[0063] According to the word vector similarity, K historical dialogue topics are selected from the plurality of historical dialogue topics as K candidate dialogue topics, and a candidate dialogue topic set is obtained. For example, the candidate dialogue topic set includes {B1, B2, B3, …, B K}.
[0064] According to the language large model, the language expression meaning similarity of the current round dialogue topic and each candidate dialogue topic is determined, and the similarity judgment result is obtained. The language large model compares the language meaning or relationship of the current round dialogue topic and each candidate dialogue topic, and determines the similarity judgment result according to the similarity degree of the language meaning or relationship. For example, the current round dialogue topic is "B place self-driving tour", and the candidate dialogue topic is "A province self-driving tour". Since B place belongs to A province, it is determined that the similarity judgment result of "A province self-driving tour" and "B place self-driving tour" is similar.
[0065] According to all similarity judgment results, a similarity judgment result set is obtained. For example, the similarity judgment result set includes }. wherein, is a similarity judgment result of the current round of dialogue topic and the i-th candidate dialogue topic, , i = 1, 2, 3, …, N, where N is the number of candidate dialogue topics, and the value of is 1 or 0. When the value of is 1, it means that the current round of dialogue topic and the i-th candidate dialogue topic are similar, and when the value of is 0, it means that the current round of dialogue topic and the i-th candidate dialogue topic are not similar.
[0066] Based on the similarity judgment result and the word vector similarity, the context information is extracted from the triple information of the candidate dialogue topic. For example, the semantic similarity of each candidate dialogue topic and each current round of dialogue topic is calculated according to the average value (or weighted sum value) of the similarity judgment result and the word vector similarity. Or compare the similarity judgment result and the word vector similarity, and take the larger value as the semantic similarity of the candidate dialogue topic and the current round of dialogue topic. According to the semantic similarity, all candidate dialogue topics are sorted to obtain the sorted candidate dialogue topics. For example, the candidate dialogue topics are sorted in descending order of semantic similarity, and according to the sorting result, the top N candidate dialogue topics (N candidate dialogue topics with larger semantic similarity) are selected. The context information is obtained by fusing all triple information of the N candidate dialogue topics. Wherein, N≥1.
[0067] The present application evaluates the similarity of each candidate dialogue topic and the current round of dialogue topic from the word vector angle through the word vector similarity. The present application evaluates the similarity of each candidate dialogue topic and the current round of dialogue topic from the overall angle of the topic through the similarity judgment result. The present application extracts the context information from the triple information of the candidate dialogue topic according to the similarity judgment result and the word vector similarity, which ensures that the extracted context information is related to the current round of dialogue topic.
[0068] Based on the above embodiment, based on the similarity judgment result and the word vector similarity, the context information is extracted from the triple information of the candidate dialogue topic, including the following steps: According to each word vector similarity and each similarity judgment result, determine the semantic similarity of the current round of dialogue topic and each candidate dialogue topic; The candidate dialogue topic corresponding to the maximum semantic similarity is taken as the similar topic of the current round of dialogue topic; The triple information of the similar topic is taken as the context information.
[0069] Based on the word vector similarity and the similarity judgment results, the semantic similarity between the current round of dialogue topic and each candidate dialogue topic is determined. For example, the similarity judgment results and the corresponding word vector similarities are weighted and summed, and the semantic similarity between the current round of dialogue topic and each candidate dialogue topic is obtained based on the weighted sum. The formula for calculating semantic similarity is as follows.
[0070] ; in, For the current round of dialogue topics and the first The semantic similarity of candidate dialogue topics. For the current round of dialogue topics and the first The similarity judgment results of candidate dialogue topics. For the first The word vector similarity between each candidate dialogue topic and the current dialogue topic. The weights are the preset similarity values. The weights for the similarity judgment results.
[0071] The candidate dialogue topic with the highest semantic similarity is taken as the similar topic of the current round of dialogue. All triple information of similar topics (all information links associated with similar topics) is recalled as context information.
[0072] For example, if the current dialogue topic is "self-driving tour in location B," and a similar topic is "self-driving tour in province A," then the triplet information of "self-driving tour in province A" will be used as the context information for "self-driving tour in location B." According to Table 1, the triplet information for "self-driving tour in province A" includes [self-driving tour in province A, departure point, city A] and [self-driving tour in province A, number of people, five people]. Therefore, the context information (recalled information link) for "self-driving tour in location B" is [self-driving tour in province A, departure point, city A] and [self-driving tour in province A, number of people, five people]. The recall topic for "self-driving tour in location B" is "self-driving tour in province A."
[0073] This application obtains semantic similarity by weighted summation of similarity judgment results and word vector similarity. It comprehensively considers the semantic similarity of the current dialogue topic and the historical dialogue topics, as well as the similarity judgment results of the language big model, thus achieving accurate calculation of semantic similarity.
[0074] Based on the above embodiments, based on the word vector similarity between the current dialogue topic and each historical dialogue topic, K candidate dialogue topics are selected from multiple historical dialogue topics, including: Multiple historical dialogue topics whose word vector similarity is greater than or equal to a set similarity are selected as multiple target historical dialogue topics after the initial screening. Based on the similarity of each word vector, all target historical dialogue topics are ranked; According to the sorting result, K target historical dialogue topics are selected as K candidate dialogue topics.
[0075] The similarity of each word vector is compared with the set similarity. All historical dialogue topics with the similarity are selected. Among them, is the word vector similarity of the th historical dialogue topic and the current round dialogue topic, is the set similarity.
[0076] In order to the word vector similarity from large to small, all the historical dialogue topics after the first screening are sorted to obtain the historical dialogue topic sequence after the first screening (sorting result). For example, the historical dialogue topic sequence after the first screening is {B1, B2, B3,..., B n}.
[0077] From the historical dialogue topic sequence after the first screening, the top K historical dialogue topics after the first screening are selected as K candidate dialogue topics. For example, the candidate dialogue topic set includes {B1, B2, B3,..., B K}.
[0078] According to the set similarity and K, the candidate dialogue topics are selected, the screening standard of the candidate dialogue topics can be limited according to the precision requirement of the user, and the candidate dialogue topics are selected according to the user requirement.
[0079] Based on the above embodiment, after constructing the knowledge graph based on the triple information, the following steps are further included: The current round dialogue topic is merged with the similar topics in the context information, and the prompt word of the optimized current round dialogue is merged with the triple information in the context information to obtain the merged triple information; According to the merged triple information, the knowledge graph is updated.
[0080] Information extraction is performed on the current round dialogue to extract the current round dialogue topic, extract the entity of the current round dialogue, and extract the relationship of the current round dialogue. The semantic similarity of the topic of the current round dialogue and the existing historical dialogue topics in the knowledge graph is calculated. The similarity degree of the topic of the current round dialogue and the historical dialogue topics is determined according to the semantic similarity.
[0081] If the semantic similarity of the topic of the current round dialogue and each historical dialogue topic in the knowledge graph is less than the similarity threshold, it means that the topic of the current round dialogue is not similar to all historical dialogue topics, and the topic of the current round dialogue is a new topic. According to the current round dialogue, new triple information is constructed.
[0082] If the semantic similarity between the topic of the current round of dialogue and the historical dialogue topic already existing in the knowledge graph is greater than or equal to the similarity threshold, it indicates that the topic of the current round of dialogue is similar to the historical dialogue topic. The similar topic (the historical dialogue topic with the greatest semantic similarity) of the topic of the current round of dialogue is obtained. The triple information of the topic of the current round of dialogue and the triple information of the similar topic are merged.
[0083] For example, as shown in Figure 6 The optimized prompt words of the current round of dialogue are "3 to 7 days", "5 people", and "A city of departure". The context information includes
A province self-driving tour, place of departure, A city
A province self-driving tour, number of people, five people
[0084] The current round of dialogue topic is merged with the similar topic in the context information to obtain the merged historical dialogue topic
A province self-driving tour, contains, B place self-driving tour
A province self-driving tour, contains, B place self-driving tour
B place self-driving tour, number of people, 5 people
B place self-driving tour, place of departure, A city
B place self-driving tour, time, 3 to 7 days
[0085] As shown in Figure 6 According to the merged triple information, the knowledge graph is updated in real time.
[0086] The application updates the knowledge graph in real time by merging triple information, further realizes feature extraction and compression of the multi-round historical dialogue of the user and the language large model, simplifies the knowledge graph, and further improves the efficiency of recalling similar topics and corresponding triple information.
[0087] After obtaining the current round of dialogue topic of the user and the language large model in the current round of dialogue, the following steps are further included: If no context information associated with the current round of dialogue topic is extracted in the knowledge graph, new triple information is constructed based on the current round of dialogue topic and the prompt words of the current round of dialogue; The new triple information is added to the knowledge graph to obtain a real-time updated knowledge graph.
[0088] If no context information associated with the current round of dialogue theme is extracted in the knowledge graph, it indicates that the current round of dialogue and the multi-round history dialogue are not related, and the triple information of the current round of dialogue needs to be newly constructed. For example, the current round of dialogue theme is "what to do if uncomfortable". The existing history dialogue themes in the knowledge graph include "A province self-driving tour" and "B place self-driving tour". All the history dialogue themes in the knowledge graph are not associated with the current round of dialogue theme. Then, according to the current round of dialogue theme and the prompt word of the current round of dialogue, new triple information is constructed. For example, the new triple information includes
what to do if uncomfortable, who, I
what to do if uncomfortable, symptoms, fever
[0089] The application updates the knowledge graph in real time by constructing new triple information, which improves the comprehensiveness of the knowledge graph.
[0090] The prompt word optimization device provided by the application is described below. The prompt word optimization device described below can be mutually corresponding and referred to with the prompt word optimization method described above.
[0091] As shown in Figure 7 A prompt word optimization device includes a theme acquisition module 701, a context extraction module 702, and an optimization module 703.
[0092] The theme acquisition module 701 is configured to acquire a current round of dialogue theme of a user and a language large model in a current round of dialogue.
[0093] The context extraction module 702 is configured to extract context information associated with the current round of dialogue theme from a knowledge graph based on the dialogue theme; the knowledge graph is constructed based on multi-round history dialogues of the user and the language large model.
[0094] The optimization module 703 is configured to optimize a prompt word of the current round of dialogue based on the context information.
[0095] The prompt word optimization device provided in the application obtains a current round dialogue theme of a user and a language large model in a current round dialogue; extracts context information associated with the current round dialogue theme from a knowledge graph based on the dialogue theme; the knowledge graph is constructed based on multiple historical dialogues of the user and the language large model; and optimizes the prompt word of the current round dialogue based on the context information. The knowledge graph based on the dialogue theme effectively compresses and extracts the features of the dialogue of the user and the language large model. The application extracts the context information of the current round dialogue theme through the knowledge graph, provides detailed associated information for understanding the current round dialogue, and realizes accurate understanding of the current round dialogue theme. Meanwhile, the prompt word of the current round dialogue is optimized according to the context information, the background of the current round dialogue with an unspecified theme is accurately understood with the help of the context information, and the accuracy of determining the prompt word of the current round dialogue is improved.
[0096] In one embodiment, the knowledge graph includes multiple triple information, each triple information includes a historical dialogue theme, and the context extraction module 702 is configured to: extract context information associated with the current round dialogue theme from the knowledge graph based on the dialogue theme, including: selecting K candidate dialogue themes from the multiple historical dialogue themes based on the word vector similarity between the current round dialogue theme and each historical dialogue theme; obtaining a similarity judgment result of the language large model for the current round dialogue theme and each candidate dialogue theme; performing weighted summation on the similarity judgment result of the candidate dialogue theme and the similarity of the candidate dialogue theme to obtain the semantic similarity between the current round dialogue theme and each candidate dialogue theme; determining the semantic similarity between the current round dialogue theme and each candidate dialogue theme according to the word vector similarity and the similarity judgment result; taking the candidate dialogue theme corresponding to the maximum semantic similarity as a similar theme of the current round dialogue theme; and taking the triple information of the similar theme as the context information.
[0097] In one embodiment, the context extraction module 702 is configured to: take multiple historical dialogue themes with a word vector similarity greater than or equal to a set similarity as multiple target historical dialogue themes after the first screening; sort all target historical dialogue themes based on the word vector similarity; and select K target historical dialogue themes as K candidate dialogue themes according to the sorting result.
[0098] In one embodiment, the prompt word optimization device further includes a knowledge graph construction module, the knowledge graph construction module is configured to: obtain multiple historical dialogues of a user and a language large model; extract multiple triple information from the multiple historical dialogues; any triple information includes a historical dialogue theme, an entity, and a target relationship, the target relationship represents an association relationship between the historical dialogue theme and the entity; and construct a knowledge graph based on the triple information.
[0099] In one embodiment, the knowledge graph construction module is further configured to: merge the current round of dialogue topic with similar topics in the context information, and merge the prompt word of the optimized current round of dialogue with the triple information in the context information to obtain merged triple information; and update the knowledge graph according to the merged triple information.
[0100] In one embodiment, the knowledge graph construction module 701 is further configured to: if no context information associated with the current round of dialogue topic is extracted in the knowledge graph, construct new triple information based on the current round of dialogue topic and the prompt word of the current round of dialogue; and add the new triple information to the knowledge graph to obtain a real-time updated knowledge graph.
[0101] Figure 8 An example of an entity structure diagram of an electronic device is shown in Figure 8 As shown, the electronic device can include a processor 810, a communications interface 820, a memory 830, and a communications bus 840, wherein the processor 810, the communications interface 820, and the memory 830 communicate with each other through the communications bus 840. The processor 810 can invoke the logic instructions in the memory 830 to execute the prompt word optimization method, which includes: obtaining a current round of dialogue topic of a user in a current round of dialogue with a language large model; extracting context information associated with the current round of dialogue topic from a knowledge graph based on the dialogue topic; the knowledge graph is constructed based on multiple rounds of historical dialogue of the user with the language large model; and optimizing the prompt word of the current round of dialogue based on the context information.
[0102] In addition, the logic instructions in the memory 830 described above can be implemented in the form of a software functional unit and sold or used as an independent product, which can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the parts that contribute to the prior art or parts of the technical solutions can be embodied in the form of a software product, which is stored in a storage medium, includes a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in the embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various storage media that can store program codes.
[0103] In another aspect, the present application also provides a computer program product comprising a computer program, the computer program being stored in a non-transitory computer-readable storage medium, and the computer program being executable by a processor to cause a computer to execute the prompt word optimization method provided by any of the above methods, the method comprising: obtaining a current round of dialogue topic of a user and a language large model in a current round of dialogue; extracting context information associated with the current round of dialogue topic from a knowledge graph based on the dialogue topic; the knowledge graph being constructed based on multiple rounds of historical dialogue of the user and the language large model; and optimizing the prompt word of the current round of dialogue based on the context information.
[0104] In another aspect, the present application also provides a non-transitory computer-readable storage medium having a computer program stored thereon, the computer program being executable by a processor to implement the prompt word optimization method provided by any of the above methods, the method comprising: obtaining a current round of dialogue topic of a user and a language large model in a current round of dialogue; extracting context information associated with the current round of dialogue topic from a knowledge graph based on the dialogue topic; the knowledge graph being constructed based on multiple rounds of historical dialogue of the user and the language large model; and optimizing the prompt word of the current round of dialogue based on the context information.
[0105] The device embodiments described above are only schematic, wherein the units illustrated as separate components may or may not be physically separate, and the components illustrated as units may or may not be physical units, i.e., may be located in one place or distributed on a plurality of network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the present embodiment. Those skilled in the art can understand and implement without creative labor.
[0106] From the above description of the embodiments, those skilled in the art can clearly understand that the embodiments can be implemented by means of software plus necessary universal hardware platforms, and of course can also be implemented by hardware. Based on such understanding, the above technical solutions, essentially or in other words, the part that contributes to the prior art can be embodied in the form of a software product, which can be stored in a computer-readable storage medium, such as a ROM / RAM, a magnetic disk, an optical disk, etc., and includes a plurality of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute the methods described in each embodiment or some parts of the embodiments.
[0107] Finally, it should be noted that the above examples are only used to illustrate the technical solutions of the present application, and are not intended to limit the same; although the present application has been described in detail with reference to the foregoing examples, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing examples, or make equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for optimizing prompt words, characterized in that, include: Obtain the current conversation topic between the user and the language model in the current round of the conversation; Extract contextual information associated with the current round of dialogue topic from the knowledge graph based on the dialogue topic; The knowledge graph is constructed based on the user's multi-turn historical dialogue with the language model; Based on the context information, the prompts for the current round of dialogue are optimized.
2. The prompt word optimization method according to claim 1, characterized in that, The knowledge graph includes multiple triplet information, and each triplet information includes a historical dialogue topic; The step of extracting contextual information associated with the current round of dialogue topic from a knowledge graph based on the dialogue topic includes: Based on the word vector similarity between the current dialogue topic and each of the historical dialogue topics, K candidate dialogue topics are selected from the multiple historical dialogue topics; Obtain the similarity judgment results of the language big model between the current round of dialogue topic and each of the candidate dialogue topics; Based on the similarity judgment result and the word vector similarity, the context information is extracted from the triple information of the candidate dialogue topic.
3. The prompt word optimization method according to claim 2, characterized in that, The step of extracting the context information from the triple information of the candidate dialogue topics based on the similarity judgment result and the word vector similarity includes: Based on the word vector similarity and the similarity judgment results, the semantic similarity between the current round dialogue topic and each of the candidate dialogue topics is determined; The candidate dialogue topic with the highest semantic similarity is taken as the similar topic of the current round of dialogue. The information of triples with similar topics is used as the context information.
4. The prompt word optimization method according to claim 2, characterized in that, The step involves selecting K candidate dialogue topics from a plurality of historical dialogue topics based on the word vector similarity between the current dialogue topic and each of the historical dialogue topics, including: Multiple historical dialogue topics whose word vector similarity is greater than or equal to a set similarity are selected as multiple target historical dialogue topics after initial screening. Based on the word vector similarity, all the target historical dialogue topics are ranked. Based on the sorting results, K target historical dialogue topics are selected as the K candidate dialogue topics.
5. The prompt word optimization method according to claim 1, characterized in that, The knowledge graph is constructed in the following way: Obtain the multi-turn historical dialogue between the user and the language model; Multiple triplet information is extracted from the multi-turn historical dialogue; each triplet information includes a historical dialogue topic, an entity, and a target relation, wherein the target relation represents the association relationship between the historical dialogue topic and the entity. The knowledge graph is constructed based on the triple information.
6. The prompt word optimization method according to claim 5, characterized in that, After constructing the knowledge graph based on the triple information, the method further includes: The topic of the current turn of dialogue is merged with similar topics in the context information, and the prompts of the optimized current turn of dialogue are merged with the triple information in the context information to obtain the merged triple information. The knowledge graph is updated based on the merged triple information.
7. A prompt word optimization device, characterized in that, include: The topic acquisition module is used to acquire the topic of the current round of dialogue between the user and the language model in the current round of dialogue; The context extraction module is used to extract context information associated with the current round of dialogue topic from a knowledge graph based on the dialogue topic. The knowledge graph is constructed based on the user's multi-turn historical dialogue with the language model; An optimization module is used to optimize the prompts for the current round of dialogue based on the context information.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the method for optimizing prompt words as described in any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method for optimizing prompt words as described in any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method for optimizing prompt words as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Method and device for optimizing cue word, equipment and medium
CN118733758A
User incoming call intention recognition method and device and readable storage medium
CN118899006A
Question and answer method and system based on large language model
CN119166767A
A prompt word generation method, device, electronic device and readable storage medium
CN119761359A
Dialogue method, dialogue system and electronic device
CN120216648A
Cited By
Dynamic enhancement method and system for cue word, electronic equipment and storage medium
CN122133652A
A prompt word dynamic enhancement method and system, an electronic device, and a storage medium
CN122133652B