Text generation methods, apparatuses, electronic devices, storage media, and program products

By generating lexical units in parallel using a text generation model and combining them with user-satisfied text portions, the problem of large language models being unable to recognize user satisfaction is solved, achieving more efficient text generation flexibility and improved user satisfaction.

CN119886066BActive Publication Date: 2026-03-06VIVO MOBILE COMM CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510071614.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-16
Publication Date
2026-03-06
Estimated Expiration
2045-01-16

AI Technical Summary

Technical Problem

Existing Large Language Models (LLMs) cannot effectively identify users' specific satisfaction with the generated content. As a result, even after users repeatedly enter the same prompts, the LLM may still only generate answers that satisfy only a portion of the content, making it difficult to improve users' satisfaction with the answers.

Method used

By obtaining the first prompt word and the first answer, at least one first word unit is generated using a text generation model, and multiple candidate word units are generated in parallel using a multi-head prediction module. Combined with the first text that satisfies the user, the second answer is output, ensuring that the new answer retains the part that satisfies the user and is optimized.

Benefits of technology

It enhances the flexibility of text generation methods, increases the probability of generating answers that satisfy users, and meets users' personalized needs for text content.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119886066B_ABST
    Figure CN119886066B_ABST
Patent Text Reader

Abstract

This application discloses a text generation method, apparatus, electronic device, storage medium, and program product, belonging to the field of artificial intelligence. The method includes: obtaining a first prompt word and a first answer, the first answer being generated based on the first prompt word and including first text; inputting the first prompt word and the first answer into a text generation model, generating at least one first word element based on the first prompt word and the first answer through the text generation model; and outputting a second answer based on the at least one first word element and the first text through the text generation model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of artificial intelligence, specifically relating to a text generation method, apparatus, electronic device, storage medium, and program product. Background Technology

[0002] With the development of artificial intelligence technology, Large Language Models (LLMs) in the field of Natural Language Processing (NLP) have gained the ability to handle complex language tasks. They can be used for various tasks such as text generation, machine translation, and sentiment analysis, greatly improving the efficiency and accuracy of information processing. After a user uses an LLM to generate an answer, the user may be satisfied with some parts of the answer but not others. The user can then repeatedly input the same prompt into the LLM to regenerate different answers until the LLM produces an answer that satisfies the user.

[0003] However, LLM cannot effectively identify the user's specific satisfaction with the generated content. This means that even after a user repeatedly enters the same prompt, LLM may still only generate answers that partially satisfy the user, making it difficult to improve user satisfaction. Thus, existing text generation methods lack flexibility. Summary of the Invention

[0004] The purpose of this application is to provide a text generation method, apparatus, electronic device, storage medium, and program product that can improve the flexibility of the text generation method.

[0005] In a first aspect, embodiments of this application provide a text generation method, the method comprising: obtaining a first prompt word and a first answer, the first answer being generated based on the first prompt word and including first text; inputting the first prompt word and the first answer into a text generation model, generating at least one first word element through the text generation model based on the first prompt word and the first answer; and outputting a second answer through the text generation model based on the at least one first word element and the first text.

[0006] Secondly, embodiments of this application provide a text generation apparatus, which includes an acquisition module and an execution module. The acquisition module is used to acquire a first prompt word and a first answer, the first answer being generated based on the first prompt word and including first text. The execution module is used to input the first prompt word and the first answer acquired by the acquisition module into a text generation model, and to generate at least one first word element based on the first prompt word and the first answer through the text generation model. The execution module is further used to output a second answer based on the at least one first word element and the first text through the text generation model.

[0007] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, wherein the memory stores programs or instructions executable on the processor, and the programs or instructions, when executed by the processor, implement the steps of the method described in the first aspect.

[0008] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.

[0009] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the method as described in the first aspect.

[0010] In a sixth aspect, embodiments of this application provide a computer program product stored in a storage medium, which is executed by at least one processor to implement the method described in the first aspect.

[0011] In this embodiment, a first prompt word and a first answer generated based on the first prompt word can be obtained. The first answer includes first text. Then, the first prompt word and the first answer can be input into a text generation model. The text generation model generates at least one first word element based on the first prompt word and the first answer. Then, the text generation model outputs a second answer based on the at least one first word element and the first text. In this solution, since the electronic device can generate at least one first word element based on the first prompt word and the first answer, that is, generate new text content based on the first prompt word and the answer generated based on the first prompt word, and then output the second answer based on the at least one first word element and the first text through the text generation model, that is, combine the new text content with the user-satisfied part of the answer generated based on the first prompt word to obtain the second answer. Thus, while generating a new answer different from the first answer based on the first prompt word, the user-satisfied part is retained, increasing the probability of generating a user-satisfied answer, thereby improving the flexibility of the text generation method. Attached Figure Description

[0012] Figure 1 This is one of the flowcharts of the text generation method provided in the embodiments of this application;

[0013] Figure 2 This is a schematic diagram of the first text in the first answer provided in the embodiments of this application;

[0014] Figure 3 This is the second flowchart of the text generation method provided in the embodiments of this application;

[0015] Figure 4 This is the third flowchart of the text generation method provided in the embodiments of this application;

[0016] Figure 5 This is a schematic diagram of the structure of the text generation model provided in the embodiments of this application;

[0017] Figure 6 This is the fourth flowchart of the text generation method provided in the embodiments of this application;

[0018] Figure 7 This is the fifth flowchart of the text generation method provided in the embodiments of this application;

[0019] Figure 8 This is a schematic diagram illustrating the calculation of the fourth probability provided in an embodiment of this application;

[0020] Figure 9 This is a schematic diagram of the second answer provided in the embodiments of this application;

[0021] Figure 10 This is the sixth flowchart of the text generation method provided in the embodiments of this application;

[0022] Figure 11 This is the seventh flowchart of the text generation method provided in the embodiments of this application;

[0023] Figure 12 This is a schematic diagram illustrating the execution process of the text generation method provided in the embodiments of this application;

[0024] Figure 13 This is one of the schematic diagrams of the text generation apparatus provided in the embodiments of this application;

[0025] Figure 14 This is a second schematic diagram of the text generation device provided in the embodiments of this application;

[0026] Figure 15 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application;

[0027] Figure 16 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0028] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.

[0029] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0030] The terms "at least one," "at least one," etc., in this application refer to any one, any two, or a combination of two or more of the included objects. For example, at least one of a, b, and c can mean: "a," "b," "c," "a and b," "a and c," "b and c," and "a, b, and c," where a, b, and c can be single or multiple. Similarly, "at least two" refers to two or more, and its meaning is similar to that of "at least one."

[0031] The text generation method, apparatus, electronic device, storage medium, and program product provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.

[0032] This application's embodiments can be applied to scenarios where text content is generated based on user-input prompts. Specifically, after a user inputs specific prompts, causing an electronic device to generate relevant text content based on these prompts, the user may only be satisfied with a portion of that text content. The user then needs the electronic device to generate new text content based on those prompts to obtain a satisfactory answer.

[0033] The following uses some specific scenarios from the embodiments of this application as examples to illustrate the text generation method provided in the embodiments of this application.

[0034] Scenario 1: Suppose a user is preparing for an interview and wants a text version of their self-introduction. After the user inputs "self-introduction for an interview" as a prompt, the electronic device generates a text version. However, the user is only satisfied with the "personal background and education" section. The user can then mark this section, allowing the electronic device to regenerate a new text version that includes this section. This ensures that the new text retains the parts the user was satisfied with from the first version while optimizing and updating other parts, thus improving the user's overall satisfaction.

[0035] Scenario 2: Suppose a user is writing an article about healthy eating. The user inputs "the importance of healthy eating" as a prompt, and the electronic device generates relevant text including two parts: "Nutritional Components" and "The Importance of Healthy Eating." However, the user finds the description of "Nutritional Components" insufficiently detailed. The user can highlight the "Importance of Healthy Eating" section, causing the electronic device to generate relevant text that retains this aspect while expanding on the "Nutritional Components" section, thus improving user satisfaction.

[0036] Scenario 3: Suppose a user wants to post a travel-related update on social media. The user enters "Share my travel experience" as a prompt, and the electronic device generates a dynamic text message including two parts: "Travel Destination" and "Travel Impressions." The user is very satisfied with the description of the "Travel Destination" section but wants to modify the "Travel Impressions" section. The user can mark the "Travel Destination" section so that the electronic device generates dynamic text that retains this content, while rewriting the "Travel Impressions" section to improve the user's satisfaction with the update.

[0037] It should be noted that scenarios 1 to 3 above are merely exemplary examples of some scenarios that may be applied to the embodiments of this application. In actual implementation, the embodiments of this application can also be applied to any possible scenario of generating more demand texts, and the embodiments of this application are not limited here.

[0038] This application provides a text generation method, apparatus, electronic device, storage medium, and program product. Since the electronic device can generate at least one first word element based on a first prompt word and a first answer, that is, generate new text content based on the first prompt word and the answer generated based on the first prompt word, and then output a second answer through a text generation model based on at least one first word element and the first text, that is, combine the new text content with the user-satisfied part of the answer generated based on the first prompt word to obtain the second answer, it can generate a new answer different from the first answer based on the first prompt word while retaining the user-satisfied part, thus increasing the probability of generating a user-satisfied answer and improving the flexibility of the text generation method.

[0039] The text generation method provided in this application can be executed by a text generation device, which can be an electronic device, or a functional module or functional entity within an electronic device. The following description uses an electronic device as an example to illustrate the technical solution provided in this application.

[0040] Figure 1A flowchart of a text generation method provided in an embodiment of this application is shown, such as... Figure 1 As shown, the text generation method provided in this application embodiment may include the following steps 201 to 203.

[0041] Step 201: The electronic device obtains the first prompt word and the first answer.

