Text generation method, device, electronic device and storage medium

By adjusting the word segmentation order of text sequences in bundle search, it maximizes the number of word segmentation in the same sort as the text sequence in the previous time step, the problem of large copy overhead in bundle search is solved and the efficiency of text generation is improved.

CN117217217BActive Publication Date: 2025-02-07合肥智能语音创新发展有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311284157.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-28
Publication Date
2025-02-07
Estimated Expiration
2043-09-28

AI Technical Summary

Technical Problem

In the case of input and output memory sharing, existing bundle searches require frequent copying of word segments in candidate output text sequences when text generation, resulting in a large copy overhead.

Method used

通过对多个分词进行排序的过程中,获取各时间步的文本序列,并调整任一时间步的文本序列的分词顺序,以最大化与上一时间步的文本序列间相同排序的分词数量, This avoids repeated copying of the same participle.

Benefits of technology

It effectively reduces the additional copy overhead when selecting text sequences at any time step, and improves the efficiency of text generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117217217B_ABST
    Figure CN117217217B_ABST
Patent Text Reader

Abstract

The present invention provides a text generation method, device, electronic device and storage medium, the method comprising: generating words from text features to obtain multiple segmented words; sorting the multiple segmented words to obtain generated text; wherein, in the process of sorting the multiple segmented words, a text sequence of each time step is obtained based on the multiple segmented words, wherein the number of segmented words in the text sequence of each time step increases with the time step, and the segmented word order of the text sequence of any time step is adjusted with the goal of maximizing the number of segmented words with the same order between the text sequence of any time step and the previous time step, and the generated text is determined based on the text sequence of the last time step. The text generation method, device, electronic device and storage medium provided by the present invention can avoid the problem of additional copying overhead caused by the need to repeatedly copy the same segmented words in the text sequence of the previous time step when selecting the text sequence of any time step.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of natural language processing, and in particular to a text generation method, device, electronic device and storage medium. Background Art

[0002] Text generation refers to the process of generating natural language text through computer programs, artificial intelligence models, or natural language processing technologies. In the process of generating text, the text generation model usually predicts the next most likely word or character based on the current input and context information. Beam search selects the most likely output text sequence by maintaining a set of candidate text sequences and expanding and sorting them according to the predicted probabilities.

[0003] However, in the case of shared input and output memory, the existing beam search needs to completely copy each word in the new candidate output text sequence to the corresponding memory each time a new candidate output text sequence is selected, resulting in a large copying overhead. Summary of the invention

[0004] The present invention provides a text generation method, device, electronic device and storage medium, which are used to solve the defect of large copy overhead of text generation in the prior art.

[0005] The present invention provides a text generation method, comprising:

[0006] Generate words based on text features to obtain multiple word segments;

[0007] Sorting the multiple word segments to obtain a generated text;

[0008] In the process of sorting the multiple word segments, a text sequence of each time step is obtained based on the multiple word segments, wherein the number of word segments in the text sequence of each time step increases with the time step, and the word segmentation order of the text sequence of any time step is adjusted with the goal of maximizing the number of word segments with the same order between the text sequence of any time step and the previous time step, and the generated text is determined based on the text sequence of the last time step.

[0009] According to a text generation method provided by the present invention, the step of adjusting the word segmentation order of the text sequence at any time step comprises:

[0010] According to the word segmentation order of the text sequence at the previous time step, traverse each word segmentation in the text sequence at the previous time step;

[0011] If there is any word segmentation in the text sequence of any time step that is the same as the word segmentation at the current position in the text sequence of the previous time step, add the word segmentation corresponding to the text sequence of any time step to the array, and delete the word segmentation corresponding to the text sequence of any time step;

[0012] After traversing each word segment in the text sequence of the previous time step, the remaining word segments in the text sequence of any time step are added to the array in sequence according to the word segmentation order, and the word segmentation order of the array is used as the adjusted word segmentation order of the text sequence of any time step.

[0013] According to a text generation method provided by the present invention, the adjustment step further includes:

[0014] In the case that there is any word segmentation in the text sequence of any time step that is different from the word segmentation at the current position in the text sequence of the previous time step, the execution is returned according to the word segmentation order of the text sequence of the previous time step, and each word segmentation in the text sequence of the previous time step is traversed.

[0015] According to a text generation method provided by the present invention, the step of adjusting the word segmentation order of the text sequence at any time step comprises:

