Text processing method, electronic equipment, storage medium and program product

By constructing a directed graph and using the model to generate text, the diversity and quality problems of text generation in traditional methods are solved, and efficient and high-quality text generation is achieved in scenarios with no sample data.

CN120687556APending Publication Date: 2025-09-23MASHANG CONSUMER FINANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510603484.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-08
Publication Date
2025-09-23

AI Technical Summary

Technical Problem

Existing text generation methods lack diversity and flexibility. The text generated by traditional methods is of low quality, especially in scenarios with no sample data.

Method used

By constructing a directed graph based on preset prompt text, using the directed graph to generate target text, combining the first model and the second model to generate high-quality text, and selecting appropriate target text to improve generation efficiency and quality.

Benefits of technology

It achieves efficient generation of high-quality text in scenarios without sample data, improves the diversity and flexibility of text generation, and ensures the quality of the target text.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120687556A_ABST
    Figure CN120687556A_ABST
Patent Text Reader

Abstract

The invention relates to artificial intelligence, and provides a text processing method, electronic equipment, a storage medium and a program product. According to the text processing method, a directed graph corresponding to a first prompt text is constructed based on the preset first prompt text, nodes in the directed graph represent texts, connecting edges in the directed graph represent semantic relationships between different texts, and weights of the connecting edges are determined based on the semantic relationships between the different texts; determining a target path from the directed graph based on the weight corresponding to the connection edge and the similarity between every two nodes in the directed graph; generating a third prompt text according to the second prompt text corresponding to the plurality of nodes in the target path; based on the third prompt text, generating a plurality of first texts corresponding to the target path through the first model, and generating a second text corresponding to the target path through the second model; and selecting a target text from the plurality of first texts based on the second text. The method can ensure the quality of the target text.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and specifically to a text processing method, electronic device, storage medium, and program product. Background Art

[0002] With the development of natural language processing technology, automatic text generation has been applied in various fields, such as intelligent customer service, smart home, and smart office. Related technologies typically rely on predefined rules to generate text. However, the text generated by this approach is monotonous, lacks diversity, and its overall quality needs to be improved. Summary of the Invention

[0003] The present application provides a text processing method, electronic device, storage medium and program product to solve the technical problem of low text quality.

[0004] A first aspect of an embodiment of the present application provides a text processing method, the method comprising: constructing a directed graph corresponding to a preset first prompt text based on the first prompt text, wherein the nodes in the directed graph represent texts, the connecting edges in the directed graph represent semantic relationships between different texts, and the weights of the connecting edges are determined based on the semantic relationships between the different texts; determining a target path from the directed graph based on the weights corresponding to the connecting edges and the similarity between each two nodes in the directed graph; generating a third prompt text based on second prompt texts corresponding to multiple nodes in the target path; generating multiple first texts corresponding to the target path through a first model based on the third prompt text, and generating a second text corresponding to the target path through a second model; and selecting a target text from the multiple first texts based on the second text.

[0005] According to a second aspect of an embodiment of the present application, there is provided a text processing device, comprising: a construction unit for constructing a directed graph corresponding to a preset first prompt text based on the first prompt text, wherein the nodes in the directed graph represent texts, the connecting edges in the directed graph represent semantic relationships between different texts, and the weights of the connecting edges are determined based on the semantic relationships between the different texts; a determination unit for determining a target path from the directed graph based on the weights corresponding to the connecting edges and the similarity between each two nodes in the directed graph; a generation unit for generating a third prompt text based on the second prompt texts corresponding to multiple nodes in the target path; the generation unit is further used to generate multiple first texts corresponding to the target path through a first model and generate a second text corresponding to the target path through a second model based on the third prompt text; and a selection unit for selecting a target text from the multiple first texts based on the second text.

[0006] A third aspect of an embodiment of the present application provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method provided in the first aspect when executing the computer program.

[0007] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps in the method provided in the first aspect are implemented.

[0008] A fifth aspect of an embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the steps in the method provided in the first aspect.

[0009] In the text processing method of this embodiment, a directed graph is constructed using a preset first prompt text, and a target text is generated based on the directed graph. This enables text generation in scenarios without sample data. Furthermore, by determining the target path from the directed graph and then generating the corresponding text using the first and second models, the efficiency of text generation can be improved because the first and second models do not need to analyze the entire directed graph. Furthermore, by selecting the target text from the first text generated by the first model using the second text generated by the second model, the quality of the target text can be ensured. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0011] Figure 1 This is a schematic diagram of an application scenario of a text processing method provided in an embodiment of the present application;

[0012] Figure 2 This is a flowchart of a text processing method provided by an embodiment of the present application;

[0013] Figure 3 is a schematic diagram of a directed graph provided in an embodiment of the present application;

[0014] Figure 4 This is a detailed flow chart of a target text selection method provided in an embodiment of the present application;

[0015] Figure 5 This is a detailed flowchart of another target text selection method provided in an embodiment of the present application;

[0016] Figure 6 Schematic diagram of the framework of the fifth text determination method provided in the embodiment of the present application;

[0017] Figure 7 is a flowchart of another text processing method provided by an embodiment of the present application;

[0018] Figure 8 Schematic diagram of the framework of the second model adjustment method provided in the embodiment of the present application;

[0019] Figure 9 Schematic diagram of the framework of the target text determination method provided in the embodiment of the present application;

[0020] Figure 10 This is a functional module diagram of a text processing device provided by an embodiment of the present application;

[0021] Figure 11 It is a structural diagram of an electronic device for implementing a text processing method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0022] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0023] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or design schemes. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete way.

[0024] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application belongs. The terms used in the specification of this application are for the purpose of describing specific embodiments only and are not intended to limit this application. It should be understood that, unless otherwise specified in this application, " / " means or. For example, A / B can mean A or B. "And / or" in this application is merely a way to describe the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. "At least one" means one or more. "Multiple" means two or more than two. For example, at least one of a, b or c can mean: a, b, c, a and b, a and c, b and c, a, b and c.

[0025] With the development of artificial intelligence (AI), progress has been made in natural language processing, particularly in text processing. Traditional text processing methods, such as rule-based approaches that generate text according to established grammatical and logical rules, and template-based approaches that use fixed templates to fill in content, have been used. However, these traditional approaches struggle to generate diverse text, resulting in relatively monotonous content and a lack of flexibility.

[0026] Large models are now a crucial tool for automatic text generation. However, training large models requires vast amounts of text data, and in scenarios where sample data is scarce, large models perform poorly. Due to the shortcomings of traditional methods and large models in certain situations, the quality of generated text is subpar.

[0027] In order to solve the above problems, an embodiment of the present application provides a text processing method, which constructs a directed graph through a preset first prompt text and generates a target text based on the directed graph, which can achieve rapid generation of high-quality text in a scenario without sample data.

[0028] See also Figure 1 , Figure 1 This is a schematic diagram of an application scenario of a text processing method provided in an embodiment of the present application. Figure 1 As shown, the electronic device 100 is connected to the terminal device 200 via network communication.

[0029] In some embodiments, the user may input a preset first prompt message to the terminal device 200 by voice or other means, and the electronic device 100 may obtain the target text based on the preset first prompt text and send the target text to the terminal device 200. The terminal device 200 may display the target text in an interface for interacting with the user.

[0030] In the process of implementing text processing, the electronic device 100 constructs a directed graph corresponding to the first prompt text based on the preset first prompt text, the nodes in the directed graph represent texts, the connecting edges in the directed graph represent semantic relationships between different texts, and the weights of the connecting edges are determined based on the semantic relationships between different texts. The electronic device 100 determines the target path from the directed graph based on the weights corresponding to the connecting edges and the similarity between every two nodes in the directed graph, and generates a third prompt text based on the second prompt texts corresponding to multiple nodes in the target path. Based on the third prompt text, the electronic device 100 generates multiple first texts corresponding to the target path through the first model, and generates the second text corresponding to the target path through the second model. The electronic device 100 selects the target text from the multiple first texts based on the second text. The use of this method can improve the efficiency of text generation and ensure the quality of the target text.

[0031] In some embodiments, the communication connection between the electronic device 100 and the terminal device 200 includes, but is not limited to, wired communication connection and wireless communication connection. The wireless communication connection includes communication connection methods such as Bluetooth, cellular network, and Wireless Fidelity (Wi-Fi) technology.

[0032] In some embodiments, the electronic device 100 may be a standalone server, a computer, or a server cluster or distributed system composed of multiple servers. It may also be a cloud server that provides basic cloud computing services such as cloud services, cloud storage, cloud computing, cloud functions, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), big data, and artificial intelligence platforms. The terminal device 200 may be any one or more of a mobile phone, tablet computer, laptop computer, PDA, wearable device, or the like.