[0042] In this embodiment of the application, the first answer is generated based on the first prompt word, and the first answer includes the first text.

[0043] It should be noted that the aforementioned prompts are also known as prompts, which are specific prompts or phrases entered by the user to guide the text generation model to generate relevant text. For example, a prompt can be a question, topic, keyword, or any other form of instruction. The text generation model can understand the user's needs based on the instruction and generate the corresponding text.

[0044] In this embodiment of the application, the first answer is text generated by the text generation model based on the first prompt word. The text may include multiple paragraphs, and the content may include topics, background information, relevant data, or suggestions related to the prompt word.

[0045] It should be noted that the aforementioned text generation model, also known as a large language model or large model, is a computational model based on machine learning and natural language processing techniques. It can generate new text content based on input text (such as prompts or context). Text generation models are typically trained on massive amounts of text data, possessing hundreds of millions, billions, or even trillions of parameters, a vast amount of knowledge information, and the ability to be fine-tuned based on different training data for different tasks. In this embodiment, the electronic device can generate a first answer by inputting prompts into the text generation model. After the user marks the first text from the first answer, the electronic device can generate a new answer by inputting the first answer and prompts into the text generation model.

[0046] In this embodiment, the first text is the text that the user wishes to retain in the first answer, meaning that the first text in the first answer satisfies the user's needs. This first text is the text selected by the user, reflecting the user's approval and satisfaction with that text.

[0047] In this embodiment, the electronic device can analyze the meaning of the first prompt word based on the user's input, using the knowledge and language patterns learned during the training of the text generation model, and generate related text content, i.e., the first answer. The user can mark the first text in the first answer so that the electronic device can know the text that satisfies the user, and retain the first text in the newly generated answer while regenerating the answer.

[0048] For example, a mobile phone is used as an illustration, such as Figure 2 As shown, assuming the user's first prompt word 10 is "self-introduction during an interview", the mobile phone can generate a first answer 11 based on this first prompt word 10. Let the content of the first answer 11 be as follows:

[0049] "A self-introduction during an interview is crucial for making a good first impression on the interviewer. A good self-introduction should be concise yet effectively showcase your strengths and personality. Below is a basic self-introduction template that you can adapt to your own situation:"

[0050] [beginning]

[0051] Good morning / afternoon, esteemed interviewers! I am [Your Name], a graduate of [Your School], majoring in [Your Major]. Thank you very much to [Company Name] for giving me this interview opportunity, allowing me to showcase myself to you all.

[0052] [Educational Background]

[0053] During my university years, I systematically studied [relevant courses] and actively participated in [relevant projects or activities]. Through this learning and practice, I not only acquired solid professional knowledge but also cultivated strong learning abilities and teamwork spirit.

[0054] [Work Experience]

[0055] (If you have relevant work or internship experience) During my internship at [Company Name], I was primarily responsible for [Specific Work Content]. During this time, I learned [Skills] and achieved [Specific Results]. These experiences gave me a deeper understanding of [Job Title] and solidified my career development direction in this field.

[0056] [Personal Strengths]

[0057] I believe I possess the following strengths: First, I have strong [a specific skill or quality] and can quickly adapt to new environments and tasks; second, I am good at communication and teamwork, and can effectively cooperate with colleagues from different backgrounds; finally, I am serious and responsible in my work, pay attention to details, and strive for excellence.

[0058] [Expectations for future work]

[0059] I am enthusiastic and excited about [Company Name] and [Job Title]. I believe my professional background and work experience will bring new vitality to the team. If I am fortunate enough to join [Company Name], I will work hard, continuously improve myself, and contribute my strength to the company's development.

[0060] [End]

[0061] Thank you again to all the interviewers for this opportunity. I look forward to further discussions with you all. Thank you!

[0062] I hope this template is helpful. Best of luck with your interview!

[0063] Users can mark the text they are satisfied with in the first answer 11, such as first text 12, first text 13, and first text 14, so that the electronic device can know the text that the user is satisfied with and generate a new answer containing these texts.

[0064] Step 202: The electronic device inputs the first prompt word and the first answer into the text generation model, and generates at least one first word element based on the first prompt word and the first answer.

[0065] In this embodiment, the aforementioned lexical unit is also called a token, which is the basic unit in text generation, typically referring to a word, subword, character, or punctuation mark. During the generation process, the text generation model can progressively generate these lexical units to construct complete text content.

[0066] In this embodiment of the application, "generating at least one first word element" can be understood as the text generation model generating text containing at least one word element based on the input prompt and answer. For example, the generated text can be a single word, or it can be a phrase.

[0067] In this embodiment, the electronic device can analyze the content of the first prompt word and the first answer through a text generation model to understand the user's needs and context. Based on this understanding, the model generates lexical units related to the prompt word, which are then concatenated to form new text content.

[0068] Optionally, in the embodiments of this application, combined with Figure 1 ,like Figure 3 As shown, step 202 can be implemented through steps 202a and 202b below.

[0069] Step 202a: The electronic device inputs the first prompt word and the first answer into the multi-head prediction module of the text generation model, and obtains N second word units based on the first answer through the multi-head prediction module.

[0070] In the embodiments of this application, N is a positive integer.

[0071] In this embodiment, the multi-head prediction module is an important component of the text generation model, typically based on a Transformer architecture. Its main function is to generate multiple subsequent lexical units in parallel, thereby improving the efficiency and diversity of text generation. During multi-head prediction in an electronic device, multiple heads can be used simultaneously to predict multiple subsequent lexical units.

[0072] It should be noted that existing large language models commonly use a decoder-only transformer structure. In this structure, the process of inferring lexical units by the large language model is as follows:

[0073] During model training, since the expected target answer is additionally input, the decoder's dedicated transformer can use the lexical units in these target answers to generate all lexical units in parallel.

[0074] Unlike during model training, large language models employing this structure, during inference and decoding, cannot access all information—that is, they cannot access subsequently generated words—and can typically only generate words sequentially, one by one. During inference, the model can only rely on the already generated portion of the text to predict the next word, meaning that only one word can be generated per inference step. Specifically, at each generation step, the model calculates the probability distribution of the next word based on the currently generated text and input prompts, and selects one word as the output. While this sequential generation method ensures the coherence of the generated text, it also leads to lower inference efficiency, especially when generating longer texts, where the model's inference time increases significantly.

[0075] Optionally, in this embodiment, since it is necessary to compare with the first text to determine the position of the first text segment, the efficiency of using serial generation of tokens is too low. Therefore, the electronic device can use a multi-head prediction module to achieve parallel generation of tokens through a multi-head mechanism. Specifically, based on retaining the original Language Model Head (LM Head) in the last hidden layer of the large model, n additional heads are added to predict subsequent tokens respectively. The structure and parameters of the added heads are consistent with the original LM Head. The first add head predicts the token after the next token, the second add head predicts the token after the next token, and so on. During training, the parameters of the original model can be frozen, and only the parameters of these add heads are trained and updated, thereby training the multi-head prediction module. By adding n additional heads, the large model can obtain the probability distribution of the subsequent n+1 tokens in one inference.

[0076] Optionally, in this embodiment, the number n of newly added heads in the multi-head prediction module can be a system default or a user-defined value. For example, n can be 2, 3, 4, etc. The specific number can be determined according to actual usage requirements, and this embodiment does not impose any restrictions.

[0077] In this embodiment of the application, the above-mentioned N second lexical units are N possible candidate lexical units predicted by the large model based on the text content of the first answer.

[0078] In this embodiment of the application, the electronic device can simultaneously input the first prompt word and the first answer into the multi-head prediction module, and then the large model can obtain N second word units for generating a new answer based on the content of the first answer.

[0079] By generating in parallel, the model can provide multiple candidate nodules in a shorter time, increasing the diversity of the generated text.

[0080] Step 202b: The electronic device uses a multi-head prediction module to determine at least one first word element from the N second word elements based on the first prompt word and N second word elements.

[0081] In this embodiment of the application, the aforementioned at least one first word element is a word element related to the first prompt word determined by the electronic device from N candidate second word elements.

[0082] Optionally, in this embodiment of the application, after obtaining N second word elements for generating a new answer, the electronic device can determine the next word element starting with the first prompt word from the N second word elements, i.e., the first word element, based on the first word element, and then determine the next word element from the N second word elements, i.e., the second word element, and so on, to generate at least one first word element.

[0083] Optionally, in embodiments of this application, the aforementioned at least one first word element is divided into at least one word element group, and each word element group includes a portion of the word elements from at least one first word element. For example, in combination with... Figure 3 ,like Figure 4 As shown, step 202b can be implemented through steps 202b1 and 202b2 as described below.

[0084] Step 202b1: For the i-th word group in at least one word group, the electronic device determines the first probability of each second word group as the first word group in the i-th word group based on the first prompt word through the multi-head prediction module, and takes the second word group with the highest first probability among the N second word groups as the first word group in the i-th word group.

[0085] In this embodiment, i is a positive integer.

[0086] In this embodiment of the application, the above-mentioned word group is a word sequence composed of multiple words, that is, the number of words that the large model can predict at the same time.

[0087] Optionally, in embodiments of this application, the number of lexical units contained in each of the at least one lexical units can be determined by the number of heads in the multi-head prediction module. For example, it can be the same as the number of heads in the multi-head prediction module, or it can be a multiple of the number of heads in the multi-head prediction module. Thus, the lexical units in each lexical unit are lexical units that the electronic device has generated an integer number of times through the multi-head prediction module.

[0088] For example, assuming that 4 new heads are added to the multi-head prediction module, that is, the multi-head prediction module includes 4+1=5 heads, then the number of truncations contained in each truncation can also be 5.