[0016] When the word segment at the current position in the text sequence of the previous time step is different from the word segment corresponding to the current position in the text sequence of any time step, traverse the word segment after the current position in the text sequence of any time step;

[0017] When it is determined after traversal that there is any word segmentation in the text sequence of any time step that is the same as the word segmentation at the current position in the text sequence of the previous time step, the corresponding word segmentation in the text sequence of any time step is adjusted to the current position.

[0018] According to a text generation method provided by the present invention, the adjustment step further includes:

[0019] When the word segment at the current position in the text sequence of the previous time step is the same as the word segment corresponding to the current position in the text sequence of any time step, the position of the next word segment in the text sequence of the previous time step is taken as the current position.

[0020] According to a text generation method provided by the present invention, the step of determining the generated text includes:

[0021] Determine the probability of each word corresponding to different positions;

[0022] Based on the probability of each word segmentation corresponding to different positions, the text sequence of the last time step is segmented and sorted to obtain the generated text.

[0023] According to a text generation method provided by the present invention, the number of segmented words in the text sequence at any time step is i, and the number of segmented words in the text sequence at the previous time step corresponding to the text sequence at any time step is i-1.

[0024] The present invention also provides a text generation device, comprising:

[0025] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, any of the above-mentioned text generation methods is implemented.

[0026] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the text generation method described in any one of the above is implemented.

[0027] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the text generation method described in any one of the above is implemented.

[0028] The text generation method, device, electronic device and storage medium provided by the present invention, in the process of sorting individual segmented words, the segmented word order of the text sequence at any time step is adjusted with the goal of maximizing the number of segmented words with the same sorting between the text sequence at any time step and the previous time step, thereby ensuring that the maximum degree of segmented word sorting in the text sequence at any time step and the previous time step corresponds one to one, avoiding the problem of additional copying overhead caused by the need to repeatedly copy the same segmented words in the text sequence at the previous time step when selecting the text sequence at any time step. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0030] Figure 1 It is a flowchart of the text generation method provided by the present invention;

[0031] Figure 2 Schematic diagram of a text sequence generation method based on beam search provided by the present invention;

[0032] Figure 3 This is one of the flow charts of the word segmentation order adjustment step provided by the present invention;

[0033] Figure 4 This is the second flow chart of the word segmentation order adjustment step provided by the present invention;

[0034] Figure 5 It is a flowchart of the steps of generating text determination provided by the present invention;

[0035] Figure 6 It is a structural schematic diagram of the text generation device provided by the present invention;

[0036] Figure 7 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0038] In the existing beam search, when the input and output memory are shared, if the new candidate output text sequence does not have a one-to-one correspondence with the previous output text sequence, each time a new candidate output text sequence is selected, an additional copy process is involved, which in turn brings additional copy overhead.

[0039] For example, when applying beam search for text generation, the word segmentation order of the current candidate text sequence is (1,2,3,4), and the word segmentation order of the next candidate text sequence is (1,1,2,2). If the first word segmentation of the current candidate text sequence and the next candidate text sequence is the same as "1" according to the conventional practice, the next candidate text sequence does not need to copy "1", but the second word segmentation of the current candidate text sequence and the next candidate text sequence is different, which is "2" and "1" respectively, that is, the next candidate text sequence needs to copy the second word segmentation "1" additionally. Similarly, the next candidate text sequence needs to copy the third word segmentation "2" and the fourth word segmentation "2" additionally, that is, the next candidate text sequence needs to be copied 3 times in total, and the copying overhead is large.

[0040] To this end, the present invention provides a text generation method. Figure 1 It is a flow chart of the text generation method provided by the present invention, such as Figure 1 As shown, the method comprises the following steps:

[0041] Step 110: Generate words based on the text features to obtain multiple word segments;

[0042] Step 120, sorting the multiple segmented words to obtain a generated text;

[0043] In the process of sorting multiple word segments, a text sequence of each time step is obtained based on multiple word segments, wherein the number of word segments in the text sequence of each time step increases with the time step, and the word segmentation order of the text sequence of any time step is adjusted with the goal of maximizing the number of word segments with the same order between any time step and the text sequence of the previous time step, and the generated text is determined based on the text sequence of the last time step.

[0044] Specifically, the text feature is used to describe the information of the text to be generated, that is, the text that needs to be generated. The text feature may include semantic information, syntactic structure information, word frequency information, etc. of the text to be generated.

