Sentence generation method, generation device and electronic equipment
By using a prefix tree to limit the generation space, the generated statements can be directly recognized by the computer system, solving the problem of inaccurate language model generation and achieving accurate statement generation and control of home appliances.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- MIDEA GRP (SHANGHAI) CO LTD
- Filing Date
- 2023-10-31
- Publication Date
- 2026-06-02
Smart Images

Figure CN117370531B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of artificial intelligence technology and data processing technology, and more specifically, to a method, apparatus and electronic device for generating sentences. Background Technology
[0002] In related technologies, language models typically generate sentences freely without restrictions based on user input. This results in a large number of free-form sentences being generated around the input information. For the computer system, these generated sentences need to be parsed again to understand the user's precise needs. Therefore, how to make the generated sentences more accurate so that the computer system can understand them more quickly has become a pressing problem. Summary of the Invention
[0003] This application aims to address at least one of the technical problems existing in the prior art or related technologies.
[0004] Therefore, the first aspect of this application proposes a method for generating statements.
[0005] The second aspect of this application proposes a statement generation apparatus.
[0006] A third aspect of this application proposes a statement generation apparatus.
[0007] The fourth aspect of this application proposes an electronic device.
[0008] The fifth aspect of this application proposes a readable storage medium.
[0009] The sixth aspect of this application proposes a computer program product.
[0010] The seventh aspect of this application proposes a chip.
[0011] In view of this, a first aspect of this application proposes a method for generating a statement, comprising: obtaining a first prefix tree corresponding to first input information, wherein the first prefix tree is used to limit the generation space corresponding to the first input information; generating at least one first response statement based on the first input information and the first prefix tree, wherein each character of the first response statement is on the same branch of the first prefix tree; and outputting at least one first response statement.
[0012] The statement generation method provided in this application can generate response statements based on user input information. The generated response statements can be recognized by a computer system, enabling the computer to generate the information needed by the user and meet their requirements. For example, it can answer user questions, or the generated statements can be control commands for home appliances, allowing the computer system to control the appliances based on user input, or provide the user with relevant information in a specific field they wish to query.
[0013] Before generating the statement, a first prefix tree corresponding to the first input information input by the user can be obtained. The first input information may be in various formats, such as text, speech, or images, and this application does not impose any restrictions on this. Specifically, if the first input information is text, the corresponding first prefix tree can be obtained based on the first input information. If the first input information is speech information input by the user, the speech information can first be converted into text information, and then the first prefix tree corresponding to the first input information can be determined based on the text information. It is understood that the first prefix tree corresponds to the input information; that is, the characters contained in the first prefix tree are characters related to the first input information.
[0014] Specifically, based on the user's initial input information and a first prefix tree, at least one first response statement is generated. Furthermore, for each first response statement, each character within it resides on the same branch of the first prefix tree; different first response statements correspond to different branches. The first prefix tree is used to limit the generation space corresponding to the initial input information. That is, by using a branch of the first prefix tree, the generation space of the first response statements is restricted, ensuring that each first response statement, based on the same branch of the first prefix tree, conforms to the basic format rules and logic of statement expression, thus enabling the generated first response statement to be effectively recognized by the computer or user.
[0015] Finally, the first response statement is output. Specifically, it can be output to a computer, allowing the computer to respond to the user's initial input. Alternatively, the computer can parse the first response statement to generate corresponding control commands for the electrical equipment, enabling the user to remotely control the equipment.
[0016] The statement generation method provided by this invention first obtains a first prefix tree corresponding to the user's first input information during the statement generation process. Then, it generates a first response statement corresponding to the first input information based on the first input information and the first prefix tree. Thus, during the generation of the first statement, the first response statement is generated according to the path defined by the first prefix tree, resulting in a first response statement that fully conforms to the required format and content. This facilitates the computer system's recognition of the generated first response statement to meet the user's needs.
[0017] According to a second aspect of this application, a statement generation apparatus is proposed, comprising: an acquisition unit for acquiring a first prefix tree corresponding to first input information, wherein the first prefix tree is used to limit the generation space corresponding to the first input information; a generation unit for generating at least one first response statement based on the first input information and the first prefix tree, wherein each character of the first response statement is on the same branch of the first prefix tree; and an output unit for outputting at least one first response statement.
[0018] According to a third aspect of this application, a statement generation apparatus is proposed, comprising: a processor and a memory, wherein the memory stores a program or instructions executable on the processor, and the program or instructions, when executed by the processor, perform the following steps: obtaining a first prefix tree corresponding to first input information, wherein the first prefix tree is used to limit the generation space corresponding to the first input information; generating at least one first response statement based on the first input information and the first prefix tree, wherein each character of the first response statement is on the same branch of the first prefix tree; and outputting at least one first response statement.
[0019] According to a fourth aspect of this application, an electronic device is proposed, including a processor and a memory, wherein the memory stores a program or instructions executable on the processor, and the program or instructions, when executed by the processor, perform the following steps: obtaining a first prefix tree corresponding to first input information, wherein the first prefix tree is used to limit the generation space corresponding to the first input information; generating at least one first response statement based on the first input information and the first prefix tree, wherein each character of the first response statement is on the same branch of the first prefix tree; and outputting at least one first response statement.
[0020] According to a fifth aspect of this application, a readable storage medium is proposed, on which a program or instructions are stored, which, when executed by a processor, perform the following steps: obtaining a first prefix tree corresponding to first input information, wherein the first prefix tree is used to limit the generation space corresponding to the first input information; generating at least one first response statement based on the first input information and the first prefix tree, wherein each character of the first response statement is on the same branch of the first prefix tree; and outputting at least one first response statement.
[0021] According to a sixth aspect of this application, a computer program product is proposed, comprising a computer program or instructions, which, when executed by a processor, perform the following steps: obtaining a first prefix tree corresponding to first input information, wherein the first prefix tree is used to limit the generation space corresponding to the first input information; generating at least one first response statement based on the first input information and the first prefix tree, wherein each character of the first response statement is on the same branch of the first prefix tree; and outputting at least one first response statement.
[0022] According to a seventh aspect of this application, a chip is proposed, including a program or instructions that, when the chip is running, performs the following steps: obtaining a first prefix tree corresponding to first input information, wherein the first prefix tree is used to limit the generation space corresponding to the first input information; generating at least one first response statement based on the first input information and the first prefix tree, wherein each character of the first response statement is on the same branch of the first prefix tree; and outputting at least one first response statement.
[0023] Additional aspects and advantages of this application will become apparent in the following description or may be learned by practice of this application. Attached Figure Description
[0024] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:
[0025] Figure 1 A flowchart illustrating a statement generation method according to an embodiment of this application is shown;
[0026] Figure 2 A flowchart illustrating a statement generation method provided in yet another embodiment of this application is shown;
[0027] Figure 3 A flowchart illustrating a statement generation method provided in yet another embodiment of this application is shown;
[0028] Figure 4 A flowchart illustrating a statement generation method provided in yet another embodiment of this application is shown;
[0029] Figure 5 A flowchart illustrating a statement generation method provided in yet another embodiment of this application is shown;
[0030] Figure 6 A schematic diagram of a first prefix tree in a statement generation method according to an embodiment of this application is shown;
[0031] Figure 7A flowchart illustrating a statement generation method according to an embodiment of this application is shown;
[0032] Figure 8 A flowchart of a statement generation method provided in another embodiment of this application is shown;
[0033] Figure 9 A block diagram of a statement generation apparatus provided in one embodiment of this application is shown. Detailed Implementation
[0034] To better understand the above-mentioned objectives, features, and advantages of this application, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.
[0035] Many specific details are set forth in the following description in order to provide a full understanding of this application. However, this application may also be implemented in other ways different from those described herein. Therefore, the scope of protection of this application is not limited to the specific embodiments disclosed below.
[0036] The following reference Figures 1 to 9 This application describes a method, apparatus, and electronic device for generating statements according to some embodiments thereof.
[0037] like Figure 1 As shown, according to one embodiment of this application, a method for generating statements is proposed, including:
[0038] Step S102: Obtain the first prefix tree corresponding to the first input information;
[0039] The first prefix tree is used to limit the generation space corresponding to the first input information;
[0040] Step S104: Generate at least one first response statement based on the first input information and the first prefix tree;
[0041] In this case, each character of the first reply statement is on the same branch of the first prefix tree;
[0042] Step S106: Output at least one first response statement.
[0043] The statement generation method provided in this application can generate response statements based on user input information. The generated response statements can be recognized by a computer system, enabling the computer to generate the information needed by the user and meet their requirements. For example, it can answer user questions, or the generated statements can be control commands for home appliances, allowing the computer system to control the appliances based on user input, or provide the user with relevant information in a specific field they wish to query.
[0044] Before generating the statement, a first prefix tree corresponding to the first input information entered by the user can be obtained. The first input information may be in various formats, such as text, voice, and images, and this application does not limit this. Specifically, the first input information can be a query-type message entered by the user, such as "What should I do if it's hot?" or a task-type message, such as "Please turn on the air conditioner." Alternatively, it can be a prompt message, such as "You are a device control assistant that can convert user requests into control or query instructions for the air conditioner, refrigerator, range hood, or oven."
[0045] When the first input information is text, the corresponding first prefix tree can be obtained based on the first input information. When the first input information is voice information input by the user, the voice information input by the user can first be converted into text information, and then the first prefix tree corresponding to the first input information can be determined based on the text information. It can be understood that the first prefix tree corresponds to the input information, that is, the characters contained in the first prefix tree are characters related to the first input information.
[0046] For example, such as Figure 6 As shown, the first input information is about the control of home appliances. Therefore, the characters contained in the first prefix tree can be characters related to control commands such as "on", "start", "adjust", and "regulate", as well as characters related to home appliances such as "air", "adjust", "refrigerator", and "box". Furthermore, it can also include characters related to the control parameters of home appliances such as "temperature", "degree", "humidity", and "degree".
[0047] Specifically, based on the user's initial input information and a first prefix tree, at least one first response statement is generated. Furthermore, for each first response statement, each character within it resides on the same branch of the first prefix tree; different first response statements correspond to different branches. The first prefix tree is used to limit the generation space corresponding to the initial input information. That is, by using a branch of the first prefix tree, the generation space of the first response statements is restricted, ensuring that each first response statement, based on the same branch of the first prefix tree, conforms to the basic format rules and logic of statement expression, thus enabling the generated first response statement to be effectively recognized by the computer or user.
[0048] Finally, the first response statement is output. Specifically, it can be output to a computer, allowing the computer to respond to the user's initial input. Alternatively, the computer can parse the first response statement to generate corresponding control commands for the electrical equipment, enabling the user to remotely control the equipment.
[0049] In some embodiments, multiple first response statements are generated based on the first input information. These multiple first response statements can be output in various ways. For example, the multiple first response statements can be output sequentially, or the multiple first response statements can be output according to preset rules (e.g., after outputting a first response statement, a newline or a preset punctuation mark is output, and then the next first response statement is output). This application does not limit this.
[0050] The statement generation method provided by this invention first obtains a first prefix tree corresponding to the user's first input information during the statement generation process. Then, it generates a first response statement corresponding to the first input information based on the first input information and the first prefix tree. Thus, during the generation of the first statement, the first response statement is generated according to the path defined by the first prefix tree, resulting in a first response statement that fully conforms to the required format and content. This facilitates the computer system's recognition of the generated first response statement to meet the user's needs.
[0051] According to one embodiment of this application, such as Figure 2 As shown, a method for generating statements is proposed, including:
[0052] Step S202: Obtain the first prefix tree corresponding to the first input information;
[0053] The first prefix tree is used to limit the generation space corresponding to the first input information;
[0054] Step S204: Generate N target characters based on the first input information and the first prefix tree;
[0055] Where N target characters are located on the same branch of the first prefix tree, and N is a positive integer;
[0056] Step S206: Arrange the N target characters according to the generation order of the N target characters to generate the first response statement;
[0057] Step S208: Output at least one first response statement.
[0058] In this embodiment, during the generation of the first response statement, N target characters are first generated based on the user-inputted first input information and the first prefix tree. The first input information allows for the generation of characters related to it, while the first prefix tree restricts the degree of freedom in character generation. Specifically, any one of the N target characters lies on the same branch of the first prefix tree. This means that by restricting the N target characters to the same branch of the first prefix tree, a sentence can be generated based on the path defined by the first prefix tree during the generation process. In other words, when generating each character, the generated character is determined, restricting the currently generated character to the path in the first prefix tree, thus ultimately generating a first response statement that fully conforms to the required format and content.
[0059] Furthermore, after generating N target characters based on the first input information and the first prefix tree, the N target characters can be arranged according to the generation order of the N target characters to finally generate the first response statement.
[0060] The statement generation method provided by this invention, in the process of generating the first response statement, firstly generates N target characters based on the first input information and the first prefix tree. The N target characters are located on the same branch of the first prefix tree. Finally, the N target characters are arranged according to the generation order to generate the first response statement. Thus, in the process of generating the first response statement, the first response statement is generated according to the path defined by the first prefix tree. That is, when generating each target character of the first response statement, the determination is based on the already generated target characters, restricting the currently generated target character to the path of the first prefix tree, thereby ultimately generating a first response statement that fully conforms to the required format and content. This facilitates the computer system's recognition of the generated first response statement to meet the user's needs.
[0061] According to one embodiment of this application, such as Figure 3 As shown, a method for generating statements is proposed, including:
[0062] Step S302: Obtain the first prefix tree corresponding to the first input information;
[0063] Step S304: Input the first input information into the preset model to generate the first character set;
[0064] Step S306: If the first prefix tree includes at least one character in the first character set, determine the first target character in the first character set according to the first prefix tree;
[0065] Step S308: Input the first input information and the first M-1 target characters into the preset model to generate the Mth character set;
[0066] Step S310: Based on the first prefix tree, determine the Mth target character in the set of Mth character symbols;
[0067] Let M take integers from 2 to N in sequence to determine the second target character to the Nth target character;
[0068] Step S312: Arrange the N target characters according to the generation order of the N target characters to generate the first response statement;
[0069] Step S314: Output at least one first response statement.
[0070] In this embodiment, during the process of generating N target characters based on the first input information and the first prefix tree, the first input information can first be input into a preset model. Through the calculation of the preset model, a first character set is generated. It is understood that the first character set includes multiple characters related to the first input information, and the first target character of the first response statement to be generated can be determined from the first character set. The preset model can be a pre-trained Large Language Model (LLM). Large Language Models can handle various natural language tasks, such as text classification, responses, and dialogues, and can generate natural language text or understand the meaning of language text.
[0071] Furthermore, it can be determined whether the first prefix tree includes at least one character from the first character set. And if the first prefix tree includes at least one character from the first character set, the first target character can be determined from the first character set based on the first prefix tree. In other words, the first target character exists both in the first character set and simultaneously in the first prefix tree.
[0072] Furthermore, after determining the first M-1 target characters, the first M-1 target characters and the first input information are simultaneously input into the preset model, so that the preset model can calculate based on the first M-1 target characters and the first input information to determine the Mth character set. That is, the Mth target character of the first response statement to be generated exists in the Mth character set.
[0073] Further, according to the first prefix tree, in the Mth character set, the Mth target character is determined. Specifically, in the process of determining the Mth target character, it is necessary to ensure that the Mth target character and the (M - 1)th target character are in the same branch of the first prefix tree, so as to limit the Mth target character currently generated on the path of the first prefix tree, and finally generate the first reply statement that fully meets the required format and content.
[0074] Specifically, after determining the first target character, the first target character and the first input information are simultaneously input into a preset model to generate the second character set. Then, in the second character set, the character that is on the same path as the first target character on the first prefix tree is determined, and further the second target character is determined. And so on, finally, N target characters are determined. Finally, according to the generation order of the N target characters, the N target characters are arranged to generate the first reply statement.
[0075] Exemplarily, as Figure 6 shown, for the first input information input by the user, the user needs to control an air conditioner. At this time, the first prefix tree related to the control instructions of household appliances can be utilized. By calculating the first input information through the preset model, it is determined that the first character set includes two characters, "open" and "adjust". Further, according to the first input instruction and the first prefix tree, the second target character is determined to be "start" which is on the same branch as "open", or "high", "low", "to" which are on the same branch as "adjust". And so on, finally, the first reply statement is determined to be "Turn on the air conditioner" or "Adjust the air conditioner temperature higher". Finally, the home appliance control system can conveniently identify the first reply statement to control the operation of the air conditioner.
[0076] In some embodiments, optionally, according to the first prefix tree, in the Mth character set, determining the Mth target character includes: determining multiple candidate characters that match the first prefix tree in the Mth character set; obtaining the confidence levels of the multiple candidate characters; and determining the candidate character with the highest confidence level among the multiple candidate characters as the Mth target character.
[0077] In this embodiment, in the process of determining the Mth target character according to the first prefix tree in the Mth character set, first, in the Mth character set, multiple candidate characters that match the first prefix tree are determined, where each candidate character is the same as one of the characters in the first prefix tree. That is, the candidate characters that coexist in the Mth character set and the first prefix tree are determined.
[0078] Furthermore, the confidence scores of multiple characters to be confirmed are obtained. It can be understood that each character in the Mth character set calculated by the preset model has its own confidence score. This confidence score is calculated by the first model simultaneously for each character in the Mth character set during the calculation process. The confidence score represents the probability that the character matches the first input information; the higher the confidence score, the more closely the character matches the true intent of the first input information. Therefore, after identifying the characters to be confirmed that coexist with the first prefix tree in the Mth character set, the character with the highest confidence score among the multiple characters to be confirmed is determined as the Mth target character.
[0079] According to one embodiment of this application, such as Figure 4 As shown, a method for generating statements is proposed, including:
[0080] Step S402: Obtain the first prefix tree corresponding to the first input information;
[0081] Step S404: Input the first input information into the preset model to generate the first character set;
[0082] Step S406: If the first prefix tree does not contain at least one character from the first character conformation set, determine the first target character based on the confidence of all characters in the first character conformation set;
[0083] Step S408: Input the first input information and the determined M-1 target characters into the preset model to generate the Mth character set;
[0084] Step S410: Determine the Mth target character based on the confidence scores of all characters in the set of characters that match the Mth character.
[0085] Let M take integers from 2 to N in sequence to determine the second target character to the Nth target character;
[0086] Step S412: Arrange the N target characters according to the generation order of the N target characters to generate the first response statement;
[0087] Step S414: Output at least one first response statement.
[0088] In this embodiment, during the process of generating N target characters based on the first input information and the first prefix tree, the first input information can first be input into a preset model. Through the calculation of the preset model, a first character set is generated. It can be understood that the first character set includes multiple characters related to the first input information, and the first target character of the first response statement to be generated can be determined from the first character set.
[0089] Furthermore, it can be determined whether the first prefix tree includes at least one character from the first character set. If the first prefix tree does not include at least one character from the first character set, the first target character can be determined directly based on the confidence scores of all characters in the first character set.
[0090] Understandably, in the first set of character symbols obtained through the pre-defined model, each character has its own confidence level. This confidence level is calculated by the first model simultaneously for each character in the Mth set of character symbols. The confidence level represents the probability that the character matches the first input information; a higher confidence level indicates that the character better matches the true intent of the first input information. Therefore, after determining the first set of character symbols, the character with the highest confidence level among the multiple characters in the first set can be identified as the first target character.
[0091] Furthermore, after determining the first M-1 target characters, the determined M-1 target characters and the first input information are simultaneously input into the preset model, so that the preset model can calculate based on the first M-1 target characters and the first input information to determine the Mth character set. That is, the Mth target character of the first response statement to be generated exists in the Mth character set.
[0092] Furthermore, similar to the method for determining the first target character, the character with the highest confidence among the multiple characters in the set of characters matching the Mth character is determined as the Mth target character.
[0093] Understandably, by taking values from 2 to N for M, we can determine the second to Nth target characters. Finally, arranging the N target characters in the order they were generated yields the first response statement.
[0094] Furthermore, such as Figure 8 As shown, the effectiveness of the sentence generation method provided in this application is analyzed. Specifically, a sentence is input into a preset model, the preset model responds, and the answer is further determined from multiple responses based on the first prefix tree. The analysis can be performed from the following three aspects:
[0095] 1. Whether the request is within the domain: This refers to whether the exact answer can be found among the options. This dimension primarily verifies the model's ability to reject questions. For example, if the options are all city names, but the question asks about the weather, then the question is not within the domain. Note a special case: even if a rejection option is provided within the choices (e.g., "I don't know," "This is beyond the scope of the question," etc.), it is still considered outside the domain.
[0096] 2. Correctness of response: This refers to whether the response answers the question positively and with information. This dimension mainly verifies the model's understanding and knowledge capabilities.
[0097] 3. Response accuracy: This refers to whether the response strictly follows the prompt's requirements and is concise and direct. This dimension mainly verifies the model's ability to follow instructions.
[0098] The analysis results are shown in Table 1 below:
[0099] Table 1
[0100]
[0101]
[0102]
[0103] Based on the above analysis, it is evident that the restricted response scheme of this application can ensure that the response results conform to the required format and logic without altering the correctness, effectively improving the rejection capability of the dialogue process and further enhancing the accuracy of the response content.
[0104] In some embodiments, optionally, generating at least one first response statement based on the first input information and the first prefix tree includes: generating a first statement based on the first input information and the first prefix tree; obtaining the character type of the last character of the first statement; determining the first statement as a first response statement if the character type of the last character of the first statement is a first type; generating a (P+1)th statement based on the first input information, the Pth statement, and the first prefix tree if the character type of the last character of the Pth statement is a second type; wherein P is a positive integer; and determining the first statement to the (P+1)th statement as first response statements if the (P+1)th statement satisfies a preset condition.
[0105] In this embodiment, the first response statement may consist of only one first statement. Correspondingly, depending on the specific content of the first input information entered by the user, the first response statement may also include both a first statement and a second statement.
[0106] Specifically, such as Figure 6As shown, in the process of generating the first response statement, the first statement is generated based on the first input information and the first prefix tree. At this point, the character type of the last character of the first statement can be obtained. The character type can include the first type (EOS), which indicates that the current first response statement has been completed, that is, the response statement generation operation for the first input information has been completed, and the generation operation can be ended. In other words, if the character type of the last character of the first statement is the first type (EOS), it means that the current first response statement has been completed, and the first statement generated at this time is the first response statement that the user needs.
[0107] Correspondingly, the character type also includes a second type (BOS). A second type (BOS) indicates that the currently generated first statement has not fully expressed the user's first input information; that is, a second statement needs to be generated to ensure a complete representation of the user's first input information. During the generation of the second statement, it can be generated based on the first input information, the first response statement, and the first prefix tree. Furthermore, since both the second statement and the first response statement are based on the user's first input information, the first prefix tree corresponding to the first input information can be reused. Additionally, the generation process of the second statement is the same as that of the first response statement, and will not be repeated here.
[0108] Understandably, the character type of the last character of the previously generated statement determines whether further statement generation is needed. That is, if the last character of statement P is of type 2, then statement P+1 needs to be generated based on the first input information, statement P, and the first prefix tree; where P is a positive integer. Specifically, whether a third statement needs to be generated depends on the character type of the last character of the second statement. If the last character of the second statement is of type 2 (BOS), then a third statement needs to be generated. The same logic applies to the fourth statement.
[0109] Furthermore, if the preset conditions are met in statement P+1, it indicates that the response statement generation operation for the first input information has been completed, and the statement generation operation can be terminated. At this point, statements from the first statement to the P+1th statement can be determined as the required first response statement, thus completing the generation of the response statement.
[0110] The preset condition can be any of the following: the character type of the last character of the P+1 statement is type 1, the character type of the last character of the P+1 statement is neither type 1 nor type 2, or the value of P+1 is a preset value.
[0111] It is understandable that when the last character of the P+1 statement has the first character type, the generation operation of the response statement for the first input information can be determined directly based on the character type, and the generation operation can be ended.
[0112] Alternatively, if the last character of the (P+1)th statement is neither of the first type nor the second type, it can be determined that the response statement generation operation for the first input information has been completed, and the generation operation can be terminated. In other words, if the last character of the (P+1)th statement cannot indicate whether statement generation needs to continue, statement generation can be terminated.
[0113] Additionally, statement generation can also end when the value of P+1 is a preset value. That is, statement generation can end when the number of statements in the response to the first input information reaches a preset value.
[0114] According to one embodiment of this application, such as Figure 5 As shown, a method for generating statements is proposed, including:
[0115] Step S502: Obtain the first prefix tree corresponding to the first input information;
[0116] The first prefix tree is used to limit the generation space corresponding to the first input information;
[0117] Step S504: Generate at least one first response statement based on the first input information and the first prefix tree;
[0118] In this case, each character of the first reply statement is on the same branch of the first prefix tree;
[0119] Step S506: Output at least one first response statement;
[0120] Step S508: Obtain the second input information;
[0121] The second input information is input based on at least one first response statement;
[0122] Step S510: Determine the second prefix tree corresponding to the second input information based on the second input information and at least one first response statement;
[0123] The second prefix tree is used to limit the generation space corresponding to the second input information;
[0124] Step S512: Generate at least one second response statement based on the second input information and the second prefix tree;
[0125] Step S514: Output at least one second response statement.
[0126] In this embodiment, during actual operation, the user may perform multiple rounds of text input. That is, the user may input a second, third, or even fourth round of input information in response to a first reply statement corresponding to the first input information, thus initiating a multi-round dialogue scenario. After generating the first reply statement based on the first input information and the first prefix tree, the user then inputs a second reply statement in response to the received first reply statement, necessitating the generation of a second reply statement. At this point, the first prefix tree needs to be updated based on the first reply statement and the second input information; that is, a second prefix tree needs to be generated based on the first reply statement and the second input information.
[0127] In some embodiments, in a multi-turn dialogue scenario, after the user inputs information in each turn of the dialogue, a first prefix tree corresponding to that turn of the dialogue can be dynamically modeled based on the current node state. This first prefix tree is used to restrict the generation space of the answers in that turn of the dialogue (also known as the dynamic answer space). For example, if the first input information entered by the user in the current turn of the dialogue is related to device control, then a corresponding first prefix tree is generated based on the first input information, thereby restricting the answer to the first input information to the generation space corresponding to the first prefix tree.
[0128] like Figure 7 The multi-turn dialogue scenario shown can be dynamically modeled based on the dialogue graph. The dialogue graph includes multiple nodes and multiple edges, with each edge connecting two nodes. In a multi-turn dialogue, when the previous turn ends and the user inputs the first input information, addressing (i.e., finding nodes) can be performed using generative instruction tasks. In this case, the generative space corresponding to the first prefix tree obtained by dynamic modeling is the action space of the next reachable node. Alternatively, pathfinding (i.e., finding edges) can be performed using retrieval instruction tasks. In this case, the generative space corresponding to the first prefix tree obtained by dynamic modeling is the user intent space of the next connected edge.
[0129] Furthermore, based on the second input information and the second prefix tree, the second response statement can be generated. It is understood that the process of generating the second response statement based on the second input information and the second prefix tree is the same as the process of generating the first response statement based on the first input information and the first prefix tree, and will not be elaborated further here.
[0130] In some embodiments, optionally, obtaining the first prefix tree corresponding to the first input information includes: determining a generation space based on the first input information; and generating the first prefix tree corresponding to the first input information based on the generation space.
[0131] In this embodiment, a first prefix tree corresponding to the first input information can be dynamically generated for the first input information entered by the user.
[0132] Specifically, firstly, the generation space of the first response statement is determined based on the first input information. This generation space can be based on the scenario indicated by the first input information. For example, if the user's first input information is "What should I do if it's too hot?", it can be seen that the scenario indicated by the first input information is the control of home appliances. At this point, analysis can be performed based on this scenario. For example, before determining the first prefix tree, analysis can reveal that "you are a device control assistant that can convert user requests into control or query instructions for air conditioners, refrigerators, range hoods, or ovens." Therefore, based on the above analysis, the generation space for the user input "What should I do if it's too hot?" can be determined to be control instructions for appliances such as air conditioners and refrigerators. Further, based on the control or query instructions for appliances such as air conditioners and refrigerators, the first prefix tree corresponding to the first input information can be generated. Then, after being constrained by the generation space, the output statement is a control instruction for the air conditioner, such as "lower the air conditioner temperature" or "turn on the air conditioner," thus meeting the user's needs.
[0133] It's important to note that in traditional language models, if the generation space isn't defined—that is, if the response is simply based on the user's input "What should I do if it's too hot?"—it may not achieve the desired effect. For example, outputting statements like "It's too hot. Here are some ways to alleviate discomfort:\n\n 1. Keep the room well-ventilated: Open the windows to let fresh air in, reduce indoor humidity, and relieve discomfort.\n\n 2. Wear light clothing: Choose breathable and lightweight clothing" or "The air conditioner is broken, the air conditioner is broken, the air conditioner is broken… (repeatedly)" will not meet the user's needs.
[0134] Furthermore, the first input information includes prompts.
[0135] Specifically, the first input information can also include prompt information, that is, the first input information can also be the information input in the prompt function of the large language model. For example, the first input information is "You are a device control assistant that can convert user requests into control or query instructions for air conditioners, refrigerators, range hoods, or ovens. Input: What to do when it's too hot. Output:\n". When generating the response statement, the content of the response statement can be restricted according to the prompt content in the prompt information, that is, the generation space of the response statement can be restricted. It can be seen that by using the restricted generation technology of this application, and in conjunction with multiple prompt question types, it is possible to select the answer in a restricted space, which makes it easier to combine consistency technology to obtain a more stable output and reduce the difficulty of constructing input information. In other words, the restricted generation technology, combined with prompt engineering, is a "software and hardware approach" that can better generate results that conform to the target form and content in specific scenarios, making it easier to adapt to downstream applications. In addition, restricted generation can also alleviate the application's high dependence on model priors and prompt engineering to a certain extent.
[0136] In some embodiments, the first prefix tree may optionally include: at least one first branch, wherein the first branch corresponds to a control instruction type; and / or, at least one second branch, wherein the second branch corresponds to a non-control instruction type; and / or, at least one third branch, wherein the third branch corresponds to at least one implicit control instruction, the implicit control instruction including a recommended keyword.
[0137] In this embodiment, the first prefix tree can include at least three different types of branches, wherein the type corresponding to the first branch can be a control instruction type. That is, if the characters in the generated first response statement are in the first branch, the first response statement can be used to generate control instructions for the electrical equipment.
[0138] Among them, control commands include, but are not limited to: atomic control commands corresponding to smart devices, such as "turn on the air conditioner".
[0139] For dynamic atomic instructions corresponding to non-enumerated entities, such as the instruction "Reserve {Reservation Time|Duration}Air Conditioner {Operating Mode}{Deadline|Duration}", since time expressions cannot be statically exhaustively enumerated, it is necessary to dynamically construct the candidate sequence for the current step in conjunction with the coarse-grained entity recognition results of the original sentence. For example, if the user request is "Air conditioner heating for 3 hours and then turning off at 6 am tomorrow" or "Reserve air conditioner heating for me from 6 am to 9 am tomorrow", traditional entity recognition technology can easily extract the two time entities "6 am tomorrow" and "3 hours|9 am", but it is difficult to determine whether they correspond to reservation time or runtime. Using restricted generation technology, when generating the word "reservation" and then generating "reservation time", the optional generation path can be restricted to "6 am tomorrow" and "3 hours" based on the entity recognition results. By utilizing the understanding and generation capabilities of the large model, "6 am tomorrow" can be filled into the corresponding grammatical fragment, thereby generating a standard templated instruction.
[0140] The second branch can correspond to a non-control instruction. If the characters in the generated first response statement are in the second branch, the first response statement can be used to generate a non-control instruction statement. Correspondingly, in a scenario where electrical equipment is being controlled, if the characters in the first response statement are in the second branch, it indicates that the first response statement is a rejected instruction that cannot be recognized in this scenario.
[0141] The third branch can correspond to an implicit instruction type. When the characters in the generated first response statement fall within the third branch, the first response statement can be output to the recommendation system. This triggers the recommendation system to provide one or more recommendation instructions that fit the complex scenario, taking into account the home device environment. For example, if a user inputs "It's too hot in the bedroom," the first response statement can be generated based on the user's input. The first response statement contains implicit instructions such as "recommend" or "recommend you to use," and then the implicit instructions are output to the home smart system's recommendation system. The system then provides one or more recommendation instructions that fit the complex scenario, such as "Turn on the air conditioner to cool down and close the blackout curtains" if the bedroom has an air conditioner, or "Lower the air conditioner temperature and turn on the fan" if only the fan or air conditioner is on.
[0142] According to the second aspect of this application, such as Figure 9 As shown, a statement generation device 600 is proposed, comprising: an acquisition unit 602, configured to acquire a first prefix tree corresponding to a first input information, wherein the first prefix tree is used to limit the generation space corresponding to the first input information; a generation unit 604, configured to generate at least one first response statement based on the first input information and the first prefix tree, wherein each character of the first response statement is located on the same branch of the first prefix tree; and an output unit 606, configured to output at least one first response statement.
[0143] The statement generation method provided by this invention first obtains a first prefix tree corresponding to the user's first input information during the statement generation process. Then, it generates a first response statement corresponding to the first input information based on the first input information and the first prefix tree. Thus, during the generation of the first statement, the first response statement is generated according to the path defined by the first prefix tree, resulting in a first response statement that fully conforms to the required format and content. This facilitates the computer system's recognition of the generated first response statement to meet the user's needs.
[0144] Further, the generation unit 604 is specifically used to input the first input information into the preset model to generate the first character symbol set; if the first prefix tree includes at least one character from the first character symbol set, determine the first target character in the first character symbol set according to the first prefix tree; input the first input information and the determined M-1 target characters into the preset model to generate the Mth character symbol set; determine the Mth target character in the Mth character symbol set according to the first prefix tree; wherein, M is set to integers from 2 to N in sequence to determine the second to Nth target characters.
[0145] Furthermore, the generation unit 604 is specifically used to determine multiple characters to be confirmed that match the first prefix tree in the Mth character set; obtain the confidence level of the multiple characters to be confirmed; and determine the character with the highest confidence level among the multiple characters to be confirmed as the Mth target character.
[0146] Furthermore, the generation unit 604 is specifically used to determine the first target character based on the confidence of all characters in the first character set when the first prefix tree does not include any character in the first character set; input the first input information and the determined M-1 target characters into the preset model to generate the Mth character set; and determine the Mth target character based on the confidence of all characters in the Mth character set; wherein, M is set to integers from 2 to N to determine the second to Nth target characters.
[0147] Further, the generation unit 604 is specifically used to generate a first statement based on the first input information and the first prefix tree; the acquisition unit 602 is also used to acquire the character type of the last character of the first statement; the generation unit 604 is also used to determine the first statement as a first reply statement if the character type of the last character of the first statement is of the first type; and to generate the P+1 statement based on the first input information, the P statement and the first prefix tree if the character type of the last character of the P statement is of the second type; where P is a positive integer; and to determine the first statement to the P+1 statement as the first reply statement if the P+1 statement satisfies the preset conditions.
[0148] The preset conditions include any of the following: the character type of the last character of the P+1 statement is type 1; the character type of the last character of the P+1 statement is neither type 1 nor type 2; or the value of P+1 is a preset value.
[0149] Furthermore, the acquisition unit 602 is also used to acquire second input information, wherein the second input information is input based on at least one first response statement; the generation unit 604 is also used to determine a second prefix tree corresponding to the second input information based on the second input information and at least one first response statement, wherein the second prefix tree is used to limit the generation space corresponding to the second input information; generate at least one second response statement based on the second input information and the second prefix tree; and the output unit 606 is also used to output at least one second response statement.
[0150] Furthermore, the acquisition unit 602 is specifically used to determine the generation space based on the first input information; and to generate a first prefix tree corresponding to the first input information based on the generation space. The first input information includes prompt information.
[0151] According to a third aspect of this application, a statement generation apparatus is proposed, comprising: a processor and a memory, wherein the memory stores a program or instructions executable on the processor, and when the program or instructions are executed by the processor, the steps of the statement generation method as described in any of the above technical solutions are implemented.
[0152] The statement generation apparatus provided in this application includes a memory and a processor, and also includes a program or instructions stored in the memory. When the program or instructions are executed by the processor, they can implement the steps of the statement generation method of any of the above-described technical solutions. Therefore, the statement generation method has all the beneficial effects of the above-described statement generation methods, which will not be elaborated here.
[0153] According to a fourth aspect of this application, an electronic device is proposed, including a processor and a memory, the memory storing a program or instructions executable on the processor, the program or instructions, when executed by the processor, implementing the steps of the statement generation method as described in the above embodiments.
[0154] The electronic device provided in this application includes the steps of the statement generation method as described in the above embodiments, and therefore possesses all the beneficial effects of the statement generation method described above, which will not be repeated here.
[0155] According to a fifth aspect of this application, a readable storage medium is proposed, on which a program or instructions are stored, which, when executed by a processor, implement a method for generating statements as described in any of the above-described technical solutions.
[0156] The storage medium provided in this application stores a program or instructions. When the program or instructions are executed by a processor, they can implement the statement generation method as described in any of the above technical solutions. Therefore, the storage medium has all the beneficial effects of the above statement generation method, which will not be elaborated here.
[0157] According to a sixth aspect of this application, a computer program product is provided, comprising a computer program or instructions, which, when executed by a processor, implement the steps of the statement generation method as described in any of the above embodiments. Therefore, this computer program product possesses all the beneficial effects of the above-described statement generation method, which will not be elaborated further here.
[0158] According to a seventh aspect of this application, a chip is provided, comprising a program or instructions that, when executed by a processor, implement the steps of the statement generation method as described in any of the above embodiments. Therefore, this chip possesses all the beneficial effects of the aforementioned statement generation method, which will not be elaborated further here.
[0159] In the description of this specification, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance, unless otherwise expressly specified and limited. The terms "connection," "installation," and "fixing," etc., should be interpreted broadly. For example, "connection" can be a fixed connection, a detachable connection, or an integral connection; it can be a direct connection or an indirect connection through an intermediate medium. Those skilled in the art can understand the specific meaning of the above terms in this application according to the specific circumstances.
[0160] In the description of this specification, the terms "one embodiment," "some embodiments," "specific embodiment," etc., refer to a specific feature, structure, material, or characteristic described in connection with that embodiment or example, which is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0161] The above are merely preferred embodiments of this application and are not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for generating statements, characterized in that, include: Obtain the first prefix tree corresponding to the first input information, wherein the first prefix tree is used to limit the generation space corresponding to the first input information; Based on the first input information and the first prefix tree, at least one first response statement is generated, wherein each character of the first response statement is on the same branch of the first prefix tree; Output at least one of the first response statements; The step of generating at least one first response statement based on the first input information and the first prefix tree includes: Based on the first input information and the first prefix tree, N target characters are generated, wherein the N target characters are located on the same branch of the first prefix tree, and N is a positive integer; Arrange the N target characters according to their generation order to generate the first response statement; The step of generating N target characters based on the first input information and the first prefix tree includes: The first input information is input into the preset model to generate the first character set; If the first prefix tree includes at least one character from the first character set, then the first target character is determined from the first prefix tree and from the first character set. The first input information and the determined M-1 target characters are input into the preset model to generate the Mth character set; Based on the first prefix tree, the Mth target character is determined from the set of Mth character symbols; Let M take integers from 2 to N in sequence to determine the second target character to the Nth target character.
2. The generation method according to claim 1, characterized in that, The step of determining the Mth target character in the Mth character set based on the first prefix tree includes: In the Mth character set, a plurality of characters to be confirmed that match the first prefix tree are identified; Obtain the confidence level of multiple characters to be confirmed; The character with the highest confidence among the multiple characters to be confirmed is determined as the Mth target character.
3. The generation method according to claim 1, characterized in that, After inputting the first input information into the preset model to generate the first character set, the generation method further includes: If the first prefix tree does not contain any character from the first character conformation set, the first target character is determined based on the confidence level of all characters in the first character conformation set. The first input information and the determined M-1 target characters are input into the preset model to generate the Mth character set; The Mth target character is determined based on the confidence scores of all characters in the set of characters conforming to the Mth character. Let M take integers from 2 to N in sequence to determine the second target character to the Nth target character.
4. The generation method according to any one of claims 1 to 3, characterized in that, The step of generating at least one first response statement based on the first input information and the first prefix tree includes: Generate a first statement based on the first input information and the first prefix tree; Get the character type of the last character in the first statement; If the character type of the last character in the first statement is of type 1, then the first statement is determined to be the first reply statement; If the last character of statement P is of type 2, then statement P+1 is generated based on the first input information, statement P, and the first prefix tree; where P is a positive integer. If the P+1th statement meets the preset conditions, the first statement to the P+1th statement will be determined as the first response statement. The preset conditions include any one of the following: The character type of the last character in the P+1 statement is the first type; the character type of the last character in the P+1 statement is neither the first type nor the second type; and the value of P+1 is a preset value.
5. The generation method according to any one of claims 1 to 3, characterized in that, After outputting at least one of the first response statements, the generation method further includes: Obtain second input information, wherein the second input information is input based on at least one of the first response statements; Based on the second input information and at least one of the first response statements, a second prefix tree corresponding to the second input information is determined, wherein the second prefix tree is used to limit the generation space corresponding to the second input information; Based on the second input information and the second prefix tree, generate at least one second response statement; Output at least one of the second response statements.
6. The generation method according to any one of claims 1 to 3, characterized in that, The step of obtaining the first prefix tree corresponding to the first input information includes: The generation space is determined based on the first input information; The first prefix tree corresponding to the first input information is generated based on the generation space.
7. The generation method according to claim 6, characterized in that, The first input information includes prompt information.
8. The generation method according to any one of claims 1 to 3, characterized in that, The first prefix tree includes: At least one first branch, wherein the first branch corresponds to a control instruction type; and / or, At least one second branch, wherein the second branch corresponds to a non-control instruction type; and / or, At least one third branch, wherein the third branch corresponds to at least one implicit control instruction, the implicit control instruction including recommended keywords.
9. A statement generation apparatus, characterized in that, include: The acquisition unit is used to acquire the first prefix tree corresponding to the first input information, wherein the first prefix tree is used to limit the generation space corresponding to the first input information; The generation unit is configured to generate at least one first response statement based on the first input information and the first prefix tree, wherein each character of the first response statement is on the same branch of the first prefix tree; An output unit is used to output at least one of the first response statements; The step of generating at least one first response statement based on the first input information and the first prefix tree includes: Based on the first input information and the first prefix tree, N target characters are generated, wherein the N target characters are located on the same branch of the first prefix tree, and N is a positive integer; Arrange the N target characters according to their generation order to generate the first response statement; The step of generating N target characters based on the first input information and the first prefix tree includes: The first input information is input into the preset model to generate the first character set; If the first prefix tree includes at least one character from the first character set, then the first target character is determined from the first prefix tree and from the first character set. The first input information and the determined M-1 target characters are input into the preset model to generate the Mth character set; Based on the first prefix tree, the Mth target character is determined from the set of Mth character symbols; Let M take integers from 2 to N in sequence to determine the second target character to the Nth target character.
10. A statement generation apparatus, characterized in that, include: A processor and a memory, the memory storing a program or instructions executable on the processor, the program or instructions, when executed by the processor, implementing the steps of the statement generation method as described in any one of claims 1 to 8.
11. An electronic device, characterized in that, It includes a processor and a memory, the memory storing a program or instructions that can run on the processor, the program or instructions being executed by the processor to implement the steps of the statement generation method as described in any one of claims 1 to 8.
12. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the statement generation method as described in any one of claims 1 to 8.
13. A computer program product, comprising a computer program or instructions, characterized in that, When the computer program or instructions are executed by the processor, they implement the steps of the statement generation method as described in any one of claims 1 to 8.
14. A chip, characterized in that, The chip includes a program or instructions that, when the chip is running, implement the steps of the statement generation method as described in any one of claims 1 to 8.