Domain-specific language response method, related device and medium
By introducing guidance instructions and constraint word sets of domain-specific language grammatical rules into the large language model, adjusting the candidate word scores, and generating domain-specific language responses that conform to the expected format, the problem of inaccurate generation results of the large language model is solved, and the generation efficiency and accuracy are improved.
Patent Information
- Application Number
- CN202410283932.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-12
- Publication Date
- 2025-09-12
AI Technical Summary
The results generated by large language models cannot be guaranteed to conform to the expected format, resulting in high development costs and poor accuracy. Existing technologies have high error rates and low efficiency.
Generate guidance instructions for predicted words through domain-specific language grammatical rules, use the constraint word set to adjust the candidate word score, obtain a second score that conforms to the domain-specific language grammatical rules, and generate a domain-specific language response.
Improves the accuracy and efficiency of large language models in generating results that conform to the expected format, reducing the need for error verification.
Smart Images

Figure CN120633893A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence, and in particular to a domain-specific language response method, related devices, and media. Background Art
[0002] Large language models are now widely used. They possess powerful language generation capabilities. They can perform tasks based on natural language understanding and, based on the results, develop further applications. However, when developing applications based on the results of large language models, developers encounter the difficulty of outputting results in any language. These results are probabilistic and cannot guarantee that they will conform to the expected format, leading to high subsequent development costs. While some techniques exist to ensure that the output of large language models conforms to the expected format, these techniques have a high error rate. Once an error occurs, each generated character must be verified from scratch to ensure it conforms to the expected format, resulting in poor accuracy and low efficiency. Summary of the Invention
[0003] The embodiments of the present disclosure provide a domain-specific language response method, related devices, and media, which can improve the accuracy and efficiency of large language models in generating results that conform to the expected format.
[0004] According to one aspect of the present disclosure, a domain-specific language response method is provided, comprising:
[0005] Input the target query into the candidate word score prediction model to obtain the first scores of multiple candidate words;
[0006] generating, based on the domain-specific language grammatical rules and the last word predicted in the domain-specific language response, a guidance instruction for the predicted word, for indicating the domain-specific language grammatical constraints that the predicted word needs to comply with;
[0007] generating a constraint word set based on the guiding instruction;
[0008] Using the constraint word set, adjusting the first scores of the plurality of candidate words to obtain second scores of the plurality of candidate words;
[0009] Obtaining predicted probabilities of the plurality of candidate words based on the second scores of the plurality of candidate words;
[0010] Determining the predicted word based on the prediction probabilities of the plurality of candidate words;
[0011] The domain-specific language response is generated based on a plurality of the determined predicted words.
[0012] According to one aspect of the present disclosure, there is provided a domain-specific language response device, comprising:
[0013] A first input unit is configured to input a target query into a candidate word score prediction model to obtain first scores of multiple candidate words;
[0014] a first generating unit, configured to generate a guiding instruction for a predicted word based on a domain-specific language grammatical rule and a previous word predicted in the domain-specific language response, the guiding instruction being configured to indicate a domain-specific language grammatical constraint that the predicted word needs to comply with;
[0015] A second generating unit, configured to generate a constraint word set based on the guiding instruction;
[0016] a first adjusting unit, configured to adjust the first scores of the plurality of candidate words by using the constraint word set to obtain second scores of the plurality of candidate words;
[0017] a probability prediction unit, configured to obtain predicted probabilities of the plurality of candidate words based on the second scores of the plurality of candidate words;
[0018] a first determining unit, configured to determine the predicted word based on the prediction probabilities of the plurality of candidate words;
[0019] The second generating unit is configured to generate the domain-specific language response based on the plurality of determined predicted words.
[0020] Optionally, the first generating unit is specifically configured to:
[0021] generating a guiding instruction generation program segment based on the domain-specific language grammar rules, wherein the guiding instruction generation program segment includes a first statement, and the first statement is used to generate the guiding instruction based on the domain-specific language grammar rules and the predicted previous word;
[0022] Generate a program segment through the guide instruction to receive the predicted previous word;
[0023] The first statement is executed to generate the guiding instruction based on the domain-specific language grammar rule and the previous word.
[0024] Optionally, the first determining unit is specifically configured to:
[0025] Acquire a sampling program segment, wherein the sampling program segment includes a second statement, and the second statement is used to return the predicted word to the guidance instruction generation program segment;
[0026] Determining the predicted word based on the prediction probabilities of the plurality of candidate words through the sampling program segment;
[0027] The second statement is executed to return the predicted word to the guidance instruction generation program segment, so that the guidance instruction generation program segment generates the guidance instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word.
[0028] Optionally, the second sentence is further used to store the predicted word in a context memory as a context;
[0029] The first determining unit is further configured to:
[0030] Execute the second statement to return the predicted word to the guide instruction generation program segment and the context memory, so that the guide instruction generation program segment generates the guide instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word, and the candidate word score prediction model obtains the first scores of multiple candidate words based on the target query and the context in the context memory.
[0031] Optionally, the domain-specific language response device further includes:
[0032] a first query unit, configured to query the previous context storage area if the guidance instruction indicates that the predicted word should be a separator;
[0033] The fourth generating unit is used to perform summary operation on the above text, generate a summary of the above text, and replace the above text in the above text storage area with the summary if the above text in the above text storage area exceeds a predetermined size, and the size of the summary is smaller than the predetermined size.
[0034] Optionally, the constraint word set includes a valid word set and an invalid word set; the domain-specific language grammar constraint indicated by the guidance instruction includes a forward constraint and a reverse constraint;
[0035] The second generating unit is specifically configured to:
[0036] Based on the forward constraint indicated by the guidance instruction, obtaining valid words matching the forward constraint from a candidate word set, and generating the valid word set based on the valid words;
[0037] Based on the reverse constraint indicated by the guidance instruction, invalid words matching the reverse constraint are obtained from a candidate word set, and the invalid word set is generated based on the invalid words.
[0038] Optionally, the first adjustment unit is specifically configured to:
[0039] Converting the valid word set into a valid word identification set, and converting the invalid word set into an invalid word identification set;
[0040] The first scores of the plurality of candidate words are adjusted using the valid word identification set and the invalid word identification set to obtain the second scores of the plurality of candidate words.
[0041] Optionally, the first adjustment unit is further configured to:
[0042] For the candidate word corresponding to the valid word identifier in the valid word identifier set among the plurality of candidate words, increasing the first score to obtain the second score;
[0043] For the candidate words among the multiple candidate words corresponding to the invalid word identifier in the invalid word identifier set, the first score is reduced to obtain the second score.
[0044] Optionally, the valid word identification set further includes a first matching degree between the valid word and the positive constraint, and the invalid word identification set further includes a second matching degree between the invalid word and the negative constraint;
[0045] The first adjustment unit is further configured to:
[0046] For a candidate word among the plurality of candidate words corresponding to a valid word identifier in the valid word identifier set, increasing the first score based on the first matching degree of the valid word in the valid word identifier set to obtain the second score;
[0047] The first adjustment unit is further configured to:
[0048] For the candidate words among the multiple candidate words corresponding to the invalid word identifier in the invalid word identifier set, the first score is reduced based on the second matching degree of the invalid word in the invalid word identifier set to obtain the second score.
[0049] Optionally, the first adjustment unit is further configured to:
[0050] For the candidate words corresponding to the valid word identifier in the valid word identifier set among the plurality of candidate words, obtaining a first maximum increase value;
[0051] determining a first increase value based on the first maximum increase value and the first matching degree;
[0052] determining the second score based on the first score and the first increase value;
[0053] The first adjustment unit is further configured to:
[0054] For the candidate words corresponding to the invalid word identifier in the invalid word identifier set among the plurality of candidate words, obtaining a first maximum reduction value;
[0055] determining a first reduction value based on the first maximum reduction value and the second matching degree;
[0056] Based on the first score and the first reduction value, the second score is determined.
[0057] Optionally, the second generating unit is further configured to:
[0058] For each candidate word in the candidate word set, determining the first matching degree between the candidate word and the positive constraint;
[0059] If the first matching degree is greater than a first threshold, determining that the candidate word is the valid word;
[0060] Based on the effective words, generating the effective word set;
[0061] The second generating unit is further configured to:
[0062] For each candidate word in the candidate word set, determining the second matching degree between the candidate word and the reverse constraint;
[0063] If the second matching degree is greater than a second threshold, determining that the candidate word is the invalid word;
[0064] The invalid word set is generated based on the invalid words.
[0065] Optionally, the third generating unit is specifically configured to:
[0066] If the predicted word is a sentence terminator, obtaining the first predicted word determined after the target query is input into the candidate word score prediction model;
[0067] The plurality of predicted words between the first predicted word and the sentence terminator are connected to form the domain-specific language response.
[0068] Optionally, the domain specific language includes a plurality of types of the domain specific language, each type corresponding to one of a plurality of guiding instruction generation program segment instances;
[0069] The first generating unit is specifically configured to:
[0070] If the predicted last word is of the type of the domain-specific language, calling the guiding instruction generation program segment instance corresponding to the type among a plurality of guiding instruction generation program segment instances;
[0071] The program segment instance is generated by calling the guide instruction, and based on the domain-specific language grammar rules of the type and the predicted previous word, the guide instruction of the predicted word is generated.
[0072] Optionally, each of the types corresponds to one of the post-processor instances in a plurality of post-processor instances;
[0073] The first adjustment unit is specifically configured to:
[0074] Determining the type of the domain-specific language corresponding to the constraint word set;
[0075] Calling the post-processor instance corresponding to the type among the plurality of post-processor instances;
[0076] By calling the post-processor instance and utilizing the constraint word set, the first scores of the plurality of candidate words are adjusted to obtain the second scores of the plurality of candidate words, wherein different post-processor instances have different ways and parameters for adjusting the first scores.
[0077] Optionally, the domain-specific language response device further includes:
[0078] A first deactivation unit is configured to deactivate the guiding instruction generation program segment instance corresponding to the type if the predicted last word is a code segment terminator of the type;
[0079] The first output unit is used to output a type code segment end mark.
[0080] Optionally, the domain-specific language response device further includes:
[0081] a second deactivation unit, configured to deactivate a plurality of instances of the guiding instruction generation program segment if the predicted last word is a domain-specific language response terminator;
[0082] The second output unit is configured to output a domain specific language response end tag.
[0083] Optionally, the domain-specific language response device further includes:
[0084] A first display unit, configured to display a target query input area on the response interaction interface;
[0085] A first receiving unit is configured to receive the target query in the target query input area.
[0086] Optionally, the response interaction interface further includes a domain-specific language response enabling control,
[0087] The domain-specific language response device further includes:
[0088] a probability generating unit, configured to obtain predicted probabilities of the plurality of candidate words based on the first scores of the plurality of candidate words if the domain-specific language response enabling control is off;
[0089] a second determining unit, configured to determine the predicted word based on the prediction probabilities of the plurality of candidate words;
[0090] A fifth generating unit is configured to generate a response based on the plurality of determined predicted words.
[0091] Optionally, the domain-specific language response device further includes:
[0092] The second display unit is used to display the title decomposition query activation control on the response interaction interface;
[0093] a third display unit, configured to display the title decomposition query input area in response to activation of the title decomposition query activation control;
[0094] The second receiving unit is configured to receive the target query of the title decomposition formula in the title decomposition formula query input area.
[0095] Optionally, the domain-specific language response device further includes:
[0096] a pausing unit, configured to suspend the execution of the guiding instruction generating program segment;
[0097] The recovery unit is used to recover the execution of the guidance instruction generation program segment when receiving the predicted word returned.
[0098] According to one aspect of the present disclosure, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the domain-specific language response method as described above when executing the computer program.
[0099] According to one aspect of the present disclosure, a computer-readable storage medium is provided, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the domain-specific language response method as described above is implemented.
[0100] According to one aspect of the present disclosure, a computer program product is provided. The computer program product includes a computer program. The computer program is read and executed by a processor of a computer device, so that the computer device executes the domain-specific language response method as described above.
[0101] When a typical large language model generates a response, it first obtains scores for multiple candidate words, then determines the probabilities of the multiple candidate words based on the scores, and then determines a predicted word based on the probabilities to generate a response. This response may or may not conform to the expected format. The disclosed embodiment generates a guide instruction for the predicted word based on the domain-specific language grammar rules and the previous word predicted in the domain-specific language response, and then generates a constrained word set based on the guide instruction. This constrained word set reflects the situation of words that conform or do not conform to the domain-specific language grammar rules (expected format). This constrained word set is used to adjust the first scores of the multiple candidate words generated by the large language model to obtain a second score. The second score reflects the situation of each candidate word after being constrained by the domain-specific language grammar rules (expected format). Using the second score instead of the first score to obtain the predicted probability and generate the final domain-specific language response ensures that the resulting domain-specific language response reflects the constraints of the domain-specific language grammar rules, thereby improving the accuracy of the large language model in generating results that conform to the expected format. Since the accuracy of each predicted word in the generated domain-specific language response is very high, there is no need for full verification after an error occurs, which improves generation efficiency.
[0102] Other features and advantages of the present disclosure will be described in the following description, and in part will become apparent from the description, or will be understood by practicing the present disclosure. The purposes and other advantages of the present disclosure can be realized and obtained by the structures particularly pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0103] The accompanying drawings are used to provide a further understanding of the technical solution of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the technical solution of the present disclosure and do not constitute a limitation to the technical solution of the present disclosure.
[0104] Figure 1 is a system architecture diagram of the domain-specific language response method of an embodiment of the present disclosure;
[0105] Figure 2A and Figure 2B This is a schematic diagram of an interface of a code auto-completion tool using the domain-specific language response method provided by an embodiment of the present disclosure;
[0106] Figure 2C This is a schematic diagram of an interface for applying the domain-specific language response method provided by an embodiment of the present disclosure to an intelligent operator;
[0107] Figure 2D and Figure 2E This is a schematic diagram of an interface of an intelligent writing assistant using the domain-specific language response method provided by an embodiment of the present disclosure;
[0108] Figure 2FThis is a schematic diagram of an interface for applying the domain-specific language response method provided by an embodiment of the present disclosure to a tool for guiding JSON generation;
[0109] Figure 3 is a main flow chart of a domain-specific language response method according to an embodiment of the present disclosure;
[0110] Figure 4A and Figure 4B is a schematic diagram of an overall implementation of a method for generating a domain-specific language sentence according to an embodiment of the present disclosure;
[0111] Figure 5 yes Figure 3 Step 320 generates a flow chart of the boot instructions;
[0112] Figure 6 is a schematic diagram of an implementation of a method for generating a domain-specific language sentence according to an embodiment of the present disclosure;
[0113] Figure 7 is a flow chart of a method for generating a domain specific language sentence in the case where the previous word is a type code segment terminator;
[0114] Figure 8 yes Figure 7 A schematic diagram of domain-specific language sentence generation in [1].
[0115] Figure 9 is a flow chart of a method for generating a domain specific language sentence when the previous word is a domain specific language response terminator;
[0116] Figure 10 yes Figure 3 Another flow chart of generating guidance instructions in step 320;
[0117] Figure 11 yes Figure 10 A schematic diagram of generating boot instructions in ;
[0118] Figure 12 yes Figure 10 A flow chart of pausing and resuming the execution of the boot instruction generation program segment after step 1030;
[0119] Figure 13 yes Figure 3 Step 330 generates a flow chart of the constraint word set;
[0120] Figure 14 yes Figure 13 A schematic diagram of generating a constrained word set;
[0121] Figure 15 yes Figure 13A flow chart for generating valid word sets and invalid word sets;
[0122] Figure 16 yes Figure 3 A flow chart of obtaining a second score in step 340;
[0123] Figure 17 yes Figure 16 A flow chart of obtaining a second score in step 1620;
[0124] Figure 18 yes Figure 17 A schematic diagram of the second score obtained;
[0125] Figure 19 yes Figure 17 A flowchart of steps 1710 and 1720 obtaining a second score;
[0126] Figure 20 yes Figure 19 A flowchart of steps 1910 and 1920 obtaining a second score;
[0127] Figure 21 yes Figure 3 Another flow chart of obtaining a second score in step 340;
[0128] Figure 22 yes Figure 3 A flow chart of determining a predicted word in step 360;
[0129] Figure 23 yes Figure 22 A schematic diagram of determining predicted words in ;
[0130] Figure 24 yes Figure 22 A flowchart of executing the second statement in step 2230;
[0131] Figure 25 It is a flow chart of a method for generating domain-specific language sentences when the predicted word is a separator;
[0132] Figure 26 yes Figure 25 A schematic diagram of generating domain-specific language sentences in [1].
[0133] Figure 27 yes Figure 3 Step 370 generates a flow chart of the domain specific language;
[0134] Figure 28 It is a flow chart for receiving target queries through the response interaction interface;
[0135] Figure 29is a flow chart for generating responses when the domain-specific language response enable control is turned off;
[0136] Figure 30 It is a flow chart for receiving a title-decomposed target query through a response interaction interface;
[0137] Figure 31 This is another interface diagram of the domain-specific language response method provided by the embodiment of the present disclosure applied to the JSON generation tool.
[0138] Figure 32 It is an implementation detail diagram of the domain-specific language response method of an embodiment of the present disclosure.
[0139] Figure 33 is a module diagram of a domain-specific language response device according to an embodiment of the present disclosure;
[0140] Figure 34 According to the embodiment of the present disclosure Figure 3 The terminal structure diagram of the domain specific language response method shown;
[0141] Figure 35 According to the embodiment of the present disclosure Figure 3 The server structure diagram of the domain-specific language response method shown. DETAILED DESCRIPTION
[0142] In order to make the purpose, technical solutions and advantages of the present disclosure more clearly understood, the present disclosure is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present disclosure and are not intended to limit the present disclosure.
[0143] Before further explaining the embodiments of the present disclosure in detail, the nouns and terms involved in the embodiments of the present disclosure are explained. The nouns and terms involved in the embodiments of the present disclosure are subject to the following interpretations:
[0144] A Domain-Specific Language (DSL) is a computer language that focuses on a specific application domain. It is a formal language for a specific domain that can be accurately parsed into data structures by computer programs and used in program execution. DSLs can use custom languages or the syntax of other languages, such as XML, SQL, JSON, and Markdown.
[0145] JSON (JavaScript Object Notation): A lightweight data exchange format that's easy for humans to read and write, and can be used to exchange data between multiple languages. It's also easy for machines to parse and generate data. JSON can be used as a DSL.
[0146] Markdown: A lightweight markup language that can be used to add formatting elements to plain text documents. It can be written using a regular text editor and uses a simple markup syntax to format plain text content. It can be mixed with Hypertext Markup Language (HTML).
[0147] A language model (LM) is a probabilistic model used to model natural language. Simply put, a language model estimates the probability of a given word sequence occurring in the real world. This model plays a key role in many natural language processing applications, such as machine translation, speech recognition, and text generation.
[0148] Large Language Model (LLM): A deep learning model trained on massive amounts of text data. It not only generates natural language text but also deeply understands the meaning of the text and can handle various natural language tasks such as text summarization, question answering, and translation.
[0149] Large language models are now widely used. They possess powerful language generation capabilities. They can perform tasks based on natural language understanding and, based on the results, develop further applications. However, when developing applications based on the results of large language models, developers encounter the difficulty of outputting results in any language. These results are probabilistic and cannot guarantee that they will conform to the expected format, leading to high subsequent development costs. While some techniques exist to ensure that the output of large language models conforms to the expected format, these techniques have a high error rate. Once an error occurs, each generated character must be verified from scratch to ensure it conforms to the expected format, resulting in poor accuracy and low efficiency.
[0150] Based on this, embodiments of the present disclosure provide a domain-specific language response method, related devices, and media. The domain-specific language response method provided by embodiments of the present disclosure can improve the accuracy and efficiency of large language models in generating results that conform to the expected format.
[0151] System architecture and scenario description of the application of the embodiments of the present disclosure
[0152] Figure 11 is a system architecture diagram for the domain-specific language response method according to an embodiment of the present disclosure, which includes a target terminal 110, the Internet 120, a gateway 130, and a server 140.
[0153] The object terminal 110 is a device used to display the generated domain-specific language response for viewing by the object, and the object can input the target query through the object terminal 110. It can be a desktop computer, laptop computer, PDA (personal digital assistant), mobile phone, vehicle-mounted terminal, home theater terminal, dedicated terminal, digital tablet, etc. In addition, it can be a single device or a collection of multiple devices. For example, multiple devices connected via a local area network and sharing a common display device to work together constitute a terminal. The terminal can also communicate with the Internet 120 in a wired or wireless manner to exchange data.
[0154] Server 140 is a computer system that provides domain-specific language response services to target terminals 110. Compared to target terminals 110, server 140 has higher requirements in terms of stability, security, and performance. Server 140 can be a single high-performance computer within a network platform, a cluster of multiple high-performance computers, a portion of a single high-performance computer (e.g., a virtual machine), or a combination of portions of multiple high-performance computers (e.g., virtual machines). Server 140 can also communicate with the internet 120 via wired or wireless means to exchange data.
[0155] The embodiments of the present disclosure can be applied in various scenarios, such as Figure 2A and Figure 2B The interface diagram of the code automatic completion tool shown in the figure is as follows: Figure 2C The interface diagram of the intelligent operator shown in FIG. Figure 2D and Figure 2E The interface diagram of the intelligent writing assistant shown in FIG. Figure 2F The following is a schematic diagram of the interface of the boot JSON generation tool.
[0156] like Figure 2A As shown, the object can write the code in the input code display area and enter the code "{"key"}", and the code automatic completion tool constructed based on the domain-specific language response method provided by the embodiment of the present disclosure processes the input code and completes the input code to obtain the completed code {"key":, and displays it in the completed code display area. In addition, refer to Figure 2BThe user can also enter the main code in the input code display area, and the code auto-completion tool will then complete the code between the code segments. The completed code is displayed in the completed code display area and conforms to the grammatical rules of the input code. It can be clearly seen that this code auto-completion tool can ensure that the completed code conforms to the code's own grammar. Compared with related technologies, it does not require the user to repair the completed code.
[0157] Figure 2C This is a schematic diagram of the interface of an intelligent operator built using the domain-specific language provided by an embodiment of the present disclosure. A subject can enter their needs, such as "processing XX service," in the demand input display area. The intelligent operator processes the subject's input, correctly calling relevant functions and generating a corresponding interface, such as "XX interface" for XX service, allowing the subject to process the relevant service on that interface.
[0158] Figure 2D and Figure 2E This is a schematic diagram of the interface of an intelligent writing assistant built based on the domain-specific language provided by the embodiment of the present disclosure. Figure 2D The content in the input text display area is the text input by the object, specifically "AA and BB go to celebrate CC's ancestor's birthday". After being processed by the intelligent writing assistant, the writing result is generated. The writing result is referenced Figure 2D The content in the writing results display area in the . It's clear that the Smart Writing Assistant has expanded the input text and corrected typos and misspellings. In addition, the Smart Writing Assistant can also provide grammatical suggestions, intelligent rewriting, and intelligent translation for the input text.
[0159] Reference Figure 2E , the subject enters his own requirement "generate a recipe" in the input text display area, and the intelligent writing assistant generates a recipe for "vanilla cream baked potatoes" according to the subject's requirement and displays it in the writing result display area.
[0160] Figure 2F This is a diagram of the interface for the JSON generation tool. A user can enter their query, "Generate a recipe," in the target query input area. By turning on the Domain-Specific Language (DSL) response enable control and clicking the Generate button, the tool generates a "Vanilla Cream Baked Potatoes" recipe based on their query, conforming to the JSON syntax.
[0161] It should be understood that the above content only illustrates some application scenarios of the present disclosure. The business scenarios to which the present disclosure can be applied may include but are not limited to the specific embodiments listed above.
[0162] General description of the embodiments of the present disclosure
[0163] It should be emphasized that the embodiments of the present disclosure are applicable to a variety of application scenarios, such as Figure 2A and Figure 2B The code auto-completion tool shown, Figure 2C The intelligent operator shown, Figure 2D and Figure 2E The intelligent writing assistant shown, Figure 2F The illustrated guide JSON generation tool and other scenarios. When generating a response, the large language model in the related art first obtains scores for multiple candidate words, obtains probabilities of the multiple candidate words based on the scores, and then determines the predicted words based on the probabilities to generate a response. This response may or may not conform to the expected format. Some embodiments of the present disclosure provide a domain-specific language response method, related devices, and media, which can improve the accuracy and efficiency of the large language model in generating results that conform to the expected format.
[0164] A domain-specific language response method processes an input target query to generate a domain-specific language response corresponding to the target query. This domain-specific language response method is applicable to various types of target queries, which can be in any domain-specific language or a natural language. The format of the target query does not affect the format of the generated domain-specific language response. This domain-specific language response method can improve the accuracy and efficiency of large language models in generating results that conform to the expected format.
[0165] The domain-specific language response method of the embodiment of the present disclosure may be executed on the target terminal 110 , or on the server 140 , or partially on the target terminal 110 and partially on the server 140 .
[0166] like Figure 3 As shown, according to one embodiment of the present disclosure, the domain-specific language response method includes:
[0167] Step 310: Input the target query into the candidate word score prediction model to obtain first scores of multiple candidate words;
[0168] Step 320: Based on the domain-specific language grammar rules and the last word predicted in the domain-specific language response, generate a guidance instruction for the predicted word, which is used to indicate the domain-specific language grammar constraints that the predicted word needs to comply with;
[0169] Step 330: Generate a constraint word set based on the guidance instruction;
[0170] Step 340: Using the constraint word set, adjust the first scores of the plurality of candidate words to obtain second scores of the plurality of candidate words;
[0171] Step 350: Obtain predicted probabilities of the multiple candidate words based on the second scores of the multiple candidate words;
[0172] Step 360: Determine a predicted word based on the prediction probabilities of the multiple candidate words;
[0173] Step 370: Generate a domain-specific language response based on the multiple determined predicted words.
[0174] Steps 310 to 370 are described in detail below.
[0175] In step 310 , the target query is input into a candidate word score prediction model to obtain first scores of multiple candidate words.
[0176] The target query refers to the query data received by the candidate word score prediction model. The target query can be object input data or data generated based on object operations. The target query can be natural language or any form of domain-specific language. The target query can be in the same domain-specific language as the expected domain-specific language response, or it can be in another type of domain-specific language.
[0177] The candidate word score prediction model is a model that predicts the first score of each candidate word in the response corresponding to the target query. The candidate word score prediction model is a language model, which can specifically be a neural network language model (NNLM). As a core component of the natural language processing system, the language model can provide a probabilistic representation of word representations and word sequences. The neural network language model introduces a neural network into the language model, thereby overcoming the dimensionality limitation and improving the performance of the traditional language model, thereby making the obtained first score of each candidate word more accurate.
[0178] The first score is the result of processing the target query based on the candidate word score prediction model. The first score represents the probability of each candidate word being a predicted word and also represents the probability of each candidate word appearing in the answer. The higher the first score, the greater the probability of the candidate word being a predicted word.
[0179] Reference Figure 2F , the target query is "generate a recipe", if the previous predicted word generated at the current moment is ""name":", the target query is input into the candidate word score prediction model, and multiple candidate words are obtained, such as "vanilla", ""vanilla", "umbrella", ""microwave oven", etc. Among them, the first score of "vanilla" is 80, the first score of ""vanilla" is 70, and the first scores of "umbrella" and ""microwave oven" are 20.
[0180] In step 320 , based on the domain-specific language grammar rules and the last word predicted in the domain-specific language response, a guidance instruction for the predicted word is generated to indicate the domain-specific language grammar constraints that the predicted word needs to comply with.
[0181] Domain-specific language grammar rules usually refer to the grammatical rules that a domain-specific language needs to follow. In the domain-specific language response method, domain-specific language grammar rules refer to the grammatical rules followed by the domain-specific language corresponding to the expected generated domain-specific language response. For example, Figure 2F As shown, when an object is guided by a JSON generation tool and expects to generate a JSON result, it expects to receive a DN-formatted response in the JSON format. The DN-formatted grammar rules are the grammatical rules that the JSON language must follow. Furthermore, the DN-formatted response can be in other languages, such as XML and SQL. Therefore, when generating the DN-formatted response, the DN-formatted grammar rules can be set based on the DN-formatted response.
[0182] It should be noted that the domain-specific language grammar rules can also be set as needed, and can be set to any structure that follows the context-free grammar (CFG). The domain-specific language grammar rules can be specifically expressed through a series of productions, or through extended Backus-Naur Form (EBNF), which is not limited to domain-specific languages such as strings, numbers, arrays, objects, and terminators (false / true / null). In addition, the domain-specific language grammar rules can also be specifically set to generate any recursively enumerable language. For example, for Figure 2C The intelligent operator shown displays the XX business interface by calling a function, and the function is specifically a domain-specific language response generated based on the object input "handle XX business". Then the domain-specific grammar rules set each business corresponding to its corresponding interface call function.
[0183] The guidance instruction corresponds to the domain-specific language response, which is the instruction information used to guide the generation of each predicted word in the domain-specific language response. The guidance instruction is specifically a restriction instruction. The restriction instruction refers to an instruction to restrict the generated characters, that is, the predicted words. The restriction instruction contains restriction information of the predicted words to be generated, such as the predicted word to be generated is a certain character, the predicted word to be generated should be in a certain range, the predicted word to be generated cannot be a certain character, and the predicted word to be generated should not be in a certain range. The guidance instruction is generated based on the domain-specific language grammar rules, and the restriction information given by the guidance instruction complies with the domain-specific language grammar rules.
[0184] The predicted previous word is the word preceding the predicted word to be generated in the domain-specific language response. When the predicted word to be generated is the first word in the domain-specific language response, the predicted previous word is set to null.
[0185] Domain-specific language grammatical constraints refer to the constraints that the predicted words need to follow, which constrains which characters the predicted words can and cannot contain. For example, Figure 2F In the JSON guidance generation tool shown, domain-specific language grammatical constraints are used to constrain predicted words to conform to JSON grammar rules and to exclude characters that conform to other grammar rules, such as XML and SQL. Therefore, the constraints can also be considered as restrictions on the predicted words indicated by the guidance instructions. In other words, guidance instructions indicate the domain-specific language grammatical constraints that the predicted words must follow.
[0186] Reference Figure 2F The domain-specific language grammar rules are JSON. If the previous predicted word generated at the current moment is "name":", then the domain-specific language grammar constraints indicated by the guidance instructions are used to restrict the predicted word to conform to the JSON grammar, that is, the predicted word is a number or a word starting with "".
[0187] In step 330 , a constraint word set is generated based on the guidance instruction.
[0188] The constraint word set corresponds to the predicted word and is a set of multiple candidate words. The constraint word set at least includes candidate words that conform to the grammatical rules of the domain-specific language. In addition, the constraint word set may also include candidate words that do not conform to the grammatical rules of the domain-specific language.
[0189] Reference Figure 2FThe domain-specific language grammar rules are JSON. If the last predicted word generated at the current moment is "name":", and multiple candidate words are "vanilla", "vanilla", "umbrella", and "microwave oven", then the constrained word set that conforms to the domain-specific language grammar rules includes "vanilla" and "microwave oven", and the constrained word set that does not conform to the domain-specific language grammar rules includes "vanilla" and "umbrella".
[0190] In step 340 , the first scores of the plurality of candidate words are adjusted using the constraint word set to obtain second scores of the plurality of candidate words.
[0191] The second score is the result of adjusting the first score using the constraint word set. The second score of each candidate word not only includes the score information given by the candidate word score model, but also includes the constraint information given by the domain-specific language grammar rules.
[0192] It should be noted that, when processing the target query based on the candidate word score prediction model, the candidate words corresponding to the multiple first scores obtained may be words that conform to the domain-specific language grammar rules, that is, the expected format, or may be words that do not conform to the domain-specific language grammar rules. Even the first score of one word that does not conform to the domain-specific language grammar rules may be higher than all words that conform to the domain-specific language grammar rules. Therefore, if the prediction probability and predicted word are directly determined based on the first score, the predicted word obtained may not conform to the domain-specific language grammar rules. The embodiment of the present disclosure uses a constraint word set to adjust the first scores of multiple candidate words, so that the scores of candidate words that conform to the domain-specific language grammar rules are higher, and the scores of candidate words that do not conform to the domain-specific language grammar rules are lower. Then the adjusted first score, that is, the second score, reflects the situation after each candidate word is constrained by the domain-specific language grammar rules, and the second score contains the constraint information given by the domain-specific language grammar rules.
[0193] Adjusting the first score using the constrained word set is to give higher scores to candidate words that conform to the grammatical rules of the domain-specific language, that is, to increase their likelihood of being predicted words. Adjusting the first score using the constrained word set is to give lower scores to candidate words that do not conform to the grammatical rules of the domain-specific language, that is, to reduce their likelihood of being predicted words.
[0194] Assume that Figure 2FIn the guided JSON generation tool shown, the constrained word set that conforms to the grammatical rules of the domain-specific language includes "vanilla" and "microwave oven", and the constrained word set that does not conform to the grammatical rules of the domain-specific language includes "vanilla" and "umbrella". Therefore, the first scores of "vanilla" and "microwave oven" are increased, and the first scores of "vanilla" and "umbrella" are reduced. Specifically, the score of "vanilla" is adjusted from 70 to 85, the score of "microwave oven" is adjusted from 20 to 35, the score of "vanilla" is adjusted from 80 to 65, and the score of "umbrella" is adjusted from 20 to 5, thereby obtaining the second score of each candidate word. It can be obviously obtained that the second score can reflect the constraints of the domain-specific language grammar.
[0195] It should be noted that in order to make the final domain-specific language response conform to the domain-specific language grammatical rules, the second scores of most candidate words that conform to the domain-specific language grammatical rules must be higher than the second scores of candidate words that do not conform to the domain-specific language grammatical rules.
[0196] In step 350 , the predicted probabilities of the multiple candidate words are obtained based on the second scores of the multiple candidate words.
[0197] The prediction probability refers to the probability of each candidate word being the predicted word. The higher the second score, the higher the prediction probability corresponding to the candidate word, and the lower the second score, the lower the prediction probability corresponding to the candidate word.
[0198] It should be noted that the conversion between the second score and the predicted probability can be specifically implemented using a normalized exponential function, i.e., a softmax activation function. The normalized exponential function converts the multiple second scores into probability values between [0, 1] to obtain the predicted probability. The predicted probability can also be determined by processing the second scores using a sigmoid function, a linear function, or the like. In addition, the predicted probability can also be determined by the ratio of the second score to the full score corresponding to the second score. For example, when the second score is 85 and the full score is 100, the corresponding predicted probability is 0.85.
[0199] In step 360 , a predicted word is determined based on the prediction probabilities of the plurality of candidate words.
[0200] A predicted word refers to a word that responds to a target query. Multiple predicted words together constitute a domain-specific language response corresponding to the target query.
[0201] The predicted word is determined based on the predicted probabilities of multiple candidate words. The greater the predicted probability, the greater the likelihood that the corresponding candidate word will be used as the predicted word. Therefore, the disclosed embodiments generally use the candidate word with the highest predicted probability among multiple candidate words as the predicted word. For example, if the predicted probability of "vanilla" is 0.85, the predicted probability of "microwave oven" is 0.35, the predicted probability of "vanilla" is 0.65, and the predicted probability of "umbrella" is 0.5, then "vanilla" will be used as the predicted word.
[0202] In step 370 , a domain-specific language response is generated based on the plurality of determined predicted words.
[0203] A domain-specific language response is a response to a target query that conforms to the grammatical rules of the domain-specific language. The domain-specific language response is generated based on multiple predicted words, and the predicted words are arranged in chronological order.
[0204] The related technology directly determines the prediction probability and predicted word of the candidate word through the first score. If the first score of "vanilla" is 80, the first score of ""vanilla"" is 70, and the first scores of ""umbrella"" and ""microwave oven"" are 20, then the final predicted word is "vanilla", and ""name":"vanilla" does not comply with the domain-specific language grammatical rules. The embodiment of the present disclosure adjusts the first score through the constraint word set to obtain the second score, and determines the prediction probability and predicted word of the candidate word based on the second score. Then, ""vanilla" is used as the predicted word, and ""name":"vanilla" complies with the domain-specific language grammatical rules.
[0205] Reference Figure 4A After inputting a target query into a candidate word score prediction model, the target query is processed using candidate word score prediction to obtain first scores for multiple candidate words corresponding to the first word in the domain-specific language response. The multiple candidate words include words that conform to the domain-specific language grammatical rules and words that do not conform to the domain-specific language grammatical rules. A guidance instruction for predicting the word is then generated based on the domain-specific language grammatical rules. The guidance instruction specifies the domain-specific language grammatical constraints that the predicted word must follow. A constrained word set is then generated based on the guidance instruction. The constrained word set is then used to adjust the first scores of the multiple candidate words to increase the scores of words that conform to the domain-specific language grammatical rules and decrease the scores of words that do not conform to the domain-specific language grammatical rules, thereby obtaining second scores. Based on the second scores, a prediction probability is determined for each candidate word, thereby determining a predicted word. This predicted word is then used as the previous predicted word to generate a new predicted word using the candidate word score prediction model and the domain-specific language grammatical rules, until the multiple predicted words generated together constitute the domain-specific language response to the target query.
[0206] Reference Figure 4B, the large language model, and the guiding device are specifically set to Figure 4A The structure of Figure 4B The large language model in Figure 4A The candidate word score prediction model in the present invention is a guidance device for a large language model, which can generate guidance instructions based on the predicted previous word and domain-specific language grammar rules, so that the large language model can output a domain-specific language response, that is, a data structure or instruction that conforms to the expected format. Interactive programs and applications can provide services to objects through the domain-specific language response method provided by the embodiment of the present disclosure. Specifically, referring to Figure 2E The intelligent writing assistant, the candidate word score prediction model, that is, the large language model obtains the object's input "generate a recipe" in the input text display area through the interactive program. If the intelligent writing assistant uses JSON language encoding, then the large language model outputs the following under the guidance of the guidance device: Figure 2F The JSON result shown is then converted into natural language and displayed in the writing result display area. In addition, depending on the writing settings of the application, the data structure or instructions can also be converted into images or interface forms.
[0207] When generating a response, a typical large language model first obtains scores for multiple candidate words, then determines the probabilities of the multiple candidate words based on the scores, and then determines a predicted word based on the probabilities to generate a response. This response may or may not conform to the expected format. The embodiment of steps 310 to 370 described above generates a guide for the predicted word based on the domain-specific language grammar rules and the previous word predicted in the domain-specific language response, and then generates a constrained word set based on the guide. This constrained word set reflects whether words conform to or do not conform to the domain-specific language grammar rules (expected format). This constrained word set is used to adjust the first scores of the multiple candidate words generated by the large language model to obtain a second score. The second score reflects the condition of each candidate word after being constrained by the domain-specific language grammar rules (expected format). Using the second score instead of the first score to obtain the predicted probability and generate the final domain-specific language response ensures that the resulting domain-specific language response reflects the constraints of the domain-specific language grammar rules, thereby improving the accuracy of the large language model's generation of results that conform to the expected format. Because the accuracy of each predicted word in the generated domain-specific language response is high, there is no need for thorough verification after an error occurs, which improves generation efficiency.
[0208] The above is a general description of steps 310 to 370. Since steps 310 and 350 have been described in sufficient detail above, only the specific implementation processes of steps 320 to 340, 360, and 370 will be described in detail below.
[0209] Detailed description of step 320
[0210] In step 320 , based on the domain-specific language grammar rules and the last word predicted in the domain-specific language response, a guidance instruction for the predicted word is generated to indicate the domain-specific language grammar constraints that the predicted word needs to comply with.
[0211] In one embodiment, the domain specific language includes multiple types of domain specific languages, each type corresponding to one of the multiple boot instruction generation program segment instances, referring to Figure 5 , step 320 includes:
[0212] Step 510: If the predicted last word is a type of the domain-specific language, call a guide instruction generation program segment instance corresponding to the type among the multiple guide instruction generation program segment instances;
[0213] Step 520: Generate a program segment instance by calling the guiding instruction, and generate a guiding instruction for the predicted word based on the domain-specific language grammar rules of the type and the predicted previous word.
[0214] Step 510 and step 520 are described in detail below.
[0215] In step 510 , if the predicted last word is a type of the domain-specific language, a guiding instruction generation segment instance corresponding to the type among the plurality of guiding instruction generation segment instances is called.
[0216] The types of domain-specific languages are divided according to the domain-specific language grammar rules. Different types of domain-specific languages follow different domain-specific language grammar rules, while the same type of domain-specific languages follow the same domain-specific language grammar rules. For example, if the domain-specific language grammar rules are JSON, XML, and SQL, then the domain-specific languages are divided into three types, corresponding to JSON, XML, and SQL respectively.
[0217] It should be noted that the domain-specific language grammar rules can be customized and only need to satisfy the context-free grammar. In this case, the domain-specific language corresponding to the customized domain-specific language grammar rules is also a type of domain-specific language.
[0218] The guiding instruction generation program segment instance corresponds to the type of the domain-specific language. The guiding instruction generation program segment instance refers to a program segment that can generate a guiding instruction based on its corresponding domain-specific language grammar rules and the previous word of the predicted word.
[0219] If multiple predicted words in a domain-specific language response all conform to the same domain-specific language grammar rules, then the multiple predicted words are all of the same type of domain-specific language. Therefore, based on the type of the domain-specific language of the last word that has been predicted, the guidance instruction corresponding to the type can be called to generate a program segment instance. When the predicted word to be obtained is the first word in the domain-specific language response, the domain-specific language grammar rules and the guidance instruction generation program segment instance can be determined by pre-setting or received interactive information. For example, for Figure 2A and Figure 2B The code auto-completion tool shown in the figure uses the domain-specific language grammar rules corresponding to the input code, and the instruction-generated program segment instance corresponds to the type of domain-specific language to which the input code belongs. Figure 2C The intelligent operator shown, Figure 2D and Figure 2E The intelligent writing assistant shown, domain specific language grammar rules, and guide instructions generate program segment instances based on the written code of the application. Figure 2F The illustrated bootstrap JSON generation tool, in response to the control being turned on in JSON mode, where the domain specific language is of JSON type, generates a program segment instance of the bootstrap instruction that is called corresponding to the JSON language.
[0220] In step 520 , a program segment instance is generated by calling a guide instruction, and a guide instruction for predicting a word is generated based on the domain-specific language grammar rules of the type and the last word that has been predicted.
[0221] A guidance instruction generation program segment instance is a program segment that can generate guidance instructions based on its corresponding domain-specific language grammar rules and the previous word of the predicted word. The guidance instruction generation program segment instance can generate guidance instructions for the predicted word based on the domain-specific language grammar rules of the type and the previous word that has been predicted.
[0222] Reference Figure 6 The guiding instruction generation program segment includes a guiding instruction generation program segment instance A, a guiding instruction generation program segment instance B, ..., a guiding instruction generation program segment instance X. When the last predicted word is a domain-specific language of type N, the guiding instruction generation program segment instance N is called in multiple guiding instruction generation program segment instances. Based on the guiding instruction generation program segment instance N, the domain-specific language grammar rules and the last predicted word are processed to obtain the guiding instruction of the predicted word, and the guiding instruction is used to indicate the domain-specific language grammar constraints of type N.
[0223] The embodiment of the above steps 510 and 520 is provided with a plurality of guiding instruction generation program segment instances corresponding to the types of domain-specific languages. When generating different types of domain-specific language responses, the guiding instruction generation program segment instance corresponding to the type is called to generate a guiding instruction, thereby being able to generate a response that conforms to the grammatical rules of the domain-specific language. The embodiment of the present disclosure can generate responses of different types of domain-specific languages by setting the guiding instruction generation program segment instance, thereby improving the scope of application of the domain-specific language response method. In addition, the domain-specific language grammatical constraints indicated by the guiding instruction generated based on the guiding instruction generation program segment instance are accurately matched with the type of the domain-specific language, so that the final response conforms to the expected format, thereby improving the accuracy of the domain-specific language response.
[0224] In one embodiment, referring to Figure 7 After step 520, the domain-specific language response method further includes:
[0225] Step 710: If the last word predicted is a code segment terminator of the type, deactivate the guide instruction corresponding to the type to generate a program segment instance;
[0226] Step 720: Output the end mark of the type code segment.
[0227] Step 710 and step 720 are described in detail below.
[0228] In step 710, if the predicted last word is a code segment terminator of the type, the boot instruction corresponding to the type is disabled to generate a program segment instance.
[0229] The type code segment terminator is the end symbol of the domain-specific language response of the current type. If the predicted previous word is the type code segment terminator, indicating the end of the domain-specific language response of the current type, the boot instruction generation program segment instance corresponding to the type is disabled.
[0230] It should be noted that if the previous predicted word is a code segment terminator, other instances corresponding to the domain-specific language type, such as post-processor instances, need to be disabled. For example, in the JSON language, if the previous predicted word is "}" and the number of "}"s and "{"s is the same across the predicted words, then the previous predicted word is a code segment terminator, and the bootstrap instruction generation segment instance corresponding to the JSON language is disabled.
[0231] In step 720, a code segment end marker is output.
[0232] Output the type code segment end marker, which represents the end of the domain-specific language response of the current type. The type code segment end marker can be set in a variety of different forms. Different type code segment end markers can be set to the same one, or the type code segment end marker can be set in a one-to-one correspondence with the type. Specifically, the type code segment end marker of JSON can be set to a combination of a newline and ```, the type code segment end marker of XML can be set to a combination of a newline and &&&&, or the type code segment end markers of JSON and XML can be set to a newline and ```. It is sufficient that the type code segment end marker can distinguish different types of domain-specific language responses.
[0233] It should be noted that for Figure 2A The code auto-completion tool shown can provide auto-completion services for multiple different types of codes, such as JSON, XML, and SQL. Therefore, within the application, it is necessary to map the type code segment end marker to the type of the domain-specific language one by one so that the code auto-completion tool can provide multiple different types of code auto-completion services at the same time.
[0234] In addition, corresponding to the end marker of the type code segment, the embodiment of the present disclosure also provides a type code segment start marker, which represents the beginning of the corresponding domain-specific language response. The type code segment start marker can be specifically set as needed. For example, the type code segment start marker of the JSON language is set to ^```json, where ^ represents the beginning of a line. When the guidance instruction indicates that the predicted word is the type code segment start marker, the guidance instruction of the JSON language is started to generate a program segment instance.
[0235] It should be noted that when the domain-specific language response method provided by the embodiment of the present disclosure is written in multiple programming languages, the domain-specific language response may be a combination of multiple domain-specific languages. In the process of generating a response corresponding to the target query, it is necessary to promptly deactivate and replace the guide instruction generation program segment instance, post-processor instance, etc., so that the generated domain-specific language response conforms to the expected format. In the response, multiple different types of domain-specific languages can be distinguished by the type code segment end mark, which is convenient for application calls and execution.
[0236] Reference Figure 8 If the last predicted word is a code segment terminator, the boot instruction generation program segment instance corresponding to the type is deactivated and the code segment terminator is output. If the last predicted word is not a code segment terminator, the boot instruction generation program segment instance corresponding to the type is continued to be executed to generate a new predicted word until the generated predicted word is a code segment terminator.
[0237] The embodiment of above-mentioned steps 710 and step 720, when the last word predicted is the type code segment terminator, disables the guide instruction generation program segment instance corresponding to the type, and outputs the type code segment end mark.The deactivation of the guide instruction generation program segment instance can guarantee that various domain-specific languages meet the expected format in the answer, thereby improving the accuracy that the domain-specific language answer generates.In addition, in the answer, can distinguish by the type code segment end mark between multiple different types of domain-specific languages, be convenient to application call and execution.
[0238] In one embodiment, referring to Figure 9 After step 720, the domain-specific language response method further includes:
[0239] Step 910: If the predicted last word is a domain-specific language response terminator, deactivate multiple guide instruction generation program segment instances;
[0240] Step 920: Output a domain-specific language response end tag.
[0241] Step 910 and step 920 are described in detail below.
[0242] In step 910 , if the predicted last word is a domain-specific language response terminator, multiple boot instruction generation program segment instances are disabled.
[0243] The domain-specific language response terminator is the symbol that ends the domain-specific language response. If the previous predicted word is the domain-specific language response terminator, generation of the domain-specific language response for the current target query is complete, and generation of new predicted words ceases. Specifically, multiple instances of the bootstrap instruction generation program segment are deactivated. Furthermore, cessation of predicted word generation requires deactivation of multiple post-processor instances.
[0244] Assuming that the domain specific language response terminator is &*^, when the predicted word is &*^, the execution of multiple guide instruction generation program segments is disabled.
[0245] In step 920 , a domain specific language response end tag is output.
[0246] The DSL response end marker is the final marker in the DSL response. Outputting the DSL response end marker indicates that the DSL response for the current target query has been generated.
[0247] It should be noted that, referring to Figure 8Assuming the last predicted word is not the domain-specific language response terminator, a new domain-specific language type is obtained and the corresponding guide instruction generation segment instance is called based on the new type to generate a new predicted word. If the last predicted word is the domain-specific language response terminator, multiple guide instruction generation segment instances need to be deactivated and the domain-specific language response end marker is output. Based on the domain-specific language response end marker and all previously generated predicted words, a complete domain-specific language response is generated.
[0248] In one embodiment, it is assumed that an application is written in the domain-specific languages of JSON and XML, and the two types of domain-specific languages are arranged in sequence in the response. First, the guide instruction generation program segment instance A corresponding to JSON is called, and multiple predicted words are generated through the candidate word score prediction model and the guide instruction generation program segment instance A. If the last predicted word is the code segment terminator of JSON, the guide instruction generation program segment instance A is disabled, and the code segment end marker of JSON is output, i.e., a line break and ```. The code segment end marker of JSON does not represent the end of the domain-specific language response. It is necessary to obtain the domain-specific language XML and call the guide instruction generation program segment instance B corresponding to XML. Multiple predicted words are generated through the candidate word score prediction model and the guide instruction generation program segment instance B until the last predicted word is the code segment terminator of XML. The guide instruction generation program segment instance B is disabled and the code segment end marker of XML is output. If the next predicted word generated is the domain-specific language response terminator, the guide instruction generation program segment instance A and the guide instruction generation program segment instance B are disabled, and the domain-specific language response end marker is output.
[0249] The embodiment of the above-mentioned steps 910 and 920 is provided with a domain-specific language response terminator. When the predicted last word is a domain-specific language response terminator, multiple guide instruction generation program segment instances are deactivated, and the domain-specific language response end mark is output. The deactivation of multiple guide instruction generation program segment instances ensures that between obtaining the response corresponding to the current target query and obtaining the next target query, the guide instruction generation program segment instance is in a deactivated state, thereby reducing the generation of redundant data and ensuring that the platform of the application domain-specific language response method can run stably. The setting of the domain-specific language response end mark represents the end of the response in the expected format, which is convenient for the platform to call and execute the domain-specific language.
[0250] In one embodiment, referring to Figure 10 , step 320 includes:
[0251] Step 1010: Generate a guidance instruction generation program segment based on the domain-specific language grammar rules, where the guidance instruction generation program segment includes a first statement, and the first statement is used to generate a guidance instruction based on the domain-specific language grammar rules and the predicted previous word;
[0252] Step 1020: Generate a program segment through the guidance instruction to receive the predicted previous word;
[0253] Step 1030: Execute the first statement to generate a guiding instruction based on the domain-specific language grammar rules and the previous word.
[0254] Steps 1010 to 1030 are described in detail below.
[0255] In step 1110, a guidance instruction generation program segment is generated based on the domain-specific language grammar rules. The guidance instruction generation program segment includes a first statement. The first statement is used to generate a guidance instruction based on the domain-specific language grammar rules and the predicted previous word.
[0256] The guidance instruction generation program segment refers to a program segment for generating guidance instructions, and the program segment includes at least one first statement. The first statement refers to a statement of the guidance instruction that can generate the predicted word, and the first statement is essentially a string of code. The guidance instruction generation program segment is generated based on the domain-specific language grammar rules, so the information contained in the guidance instruction conforms to the domain-specific language grammar rules, that is, the domain-specific language grammar constraints that the predicted word indicated by the guidance instruction needs to follow conform to the domain-specific language grammar rules. For example, for Figure 2A In the code auto-completion tool shown, if the input code is "{"key"}", the generated guide instruction indicates that the value range of the next character is ":". The combination of the value range of this character and the input code conforms to the JSON language syntax, that is, the domain-specific language syntax rules.
[0257] It should be noted that if the boot instruction generation program segment is provided with multiple boot instruction generation program segment instances, and the multiple boot instruction generation program segment instances are provided in one-to-one correspondence with the types of domain-specific languages, then each boot instruction generation program segment instance is provided with a first statement, and the boot instruction generated by executing the first statement is used to indicate the corresponding type of domain-specific language grammatical constraint.
[0258] Reference Figure 11, the embodiment of the present disclosure parses the domain-specific grammar rules through a domain-specific language grammar rule parser to generate a guide instruction generation program segment. The guide instruction generation program segment includes a first statement, and the first statement is specifically "let input=yield new Instruction(…args);", wherein yield refers to an asynchronous conversion method and program running method, which is an advanced feature of some programming languages, input is the information received by the guide instruction generation program segment, new Instruction represents the guide instruction generated by executing the first statement, and args is the information carried by the guide instruction. Figure 2A The input code shown is “{"key"}”, and the information args carried by the guide instruction is used to limit the predicted word to “:”.
[0259] In step 1020, the program segment is generated by the guidance instruction to receive the predicted previous word. The predicted previous word is the word before the predicted word to be generated. When the predicted word to be generated is the first word of the domain-specific language response, the predicted previous word is set to be empty. For example, for Figure 2F In the guided JSON generation tool shown, after clicking the Generate button, if no predicted word is generated, the first predicted word is set to empty. If the predicted word to be generated is "recipe", the previous predicted word is "{".
[0260] In step 1030 , the first statement is executed to generate a guidance instruction based on the domain specific language grammar rules and the previous word.
[0261] After the domain-specific language grammar rules, the guide instruction generation program segment, and the predicted previous word are confirmed, the first statement is executed to generate the guide instruction based on the domain-specific language grammar rules and the predicted previous word.
[0262] Reference Figure 11 The guidance instruction generation program segment includes the first statement "let input = yield newInstruction(...args);", which receives the predicted previous word. Based on the predicted previous word and the domain-specific language grammar rules, the information "args" carried by the guidance instruction can be determined, and then the guidance instruction can be generated.
[0263] The above steps 1010 to 1030 are provided with a guidance instruction generation program segment, and the guidance instruction generation program segment includes a first statement for generating a guidance instruction. The setting of the guidance instruction generation program segment makes the domain-specific language grammatical constraints indicated by the generated guidance instruction more accurate, thereby improving the accuracy of the generated domain-specific language response.
[0264] In one embodiment, referring to Figure 12 After step 1030, the domain-specific language response method further includes:
[0265] Step 1210: suspend the execution of the boot instruction generation program segment;
[0266] Step 1220: When the predicted word is received, the execution of the guidance instruction generation program segment is resumed.
[0267] Step 1210 and step 1220 are described in detail below.
[0268] In step 1210 , the execution of the boot instruction generation program segment is suspended.
[0269] After the boot instruction is generated, the execution of the boot instruction generation program segment is suspended to wait for the next execution of the boot instruction generation program segment.
[0270] It should be noted that the guiding instruction generating program segment can be suspended only after the guiding instruction generating program segment forwards the guiding instruction generating program segment to the next node, ie, the node that generates the constraint word set based on the guiding instruction.
[0271] In step 1220, when the predicted word is returned, execution of the guidance instruction generation program segment is resumed. The returned predicted word is the previous word of the predicted word to be generated. When the predicted word is returned, execution of the guidance instruction generation program segment is resumed to generate a new predicted word.
[0272] It should be noted that when the execution of the guidance instruction generation program segment is suspended, the running state of the guidance instruction generation program segment needs to be saved. Correspondingly, when the execution of the guidance instruction generation program segment is resumed, the previously saved running state needs to be restored so that the guidance instruction program segment can run normally.
[0273] In one embodiment, referring to Figure 2F Assuming that the predicted word to be generated is "name", after the guidance instruction generation program segment generates the guidance instruction "name", the execution of the guidance instruction generation program segment is suspended. When the predicted word "name" is returned, the execution of the guidance instruction generation program segment is resumed.
[0274] In the embodiment of the above-mentioned steps 1210 and 1220, after the guide instruction is generated, the execution of the guide instruction generation program segment is suspended, and when the returned prediction word is received, the execution of the guide instruction generation program segment is resumed. Then, in this process of generating the prediction word based on the guide instruction, the guide instruction generation program segment is in a suspended running state. In this way, when an error is found in the process of generating the prediction word based on the guide instruction, that is, from step 330 to step 360, due to the suspension of the guide instruction generation program segment, the position of the guide instruction generation program segment error can be quickly determined, thereby better reflecting the error when generating the domain-specific language response, and improving the accuracy of the generated domain-specific language response. It can continuously guide the repair of errors and continue to generate new prediction words, reducing the resource loss caused by backtracking.
[0275] Detailed description of step 330
[0276] In step 330 , a constraint word set is generated based on the guidance instruction.
[0277] In one embodiment, the constraint word set includes a valid word set and an invalid word set, and the domain-specific language grammar constraints indicated by the guidance instruction include positive constraints and negative constraints. Figure 13 , step 330 includes:
[0278] Step 1310: Based on the forward constraint indicated by the guidance instruction, obtain valid words matching the forward constraint from the candidate word set, and generate a valid word set based on the valid words;
[0279] Step 1320: Based on the reverse constraint indicated by the guidance instruction, obtain invalid words that match the reverse constraint in the candidate word set, and generate an invalid word set based on the invalid words.
[0280] Step 1310 and step 1320 are described in detail below.
[0281] In step 1310 , based on the forward constraint indicated by the guidance instruction, valid words matching the forward constraint are obtained from the candidate word set, and a valid word set is generated based on the valid words.
[0282] The candidate word set is a collection of multiple candidate words, including words from various domain-specific languages. Positive constraints are constraints imposed by the grammatical rules of the domain-specific language on which words can be predicted. The valid word set is a collection of candidate words for which the predicted word can be. Therefore, all valid words in the valid word set conform to the grammatical rules of the domain-specific language.
[0283] In the candidate word set, the candidate words are matched based on the positive constraint indicated by the guide instruction, and the candidate words matching the positive constraint are used as valid words. After determining the valid words matching the positive constraint, a valid word set is generated based on the valid words, and the valid word set contains at least one valid word.
[0284] Reference Figure 2F As shown in the figure, assuming that the last predicted word generated is "name":", the positive constraint is used to restrict the predicted words to conform to the JSON syntax, that is, the predicted words are numbers or words starting with ". For the candidate word set including "vanilla", "vanilla", "umbrella", and "microwave oven", the valid word set is "vanilla" and "microwave oven".
[0285] In step 1320 , based on the reverse constraint indicated by the guidance instruction, invalid words matching the reverse constraint are obtained from the candidate word set, and an invalid word set is generated based on the invalid words.
[0286] Inverse constraints are constraints imposed by the grammatical rules of the domain-specific language that prevent certain words from being predicted. The invalid word set is a set of candidate words that cannot be predicted. Therefore, invalid words in the invalid word set do not conform to the grammatical rules of the domain-specific language.
[0287] In the candidate word set, the candidate words are matched based on the reverse constraint indicated by the guide instruction, and the candidate words matching the reverse constraint are regarded as invalid words. After determining multiple invalid words matching the reverse constraint, an invalid word set is generated based on the multiple invalid words.
[0288] Reference Figure 2F As shown in the figure, assuming the last predicted word is "name":", the inverse constraint indicates that the predicted word cannot be a word other than one that conforms to the JSON syntax. For a candidate word set including "vanilla", "vanilla", "umbrella", and "microwave oven", the invalid word set is "vanilla" and "umbrella".
[0289] Reference Figure 4A , the embodiment of the present disclosure can process the guidance instruction through the language model guidance device to obtain the constraint word set. Specifically, Figure 14 As shown, the domain-specific language grammatical constraints indicated by the guidance instructions include positive constraints and negative constraints. Based on the positive constraints, matching is performed in the candidate word set to obtain multiple valid words, and the set of multiple valid words is used as the valid word set. In addition, in the candidate word set, matching is performed with the candidate words based on the negative constraints, and the candidate words matching the negative constraints are used as invalid words. An invalid word set is generated based on the multiple invalid words. Based on the valid word set and the invalid word set, a constrained word set is determined.
[0290] The embodiments of steps 1310 and 1320 above specifically divide the domain-specific language grammatical constraints indicated by the guidance instructions into positive constraints and negative constraints, determine the valid word set based on the positive constraints, and determine the invalid word set based on the negative constraints, thereby using the valid word set and the invalid word set as the constrained word set. The disclosed embodiments specifically classify and set the domain-specific language grammatical constraints and constrained word sets so that the resulting constrained word set can accurately reflect the domain-specific language grammatical rules, thereby improving the accuracy of the second score and further improving the accuracy of the domain-specific language response.
[0291] The above is a general description of step 1310 and step 1320. The specific implementation process of step 1310 and step 1320 is described in detail below.
[0292] In step 1310 , based on the forward constraint indicated by the guidance instruction, valid words matching the forward constraint are obtained from the candidate word set, and a valid word set is generated based on the valid words.
[0293] In step 1320 , based on the reverse constraint indicated by the guidance instruction, invalid words matching the reverse constraint are obtained from the candidate word set, and an invalid word set is generated based on the invalid words.
[0294] In one embodiment, referring to Figure 15 , step 1310 includes:
[0295] Step 1510: for each candidate word in the candidate word set, determine a first matching degree between the candidate word and the positive constraint;
[0296] Step 1520: If the first matching degree is greater than the first threshold, determine that the candidate word is a valid word;
[0297] Step 1530: Generate a valid word set based on the valid words;
[0298] Correspondingly, step 1320 includes:
[0299] Step 1540: for each candidate word in the candidate word set, determine a second matching degree between the candidate word and the reverse constraint;
[0300] Step 1550: If the second matching degree is greater than the second threshold, determine that the candidate word is an invalid word;
[0301] Step 1560: Generate an invalid word set based on the invalid words.
[0302] Steps 1510 to 1560 are described in detail below.
[0303] In step 1510 , for each candidate word in the candidate word set, a first matching degree between the candidate word and the positive constraint is determined.
[0304] The first matching degree refers to the degree of matching between each candidate word in the candidate word set and the positive constraint. The higher the first matching degree, the higher the possibility that the combination of the candidate word and the above context conforms to the grammatical rules of the domain-specific language.
[0305] Reference Figure 2F As shown in the figure, assuming that the last predicted word generated is "name":", the positive constraint indicates that the predicted word conforms to JSON, and the predicted word is food, and the multiple candidate words in the candidate word set are "vanilla", "vanilla", "umbrella", and "microwave oven", then the first matching degree of "vanilla" with the positive constraint is 30%, the first matching degree of "vanilla" with the positive constraint is 100%, the first matching degree of "umbrella" with the positive constraint is 0, and the first matching degree of "microwave oven" with the positive constraint is 70%.
[0306] In step 1520 , if the first matching degree is greater than the first threshold, the candidate word is determined to be a valid word.
[0307] The first threshold can be set according to actual needs. Multiple types of domain-specific languages can be set to the same first threshold. Multiple types of domain-specific languages can also be set to correspond to multiple first thresholds in a one-to-one manner.
[0308] Assume that the last predicted word generated is "name":", the first matching degree of "vanilla" with the positive constraint is 0, the first matching degree of "vanilla" with the positive constraint is 100%, the first matching degree of "umbrella" with the positive constraint is 0, and the first matching degree of "microwave oven" with the positive constraint is 70%. If the first threshold is 50%, then the candidate words "vanilla" and "microwave oven" are valid word sets.
[0309] It should be noted that after determining the first matching degrees of multiple candidate words in the candidate word set, the multiple candidate words can be sorted in descending order according to the first matching degrees, and the first preset number of candidate words can be determined as valid words.
[0310] In step 1530, a valid word set is generated based on the valid words. The set of multiple valid words is considered as the valid word set, and the multiple valid words in the valid word set all conform to the grammatical rules of the domain-specific language. For the valid words "vanilla" and "microwave oven", the valid word set is the set of "vanilla" and "microwave oven".
[0311] In step 1540 , for each candidate word in the candidate word set, a second matching degree between the candidate word and the reverse constraint is determined.
[0312] The second matching degree refers to the matching degree between each candidate word in the candidate word set and the reverse constraint. The higher the second matching degree is, the higher the possibility that the combination of the candidate word and the above text does not conform to the grammatical rules of the domain-specific language.
[0313] Reference Figure 2F As shown, assuming that the last predicted word generated is "name":", the reverse constraint is used to indicate that the candidate word does not conform to JSON or does not include food, and the multiple candidate words in the candidate word set are "vanilla", "vanilla", "umbrella" and "microwave oven", then the second matching degree of "vanilla" with the reverse constraint is 70%, the second matching degree of "vanilla" with the reverse constraint is 0, the second matching degree of "umbrella" with the reverse constraint is 100%, and the second matching degree of "microwave oven" with the reverse constraint is 30%.
[0314] In step 1550 , if the second matching degree is greater than the second threshold, the candidate word is determined to be an invalid word.
[0315] The second threshold can be set as needed. Multiple types of domain-specific languages can be set to the same second threshold. Multiple types of domain-specific languages can also be set to correspond to multiple second thresholds in a one-to-one manner.
[0316] Assume that the last predicted word generated is "name":", the second matching degree between "vanilla" and the reverse constraint is 70%, the second matching degree between "vanilla" and the reverse constraint is 0, the second matching degree between "umbrella" and the reverse constraint is 100%, and the second matching degree between "microwave oven" and the reverse constraint is 30%. If the second threshold is 50%, then the candidate words "vanilla" and "umbrella" are invalid words.
[0317] In step 1560, an invalid word set is generated based on the invalid words. After all invalid words in the candidate word set are determined, the set of multiple invalid words is used as the invalid word set. For the invalid words "vanilla" and "umbrella", the invalid word set is the set of "vanilla" and "umbrella".
[0318] It should be noted that the first threshold and the second threshold need to be set correspondingly so that all candidate words in the candidate words are located in the valid word set or the invalid word set.
[0319] Reference Figure 14 Each valid word in the valid word set is determined based on a first matching degree between the candidate word and the positive constraint. If the first matching degree between the candidate word and the positive constraint is greater than a first threshold, the candidate word can be used as a valid word. In addition, in the candidate word set, a second matching degree between each candidate word and the negative constraint is determined. If the second matching degree is greater than a second threshold, the candidate word is determined to be an invalid word, and an invalid word set is generated based on the invalid words.
[0320] The embodiment of steps 1510 to 1560 above determines valid words by the first matching degree and determines invalid words by the second matching degree, thereby making each word in the valid word set and the invalid word set more accurate, improving the accuracy of the second score, and improving the accuracy of the domain-specific language response.
[0321] Detailed description of step 340
[0322] In step 340 , the first scores of the plurality of candidate words are adjusted using the constraint word set to obtain second scores of the plurality of candidate words.
[0323] In the embodiment of the above steps 1310 and 1320, valid words matching the positive constraint and invalid words matching the negative constraint are respectively obtained from the candidate word set to form a valid word set and an invalid word set, thereby forming a constrained word set. In this case, in one embodiment, referring to Figure 16 , step 340 includes:
[0324] Step 1610: convert the valid word set into a valid word identification set, and convert the invalid word set into an invalid word identification set;
[0325] Step 1620: Use the valid word identification set and the invalid word identification set to adjust the first scores of the multiple candidate words to obtain second scores of the multiple candidate words.
[0326] Step 1610 and step 1620 are described in detail below.
[0327] In step 1610, the valid word set is converted into a valid word identification set, and the invalid word set is converted into an invalid word identification set.
[0328] The valid word identification set is a collection of identifications of multiple valid words. The valid word identification set includes multiple valid word identifications, and the multiple valid word identifications correspond one-to-one to the valid words in the valid word set.
[0329] The invalid word identification set is a collection of identifications of multiple invalid words. The invalid word identification set includes multiple invalid word identifications, and the multiple invalid word identifications correspond one-to-one to the invalid words in the invalid word set.
[0330] Assuming that the valid word set includes "vanilla" and "microwave oven", and the invalid word set includes "vanilla" and "umbrella", then the valid word identification set includes "1!@" and "2!@", where "1!@" corresponds to "vanilla" and "2!@" corresponds to "microwave oven". The invalid word identification set includes "1&*" and "2&*", where "1&*" corresponds to "vanilla" and "2&*" corresponds to "umbrella".
[0331] In step 1620, the first scores of the plurality of candidate words are adjusted using the valid word identification set and the invalid word identification set to obtain second scores of the plurality of candidate words.
[0332] After determining the identification set corresponding to the constraint word set, namely the valid word identification set and the invalid word identification set, the first scores of multiple candidate words can be adjusted by the valid word identification set and the invalid word identification set to obtain the second scores of multiple candidate words.
[0333] Assume that Figure 2F In the guided JSON generation tool shown, the candidate words corresponding to the valid word identification set are "vanilla" and "microwave oven", and the candidate words corresponding to the invalid word identification set are "vanilla" and "umbrella". Then the first scores of "vanilla" and "microwave oven" are increased, and the first scores of "vanilla" and "umbrella" are reduced, so that the scores of candidate words that conform to the grammatical rules of the domain-specific language are increased. Specifically, the score of "vanilla" is adjusted from 70 to 85, the score of "microwave oven" is adjusted from 20 to 35, the score of "vanilla" is adjusted from 80 to 65, and the score of "umbrella" is adjusted from 20 to 5, thereby obtaining the second scores of each candidate word.
[0334] Reference Figure 4A , the constraint word set is divided into a valid word set and an invalid word set, and the constraint word identification set is divided into a valid word identification set and an invalid word identification set. In the embodiment of the present disclosure, the constraint word set is converted into a constraint word identification set by a tagger. In addition, Figure 6 As shown, when the domain-specific language is provided with multiple types, the marker is provided with multiple marker instances corresponding to the types, and each marker instance is used to convert the constraint word set of the corresponding domain-specific language into a constraint word identifier set.
[0335] In the above-described embodiment of steps 1610 and 1620, the valid word set is converted into a valid word identifier set, and the invalid word set is converted into an invalid word identifier set, so that the first score is adjusted using the valid word identifier set and the invalid word identifier set. Since the postprocessor cannot directly access the constraint word set, the conversion of the valid word identifier set and the invalid word identifier set facilitates the postprocessor's adjustment of the first score using the constraint identifier set, thereby ensuring the normal execution of the domain-specific language response generation process.
[0336] The above is a general description of step 1610 and step 2220. Since step 1610 has been described in sufficient detail, the specific implementation process of step 1620 will be described in detail below.
[0337] In step 1620, the first scores of the plurality of candidate words are adjusted using the valid word identification set and the invalid word identification set to obtain second scores of the plurality of candidate words.
[0338] In one embodiment, referring to Figure 17 , step 1620 includes:
[0339] Step 1710: For a candidate word among the multiple candidate words corresponding to the valid word identifier in the valid word identifier set, increase the first score to obtain a second score;
[0340] Step 1720: For a candidate word among the multiple candidate words corresponding to the invalid word identifier in the invalid word identifier set, reduce the first score to obtain a second score.
[0341] Step 1710 and step 1720 are described in detail below.
[0342] In step 1710 , for a candidate word among the plurality of candidate words that corresponds to a valid word identifier in the valid word identifier set, the first score is increased to obtain a second score.
[0343] The candidate word corresponding to the valid word identifier conforms to the grammatical rules of the domain-specific language. Therefore, for the candidate word corresponding to the valid word identifier, the first score is increased to obtain a second score. For example, for the candidate words "vanilla" and "microwave oven" corresponding to the valid word identifier, the first score of "vanilla" is adjusted from 70 to the second score of 85, and the first score of "microwave oven" is adjusted from 20 to the second score of 35.
[0344] Increasing the first score can be achieved through various calculation methods. For example, a fixed increment can be added to the multiple first scores, or a fixed coefficient can be multiplied by the multiple first scores, where the coefficient is greater than 1, or, if all the first scores are greater than 1, the multiple first scores can be squared or cubed. Furthermore, increasing the first score can also be achieved through a combination of various calculation methods.
[0345] In step 1720 , for a candidate word among the plurality of candidate words corresponding to the invalid word identifier in the invalid word identifier set, the first score is reduced to obtain a second score.
[0346] The candidate word corresponding to the stopword marker does not conform to the grammatical rules of the domain-specific language. Therefore, for the candidate word corresponding to the stopword marker, the first score is reduced to obtain a second score. For example, for the candidate words "vanilla" and "umbrella" corresponding to the stopword marker in the stopword marker set, the first score of "vanilla" is adjusted from 80 to the second score of 65, and the first score of "umbrella" is adjusted from 20 to the second score of 5.
[0347] The first fraction can be reduced by various calculation methods. For example, a fixed increment can be subtracted from the multiple first fractions, or a fixed coefficient can be multiplied by the multiple first fractions, where the coefficient is an integer less than 1, or, when the multiple first fractions are all greater than 1, the square roots of the multiple first fractions can be taken. Furthermore, the first fraction can be reduced by a combination of various calculation methods.
[0348] It should be noted that the increase or decrease of the first score needs to ensure that the second score of the candidate word corresponding to the valid word identifier is greater than the candidate word corresponding to the invalid word identifier. Only in this way can the word with the highest second score comply with the domain-specific language grammatical rules.
[0349] Reference Figure 18 , obtain a valid word identifier from the valid word identifier set, determine a first score of the corresponding candidate word based on the valid word identifier, and increase the first score to obtain a second score. For the candidate word in the candidate word that corresponds to the invalid word identifier in the invalid word identifier set, reduce the first score to obtain a second score.
[0350] The embodiments of the above steps 1710 and 1720 increase the first score of the candidate word corresponding to the valid word identifier and decrease the first score of the candidate word corresponding to the invalid word identifier to obtain a second score. Then the second score can reflect the constraints of the domain-specific language grammatical rules, and the final predicted word will comply with the domain-specific language grammatical rules.
[0351] The above is a general description of step 1710 and step 1720. In the above embodiment, the first score is uniformly increased or decreased by a fixed increment or multiplied by a fixed coefficient, etc. The adjustment strength of this method is equal for all first scores. In the following embodiment, the first score can be adjusted in a targeted manner based on the first matching degree of the valid word and the positive constraint and the second matching degree of the invalid word and the reverse constraint, so that the adjustment strength for each candidate word is different.
[0352] In this embodiment, the valid word identification set also includes a first matching degree between the valid word and the positive constraint, and the invalid word identification set also includes a second matching degree between the invalid word and the negative constraint. Figure 19 , step 1710 includes:
[0353] Step 1910: For a candidate word among the multiple candidate words corresponding to a valid word identifier in the valid word identifier set, increase the first score based on the first matching degree of the valid word in the valid word identifier set to obtain a second score;
[0354] Corresponding to step 1910, step 1720 includes:
[0355] Step 1920: For a candidate word among the multiple candidate words corresponding to the invalid word identifier in the invalid word identifier set, reduce the first score based on the second matching degree of the invalid word in the invalid word identifier set to obtain a second score.
[0356] Step 1910 and step 1920 are described in detail below.
[0357] In step 1910, for a candidate word among multiple candidate words corresponding to a valid word identifier in the valid word identifier set, a first score is increased based on a first matching degree of the valid word in the valid word identifier set to obtain a second score.
[0358] For a candidate word corresponding to a valid word identifier, the specific degree of increase in the first score can be determined by the first degree of match, i.e., the degree of match between the valid word and the domain-specific grammatical constraint. Specifically, a mathematical rule operation can be performed on the first matching pair to determine the amount by which the first score should be increased. Alternatively, embodiments of the present disclosure can also determine the amount by which the first score should be increased using a table lookup method.
[0359] In step 1920, for a candidate word among the multiple candidate words corresponding to the invalid word identifier in the invalid word identifier set, the first score is reduced based on the second matching degree of the invalid word in the invalid word identifier set to obtain a second score.
[0360] For multiple candidate words corresponding to invalid word identifiers in the invalid word identifier set, the specific degree of reduction in the first score can be determined by the second matching degree, i.e., the degree of matching of the invalid word domain-specific grammatical constraints. Specifically, a mathematical rule operation can be performed on the second matching pair to determine the amount by which the first score needs to be reduced. In addition, the embodiment of the present disclosure can also determine the amount of reduction in the first score by using a table lookup method.
[0361] Reference Figure 18 Based on the valid word identifier set, a plurality of valid word identifiers and a first matching degree corresponding to the valid word identifiers are determined. A first score is increased based on the first matching degree to obtain a second score. Based on the invalid word identifier set, a plurality of invalid word identifiers and a second matching degree corresponding to the invalid word identifiers are determined. The first score is reduced based on the second matching degree to obtain a second score.
[0362] In the above-described embodiment of steps 1910 and 1920, the first scores of the plurality of candidate words are adjusted based on the first and second matching degrees to obtain second scores. During the adjustment of the first scores, the inclusion of the matching degrees enables the second scores to further reflect the relationship between the candidate words and the domain-specific grammatical constraints, making the resulting predicted words more accurate and improving the accuracy of the domain-specific language response.
[0363] The above is a general description of step 1910 and step 1920. The specific implementation process of step 1910 and step 1920 is described in detail below.
[0364] In one embodiment, referring to Figure 20 , step 1910 includes:
[0365] Step 2010: Obtain a first maximum increase value for a candidate word corresponding to a valid word identifier in the valid word identifier set among the plurality of candidate words;
[0366] Step 2020: Determine a first increase value based on the first maximum increase value and the first matching degree;
[0367] Step 2030: Determine a second score based on the first score and the first increase value;
[0368] Correspondingly, step 1920 includes:
[0369] Step 2040: Obtain a first maximum reduction value for a candidate word corresponding to an invalid word identifier in the invalid word identifier set among the multiple candidate words;
[0370] Step 2050: Determine a first reduction value based on the first maximum reduction value and the second matching degree;
[0371] Step 2060: Determine a second score based on the first score and the first reduction value.
[0372] Steps 2010 to 2060 are described in detail below.
[0373] In step 2010, a first maximum increase value is obtained for a candidate word corresponding to a valid word identifier in the valid word identifier set among a plurality of candidate words.
[0374] The first maximum increment is the maximum value by which the candidate word's first score can be increased. When the first degree of match for the valid word identifier corresponding to the candidate word is 100%, the maximum value by which its corresponding first score can be increased is the first maximum increment. The first maximum increment can be determined based on actual needs. Different types of domain-specific languages have different corresponding first maximum increments.
[0375] In step 2020, a first increase value is determined based on the first maximum increase value and the first matching degree.
[0376] The first added value can be calculated based on the product of the first maximum added value and the first matching degree. Assuming the candidate words corresponding to the valid word identifier are "vanilla" and "microwave oven," the first matching degree of "vanilla" with the positive constraint is 100%, the first matching degree of "microwave oven" with the positive constraint is 70%, and the first maximum added value is 20, then the first added value corresponding to "vanilla" is 20, and the first added value corresponding to "microwave oven" is 14.
[0377] In addition, the first added value can also be determined by the relationship between the first maximum added value and the first matching degree. Specifically, the first matching degree and the increase coefficient are in a step-matching relationship. For example, assuming that the first threshold is 0.5 and the first matching degrees corresponding to valid word identifiers are all greater than or equal to 0.5, then the increase coefficient corresponding to the first matching degrees between 0.5 and 0.8 is set to 0.3, the increase coefficient corresponding to the first matching degrees between 0.8 and 0.9 is set to 0.6, and the increase coefficient corresponding to the first matching degrees between 0.9 and 1.0 is set to 1. The first added value is obtained by multiplying the first maximum added value by the increase coefficient corresponding to the first matching degree.
[0378] In step 2030, a second score is determined based on the first score and the first increase value.
[0379] The second score can be determined by the sum of the first score and the first increase value. In addition, if the first increase values of the candidate words corresponding to the valid word identifiers in the valid word identifier set are all greater than 1, the product of the first score and the first increase value can be determined as the second score. If the first score of "vanilla" is 70 and the first increase value is 20, then its corresponding second score is 90. If the first score of "microwave oven" is 20 and the first increase value is 14, then its corresponding second score is 34.
[0380] In step 2040, a first maximum reduction value is obtained for a candidate word corresponding to the invalid word identifier in the invalid word identifier set among the multiple candidate words.
[0381] The first maximum reduction value is the maximum value by which the candidate word's first score can be reduced. When the second matching degree of the invalid word identifier corresponding to the candidate word is 100%, the maximum value by which its corresponding first score can be reduced is the first maximum reduction value. The first maximum reduction value can be determined based on actual needs. Different types of domain-specific languages have different corresponding first maximum reduction values.
[0382] In step 2050 , a first reduction value is determined based on the first maximum reduction value and the second matching degree.
[0383] The first reduction value can be calculated based on the product of the first maximum reduction value and the second matching degree. Assume that the candidate words corresponding to the invalid word identifier are "vanilla" and "umbrella", the first maximum reduction value is 20, and the second matching degree of "vanilla" with the reverse constraint is 70%, so its corresponding first reduction value is 14. If the second matching degree of "umbrella" with the reverse constraint is 100%, its corresponding first reduction value is 20.
[0384] In addition, the first reduction value can also be determined by the relationship between the first maximum reduction value and the second matching degree. Specifically, the second matching degree and the reduction coefficient have a step-matching relationship. For example, assuming that the second threshold is 0.5 and the second matching degrees corresponding to the invalid word identifiers are all greater than or equal to 0.5, then the reduction coefficient corresponding to the second matching degrees between 0.5 and 0.8 is set to 0.3, the reduction coefficient corresponding to the second matching degrees between 0.8 and 0.9 is set to 0.6, and the reduction coefficient corresponding to the second matching degrees between 0.9 and 1.0 is set to 1. The first maximum reduction value is multiplied by the reduction coefficient corresponding to the first matching degree to obtain the first reduction value.
[0385] In step 2060, a second score is determined based on the first score and the first reduction value.
[0386] The second score can be determined by the difference between the first score and the first reduction value. Furthermore, if the first reduction values of the candidate words corresponding to the invalid word identifiers in the invalid word identifier set are all less than 1, the second score can be determined by multiplying the first score and the first reduction value. For example, if the first score of "vanilla" is 80 and the first reduction value is 14, then its corresponding second score is 66. For "umbrella" with a first score of 20 and a first reduction value of 20, then its corresponding second score is 0.
[0387] Reference Figure 18 First, a first maximum increase value and a first maximum decrease value are obtained. A first increase value is determined based on a first degree of match between a plurality of candidate words and a valid word identifier in the valid word identifier set and the first maximum increase value, and a second score for the candidate words that conform to the domain-specific language grammar is determined based on the first increase value and the first score. Then, a first decrease value is determined based on a second degree of match between a plurality of candidate words and an invalid word identifier in the invalid word identifier set and the first maximum decrease value, and a second score for the candidate words that do not conform to the domain-specific language grammar is determined based on the first decrease value and the first score.
[0388] The embodiment of the above steps 2010 to 2060 determines the degree of adjustment of the first score of each candidate word based on the first matching degree and the second matching degree, and adjusts the first score to obtain the second score, so that the second score can more accurately reflect the relationship between the candidate word and the domain-specific grammatical constraints, making the predicted word more accurate and improving the accuracy of the domain-specific language response.
[0389] In the above steps 510 and 520, based on the DSL type of the last word that has been predicted, the guide instruction generation program segment instance corresponding to the type is called to generate the guide instruction of the predicted word based on the domain-specific language grammar rules of the type and the last word that has been predicted. Similar to the correspondence between each type and a guide instruction generation program segment instance, in one embodiment, each type can also correspond to one post-processor instance among multiple post-processor instances. Figure 21 , step 340 includes:
[0390] Step 2110: Determine the type of the domain specific language corresponding to the constraint word set;
[0391] Step 2120: Call a post-processor instance corresponding to the type among the multiple post-processor instances;
[0392] Step 2130: By calling the post-processor instance, the first scores of the plurality of candidate words are adjusted using the constraint word set to obtain the second scores of the plurality of candidate words, wherein different post-processor instances have different ways and parameters for adjusting the first scores.
[0393] It should be noted that the postprocessor is a device that uses a constraint word set to adjust the first score to obtain a second score. The postprocessor is provided with multiple postprocessor instances, and the multiple postprocessor instances correspond one-to-one to the types of domain-specific languages. A postprocessor instance is a program segment that can adjust the first scores of multiple candidate words based on its corresponding constraint word set to obtain a second score. The constraint word set is determined based on a guide instruction, and the constraints indicated by the guide instruction follow the same domain-specific language grammar rules as the postprocessor instance.
[0394] Steps 2110 to 2130 are described in detail below.
[0395] In step 2110 , the type of the domain specific language corresponding to the constraint word set is determined.
[0396] The constraint word set is generated based on the guide instruction, so the type of the domain specific language corresponding to the constraint word set is determined, specifically the type of the domain specific language corresponding to the guide instruction generation program segment instance that generates the guide instruction and the type of the domain specific language grammar rule.
[0397] Reference Figure 6, when the domain specific language grammar rule is of type N and the guiding instruction generation program segment instance is N, the type of the domain specific language corresponding to the constraint word set is determined to be N.
[0398] In step 2120, a post-processor instance corresponding to the type is called from among the plurality of post-processor instances. After determining the type of the domain-specific language corresponding to the constraint word set, a post-processor instance corresponding to the domain-specific language type is selected from among the plurality of post-processor instances in the post-processor.
[0399] Reference Figure 6 The postprocessor is provided with postprocessor instance A, postprocessor instance B, ..., postprocessor instance X. When the type of the domain-specific language corresponding to the constraint word set is determined to be N, the postprocessor instance N in the postprocessor is called, and the postprocessor instance N corresponds to the type N of the domain-specific language.
[0400] In step 2130, the first scores of the plurality of candidate words are adjusted by the called post-processor instance using the constraint word set to obtain the second scores of the plurality of candidate words, wherein different post-processor instances have different ways and parameters for adjusting the first scores.
[0401] After determining the post-processing instance, the first scores of the plurality of candidate words are adjusted by the post-processor instance using the constraint word set to obtain second scores for the plurality of candidate words. The second scores reflect the result of each candidate word being constrained by a type of domain-specific language grammar rule.
[0402] The candidate words corresponding to the multiple first scores include words that conform to the grammatical rules of the domain-specific language of each type, and the first scores of different candidate words are different. If the second score is required to reflect the constraint information of the domain-specific language grammar, it is necessary to increase the difference between the scores of the candidate words corresponding to the domain-specific language of the expected type and the candidate words of other types. If the multiple post-processor instances have the same method and parameters for adjusting the first scores, then no matter what type of domain-specific language is, the final result is the same type of domain-specific language response. Therefore, different post-processor instances have different methods and parameter settings for adjusting the first scores, and the candidate words that meet the current type of domain-specific language have the highest second score.
[0403] It should be noted that the same type of post-processor instances adjust the first score in the same way and with the same parameters, so that the arrangement of the second scores of the corresponding multiple candidate words of the current type of domain-specific language is the same as the arrangement of their corresponding first scores, thereby retaining the processing results of the candidate word score prediction model.
[0404] The above steps 2110 to 2130 are configured with post-processor instances corresponding to multiple types of domain-specific languages, and different post-processor instances adjust the first score in different ways and with different parameters, so that the second score of the candidate word corresponding to the current type of domain-specific language is the highest, so that the final response conforms to the grammatical rules of the current type of domain-specific language. The configuration of different post-processing instances makes the domain-specific language response method of the present embodiment applicable to multiple types of domain-specific languages and ensures that the final response conforms to the grammatical rules of the domain-specific language.
[0405] Detailed description of step 360
[0406] In step 360 , a predicted word is determined based on the prediction probabilities of the plurality of candidate words.
[0407] In the above steps 1010 to 1030, a guidance instruction generation program segment is generated, and a guidance instruction is generated based on the domain specific language grammar rules and the previous word through the guidance instruction generation program segment. Correspondingly, in step 360, a second statement can be included in the sampling program segment for returning the predicted word to the guidance instruction generation program segment. In this embodiment, referring to Figure 22 , step 360 includes:
[0408] Step 2210: Obtain a sample program segment, where the sample program segment includes a second statement, and the second statement is used to return the predicted word to the guidance instruction generation program segment;
[0409] Step 2220: Determine a predicted word based on the prediction probabilities of multiple candidate words by sampling the program segment;
[0410] Step 2230: Execute the second statement to return the predicted word to the guidance instruction generation program segment, so that the guidance instruction generation program segment generates a guidance instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word.
[0411] Steps 2210 to 2230 are described in detail below.
[0412] In step 2210, a sample program segment is obtained, where the sample program segment includes a second statement, and the second statement is used to return the predicted word to the guidance instruction generation program segment.
[0413] The sampling program segment is a program code segment that can determine a predicted word based on the predicted probabilities of multiple candidate words. The sampling program segment includes at least one second statement, which is a statement that returns the predicted word to the guidance instruction generation program segment. The second statement is a string of code.
[0414] Reference Figure 23The sampling program segment includes a second statement, and the second statement is specifically set to "let instruction = generator.next(...asks);", where generator represents the sampling program segment, next represents next, and asks refers to the predicted word returned by the second statement to the boot instruction generation program segment. Then next(...asks) means that the sampling program segment returns the predicted word to the boot instruction generation program segment by executing the second statement.
[0415] It should be noted that, referring to Figure 6 , the domain-specific language is set with multiple types, then the sampling program segment is set with multiple sampling program segment instances, and the multiple sampling program segment instances are set in a one-to-one correspondence with the types of the domain-specific language, then each sampling program segment instance is set with a second statement, and the second statement is executed to return the predicted word to the guide instruction generation program segment.
[0416] In step 2220, a predicted word is determined based on the prediction probabilities of multiple candidate words through a sampling program segment.
[0417] In addition to the second statement, the sampling program segment is also provided with other statements, such as sampling statements. The sampling statement is located before the second statement in the sampling program segment. Therefore, when executing the sampling program segment, the second statement is executed first to determine the predicted word based on the prediction probability of multiple candidate words. The predicted word is determined based on the prediction probability of multiple candidate words. The greater the prediction probability, the greater the possibility that the corresponding candidate word will be used as the predicted word. Therefore, the sampling program segment usually uses the candidate word with the highest prediction probability among multiple candidate words as the predicted word. For example, the prediction probability of "vanilla" is 0.85, the prediction probability of "microwave oven" is 0.35, the prediction probability of "vanilla" is 0.65, and the prediction probability of "umbrella" is 0.5, then "vanilla" is used as the predicted word.
[0418] In step 2230 , the second statement is executed to return the predicted word to the guidance instruction generation program segment, so that the guidance instruction generation program segment generates a guidance instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word.
[0419] After determining the predicted word, the sampling program segment continues to execute, thereby executing the second statement to return the predicted word to the guidance instruction generation program segment. The guidance instruction generation program segment can generate a guidance instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word.
[0420] Reference Figure 23The sampling program segment first determines a predicted word from among multiple candidate words based on their predicted probabilities. It then executes the second statement, "let instruction = generator.next(...asks);," to return the predicted word to the guidance instruction generation program segment. After receiving the predicted word, the guidance instruction generation program segment resumes execution and processes the domain-specific language grammar rules and the predicted word through the first statement, "let input = yield new Instruction(...args);," to generate the guidance instruction for the next predicted word.
[0421] The embodiment of steps 2210 to 2230 described above is provided with a sampling program segment, and the sampling program segment is provided with a second statement. After determining the predicted word, the second statement is executed, and the generated predicted word can be returned to the guide instruction generation program segment to generate the guide instruction for the next predicted word based on the guide instruction generation program segment, thereby facilitating the generation of a new predicted word. The disclosed embodiment returns the predicted word to the guide instruction generation program segment by executing the second statement, so as to generate multiple predicted words and obtain a domain-specific language response. In addition, the return of the predicted word enables the generated multiple predicted words to have a contextual association, thereby improving the accuracy of the domain-specific language response.
[0422] In step 2230 , the second statement is executed to return the predicted word to the guidance instruction generation program segment, so that the guidance instruction generation program segment generates a guidance instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word.
[0423] In one embodiment, the second sentence is also used to store the predicted word in the context memory as the context, referring to Figure 24 , step 2230 includes:
[0424] Step 2410: Execute the second statement to return the predicted word to the guide instruction generation program segment and the context memory, so that the guide instruction generation program segment generates the guide instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word, and the candidate word score prediction model obtains the first scores of multiple candidate words based on the target query and the context in the context memory.
[0425] It should be noted that the context memory refers to a device for storing predicted words. The context memory can store the predicted words and use the predicted words as context.
[0426] Step 2410 is described in detail below.
[0427] In step 2410, the second statement is executed to return the predicted word to the guide instruction generation program segment and the context memory, so that the guide instruction generation program segment generates the guide instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word, and the candidate word score prediction model obtains the first scores of multiple candidate words based on the target query and the context in the context memory.
[0428] Executing the second statement can return the generated predicted word to the guidance instruction generation program segment and the context memory. The guidance instruction generation program segment generates a guidance instruction for the next predicted word based on the received predicted word and the domain-specific language grammar rules. In addition, the candidate word score prediction model generates first scores for multiple candidate words corresponding to the predicted word based on the context in the context memory and the target query.
[0429] It should be noted that the embodiment of the present disclosure can also return the predicted word to the guidance instruction generation program segment through the previous context memory. Specifically, the second statement is executed, the predicted word is returned to the previous context memory, and the new content in the previous context memory, that is, the predicted word, is sent to the guidance instruction generation program segment.
[0430] for Figure 2F The guidance JSON generation tool shown, assuming that the currently generated predicted word is ""recipe"", returns ""recipe"" to the guidance instruction generation program segment and the context memory. The guidance instruction generation program segment generates guidance instructions based on the domain-specific language grammar rules and ""recipe"", and the context memory stores the target query, ""recipe"" and the predicted words generated before as context, so that the candidate word score prediction model can obtain the first scores of multiple candidate words based on the target query and the context in the context memory.
[0431] Reference Figure 4A The embodiment of the present disclosure is provided with a context memory to store all predicted words generated based on the target query. The candidate word score prediction model can obtain first scores of multiple candidate words based on the target query and the context in the context memory.
[0432] The embodiment of the above-mentioned step 2410 is provided with a context memory, so that the candidate word score prediction model can determine the first scores of multiple candidate words based on the context of the predicted word to be generated and the target query, so that the contextual relationship between the multiple predicted words in the final domain-specific language response is closely connected, thereby improving the accuracy of the domain-specific language response.
[0433] In one embodiment, referring to Figure 25 After step 320, the domain-specific language response method further includes:
[0434] Step 2510: If the guidance instruction indicates that the predicted word should be a separator, query the previous storage area;
[0435] Step 2520: If the text in the text storage area exceeds a predetermined size, perform a summary operation on the text to generate a summary of the text, and use the summary to replace the text in the text storage area. The size of the summary is smaller than the predetermined size.
[0436] Step 2510 and step 2520 are described in detail below.
[0437] In step 2510, if the guidance indicates that the predicted word should be a separator, the previous context storage area is searched.
[0438] Delimiters are symbols that separate statements in a domain-specific language response. Delimiters can be a Chinese period, a combination of an English period and a space, a line break, a paragraph break, a page break, etc.
[0439] In step 2520, if the context in the context storage area exceeds a predetermined size, a summary operation is performed on the context to generate a summary of the context, and the summary is used to replace the context in the context storage area, and the size of the summary is less than the predetermined size.
[0440] The summary of the preceding text refers to the result of a summary operation on the preceding text. The summary provides a synopsis of the preceding text's content, describing it concisely and clearly. Summarization is the process of determining the summary of the preceding text. The size of the summary of the preceding text is smaller than a predetermined size, meaning that the summary is smaller than the original preceding text. The summary replaces the preceding text in the preceding text storage area, leaving sufficient space in the preceding text storage area for storing the new predicted word.
[0441] for Figure 2F In the illustrated guided JSON generation tool, if all content from lines 1 to 12 has been generated, the guidance instructions indicate that the predicted word should be a delimiter, i.e., a line break. The tool then checks whether the context in the context storage exceeds a predetermined size. If so, it performs a summary operation on the context, generating a summary of the context, "ZGYA2^%4." This summary indicates that the recipe is for potatoes gratin with vanilla cream, requiring four medium potatoes and two tablespoons of butter. The summary, "ZGYA2^%4," then replaces the content from lines 1 to 12.
[0442] Furthermore, the predetermined size is less than or equal to the maximum capacity of the context memory. However, if the predetermined size is significantly less than the maximum capacity of the context memory, multiple summary operations must be repeated during the process of generating the domain-specific language response. Therefore, to improve the efficiency of generating the domain-specific language response and reduce unnecessary steps, the predetermined size is determined based on the maximum capacity of the context memory, and the difference between the predetermined size and the maximum capacity of the context memory is relatively small.
[0443] It should be noted that when the guiding instruction prediction word is a separator, the semantics of the separator and the preceding context are relatively complete, which facilitates summary calculation.
[0444] Reference Figure 26 When the guidance instruction indicates that the predicted word is a separator and the context in the context memory exceeds a predetermined size, a summary operation is performed on the context to generate a summary of the context, and the summary is used to replace the context in the context storage area. Afterwards, a constrained word set is determined through the guidance instruction, and the constrained word set is a set of multiple separators. When the predicted word is not a separator and the context in the context memory exceeds a predetermined size, the separator closest to the current moment is determined, and a summary operation is performed on the separator and the context before it to obtain a summary, and the separator and the context before it are replaced by the summary. In addition, regardless of whether the predicted word is a separator, as long as the context in the context memory does not exceed a predetermined size, the constrained word set can be directly determined based on the guidance instruction. After the constrained word set is determined, the first scores of the multiple candidate words can be adjusted based on the constrained word set to obtain a second score to determine the prediction probability of the multiple candidate words. Based on the prediction probabilities of the multiple candidate words, the predicted word is determined from the multiple candidate words.
[0445] In the embodiment of the above-mentioned steps 2510 and 2520, when the guidance instruction indicates that the predicted word is a separator and the context in the context memory exceeds a predetermined size, a summary operation is performed on the context to generate a summary of the context, and the summary is used to replace the context in the context storage area, so that the context memory has sufficient space for storing new predicted words, thereby being suitable for the generation of domain-specific language responses of various sizes and improving the stability of the domain-specific language response generation process.
[0446] Detailed description of step 370
[0447] In step 370 , a domain-specific language response is generated based on the plurality of determined predicted words.
[0448] In one embodiment, referring to Figure 27 , step 370 includes:
[0449] Step 2710: If the predicted word is a sentence terminator, obtain the first predicted word determined after the target query is input into the candidate word score prediction model;
[0450] Step 2720: Concatenate multiple predicted words between the first predicted word and the sentence terminator into a domain-specific language response.
[0451] Step 2710 and step 2720 are described in detail below.
[0452] In step 2710 , if the predicted word is a sentence terminator, the first predicted word determined after the target query is input into the candidate word score prediction model is obtained.
[0453] The sentence terminator marks the end of the domain-specific language response corresponding to the target query. If the predicted word is a sentence terminator, multiple predicted words corresponding to the domain-specific language response corresponding to the current target query have already been generated. Therefore, it is necessary to obtain the first predicted word determined after the target query is input into the candidate word score prediction model.
[0454] In step 2720, multiple predicted words between the first predicted word and the sentence terminator are concatenated into a domain-specific language response.
[0455] After inputting the target query into the candidate word score prediction model, the multiple predicted words between the first predicted word and the sentence terminator are generated based on the current target query. Therefore, the domain-specific language answer is the result of concatenating the multiple predicted words between the first predicted word and the sentence terminator.
[0456] Assuming that the statement terminator of JSON language is "^```json", for Figure 2F The guided JSON generation tool, shown in the figure, retrieves the first predicted word determined after the target query is input into the candidate word score prediction model, namely, the "{" in the first line. It then concatenates the multiple predicted words between the "{" and "^```json" in the first line to form a domain-specific language response.
[0457] It should be noted that, referring to Figure 4A The multiple predicted words generated based on the target query are stored in the context memory. Therefore, when generating a domain-specific language response, the multiple predicted words between the first predicted word and the sentence terminator can be retrieved from the context memory. In addition, if a summary is stored in the context memory, a reverse summary operation can be performed on the summary to restore it to the form of multiple predicted words.
[0458] The embodiment of the above-mentioned steps 2710 and 2720 is provided with a sentence terminator, and the connection result of multiple predicted words between the first predicted word corresponding to the target query and the sentence terminator is used as the domain-specific language response, then the domain-specific language response finally obtained is the complete response to the target query.
[0459] Steps 310 to 370 have been explained in detail above. The following will describe in detail some of the specific points or derived contents involved therein, including the content about the response interaction interface.
[0460] About the response interface
[0461] The response interaction interface refers to the interface of the platform that applies the domain-specific language response method provided by the embodiment of the present disclosure, such as Figure 2A and Figure 2B The code shown in the code shows the interface of the code automatic completion tool, Figure 2C The interface of the intelligent operator shown, Figure 2D and Figure 2E The interface of the intelligent writing assistant shown, Figure 2F The interfaces of the JSON generation tool shown can all be considered as response interaction interfaces.
[0462] In one embodiment, referring to Figure 28 Before step 310, the domain-specific language response method further includes:
[0463] Step 2810: Display a target query input area on the response interaction interface;
[0464] Step 2820: Receive a target query in the target query input area.
[0465] Step 2810 and step 2820 are described in detail below.
[0466] In step 2810, a target query input area is displayed on the response interaction interface.
[0467] The target query input area refers to the area where the object inputs the target query, such as Figure 2A The input code display area of the code auto-completion tool.
[0468] In step 2820, a target query is received in a target query input area.
[0469] When it is detected that an object inputs content in the target query input area, the target query input by the object in the target query input area may be received.
[0470] It should be noted that the embodiment of the present disclosure can receive the target query in real time, or can receive the target query after the object is identified and input in the target query input area. Figure 2A In the code auto-completion tool shown, the object usually writes the code in the input code display area. In order to save the time of code completion, the target query input by the object is usually received in real time. Figure 2B The code auto-completion tool shown completes the main code of the object input. To avoid missing information, it usually receives the target query after the target query is input.
[0471] The embodiment of the above-mentioned steps 2810 and 2820 is provided with a response interaction interface, and a target query input area is displayed in the response interaction interface. Afterwards, the target query is received in the target query input area, a domain-specific language response is generated based on the query input by the object, and the domain-specific language response is used to respond to the object, thereby improving the smooth operation of the platform that applies the domain-specific language response method and ensuring that the platform can make accurate responses to the object.
[0472] In one embodiment, the response interaction interface further includes a domain specific language response enabling control, referring to Figure 29 After step 310, the domain specific language response method further includes:
[0473] Step 2910: If the domain-specific language response enabling control is off, obtain predicted probabilities of the multiple candidate words based on the first scores of the multiple candidate words;
[0474] Step 2920: Determine a predicted word based on the prediction probabilities of the multiple candidate words;
[0475] Step 2930: Generate a response based on the multiple determined predicted words.
[0476] It should be noted that the domain-specific language response enabling control is a switch control for the platform regarding the guidance instruction generation program segment, the language model guidance device, and the marker, that is, steps 320 to 340. Figure 2F When the domain-specific language response enable control is turned on, click the Generate button to guide the instruction generation program segment, the language model guidance device, and the tagger to start working, and work with the candidate word score prediction model to generate a response that conforms to the expected format, that is, the JSON syntax rules.
[0477] Step 2910 and step 2930 are described in detail below.
[0478] In step 2910 , if the domain-specific language answer enabling control is off, prediction probabilities of the plurality of candidate words are obtained based on the first scores of the plurality of candidate words.
[0479] If the domain-specific language response enabling control is off, the guidance instruction generation program segment, the language model guidance device, and the tagger are in an inoperative state. In this case, the prediction probabilities of the plurality of candidate words are determined directly based on the first scores of the plurality of candidate words.
[0480] In step 2920, a predicted word is determined based on the prediction probabilities of the plurality of candidate words.
[0481] A predicted word is a word that answers the target query. It is determined based on the predicted probabilities of multiple candidate words. The higher the predicted probability, the more likely the corresponding candidate word is to be the predicted word. Therefore, embodiments of the present disclosure typically use the candidate word with the highest predicted probability among multiple candidate words as the predicted word.
[0482] In step 2930, a response is generated based on the plurality of determined predicted words.
[0483] When the DSL answer enable control is off, the generated answers may or may not conform to the DSL grammar rules.
[0484] Reference Figure 2F If the Domain-Specific Language Response Enable control is turned off, clicking the Generate button will generate prediction probabilities for multiple candidate words based on their first scores, and then determine the candidate word. The generated result may be a response that conforms to JSON grammar rules, a response that conforms to other grammar rules, or even a combination of statements using multiple different grammar rules. For example, if the first score for "vanilla" is 80, the first score for "vanilla" is 70, and the first scores for "umbrella" and "microwave oven" are 20, the final predicted word is "vanilla."
[0485] The embodiment of the above steps 2910 to 2930 is provided with a domain-specific language response enabling control in the response interaction interface. After the domain-specific language response enabling control is turned off, it can generate a response to the target query based only on the candidate word score prediction model, thereby improving the applicability of the platform that applies the domain-specific language response method.
[0486] In one embodiment, referring to Figure 30 Before step 310, the domain-specific language response method further includes:
[0487] Step 3010: Displaying a title decomposition query activation control on the response interaction interface;
[0488] Step 3020: In response to activation of the title decomposition query activation control, display a title decomposition query input area;
[0489] Step 3030: In the title decomposition query input area, receive a target query of the title decomposition.
[0490] Steps 3010 to 3030 are described in detail below.
[0491] In step 3010, a title decomposition query activation control is displayed on the response interaction interface.
[0492] The title decomposition query activation control is a control in the response interaction interface for determining whether to accept the title decomposition target query.
[0493] In step 3020, in response to activation of the title decomposition query activation control, a title decomposition query input area is displayed.
[0494] Figure 2F The interface shown is the interface when the title decomposition query activation control is in the inactive state. Figure 31 This is a diagram of the interface when the title-decomposition query activation control is activated. The target query input area is displayed in the form of a title decomposition, that is, the title-decomposition query input area is displayed. Multiple input boxes are displayed in the title-decomposition query input area, and the subject can enter their requirements in each input box. For example, the subject's primary requirement is to "generate a recipe," and secondly, the recipe must include dish AAAAAA and vanilla cream-roasted potatoes.
[0495] In step 3030, a target query of the title decomposition is received in the title decomposition query input area.
[0496] The answers related to the target query of the title decomposition type are related to each title, and the positions of each predicted word in the answer results are related to each title of the target query. Therefore, when the title decomposition query activation control is activated, it is accepted after the target query is entered.
[0497] Based on the target query of the title decomposition formula, generate the title decomposition formula, that is, the domain specific language response in Markdown format, refer to Figure 31 , when the title decomposition query activation control is activated, the JSON result in Markdown format is generated.
[0498] The embodiment of the above steps 3010 to 3030 is provided with a title decomposition query activation control. When the title decomposition query activation control is in an activated state, it accepts a target query of the title decomposition and generates a domain-specific language response of the title decomposition, so that the domain-specific language response method is applicable to the query of the title decomposition, thereby expanding the scope of application of the domain-specific language response method.
[0499] Implementation details of the domain-specific language response method of the present disclosure embodiment
[0500] Refer to the following Figure 32 , which illustrates in detail the implementation details of the domain-specific language response method of the embodiment of the present disclosure.
[0501] In step 3210, a target query is obtained.
[0502] In one embodiment, a target query input area is displayed on the response interaction interface, and a target query is received in the target query input area.
[0503] In another embodiment, a title decomposition query activation control is displayed on the response interaction interface, and in response to activation of the title decomposition query activation control, a title decomposition query input area is displayed, and a target query of the title decomposition is received in the title decomposition query input area.
[0504] In step 3220, the target query is input into the candidate word score prediction model to obtain first scores of multiple candidate words.
[0505] In step 3231, domain specific language grammar rules are obtained.
[0506] In one embodiment, the domain specific language includes multiple types of domain specific languages.
[0507] In step 3232, a guiding instruction generation program segment is generated based on the domain-specific language grammar rules, and the guiding instruction generation program segment includes a first statement.
[0508] In one embodiment, each type corresponds to one boot instruction generation program segment instance among a plurality of boot instruction generation program segment instances.
[0509] In step 3233 , the first statement is executed to generate a guidance instruction for the predicted word based on the domain-specific language grammar rules and the last predicted word, for indicating the domain-specific language grammar constraints that the predicted word needs to follow.
[0510] In one embodiment, if the last predicted word is a type of a domain-specific language, a guide instruction generation segment instance corresponding to the type is called from among the plurality of guide instruction generation segment instances. A guide instruction for the predicted word is generated based on the domain-specific language grammar rules of the type and the last predicted word by the called guide instruction generation segment instance.
[0511] In step 3240, a constraint word set is generated based on the guidance instruction.
[0512] In one embodiment, the constraint word set includes a valid word set and an invalid word set, and the domain-specific language grammar constraints indicated by the guidance instruction include positive constraints and negative constraints.
[0513] For each candidate word in the candidate word set, a first matching degree between the candidate word and the positive constraint is determined. If the first matching degree is greater than a first threshold, the candidate word is determined to be a valid word. Based on the valid words, a valid word set is generated.
[0514] For each candidate word in the candidate word set, a second matching degree between the candidate word and the reverse constraint is determined. If the second matching degree is greater than a second threshold, the candidate word is determined to be an invalid word. Based on the invalid words, an invalid word set is generated.
[0515] In step 3251, the valid word set is converted into a valid word identification set, and the invalid word set is converted into an invalid word identification set.
[0516] In step 3252 and step 3253, the first scores of the plurality of candidate words are adjusted using the valid word identification set and the invalid word identification set to obtain the second scores of the plurality of candidate words.
[0517] In one embodiment, for a candidate word among multiple candidate words corresponding to a valid word identifier in the valid word identifier set, a first score is increased based on a first matching degree of the valid word in the valid word identifier set to obtain a second score.
[0518] In one embodiment, for a candidate word among multiple candidate words corresponding to an invalid word identifier in the invalid word identifier set, the first score is reduced based on the second matching degree of the invalid word in the invalid word identifier set to obtain a second score.
[0519] In one embodiment, each type corresponds to one of a plurality of post-processor instances. First, the type of the domain-specific language corresponding to the constraint word set is determined. A post-processor instance corresponding to the type is called from the plurality of post-processor instances. The called post-processor instance uses the constraint word set to adjust the first scores of the plurality of candidate words to obtain second scores for the plurality of candidate words, wherein different post-processor instances adjust the first scores in different ways and with different parameters.
[0520] In step 3260, based on the second scores of the multiple candidate words, the predicted probabilities of the multiple candidate words are obtained.
[0521] In steps 3271 and 3272 , a predicted word is determined based on the prediction probabilities of the plurality of candidate words.
[0522] In one embodiment, a sampling program segment is obtained, the sampling program segment including a second statement, the second statement being used to return a predicted word to the guidance instruction generation program segment. A predicted word is determined based on the predicted probabilities of multiple candidate words using the sampling program segment. The second statement is executed to return the predicted word to the guidance instruction generation program segment, thereby generating guidance instructions for the next predicted word based on domain-specific language grammar rules and the predicted word by the guidance instruction generation program segment.
[0523] In step 3280, the second statement is further used to store the predicted word in the context memory as a context. The second statement is executed to return the predicted word to the guidance instruction generation program segment and the context memory. The guidance instruction generation program segment then generates a guidance instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word. The candidate word score prediction model then determines first scores for the plurality of candidate words based on the target query and the context in the context memory.
[0524] In one embodiment, if the guidance instruction indicates that the predicted word should be a separator, a previous context storage area is queried. If the previous context in the previous context storage area exceeds a predetermined size, a summary operation is performed on the previous context to generate a summary of the previous context, and the summary is used to replace the previous context in the previous context storage area, wherein the size of the summary is less than a predetermined size.
[0525] In step 3290, a domain-specific language response is generated based on the plurality of determined predicted words.
[0526] In one embodiment, if the predicted word is a sentence terminator, the first predicted word determined after the target query is input into the candidate word score prediction model is obtained, and multiple predicted words between the first predicted word and the sentence terminator are concatenated into a domain-specific language response.
[0527] Description of the apparatus and device of the present disclosure
[0528] It is to be understood that, although the steps in the above-mentioned flowcharts are shown in sequence according to the arrow representations, these steps are not necessarily performed in sequence according to the order represented by the arrows. Unless otherwise specified in the present embodiment, there is no strict order restriction on the execution of these steps, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the above-mentioned flowcharts may include multiple steps or multiple stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these steps or stages is not necessarily performed in sequence, but can be performed in turn or alternately with other steps or at least a portion of the steps or stages in other steps.
[0529] It should be noted that in each specific embodiment of the present application, when it comes to the need to perform relevant processing based on data related to the characteristics of the task content, such as task content attribute information or attribute information sets, the permission or consent of the task content will be obtained first, and the collection, use and processing of such data will comply with relevant laws, regulations and standards. In addition, when the embodiment of the present application needs to obtain task content attribute information, it will obtain a separate permission or separate consent for the task content through a pop-up window or jump to a confirmation page. After clearly obtaining a separate permission or separate consent for the task content, the necessary task content-related data for the normal operation of the embodiment of the present application will be obtained.
[0530] Figure 33 This is a schematic diagram of the structure of the domain-specific language response device 3300 provided in an embodiment of the present disclosure. The domain-specific language response device 3300 includes:
[0531] A first input unit 3310 is configured to input a target query into a candidate word score prediction model to obtain first scores of multiple candidate words;
[0532] A first generating unit 3320 is configured to generate a guidance instruction for a predicted word based on the domain-specific language grammar rules and the last word predicted in the domain-specific language response, to indicate the domain-specific language grammar constraints that the predicted word needs to comply with;
[0533] A second generating unit 3330 is configured to generate a constraint word set based on the guiding instruction;
[0534] A first adjusting unit 3340 is configured to adjust the first scores of the plurality of candidate words by using the constraint word set to obtain second scores of the plurality of candidate words;
[0535] a probability prediction unit 3350, configured to obtain predicted probabilities of the plurality of candidate words based on the second scores of the plurality of candidate words;
[0536] A first determining unit 3360 is configured to determine the predicted word based on the prediction probabilities of the plurality of candidate words;
[0537] The third generating unit 3370 is configured to generate the domain-specific language response based on the multiple determined predicted words.
[0538] Optionally, the first generating unit 3320 is specifically configured to:
[0539] Generate a guidance instruction generation program segment based on the domain-specific language grammar rules, the guidance instruction generation program segment including a first statement, the first statement being used to generate a guidance instruction based on the domain-specific language grammar rules and the predicted previous word;
[0540] Generate a program segment through the guidance instruction and receive the predicted previous word;
[0541] The first statement is executed to generate a guide instruction based on the domain specific language grammar rules and the previous word.
[0542] Optionally, the first determining unit 3360 is specifically configured to:
[0543] Obtaining a sampling program segment, the sampling program segment includes a second statement, and the second statement is used to return the predicted word to the guidance instruction generation program segment;
[0544] Determine the predicted word based on the prediction probabilities of multiple candidate words by sampling program segments;
[0545] The second statement is executed to return the predicted word to the guidance instruction generation program segment, so that the guidance instruction generation program segment generates a guidance instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word.
[0546] Optionally, the second sentence is further used to store the predicted word in the context memory as the context;
[0547] The first determining unit 3360 is further specifically configured to:
[0548] Execute the second statement to return the predicted word to the guide instruction generation program segment and the context memory, so that the guide instruction generation program segment generates the guide instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word, and the candidate word score prediction model obtains the first scores of multiple candidate words based on the target query and the context in the context memory.
[0549] Optionally, the domain-specific language response device further includes:
[0550] a first query unit, configured to query a previous context storage area if the guidance instruction indicates that the predicted word should be a separator;
[0551] The fourth generating unit is configured to perform summary operation on the text to generate a summary of the text if the text in the text storage area exceeds a predetermined size, and replace the text in the text storage area with the summary, wherein the size of the summary is less than a predetermined size.
[0552] Optionally, the constraint word set includes a valid word set and an invalid word set; the domain-specific language grammar constraints indicated by the guidance instruction include forward constraints and reverse constraints;
[0553] The second generating unit 3330 is specifically configured to:
[0554] Based on the positive constraint indicated by the guide instruction, obtaining valid words matching the positive constraint from the candidate word set, and generating a valid word set based on the valid words;
[0555] Based on the reverse constraint indicated by the guide instruction, invalid words matching the reverse constraint are obtained from the candidate word set, and an invalid word set is generated based on the invalid words.
[0556] Optionally, the first adjusting unit 3340 is specifically configured to:
[0557] Convert the valid word set into a valid word identification set, and convert the invalid word set into an invalid word identification set;
[0558] The first scores of the plurality of candidate words are adjusted using the valid word identification set and the invalid word identification set to obtain second scores of the plurality of candidate words.
[0559] Optionally, the first adjusting unit 3340 is further configured to:
[0560] For a candidate word corresponding to a valid word identifier in the valid word identifier set among the multiple candidate words, increasing the first score to obtain a second score;
[0561] For a candidate word among the multiple candidate words corresponding to the invalid word identifier in the invalid word identifier set, the first score is reduced to obtain a second score.
[0562] Optionally, the valid word identification set further includes a first matching degree between the valid word and the positive constraint, and the invalid word identification set further includes a second matching degree between the invalid word and the negative constraint;
[0563] The first adjustment unit 3340 is further configured to:
[0564] For a candidate word among the multiple candidate words corresponding to the valid word identifier in the valid word identifier set, based on the first matching degree of the valid word in the valid word identifier set, increasing the first score to obtain a second score;
[0565] The first adjustment unit 3340 is further configured to:
[0566] For a candidate word among the multiple candidate words corresponding to an invalid word identifier in the invalid word identifier set, the first score is reduced based on the second matching degree of the invalid word in the invalid word identifier set to obtain a second score.
[0567] Optionally, the first adjusting unit 3340 is further configured to:
[0568] For a candidate word corresponding to the valid word identifier in the valid word identifier set among the multiple candidate words, obtaining a first maximum increase value;
[0569] Determining a first increase value based on the first maximum increase value and the first matching degree;
[0570] determining a second score based on the first score and the first added value;
[0571] The first adjustment unit 3340 is further configured to:
[0572] For a candidate word corresponding to the invalid word identifier in the invalid word identifier set among the multiple candidate words, obtaining a first maximum reduction value;
[0573] determining a first reduction value based on the first maximum reduction value and the second matching degree;
[0574] Based on the first score and the first reduction value, a second score is determined.
[0575] Optionally, the second generating unit 3330 is further configured to:
[0576] For each candidate word in the candidate word set, determining a first matching degree between the candidate word and the positive constraint;
[0577] If the first matching degree is greater than a first threshold, determining the candidate word as a valid word;
[0578] Based on the effective words, generate an effective word set;
[0579] The second generating unit 3330 is further specifically configured to:
[0580] For each candidate word in the candidate word set, determining a second matching degree between the candidate word and the reverse constraint;
[0581] If the second matching degree is greater than the second threshold, determining that the candidate word is an invalid word;
[0582] Based on the invalid words, an invalid word set is generated.
[0583] Optionally, the third generating unit 3370 is specifically configured to:
[0584] If the predicted word is a sentence terminator, obtain the first predicted word determined after the target query is input into the candidate word score prediction model;
[0585] Multiple predicted words between the first predicted word and the sentence terminator are concatenated into a domain-specific language response.
[0586] Optionally, the domain specific language includes multiple types of domain specific languages, each type corresponding to one of the multiple guiding instruction generation program segment instances;
[0587] The first generating unit 3320 is specifically configured to:
[0588] If the predicted previous word is a type of the domain-specific language, calling a guide instruction generation program segment instance corresponding to the type among the multiple guide instruction generation program segment instances;
[0589] A program segment instance is generated by calling a guide instruction, and a guide instruction of a predicted word is generated based on a domain-specific language grammar rule of the type and a predicted previous word.
[0590] Optionally, each type corresponds to one post-processor instance among a plurality of post-processor instances;
[0591] The first adjustment unit 3340 is specifically configured to:
[0592] Determine the type of domain-specific language corresponding to the constraint word set;
[0593] Call the post-processor instance corresponding to the type in multiple post-processor instances;
[0594] By calling the post-processor instance and using the constraint word set, the first scores of the multiple candidate words are adjusted to obtain the second scores of the multiple candidate words, wherein different post-processor instances have different ways and parameters for adjusting the first scores.
[0595] Optionally, the domain-specific language response device 3300 further includes:
[0596] A first deactivation unit is configured to deactivate a guide instruction generation program segment instance corresponding to a type if the predicted last word is a type code segment terminator;
[0597] The first output unit is used to output a type code segment end mark.
[0598] Optionally, the domain-specific language response device 3300 further includes:
[0599] a second deactivation unit, configured to deactivate the plurality of guiding instruction generation program segment instances if the last predicted word is a domain-specific language response terminator;
[0600] The second output unit is configured to output a domain specific language response end tag.
[0601] Optionally, the domain-specific language response device 3300 further includes:
[0602] A first display unit, configured to display a target query input area on the response interaction interface;
[0603] The first receiving unit is configured to receive a target query in a target query input area.
[0604] Optionally, the response interaction interface further includes a domain specific language response enabling control,
[0605] The domain-specific language response device 3300 further includes:
[0606] a probability generating unit, configured to obtain predicted probabilities of the plurality of candidate words based on the first scores of the plurality of candidate words if the domain-specific language response enabling control is off;
[0607] a second determining unit, configured to determine a predicted word based on the prediction probabilities of the plurality of candidate words;
[0608] The fifth generating unit is configured to generate a response based on the plurality of determined predicted words.
[0609] Optionally, the domain-specific language response device 3300 further includes:
[0610] The second display unit is used to display the title decomposition query activation control on the response interaction interface;
[0611] a third display unit for displaying a title decomposition query input area in response to activation of the title decomposition query activation control;
[0612] The second receiving unit is configured to receive a target query in the title decomposition format in the title decomposition format query input area.
[0613] Optionally, the domain-specific language response device 3300 further includes:
[0614] A pause unit, used for pausing the execution of the program segment generated by the boot instruction;
[0615] The recovery unit is used to recover the execution of the guidance instruction generation program segment when receiving the returned predicted word.
[0616] Reference Figure 34 , Figure 34 The following is a block diagram of the structure of a terminal for implementing the domain-specific language response method according to an embodiment of the present disclosure. The terminal includes: a radio frequency (RF) circuit 3410, a memory 3415, an input unit 3430, a display unit 3440, a sensor 3450, an audio circuit 3460, a wireless fidelity (WiFi) module 3470, a processor 3480, and a power supply 3490. It will be understood by those skilled in the art that Figure 34 The terminal structure shown does not constitute a limitation on the mobile phone or computer, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0617] The RF circuit 3410 may be used for receiving and sending signals during information transmission or calls. In particular, after receiving downlink information from the base station, it is sent to the processor 3480 for processing. In addition, the designed uplink data is sent to the base station.
[0618] The memory 3415 may be used to store software programs and modules. The processor 3480 executes various functional applications and data processing of the content terminal by running the software programs and modules stored in the memory 3415 .
[0619] The input unit 3430 may be configured to receive input digital or character information and generate key signal input related to the settings and function control of the content terminal. Specifically, the input unit 3430 may include a touch panel 3431 and other input devices 3432 .
[0620] The display unit 3440 may be configured to display input information or provided information and various menus of the content terminal. The display unit 3440 may include a display panel 3441.
[0621] The audio circuit 3460 , the speaker 3461 , and the microphone 3462 may provide an audio interface.
[0622] In this embodiment, the processor 3480 included in the terminal can execute the domain-specific language response method of the previous embodiment.
[0623] The terminals of the embodiments of the present disclosure include but are not limited to mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft, etc. The embodiments of the present invention can be applied to various scenarios, including but not limited to content recommendation, data screening, etc.
[0624] Figure 35 A structural block diagram of a portion of the server 140 for implementing the domain-specific language response method of an embodiment of the present disclosure. The server 140 may vary greatly due to different configurations or performance, and may include one or more central processing units (CPUs) 3522 (for example, one or more processors) and memories 3532, and one or more storage media 3530 (for example, one or more mass storage devices) for storing application programs 3542 or data 3544. Among them, the memories 3532 and the storage media 3530 may be temporary storage or permanent storage. The program stored in the storage medium 3530 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server 140. Furthermore, the central processing unit 3522 may be configured to communicate with the storage medium 3530 to execute a series of instruction operations in the storage medium 3530 on the server 140.
[0625] The server 140 may also include one or more power supplies 3526, one or more wired or wireless network interfaces 3550, one or more input and output interfaces 3558, and / or one or more operating systems 3541, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0626] The central processing unit 3522 in the server 140 can be used to execute the domain-specific language response method of the embodiment of the present disclosure.
[0627] The embodiments of the present disclosure further provide a computer-readable storage medium for storing program codes, and the program codes are used to execute the domain-specific language response methods of the aforementioned embodiments.
[0628] The present disclosure also provides a computer program product, which includes a computer program. A processor of a computer device reads and executes the computer program, so that the computer device implements the above-mentioned domain-specific language response.
[0629] The terms "first," "second," "third," "fourth," and the like (if any) in the specification of the present disclosure and the accompanying drawings are used to distinguish between similar contents and are not necessarily used to describe a particular order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the embodiments of the present disclosure described herein, for example, can be implemented in orders other than those illustrated or described herein. In addition, the terms "comprises" and "comprising," and any variations thereof, are intended to cover non-exclusive inclusions, e.g., a process, method, system, product, or apparatus comprising a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0630] It should be understood that in the present disclosure, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated content, indicating that there can be three relationships. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and following associated content is in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0631] It should be understood that in the description of the embodiments of the present disclosure, the meaning of multiple (or multiple items) is more than two, greater than, less than, exceed, etc. are understood to exclude the number itself, and above, below, within, etc. are understood to include the number itself.
[0632] In the several embodiments provided in the present disclosure, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0633] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0634] In addition, the functional units in the various embodiments of the present disclosure may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0635] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present disclosure is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, server 140, or network device, etc.) to execute all or part of the steps of the various embodiments of the present disclosure. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store program code.
[0636] It should also be understood that the various implementations provided in the embodiments of the present disclosure can be combined arbitrarily to achieve different technical effects.
[0637] The above is a specific description of the implementation methods of the present disclosure, but the present disclosure is not limited to the above implementation methods. Those skilled in the art can make various equivalent modifications or substitutions without violating the spirit of the present disclosure. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present disclosure.
Claims
1. A domain-specific language response method, characterized in that: include: Input the target query into the candidate word score prediction model to obtain the first scores of multiple candidate words; generating, based on the domain-specific language grammatical rules and the last word predicted in the domain-specific language response, a guidance instruction for the predicted word, for indicating the domain-specific language grammatical constraints that the predicted word needs to comply with; generating a constraint word set based on the guiding instruction; Using the constraint word set, adjusting the first scores of the plurality of candidate words to obtain second scores of the plurality of candidate words; Obtaining predicted probabilities of the plurality of candidate words based on the second scores of the plurality of candidate words; Determining the predicted word based on the prediction probabilities of the plurality of candidate words; The domain-specific language response is generated based on a plurality of the determined predicted words.
2. The domain-specific language response method according to claim 1, characterized in that: The step of generating a guidance instruction for a predicted word based on the domain-specific language grammar rules and the previous word predicted in the domain-specific language response includes: generating a guiding instruction generation program segment based on the domain-specific language grammar rules, wherein the guiding instruction generation program segment includes a first statement, and the first statement is used to generate the guiding instruction based on the domain-specific language grammar rules and the predicted previous word; Generate a program segment through the guide instruction to receive the predicted previous word; The first statement is executed to generate the guiding instruction based on the domain-specific language grammar rule and the previous word.
3. The domain-specific language response method according to claim 2, characterized in that: The step of determining the predicted word based on the prediction probabilities of the plurality of candidate words includes: Acquire a sampling program segment, wherein the sampling program segment includes a second statement, and the second statement is used to return the predicted word to the guidance instruction generation program segment; Determining the predicted word based on the prediction probabilities of the plurality of candidate words through the sampling program segment; The second statement is executed to return the predicted word to the guidance instruction generation program segment, so that the guidance instruction generation program segment generates the guidance instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word.
4. The domain-specific language response method according to claim 3, characterized in that: The second sentence is further used to store the predicted word in a context memory as a context; The executing the second statement so as to return the predicted word to the guide instruction generation program segment, so that the guide instruction generation program segment generates the guide instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word, includes: executing the second statement so as to return the predicted word to the guide instruction generation program segment and the context memory, so that the guide instruction generation program segment generates the guide instruction for the next predicted word based on the domain-specific language grammar rules and the predicted word, and the candidate word score prediction model obtains the first scores of multiple candidate words based on the target query and the context in the context memory.
5. The domain-specific language response method according to claim 4, characterized in that: After generating a guidance instruction for the predicted word based on the domain-specific language grammar rules and the previous word predicted in the domain-specific language response, the domain-specific language response method further includes: If the guidance instruction indicates that the predicted word should be a separator, query the previous context storage area; If the context in the context storage area exceeds a predetermined size, a summary operation is performed on the context to generate a summary of the context, and the context in the context storage area is replaced with the summary, the size of the summary being smaller than the predetermined size.
6. The domain-specific language response method according to claim 1, characterized in that: The constraint word set includes a valid word set and an invalid word set; the domain-specific language grammar constraints indicated by the guidance instruction include forward constraints and reverse constraints; The generating of a constraint word set based on the guiding instruction includes: Based on the forward constraint indicated by the guidance instruction, obtaining valid words matching the forward constraint from a candidate word set, and generating the valid word set based on the valid words; Based on the reverse constraint indicated by the guidance instruction, invalid words matching the reverse constraint are obtained from a candidate word set, and the invalid word set is generated based on the invalid words.
7. The domain-specific language response method according to claim 6, characterized in that: The step of adjusting the first scores of the plurality of candidate words by using the constraint word set to obtain second scores of the plurality of candidate words includes: Converting the valid word set into a valid word identification set, and converting the invalid word set into an invalid word identification set; The first scores of the plurality of candidate words are adjusted using the valid word identification set and the invalid word identification set to obtain the second scores of the plurality of candidate words.
8. The domain-specific language response method according to claim 7, characterized in that: The adjusting the first scores of the plurality of candidate words by using the valid word identification set and the invalid word identification set to obtain the second scores of the plurality of candidate words includes: For the candidate word corresponding to the valid word identifier in the valid word identifier set among the plurality of candidate words, increasing the first score to obtain the second score; For the candidate words among the multiple candidate words corresponding to the invalid word identifier in the invalid word identifier set, the first score is reduced to obtain the second score.
9. The domain-specific language response method according to claim 8, characterized in that: The valid word identification set further includes a first matching degree between the valid word and the positive constraint, and the invalid word identification set further includes a second matching degree between the invalid word and the negative constraint; The step of increasing the first score for the candidate word corresponding to the valid word identifier in the valid word identifier set among the plurality of candidate words to obtain the second score comprises: increasing the first score for the candidate word corresponding to the valid word identifier in the valid word identifier set among the plurality of candidate words based on the first matching degree of the valid word in the valid word identifier set to obtain the second score; The reducing the first score to obtain the second score for the candidate word corresponding to the invalid word identifier in the invalid word identifier set among the multiple candidate words includes: reducing the first score to obtain the second score for the candidate word corresponding to the invalid word identifier in the invalid word identifier set among the multiple candidate words based on the second matching degree of the invalid word in the invalid word identifier set.
10. The domain-specific language response method according to claim 9, characterized in that: The step of increasing the first score of the candidate word corresponding to the valid word identifier in the valid word identifier set among the plurality of candidate words based on the first matching degree of the valid word in the valid word identifier set to obtain the second score includes: For the candidate words corresponding to the valid word identifier in the valid word identifier set among the plurality of candidate words, obtaining a first maximum increase value; determining a first increase value based on the first maximum increase value and the first matching degree; determining the second score based on the first score and the first increase value; The step of reducing the first score of the candidate word corresponding to the invalid word identifier in the invalid word identifier set among the plurality of candidate words based on the second matching degree of the invalid word in the invalid word identifier set to obtain the second score includes: For the candidate words corresponding to the invalid word identifier in the invalid word identifier set among the plurality of candidate words, obtaining a first maximum reduction value; determining a first reduction value based on the first maximum reduction value and the second matching degree; Based on the first score and the first reduction value, the second score is determined.
11. The domain-specific language response method according to claim 1, characterized in that: Generating the domain-specific language response based on the plurality of determined predicted words comprises: If the predicted word is a sentence terminator, obtaining the first predicted word determined after the target query is input into the candidate word score prediction model; The plurality of predicted words between the first predicted word and the sentence terminator are connected to form the domain-specific language response.
12. The domain-specific language response method according to claim 1, characterized in that: The domain specific language includes a plurality of types of the domain specific language, each type corresponding to one of the plurality of boot instruction generation program segment instances; The generating of a guidance instruction for a predicted word based on the domain-specific language grammar rules and the previous word predicted in the domain-specific language response includes: If the predicted last word is of the type of the domain-specific language, calling the guiding instruction generation program segment instance corresponding to the type among a plurality of guiding instruction generation program segment instances; The program segment instance is generated by calling the guide instruction, and based on the domain-specific language grammar rules of the type and the predicted previous word, the guide instruction of the predicted word is generated.
13. The domain-specific language response method according to claim 12, characterized in that: Each of the types corresponds to one of the plurality of post-processor instances; The step of adjusting the first scores of the plurality of candidate words by using the constraint word set to obtain second scores of the plurality of candidate words includes: Determining the type of the domain-specific language corresponding to the constraint word set; Calling the post-processor instance corresponding to the type among the plurality of post-processor instances; By calling the post-processor instance and utilizing the constraint word set, the first scores of the plurality of candidate words are adjusted to obtain the second scores of the plurality of candidate words, wherein different post-processor instances have different ways and parameters for adjusting the first scores.
14. The domain-specific language response method according to claim 12, characterized in that: After generating a program segment instance by calling the guiding instruction and generating the guiding instruction of the predicted word based on the domain-specific language grammar rule of the type and the predicted previous word, the domain-specific language response method further includes: If the predicted last word is a code segment terminator of type, deactivating the guide instruction generation program segment instance corresponding to the type; Output type code segment end marker.
15. The domain-specific language response method according to claim 14, characterized in that: After outputting the end mark of the type code segment, the domain specific language response method further includes: If the predicted last word is a domain-specific language response terminator, deactivating a plurality of the guiding instruction generation program segment instances; Outputs the end tag of the domain specific language response.
16. The domain-specific language response method according to claim 1, characterized in that: Before inputting the target query into the candidate word score prediction model to obtain first scores of the plurality of candidate words, the domain-specific language answering method further includes: Display title decomposition query activation control in the response interaction interface; In response to activation of the title decomposition query activation control, displaying the title decomposition query input area; In the title decomposition query input area, the target query of the title decomposition is received.
17. A domain-specific language response device, characterized in that: include: A first input unit is configured to input a target query into a candidate word score prediction model to obtain first scores of multiple candidate words; a first generating unit, configured to generate a guiding instruction for a predicted word based on a domain-specific language grammatical rule and a previous word predicted in the domain-specific language response, the guiding instruction being configured to indicate a domain-specific language grammatical constraint that the predicted word needs to comply with; A second generating unit, configured to generate a constraint word set based on the guiding instruction; a first adjusting unit, configured to adjust the first scores of the plurality of candidate words by using the constraint word set to obtain second scores of the plurality of candidate words; a probability prediction unit, configured to obtain predicted probabilities of the plurality of candidate words based on the second scores of the plurality of candidate words; a first determining unit, configured to determine the predicted word based on the prediction probabilities of the plurality of candidate words; The second generating unit is configured to generate the domain-specific language response based on the plurality of determined predicted words.
18. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the domain-specific language response method according to any one of claims 1 to 16 is implemented.
19. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the domain-specific language response method according to any one of claims 1 to 16 is implemented.
20. A computer program product, comprising a computer program, wherein the computer program is read and executed by a processor of a computer device, so that the computer device executes the domain-specific language response method according to any one of claims 1 to 16.