[0033] Figure 1 The scenarios shown are merely illustrative examples, and the text processing method provided in this application can also be applied in other scenarios. For example, in some scenarios, multiple electronic devices 100 and multiple terminal devices 200 may be included; in some scenarios, electronic devices 100 may be included but terminal devices 200 may not be included; in some scenarios, electronic devices 100 and servers may be included but terminal devices 200 may not be included; and in some scenarios, other types of devices may also be included. The embodiments of this application do not limit the specific application scenarios of the text processing method.

[0034] like Figure 2 FIG. 1 is a flowchart of a text processing method provided by an embodiment of the present application. The text processing method is applied in electronic devices, for example, Figure 1The electronic device 100. According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted.

[0035] S201: Based on a preset first prompt text, construct a directed graph corresponding to the first prompt text.

[0036] In at least one embodiment of the present application, the first prompt text may be one or more paragraphs of text, one or more sentences of text, one or more words, and the first prompt text may also be other forms of text, such as files in preset formats, such as WORD documents, TXT documents, etc., which are not limited in actual applications. The first prompt text may include the scene name of the task-based dialogue scene and descriptive information of the communication framework (also referred to as the "communication process"), etc. The communication framework may include multiple communication links. In one example, the task-based dialogue scene may be: car sales scene, the scene name is: loan sales, and the communication framework may include the opening link, the demand inquiry link, the product explanation link, the question answering link and the marketing results link, etc. In another example, the task-based dialogue scene may be: medical service scene, the scene name is: online consultation, and the communication framework may include the opening link, the condition inquiry link, the analysis and diagnosis link, the question answering link and the summary link, etc. Exemplarily, the first prompt text may be:

[0037] You are a customer. Your goal is to develop a communication plan (communication steps) with a sales representative to gain a clearer understanding of the product or service. Based on the "specified communication steps" provided as input, you will identify and extract the key communication steps from the customer's perspective. Please follow the steps and requirements below.

[0038] #Quest Requirements

[0039] -You need to understand the “designated communication links” from the customer’s perspective and identify the scenario name and scenario description.

[0040] -You need to generate communication links from the customer's perspective based on the scenario name and scenario description.

[0041] -You need to improve the communication links from the customer's perspective according to the "designated communication links" and ensure the order and completeness of these links.

[0042] -The communication segments you extract should be detailed and non-repetitive.

[0043] -Note! The description in the "description" field of your response must be a description of the communication process from the customer's perspective.

[0044] -“Opening Questions” and “Closing Conversation” are necessary steps, and generally do not rewrite their content.

[0045] - In the generated content, do not involve specific names, titles, etc., such as "Mr. X", "Ms. X", "XX name", etc.

[0046] # Extraction steps

[0047] - Step 1: After you understand the "specified communication session", identify the scenario name and scenario description from the customer's perspective.

[0048] - Step 2: Based on the scenario name and scenario description, generate the communication sessions to be carried out from the customer's perspective.

[0049] - Step 3: According to the "specified communication session", enrich and supplement the communication sessions in Step 2 from the customer's perspective.

[0050] - Step 4: Combine duplicate communication sessions and ensure they meet the task requirements.

[0051] - Step 5: If the communication sessions do not meet the requirements, continue to analyze the conversation content.

[0052] # Output format:

[0053] - The output should include the "opening inquiry" and "ending the conversation" sessions.

[0054] - Please use the following template for the response without adding any additional content:

[0055] {

[0056] "name": <string, recognized scenario name>,

[0057] "description": <string, description of the conversation scenario understood from the customer's perspective>,

[0058] "arguments":

[0059] {

[0060] "name": "opening inquiry",

[0061] "type": "string",

[0062] "description": When the salesperson does not state the purpose of the conversation, the customer takes the initiative to ask about the purpose of the conversation with the other party

[0063] },

[0064] {

[0065] "name": <string, communication session name>,

[0066] "type": "string",

[0067] "description": <string, description of the communication link understood from the customer's perspective>

[0068] },

[0069] {

[0070] "name": <string, name of the communication link>,

[0071] "type": "string",

[0072] "description": <string, description of the communication link understood from the customer's perspective>,

[0073] "possible_values": <string, enum["", "<string, possible values of this communication link understood from the customer's perspective, such as expensive, cheap, moderate>"]>

[0074] },

[0075] {

[0076] "name": "End the conversation",

[0077] "type": "string",

[0078] "description": "Express gratitude and actively end the conversation",

[0079] }

[0081] }。

[0082] In at least one embodiment of the present application, the electronic device constructs a directed graph corresponding to the first prompt text based on the preset first prompt text, including: generating a third text based on the first prompt text through the first model; filling the third text into a preset template to obtain a fourth prompt text; generating a fourth text based on the fourth prompt text through the first model; determining the semantic association degree between the fourth text and the third text according to the semantic relationship between the fourth text and the third text; constructing a directed graph with the third text as the first node, the fourth text as the second node, and the semantic association degree as the weight corresponding to the connection edge between the first node and the second node. Through the first prompt text and the fourth prompt text, the present application embodiment can generate corresponding texts. Using the third text and the fourth text generated by the first model as the nodes of the directed graph can increase the number of nodes of the directed graph, thereby improving the richness and diversity of the directed graph. ​

[0083] In some embodiments, the electronic device inputs the first prompt text into the first model to obtain the third text. The first model may be a large language model, for example, the first model may be a 7B model, or a model of another architecture, for example, the first model may be a machine learning model. The first model may include an encoding layer, multiple attention network layers, a feedforward neural network layer, and an activation function.

[0084] Specifically, the electronic device segments the descriptive information of the communication link in the first prompt text to obtain multiple word-units. The electronic device then encodes the multiple word-units using the encoding layer in the first model to obtain encoding vectors, which are used to represent the multiple word-units in the descriptive information. The electronic device then performs attention analysis on the encoding vectors using multiple attention network layers in the first model to obtain feature vectors output by each attention network layer. Each feature vector indicates a characteristic of the descriptive information along a corresponding dimension. For example, a feature vector may indicate a characteristic of the descriptive information along a semantic dimension, or a syntactic dimension. The electronic device then fuses the multiple feature vectors using the feedforward neural network layer in the first model to obtain a fused feature. The fused feature may indicate characteristics of the descriptive information along multiple dimensions. The electronic device then uses the activation function in the first model to calculate the fused feature, obtain a probability corresponding to each preset word, and selects the preset word with the highest probability as the predicted word for the first prompt text. The electronic device then concatenates the multiple word-units and the predicted word to obtain a concatenated text. If the concatenated text meets the configuration conditions, the electronic device determines the concatenated text as the third text. If the spliced ​​text does not meet the configuration condition, the electronic device uses the spliced ​​text as the description information of the communication link, and uses the first model to analyze the description information of the communication link until the third text is obtained.

[0085] In this embodiment, each attention network layer corresponds to a query matrix, a key matrix, and a value matrix. In the process of using multiple attention network layers in the first model to perform attention analysis on the coding vector, the electronic device can use the query matrix, key matrix, and value matrix in the attention network layer to perform attention analysis on the coding vector to obtain a feature vector. Specifically, the electronic device calculates the dot product of the coding vector and the query matrix to obtain the query vector, calculates the dot product of the coding vector and the key matrix to obtain the key vector, and calculates the dot product of the coding vector and the value matrix to obtain the value vector. The electronic device uses the formula The query vector, key vector and value vector are operated to obtain the feature vector, where softmax() can represent the activation function, Q can represent the query vector, K can represent the key vector, and V can represent the value vector. The dimensions of the key vector can be represented.

[0086] In this embodiment, the electronic device uses the feedforward neural network layer in the first model to perform linear transformation on multiple feature vectors to obtain fusion features. The fusion features can be expressed as P=W1T1+…+W i T i +b, where P can represent the fusion feature, W1, ..., W i It can represent the weight matrix in the feedforward neural network layer. The number of weight matrices in the feedforward neural network layer is the same as the number of multiple attention network layers in the first model, T1, ..., T i It can represent the feature vectors output by multiple attention network layers in the first model, and b can represent the bias vector in the feedforward neural network layer.

[0087] In this embodiment, the activation function in the first model may include but is not limited to: softmax() function, LogSoftmax() function. The configuration conditions may include but are not limited to: the character length corresponding to the spliced ​​text meets the preset requirements, for example, the character length corresponding to the spliced ​​text reaches 20 characters. The configuration conditions may also include: the spliced ​​text includes a preset identifier, and the preset identifier can be used to indicate the termination condition. For example, the preset identifier is end. If it is detected that the spliced ​​text includes the preset identifier end, the electronic device determines that the spliced ​​text meets the configuration conditions. For another example, the preset identifier is a period ".". If it is detected that the spliced ​​text includes the preset identifier ".", the electronic device determines that the spliced ​​text meets the configuration conditions.