[0045] Since the text features are used to describe the information of the text to be generated, when generating words from the text features, multiple new segmented words (ie, multiple segmented words in step 110) can be generated based on the information of the text to be generated. The multiple segmented words are used to form the generated text.

[0046] Optionally, the text to be generated may be input into a pre-trained language model, and the language model extracts text features of the text to be generated, and performs word generation on the text features to obtain a plurality of word segments.

[0047] In addition, the multiple word segments generated in step 110 are unarranged word segments. Since the semantic information of the text obtained by sorting different word segments is different, the multiple word segments need to be sorted to obtain an accurate generated text.

[0048] Optionally, multiple segmented words can be sorted based on the probability of each segmented word at different positions in the text to obtain a generated text. For example, multiple segmented words "A", "B" and "C" are obtained by generating words based on text features, and their probabilities at position 1 are 0.5, 0.3 and 0.2 respectively. Since the probability of segmented word "A" at position 1 is the largest, segmented word "A" is arranged at position 1. Similarly, segmented words at positions 2 and 3 are determined respectively to complete the sorting of segmented words and obtain a generated text.

[0049] In the process of sorting multiple word segments, the text sequence of each time step is obtained based on the multiple word segments, and the number of word segments in the text sequence of each time step increases with the time step. However, if the text sequence of any time step has the same word segment as the text sequence of the previous time step, but the sorting of the same word segment is different, then each time the text sequence of any time step is selected, the same word segment needs to be copied again, which brings additional copying overhead.

[0050] To this end, an embodiment of the present invention adjusts the word segmentation order of a text sequence at any time step, and the adjustment goal is to maximize the number of word segments with the same order between the text sequence at any time step and the previous time step, so as to maximize the one-to-one correspondence between the word segmentation order in the text sequence at any time step and the previous time step.

[0051] For example, the word segmentation order of the text sequence at any time step is (1,5,2,6), and the corresponding word segmentation order of the text sequence at the previous time step is (1,2,3,4). There are two identical word segmentations "1" and "2" in the text sequence at any time step and the text sequence at the previous time step. In order to maximize the number of identically ordered word segmentations between the text sequence at any time step and the previous time step, the word segmentation order of the text sequence at the previous time step can be adjusted to (1,2,5,2), so that the identically ordered word segmentations between the text sequence at any time step and the previous time step are (1,2), that is, the number of identically ordered word segmentations is 2, thereby avoiding the need to additionally copy the word segmentation "2" when selecting the text sequence at any time step, thereby incurring additional copying overhead.

[0052] In addition, the number of word segments in the text sequence of each time step increases with the time step, and the text sequence of the last time step contains all word segments. After the text sequence of the last time step is segmented and sorted, the generated text can be obtained.

[0053] In the text generation method provided by the embodiment of the present invention, in the process of sorting multiple participles, the participle order of the text sequence at any time step is adjusted with the goal of maximizing the number of participles with the same order between the text sequence at any time step and the previous time step, thereby ensuring a one-to-one correspondence between the maximum degree of participle ordering in the text sequence at any time step and the previous time step, avoiding the problem of additional copying overhead caused by the need to repeatedly copy the same participles in the text sequence at the previous time step when selecting the text sequence at any time step.

[0054] As an optional embodiment, the present invention can use a beam search algorithm to generate a text sequence for each time step. For the beam search, there is a hyperparameter beam width, which is set to k. At time step 1, the k words with the largest current conditional probability are selected as the first word of the k text sequence of time step 1. At each subsequent time step, based on the text sequence of the previous time step, the k words with the largest conditional probability among all combinations are selected as the text sequence at that time step. The k text sequences are always maintained, and finally the optimal text sequence is selected from the k text sequences as the generated text. Figure 2 is a schematic diagram of a text sequence generation method based on beam search provided by the present invention, such as Figure 2As shown, the size of k is 2. At time step 1, the two text sequences "A" and "B" with the largest conditional probabilities are selected; at time step 2, the two text sequences "AC" and "BD" with the largest conditional probabilities are selected based on time step 1; at time step 3, the two text sequences "ACB" and "BDC" with the largest conditional probabilities are selected based on time step 2; at time step 4, the two text sequences "BDCA" and "BDCB" with the largest conditional probabilities are selected based on time step 3; finally, the text sequence with the largest probability is selected from "BDCA" and "BDCB" as the generated text for the final output.

