Decoding processing method, device, equipment, medium and program product
By introducing a decoding processing method into the natural language generation model and correcting the probability distribution of candidate word elements based on specific fields, the problem of the model's lack of professionalism in generating content in specific fields is solved, and low-cost and efficient domain generation capabilities are enhanced and collapsed. Risk aversion.
Patent Information
- Application Number
- CN202410787655.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-18
- Publication Date
- 2024-09-06
AI Technical Summary
There is a problem of insufficient professionalism in the application of natural language generation models in specific fields, resulting in the universality and generality of generated content. Existing methods such as prompt engineering, retrieval enhancement generation and secondary training/fine-tuning are expensive and easy to There is a risk of model collapse.
By introducing a decoding processing method, the decoding layer of the natural language generation model is determined to predict the set and probability distribution of candidate word elements at the next position, and the probability distribution of candidate word elements is corrected according to the distribution rules of the specific field, thereby determining the target word at the next position. Yuan, avoiding the risk of collapse of secondary training of large models.
It realizes the enhancement of the natural language generation model's ability to generate content in specific fields, optimizes language habits and vocabulary tendencies, has low cost and direct effects, and avoids the high cost and risk of model collapse of existing methods.
Smart Images

Figure CN118607667A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence, and more specifically, to a decoding processing method, device, equipment, medium and program product. Background Art
[0002] Natural language generation models (such as large language models, Large Language Model, abbreviated as LLM) are natural language processing technologies based on deep learning. They can learn language patterns and structures by training large amounts of text data, thereby generating natural language text or understanding the meaning of language text. Text generation is an important and challenging task in the field of natural language processing (NLP).
[0003] In the related art, the application of general natural language generation models in specific fields often faces the problem of insufficient professionalism of text generation content. This problem restricts the implementation effect of natural language generation models in specific fields. To solve such problems, prompt engineering, retrieval enhancement generation, and secondary training / fine tuning are usually used.
[0004] In the process of implementing the inventive concept of the present disclosure, the inventors found that the natural language generation model is universal and general in content generation due to the universality of the training data, and lacks professionalism in content generation in the field. For example, the effect of the prompt project on the model is limited, and there is a problem of the effect gradually weakening with the length of the conversation. The implementation cost of the retrieval enhancement generation project is high; it has very high requirements for the retrieval quality of the external knowledge base. The secondary training / fine-tuning method has a high cost for training a large model once, and the requirements for corpus quality and computing power resources are extremely high; it has high requirements for the technical capabilities of the team, and it is easy to have the risk of model collapse. Summary of the invention
[0005] In view of the above problems, the present disclosure provides a decoding processing method, apparatus, device, medium and program product.
[0006] According to the first aspect of the present disclosure, a decoding processing method is provided, characterized in that it includes: in response to inputting text into a natural language generation model, determining a candidate word set and a probability distribution of the next position predicted by the decoding layer of the natural language generation model; obtaining a revised probability of each candidate word in the candidate word set in a specific field, wherein the revised probability is determined according to a distribution pattern of the candidate word in the specific field, and the specific field is associated with the input text; based on the revised probability of each candidate word, performing a revision operation on the probability distribution; and based on the revised probability distribution, determining a target word at the next position from the candidate word set.
[0007] According to an embodiment of the present disclosure, before obtaining the correction probability of each candidate word in the candidate word set in a specific domain, the method further includes: based on a first corpus of the specific domain, determining at least one domain word and a first distribution feature of each domain word, wherein the first distribution feature is used to represent the distribution law; based on the first distribution feature of each domain word, obtaining the correction probability of each candidate word.
[0008] According to an embodiment of the present disclosure, determining at least one domain word based on the first corpus of the specific domain includes: determining the probability distribution of at least one general word based on the second corpus of the general domain, determining the probability distribution of at least one candidate domain word based on the first corpus, the general domain including an open domain not restricted to a specific domain; determining the at least one domain word based on the degree of difference between the probability distribution of the at least one general word and the probability distribution of the at least one candidate domain word.
[0009] According to an embodiment of the present disclosure, determining the first distribution feature of each domain word based on the first corpus of the specific domain includes: determining the individual distribution feature of each domain word based on the number of occurrences of each domain word in the first corpus; or determining the joint distribution feature of each domain word based on the number of co-occurrences of each domain word and at least one other domain word in the first corpus.
[0010] According to an embodiment of the present disclosure, based on the first corpus of the specific domain, determining the first distribution feature of each domain word-gram includes: standardizing the degree of difference corresponding to each domain word-gram to obtain a standardized distribution feature; and using the standardized distribution feature of each domain word-gram as the first distribution feature.
[0011] According to an embodiment of the present disclosure, obtaining the revised probability of each candidate word-gram based on the first distribution feature of each domain word-gram includes: obtaining the joint probability of each candidate word-gram based on the first distribution feature of each domain word-gram, the joint probability being the probability of the candidate word-gram at the next position and the word-grams at the N positions before the next position co-occurring, N being an integer greater than or equal to 1; obtaining the revised probability of each candidate word-gram based on the joint probability of each candidate word-gram and a first correction coefficient, wherein the first correction coefficient of each candidate word-gram is pre-set.
[0012] According to an embodiment of the present disclosure, based on the first distribution feature of each domain word-gram, obtaining the joint probability of each candidate word-gram includes: based on the first distribution feature of each candidate word-gram, obtaining the marginal probability of each candidate word-gram; for the words in the first N positions, obtaining the conditional probability of the word-gram in the nth position, where n is an integer greater than or equal to 1, and n is less than or equal to N; based on the marginal probability and the conditional probability of each word-gram in the words in the first N positions, obtaining the joint probability of each candidate word-gram.
[0013] According to an embodiment of the present disclosure, for the word-grams at the first N positions, obtaining the conditional probability of the word-gram at the nth position includes: obtaining the conditional probability of the word-gram at the nth position given all the word-grams before the word-gram at the nth position; or, obtaining the conditional probability of the word-gram at the nth position given the word-gram at the n-1th position.
[0014] According to an embodiment of the present disclosure, obtaining the revised probability of each candidate word-gram based on the first distribution feature of each domain word-gram includes: obtaining the marginal probability of each candidate word-gram based on the first distribution feature of each candidate word-gram; obtaining the revised probability of each candidate word-gram based on the marginal probability of each candidate word-gram and the second correction coefficient, wherein the second correction coefficient of each candidate word-gram is pre-set.
[0015] According to an embodiment of the present disclosure, M knowledge bases corresponding to M candidate fields are pre-stored, wherein each knowledge base includes a corresponding relationship between each field word in the corresponding candidate field and its correction probability, and M is an integer greater than or equal to 1; obtaining the correction probability of each candidate word in the candidate word set in a specific field includes: determining the specific field from the M candidate fields based on the input text; and obtaining the correction probability of each candidate word in the candidate word set in the specific field based on the knowledge base of the specific field.
[0016] According to an embodiment of the present disclosure, based on the revised probability of each candidate word-gram, the modification operation on the probability distribution includes: summing the revised probability of each candidate word-gram and the corresponding probability value in the probability distribution.
[0017] According to an embodiment of the present disclosure, the probability distribution of the next position candidate word set is obtained according to at least one of the following decoding strategies: greedy search decoding strategy, beam search decoding strategy, Top-K sampling decoding strategy, Top-P sampling decoding strategy.
[0018] Another aspect of an embodiment of the present disclosure provides a decoding processing device, characterized in that it includes: a determination module, which is used to determine the candidate word set and probability distribution of the next position predicted by the decoding layer of the natural language generation model in response to inputting text into the natural language generation model; an acquisition module, which is used to obtain the revised probability of each candidate word in the candidate word set in a specific field, wherein the revised probability is determined according to the distribution pattern of the candidate word in the specific field, and the specific field is associated with the input text; a correction module, which is used to perform a correction operation on the probability distribution based on the revised probability of each candidate word; and a target module, which is used to determine the target word at the next position from the candidate word set based on the revised probability distribution.
[0019] Another aspect of an embodiment of the present disclosure provides an electronic device, including: one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors execute the method described above.
[0020] Another aspect of an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the processor executes the method as described above.
[0021] Another aspect of an embodiment of the present disclosure provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0022] One or more of the above embodiments have the following beneficial effects: an external decoding correction strategy is introduced to correct the output content of the natural language generation model, which can ensure the rationality of the generated content through the original prediction ability of the natural language generation model, and make corrections based on the correction probability of candidate words appearing in specific fields to achieve the enhancement of field generation capabilities. Not only can the correction capabilities of different specific fields be switched freely, but also the collapse risk of secondary training of large models is avoided. The natural language generation model can enhance the content generation capabilities of specific fields to a certain extent, optimize the usage habits and vocabulary tendencies in its content, and has the characteristics of more direct effects and lower implementation costs compared to prompt engineering, retrieval enhancement generation, secondary training and other methods. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The above contents and other purposes, features and advantages of the present disclosure will become more apparent through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, in which:
[0024] Figure 1 The application scenario diagram of the decoding processing method according to the embodiment of the present disclosure is schematically shown;
[0025] Figure 2 A flowchart of a decoding processing method according to an embodiment of the present disclosure is schematically shown;
[0026] Figure 3 A flowchart of obtaining a modified probability according to an embodiment of the present disclosure is schematically shown;
[0027] Figure 4 A flowchart for determining a domain word according to an embodiment of the present disclosure is schematically shown;
[0028] Figure 5 A flowchart for determining a first distribution feature of each domain word-unit according to an embodiment of the present disclosure is schematically shown;
[0029] Figure 6 A flowchart of obtaining a modified probability of each candidate word-gram according to another embodiment of the present disclosure is schematically shown;
[0030] Figure 7 A flowchart for obtaining the joint probability of each candidate word-element according to an embodiment of the present disclosure is schematically shown;
[0031] Figure 8 A flowchart of obtaining a modified probability of each candidate word-gram according to another embodiment of the present disclosure is schematically shown;
[0032] Fig. 9 Schematically shows a flow chart of obtaining a correction probability according to yet another embodiment of the present disclosure;
[0033] Fig.10A schematic diagram showing a greedy search decoding strategy in some embodiments of the present disclosure is shown;
[0034] Fig.11 A schematic diagram showing a beam search decoding strategy in some embodiments of the present disclosure is shown;
[0035] Fig.12 The schematic diagram shows an architecture diagram of a decoding processing method according to other embodiments of the present disclosure;
[0036] Fig.13 The structure block diagram of the decoding processing device according to the embodiment of the present disclosure is schematically shown;
[0037] Fig.14 The block diagram schematically shows an electronic device suitable for implementing the decoding processing method according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0038] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present disclosure. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present disclosure. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present disclosure.
[0039] In the technical solution of the present invention, the user information (including but not limited to user personal information, user image information, user device information, such as location information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved are all information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of the relevant data comply with relevant laws, regulations and standards, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0040] In the scenario of using personal information for automated decision-making, the methods, devices, and systems provided by the embodiments of the present invention provide users with corresponding operation portals for users to choose to agree or reject the automated decision-making results; if the user chooses to reject, the expert decision-making process will be entered. The expression "automated decision-making" here refers to the activity of automatically analyzing and evaluating an individual's behavioral habits, interests and hobbies, or economic, health, credit status, etc. through computer programs, and making decisions. The expression "expert decision-making" here refers to the activity of making decisions by people who specialize in a certain field, have specialized experience, knowledge and skills, and have reached a certain level of professionalism.
[0041] In related technologies, prompt engineering, retrieval-enhanced generation, and secondary training / fine-tuning methods are usually used to improve the effectiveness of natural language generation models in specific fields.
[0042] The natural language generation model has a very rich corpus during the training process. It has knowledge in different fields and has a certain understanding of concepts in specific fields during the training process. Therefore, by giving the natural language generation model relevant identities through the prompt project, it can have a guiding role in content generation, such as: "If you are a senior tourism expert", "If you are a physicist", "If you are a stock researcher", etc. The prompt project is simple to implement and has low adaptability costs for different fields, but it has limited effect on the model, and there is a problem that the effect gradually weakens with the length of the conversation.
[0043] Retrieval-Augmented Generation (RAG) is a method for optimizing the output of natural language generation models, enabling them to reference the content of external knowledge bases before generating responses, to improve the accuracy and reliability of the generation model. RAG technology greatly improves the accuracy and reliability of generated content and solves the problem of hallucinations, but the cost of engineering implementation is high; it has very high requirements for the retrieval quality of external knowledge bases.
[0044] In order to make the model have more advanced specific domain capabilities, many institutions have begun to build industry natural language generation models and enterprise-level natural language generation models, generally through secondary training or fine-tuning. Secondary training or fine-tuning allows the natural language generation model to internalize domain knowledge and is more friendly to the development of upper-level applications. However, the cost of training a natural language generation model is high, and the requirements for corpus quality and computing resources are extremely high; it also requires high technical capabilities of the team, and it is easy to have the risk of model collapse.
[0045] Some embodiments of the present disclosure provide a decoding processing method, which introduces an external decoding correction strategy to correct the output content of the natural language generation model. It can ensure the rationality of the generated content through the original prediction ability of the natural language generation model, and enhance the field generation ability by correcting the correction probability of candidate words appearing in specific fields. Not only can the correction ability of different specific fields be switched freely, but also the collapse risk of secondary training of large models is avoided. The natural language generation model can enhance the content generation ability of specific fields to a certain extent, and optimize the wording habits and vocabulary tendencies in its content. Compared with prompt engineering, retrieval enhancement generation, secondary training and other methods, it has the characteristics of more direct effect and lower implementation cost.
[0046] Based on the improvement of the decoding method for optimizing the natural language generation model, an external decoding correction strategy is introduced to control at the token level, so that the natural language generation model can enhance the content generation ability of a specific field to a certain extent. The core idea is to calculate the distribution model of the next token in a specific field, and then act on the decoding strategy of the natural language generation model to correct the next token probability originally calculated by the natural language generation model. Based on the optimization of the decoding method of the natural language generation model, a low-cost method is used to enhance the generation ability of the natural language generation model in a specific field, fully utilize and stimulate the natural language generation model's own existing domain knowledge, and can also control the preference of the natural language generation model to generate content in the decoding link through the external knowledge base in the specific field.
[0047] Figure 1 The following schematically shows an application scenario diagram of the decoding processing method according to an embodiment of the present disclosure. It should be noted that: Figure 1 What is shown are merely examples to which the embodiments of the present disclosure can be applied, so as to help those skilled in the art understand the technical content of the present disclosure, but it does not mean that the embodiments of the present disclosure cannot be used in other devices, systems, environments or scenarios.
[0048] like Figure 1 As shown, the application scenario 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for a communication link between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0049] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
[0050] The terminal devices 101 , 102 , and 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0051] The server 105 may be a server that provides various services, such as a background management server that provides support for websites browsed by users using the terminal devices 101, 102, and 103 (for example only). The background management server may analyze and process the received data such as user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal device. For example, the server 105 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud computing, network services, and middleware services.
[0052] In applications such as client applications and web applications (abbreviated as APP in English), the client (i.e., front end) and the server (i.e., back end) can communicate data through network messages. For example, the user can enter the corresponding text content in the client, and then in the APP client, the input text parameters that the server needs to obtain from the client are assembled, and the network request method is called to send to the server. The server runs the deployed natural language generation model and plugs in at least one knowledge base in a specific field to implement the decoding processing method provided in some embodiments of the present disclosure, and finally returns the generated content to the client.
[0053] It should be noted that the decoding processing method provided in the embodiment of the present disclosure can generally be executed by at least one of a terminal device or a server. Accordingly, the decoding processing device provided in the embodiment of the present disclosure can generally be set in at least one of a terminal device or a server.
[0054] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0055] The following will be based on Figure 1 The scene described by Figure 2 to Figure 12 The decoding processing method of the embodiment of the present disclosure is described in detail.
[0056] Figure 2 The flowchart of the decoding processing method according to the embodiment of the present disclosure is schematically shown.
[0057] like Figure 2 As shown, this embodiment includes:
[0058] In operation S210, in response to inputting text into a natural language generation model, determining a candidate word set and probability distribution of a next position predicted by a decoding layer of the natural language generation model;
[0059] The natural language generation model can be an autoregressive language model that can predict the next word based on the previous content. In the field of natural language processing, "token" is usually translated as "word" or "mark". Token is the basic unit in the text data processing process, which can be a character, word, number, punctuation mark or set.
[0060] For example, a natural language generation model can include an encoding layer and a decoding layer. The encoder is used to encode the text, and the decoder is used to autoregressively decode the text based on the original encoding and partial decoding output.
[0061] In some embodiments, the natural language generation model may be an initial large language model obtained by pre-training, or may be used in combination with one or more methods of prompt engineering, retrieval enhancement generation, and secondary training / fine tuning based on the initial large language model. The initial large language model refers to a large language model obtained by pre-training, that is, a general large language model trained through parameter adjustments at the billion level or even the trillion level.
[0062] The input text may be the text input to the encoding layer of the natural language generation model. It is understandable that in practical applications, the text to be input to the natural language generation model may be determined according to actual needs, and this embodiment does not specifically limit the input text.
[0063] In some embodiments, the encoding layer of the natural language generation model may be any encoding layer that can encode text. For example, the encoding layer of the natural language generation model may be an encoding layer used in a semantic enhancement representation model. In some examples, in order to further improve the accuracy of the words determined at the next position, the encoding layer in this example may also be an encoding layer based on an attention mechanism.
[0064] In some embodiments, the decoding layer of the natural language generation model can select a word from the predicted candidate word set as the output word of the next position. The decoding algorithms of the decoding layer include greedy search, beam search, top-k sampling, and top-p (selecting tokens with cumulative probability ≤ P). Among them, the greedy search decoding algorithm selects the word with the highest conditional probability as the current output each time. The beamsearch decoding algorithm will retain several paths with the highest probability at the same time during decoding, and select the path with the highest probability as the current output. The Top-k sampling decoding algorithm takes the first k words with the highest conditional probability, reorganizes them into a new probability distribution, and then samples them as the current output. Top-P sampling selects tokens with cumulative probability ≤ P and performs random sampling.
[0065] In operation S220, obtain the correction probability of each candidate token in the candidate token set in a specific domain, where the correction probability is determined according to the distribution law of candidate tokens in the specific domain, and the specific domain is associated with the input text;
[0066] Exemplarily, the specific domain includes a knowledge system, terms, concepts, and practices related to a specific topic or professional field, such as the financial field, the medical field, the mechanical field, etc. It should be noted that the scope of the specific domain depends on the scope of the pre-collected knowledge base. For example, the financial field can be further divided into multiple sub-fields such as banking, funds, insurance, and securities, and the specific domain can be one of these sub-fields.
[0067] The correction probability is determined according to the distribution law of candidate tokens in the specific domain, and the correction probability indicates the language usage law of each candidate token in the candidate token set in the specific domain. For example, if the character starts with "金" (gold), if the specific domain is the financial field, it tends to generate "金融资本" (financial capital), that is, when the current position is "金" and "融" is a candidate token, the correction probability is relatively large; while if the specific domain is the medical field, it tends to generate "金丝草" (Japanese stiltgrass), that is, when the current position is "金" and "丝草" is a candidate token, the correction probability is relatively large.
[0068] Exemplarily, the specific domain being associated with the input text means that a prompt word about the specific domain is input before the input text. Or, the input text contains questions related to the specific domain, such as "Please answer the meaning of futures in stocks" and "Please answer the matters needing attention when having a cold". Among them, the specific domain can be determined as the stock field through stocks and futures, and the specific domain can be determined as the medical field through cold. Or, the input text contains role prompt words related to the specific domain, such as "You are a financial expert with decades of experience and have very in-depth experience in stocks" and "You are a mathematician with more than a decade of experience". The specific domain can be determined as the stock field through finance and stocks, and the specific domain can be determined as the mathematics field through mathematician. Or, when using the retrieval-augmented generation technology, determine from which domain's vector knowledge base to retrieve during the RAG process, or which domain the retrieved and generated content involves. Or, the specific domain can be predicted through the semantic information of the input text.
[0069] In operation S230, based on the correction probability of each candidate token, perform a correction operation on the probability distribution;
[0070] A probability distribution refers to the probability of each token in the set of candidate tokens. For example, if the probability of "zai" is 0.7 and the probability of "shi" is 0.3, they constitute a probability distribution. The correction operation includes operations to adjust the probability of each token in the set of candidate tokens, aiming to make the generated text more conform to the language usage habits and professionalism of a specific field. The acquisition of the corrected probability includes at least one of the following: rule-based correction, that is, setting the weights of certain tokens according to the language rules of a specific field; using a domain-specific corpus to count the frequencies of tokens and adjusting the probability distribution accordingly; pre-training a classifier or regression model to predict the corrected probability of each candidate token according to domain characteristics.
[0071] In operation S240, based on the corrected probability distribution, the target token at the next position is determined from the set of candidate tokens.
[0072] Exemplarily, based on the corrected probability distribution, the candidate tokens can be sorted in descending order of probability values to obtain a sorting result. The candidate token with the largest probability value in the sorting result is taken as the target token.
[0073] In the embodiments of the present disclosure, the set of candidate tokens predicted and output by the decoding layer of the natural language generation model in each round is determined based on the input text and the predicted tokens selected in the previous rounds. That is, in each round of token prediction process, the predicted tokens are used as the above text, combined with the input text, to predict the token at the next position. When the selected target token is the end identifier, the predicted words in each round are concatenated in turn to obtain the generated content of the natural language generation model.
[0074] According to the embodiments of the present disclosure, an external decoding correction strategy is introduced to correct the output content of the natural language generation model, which can ensure the rationality of the generated content through the original prediction ability of the natural language generation model, and enhance the domain generation ability by correcting the corrected probability of candidate tokens appearing in a specific field. It can not only freely switch the correction capabilities of different specific fields, but also avoid the collapse risk of secondary training of large models. The natural language generation model can enhance the content generation ability of a specific field to a certain extent, optimize the language usage habits and vocabulary tendencies in its content, and has the characteristics of more direct effect and lower implementation cost compared with methods such as prompt engineering, retrieval-augmented generation, and secondary training.
[0075] Figure 3 Schematically shows a flowchart of obtaining the corrected probability according to an embodiment of the present disclosure.
[0076] Before obtaining the corrected probability of each candidate token in the set of candidate tokens in a specific field, as Figure 3 shown, this embodiment includes:
[0077] In operation S310, based on a first corpus of a specific domain, at least one domain word-gram and a first distribution feature of each domain word-gram are determined, wherein the first distribution feature is used to represent a distribution regularity, and the domain word-gram includes a word-gram extracted from the first corpus;
[0078] Exemplarily, the first corpus includes a collection of texts in a specific field. For example, in the process of constructing the first corpus, the specific field is split into different sub-fields to obtain the texts of each sub-field. The splitting dimension can be carried out according to the planning of the sub-field, such as by sub-industry division: banking, insurance, funds, futures, etc., or by investment sector: new energy, financial real estate, TMT, healthcare, etc. The corresponding token word vector can be generated for the corpus through the embedding layer of the natural language generation model. The embedding layer used is consistent with the corresponding natural language generation model to ensure consistent expression in the same word space.
[0079] Domain terms include characters, words or terms with specific meanings in a specific field. For example, in the legal field, "contract", "litigation", "judgment" and so on are all domain terms. The first distribution feature is used to describe the basic characteristics or attributes of domain terms related to data distribution in the first corpus, including the distribution law of domain terms in the first corpus, which may include mean, probability distribution, word frequency, word position information, co-occurrence words and so on.
[0080] In operation S320 , based on the first distribution feature of each domain word-gram, a revised probability of each candidate word-gram is obtained.
[0081] The candidate word set may include domain words determined in the first corpus, and may also include general words without domain restrictions. When the candidate word belongs to the domain word category, the correction probability is calculated based on the first distribution feature corresponding to it. When the candidate word belongs to the general word category, there is no first distribution feature, so no correction is performed, and the correction probability is a null value.
[0082] Take the automatic report generation in the financial field as an example. For example, first collect a large amount of text data in a specific field to form a first corpus. Then extract domain words such as "stock", "market", and "investment" from the first corpus. Then, analyze the first distribution characteristics of these words in the corpus, such as: word frequency, the frequency of domain words in the corpus; co-occurrence analysis, the frequency and pattern of domain words co-occurring with other words; position information, the position distribution of domain words in sentences or documents; context association, the relationship between domain words and their context, such as grammatical structure or semantic role. Next, establish a probability model to predict the revised probability of each candidate word in a specific field, such as a statistical model or a machine learning model. Statistical models such as Poisson distribution and multinomial distribution estimate the probability of a word based on word frequency. Machine learning models such as logistic regression, support vector machine, neural network, etc. predict the weight of a word in a specific field based on its distribution characteristics. For example, if "investment" appears frequently in the "analysis" part of the report, then when generating this part of the text, the revised probability of "investment" will be increased. For another example, if "stock" and "investment" often appear adjacent to each other, then when the word at the current position is "stock", "investment" has a higher probability of being corrected.
[0083] According to the embodiments of the present disclosure, by introducing a first corpus of an external specific domain, domain words and corresponding first distribution features are obtained, which is conducive to calculating the correction probability in combination with the professional characteristics of the specific domain, so that the target words generated by the natural language generation model are more in line with the language habits and professionalism of the specific domain, thereby improving the accuracy and reliability of the target words.
[0084] Figure 4 The flowchart of determining domain word-grams according to an embodiment of the present disclosure is schematically shown.
[0085] like Figure 4 As shown, this embodiment is one of the embodiments of operation S310, including:
[0086] In operation S410, a probability distribution of at least one general word-gram is determined based on a second corpus of a general domain, and a probability distribution of at least one candidate domain word-gram is determined based on the first corpus, wherein the general domain includes an open domain that is not limited to a specific domain, for example, the second corpus is obtained based on corpora of at least two domains;
[0087] Exemplarily, the second corpus includes a collection of texts in a general domain, including texts in multiple different domains. General word-grams include word-grams extracted from the second corpus. Candidate domain word-grams include candidate words extracted from the first corpus that can become domain-specific vocabulary. The word-grams involved in the present disclosure may include dividing the corpus in the corpus, and then screening word-grams whose frequency of occurrence is greater than a certain number of times. Among them, statistical methods can be applied to estimate the probability distribution of word-grams in the corpus. The first distribution feature can be obtained through the probability distribution.
[0088] Similarly, the corresponding token word vectors can be generated for the corpus through the embedding layer of the natural language generation model. The embedding layer used is consistent with the corresponding natural language generation model to ensure consistent expression in the same word space.
[0089] In operation S420 , at least one domain word-gram is determined based on a degree of difference between a probability distribution of at least one common word-gram and a probability distribution of at least one candidate domain word-gram.
[0090] For example, for a certain word, which is both a general word and a candidate domain word, a difference metric is used to calculate the difference between the two probability distributions of the same word, and the token probability distribution of the general corpus is compared with the token probability distribution of the candidate domain word, to identify the statistical characteristics of a specific domain, such as listing tokens with a distribution probability significantly higher than that of the general corpus as tokens of a specific domain (i.e., domain words), or listing tokens with large joint distribution differences as tokens of a specific domain. Alternatively, if a certain word is only a candidate domain word, it is identified as a token of a specific domain. For example, a financial vocabulary dictionary is converted into a token, included in the range of specific domain tokens, and a fixed value is assigned as the marginal probability in the first distribution feature. One or more tokens are manually designated as specific tokens in a specific domain, and a fixed value is assigned as the marginal probability in the first distribution feature.
[0091] According to the embodiments of the present disclosure, the selected domain words are closer to the professional terms and expressions of a specific domain, thereby enhancing the domain relevance of the generated text.
[0092] In some embodiments, based on a first corpus in a specific domain, determining a first distribution feature of each domain word includes:
[0093] Based on the number of occurrences of each domain word in the first corpus, the individual distribution characteristics of each domain word are determined; or, based on the number of co-occurrences of each domain word and at least one other domain word in the first corpus, the joint distribution characteristics of each domain word are determined.
[0094] For example, individual distribution features refer to the distribution of a single domain word in the first corpus, using a word frequency statistical algorithm, such as simple counting or TF-IDF weight calculation. Joint distribution features refer to the distribution of two or more domain words that appear together in the first corpus, which can be obtained by applying a co-occurrence analysis algorithm.
[0095] According to the embodiments of the present disclosure, individual distribution features and joint distribution features complement each other, avoiding omission of domain word units, and facilitating more accurate identification of domain keyword word units.
[0096] Figure 5 The flowchart of determining the first distribution feature of each domain word according to an embodiment of the present disclosure is schematically shown.
[0097] like Figure 5 As shown, this embodiment is one of the embodiments of operation S310, including:
[0098] In operation S510, the difference degree corresponding to each domain word is normalized to obtain a normalized distribution feature;
[0099] The degree of difference is used to measure the difference between domain terms in a specific domain and in a general domain, such as the difference between the frequency of "heart disease" in the medical domain and in the general domain, and the difference between the frequency of "finance" in the financial domain and in the general domain. Standardization is used to convert the degree of difference corresponding to different terms into a standardized measure for easy comparison and processing. The standardized distribution feature includes the result of the standardization process.
[0100] In some embodiments, the individual distribution features and / or joint distribution features of each domain word between two corpora may be standardized to obtain standardized distribution features.
[0101] In operation S520 , the standardized distribution feature of each domain word is used as a first distribution feature.
[0102] For example, suppose a financial institution wants to develop an automated loan document generation system that can generate personalized loan agreements and risk assessment reports based on the customer's financial status and loan needs.
[0103] First, we collected and constructed a first corpus in the loan field, which consisted of professional documents including historical loan agreements, risk assessment reports, and financial regulations. Then, in order to contrast with the loan field, we also constructed a second corpus containing texts from multiple fields such as news reports and popular science articles. Then, by applying regular expressions and named entity recognition techniques, we extracted key professional terms in the loan field, such as "interest rate", "mortgage", and "credit rating", from the first corpus.
[0104] Next, the frequency of occurrence of these domain words in the two corpora was counted to determine their individual distribution characteristics and joint distribution characteristics. Then, the differences between these domain words in the two corpora were normalized by Z-score to convert them into standardized distribution characteristics.
[0105] These standardized distribution features are used as the first distribution features of the updated domain word-units, and machine learning models such as logistic regression or random forest are used to calculate the correction probability of each domain word-unit based on these features.
[0106] According to the embodiments of the present disclosure, the general domain is used as a benchmark for obtaining the degree of difference. After the degree of difference is standardized, the decoding stage has different tendencies for different domain words, further enhancing the content generation capability for a specific domain.
[0107] Figure 6 The flowchart of obtaining the revised probability of each candidate word-gram according to another embodiment of the present disclosure is schematically shown.
[0108] like Figure 6 As shown, this embodiment is one of the embodiments of operation S320, including:
[0109] In operation S610, based on the first distribution feature of each domain word-gram, a joint probability of each candidate word-gram is obtained, where the joint probability is the probability that the candidate word-gram at the next position and the word-grams at the N positions before the next position co-occur, where N is an integer greater than or equal to 1;
[0110] For example, the first distribution feature includes the high-frequency positions of domain words obtained based on the first corpus. When a candidate word belongs to the domain word, the probability of co-occurrence is calculated by the position of the candidate word and the positions of the words in the first N predicted positions in the first corpus.
[0111] In some embodiments, the joint probability between the next token and the previous context is derived according to the marginal probability and the conditional probability according to the chain rule; and / or, in other embodiments, the joint probability between the next token and the previous context is calculated using a Markov chain.
[0112] In operation S620, a revised probability of each candidate word-gram is obtained based on the joint probability of each candidate word-gram and the first revision coefficient, wherein the first revision coefficient of each candidate word-gram is preset.
[0113] The first correction coefficient is a pre-set value (such as a value between 0 and 1) used to adjust the joint probability of candidate word units to obtain a correction probability. For example, if the word "contract" is very important in legal texts, a higher first correction coefficient may be set to increase its correction probability, thereby guiding the natural language generation model to consider domain specificity and context relevance to decode the accurate target word unit.
[0114] Exemplarily, the correction coefficients involved in the present disclosure (such as the first correction coefficient and the second correction coefficient described below) can be determined based on at least one of the following methods: determined by the knowledge and experience of domain experts; statistically analyzing the frequency of occurrence of domain words in the first corpus, and assigning higher correction coefficients to words with high frequency of occurrence; after the correction coefficients are preliminarily set, their effects are verified through experiments, and adjusted according to the experimental results. After the correction coefficients are preliminarily set, a dynamic adjustment mechanism is established, and according to the distribution characteristics of words in different specific fields, the same words have different correction coefficients in different specific fields.
[0115] In some embodiments, in order to improve the consistency of the correction coefficient, a standardized evaluation method, such as Z-score standardization, may be used to convert the correction coefficient into a standard score to eliminate the dimensional effects between different word units.
[0116] According to the embodiments of the present disclosure, the specific domain matching degree of the target word unit selection and the context is improved by the joint probability. By considering the context and domain importance, the generated text is more professional and accurate. The purpose of the first correction coefficient is to improve the accuracy of the correction probability.
[0117] Figure 7 The flowchart of obtaining the joint probability of each candidate word-gram according to an embodiment of the present disclosure is schematically shown.
[0118] like Figure 7 As shown, this embodiment is one of the embodiments of operation S610, including:
[0119] In operation S710, based on the first distribution feature of each candidate word-gram, a marginal probability of each candidate word-gram is obtained;
[0120] In operation S720, for the word-grams at the first N positions, the conditional probability of the word-gram at the nth position is obtained, where n is an integer greater than or equal to 1, and n is less than or equal to N;
[0121] In operation S730 , a joint probability of each candidate word-gram is obtained based on the marginal probability and the conditional probability of each word-gram in the first N positions.
[0122] Marginal Probability is the probability of an event occurring regardless of other events.
[0123] In some embodiments, obtaining the conditional probability of the word at the nth position includes: obtaining the conditional probability of the word at the nth position given all word elements before the word at the nth position; or, obtaining the conditional probability of the word at the nth position given the word at the n-1th position.
[0124] When the conditional probability of the nth token is obtained given all the tokens before the nth token, it is called the conditional probability correction method. The chain rule is used here, that is, through a series of conditional probabilities and marginal probabilities, the joint probability is derived using formula 1 to correct the probability value of the next token. Where N is the set derivation sequence length, that is, how many tokens are pushed from the next position to the previous text, and the joint probability As shown in formula 1:
[0125] Formula 1
[0126] According to the domain corpus, the marginal probability and conditional probability of each token are counted, so the joint probability value of the token can be calculated. Then the marginal probability of the next token is , the revised probability of next token: , where α is the first correction coefficient.
[0127] The conditional probability correction method takes the above influences into account, and the calculation method is simple and easy to understand and apply.
[0128] When the conditional probability of the word at the nth position is obtained given the word at the n-1th position, it is called the Markov chain correction method. Construct a Markov chain probability model for a specific token in a specific field. Markov is a random process with the Markov property, that is, the future state depends only on the current state and has nothing to do with the past state.
[0129] Based on the chain rule, the Markov chain correction method derives the joint probability according to Formula 2. The joint probability is as follows: It is expressed as:
[0130] Formula 2
[0131] in, etc. are token expressions, while is given under the conditions Probability distribution.
[0132] Then the marginal probability of the next token is , the revised probability of next token is: , where β is the first correction coefficient, and α and β may be the same or different.
[0133] The Markov chain correction method simplifies the calculation process of the temporal joint probability.
[0134] In some embodiments, M knowledge bases corresponding to M candidate domains are pre-stored, where each knowledge base includes the correspondence between each domain token in the corresponding candidate domain and its marginal probability. M is an integer greater than or equal to 1. For example, it is stored in the form of key-value pairs as "<token, marginal probability>". When obtaining the corrected probability, first, a specific domain is determined from the M candidate domains based on the input text; then the marginal probability of the candidate token is obtained from the knowledge base of the specific domain. And, the conditional probability of the candidate token is obtained from the first corpus according to the Markov chain correction method or the conditional probability correction method. Finally, the joint probability is obtained based on the marginal probability and the conditional probability, and the corrected probability is further obtained. In other embodiments, each knowledge base may include the correspondence between each domain token in the corresponding candidate domain and its marginal probability, and the conditional probability of each domain token given at least one other domain token. When obtaining the corrected probability, after determining the specific domain, the marginal probability and the conditional probability are directly obtained from the knowledge base, for example, stored in the form of key-value pairs as "<token, marginal probability, conditional probability 1, conditional probability 2...>".
[0135] Figure 8 Schematically shows a flowchart of obtaining the corrected probability of each candidate token according to another embodiment of the present disclosure.
[0136] As Figure 8 shown, this embodiment is one of the embodiments of operation S320, including:
[0137] In operation S810, based on the first distribution feature of each candidate token, the marginal probability of each candidate token is obtained;
[0138] In operation S820, based on the marginal probability of each candidate token and the second correction coefficient, the corrected probability of each candidate token is obtained, where the second correction coefficient of each candidate token is pre-set.
[0139] The second correction coefficient is a pre-set value (such as a value between 0 and 1), which is used to adjust the joint probability of the candidate token to obtain the corrected probability.
[0140] This embodiment refers to the method of directly combining the marginal probability and the second correction coefficient to obtain the corrected probability as the greedy correction method. next token is represented as , and its corrected probability is: , where γ is the second correction coefficient. The greedy correction method calculates the correction probability in a simple and efficient way.
[0141] Fig. 9 Schematically shows a flowchart of obtaining a correction probability according to another embodiment of the present disclosure.
[0142] In an embodiment of the greedy correction method, M knowledge bases corresponding to M candidate fields can be pre-stored, where each knowledge base includes the correspondence between each field token in the corresponding candidate field and its correction probability, and M is an integer greater than or equal to 1;
[0143] Compared with the conditional probability correction method and the Markov chain correction method, the greedy correction method can directly obtain the correction probability based on the marginal probability and the second correction coefficient, without calculating the joint probability between the next token and the N tokens in the above text. Therefore, on the premise of determining the second correction coefficient, the correspondence between each field token and its correction probability can be pre-stored in the knowledge base, for example, stored in the form of key-value pairs as "<token, correction probability>".
[0144] As Fig. 9 shown, this embodiment is one of the embodiments of operation S220, including:
[0145] In operation S910, determine a specific field from the M candidate fields based on the input text;
[0146] The specific field can be determined by means of a prompt word, a keyword in the input text, or the semantics of the input text, etc.
[0147] In operation S920, based on the knowledge base of the specific field, obtain the correction probability of each candidate token in the candidate token set in the specific field.
[0148] According to the embodiments of the present disclosure, one or more external knowledge bases of specific fields can be introduced, the input text can be routed to the corresponding specific field, and the correction probability can be obtained from the knowledge base to efficiently determine the target token.
[0149] Exemplarily, the calculation of the modified probability disclosed in the present invention involves a conditional probability modification method, a Markov chain modification method, and a greedy modification method. In the process of implementing the decoding processing method, at least one of the conditional probability modification method, the Markov chain modification method, and the greedy modification method can be executed to obtain the modified probability. For example, the modified probability can be obtained according to the calculation result of a method among the conditional probability modification method, the Markov chain modification method, and the greedy modification method, or it can be obtained by weighted calculation according to the calculation results of multiple methods. Specifically, when calculating the modified probability, it can be determined whether the domain word of a specific domain satisfies the Markov property. If it satisfies, the Markov chain modification method is executed, otherwise the Markov chain modification method is not executed. It can be determined whether the computing resources are sufficient. If not, only the greedy modification method is executed. If sufficient, the greedy modification method is executed, and at least one of the conditional probability modification method and the Markov chain modification method (assuming that the Markov property is satisfied) can be optionally executed. Alternatively, at least one of the conditional probability modification method, the Markov chain modification method, and the greedy modification method can be selected according to the characteristics of a specific domain. For example, the corresponding relationship between each specific domain and the modification method can be preset.
[0150] In some embodiments, performing a modification operation on the probability distribution based on the modified probability of each candidate word-gram includes: summing the modified probability of each candidate word-gram with the corresponding probability value in the probability distribution.
[0151] In some embodiments, the probability distribution of the next position candidate word-unit set is obtained according to at least one of the following decoding strategies: greedy search decoding strategy, beam search decoding strategy, Top-K sampling decoding strategy, Top-P sampling decoding strategy.
[0152] Fig.10 A schematic diagram of a greedy search decoding strategy in some embodiments of the present disclosure is shown.
[0153] Under the greedy search decoding strategy, considering the model vocabulary size, the decoding layer calculates the probabilities of all possible candidate words for the next position and selects the word with the highest probability as the output for the next step. Fig.10 The probability distribution of the candidate word set shown in Figure 2, where the probability of the i-th candidate word is expressed as .
[0154] In the related art, the greedy search decoding strategy selects the next token according to Formula 3:
[0155] Formula 3
[0156] Based on the modified probability of each candidate word, after the probability distribution is modified, the modified probability of the i-th candidate word is expressed as , select the next token according to formula 4:
[0157] Formula 4
[0158] Fig.11 A schematic diagram of a beam search decoding strategy in some embodiments of the present disclosure is shown.
[0159] Beam search is different from greedy search in that it retains more candidate words. For example, when the beam width num_beams=K (K≥1), the sequence with the highest probability in K steps is considered comprehensively. Fig.11 The probability distribution shown in the figure is that the probability of the next token is the sum of the probabilities of the K-step word units in each step. The format is<word:probability> ). The result of the greedy algorithm is: the nicewoman, while the result of the beam search is: the dog has.
[0160] When the beam search decoding strategy is adopted, each candidate word-gram in operations S210 to S240 refers to a K-step candidate word-gram sequence. Accordingly, the modified probability of the K-step candidate word-gram sequence is calculated.
[0161] X represents the candidate word sequence, Represents the probability of the i-th candidate token in the candidate token sequence of K steps in the probability distribution. In the related art, the beam search decoding strategy selects the next token according to Formula 5:
[0162] Formula 5
[0163] Based on the modified probability of each candidate word, after the probability distribution is modified, the modified probability of the i-th candidate word in the K-step candidate word sequence is expressed as , if the greedy correction method is used, nexttoken is selected according to formula 6:
[0164] Formula 6
[0165] If the conditional probability or Markov correction method is used, the corrected probability of the candidate word sequence of K steps is expressed as , refer to formula 1 or 2, and take the marginal probability of the last word in the sequence when calculating. The words in the first N positions can include other words in the candidate word sequence and calculate the conditional probability. Then select the next token according to formula 7:
[0166] Formula 7
[0167] The next token in Formula 6 and Formula 7 may be a target word-gram sequence. In some embodiments, the word-grams at the first N positions may include word-grams at one or more positions that have been predicted previously in addition to other word-grams in the candidate word-gram sequence.
[0168] Top-K sampling is to select the k tokens with the highest probability and perform random sampling. The next token is selected according to formula 8:
[0169] Formula 8
[0170] Based on the modified probability of each candidate word, after modifying the probability distribution, the Top-K sampling nexttoken is selected according to Formula 9:
[0171] Formula 9
[0172] In Formula 8 and Formula 9, represents the probability of the i-th candidate word in the probability distribution predicted by the decoding layer, is the modified probability of the ith candidate word.
[0173] Top-P sampling is to select m (m>0) tokens with cumulative probability ≤ P for random sampling. The next token is selected according to formula 10:
[0174] Formula 10
[0175] Based on the modified probability of each candidate word, after modifying the probability distribution, the Top-P sampling nexttoken is selected according to formula 11:
[0176] Formula 11
[0177] In Formula 10 and Formula 11, represents the probability of the i-th candidate word in the probability distribution predicted by the decoding layer, is the modified probability of the ith candidate word.
[0178] Fig.12 The following schematically shows an architecture diagram of a decoding processing method according to some other embodiments of the present disclosure.
[0179] Reference Fig.12First, construct a domain-specific corpus and a general corpus. The corpus word embedding process is performed through the embedding layer of the natural language generation model to generate the corresponding token word vector. Then compare the token distribution characteristics of the general corpus with the token distribution characteristics of the domain-specific corpus to identify the statistical characteristics of the specific domain, such as listing tokens with a distribution probability significantly higher than that of the general corpus as tokens of the specific domain, or listing tokens with large joint distribution differences as tokens of the specific domain. Next, extract the token distribution model of the specific domain. On the one hand, standardize its difference value to obtain the first distribution feature of the token. On the other hand, convert the financial vocabulary dictionary into a token and include it in the domain-specific token range, and assign a fixed value to the token as the first distribution feature of the token. On the other hand, manually designate one or more tokens as specific tokens in a specific domain, and assign a fixed value as the first distribution feature.
[0180] The natural language generation model is an autoregressive model, and the content is generated by token by token. Generating the next token itself is a probability selection problem. If you want to correct the token generation of the natural language generation model, here are three optional methods: the first is the greedy correction method, that is, according to the probability of each specific token; the second is the conditional probability correction method, that is, according to the marginal probability and conditional probability, the joint probability between the next token and the previous text is derived, and then corrected; the third is the Markov chain correction method, that is, using the Markov chain to calculate the modification probability of the next next token.
[0181] Then, for example, if the input text is "my name is han mei", the candidate word set includes mei, li, and hua, with probability distribution of 90%, 5%, and 2%. Adapt the existing decoding strategy, obtain the correction probability of each candidate word, correct the decoding strategy, and generate the next token.
[0182] According to the embodiments of the present disclosure, by introducing an external domain-specific token distribution model to optimize the decoding process, the output of the model can be effectively corrected and enhanced without changing the original model architecture.
[0183] Specifically, we first use the predictive power of the natural language generation model to generate preliminary text content. Then, by introducing a token distribution model for a specific field, we calculate the correction probability to adjust and correct the generated content, optimize the use of vocabulary and sentence structure according to the characteristics of the field, and thus improve the professionalism and accuracy of the text.
[0184] Compared with prompt engineering, RAG technology, secondary training and other methods, the method of introducing an external domain token distribution model has obvious advantages. First, its effect is more direct because it acts directly on the output layer of the model instead of modifying the input or training process of the model. Secondly, the implementation cost is lower because it does not require retraining the model or adjusting the internal parameters of the model, but only requires the introduction of additional domain models in the decoding stage. In addition, the rationality of the generated content can be guaranteed. The original predictive ability of the natural language generation model ensures the basic fluency and readability of the text, while the introduction of the domain token distribution model further enhances the domain relevance and professionalism of the text, which not only retains the original advantages of the model, but also improves the quality of the generated content through the correction of the domain model.
[0185] Finally, the use of external domain distribution models not only allows the generation capabilities of different domains to be freely switched as needed, but also avoids the risks that may be brought about by secondary training of the natural language generation model, such as model collapse or overfitting.
[0186] Based on the above decoding processing method, the present disclosure also provides a decoding processing device. Fig.13 The device is described in detail.
[0187] Fig.13 The structure block diagram of the decoding processing device according to the embodiment of the present disclosure is schematically shown.
[0188] like Fig.13 As shown, the decoding processing device 1300 of this embodiment includes a determination module 1310 , an acquisition module 1320 , a correction module 1330 and a target module 1340 .
[0189] The determination module 1310 may perform operation S210 for determining a candidate word set and probability distribution of a next position predicted by a decoding layer of the natural language generation model in response to inputting text into the natural language generation model;
[0190] The acquisition module 1320 may perform operation S220 for acquiring a correction probability of each candidate word in the candidate word set in a specific field, wherein the correction probability is determined according to a distribution rule of the candidate word in the specific field, and the specific field is associated with the input text;
[0191] The correction module 1330 may perform operation S230 for performing a correction operation on the probability distribution based on the correction probability of each candidate word-gram;
[0192] The target module 1340 may perform operation S240 to determine a target word-gram at the next position from the candidate word-gram set based on the modified probability distribution.
[0193] In some embodiments, the decoding processing device 1300 may also include a modified probability calculation module, and the model can perform operations S310~operation S320, operation S410~operation S420, operation S510~operation S520, operation S610~operation S620, operation S710~operation S730, operation S810~operation S820, and operation S910~operation S920, which will not be repeated here.
[0194] For the parts not mentioned in the device part, they can be understood with reference to the various embodiments of the above method. That is, the device part includes modules for executing the various steps of any one of the method embodiments described above. In addition, the implementation methods, technical problems solved, functions implemented, and technical effects achieved of each module / unit / subunit, etc. in the device part embodiment are respectively the same or similar to the implementation methods, technical problems solved, functions implemented, and technical effects achieved of each corresponding step in the method part embodiment, and will not be repeated here.
[0195] According to an embodiment of the present disclosure, any multiple modules among the determination module 1310, the acquisition module 1320, the correction module 1330 and the target module 1340 can be combined into one module for implementation, or any one of the modules can be split into multiple modules. Alternatively, at least part of the functions of one or more of these modules can be combined with at least part of the functions of other modules and implemented in one module.
[0196] According to an embodiment of the present disclosure, at least one of the determination module 1310, the acquisition module 1320, the correction module 1330 and the target module 1340 may be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application-specific integrated circuit (ASIC), or may be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware and firmware or in an appropriate combination of any of them. Alternatively, at least one of the determination module 1310, the acquisition module 1320, the correction module 1330 and the target module 1340 may be at least partially implemented as a computer program module, and when the computer program module is executed, the corresponding function may be executed.
[0197] Fig.14 The block diagram schematically shows an electronic device suitable for implementing the decoding processing method according to an embodiment of the present disclosure.
[0198] like Fig.14As shown, the electronic device 1400 according to an embodiment of the present disclosure includes a processor 1401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1402 or a program loaded from a storage part 1408 to a random access memory (RAM) 1403. The processor 1401 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or a related chipset and / or a dedicated microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 1401 may also include an onboard memory for caching purposes. The processor 1401 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present disclosure.
[0199] In RAM 1403, various programs and data required for the operation of electronic device 1400 are stored. Processor 1401, ROM 1402 and RAM 1403 are connected to each other via bus 1404. Processor 1401 performs various operations of the method flow according to the embodiment of the present disclosure by executing the program in ROM 1402 and / or RAM 1403. It should be noted that the program can also be stored in one or more memories other than ROM 1402 and RAM 1403. Processor 1401 can also perform various operations of the method flow according to the embodiment of the present disclosure by executing the program stored in one or more memories.
[0200] According to an embodiment of the present disclosure, the electronic device 1400 may further include an input / output (I / O) interface 1405, which is also connected to the bus 1404. The electronic device 1400 may further include one or more of the following components connected to the I / O interface 1405: an input portion 1406 including a keyboard, a mouse, etc.; an output portion 1407 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 1408 including a hard disk, etc.; and a communication portion 1409 including a network interface card such as a LAN card, a modem, etc. The communication portion 1409 performs communication processing via a network such as the Internet. A drive 1410 is also connected to the I / O interface 1405 as needed. A removable medium 1411, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1410 as needed, so that a computer program read therefrom is installed into the storage portion 1408 as needed.
[0201] The present disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present disclosure is implemented.
[0202] According to an embodiment of the present disclosure, a computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, an apparatus, or a device. For example, according to an embodiment of the present disclosure, a computer-readable storage medium may include the ROM 1402 and / or RAM 1403 described above and / or one or more memories other than ROM 1402 and RAM 1403.
[0203] The embodiment of the present disclosure also includes a computer program product, which includes a computer program, and the computer program contains program code for executing the method shown in the flowchart. When the computer program product is run in a computer system, the program code is used to enable the computer system to implement the method provided by the embodiment of the present disclosure.
[0204] The above functions defined in the system / device of the embodiment of the present disclosure are performed when the computer program is executed by the processor 1401. According to the embodiment of the present disclosure, the system, device, module, unit, etc. described above can be implemented by a computer program module.
[0205] In one embodiment, the computer program may rely on tangible storage media such as optical storage devices, magnetic storage devices, etc. In another embodiment, the computer program may also be transmitted and distributed in the form of signals on a network medium, and downloaded and installed through the communication part 1409, and / or installed from the removable medium 1411. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0206] In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 1409, and / or installed from the removable medium 1411. When the computer program is executed by the processor 1401, the above functions defined in the system of the embodiment of the present disclosure are performed. According to the embodiment of the present disclosure, the system, device, means, module, unit, etc. described above can be implemented by a computer program module.
[0207] According to an embodiment of the present disclosure, the program code for executing the computer program provided by the embodiment of the present disclosure can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, Java, C++, python, "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on the remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect through the Internet).
[0208] The flowchart and block diagram in the accompanying drawings illustrate the system architecture, functions and operations that can be realized according to the system, method and computer program product of various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0209] It will be appreciated by those skilled in the art that the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways, even if such combinations and / or combinations are not explicitly described in the present disclosure. In particular, the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways without departing from the spirit and teachings of the present disclosure. All of these combinations and / or combinations fall within the scope of the present disclosure.
[0210] The embodiments of the present disclosure are described above. However, these embodiments are only for illustrative purposes and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the various embodiments cannot be used in combination to advantage. The scope of the present disclosure is defined by the attached claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art may make a variety of substitutions and modifications, which should all fall within the scope of the present disclosure.
Claims
1. A decoding processing method, characterized in that: include: In response to inputting text into a natural language generation model, determining a candidate word set and probability distribution of a next position predicted by a decoding layer of the natural language generation model; Obtaining a modified probability of each candidate word in the candidate word set in a specific field, wherein the modified probability is determined according to a distribution rule of the candidate word in the specific field, and the specific field is associated with the input text; Based on the modified probability of each candidate word, modifying the probability distribution; Based on the modified probability distribution, the target word-gram at the next position is determined from the candidate word-gram set.
2. The method according to claim 1, characterized in that Before obtaining the modified probability of each candidate word in the candidate word set in a specific field, the method further includes: Based on the first corpus of the specific domain, determining at least one domain word-gram and a first distribution feature of each domain word-gram, wherein the first distribution feature is used to represent the distribution law; Based on the first distribution feature of each domain word-gram, a revised probability of each candidate word-gram is obtained.
3. The method according to claim 2, characterized in that Determining at least one domain word based on the first corpus of the specific domain includes: Determine the probability distribution of at least one general word-gram based on a second corpus of a general domain, and determine the probability distribution of at least one candidate domain word-gram based on the first corpus, wherein the general domain includes an open domain that is not limited to a specific domain; The at least one domain word-gram is determined based on the degree of difference between the probability distribution of the at least one general word-gram and the probability distribution of the at least one candidate domain word-gram.
4. The method according to claim 2 or 3, characterized in that: Determining the first distribution feature of each domain word based on the first corpus of the specific domain includes: Determine the individual distribution characteristics of each domain word based on the number of occurrences of each domain word in the first corpus; or, Based on the number of co-occurrences of each domain word-gram and at least one other domain word-gram in the first corpus, a joint distribution feature of each domain word-gram is determined.
5. The method according to claim 3, characterized in that: Determining the first distribution feature of each domain word based on the first corpus of the specific domain includes: Standardizing the degree of difference corresponding to each domain word to obtain a standardized distribution feature; The standardized distribution feature of each domain word is used as the first distribution feature.
6. The method according to claim 2, characterized in that Based on the first distribution feature of each domain word, obtaining the modified probability of each candidate word includes: Based on the first distribution feature of each domain word-gram, a joint probability of each candidate word-gram is obtained, wherein the joint probability is the probability of the candidate word-gram at the next position and the word-grams at the N positions before the next position co-occurring, where N is an integer greater than or equal to 1; Based on the joint probability of each candidate word-gram and the first correction coefficient, the corrected probability of each candidate word-gram is obtained, wherein the first correction coefficient of each candidate word-gram is preset.
7. The method according to claim 6, characterized in that Based on the first distribution feature of each domain word, obtaining the joint probability of each candidate word includes: Based on the first distribution feature of each candidate word, obtaining the marginal probability of each candidate word; For the word-grams at the first N positions, obtain the conditional probability of the word-gram at the nth position, where n is an integer greater than or equal to 1, and n is less than or equal to N; Based on the marginal probability and the conditional probability of each word-gram in the word-grams at the first N positions, a joint probability of each candidate word-gram is obtained.
8. The method according to claim 7, characterized in that For the word-grams at the first N positions, obtaining the conditional probability of the word-gram at the nth position includes: Obtaining the conditional probability of the n-th position word-gram given all word-grams before the n-th position word-gram; or, Obtain the conditional probability of the word-gram at the n-th position given the word-gram at the n-1th position.
9. The method according to claim 2, characterized in that: Based on the first distribution feature of each domain word, obtaining the modified probability of each candidate word includes: Based on the first distribution feature of each candidate word, obtaining the marginal probability of each candidate word; Based on the marginal probability of each candidate word-gram and the second correction coefficient, a correction probability of each candidate word-gram is obtained, wherein the second correction coefficient of each candidate word-gram is preset.
10. The method according to claim 9, characterized in that Pre-store M knowledge bases corresponding to M candidate fields, wherein each knowledge base includes a corresponding relationship between each field word in the corresponding candidate field and its correction probability, and M is an integer greater than or equal to 1; Obtaining the modified probability of each candidate word in the candidate word set in a specific field includes: Determining the specific field from the M candidate fields based on the input text; Based on the knowledge base of the specific field, a revised probability of each candidate word in the candidate word set in the specific field is obtained.
11. The method according to any one of claims 1 to 3 and 5 to 10, characterized in that: Based on the modified probability of each candidate word, modifying the probability distribution includes: The modified probability of each candidate word is summed with the corresponding probability value in the probability distribution.
12. The method according to any one of claims 1 to 3 and 5 to 10, characterized in that: The probability distribution of the next position candidate word set is obtained according to at least one of the following decoding strategies: Greedy search decoding strategy, beam search decoding strategy, Top-K sampling decoding strategy, Top-P sampling decoding strategy.
13. A decoding processing device, characterized in that: include: A determination module, configured to determine, in response to inputting text into a natural language generation model, a candidate word set and probability distribution of a next position predicted by a decoding layer of the natural language generation model; an acquisition module, configured to acquire a modified probability of each candidate word in the candidate word set in a specific field, wherein the modified probability is determined according to a distribution rule of the candidate word in the specific field, and the specific field is associated with the input text; A correction module, configured to perform a correction operation on the probability distribution based on the correction probability of each candidate word; The target module is used to determine the target word-element at the next position from the candidate word-element set based on the modified probability distribution.
14. An electronic device comprising: one or more processors; a memory for storing one or more computer programs, It is characterized in that the one or more processors execute the one or more computer programs to implement the steps of the method according to any one of claims 1 to 12.
15. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 12 are implemented.
16. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 12 are implemented.
Citation Information
Cited By
Problem processing method and device, equipment, storage medium and program product
CN119128102A
Security defense method, device and equipment of large language model for malicious query
CN119442242A
Code generation method and device based on token occurrence probability adjustment and computer equipment
CN120704663A
Code generation method and device based on token occurrence probability adjustment, computer device
CN120704663B
Speech recognition method and device, electronic equipment and storage medium
CN121708918A