[0088] In one example, the descriptive information of a communication framework is used to describe specific communication steps within the communication framework. For the description of the communication step "inquiring about the purpose of the loan" in the first prompt text, the electronic device may divide the description of the communication step "inquiring about the purpose of the loan" into three tokens: "inquiry," "loan," and "purpose." The encoding layer in the first model encodes these tokens to obtain encoding vectors [Q1, Q2, Q3], where Q1 may be the encoding vector corresponding to the token "inquiry," Q2 may be the encoding vector corresponding to the token "loan," and Q3 may be the encoding vector corresponding to the token "purpose." The electronic device then performs attention analysis on the encoding vectors [Q1, Q2, Q3] using multiple attention network layers in the first model, obtaining feature vectors output by each attention network layer, such as feature vector T1 corresponding to attention network layer z1, feature vector T2 corresponding to attention network layer z2, and feature vector T3 corresponding to attention network layer z3. The electronic device then fuses feature vectors T1, T2, and T3 using the feedforward neural network layer in the first model to obtain fused features P. The electronic device uses the activation function in the first model to calculate the fused feature P, obtaining the probability corresponding to each preset word. For example, if the preset vocabulary includes 1,000 words, a 1,000-dimensional probability vector can be obtained, with the components in the probability vector corresponding to the preset words. The electronic device uses the preset word corresponding to the component with the largest value in the probability vector as the predicted word for the first prompt text. For example, the predicted word is "understand." The electronic device concatenates the word unit "inquire," the word unit "loan," the word unit "purpose," and the predicted word "understand" to obtain the concatenated text "inquire about the purpose of the loan, understand." In response to the concatenated text "inquire about the purpose of the loan, understand" not meeting the configuration conditions, the concatenated text "inquire about the purpose of the loan, understand" is used as the descriptive information for the communication link. The first model is then used to analyze the descriptive information for the communication link "inquire about the purpose of the loan, understand" until the resulting concatenated text meets the configuration conditions. The electronic device then determines the concatenated text that meets the configuration conditions as the third text. Continuing with the above example, the third text for the "inquire about the purpose of the loan" link is "inquire about the purpose of the loan, understand the customer's financial situation, and confirm the legality of the loan purpose, etc."

[0089] This embodiment can improve the representation accuracy of the encoding vector by encoding multiple word units, and can analyze the encoding vector from multiple dimensions by performing attention analysis on the encoding vector through multiple attention network layers, thereby improving the diversity of the feature vector. By fusing multiple feature vectors, the fused features include features from multiple dimensions, thereby improving the accuracy of predicted vocabulary and thus improving the accuracy of the third text.

[0090] In some embodiments, the preset template may include a first task description module, a first task requirement module and a first output module. Among them, the first task description module can be used to set the extension of a given communication link (also referred to as the "original link") and the evaluation of the semantic relevance between the original link and the extended link. The first task requirement module can be used to clarify the following: the direction of the extension of the original link, the connection relationship between the extended link and the original link, the scoring range of the generated extended link and the explanation of the scoring reasons. The first output module is used to prompt the output format of the original link, the extended link, the score (also referred to as "semantic relevance") and the scoring reason. Exemplarily, the preset template can be:

[0091] You are now an expert in conversation path design. Your task is to expand a given communication link, generate multiple possible subsequent links, and score each link to assess its relevance to the original framework. Please expand based on the following requirements:

[0092] #Require

[0093] - Expand each given communication link in different directions to generate multiple possible subsequent links.

[0094] -Each extended link needs to have a clear connection relationship with the original link to form a directed graph.

[0095] - Score each generated extension on a scale of 0 to 10, with 10 indicating a high correlation with the original framework and 0 indicating a low correlation.

[0096] -Please provide detailed justification for each rating.

[0097] #Output format

[0098] Original link: xx

[0099] Extension 1: xx

[0100] Rating: xx

[0101] Rating reason: xxx

[0102] Extension 2: xx

[0103] Rating: xx

[0104] Rating reason: xxx

[0105] Sample output:

[0106] Original step: Asking about the purpose of the loan

[0107] Extension 1: Exploring loan plans

[0108] Rating: 7.5

[0109] Reason for rating: Inquiring about loan plans is somewhat related to asking about the purpose of the loan, but focuses more on the customer's detailed plans and arrangements.

[0110] Extension 2: Understanding consumption habits

[0111] Rating: 6.0

[0112] Rating reason: Understanding consumer habits is related to asking about the purpose of the loan, but the correlation is weak. It is more about understanding the customer's consumption behavior rather than the purpose of the loan.

[0113] Extension 3: Confirm the loan amount

[0114] Rating: 9.0

[0115] Reason for scoring: Confirming the loan amount is closely related to inquiring about the purpose of the loan, which can better recommend suitable loan products to customers.

[0116] Extension 4: Ask about repayment plan

[0117] Rating: 7.0

[0118] Rating reason: Asking about the repayment plan is somewhat related to asking about the purpose of the loan, but focuses more on the customer's repayment ability and plan.

[0119] In some embodiments, the electronic device may fill the third text into the position corresponding to a given communication link in the preset template to obtain the fourth prompt text. For example, the electronic device may fill the third text into the position corresponding to the original link in the preset template to obtain the fourth prompt text. In other embodiments, the electronic device may concatenate the third text and the preset template to obtain the fourth prompt text. The embodiments of the present application do not limit the order in which the third text and the preset template are concatenated.

[0120] In some embodiments, the electronic device inputs the fourth prompt text into the first model to obtain the fourth text. The way in which the electronic device obtains the fourth text is similar to the way in which the electronic device obtains the third text, and this application will not repeat the description. Continuing with the above example, for the "inquiring about the purpose of the loan" link in the first prompt text, the third text "inquiring about the purpose of the loan, understanding the customer's financial situation, confirming the legality of the purpose of the loan, etc." can be expanded to obtain the fourth text "inquiring about the purpose of the loan." The electronic device can further expand the fourth text "inquiring about the purpose of the loan" as the third text to obtain the fourth text "inquiring about the loan plan". In this way, the electronic device can also further expand the fourth text "inquiring about the loan plan" as the third text to obtain the fourth text "consumption habits".

[0121] In some embodiments, the electronic device analyzes the semantic relationship between the fourth text and the third text through the first model to obtain the semantic association degree (also referred to as "score") between the fourth text and the third text.

[0122] In one example, the electronic device performs semantic extraction on the third text through the first model to obtain the first semantic feature, and performs semantic extraction on the fourth text through the first model to obtain the second semantic feature. The first semantic feature and the second semantic feature can be obtained through the attention network layer in the first model. The electronic device calculates the similarity between the second semantic feature and the first semantic feature to obtain the semantic association between the fourth text and the third text. Among them, the similarity between the second semantic feature and the first semantic feature can be calculated by the consine similarity formula and the jaccard similarity formula, and this application does not limit this. This embodiment can quickly determine the semantic association between the fourth text and the third text through the similarity between the second semantic feature and the first semantic feature.

[0123] In another example, the electronic device can build a preset corpus based on the collected multiple articles. When calculating the semantic relevance between the fourth text and the third text, it can be determined by the first probability that the first subject word in the third text and the second subject word in the fourth text appear in the preset corpus at the same time, the second probability that the first subject word appears in the preset corpus, and the third probability that the second subject word appears in the preset corpus. Among them, the first subject word can be a keyword word in the third text, etc., and the second subject word can be a keyword word in the fourth text, etc. The formula for the semantic relevance between the fourth text and the third text can be expressed as: Here, q can represent the semantic relevance between the fourth text and the third text, p(x, y) can represent the first probability, p(x) can represent the second probability, and p(y) can represent the third probability. This embodiment can quantify the semantic relevance between the fourth text and the third text using the first keyword in the third text and the second keyword in the fourth text.

[0124] In some embodiments, the nodes in the directed graph represent texts, the edges in the directed graph represent semantic relationships between different texts, and the weights of the edges are determined based on the semantic relationships between different texts. For example, Figure 3The nodes in the directed graph shown include Node A, Node B, Node C, Node D, Node E, and Node F. Node A is connected to Node B and Node F, respectively. The arrows after the connections go from Node A to Node B and Node A to Node F. The weight of the edge between Node A and Node B is 8, and the weight of the edge between Node A and Node F is 2. Node B is connected to Node C and Node E, respectively. The arrows after the connections go from Node B to Node C and Node B to Node E. The weight of the edge between Node B and Node C is 7, and the weight of the edge between Node B and Node E is 3. Node C is connected to Node D and Node E, and the arrows after the connections go from Node C to Node D and Node C to Node E. The weight of the edge between Node C and Node D is 6, and the weight of the edge between Node C and Node E is 4. Node E is connected to Node F, and the arrows after the connections go from Node F to Node E, and the weight of the edge between Node E and Node F is 6.