[0055] Based on the above embodiments, Figure 3 is one of the flow charts of the word segmentation order adjustment step provided by the present invention, such as Figure 3 As shown, the steps for adjusting the word segmentation order at any time step include:

[0056] Step 310a, traversing each word segmentation in the text sequence of the previous time step according to the word segmentation order of the text sequence of the previous time step;

[0057] Step 320a: if there is any word segmentation in the text sequence at any time step that is the same as the word segmentation at the current position in the text sequence at the previous time step, add the word segmentation corresponding to the text sequence at any time step to the array, and delete the word segmentation corresponding to the text sequence at any time step;

[0058] Step 330a: After traversing all the word segments in the text sequence of the previous time step, the remaining word segments in the text sequence of any time step are added to the array in the word segmentation order, and the word segmentation order of the array is used as the adjusted word segmentation order of the text sequence of any time step.

[0059] Specifically, the word segments in the text sequence of the previous time step are traversed in sequence according to the word segmentation order of the text sequence of the previous time step. If there is any word segmentation in the text sequence of any time step that is the same as the word segmentation at the current position in the text sequence of the previous time step, the corresponding same word segmentation is added to the array, and the corresponding word segmentation is deleted from the text sequence of any time step, and the execution of step 310a is returned until all the word segmentations in the text sequence of the previous time step have been traversed. The initial state of the array is empty.

[0060] After traversing all the word segments in the text sequence of the previous time step, the remaining word segments in the text sequence of any time step are added to the array in the word segmentation order, and the word segmentation order of the array is used as the adjusted word segmentation order of the text sequence of any time step.

[0061] As an optional embodiment, assume that the text sequence at any time step is S i+1 , the text sequence of the previous time step is S i, create a map and an array, for S i+1 The key is the first i tokens of the element, and the value is the element. Iterate through S in sequence. i If a key-value pair with the key as the element value is found in the map, it is directly put into the array and the key-value pair is deleted. After the traversal is completed, the map is traversed and the values ​​of the remaining key-value pairs are put into the array in sequence. The order of the elements in the final array is used as the text sequence of any time step as S i+1 The initial state of the array is empty.

[0062] Based on any of the above embodiments, the step of adjusting the word segmentation order at any time step further includes:

[0063] If there is any word segmentation in the text sequence of any time step that is different from the word segmentation at the current position in the text sequence of the previous time step, the execution is returned according to the word segmentation order of the text sequence of the previous time step, and each word segmentation in the text sequence of the previous time step is traversed.

[0064] Specifically, when there is any word segmentation in the text sequence of any time step that is different from the word segmentation at the current position in the text sequence of the previous time step, it indicates that there is no word segmentation identical to the word segmentation at the current position in the text sequence of any time step, that is, there is no need to copy the word segmentation at the current position when selecting the text sequence of any time step, so the loop can be returned to execute steps 310a to 320a until all the word segmentations in the text sequence of the previous time step have been traversed.

[0065] Based on any of the above embodiments, Figure 4 This is the second flow chart of the word segmentation order adjustment step provided by the present invention. Figure 4 As shown, the steps for adjusting the word segmentation order at any time step include:

[0066] Step 310b: When the word segment at the current position in the text sequence of the previous time step is different from the word segment corresponding to the current position in the text sequence of any time step, traverse the word segment after the current position in the text sequence of any time step;

[0067] Step 320b: When it is determined after traversal that there is any word segmentation in the text sequence of any time step that is the same as the word segmentation at the current position in the text sequence of the previous time step, adjust the corresponding word segmentation in the text sequence of any time step to the current position.

[0068] Specifically, when the word segmentation at the current position in the text sequence of the previous time step is different from the word segmentation corresponding to the current position in the text sequence of any time step, it indicates that there is no need to copy the word segmentation corresponding to the current position when selecting the text sequence of any time step, so continue to traverse the word segmentation after the current position in the text sequence of any time step.

[0069] If after traversal it is determined that there is any word in the text sequence of any time step that is the same as the word at the current position in the text sequence of the previous time step, it means that there is a word after the current position in the text sequence of any time step that is the same as the word at the current position in the text sequence of the previous time step, so the corresponding word in the text sequence of any time step is adjusted to the current position.