[0089] Optionally, in this embodiment of the application, for the first byte group in at least one byte group, the electronic device can use a multi-head prediction module to determine the probability of each second byte group being the first byte group in the first byte group based on the first prompt word, and take the second byte group with the highest probability as the first byte group in the first byte group.

[0090] Optionally, in the embodiments of this application, for at least one word group other than the first word group, the electronic device can use a multi-head prediction module to determine the first probability of each second word as the first word in the word group based on the last word in the previous word group, and take the second word with the highest probability as the first word in the word group.

[0091] Step 202b2: The electronic device, through the multi-head prediction module, determines the second probability of each second word element as the j-th word element in the i-th word element group based on the first prompt word, and takes the second word element with the highest second probability among the N second word elements and associated with the (j-1)-th word element in the i-th word element group as the j-th word element in the i-th word element group.

[0092] In this embodiment of the application, j is a positive integer greater than 1.

[0093] In this embodiment of the application, the aforementioned associations include semantic, syntactic, contextual, or logical relationships between the generated lexical units. Specifically:

[0094] (1) The generated lexical units should be semantically related to the previous lexical unit. For example, if the previous lexical unit is "interview", then the next lexical unit of "interview" may be "time" or "of". These lexical units are semantically related to "interview" and form a coherent phrase or sentence.

[0095] (2) The generated lexical units need to follow the grammatical rules of the language to ensure the correctness and fluency of the sentence. For example, if the previous lexical unit is a noun, the next lexical unit may be a verb or an adjective to maintain the grammatical structure of the sentence.

[0096] (3) The generated lexical units should take into account the preceding context information to ensure that the generated content is consistent with the preceding content. For example, if the preceding lexical unit mentions a specific topic or object, then the subsequent lexical unit should be consistent with that topic or object.

[0097] (4) The generated lexical units may need to be logically related to each other. For example, if the previous lexical unit is "because", then the next lexical unit may need to be "so" or "therefore" to form a logically coherent sentence.

[0098] In this way, by taking into account the relationships between these lexical units, electronic devices can generate more natural and coherent text that conforms to the expression habits of human language.

[0099] Optionally, in this embodiment, after determining the first word element in the first word group, the electronic device can, based on the first prompt word, continue to determine the probability of each second word element being the second word element in the first word group, and select the second word element with the highest probability and associated with the first word element in the first word group as the second word element in the first word group. Simultaneously, the electronic device can, based on the first prompt word, continue to determine the probability of each second word element being the third word element in the first word group, and select the second word element with the highest probability and associated with the second word element in the first word group as the third word element in the first word group. And so on. For each word group, the electronic device can, through a multi-head prediction module, simultaneously determine all word elements in the word group with the highest probability of occurrence and associated with each other from N second word elements.

[0100] For example, assuming the multi-head prediction module has 5 heads and each tuple contains 5 lexical units, taking the first prompt word as "self-introduction during an interview" as an example, the electronic device calculates the probability that each second lexical unit is the first lexical unit in the first tuple based on the first prompt word. Assume the N second lexical units include: "respectfully," "of," "everyone," "interviewer," "hello everyone," "I am," "Zhang San," "graduated from," "computer science," "major," "thank you very much," "company," "give me," "this time," "opportunity," "please allow me," "share," "my experience," "background," etc. The electronic device can use the multi-head prediction module to simultaneously calculate the probability of each lexical unit in the N second lexical units as the first lexical unit in the first tuple based on the first prompt word "self-introduction during an interview."

[0101] (1) The first token in the first token group:

[0102] The electronic device uses a multi-head prediction module to calculate the probability of each second token as the first token based on the first prompt "Self-introduction during an interview".

[0103] Suppose the following probabilities are obtained:

[0104] P(Respect) = 0.30

[0105] P(of) = 0.05

[0106] P(ladies and gentlemen) = 0.20

[0107] P(interviewer) = 0.25

[0108] P(Hello everyone) = 0.10

[0109] P(Please allow me) = 0.05

[0110] P(share) = 0.05

[0111] The electronic device selects the token with the highest probability according to the probability. Among them, P(Respect) = 0.30 is the highest, so the first token is "Respect".

[0112] (2) The second token in the first token group:

[0113] The electronic device uses a multi-head prediction module to calculate the probability of each second token as the second token in the first token group according to the first prompt "Self-introduction during an interview". At this time, the first token is "interviewer".

[0114] Suppose the following probabilities are obtained:

[0115] P(of) = 0.40

[0116] P(ladies and gentlemen) = 0.25

[0117] P(Hello everyone) = 0.20

[0118] P(Respect) = 0.05

[0119] P(Please allow me) = 0.05

[0120] P(share) = 0.05

[0121] The electronic device selects the token with the highest probability according to the probability. Among them, P(of) = 0.40 is the highest, so the second token is "of".

[0122] (3) The third token in the first token group:

[0123] The electronic device uses a multi-head prediction module to calculate the probability of each second token as the third token in the first token group according to the first prompt word "Self-introduction during an interview". At this time, the second token is "的".

[0124] Suppose the following probabilities are obtained:

[0125] P(各位) = 0.50

[0126] P(大家好) = 0.30

[0127] P(尊敬) = 0.10

[0128] P(请允许我) = 0.05

[0129] P(分享一下) = 0.05

[0130] The electronic device selects the token with the highest probability according to the probability. Among them, in this example, P(各位) = 0.50 is the highest, so the third token is "各位".

[0131] (4) The fourth token in the first token group:

[0132] The electronic device uses a multi-head prediction module to calculate the probability of each second token as the fourth token in the first token group according to the first prompt word "Self-introduction during an interview". At this time, the third token is "各位".

[0133] Suppose the following probabilities are obtained:

[0134] P(尊敬) = 0.20

[0135] P(面试官) = 0.40

[0136] P(大家好) = 0.10

[0137] P(请允许我) = 0.10

[0138] P(分享一下) = 0.20

[0139] Select the token with the highest probability according to the probability.

[0140] In this example, P(面试官) = 0.40 is the highest, so the fourth token is "面试官".

[0141] (5) The fifth token in the first token group:

[0142] The electronic device uses a multi-head prediction module to calculate the probability of each second token as the fifth token in the first token group according to the first prompt word "Self-introduction during an interview". At this time, the fourth token is "大家好".

[0143] Assume the following probabilities are obtained:

[0144] P(Please allow me) = 0.20

[0145] P(Share this) = 0.10

[0146] P(Hello everyone) = 0.40

[0147] P(Zhang San) = 0.30

[0148] Based on probability, select the word with the highest probability.

[0149] In this example, P(Hello everyone) = 0.40 is the highest, so the 5th word is "Hello everyone".

[0150] The first word tuple generated by the electronic device is: “Respected,” “of,” “Everyone,” “Interviewer,” “Hello everyone.” Then, the electronic device can use a multi-head prediction module to calculate the probability of each of the N second word tuples, based on the last word tuple “Hello everyone,” in the second word tuple. For example, the five words in the second word tuple could be: “I am,” “Zhang San,” “Graduated from,” “Computer Science,” “Major.” Similarly, the electronic device can continue to generate multiple word tuples, forming at least one first word tuple in sequence. For example, “Respected interviewers, hello everyone. I am Zhang San, a graduate of Computer Science. During my university years, I participated in several projects and received awards for excellence. I believe my abilities can contribute to your company.”

[0151] In this way, electronic devices can generate the probability distributions of multiple subsequent words in parallel through a multi-head prediction module, thereby determining multiple words simultaneously and improving the efficiency of word determination.

[0152] Optionally, in this embodiment of the application, the text generation method provided in this embodiment of the application further includes the following step 301.

[0153] Step 301: After determining the kth word in the i-th word group, if the number of determined first word elements is greater than or equal to the number threshold, the electronic device uses the multi-head prediction module to determine the third probability of each second word element as the k+1th word element in the i-th word group based on the first prompt word and the first text, and takes the second word element with the highest third probability among the N second word elements and associated with the k-th word element as the k+1th word element.

[0154] In this embodiment, k is a positive integer.

[0155] In this embodiment of the application, in order for the large model to generate the first text, the electronic device needs to input the token from the first text into the large model, so that the large model can generate the specified text fragment based on the input token. Therefore, as Figure 5 As shown, this method, in addition to encoding the original input at the model input layer, also uses an embedding layer to encode the first text, thus obtaining a vector representation of the first text. Based on the original large model, this method adds an activation classifier C and a connection layer M. The input to the activation classifier C is the vector of the first text, and the output is either 0 or 1. An output of 0 indicates that the model does not need the information of the first text in the current decoding step, while an output of 1 indicates that the information of the first text is needed. The input to the connection layer M is the vector of the first text multiplied by the output of the activation classifier C (the dimension remains the same as the dimension of the first text vector). The structure of the connection layer M can be a simple matrix or a transformer layer; a suitable structure can be chosen during training, as long as the output dimension is the same as the vector of the last layer of the large model. When the output of the activation classifier C is 0, it means that all its inputs are 0, and the large model will not use any information related to the first text. When the output of the activation classifier C is 1, the dimension of the vector of the first text can be transformed into the dimension of the vector of the last layer of the large model through the trained connection layer M, and the two are added together to update the vector of the last layer, so that the large model generates the first text in the subsequent process of determining the word units.

[0156] Optionally, in the embodiments of this application, during the process of the electronic device determining at least one first word, the electronic device may record the number of determined word elements.

[0157] Optionally, in this embodiment, if the number of tokens determined by the electronic device is less than a threshold, the electronic device can determine that new text content needs to be generated. The electronic device can then set the output of the activation classifier C to 0, making the input of the connection layer M the product of the first text vector and 0, resulting in a vector with the same dimension as the first text vector, where all elements are 0. After the connection layer M obtains the vector with all zeros, when the electronic device adds this vector to the last layer vector of the large model using the connection layer M, it can avoid affecting the last layer vector of the large model. Therefore, the electronic device can continue with subsequent steps of text generation, using the large model to generate new tokens based on the new context and input. At this point, the generated content will be unrelated to the first text, thus ensuring that the generated text is sufficiently novel.