[0125] S202 : Determine a target path from the directed graph based on the weights corresponding to the connecting edges and the similarity between every two nodes in the directed graph.

[0126] In at least one embodiment of the present application, in the process of determining the similarity between every two nodes in a directed graph, the electronic device performs feature encoding on the text corresponding to each node in the directed graph based on a multi-head attention mechanism, and obtains multiple first feature codes corresponding to each node, and each first feature code includes at least one component. The electronic device performs bitwise operations on the components in the multiple first feature codes of each node to obtain a second feature code corresponding to each node. The electronic device calculates the similarity between every two nodes based on the second feature code of each node. The embodiment of the present application performs feature encoding on the text corresponding to each node in the directed graph through a multi-head attention mechanism, which can capture the features of the text in different dimensions, and thus can accurately determine the second feature code corresponding to each node, and then through the second feature code of each node, can accurately calculate the similarity between every two nodes.

[0127] In some embodiments, when the electronic device calls the multi-head attention mechanism to process the text corresponding to each node in the directed graph, it can obtain N first feature codes corresponding to each node, where N can be used to indicate the number of attention heads in the multi-head attention mechanism. Each first feature code may include at least one component, and the number of components in each first feature code can be expressed as d, which can be set according to actual needs. For example, d can be set to 768. For example, the multi-head attention mechanism includes 10 attentions, and the electronic device can obtain 10 first feature codes based on the multi-head attention mechanism, and the number of components in each first feature code is 768.

[0128] In some embodiments, the electronic device performs a bitwise operation on the components in the multiple first feature codes of each node to obtain a second feature code corresponding to each node, and the dimension of the second feature code can be the same as the dimension of the first feature code. In one example, the electronic device can calculate the average value of the components in the multiple first feature codes of each node bit by bit to obtain the second feature code. Continuing with the above example, each first feature code includes 768-bit components, and the electronic device calculates the average value of the first bit component in 10 first feature codes as the first bit component of the second feature code, and can obtain the 768-bit components in the second feature code in sequence. In another embodiment, the electronic device can also calculate the weighted values ​​of the components in the multiple first feature codes of each node bit by bit to obtain the second feature code. In other embodiments, the electronic device can also use other methods to calculate the multiple first feature codes of each node bit by bit to obtain the second feature code corresponding to each node.

[0129] In some embodiments, the electronic device calculates the similarity between every two nodes based on the second feature code of each node. The formula for the similarity between every two nodes can be expressed as: Among them, similarity(V, U) can represent the similarity between the Vth node and the Uth node. It can represent the second feature code of the Vth node, It can represent the second feature code of the U-th node.

[0130] In at least one embodiment of the present application, an electronic device determines a target path from a directed graph based on weights corresponding to connecting edges and the similarity between each two nodes in the directed graph, including: calculating a first score between each two nodes based on the weights corresponding to the connecting edges and the similarity between each two nodes in the directed graph; selecting a start node and an end node from multiple nodes in the directed graph; determining a third node between the start node and the end node in the directed graph based on the first score; and constructing a target path based on the start node, the end node, and the third node. The embodiment of the present application comprehensively considers the weights corresponding to the connecting edges of each two nodes in the directed graph and the similarity between each two nodes, and can accurately determine the first score between each two nodes, and further, based on the first score, can accurately determine the target path from the directed graph.

[0131] In some embodiments, the calculation formula for the first score between every two nodes can be expressed as: Score(V, U) = α×W(V, U) + (1-α)×[1-similarity(V, U)], where Score(V, U) can represent the first score between the Vth node and the Uth node, α is a preset weight, and α can be set and adjusted according to actual needs, for example, α = 0.6, W(V, U) can represent the weight corresponding to the connecting edge between the Vth node and the Uth node, and similarity(V, U) can represent the similarity between the Vth node and the Uth node.

[0132] In some embodiments, the electronic device may select a corresponding node from a plurality of nodes in a directed graph as the starting node of the target path based on the first communication link in the communication framework, and the starting node may be used to indicate the starting direction of the target path. For example, if the first communication link in the communication framework is "start inquiry", the starting node of the target path may be the node in the directed graph corresponding to the communication link "start inquiry". The electronic device may select a corresponding node from a plurality of nodes in the directed graph as the ending node of the target path based on the last communication link in the communication framework, and the ending node may be used to indicate the end of the target path. For example, if the last communication link in the communication framework is "end conversation", the ending node of the target path may be the node in the directed graph corresponding to the communication link "end conversation".

[0133] In some embodiments, in the process of determining the third node between the starting node and the ending node, the electronic device uses the fourth node corresponding to the largest first score as the third node, and the fourth node is any one of the nodes connected to the starting node.

[0134] In some embodiments, the electronic device constructs a target path based on the starting node, the ending node, and the third node. For example, if the starting node is "opening inquiry" and the ending node is "end conversation," the target path may be: opening inquiry -> loan amount -> loan purpose -> product recommendation -> product advantages explanation -> answering customer questions -> inquiring about purchase intention -> end conversation.

[0135] Combine Figure 3 To illustrate the determination of the target path, if the starting node is node A and the ending node is node C, and the first score of node B and node A is greater than the first score of node F and node A, the electronic device can determine that node B is the third node. Therefore, the target path can be obtained as: node A->node B->node C.

[0136] S203: Generate a third prompt text according to the second prompt texts corresponding to the multiple nodes in the target path.

[0137] In at least one embodiment of the present application, the second prompt text may be a third text or a fourth text. For example, the second prompt text for the node corresponding to "inquire about the purpose of the loan" in the target path may be: "Inquire about the purpose of the loan, understand the customer's financial situation, confirm the legality of the purpose of the loan, etc." The first configuration template may include a scene setting module, a second task requirement module, an input module corresponding to the second prompt text, and a second output module. The scene setting module can be used to set the identity of the communication subject, the second task requirement module can be used to set the standard for the generated first text or second text, the input module corresponding to the second prompt text is used to prompt the fill position of the second prompt text corresponding to multiple nodes in the target path, and the second output module is used to prompt the output format of the first text or the second text. Exemplarily, the first configuration template may be:

[0138] You are now a communication expert. The current scenario is a loan marketing scenario. Please generate a dialogue between sales and customers based on the incoming communication nodes.

[0139] #Require

[0140] - The generated dialogue should be colloquial and the context should be natural and coherent

[0141] -You must proceed according to the incoming communication nodes, you cannot generate them randomly

[0142] #Input communication node

[0143] 1. Opening Questions

[0144] 2. Ask about the loan amount

[0145] 3. Ask about the purpose of the loan

[0146] 4. Product Recommendations

[0147] 5. Explain the product advantages

[0148] 6. Answer customer questions

[0149] 7. Ask about purchase intention

[0150] 8. End the conversation

[0151] #Output format

[0152] Return:

[0153] Sales: xxx

[0154] Customer: xxx.

[0155] In some embodiments, the electronic device can fill the second prompt text corresponding to multiple nodes in the target path into the first configuration template to obtain a third prompt text. In one example, the second prompt text can be filled into the corresponding communication node in the first configuration template. For example, the second prompt text "inquire about the purpose of the loan, understand the customer's financial situation, confirm the legality of the purpose of the loan, etc." can be filled into the position corresponding to "inquire about the purpose of the loan" in the first configuration template. In another example, the electronic device can splice the second prompt text and the first configuration template to obtain the third prompt text. The splicing order of the second prompt text and the first configuration template is not specifically limited.

[0156] S204 : Based on the third prompt text, generate a plurality of first texts corresponding to the target path through the first model, and generate a second text corresponding to the target path through the second model.

[0157] In at least one embodiment of the present application, the network architecture of the first model and the network architecture of the second model can be the same, for example, the network architecture of the first model and the second model are both Transformer architectures. The network parameters in the first model are different from the network parameters in the second model, for example, the weight matrix of the attention layer in the first model is different from the weight matrix of the attention layer in the second model.

[0158] In at least one embodiment of the present application, the electronic device inputs the third prompt text into the first model to obtain the first text. The electronic device inputs the third prompt text into the second model to obtain the second text. Typically, the number of second texts generated by the second model is less than the number of first texts generated by the first model. For example, the number of second texts generated by the second model based on the third prompt text is 1, and the number of first texts generated by the first model based on the third prompt text is 500. Specifically, the analysis process of the third prompt text by the first model and the second model can refer to the process of inputting the first prompt text into the first model in step S201 to obtain the third text, and this application will not repeat the description of this.