[0070] For example, the word segmentation order of the text sequence at any time step is (1,5,2,6), and the word segmentation order of the text sequence at the previous time step is (1,2,3,4). Assume that the word segmentation at the current position in the text sequence at any time step is "5", and the word segmentation at the current position corresponding to the text sequence at the previous time step is "2", that is, the word segmentation at the current position in the text sequence at any time step is different from the word segmentation at the current position corresponding to the text sequence at the previous time step. At this time, the word segmentation after the current position in the text sequence at any time step is traversed, that is, the word segmentations "2" and "6" in the text sequence at any time step are traversed. After traversal, it is determined that the word segmentation "2" in the text sequence at any time step is the same as the word segmentation "2" at the current position corresponding to the text sequence at the previous time step. At this time, the word segmentation "2" in the text sequence at any time step is adjusted to the current position, that is, the adjusted word segmentation order of the text sequence at any time step is (1,2,5,6).

[0071] Based on any of the above embodiments, the step of adjusting the word segmentation order at any time step further includes:

[0072] When the word segment at the current position in the text sequence of the previous time step is the same as the word segment corresponding to the current position in the text sequence of any time step, the position of the next word segment in the text sequence of the previous time step is taken as the current position.

[0073] Specifically, when the word segmentation at the current position in the text sequence of the previous time step is the same as the word segmentation corresponding to the current position in the text sequence of any time step, it indicates that the word segmentation at the current position in the text sequence of the previous time step and the word segmentation corresponding to the current position in the text sequence of any time step are corresponding, so jump to the next word segmentation in the text sequence of the previous time step, that is, take the position of the next word segmentation in the text sequence of the previous time step as the current position.

[0074] For example, the word segmentation order of the text sequence at any time step is (1, 5, 2, 6), and the word segmentation order of the text sequence at the previous time step is (1, 2, 3, 4). Assume that the word segmentation at the current position in the text sequence at any time step is "1", and the word segmentation at the current position corresponding to the text sequence at the previous time step is "1", that is, the word segmentation at the current position in the text sequence at any time step is the same as the word segmentation at the current position corresponding to the text sequence at the previous time step. At this time, jump to the next word segmentation "2" in the text sequence at the previous time step for judgment, that is, the position of the next word segmentation "2" in the text sequence at the previous time step is taken as the current position.

[0075] Based on any of the above embodiments, Figure 5 It is a flow chart of the steps of generating text determination provided by the present invention, such as Figure 5 As shown, the determination steps for generating text include:

[0076] Step 510: determine the probability of each word segment corresponding to different positions;

[0077] Step 520: Based on the probability of each word segmentation at different positions, the text sequence of the last time step is segmented and sorted to obtain the generated text.

[0078] Specifically, the probability of each word segmentation at different positions is used to characterize the confidence of each word segmentation at different positions. The higher the probability, the higher the confidence of each word segmentation at the corresponding position. Therefore, based on the probability of each word segmentation at different positions, the text sequence of the last time step is segmented and sorted to obtain the generated text. The probability of each word segmentation at different positions can be obtained when generating words from text features.

[0079] It can be understood that in the process of applying beam search to sort multiple word segments, the number of text sequences at each time step is the same as the beam width of the beam search, that is, when the beam width is greater than 1, there are multiple text sequences at each time step, that is, there are also multiple text sequences at the last time step. At this time, based on the probability of each word at the corresponding position in the text sequence of each last time step after the word segmentation is sorted, the probability of the text sequence corresponding to the last time step after the word segmentation is sorted can be calculated, and the text sequence of the last time step with the maximum probability is used as the generated text.

[0080] Based on any of the above embodiments, the number of word segments in a text sequence at any time step is i, and the number of word segments in a text sequence at any time step corresponding to a text sequence at a previous time step is i-1.

[0081] Specifically, the number of segmented words in the text sequence at each time step increases by 1 with each time step, so that the optimal text sequence can be obtained as the generated text by continuously traversing, expanding and screening the segmented word combinations, thereby improving the accuracy of the generated text.

[0082] The text generation device provided by the present invention is described below. The text generation device described below and the text generation method described above can be referenced to each other.

[0083] Based on any of the above embodiments, Figure 6 is a schematic diagram of the structure of the text generation device provided by the present invention, such as Figure 6 As shown, the device comprises:

[0084] A word segmentation generating unit 610 is used to generate words based on text features to obtain multiple word segments;