[0158] It should be noted that the large model generates the sampling probabilities of all words at the end of each inference. During inference, various sampling methods can be selected according to the specific task. These methods can be called sampling strategies. For example, Top-K Sampling can keep only the top K most likely tokens and then randomly sample from these K tokens. Another example is Top-p Sampling, which can keep only tokens with a cumulative probability greater than a certain threshold and then randomly sample from this set.

[0159] Optionally, in this embodiment, if the number of tokens determined by the electronic device is less than a threshold, the electronic device can determine that new text content needs to be generated. The electronic device can then calculate the frequency of each token in the first answer and, during model sampling, apply a specific penalty coefficient strategy based on the token frequency distribution to reduce the probability of the corresponding token being selected (this may exclude single-character tokens and punctuation). Since the most frequently occurring token is highly likely to be strongly related to the topic, the electronic device can sort the tokens in the first answer from highest to lowest frequency, applying the highest penalty coefficient to the token with the median frequency, and decreasing the penalty coefficient for the remaining tokens according to their frequency. The penalty coefficient can be used as a hyperparameter for testing and adjustment based on the specific task, so that the adjusted sampling strategy makes the text generated by the large model more consistent with the requirements of the first answer.

[0160] For example, suppose the model obtains the token and its corresponding probability [interview: 0.45, in: 0.31, of course: 0.18, respected: 0.08,...] when determining the token in one instance. Suppose the first answer is: "A self-introduction during an interview is a key step in leaving a good first impression on the interviewer. A good self-introduction should be concise and to the point, while fully showcasing your strengths and personality. Below is a basic self-introduction template, which you can adjust according to your own situation: [Opening] Respected interviewers, hello everyone! I am [your name], graduated from [your school], majoring in [your major]. Thank you very much to [company name] for giving me this interview opportunity, allowing me to showcase myself to you." Electronic devices can count the first answer. The token frequencies are calculated, with the highest frequency being 4, the lowest being 1, and the median being 2 and 3. Assuming a penalty coefficient of 0.8, to improve the distinctiveness of newly generated text, the penalty coefficient for tokens appearing 2 and 3 times in the frequency table is 0.8*0.8, and the penalty coefficient for tokens appearing 1 and 4 times is also 0.8. The adjusted token probability distribution is [interview: 0.36, at: 0.31, of course: 0.08, respect: 0.064,...]. The electronic device can then normalize the token probabilities and sample according to the modified probabilities. Thus, by adjusting the penalty coefficient, the probability of the token "interview" decreases, and the model is more likely to generate tokens that differ from the previous answer, such as "at".

[0161] Optionally, in this embodiment, when the number of tokens determined by the electronic device is greater than or equal to a threshold, the electronic device can determine that it needs to find an opportunity to insert the first text. The electronic device can then set the output of the activation classifier C to 1, making the input of the connection layer M the product of the vector of the first text and 1, thus obtaining the vector of the first text. After the connection layer M obtains the vector of the first text, the electronic device can use the connection layer M to add the vector of the first text to the last layer vector of the large model, thereby influencing the last layer vector of the large model and allowing the electronic device to generate the first text more favorably through the large model. At this time, the generated content will be influenced by the first text, allowing the large model to output the first text at an appropriate position.

[0162] Step 203: The electronic device outputs a second answer based on at least one first word and the first text using a text generation model.

[0163] In this embodiment, the second answer is a new answer obtained by the electronic device through a text generation model, which merges at least one first word element with the first text. The second answer retains the text portion that satisfies the user, while generating new content based on the context; therefore, the second answer is more in line with the user's needs.

[0164] Optionally, in the embodiments of this application, combined with Figure 1 ,like Figure 6 As shown, step 203 can be implemented through steps 203a and 203b below.

[0165] Step 203a: The electronic device merges the first word and the first text based on the multi-head prediction module of the text generation model to obtain the first text.

[0166] Optionally, in the embodiments of this application, during the process of generating at least one first word element, the electronic device can continuously generate the first word element through the multi-head prediction module of the text generation model until the generated first word element is associated with the text content of the first text, so that the electronic device can determine the position of the first text in at least one first word element.

[0167] Optionally, in embodiments of this application, the aforementioned at least one first word element is divided into at least one word element group, and each word element group includes a portion of the word elements from at least one first word element. For example, in combination with... Figure 6 ,like Figure 7 As shown, step 203a can be implemented through steps 203a1 and 203a2 as described below.

[0168] Step 203a1: The electronic device uses a multi-head prediction module to determine the first a third word units of the first text as the fourth probability of word units in the bth word unit group.

[0169] In the embodiments of this application, a is a positive integer and b is a positive integer.

[0170] Optionally, in this embodiment, 'a' can be the number of heads in the multi-head prediction module, i.e., n+1, or 'a' can be less than the number of heads in the multi-head prediction module. Thus, the electronic device can simultaneously predict the probability that the first 'a' third-order words in the first text are each word in the b-th word group, and then calculate the fourth probability using these probabilities.

[0171] Optionally, in the embodiments of the present application, the electronic device may determine the probabilities of the N second tokens as each token in the b-th token group respectively, and then the electronic device may find the tokens in the first text from the N second tokens, so as to know the probabilities of these tokens as the tokens corresponding to the positions of the tokens in the first text in the b-th token group, and then multiply these probabilities to calculate the fourth probability that the first a third tokens of the first text are tokens in the b-th token group.

[0172] Optionally, in the embodiments of the present application, for the first token in the b-th token group, the electronic device may determine the probability that each token in the N second tokens is the first token in the b-th token group, so as to know the probability that the first token in the first text is the first token in the b-th token group; for the second token in the b-th token group, the electronic device may determine the probability that each token in the N second tokens is the second token in the b-th token group, so as to know the probability that the second token in the first text is the second token in the b-th token group. And so on, the electronic device may know the probabilities that the first a tokens in the first text are the a-th tokens in the b-th token group respectively. Then, the electronic device may multiply these a probabilities to calculate the fourth probability.

[0173] Exemplarily, as Figure 8 shown, assume that a is 5. For the first token in the b-th token group, assume that the first text 12 is "Dear interviewers, hello! I am [your name], graduated from [your school], and my major is [your major].", then the electronic device may calculate the first 5 tokens in the first text 12, that is, "Dear", "of", "distinguished", "interviewers", "hello" as the probabilities of the first 5 tokens in the b-th token group respectively. Assume that the probability calculated by the electronic device that "Dear" is the first token in the b-th token group is 0.71, the probability that "of" is the second token in the b-th token group is 0.26, the probability that "distinguished" is the second token in the b-th token group is 0.67, the probability that "interviewers" is the second token in the b-th token group is 0.43, and the probability that "hello" is the second token in the b-th token group is 0.74. Then the electronic device may calculate the probability that "Dear", "of", "distinguished", "interviewers", "hello" are simultaneously the first 5 tokens in the b-th token group as P("Dear") * P("of") * P("distinguished") * P("interview") * P("ers") = 0.71 × 0.26 × 0.67 × 0.43 × 0.74 = 0.039, that is, the fourth probability.

[0174] Step 203a2: When the fourth probability is greater than or equal to the probability threshold, the electronic device merges according to the generated first token and the first text through the multi-head prediction module to obtain the second text.

[0175] Optionally, in this embodiment, the probability threshold can be the default value of the electronic device or a value preset by the user. For example, the probability threshold can be 0.3, 0.4, 0.5, etc. The specific threshold can be determined according to actual usage requirements, and this embodiment does not impose any limitations.

[0176] Optionally, in this embodiment of the application, if the fourth probability is greater than or equal to the probability threshold, and the electronic device determines that the position of the current token is a suitable position to be placed in the first text, the electronic device can use the multi-head prediction module to merge the first text after the generated first word.

[0177] For example, assuming a probability threshold of 0.3, and the first text is "Dear interviewers, hello everyone! I am [your name], graduated from [your school], majoring in [your major]." Assuming the electronic device calculates that the probability of the first 5 tokens "Dear," "of," "everyone," "interviewer," and "hello everyone" in the first text being simultaneously the first 5 tokens in the b-th byte group is 0.039, then the electronic device can determine that the current position is suitable for placement in the first text. Assuming the generated first byte is: "A self-introduction during an interview is a crucial step in leaving a good first impression on the interviewer. A good self-introduction..." A good self-introduction should be concise yet showcase your strengths and personality. Below is a basic self-introduction template, which you can adjust according to your own situation: "The electronic device can then merge this first text after the already generated first word unit, resulting in: "A self-introduction during an interview is a crucial step in making a good first impression on the interviewer. A good self-introduction should be concise yet showcase your strengths and personality. Below is a basic self-introduction template, which you can adjust according to your own situation: Dear interviewers, good afternoon! I am [your name], graduated from [your school], majoring in [your major]."

[0178] In this way, electronic devices can calculate the probability that a token is the first word element in the first text, and then calculate the probability of the first text at the position of each token. Only when the generated text and the first text have a high degree of semantic matching will they be merged, thereby improving the accuracy of the merging position and enhancing the coherence of the merged text.

[0179] Step 203b: The electronic device outputs the second answer based on the second text through the multi-head prediction module.

[0180] Optionally, in this embodiment, after the user selects the first text in the first answer, the electronic device can detect information in the first answer, including the number of the first text and its corresponding token count, and the number of other texts in the first answer besides the first text and their corresponding token counts. Based on this information and the first prompt word, the electronic device can determine a generation requirement list, which is used by the electronic device to process the first answer. The electronic device can read and judge the generation requirement list in the order of the list, and generate the corresponding text according to the generation requirements in the generation requirement list.