[0159] S205: Select a target text from a plurality of first texts based on the second text.

[0160] In at least one embodiment of the present application, the target text may be the M first texts that have the highest consistency with the second text, where M may be a positive integer. The electronic device may select the target text from the plurality of first texts based on the second text, as described in the following example. Figure 4 The steps shown are: Figure 4 The process shown includes steps S401 to S405.

[0161] S401 : Determine a second score of each first text and second text based on a position of a text corresponding to a node in a target path in each first text and a position of a text corresponding to a node in a target path in the second text.

[0162] In some embodiments, when determining the second score for each first text and second text, the electronic device counts the number of nodes in the target path whose text corresponds to a node in the target path and is located at the same position in the first text and the second text, and calculates the ratio of the number of nodes to the total number of nodes in the target path to obtain the second score. The second score is used to quantify the similarity between the position of the text corresponding to the node in the target path in the first text and the position of the text corresponding to the node in the target path in the second text.

[0163] For example, if the total number of nodes in the target path is 3, and the nodes in the target path include: node A, node B, and node C, the positions of the texts corresponding to the nodes in the target path in the first text are: the text corresponding to node A, the text corresponding to node B, and the text corresponding to node C, and the positions of the texts corresponding to the nodes in the target path in the second text are: the text corresponding to node A, the text corresponding to node B, and the text corresponding to node C. Then, the number of nodes in the target path whose texts are in the same position in the first and second texts is 3, and the second score is calculated to be 1.

[0164] For another example, the positions of the text corresponding to the nodes in the target path in the first text are: the text corresponding to node A, the text corresponding to node B, and the text corresponding to node C, and the positions of the text corresponding to the nodes in the target path in the second text are: the text corresponding to node A, the text corresponding to node C, and the text corresponding to node B. Then, the number of nodes in the target path whose text corresponds to the nodes in the first and second texts is 1, and the second score is calculated to be 1 / 3.

[0165] S402 : Determine a third score between each first text and the second text based on the similarity between each first text and the second text.

[0166] In some embodiments, the electronic device can calculate the character similarity between each first text and the second text through a similarity calculation formula to obtain the similarity between each first text and the second text. The electronic device can use the similarity between each first text and the second text as the third score between each first text and the second text. The electronic device can also calculate the product of the similarity and the first preset multiple to obtain the third score between each first text and the second text. The first preset multiple can be set and adjusted according to actual needs. This application does not impose specific restrictions on the relationship between the similarity and the third score. The third score is used to quantify the similarity between the first text and the second text in the content dimension.

[0167] S403 : Determine a fourth score of each first text and each second text based on the context of each first text and the context of the second text.

[0168] In some embodiments, the electronic device can determine the third semantic feature of each first text based on the context of each first text, and determine the fourth semantic feature of the second text based on the context of the second text. Specifically, the electronic device can input multiple first texts into the first model, use the attention network layer in the first model to analyze the context of each first text, and obtain the third semantic feature corresponding to each first text. The electronic device inputs the second text into the second model, uses the attention network layer in the second model to analyze the context of the second text, and obtains the fourth semantic feature.

[0169] The electronic device uses a similarity calculation formula to calculate the similarity between each third semantic feature and the fourth semantic feature to obtain the semantic similarity between each first text and the second text. The electronic device determines the fourth score of each first text and the second text based on the semantic similarity between each first text and the second text. In one example, the electronic device can use the semantic similarity between each first text and the second text as the fourth score. In another example, the electronic device can also calculate the product of the semantic similarity and the second preset multiple to obtain the fourth score of each first text and the second text. The second preset multiple can be set and adjusted according to actual needs. This application does not impose specific restrictions on the relationship between semantic similarity and the fourth score. The fourth score is used to quantify the similarity between the first text and the second text in the context dimension.

[0170] S404 , calculating a fifth score of each of the first text and the second text according to the second score, the third score, and the fourth score.

[0171] In some embodiments, the electronic device calculates a weighted sum of the second score, the third score, and the fourth score to obtain a fifth score for each first text and second text. The fifth score is used to quantify the comprehensive similarity between the first text and the second text in multiple dimensions, such as content dimension and context dimension.

[0172] S405: Determine the first text whose fifth score is greater than the first preset score threshold as the target text.

[0173] In some embodiments, the first preset score threshold can be set and adjusted according to actual needs, and this application does not impose any specific restrictions on this.

[0174] The embodiment of the present application combines the position of the text corresponding to the node in the target path in each first text and the position in the second text, the content similarity between each first text and the second text, and the overall context of each first text and the second text to accurately quantify the consistency between each first text and the second text, thereby ensuring the quality of the target text. In addition, by selecting the target text from the first text, the number of texts in the target text can be increased to a certain extent.

[0175] In at least one embodiment of the present application, the electronic device selects the target text from the plurality of first texts based on the second text. Figure 5 The steps shown are: Figure 5 The process shown includes steps S501 to S504.

[0176] S501: Perform a Monte Carlo tree search on multiple first texts to obtain a fifth text.

[0177] In some embodiments, the first text includes a sixth text corresponding to a plurality of nodes in the target path. The fifth text can be obtained by selecting a seventh text corresponding to a node in the target path from a plurality of sixth texts, and the seventh text corresponding to a node in the target path can be the sixth text that best matches the second prompt text corresponding to the node in the target path. Specifically, in the process of performing a Monte Carlo tree search on a plurality of first texts, the electronic device determines the seventh score of the sixth text based on the semantic relationship between the second prompt text corresponding to the node in the target path and the sixth text corresponding to the node in the target path. The seventh score can be used to quantify the semantic similarity between the second prompt text corresponding to the node in the target path and the sixth text corresponding to the node in the target path. The electronic device selects the sixth text corresponding to the largest seventh score as the seventh text corresponding to the node in the target path. The electronic device splices the seventh text to obtain the fifth text.

[0178] In some embodiments, in the process of determining the seventh score of the sixth text, the electronic device uses the third model to score the sixth text to obtain an eighth score. The eighth score can be used to quantify the fluency of the sixth text. The eighth score can also be used to quantify the logical clarity of the sixth text. The eighth score can also be used to quantify the degree of the sixth text in the dimension of fluency and the dimension of logical clarity, etc. The electronic device determines the number of times the third model scores the sixth text as the first number of visits to the sixth text by the third model. The electronic device determines the total number of times the third model scores the sixth text in the node as the second number of visits to the second prompt text by the third model. The electronic device determines the seventh score of the sixth text based on the eighth score of the sixth text, the first number of visits to the sixth text by the third model, and the second number of visits to the second prompt text by the third model. The calculation formula for the seventh score corresponding to the sixth text can be expressed as: Among them, l can represent the seventh score corresponding to the sixth text, w can represent the score of the sixth text by the third model, m can represent the first number of visits to the sixth text by the third model, M can represent the second number of visits to the second prompt text by the third model, ln(M) can represent the natural logarithm function value of the second number of visits, K is a positive integer, and K can be set and adjusted according to actual needs, for example, K=2.

[0179] In other embodiments, the electronic device uses the third model to evaluate the semantic relationship between the second prompt text and the sixth text to obtain a seventh score corresponding to the sixth text.

[0180] Combine Figure 6 Explain the process of obtaining the fifth text, such as Figure 6 As shown, the nodes in the target path include: node A, node B and node C, the first model generates multiple first texts corresponding to the target path including first text K1, first text K2, first text K3 and first text K4, the sixth text corresponding to node A includes sixth text a1, sixth text a2, sixth text a3 and sixth text a4, the sixth text corresponding to node B includes sixth text b1, sixth text b2, sixth text b3 and sixth text b4, and the sixth text corresponding to node C includes sixth text c1, sixth text c2, sixth text c3 and sixth text c4. The electronic device can determine the seventh score of the sixth text a1 based on the semantic relationship between the second prompt text corresponding to node A and the sixth text a1 corresponding to node A. In this way, the seventh score of the sixth text a2, the seventh score of the sixth text a3 and the seventh score of the sixth text a4 can also be obtained. If the seventh score of the sixth text a1> the seventh score of the sixth text a2> the seventh score of the sixth text a4> the seventh score of the sixth text a3, the electronic device can select the sixth text a1 as the seventh text corresponding to node A in the target path. In this way, the sixth text b2 is obtained as the seventh text corresponding to node B in the target path, and the sixth text c3 is obtained as the seventh text corresponding to node C in the target path. The electronic device concatenates the seventh texts according to the order of the nodes in the target path to obtain the fifth text as follows: sixth text a1 - sixth text b2 - sixth text c3.