[0085] A text generation unit 620, used to sort the multiple segmented words to obtain a generated text;

[0086] In the process of sorting multiple word segments, a text sequence of each time step is obtained based on multiple word segments, wherein the number of word segments in the text sequence of each time step increases with the time step, and the word segmentation order of the text sequence of any time step is adjusted with the goal of maximizing the number of word segments with the same order between any time step and the text sequence of the previous time step, and the generated text is determined based on the text sequence of the last time step.

[0087] Based on any of the above embodiments, the step of adjusting the word segmentation order of the text sequence at any time step includes:

[0088] According to the word segmentation order of the text sequence at the previous time step, traverse each word segmentation in the text sequence at the previous time step;

[0089] If there is any word in the text sequence at any time step that is the same as the word at the current position in the text sequence at the previous time step, add the word corresponding to the text sequence at any time step to the array, and delete the word corresponding to the text sequence at any time step;

[0090] After traversing each word in the text sequence of the previous time step, the remaining words in the text sequence of any time step are added to the array in the word segmentation order, and the word segmentation order of the array is used as the adjusted word segmentation order of the text sequence of any time step.

[0091] Based on any of the above embodiments, the adjusting step further includes:

[0092] If there is any word segmentation in the text sequence of any time step that is different from the word segmentation at the current position in the text sequence of the previous time step, the execution is returned according to the word segmentation order of the text sequence of the previous time step, and each word segmentation in the text sequence of the previous time step is traversed.

[0093] Based on any of the above embodiments, the step of adjusting the word segmentation order of the text sequence at any time step includes:

[0094] When the word segment at the current position in the text sequence of the previous time step is different from the word segment corresponding to the current position in the text sequence of any time step, traverse the word segment after the current position in the text sequence of any time step;

[0095] When it is determined after traversal that there is any word segmentation in the text sequence of any time step that is the same as the word segmentation at the current position in the text sequence of the previous time step, the corresponding word segmentation in the text sequence of any time step is adjusted to the current position.

[0096] Based on any of the above embodiments, the adjusting step further includes:

[0097] When the word segment at the current position in the text sequence of the previous time step is the same as the word segment corresponding to the current position in the text sequence of any time step, the position of the next word segment in the text sequence of the previous time step is taken as the current position.

[0098] Based on any of the above embodiments, the step of determining to generate text includes:

[0099] Determine the probability of each word corresponding to different positions;

[0100] Based on the corresponding probability of each word at different positions, the text sequence of the last time step is segmented and sorted to obtain the generated text.

[0101] Based on any of the above embodiments, the number of word segments in a text sequence at any time step is i, and the number of word segments in a text sequence at any time step corresponding to a text sequence at a previous time step is i-1.

[0102] Figure 7 is a schematic diagram of the structure of the electronic device provided by the present invention, such as Figure 7As shown, the electronic device may include: a processor 710, a memory 720, a communication interface 730 and a communication bus 740, wherein the processor 710, the memory 720 and the communication interface 730 communicate with each other through the communication bus 740. The processor 710 may call the logic instructions in the memory 720 to execute the text generation method, which includes: generating words from text features to obtain multiple segmented words; sorting the multiple segmented words to obtain generated text; wherein, in the process of sorting the multiple segmented words, a text sequence of each time step is obtained based on the multiple segmented words, wherein the number of segmented words in the text sequence of each time step increases with the time step, and the segmented word order of the text sequence of any time step is adjusted with the goal of maximizing the number of segmented words with the same order between the text sequence of any time step and the previous time step, and the generated text is determined based on the text sequence of the last time step.

[0103] In addition, the logic instructions in the above-mentioned memory 720 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0104] On the other hand, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the text generation method provided by the above methods, the method including: generating words from text features to obtain multiple word segments; sorting the multiple word segments to obtain generated text; wherein, in the process of sorting the multiple word segments, a text sequence of each time step is obtained based on the multiple word segments, wherein the number of word segments in the text sequence of each time step increases with the time step, and the word segmentation order of the text sequence of any time step is adjusted with the goal of maximizing the number of word segments with the same order between the text sequence of any time step and the previous time step, and the generated text is determined based on the text sequence of the last time step.