[0181] For example, combined Figure 2 ,like Figure 9 As shown, after the user marks the first text 12, first text 13, and first text 14 in the first answer 11, the mobile phone can determine the generation requirement list 15. This generation requirement list includes the first prompt word and 7 generation requirements. The 7 generation requirements are: regenerate text fragment-1 (token count: 42), retain text fragment-1 (token count: 42), regenerate text fragment-2 (token count: 53), retain text fragment-2 (token count: 31), regenerate text fragment-3 (token count: 105), retain text fragment-3 (token count: 34), and regenerate text fragment-4 (token count: 28). The content of the generation requirement list 15 is as follows:

[0182] {"User input question": "Self-introduction during the interview",}

[0183] "Generate a list of requirements":[

[0184] "Regenerate Text Fragment - 1 (token count: 42): A self-introduction during an interview is crucial for making a good first impression on the interviewer. A good self-introduction should be concise yet fully showcase your strengths and personality. Below is a basic self-introduction template that you can adjust according to your own situation: [Beginning]",

[0185] "Preserved text fragment - 1 (token count: 42): Dear interviewers, good afternoon! I am [your name], a graduate of [your school], majoring in [your major]. Thank you very much to [company name] for giving me this interview opportunity, allowing me to showcase myself to you."

[0186] "Regenerate Text Fragment - 2 (token count: 53): [Education Background] During my university years, I systematically studied [relevant courses] and actively participated in [relevant projects or activities]. Through this learning and practice, I not only mastered solid professional knowledge but also cultivated strong learning abilities and teamwork spirit. [Work Experience] (If you have relevant work or internship experience)"

[0187] “Preserved text fragment - 2 (token count: 31): During my internship at [internship company], I was mainly responsible for [specific work content], during which I learned [skills acquired] and achieved [specific results].”

[0188] "Regenerated Text Fragment - 3 (token count: 105): These experiences have given me a deeper understanding of [Job Title] and solidified my career development direction in this field. [Personal Strengths] I believe I possess the following strengths: First, I have strong [a specific skill or quality], enabling me to quickly adapt to new environments and tasks; second, I am good at communication and teamwork, able to effectively collaborate with colleagues from diverse backgrounds; finally, I am conscientious, detail-oriented, and strive for excellence. [Expectations for Future Work] I am passionate and excited about [Company Name] and [Job Title]."

[0189] "Preserved text fragment - 3 (token count: 34): I believe my professional background and work experience can bring new vitality to the team. If I am fortunate enough to join [Company Name], I will work hard, continuously improve myself, and contribute my strength to the company's development."

[0190] "Regenerate Text Fragment - 4 (token count: 28): [End] Thank you again to all the interviewers for this opportunity. I look forward to further communication with you all. Thank you! I hope this template is helpful to you. Best of luck with your interview!"

[0191] }

[0192] The phone can read and judge the generation requirement list in the order of the list. Based on the regenerated text fragment -1 (token count: 42) in generation requirement list 15, it starts regenerating text, resulting in the newly generated text 16: "In an interview, self-introduction is a very important part. A proper and brilliant self-introduction can leave a good first impression on the interviewer. Below is a template for a self-introduction; you can adjust it according to your own situation:". Furthermore, the phone can determine whether the first text 12 can be placed based on the retained text fragment -1 (token count: 42) in generation requirement list 15, and then merge the first text 12 after the newly generated text 16.

[0193] Then, the phone can start regenerating text based on the regenerated text fragment -2 (token count: 53), resulting in the newly generated text 17: "Personal Background: I graduated from [your university], majoring in [your major]. During my time at university, I achieved excellent grades and focused on learning in the field of [the company I'm interviewing with], and I have internship experience in related industries." Furthermore, the phone can determine whether the first text 13 can be placed based on the retained text fragment -2 (token count: 31) in the generation requirement list 15, and then merge the first text 13 into the newly generated text 17.

[0194] Following this logic, the phone generates a new text 18 based on the regenerated text fragment -3 (token count: 105) and merges the first text 14 into the new text 18. Finally, it generates a new text 19 based on the regenerated text fragment -4 (token count: 28), thus obtaining the second answer 20.

[0195] In this way, electronic devices can merge the generated first word units with the first text through the multi-head prediction module, ensuring that the generated first text not only contains the content that the user wants to retain, but also remains consistent with the context, thereby making the generated text more semantically coherent and natural.

[0196] In this embodiment, the electronic device can adjust the output answer according to the text requirements selected by the user. By adjusting the structure of the large model, the two-stage inference decoding strategy and the multi-head generation mechanism, the large model can retain the user-specified text fragment in the corresponding appropriate position in the generation of new answers. At the same time, the content generated by the other text fragments is diversified, which improves the difference between the answer and the previous answer, thereby improving user satisfaction.

[0197] In this embodiment, the electronic device is universally applicable to various text generation tasks such as text rewriting, transcribing creative copy, writing, and copywriting. The solution retains text fragments strictly according to their position in the original answer. Furthermore, the user can specify any position of the text fragment in the new answer, which can be achieved by adding training data to optimize the activation classifier.

[0198] This application provides a text generation method. Since the electronic device can generate at least one first word element based on the first prompt word and the first answer, that is, generate new text content based on the first prompt word and the answer generated based on the first prompt word, and then output a second answer through the text generation model based on at least one first word element and the first text, that is, combine the new text content with the part of the answer generated based on the first prompt word that satisfies the user to obtain the second answer. Thus, while generating a new answer that is different from the first answer based on the first prompt word, the part that satisfies the user is retained, which increases the probability of generating a user-satisfied answer, thereby improving the flexibility of the text generation method.

[0199] Optionally, in the embodiments of this application, combined with Figure 1 ,like Figure 10 As shown, prior to step 202 above, the text generation method provided in this application embodiment further includes steps 401 to 404 as described below.

[0200] Step 401: The electronic device acquires the first sample prompt word and the first sample answer.

[0201] In this embodiment of the application, the first sample answer is generated based on the first sample prompt word, and the first sample answer includes the first sample text.

[0202] Optionally, in this embodiment, the first sample prompt word can be a sufficiently large number of prompt words, and the first sample answer can be a sample answer generated and labeled for each prompt word in the first sample text. For example, there are 5,000 first sample prompt words and 5,000 first sample answers, with a one-to-one correspondence between the first sample prompt words and the first sample answers.

[0203] It should be noted that the specific number of first sample prompt words and first sample answers can be determined according to the actual needs during the model training process, and this application does not impose any restrictions here.

[0204] Optionally, in this embodiment of the application, the electronic device can construct a dataset to train the parameters of the activation classifier C and the connection layer M. The method for constructing the dataset is as follows:

[0205] (1) First, input a certain number of prompts into the large model and record the output of the large model to construct a batch of training data. For example, for the input of "global climate change", we can obtain ["Input": "global climate change", "Output": "Global climate change refers to the long-term changes in the Earth's climate system caused by human activities and natural factors. These changes may manifest as rising temperatures, changes in precipitation patterns, and rising sea levels. Climate change has a profound impact on ecosystems, economies, and societies, leading to frequent extreme weather events and affecting agricultural production and water resource management. Countries are working hard to address the challenges of climate change through emission reduction and sustainable development strategies."]

[0206] (2) Then, the electronic device can randomly retain a portion of the text fragments from the answer output by the large model, and then randomly modify the remaining text fragments of the answer. For example, it can use various processing methods such as abbreviation and rewriting to construct corresponding training data for the example mentioned above:

[0207] ["Enter": "Global climate change",

[0208] "Token count for each text fragment": [Newly generated text fragment (token count - 35), (Specified text fragment: token count - 35), (Newly generated text fragment: token count - 17)],

[0209] The specified text snippet states, "Climate change has profound impacts on ecosystems, economies, and societies, leading to more frequent extreme weather events and affecting agricultural production and water resource management."

[0210] "Output": "Global climate change refers to long-term changes in the Earth's climate system caused by human activities and natural factors. These changes may manifest as rising temperatures, altered precipitation patterns, and rising sea levels. Climate change has profound impacts on ecosystems, economies, and societies, leading to more frequent extreme weather events and affecting agricultural production and water resource management. Countries are striving to address the challenges of climate change through emissions reduction and sustainable development strategies."

[0211] Optionally, in this embodiment of the application, the electronic device may randomly initialize the parameters when training the parameters of the activation classifier C and the connection layer M, and determine whether the activation classifier C and the connection layer M need to be used based on the current decoding position.

[0212] Optionally, in this embodiment, the electronic device can train the activation classifier C and the connection layer M in two stages, distinguishing them by the number of tokens for each text fragment recorded in the requirement list. The specific training method is as follows:

[0213] Exemplarily, assume that the token length of the newly generated text segment is n, and assume that the preset threshold is 2. The electronic device needs to determine whether to generate a certain length of new text through the model first. Therefore, when the token step corresponding to the model < n / 2, the electronic device can set the output of the activation classifier to 0, so that the output result of the connection layer M is all 0, making the result unchanged after the output result is superimposed and summed with the last layer vector of the model. That is, when the current model is decoding, it does not need to specify the information of the token sequence of the text, and thus directly generates new text by the model. Assume that the number of tokens in the currently newly generated text segment is 35, and the current model input is "Global climate change: Global climate change is". The token length generated by the model ("Global", "climate", "change", "is") is 4, which is less than 35 / 2. Therefore, the electronic device can set all the parameters of the connection layer M to 0, and the model samples and generates the token "impact" at the current step.

[0214] When the token step corresponding to the model >= n / 2, at this time, the electronic device can enable the activation classifier C and the connection layer M through the model, and determine whether to input the vector of the specified text segment at the current position by training the activation classifier C. If the electronic device determines that the vector of the specified text segment is input at the current position, the electronic device can multiply the encoded vector of the specified text segment by the connection layer and then add it to the last layer vector parameter, so that the model can accept the subsequent token sequence information during decoding and output the specified text segment at the appropriate position. Assume that the current input is "Global climate change: Global climate change is caused by long-term changes in the Earth's climate system due to human activities and natural factors. These changes may manifest as rising temperatures, altered precipitation patterns, sea-level rise, etc.". The currently generated token length is 35, which is greater than 35 / 2. Through training iterations, at this time, the electronic device can determine through the activation classifier C that the model can accept new information at this position. Therefore, the electronic device can use the Embedding layer to encode "Climate change has a profound impact on ecosystems, economies, and societies, leading to frequent extreme weather events and affecting agricultural production and water resource management." as the vector of the specified text segment, then use the connection layer M to add it to the last layer vector representation, and finally perform prediction through the LM head. Affected by the vector of the specified text segment, the model will tend to output the retained text segment and output the token "impact" at the current step.

[0215] In this way, the electronic device can update the parameters of the activation classifier C and the connection layer M of the large model. Through such training, the model can learn to retain the given text at the appropriate position and generate new text at the remaining positions when given text information, and the model output is complete and fluent.

[0216] Step 402: The electronic device inputs the first sample prompt word and the first sample answer into the preset model, and generates at least one first sample word based on the first sample prompt word and the first sample answer through the preset model.

[0217] Optionally, in the embodiments of this application, the structure of the preset model is roughly the same as that of the text generation model. For details, please refer to the description of the above embodiments. The embodiments of this application will not be repeated here.

[0218] Optionally, in the embodiments of this application, combined with Figure 10 ,like Figure 11 As shown, step 402 above can be implemented by steps 402a to 402c below.

[0219] Step 402a: The electronic device inputs the first sample prompt word and the first sample answer into the preset module of the preset model, and obtains N second sample words based on the first sample answer through the preset module.

[0220] In this embodiment of the application, the above-mentioned N second sample lexical units are N possible candidate lexical units predicted by the preset model based on the text content of the first sample answer.

[0221] Optionally, in the embodiments of this application, the configuration of the above-mentioned preset module is roughly the same as that of the above-mentioned multi-head prediction module. For details, please refer to the description of the above embodiments. The embodiments of this application will not be repeated here.

[0222] Step 402b: The electronic device determines at least one first sample word from the N second sample words based on the first sample prompt word and N second sample words through a preset module.

[0223] In this embodiment of the application, the aforementioned at least one first sample word is a sample word related to the first sample prompt word determined by the electronic device from N candidate second sample words.

[0224] Step 402c: The electronic device trains the preset module based on at least one first sample word and at least one target word to obtain a multi-head prediction module.

[0225] Optionally, in this embodiment, the electronic device can add n add heads to the original LMHead in the last hidden layer of the large model to predict subsequent tokens. The structure and parameters of the added heads are consistent with the original LM Head. The first add head predicts the token after the next token, and so on for subsequent add heads. During training, the original model parameters are frozen, and only the parameters of the add heads (i.e., the multi-head prediction module mentioned above) are trained and updated. This modification enables the large model to obtain the probability distribution of the next n+1 tokens in one inference. For example, if the large model adds 4 additional add heads, the model training will enable the large model to generate the probability distribution of the next 5 tokens as much as possible in each inference. For the input "Global climate change: Global climate change is", the token predicted by the original LM head is "impact", and the tokens predicted by the add heads are the subsequent "of", "one", "factor", and "cause".

[0226] Optionally, in this embodiment of the application, the electronic device may calculate a first loss value based on at least one first sample word and at least one target word.

[0227] Optionally, in the embodiments of this application, the first loss value can characterize at least one of the following differences between the first sample word and at least one target word: semantic feature difference, contextual consistency difference, and degree of matching with the first sample prompt word.

[0228] Optionally, in this embodiment of the application, the electronic device can adjust the module parameters in the preset module based on the first loss value to obtain the multi-head prediction module.

[0229] It should be noted that the smaller the difference between at least one first sample word and at least one target word, the closer the at least one first sample word is to the answer required by the user, and the smaller the first loss value.

[0230] Optionally, in this embodiment of the application, the electronic device may use a backpropagation algorithm to iteratively update the parameters in the preset module based on the first loss value until convergence, so as to train a multi-head prediction module.

[0231] In this way, the electronic device can continuously calculate the loss value using at least one first sample word and at least one target word, and adjust the module parameters of the preset module according to the loss value, thereby training the preset module into a multi-head prediction module.

[0232] Step 403: The electronic device outputs the second sample answer based on at least one first sample word and the first sample text using a preset model.

[0233] In this embodiment of the application, the second sample answer is the answer obtained by the electronic device through a text generation model, which merges at least one first sample word with the first sample text.

[0234] Step 404: The electronic device trains the preset model based on the second sample answer and the target answer to obtain the text training model.

[0235] Optionally, in this embodiment of the application, the electronic device can calculate a second loss value based on the second sample answer and the target answer.

[0236] Optionally, in this embodiment of the application, the second loss value can characterize at least one of the following differences between the second sample answer and the target answer: semantic feature difference, contextual consistency difference, and difference in the degree of matching with the first sample prompt word.

[0237] Optionally, in this embodiment of the application, the electronic device may adjust the model parameters in the preset model based on the second loss value to obtain a text generation model.

[0238] It should be noted that the smaller the difference between the second sample answer and the target answer, the closer the second sample answer is to the answer required by the user, and the smaller the second loss value.

[0239] Optionally, in this embodiment of the application, the electronic device may use a backpropagation algorithm based on the second loss value to iteratively update the model parameters in the preset model until convergence, so as to train a text generation model.

[0240] Optionally, in this embodiment, the electronic device can add an activation classifier C, a connection layer M, and an add heads module to the original structure of the large model. When training and updating the model parameters, the parameters of the original model are frozen, and only the parameters of these three modules are updated, thus decoupling the model structure while avoiding affecting the performance of the original large model.

[0241] In this way, the electronic device can continuously calculate the loss value using the second sample answer and the target answer, and adjust the model parameters of the preset model according to the loss value, thereby training the preset model into a text generation model.

[0242] This application provides a text generation method. Figure 12 A flowchart of a text generation method provided in an embodiment of this application is shown, which can be applied to electronic devices. Figure 12 As shown, the text generation method provided in this application embodiment may include the following steps 10 to 16.

[0243] Step 10: The electronic device receives the user's input of the first text in the first answer.

[0244] Step 11: Generate a list of requirements for electronic devices.

[0245] Optionally, in this embodiment of the application, the electronic device may mark the first text in the first answer and the non-first text in the first answer, and calculate the number of tokens for each text fragment in the first text and the non-first text, and then assemble these text fragments into a request list in the order in the first answer.

[0246] Step 12: The electronic device determines whether the generated requirement list is empty.

[0247] If the generated requirement list is not empty, the electronic device performs step 13 as follows; if the generated requirement list is empty, the electronic device performs step 16 as follows.

[0248] Step 13: The electronic device determines whether to regenerate the current text segment.

[0249] If the electronic device determines that the current text segment has been regenerated, the electronic device performs step 14 below; if the electronic device determines that the current text segment has not been regenerated, the electronic device performs step 15 below.

[0250] Optionally, in this embodiment of the application, the electronic device may process each text fragment sequentially according to the order of the text fragments in the generation requirements list.

[0251] Optionally, in this embodiment of the application, for non-first text, the electronic device can generate new text fragments; for first text, the electronic device can determine a suitable position for splicing the first text during the generation of the first text, and splice the first text to the end of the newly generated text at that position.

[0252] Step 14: The electronic device uses a text generation model to generate new text fragments.

[0253] Step 15: The electronic device splices the first text.

[0254] Optionally, in this embodiment of the application, if the first text fragment in the generated requirement list is the first text, the electronic device can directly concatenate the first text at the position of the first token.

[0255] Step 16: The electronic device outputs the generated text as the second answer.

[0256] Optionally, in this embodiment of the application, after executing steps 13, 14 and 15 multiple times, the electronic device can process all text fragments in the generation requirement list according to their corresponding processing methods, and finally obtain a second answer containing the first text and the newly generated text.

[0257] Each of the above-described method embodiments, or various possible implementations of each method embodiment, can be executed individually or in combination of any two or more. The specific implementation can be determined according to actual usage requirements, and this application does not impose any restrictions on this.

[0258] The text generation method provided in this application can be executed by a text generation device. This application uses a text generation device executing the text generation method as an example to illustrate the text generation device provided in this application.

[0259] Figure 13 A schematic diagram of a possible structure of a text generation apparatus involved in some embodiments of this application is shown. For example... Figure 13 As shown, the text generation device 70 may include an acquisition module 71 and an execution module 72.

[0260] The aforementioned acquisition module 71 is used to acquire the first prompt word and the first answer. The first answer is generated based on the first prompt word and includes the first text.

[0261] The execution module 72 is used to input the first prompt word and the first answer obtained by the acquisition module 71 into the text generation model, and generate at least one first word element based on the first prompt word and the first answer through the text generation model.

[0262] The aforementioned execution module 72 is also used to output a second answer based on at least one first word and the first text through a text generation model.

[0263] In one possible implementation, exemplarily, combining Figure 13 ,like Figure 14 As shown, the text generation apparatus provided in this application embodiment further includes a determining module 73. The execution module 72 is specifically used to input the first prompt word and the first answer obtained by the acquisition module 71 into the multi-head prediction module of the text generation model, and to obtain N second word elements based on the first answer through the multi-head prediction module, where N is a positive integer. The determining module 73 is used to determine at least one first word element from the N second word elements through the multi-head prediction module based on the first prompt word obtained by the acquisition module 71 and the N second word elements obtained by the execution module 72.

[0264] In one possible implementation, the aforementioned at least one first word element is divided into at least one word element group, and each word element group includes a portion of the words in the at least one first word element. The determining module 73 is specifically configured to: for the i-th word element group in the at least one word element group, determine the first probability of each second word element as the first word element in the i-th word element group based on the first prompt word obtained by the acquisition module 71 using the multi-head prediction module, and select the second word element with the highest first probability among the N second word elements obtained by the acquisition module 71 as the first word element in the i-th word element group. Furthermore, the multi-head prediction module determines the second probability of each second word element as the j-th word element in the i-th word element group based on the first prompt word obtained by the acquisition module 71, and selects the second word element with the highest second probability among the N second word elements obtained by the acquisition module 71, which is associated with the (j-1)-th word element in the i-th word element group, as the j-th word element in the i-th word element group. Here, i is a positive integer, and j is a positive integer greater than 1.

[0265] In one possible implementation, the determining module 73 is further configured to, after determining the k-th word element in the i-th word element group, if the number of determined first word elements is greater than or equal to a quantity threshold, then, through the multi-head prediction module, determine the third probability of each second word element as the (k+1)-th word element in the i-th word element group based on the first prompt word and the first text, and take the second word element with the highest third probability among the N second word elements that is associated with the k-th word element as the (k+1)-th word element. Here, k is a positive integer.

[0266] In one possible implementation, the execution module 72 is specifically used to: merge the first generated first word and the first text obtained by the acquisition module 71 through the multi-head prediction module of the text generation model to obtain the first text; and to output the second answer through the multi-head prediction module based on the second text.

[0267] In one possible implementation, the aforementioned at least one first word element is divided into at least one word element group, and each word element group includes at least a portion of the first word element. Specifically, the execution module 72 is used to: determine, through the multi-head prediction module, the fourth probability of the first a third word elements of the first text acquired by the acquisition module 71 as word elements in the b-th word element group, where a is a positive integer and b is a positive integer; and, if the fourth probability is greater than or equal to a probability threshold, merge the first word elements and the first text through the multi-head prediction module.

[0268] In one possible implementation, the acquisition module 71 is further configured to acquire a first sample prompt word and a first sample answer before inputting the first prompt word and the first answer into the text generation model and generating at least one first word element based on the first prompt word and the first answer. The first sample answer is generated based on the first sample prompt word and includes sample first text. The execution module 72 is further configured to: input the first sample prompt word and the first sample answer acquired by the acquisition module 71 into a preset model and generate at least one first sample word element based on the first sample prompt word and the first answer; output a second sample answer based on the at least one first sample word element and sample first text; and train the preset model based on the second sample answer and the target answer to obtain a text training model.

[0269] In one possible implementation, the above-described apparatus further includes a determining module 73. The acquiring module 71 is specifically configured to input the first sample prompt word and the first sample answer into a preset module of a preset model, and obtain N second sample word units based on the first sample answer through the preset module. The determining module 73 is configured to determine at least one first sample word unit from the N second sample word units using the preset module based on the first sample prompt word and the N second sample word units obtained by the acquiring module 71. The execution module 72 is further configured to train the preset module based on the at least one first sample word unit and at least one target word unit determined by the determining module 73, thereby obtaining a multi-head prediction module.

[0270] This application provides a text generation device. Since the text generation device can generate at least one first word element based on the first prompt word and the first answer, that is, generate new text content based on the first prompt word and the answer generated based on the first prompt word, and then output a second answer through the text generation model based on at least one first word element and the first text, that is, combine the new text content with the part of the answer generated based on the first prompt word that satisfies the user to obtain the second answer. Thus, while generating a new answer that is different from the first answer based on the first prompt word, the part that satisfies the user is retained, which increases the probability of generating a user-satisfied answer, thereby improving the flexibility of the text generation method.

[0271] The text generation device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television set (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the device.

[0272] The text generation device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system used.

[0273] The text generation apparatus provided in this application embodiment can implement all the processes implemented in the above method embodiments, and will not be described again here to avoid repetition.

[0274] Optionally, such as Figure 15 As shown, this application embodiment also provides an electronic device 1000, including a processor 1001 and a memory 1002. The memory 1002 stores a program or instructions that can run on the processor 1001. When the program or instructions are executed by the processor 1001, they implement the various steps of the above-described text generation method embodiment and can achieve the same technical effect. To avoid repetition, they will not be described again here.

[0275] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.

[0276] Figure 16 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of this application.

[0277] The electronic device 100 includes, but is not limited to, components such as: radio frequency unit 101, network module 102, audio output unit 103, input unit 104, sensor 105, display unit 106, user input unit 107, interface unit 108, memory 109, and processor 110.

[0278] Those skilled in the art will understand that the electronic device 100 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 110 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 16 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.

[0279] The processor 110 is used to obtain a first prompt word and a first answer. The first answer is generated based on the first prompt word and includes first text.

[0280] The processor 110 is further configured to input the first prompt word and the first answer obtained by the processor 110 into the text generation model, and generate at least one first word element by the text generation model based on the first prompt word and the first answer.

[0281] The aforementioned processor 110 is also used to output a second answer based on at least one first word and the first text through a text generation model.

[0282] Optionally, the processor 110 is specifically configured to input the first prompt word and the first answer into the multi-head prediction module of the text generation model, and obtain N second word elements based on the first answer through the multi-head prediction module, where N is a positive integer. The processor 110 is also configured to determine at least one first word element from the N second word elements through the multi-head prediction module based on the first prompt word and the N second word elements.

[0283] Optionally, the aforementioned at least one first word element is divided into at least one word element group, and each word element group includes a portion of the words in the at least one first word element. The processor 110 is specifically configured to: for the i-th word element group in the at least one word element group, determine, based on the first prompt word, the first probability of each second word element being the first word element in the i-th word element group using a multi-head prediction module, and select the second word element with the highest first probability among N second word elements as the first word element in the i-th word element group. Furthermore, based on the first prompt word, determine, based on the first prompt word, the second probability of each second word element being the j-th word element in the i-th word element group using a multi-head prediction module, and select the second word element with the highest second probability among N second word elements that is associated with the (j-1)-th word element in the i-th word element group as the j-th word element in the i-th word element group. Where i is a positive integer, and j is a positive integer greater than 1.

[0284] Optionally, the processor 110 is further configured to, after determining the k-th word element in the i-th word tuple, if the number of determined first word elements is greater than or equal to a quantity threshold, determine the third probability of each second word element as the (k+1)-th word element in the i-th word tuple based on the first prompt word and the first text using a multi-head prediction module, and select the second word element with the highest third probability among the N second word elements that is associated with the k-th word element as the (k+1)-th word element. Here, k is a positive integer.

[0285] Optionally, the processor 110 is specifically used to: merge the generated first word and the first text using the multi-head prediction module of the text generation model to obtain the first text; and to output the second answer using the multi-head prediction module based on the second text.

[0286] Optionally, the aforementioned at least one first word element is divided into at least one word element group, and each word element group includes at least one part of the first word element. The aforementioned processor 110 is specifically configured to: determine, through a multi-head prediction module, the fourth probability of the first a third word elements of the first text as word elements in the b-th word element group, where a is a positive integer and b is a positive integer; and, if the fourth probability is greater than or equal to a probability threshold, merge the generated first word elements and the first text through the multi-head prediction module.

[0287] Optionally, the processor 110 is further configured to: before inputting the first prompt word and the first answer into the text generation model, and generating at least one first word unit by the text generation model based on the first prompt word and the first answer, obtain a first sample prompt word and a first sample answer, wherein the first sample answer is generated based on the first sample prompt word and includes sample first text. The processor 110 is further configured to: input the first sample prompt word and the first sample answer into a preset model, and generate at least one first sample word unit by the preset model based on the first sample prompt word and the first answer; output a second sample answer by the preset model based on at least one first sample word unit and sample first text; and train the preset model based on the second sample answer and the target answer to obtain a text training model.

[0288] Optionally, the above-mentioned device further includes a processor 110. Specifically, the processor 110 is used to input the first sample prompt word and the first sample answer into a preset module of a preset model, and to obtain N second sample word units based on the first sample answer through the preset module. The processor 110 is also used to determine at least one first sample word unit from the N second sample word units according to the first sample prompt word and the N second sample word units through the preset module. The processor 110 is further used to train the preset module based on at least one first sample word unit and at least one target word unit to obtain a multi-head prediction module.

[0289] This application provides an electronic device that can generate at least one first word element based on a first prompt word and a first answer. That is, it generates new text content based on the first prompt word and the answer generated based on the first prompt word. Then, it outputs a second answer through a text generation model based on at least one first word element and the first text. That is, it combines the new text content with the part of the answer generated based on the first prompt word that satisfies the user to obtain the second answer. In this way, it can generate a new answer that is different from the first answer based on the first prompt word while retaining the part that satisfies the user, thereby increasing the probability of generating a user-satisfied answer and improving the flexibility of the text generation method.

[0290] The electronic device provided in this application embodiment can implement all the processes implemented in the above method embodiments and achieve the same technical effects. To avoid repetition, it will not be described again here. The beneficial effects of the various implementation methods in this embodiment can be found in the beneficial effects of the corresponding implementation methods in the above method embodiments. To avoid repetition, it will not be described again here.

[0291] It should be understood that, in this embodiment, the input unit 104 may include a graphics processing unit (GPU) 1041 and a microphone 1042. The GPU 1041 processes image data of still images or videos obtained by an image capture device (such as a camera) in video capture mode or image capture mode. The display unit 106 may include a display panel 1061, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like. The user input unit 107 includes at least one of a touch panel 1071 and other input devices 1072. The touch panel 1071 is also called a touch screen. The touch panel 1071 may include a touch detection device and a touch controller. Other input devices 1072 may include, but are not limited to, a physical keyboard, function keys (such as volume control buttons, power buttons, etc.), a trackball, a mouse, and a joystick, which will not be described in detail here.

[0292] The memory 109 can be used to store software programs and various data. The memory 109 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 109 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus RAM (DRRAM). The memory 109 in the embodiments of this application includes, but is not limited to, these and any other suitable types of memory.

[0293] Processor 110 may include one or more processing units; optionally, processor 110 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into processor 110.

[0294] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described text generation method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0295] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0296] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described text generation method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0297] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0298] This application provides a computer program product that is stored in a storage medium and executed by at least one processor to implement the various processes of the text generation method embodiments described above, and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0299] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0300] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0301] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