[0181] S502: Construct a fifth prompt text according to the fifth text and the second text.

[0182] In at least one embodiment of the present application, the electronic device fills the fifth text and the second text into the second configuration template to obtain the fifth prompt text. The second configuration template may include a task content setting module, a third task requirement module, an input module corresponding to the fifth text, an input module corresponding to the second text, and a third output module. The task content setting module can be used to set the task content, the third task requirement module can be used to clarify the following contents: the scoring range of the sixth score, the scoring criteria of the sixth score, and the scoring reasons for the sixth score. The input module corresponding to the fifth text can be used to prompt the filling position of the fifth text, the input module corresponding to the second text can be used to prompt the filling position of the second text, and the third output module can be used to prompt the output format of the sixth score.

[0183] Specifically, the electronic device can fill the fifth text into the position corresponding to the input module of the fifth text in the second configuration template, and fill the second text into the position corresponding to the input module of the second text, to obtain the fifth prompt text. For example, the fifth prompt text can be expressed as:

[0184] You are now a dialogue path consistency assessment expert. Your task is to compare two dialogue paths and score their consistency. Please evaluate according to the following requirements:

[0185] #Require

[0186] -Conversation paths are scored on a scale of 0 to 10, with 10 indicating perfect agreement and 0 indicating no agreement.

[0187] - Scoring criteria include the order of dialogue nodes, similarity of content, and consistency of overall context.

[0188] -Please provide detailed justification for your rating.

[0189] # Input dialogue

[0190] ##Dialogue Path 1 (also known as "Fifth Text")

[0191] 1. Sales: Hello, how can I help you?

[0192] Customer: I would like to learn more about your loan products.

[0193] 2. Salesperson: Okay, how much loan do you need?

[0194] Customer: 100,000 yuan.

[0195] 3. Sales: What is the main purpose of this loan?

[0196] Customer: My child is going to school.

[0197] 4. Sales: Based on your needs, we recommend this product. It has a low interest rate and fast approval, which is very suitable for your needs.

[0198] Customer: Is there anything else I need to pay attention to?

[0199] 5. Sales: Yes, the repayment method of this product is also very flexible. You can choose a suitable repayment plan according to your situation.

[0200] Customer: I have some more questions.

[0201] 6. Sales: Okay, go ahead.

[0202] Customer: How long will it take to get this loan approved?

[0203] 7. Sales: Generally speaking, it takes about 3 working days from application submission to approval.

[0204] Customer: I see. I’m very interested in this product.

[0205] 8. Sales: Great. Let me help you start the relevant procedures now.

[0206] Customer: OK, thank you.

[0207] Sales: You’re welcome, thank you for your consultation and wish you a happy life!

[0208] ##Dialogue Path 2 (also known as "Second Text")

[0209] 1. Sales: Hello, how can I help you?

[0210] Customer: I would like to learn more about your loan products.

[0211] 2. Salesperson: Okay, how much loan amount do you need?

[0212] Customer: I need about 500,000 yuan.

[0213] 3. Sales: What do you plan to do with this loan?

[0214] Client: I want to use the money to renovate my house.

[0215] 4. Sales: We have a product with low interest rates and fast approval that is very suitable for your needs.

[0216] Customer: That sounds great. Are there any other advantages to this product?

[0217] 5. Sales: Yes, the repayment method of this product is very flexible and you can choose a suitable repayment plan based on your situation.

[0218] Customer: I have some more questions.

[0219] 6. Sales: Excuse me.

[0220] Customer: How long does it take for loan approval?

[0221] 7. Sales: Generally, it takes 3 working days from application submission to approval.

[0222] Customer: I see, this product is perfect for me.

[0223] 8. Sales: Great, I will help you start the relevant procedures now.

[0224] Customer: OK, thank you.

[0225] Sales: You’re welcome, I wish you a happy life!

[0226] #Output format

[0227] Consistency score: XX

[0228] Reason for rating: XXX.

[0229] S503: Input the fifth prompt text into the third model to obtain a sixth score.

[0230] In some embodiments, a third model can be used to evaluate the consistency between texts. The third model can be a large language model, for example, the third model can be a qwen2.5-72B model. The third model can also be a model of other network architectures, which is not limited in this application. The electronic device inputs the fifth prompt text into the third model to obtain a sixth score, which is used to evaluate the consistency between the fifth text and the second text.

[0231] Specifically, the third model may include an encoder layer, a decoder layer, and an output layer. The encoder layer may include multiple stacked Transformer encoding layers, and the electronic device uses the multiple stacked Transformer encoding layers in the encoder layer to encode the fifth prompt text to obtain encoding features. The decoder layer may include multiple stacked Transformer decoding layers, and the electronic device uses the multiple stacked Transformer decoding layers in the decoder layer to decode the encoding features to obtain decoding features. The output layer may include a fully connected layer, and the electronic device uses the fully connected layer to perform feature mapping on the decoded features to obtain a sixth score. S504, the fifth text whose sixth score is greater than the second preset score threshold is used as the target text.

[0232] In some embodiments, the second preset score threshold can be set and adjusted according to actual needs. For example, the second preset score threshold can be equal to the first preset score threshold. For example, the second preset score threshold can be different from the first preset score threshold. This application does not impose any specific restrictions on this.

[0233] The embodiment of the present application can preliminarily screen out a fifth text from the multiple first texts by performing a Monte Carlo tree search on the multiple first texts, and then by comparing the fifth text with the second texts, not only can the target text be quickly determined from the fifth text, but the quality of the target text can also be ensured.

[0234] In at least one embodiment of the present application, the electronic device repeatedly executes steps S201-S205 to obtain multiple target texts and construct a text dataset based on the multiple target texts. The text dataset can be used to train the model and to optimize the dialogue strategy in the human-computer interaction process.

[0235] In the text processing method of this embodiment, a directed graph is constructed using a preset first prompt text, and a target text is generated based on the directed graph. This enables text generation in scenarios without sample data. Furthermore, by determining the target path from the directed graph and then generating the corresponding text using the first and second models, the efficiency of text generation can be improved because the first and second models do not need to analyze the entire directed graph. Furthermore, by selecting the target text from the first text generated by the first model using the second text generated by the second model, the quality of the target text can be ensured.

[0236] like Figure 7 FIG. 1 is a flowchart of another text processing method provided by an embodiment of the present application. The text processing method is applied to electronic devices, for example, Figure 1 The electronic device 100. According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted.

[0237] S701: Based on a preset first prompt text, construct a directed graph corresponding to the first prompt text.

[0238] S702 : Determine a target path from the directed graph based on the weights corresponding to the connecting edges and the similarity between every two nodes in the directed graph.

[0239] S703: Generate a third prompt text according to the second prompt texts corresponding to the multiple nodes in the target path.

[0240] S704: Based on the third prompt text, generate multiple first texts corresponding to the target path through the first model.

[0241] The details of steps S701-S704 can be found above. Figure 2The detailed description of steps S201-S204 is not repeated here.

[0242] S705 , scoring each first text to obtain a ninth score of each first text in a plurality of preset dimensions.

[0243] In at least one embodiment of the present application, the plurality of preset dimensions may include a coherence dimension, a relevance dimension, an integrity dimension, a logic dimension, and the like.

[0244] In at least one embodiment of the present application, the electronic device generates a sixth prompt text based on multiple preset dimensions. Specifically, the electronic device can splice the dimensional information of multiple preset dimensions and the third configuration template to obtain the sixth prompt text. Among them, the third configuration template may include a second task description module, and the second task description module can be used to set the evaluation requirements for the first text. For example, the second task description module may be "Please evaluate the first text from the following multiple preset dimensions." The dimensional information of the preset dimension can indicate the evaluation content of the preset dimension. For example, the dimensional information corresponding to the coherence dimension may be "In terms of coherence, check whether the connection between sentences and sentences, paragraphs and paragraphs is natural and smooth, and whether there are semantic jumps."

[0245] In at least one embodiment of the present application, the electronic device uses the third model to analyze each first text based on the sixth prompt text to obtain a ninth score for each first text in multiple preset dimensions. The ninth score for each first text may include a coherence evaluation value, a relevance evaluation value, a completeness evaluation value, and a logic evaluation value of the first text. Specifically, the manner in which the electronic device determines the ninth score of the first text using the third model is similar to the manner in which the electronic device determines the sixth score using the third model, and this application will not repeat this description.

[0246] In other embodiments, the ninth score of each first text in multiple preset dimensions may also be determined through manual review.

[0247] S706 : Select an eighth text from the first text based on the ninth score of the first text in the plurality of preset dimensions.