[0105] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to execute the above-mentioned text generation methods, the method comprising: generating words from text features to obtain multiple word segments; sorting the multiple word segments to obtain generated text; wherein, in the process of sorting the multiple word segments, a text sequence of each time step is obtained based on the multiple word segments, wherein the number of word segments in the text sequence of each time step increases with the time step, and the word segmentation order of the text sequence of any time step is adjusted with the goal of maximizing the number of word segments with the same order between the text sequence of any time step and the previous time step, and the generated text is determined based on the text sequence of the last time step.

[0106] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0107] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0108] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A text generation method, characterized in that: include: Generate words based on text features to obtain multiple word segments; Sorting the multiple word segments to obtain a generated text; Wherein, in the process of sorting the multiple segmented words, a text sequence of each time step is obtained based on the multiple segmented words, wherein the number of segmented words in the text sequence of each time step increases with the time step, and the segmented word order of the text sequence of any time step is adjusted with the goal of maximizing the number of segmented words with the same sorting between the text sequence of any time step and the previous time step, and the generated text is determined based on the text sequence of the last time step; The step of adjusting the word segmentation order of the text sequence at any time step comprises: When the word segment at the current position in the text sequence of the previous time step is different from the word segment corresponding to the current position in the text sequence of any time step, traverse the word segment after the current position in the text sequence of any time step; When it is determined after traversal that there is any word segmentation in the text sequence of any time step that is the same as the word segmentation at the current position in the text sequence of the previous time step, the corresponding word segmentation in the text sequence of any time step is adjusted to the current position.

2. The text generation method according to claim 1, characterized in that: The step of adjusting the word segmentation order of the text sequence at any time step comprises: According to the word segmentation order of the text sequence at the previous time step, traverse each word segmentation in the text sequence at the previous time step; If there is any word segmentation in the text sequence of any time step that is the same as the word segmentation at the current position in the text sequence of the previous time step, add the word segmentation corresponding to the text sequence of any time step to the array, and delete the word segmentation corresponding to the text sequence of any time step; After traversing each word segment in the text sequence of the previous time step, the remaining word segments in the text sequence of any time step are added to the array in sequence according to the word segmentation order, and the word segmentation order of the array is used as the adjusted word segmentation order of the text sequence of any time step.

3. The text generation method according to claim 2, characterized in that: The adjusting step further comprises: In the case that there is any word segmentation in the text sequence of any time step that is different from the word segmentation at the current position in the text sequence of the previous time step, the execution is returned according to the word segmentation order of the text sequence of the previous time step, and each word segmentation in the text sequence of the previous time step is traversed.

4. The text generation method according to claim 1, characterized in that: The adjusting step further comprises: When the word segment at the current position in the text sequence of the previous time step is the same as the word segment corresponding to the current position in the text sequence of any time step, the position of the next word segment in the text sequence of the previous time step is taken as the current position.

5. The text generation method according to any one of claims 1 to 4, characterized in that: The step of determining the generated text includes: Determine the probability of each word corresponding to different positions; Based on the probability of each word segmentation corresponding to different positions, the text sequence of the last time step is segmented and sorted to obtain the generated text.

6. The text generation method according to any one of claims 1 to 4, characterized in that: The number of word segments in the text sequence at any time step is i, and the number of word segments in the text sequence at the previous time step corresponding to the text sequence at any time step is i-1.

7. A text generation device, characterized in that: include: A word segmentation generating unit, used to generate words based on text features to obtain multiple word segments; A text generation unit, used for sorting the multiple word segments to obtain a generated text; Wherein, in the process of sorting the multiple segmented words, a text sequence of each time step is obtained based on the multiple segmented words, wherein the number of segmented words in the text sequence of each time step increases with the time step, and the segmented word order of the text sequence of any time step is adjusted with the goal of maximizing the number of segmented words with the same sorting between the text sequence of any time step and the previous time step, and the generated text is determined based on the text sequence of the last time step; The step of adjusting the word segmentation order of the text sequence at any time step comprises: When the word segment at the current position in the text sequence of the previous time step is different from the word segment corresponding to the current position in the text sequence of any time step, traverse the word segment after the current position in the text sequence of any time step; When it is determined after traversal that there is any word segmentation in the text sequence of any time step that is the same as the word segmentation at the current position in the text sequence of the previous time step, the corresponding word segmentation in the text sequence of any time step is adjusted to the current position.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the text generation method according to any one of claims 1 to 6 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the text generation method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Comment information generation method and device, electronic equipment and storage medium

    CN112667780A

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

    CN114912440A