Claims

1. A text generation method characterized by, The method comprises: obtaining a first prompt and a first answer, the first answer being generated based on the first prompt, and the first answer comprising a first text; inputting the first prompt and the first answer into a text generation model, and generating at least one first word element based on the first prompt and the first answer through the text generation model; outputting a second answer based on the at least one first word element and the first text through the text generation model; the outputting a second answer based on the at least one first word element and the first text through the text generation model comprises: merging the generated first word element and the first text through a multi-head prediction module of the text generation model to obtain a second text; outputting the second answer based on the second text through the multi-head prediction module.

2. The method of claim 1, wherein, the inputting the first prompt and the first answer into a text generation model, and generating at least one first word element based on the first prompt and the first answer through the text generation model comprises: inputting the first prompt and the first answer into a multi-head prediction module of the text generation model, obtaining N second word elements based on the first answer through the multi-head prediction module, N being a positive integer; determining the at least one first word element from the N second word elements based on the first prompt and the N second word elements through the multi-head prediction module.

3. The method of claim 2, wherein, the at least one first word element is divided into at least one word element group, and each word element group comprises part of the at least one first word element; the determining the at least one first word element from the N second word elements based on the first prompt and the N second word elements through the multi-head prediction module comprises: for an i-th word element group in the at least one word element group, determining a first probability of each second word element as a first word element in the i-th word element group based on the first prompt through the multi-head prediction module, and taking a second word element with the highest first probability in the N second word elements as the first word element in the i-th word element group; determining a second probability of each second word element as a j-th word element in the i-th word element group based on the first prompt through the multi-head prediction module, and taking a second word element with the highest second probability in the N second word elements and associated with a j-1-th word element in the i-th word element group as the j-th word element in the i-th word element group; wherein i is a positive integer, and j is a positive integer greater than 1.