[0248] In at least one embodiment of the present application, the electronic device performs a weighted sum calculation on the ninth scores of the first texts in multiple preset dimensions to obtain the tenth score corresponding to each first text. The electronic device determines the first text corresponding to the tenth score greater than a set threshold as the eighth text. The set threshold can be set and adjusted according to actual needs.

[0249] In other embodiments, the electronic device compares the ninth score of the first text in the preset dimension with the evaluation threshold corresponding to the preset dimension. If the ninth score of the first text in the preset dimension is greater than the corresponding evaluation threshold, the electronic device determines the first text as the eighth text. The evaluation threshold can be set and adjusted according to actual needs.

[0250] By combining multiple preset dimensions, the embodiment of the present application can filter out an eighth text that meets the preset standards from the first text, thereby improving the quality of the eighth text.

[0251] S707: Adjust the first model based on the target path and the eighth text to obtain a second model.

[0252] In at least one embodiment of the present application, the electronic device updates the weight matrix of the preset network layer in the first model to obtain an adjusted first model. The preset network layer can be any network layer in the first model. For example, the preset network layer can be the encoding layer in the first model, the attention network layer in the first model, the feedforward neural network layer in the first model, etc. The electronic device uses the adjusted first model to generate a ninth text corresponding to the target path. The electronic device calculates the loss value of the adjusted first model based on the text similarity between the eighth text and the ninth text. Based on the loss value, the electronic device readjusts the adjusted first model until the preset conditions are met to obtain the second model. The preset conditions can be set as: the loss value is less than the preset loss value, the number of training times reaches the preset number of times, etc.

[0253] In some embodiments, the electronic device may update the weight matrix based on the dimension of the weight matrix. For example, if the weight matrix of the attention layer in the first model is W1, and the dimension of the weight matrix W1 is d1×d2, the electronic device updates the weight matrix W1, and the updated weight matrix can be W1+XY, where the dimension of X is r×d2, the dimension of Y is d1×r, and r is an integer value less than d1 and less than d2.

[0254] In some embodiments, the loss value of the adjusted first model may be inversely proportional to the text similarity.

[0255] S708: Generate a second text corresponding to the target path through a second model based on the third prompt text.

[0256] S709: Select a target text from the plurality of first texts based on the second text.

[0257] The details of steps S708-S709 can be found above. Figure 2 The detailed description of steps S204-S205 is not repeated here.

[0258] In the text processing method of this embodiment, based on preset dimensions, a high-quality eighth text can be screened from multiple first texts generated by the first model. By adjusting the first model using the eighth text, the model effect of the second model can be rapidly improved, thereby improving the quality of the text generated by the second model. The quality of the target text can be ensured by selecting the target text from the first texts generated by the first model using the second text generated by the second model.

[0259] like Figure 8 FIG. 1 is a schematic diagram of a framework of a second model adjustment method provided in an embodiment of the present application. Figure 8 In the embodiment of the present invention, the electronic device generates a first prompt text based on the scene name input by the user and the description information of the communication framework. The electronic device inputs the first prompt text into the first model, and generates a third text as a communication node (also referred to as the "first node" above) through the first model. The electronic device generates a fourth prompt text based on the third text, inputs the fourth text into the first model, generates the fourth text as an extension node of the communication node (also referred to as the "second node" above) through the first model, and generates the semantic association between the third text and the fourth text through the first model. The electronic device uses the semantic association between the third text and the fourth text as the weight of the connection edge between the communication node (also referred to as the "first node" above) and the extension node (also referred to as the "second node" above), and obtains a directed graph based on the semantic association between the communication node, the extension node and the third text and the fourth text as the weight of the connection edge between the communication node and the extension node.

[0260] The electronic device determines the target path from the directed graph based on the weights corresponding to the connecting edges in the directed graph and the similarity between each two nodes in the directed graph. The electronic device generates a small amount of data set of the target path (also referred to as "first text" above) through the first model.

[0261] The electronic device selects a high-quality dataset (also referred to as the "eighth text") from a small number of datasets (also referred to as the "first text") based on multiple preset dimensions. The electronic device fine-tunes the first model using the high-quality dataset (also referred to as the "eighth text") and the target path to obtain a second model.

[0262] like Figure 9 FIG. 1 is a schematic diagram of a target text determination method according to an embodiment of the present application. Figure 9 In the embodiment, the electronic device generates multiple dialogue paths (also referred to as "first texts" above) of nodes in the target path through the original LLM-7B model (referred to as "first model" above), and generates a single high-quality dialogue path (referred to as "second text" above) of nodes in the target path through the fine-tuned LLM-7B model (referred to as "second model" above).

[0263] The electronic device uses the MCTS algorithm to select the optimal dialogue path (referred to as the "fifth text") from multiple dialogue paths (referred to as the "first text" above). Based on the consistency score between the optimal dialogue path (referred to as the "fifth text") and a single high-quality dialogue path (referred to as the "second text" above), the electronic device selects a target text from the optimal dialogue path (referred to as the "fifth text") and stores the target text.