4. The method of claim 3, wherein, The method further comprises: after determining a k-th word element in the i-th word element group, if the number of determined first word elements is greater than or equal to a quantity threshold, determining a third probability of each second word element as a k+1-th word element in the i-th word element group based on the first prompt and the first text through the multi-head prediction module, and taking a second word element with the highest third probability in the N second word elements and associated with the k-th word element as the k+1-th word element; wherein k is a positive integer.

5. The method of claim 1, wherein, The at least one first word unit comprises at least one word unit group, and each word unit group comprises part of the at least one first word unit; The first text is merged according to the generated first word unit and the first text by a multi-head prediction module of the text generation model, comprising: The first text is determined as the fourth probability of the word unit in the bth word unit group by the multi-head prediction module, a is a positive integer, and b is a positive integer; In the case where the fourth probability is greater than or equal to a probability threshold, the first text is merged according to the generated first word unit and the first text by the multi-head prediction module.

6. The method of claim 1, wherein, Before the first prompt word and the first answer are input into the text generation model, and at least one first word unit is generated according to the first prompt word and the first answer by the text generation model, the method further comprises: Obtaining a first sample prompt word and a first sample answer, the first sample answer is generated based on the first sample prompt word, and the first sample answer comprises a sample first text; The first sample prompt word and the first sample answer are input into a preset model, and at least one first sample word unit is generated according to the first sample prompt word and the first sample answer by the preset model; According to the at least one first sample word unit and the sample first text, a second sample answer is output by the preset model; According to the second sample answer and the target answer, the preset model is trained to obtain the text generation model.

7. The method of claim 6, wherein, The first sample prompt word and the first sample answer are input into a preset model, and at least one first sample word unit is generated according to the first sample prompt word and the first answer by the preset model, comprising: The first sample prompt word and the first sample answer are input into a preset module of the preset model, and N second sample word units are obtained based on the first sample answer by the preset module; According to the first sample prompt word and the N second sample word units, the at least one first sample word unit is determined from the N second sample word units by the preset module; According to the at least one first sample word unit and at least one target word unit, the preset module is trained to obtain the multi-head prediction module.

8. A text generating apparatus characterized by comprising: Comprise: An acquisition module and an execution module; The acquisition module is used to acquire a first prompt word and a first answer, the first answer is generated based on the first prompt word, and the first answer comprises a first text; The execution module is used to input the first prompt word and the first answer acquired by the acquisition module into a text generation model, and generate at least one first word unit according to the first prompt word and the first answer by the text generation model; The execution module is further used to output a second answer according to the at least one first word unit and the first text by the text generation model; The execution module is specifically used to: In the process of generating the at least one first word piece obtained by the obtaining module, a multi-head prediction module of the text generation model merges the generated first word piece and the first text obtained by the obtaining module to obtain a second text; and The second answer is output by the multi-head prediction module according to the second text.

9. The apparatus of claim 8, wherein, The apparatus further includes a determining module; The execution module is specifically configured to input the first prompt word obtained by the obtaining module and the first answer to a multi-head prediction module of the text generation model, and obtain N second word pieces based on the first answer by the multi-head prediction module, N being a positive integer; The determining module is configured to determine the at least one first word piece from the N second word pieces by the multi-head prediction module according to the first prompt word obtained by the obtaining module and the N second word pieces obtained by the execution module.

10. The apparatus of claim 9, wherein, The at least one first word piece is divided into at least one word piece group, and each word piece group includes part of the at least one first word piece; The determining module is specifically configured to: For an i-th word piece group in the at least one word piece group, the multi-head prediction module determines a first probability of each second word piece as a first word piece in the i-th word piece group according to the first prompt word obtained by the obtaining module, and takes a second word piece with the highest first probability in the N second word pieces obtained by the obtaining module as the first word piece in the i-th word piece group; And The multi-head prediction module determines a second probability of each second word piece as a j-th word piece in the i-th word piece group according to the first prompt word obtained by the obtaining module, and takes a second word piece with the highest second probability and associated with a (j-1)-th word piece in the i-th word piece group in the N second word pieces obtained by the obtaining module as the j-th word piece in the i-th word piece group; Wherein, i is a positive integer, and j is a positive integer greater than 1.

11. The apparatus of claim 10, wherein, The determining module is further configured to, after determining a k-th word piece in the i-th word piece group, if the number of the determined first word pieces is greater than or equal to a number threshold, determine a third probability of each second word piece as a (k+1)-th word piece in the i-th word piece group according to the first prompt word and the first text by the multi-head prediction module, and take a second word piece with the highest third probability and associated with the k-th word piece in the N second word pieces as the (k+1)-th word piece; Wherein, k is a positive integer.

12. The apparatus of claim 8, wherein, The at least one first word piece is divided into at least one word piece group, and each word piece group includes part of the at least one first word piece; The execution module is specifically configured to: The multi-head prediction module determines a fourth probability of a first a third word piece of the first text obtained by the obtaining module as a word piece in a b-th word piece group, a being a positive integer and b being a positive integer; And In the case where the fourth probability is greater than or equal to a probability threshold, the multi-head prediction module merges the generated first word piece and the first text.

13. The apparatus of claim 8, wherein, The acquisition module is further configured to, before inputting the first prompt word and the first answer into the text generation model, acquire a first sample prompt word and a first sample answer, generate the first sample answer based on the first sample prompt word, and include a sample first text in the first sample answer, and generate at least one first token based on the first sample prompt word and the first answer by using the text generation model. The execution module is further configured to: input the first sample prompt word acquired by the acquisition module and the first sample answer acquired by the acquisition module into a preset model, generate at least one first sample token based on the first sample prompt word and the first sample answer by using the preset model; output a second sample answer based on the at least one first sample token and the sample first text by using the preset model; train the preset model based on the second sample answer and a target answer, and obtain the text generation model.

14. The apparatus of claim 13, wherein, The device further includes a determination module. The acquisition module is specifically configured to input the first sample prompt word and the first sample answer into a preset module of the preset model, and acquire N second sample tokens based on the first sample answer by using the preset module. The determination module is configured to determine the at least one first sample token from the N second sample tokens based on the first sample prompt word acquired by the acquisition module and the N second sample tokens by using the preset module. The execution module is further configured to train the preset module based on the at least one first sample token determined by the determination module and at least one target token, and obtain the multi-head prediction module.

15. An electronic device, comprising: A processor and a memory are included, the memory stores programs or instructions that can be run on the processor, and the programs or instructions are executed by the processor to implement the steps of the text generation method in any one of claims 1 to 7.

16. A readable storage medium, characterized by, The readable storage medium stores programs or instructions, and the programs or instructions are executed by the processor to implement the steps of the text generation method in any one of claims 1 to 7.

17. A computer program product, characterised in that, The program product is stored in a storage medium, and the program product is executed by at least one processor to implement the text generation method in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Text processing method and device, electronic equipment and computer readable storage medium

    CN116340467A

  • Question and answer processing method and device, electronic equipment and storage medium

    CN116881427A