[0264] like Figure 10 , is a functional module diagram of a text processing device provided by an embodiment of the present application. The text processing device 1001 includes a construction unit 1010, a determination unit 1011, a generation unit 1012, a selection unit 1013 and an adjustment unit 1014. The module / unit referred to in this application refers to a type of unit that can be processed by a processor (e.g. Figure 11 A series of computer readable instruction segments are obtained by the processor 1101 shown in FIG. 1 and are capable of completing fixed functions, which are stored in a memory (eg Figure 11 In the memory 1102 shown.

[0265] The construction unit 1010 is used to construct a directed graph corresponding to the first prompt text based on the preset first prompt text, where the nodes in the directed graph represent texts, the connecting edges in the directed graph represent semantic relationships between different texts, and the weights of the connecting edges are determined based on the semantic relationships between different texts; the determination unit 1011 is used to determine the target path from the directed graph based on the weights corresponding to the connecting edges and the similarity between every two nodes in the directed graph; the generation unit 1012 is used to generate a third prompt text based on the second prompt texts corresponding to multiple nodes in the target path; the generation unit 1012 is also used to generate multiple first texts corresponding to the target path through the first model based on the third prompt text, and to generate a second text corresponding to the target path through the second model; the selection unit 1013 is used to select a target text from multiple first texts based on the second text.

[0266] In one embodiment, the construction unit 1010 is specifically used to: generate a third text based on the first prompt text through the first model; fill the third text into a preset template to obtain a fourth prompt text; generate a fourth text based on the fourth prompt text through the first model; determine the semantic relevance between the fourth text and the third text based on the semantic relationship between the fourth text and the third text; and construct a directed graph with the third text as the first node, the fourth text as the second node, and the semantic relevance as the weight corresponding to the connecting edge between the first node and the second node.

[0267] In one embodiment, the determination unit 1011 is specifically used to: based on the multi-head attention mechanism, feature encode the text corresponding to each node in the directed graph to obtain multiple first feature codes corresponding to each node, each first feature code including at least one component; perform bitwise operations on the components in the multiple first feature codes of each node to obtain a second feature code corresponding to each node; and calculate the similarity between each two nodes based on the second feature code of each node.

[0268] In one embodiment, the determination unit 1011 is further specifically used to: calculate a first score between each two nodes based on the weight and similarity; select a starting node and an ending node from multiple nodes in the directed graph; based on the first score, determine a third node between the starting node and the ending node in the directed graph; and construct a target path based on the starting node, the ending node, and the third node.

[0269] In one embodiment, the determining unit 1011 is further configured to: select a fourth node corresponding to the largest first score as the third node, where the fourth node is any one of the nodes connected to the start node.

[0270] In one embodiment, the selection unit 1013 is specifically used to: determine the second score of each first text and the second text based on the position of the text corresponding to the node in the target path in each first text, and the position of the text corresponding to the node in the target path in the second text; determine the third score of each first text and the second text based on the similarity between each first text and the second text; determine the fourth score of each first text and the second text based on the context of each first text and the context of the second text; calculate the fifth score of each first text and the second text according to the second score, the third score and the fourth score; and determine the first text whose fifth score is greater than the first preset score threshold as the target text.

[0271] In one embodiment, the selection unit 1013 is further specifically used to: perform a Monte Carlo tree search on multiple first texts to obtain a fifth text; construct a fifth prompt text based on the fifth text and the second text; input the fifth prompt text into the third model to obtain a sixth score, and the sixth score is used to evaluate the consistency between the fifth text and the second text; and use the fifth text whose sixth score is greater than the second preset score threshold as the target text.

[0272] In one embodiment, the selection unit 1013 is further configured to: determine the seventh score of the sixth text according to the semantic relationship between the second prompt text corresponding to the node in the target path and the sixth text corresponding to the node in the target path; select the sixth text corresponding to the largest seventh score as the seventh text corresponding to the node in the target path; and concatenate the seventh texts to obtain the fifth text.

[0273] In one embodiment, the determination unit 1011 is further used to score each first text to obtain a ninth score of each first text in multiple preset dimensions; the selection unit 1013 is further used to select an eighth text from the first text based on the ninth score of the first text in multiple preset dimensions; the adjustment unit 1014 is used to adjust the first model based on the target path and the eighth text to obtain a second model.

[0274] In multiple embodiments of the present application, by constructing a directed graph through a preset first prompt text and generating a target text based on the directed graph, text generation can be achieved in scenarios without sample data. At the same time, by determining the target path from the directed graph and then generating the corresponding text through the first model and the second model, the efficiency of text generation can be improved because the first model and the second model do not need to analyze the entire directed graph. In addition, by selecting the target text from the first text generated by the first model through the second text generated by the second model, the quality of the target text can be ensured.

[0275] Figure 11 is a schematic diagram of the structure of an electronic device for implementing a text processing method provided in an embodiment of the present application. Figure 11 The electronic device 100 is used to perform Figure 2 、 Figure 4 、 Figure 5 、 Figure 7 、 Figure 8 、 Figure 9 The method shown.

[0276] The electronic device 100 includes at least one processor 1101 , a memory 1102 , and at least one network interface 1103 .

[0277] The processor 1101 is, for example, a general-purpose central processing unit (CPU), a network processor (NP), a graphics processing unit (GPU), a neural-network processing unit (NPU), a data processing unit (DPU), a microprocessor, or one or more integrated circuits for implementing the solution of the present application. For example, the processor 1101 includes an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The PLD is, for example, a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0278] The memory 1102 is, for example, a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a random access memory (RAM) or other type of dynamic storage device that can store information and instructions, an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, an optical disc storage (including a compact disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. Optionally, the memory 1102 exists independently and is connected to the processor 1101 via an internal connection 1104. Alternatively, the memory 1102 and the processor 1101 are optionally integrated together.

[0279] The network interface 1103 uses any transceiver-like device for communicating with other devices or communication networks. For example, the network interface 1103 includes at least one of a wired network interface and a wireless network interface. For example, the wired network interface is an Ethernet interface. For example, the Ethernet interface is an optical interface, an electrical interface, or a combination thereof. For example, the wireless network interface is a wireless local area network (WLAN) interface, a cellular network interface, or a combination thereof.

[0280] In some embodiments, the processor 1101 includes one or more CPUs, such as Figure 11 CPU0 and CPU1 are shown in the figure.

[0281] In some embodiments, the electronic device 100 optionally includes multiple processors, such as Figure 11 1 and 1105. Each of these processors is, for example, a single-CPU or a multi-CPU. A processor herein optionally refers to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).

[0282] In some embodiments, electronic device 100 further includes internal connections 1104. Processor 1101, memory 1102, and at least one network interface 1103 are connected via internal connections 1104. Internal connections 1104 include pathways for transmitting information between these components. Internal connections 1104 may optionally be a single board or bus. Internal connections 1104 may optionally be divided into an address bus, a data bus, a control bus, and the like.

[0283] In some embodiments, the electronic device 100 further includes an input / output interface 1106 , which is connected to the internal connection 1104 .

[0284] Optionally, the processor 1101 implements the method in the above embodiment by reading the program code 910 stored in the memory 1102, or the processor 1101 implements the method in the above embodiment by internally stored program code. In the case where the processor 1101 implements the method in the above embodiment by reading the program code 910 stored in the memory 1102, the memory 1102 stores the program code that implements the method provided in the embodiment of the present application.

[0285] For more details on how the processor 1101 implements the above functions, please refer to the descriptions in the previous method embodiments, which will not be repeated here.

[0286] This embodiment further provides a computer storage medium, which stores computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the text processing method in the above-mentioned embodiment.

[0287] This embodiment further provides a computer program product. When the computer program product is run on an electronic device, the electronic device is caused to execute the above-mentioned related steps to implement the text processing method in the above-mentioned embodiment.

[0288] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory to enable the chip to execute the text processing method in the above-mentioned method embodiments.

[0289] Among them, the electronic device, computer storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be repeated here.

[0290] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0291] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0292] The units described as separate components may or may not be physically separate, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0293] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0294] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0295] The above are only specific embodiments of the present application, but the scope of protection of the present application is not limited thereto. Any changes or replacements within the technical scope disclosed in this application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

Claims

1. A text processing method, characterized in that: The method comprises: Based on a preset first prompt text, construct a directed graph corresponding to the first prompt text, where nodes in the directed graph represent texts, edges in the directed graph represent semantic relationships between different texts, and weights of the edges are determined based on the semantic relationships between the different texts; Determining a target path from the directed graph based on weights corresponding to the connecting edges and similarities between every two nodes in the directed graph; generating a third prompt text according to the second prompt texts corresponding to the plurality of nodes in the target path; Based on the third prompt text, generating a plurality of first texts corresponding to the target path through a first model, and generating a second text corresponding to the target path through a second model; Based on the second text, a target text is selected from the plurality of first texts.

2. The text processing method according to claim 1, characterized in that: The step of constructing a directed graph corresponding to the preset first prompt text based on the first prompt text includes: Based on the first prompt text, generate a third text through the first model; Filling the third text into a preset template to obtain a fourth prompt text; Based on the fourth prompt text, generating a fourth text by using the first model; determining a semantic relevance between the fourth text and the third text according to a semantic relationship between the fourth text and the third text; The directed graph is constructed by using the third text as the first node, the fourth text as the second node, and the semantic relevance as the weight corresponding to the connecting edge between the first node and the second node.

3. The text processing method according to claim 1, characterized in that: The process of determining the similarity between every two nodes in the directed graph includes: Based on a multi-head attention mechanism, feature encoding is performed on the text corresponding to each node in the directed graph to obtain multiple first feature codes corresponding to each node, each first feature code including at least one component; Performing a bitwise operation on the components of the multiple first feature codes of each node to obtain a second feature code corresponding to each node; Based on the second feature code of each node, the similarity between each two nodes is calculated.

4. The text processing method according to claim 1, wherein: The determining a target path from the directed graph based on the weights corresponding to the connecting edges and the similarity between every two nodes in the directed graph includes: Calculating a first score between each two nodes according to the weight and the similarity; Selecting a starting node and an ending node from a plurality of nodes of the directed graph; Determining, based on the first score, a third node between the starting node and the ending node in the directed graph; The target path is constructed based on the start node, the end node, and the third node.

5. The text processing method according to claim 4, characterized in that: The determining, in the directed graph, a third node between the start node and the end node based on the first score includes: The fourth node corresponding to the largest first score is used as the third node, and the fourth node is any one of the nodes connected to the starting node.

6. The text processing method according to claim 1, characterized in that: The selecting a target text from the plurality of first texts based on the second text includes: determining a second score for each of the first texts and the second text based on a position of the text corresponding to the node in the target path in each first text and a position of the text corresponding to the node in the target path in the second text; determining a third score between each first text and the second text based on the similarity between each first text and the second text; determining a fourth score for each of the first texts and the second text based on a context of each of the first texts and a context of the second text; Calculating a fifth score for each of the first texts and the second text according to the second score, the third score, and the fourth score; The first text whose fifth score is greater than the first preset score threshold is determined as the target text.

7. The text processing method according to claim 1, characterized in that: The selecting a target text from the plurality of first texts based on the second text includes: Performing a Monte Carlo tree search on the plurality of first texts to obtain a fifth text; constructing a fifth prompt text according to the fifth text and the second text; Inputting the fifth prompt text into a third model to obtain a sixth score, wherein the sixth score is used to evaluate the consistency between the fifth text and the second text; The fifth text having a sixth score greater than the second preset score threshold is used as the target text.

8. The text processing method according to claim 7, characterized in that: The first text includes a sixth text corresponding to a node in the target path, and the Monte Carlo tree search is performed on the plurality of first texts to obtain a fifth text, including: determining a seventh score of the sixth text according to a semantic relationship between the second prompt text corresponding to the node in the target path and the sixth text corresponding to the node in the target path; Selecting the sixth text corresponding to the largest seventh score as the seventh text corresponding to the node in the target path; The seventh text is spliced ​​together to obtain the fifth text.

9. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the text processing method according to any one of claims 1 to 8 when executing the computer program.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the text processing method according to any one of claims 1 to 8 is implemented.

11. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the text processing method according to any one of claims 1 to 8 is implemented.