Language response method and device, storage medium and electronic device
By receiving natural language input from users and dynamically calling large language models and CRF models, the problem of long-distance dependence in the joint training of BERT and CRF models is solved, and more accurate responses are achieved.
Patent Information
- Application Number
- CN202511588348.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-31
- Publication Date
- 2026-02-10
AI Technical Summary
The existing joint training of BERT and CRF models has the limitation of long-distance dependence, which leads to inaccurate response answers.
By receiving natural language input from the target user, the calling pattern and connection relationship are determined, and the large language model and probability model are dynamically called. The target model outputs response data and uses dynamic calling to call the CRF model as an independent tool. It can be embedded or called independently to improve the recognition ability of long-distance tasks.
It improves the ability to identify long-distance tasks and increases the accuracy of response answers.
Smart Images

Figure CN121501529A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and more specifically, to a language response method, apparatus, storage medium, and electronic device. Background Technology
[0002] In related technologies, since the BERT model is used to process input text and generate context-aware representations, the joint training of the traditional BERT model and the CRF model has the limitation of long-distance dependency.
[0003] This indicates that there is a technical problem in the relevant technologies that results in inaccurate responses due to the inability to handle long-distance tasks.
[0004] There is currently no effective solution to the aforementioned problems in the relevant technologies. Summary of the Invention
[0005] This invention provides a language response method, apparatus, storage medium, and electronic device to at least solve the problem of inaccurate response answers caused by the inability to perform long-distance tasks in related technologies.
[0006] According to an embodiment of the present invention, a language response method is provided, comprising: receiving natural language input by a target user through an input interface of a target model, wherein the target model includes a first model and a second model, the first model including a large language model and the second model including a probabilistic model; determining a calling pattern based on the natural language, wherein the calling pattern is used to indicate whether the first model calls the second model; determining a connection relationship between the first model and the second model; and controlling the target model to output target response data to the natural language based on the calling pattern and the connection relationship.
[0007] In one exemplary embodiment, determining the invocation pattern based on the natural language includes: if the natural language includes an invocation instruction, determining the invocation pattern as invoking the second model; if the natural language does not include the invocation instruction, determining the invocation pattern as not invoking the second model; determining the character length of the natural language; if the character length is greater than a first predetermined threshold, determining the invocation pattern as invoking the second model; if the character length is less than or equal to the first predetermined threshold, determining the invocation pattern as not invoking the second model.
[0008] In one exemplary embodiment, controlling the target model to output target response data to the natural language based on the invocation mode and the connection relationship includes: when the invocation mode is to invoke the second model and the connection relationship indicates that the second model is embedded in the first model, determining that the second model is embedded in the target layer of the first model, and determining the target response data based on the target layer; when the invocation mode is to invoke the second model and the connection relationship indicates that the second model is not embedded in the first model, controlling the first model to output the target response data based on the first response data to the natural language from the second model.
[0009] In an exemplary embodiment, determining the target response data based on the target layer includes: when the target layer is a decoding layer, and the second model is embedded after a regularization module included in the decoding layer, and the second model is embedded after a multilayer perceptron module included in the decoding layer, determining a first feature output by the second model embedded after the regularization module and a second feature output by the multilayer perceptron module, controlling the second model embedded after the multilayer perceptron module to fuse the first feature and the second feature to obtain a fused feature, and sending the fused feature to a sub-model included in the first model located after the multilayer perceptron module to instruct the sub-model to output the target response data; when the target layer is a decoding layer, and the second model is embedded after the multilayer perceptron module included in the decoding layer, inputting the feature output by the multilayer perceptron module to the second model, and sending the feature output by the second model to a sub-model included in the first model located after the multilayer perceptron module to instruct the sub-model to output the target response data.
[0010] In an exemplary embodiment, determining the target response data based on the target layer includes: when the target layer is an output layer and the second model is embedded in a normalized exponential function layer included in the first model, inputting the features output by the normalized exponential function layer into the second model to obtain the target response data.
[0011] In one exemplary embodiment, when there are multiple second models, inputting the features output by the normalized exponential function layer into the second model to obtain the target response data includes: inputting the features output by the normalized exponential function layer into each of the second models respectively to obtain the second response data output by each of the second models; and fusing multiple second response data to obtain the target response data.
[0012] In one exemplary embodiment, the method further includes one of the following: when the connection relationship indicates that the second model is embedded in the first model, optimizing the first model using a first loss function and optimizing the second model using a second loss function, wherein the first loss function and the second loss function are different; when the connection relationship indicates that the second model is embedded in the first model, determining the loss value of the target model using multiple loss functions, obtaining multiple loss values, fusing the multiple loss values to obtain a target loss value, and optimizing the target model based on the target loss value.
[0013] According to another embodiment of the present invention, a language response device is provided, comprising: a receiving module for receiving natural language input by a target user through an input interface of a target model, wherein the target model includes a first model and a second model, the first model including a large language model and the second model including a probability model; a first determining module for determining a calling pattern based on the natural language, wherein the calling pattern is used to indicate whether the first model calls the second model; a second determining module for determining a connection relationship between the first model and the second model; and an output module for controlling the target model to output target response data to the natural language based on the calling pattern and the connection relationship.
[0014] According to yet another embodiment of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored therein, wherein the computer program is configured to perform the steps in any of the above method embodiments when executed.
[0015] According to yet another embodiment of the present invention, an electronic device is also provided, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above method embodiments.
[0016] According to yet another embodiment of the present invention, a computer program product is also provided, including a computer program that, when executed by a processor, implements the steps of the methods described in various embodiments of the present application.
[0017] This invention first receives natural language input from a target user through the input interface of a target model. The natural language input determines whether the first model should invoke the second model. The target model includes both a first model and a second model; the first model includes a large language model, and the second model includes a probability model. The connection relationship between the first and second models is then determined, and the connection relationship and invocation pattern are used to control the target model's output of target response data to natural language. By combining the first and second models to respond to natural language, the recognition capability for long-distance tasks can be improved. Furthermore, the first model can be invoked dynamically, allowing it to be used as a separate tool to adaptively determine whether to invoke it. Therefore, this solves the technical problem in related technologies where inaccurate responses are due to the inability to handle long-distance tasks, thus improving the accuracy of response answers. Attached Figure Description
[0018] Figure 1 This is a hardware structure block diagram of a mobile terminal according to an embodiment of the present invention, which describes a language response method.
[0019] Figure 2 This is a flowchart of a language response method according to an embodiment of the present invention;
[0020] Figure 3 This is a schematic diagram of the instruction invocation method of the second model according to an embodiment of the present invention;
[0021] Figure 4 This is a schematic diagram of the adaptive calling method of the second model according to an embodiment of the present invention;
[0022] Figure 5 This is a schematic diagram illustrating the fusion of the decoding layer and the second model according to an embodiment of the present invention;
[0023] Figure 6 This is a schematic diagram illustrating the fusion of the output layer and the second model according to an embodiment of the present invention;
[0024] Figure 7 This is a schematic diagram of the fusion of the output layer and the second model according to a specific embodiment of the present invention;
[0025] Figure 8 This is a schematic diagram of a language response method according to a specific embodiment of the present invention;
[0026] Figure 9 This is a structural block diagram of a language response device according to an embodiment of the present invention. Detailed Implementation
[0027] The embodiments of the present invention will be described in detail below with reference to the accompanying drawings and examples.
[0028] It should be noted that the terms "first," "second," etc., in the specification, claims, and drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0029] The methods and embodiments provided in this application can be executed on a mobile terminal, computer terminal, or similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal for a language response method according to an embodiment of the present invention. For example... Figure 1 As shown, a mobile terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0030] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the language response method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, thereby implementing the methods described above. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0031] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module used for wireless communication with the Internet.
[0032] This embodiment provides a language response method. Figure 2 This is a flowchart of a language response method according to an embodiment of the present invention, such as... Figure 2 As shown, the process includes the following steps:
[0033] Step S202: Receive natural language input from the target user through the input interface of the target model, wherein the target model includes a first model and a second model, the first model includes a large language model, and the second model includes a probability model;
[0034] Step S204: Determine the invocation pattern based on the natural language, wherein the invocation pattern is used to indicate whether the first model invokes the second model;
[0035] Step S206: Determine the connection relationship between the first model and the second model;
[0036] Step S208: Based on the calling pattern and the connection relationship, control the target model to output target response data to the natural language.
[0037] In the above embodiments, the first model can be an LLM (Large Language Model), and the second model can be a CRF (Conditional Random Field) model. The large language model can be understood as an artificial intelligence model designed to understand and generate human language, typically including a language model with hundreds of billions (or more) parameters, trained on massive amounts of text data to achieve a deep understanding of language. Specifically, it exhibits the following characteristics: Context learning: It can perform tasks by understanding the context and generating corresponding outputs without additional training or parameter updates; Instruction following: It can execute tasks according to instructions without having seen specific examples beforehand, demonstrating its powerful generalization ability; Stepwise reasoning: It uses a Chain of Thought (CoT) reasoning strategy, utilizing a hint mechanism that includes intermediate reasoning steps to solve complex tasks, such as mathematical problems. The CRF model can be understood as a discriminative probabilistic model, primarily used for sequence labeling tasks, such as part-of-speech tagging and named entity recognition in natural language processing. That is, by considering the dependencies between the input sequence and the output labels, it captures the contextual information of the sequence data, offering advantages such as global optimization, flexibility, and wide applicability.
[0038] In the above embodiments, the target model may include a first model and a second model. The target user can input the natural language query they wish to use on the target model's input interface. During interaction with the target user, the system can ask if the first model needs to be invoked; that is, the system can determine the invocation mode of the second model based on the natural language response from the target user. After determining the invocation mode, the connection relationship between the first and second models within the target model can also be determined. Finally, based on the connection relationship and the invocation mode, the system controls the target model to respond to the natural language input by the target user and output target response data.
[0039] This invention first receives natural language input from a target user through the input interface of a target model. The natural language input determines whether the first model should invoke the second model. The target model includes both a first model and a second model; the first model includes a large language model, and the second model includes a probabilistic model. The connection relationship between the first and second models is then determined, and the connection relationship and invocation pattern are used to control the target model's output of target response data to natural language. By combining the first and second models to respond to natural language, the recognition capability for long-distance tasks can be improved. Furthermore, the second model can be invoked dynamically, allowing it to be used as a separate tool to adaptively determine whether to invoke it. Therefore, this invention solves the technical problem in related technologies where inaccurate responses are due to the inability to handle long-distance tasks, thus improving the accuracy of response answers.
[0040] Optionally, the entity performing the above steps may be a processor, a terminal, a server, or other devices with similar processing capabilities, but is not limited to these.
[0041] In one exemplary embodiment, determining the invocation pattern based on the natural language includes: if the natural language includes an invocation instruction, determining the invocation pattern as invoking the second model; if the natural language does not include the invocation instruction, determining the invocation pattern as not invoking the second model; determining the character length of the natural language; if the character length is greater than a first predetermined threshold, determining the invocation pattern as invoking the second model; if the character length is less than or equal to the first predetermined threshold, determining the invocation pattern as not invoking the second model.
[0042] In the above embodiments, the calling mode of the first model to the second model may include instruction calling and adaptive calling:
[0043] When the first model invokes the second model via command, the decision to invoke the second model can be determined based on the invocation commands included in the natural language input by the target user and the system's invocation commands. Alternatively, the target model can query the target user to confirm their choice to invoke the second model. The invocation process for the second model can be found in [link to relevant documentation]. Figure 3 , Figure 3 This is a schematic diagram of the instruction invocation method of the second model according to an embodiment of the present invention, as shown below. Figure 3 As shown, the second model can be configured and its functions defined as a tool. That is, the second module can be defined as a super query tool, which determines whether to call it based on the instruction, thereby improving the model's entity extraction for target user questions.
[0044] example:
[0045] a. System Instructions: You are an intelligent AI assistant. Users can ask you for information. After each reply to a user's question, you need to request satisfaction feedback from the user. If the information is not satisfactory, ask the user if they can choose to use the super search function to conduct further research.
[0046] b. User command: Help me check the weather for August 3rd, 4th, 5th, and yesterday?
[0047] c. System reply: We have retrieved the weather information for August 3rd and yesterday, as follows. Are you satisfied with the search results?
[0048] d. User instruction: Dissatisfied.
[0049] e. System reply: Do you want to enable the super query function?
[0050] f. User command: Enable.
[0051] g. System reply: We have retrieved the weather information for August 3, August 4, August 5 and yesterday, as follows.
[0052] When the first model calls the second model in an adaptive manner, a judgment mechanism can be adopted to judge the natural language input by the target user. Figure 4 This is a schematic diagram of the adaptive calling method of the second model according to an embodiment of the present invention, as shown below. Figure 4 As shown, natural language can be segmented and tokenized to generate tokens (i.e., the character length mentioned above). The following formula is used to determine whether to call the second model: Here, Thr is the first preset threshold mentioned above, which can be 100, 150, etc., but is not limited to this. If the character length exceeds the specified length (i.e., greater than the first preset threshold), the second model is invoked; if the character length is less than or equal to the first preset threshold, the second model is not invoked.
[0053] example:
[0054] a. Target User (Natural Language): I'm preparing for my upcoming holiday and plan to travel to Hangzhou early next month. Could you please help me find detailed information about the weather in Hangzhou from the 1st to the 7th of next month? I'm particularly interested in daily high and low temperatures, whether it will rain, the amount of rainfall, wind speed and direction, humidity, UV index, and other detailed information. This data will be very important for my travel planning. Thank you very much for your help!
[0055] b. At this point, Thr = 100, and the calculation is as follows: tokenize(user question) = 103 > 100. Therefore, the target user question uses the combined pathway of the first model and the second model to generate an answer.
[0056] When the first model calls the second model in an adaptive manner, the second model can also be packaged into a super query function to parse or retrieve the target user's question. When a "super query" appears, it will jump to the path of using the second model.
[0057] In one exemplary embodiment, controlling the target model to output target response data to the natural language based on the invocation mode and the connection relationship includes: when the invocation mode is to invoke the second model and the connection relationship indicates that the second model is embedded in the first model, determining that the second model is embedded in the target layer of the first model, and determining the target response data based on the target layer; when the invocation mode is to invoke the second model and the connection relationship indicates that the second model is not embedded in the first model, controlling the first model to output the target response data based on the first response data to the natural language from the second model.
[0058] In the above embodiments, the connection relationship between the first model and the second model can be that the second model is embedded in the first model, or the second model is not embedded in the first model (e.g., as an external tool).
[0059] When the first model calls the second model and the second model is embedded in the first model, the target layer of the second model's embedding into the first model can be determined, and different target response data can be determined based on different target layers. The embedded target layer can be adjusted according to task requirements, model performance, or experimental results. When the first model calls the second model but the second model is not embedded in the first model, the first model can be controlled to output target response data through the second model's first response data to natural language. That is, the first model can output the second model's first response data as target response data alone, or it can integrate the first response data with its own output results and output the integrated response data as target response data. By flexibly determining the interaction method between the first and second models (embedded or independently called), the system can dynamically adjust the model combination and calling strategy according to the complexity and requirements of the task, thereby achieving efficient resource utilization while maintaining high performance. Simultaneously, it also provides the possibility for modular design and flexible expansion of the model, enabling more efficient and intelligent responses to different types of natural language processing tasks.
[0060] In an exemplary embodiment, determining the target response data based on the target layer includes: when the target layer is a decoding layer, and the second model is embedded after a regularization module included in the decoding layer, and the second model is embedded after a multilayer perceptron module included in the decoding layer, determining a first feature output by the second model embedded after the regularization module and a second feature output by the multilayer perceptron module, controlling the second model embedded after the multilayer perceptron module to fuse the first feature and the second feature to obtain a fused feature, and sending the fused feature to a sub-model included in the first model located after the multilayer perceptron module to instruct the sub-model to output the target response data; when the target layer is a decoding layer, and the second model is embedded after the multilayer perceptron module included in the decoding layer, inputting the feature output by the multilayer perceptron module to the second model, and sending the feature output by the second model to a sub-model included in the first model located after the multilayer perceptron module to instruct the sub-model to output the target response data.
[0061] In the above embodiments, the decoding layer can mainly include an attention module, a multi-layer perceptron (MLP) module, a regularization module (LayerNorm), and residual block connections (RB). Because the decoding layer has residual block connections, it can effectively pass information from previous layers to later layers. Therefore, when using the second model in the decoding layer, a multi-level fusion approach can be used to embed it into the decoding layer. Figure 5This is a schematic diagram illustrating the fusion of the decoding layer and the second model according to an embodiment of the present invention, as shown below. Figure 5 As shown, when a second model is embedded after a regularization module in the decoding layer, or after a multilayer perceptron module, the first feature output by the second model embedded after the regularization module and the second feature output by the multilayer perceptron module can be fused to obtain a fused feature. This fused feature is then sent to the sub-model located after the multilayer perceptron module in the first model to determine the target response data. The decoding layer can include multiple regularization modules, each of which can be followed by a second model. That is, the first features output by the second model embedded after each regularization module can be fused first, and then the fused first feature can be fused with the second feature. The fusion of cascaded features (i.e., multiple first features) can be achieved through addition, multiplication, and dimension concatenation. The fusion of first and second features can be achieved through channel concatenation, convolutional fusion, addition, and multiplication.
[0062] In the above embodiments, when the second model is not embedded after the regularization module in the decoding layer, but is embedded after the multilayer perceptron module, the features output by the second model embedded after the multilayer perceptron module can be input into the second model. The second model can then send the features to the sub-model located after the multilayer perceptron module in the first model to determine the target response data through the features.
[0063] In one exemplary embodiment, determining a first feature output by the second model embedded after the regularization module and a second feature output by the multilayer perceptron module includes: determining a first number of samples, a first length of a sample sequence, a first width of a sample sequence, and a first number of channels input to the second model embedded after the regularization module; determining the first feature based on the first number of samples, the first length of the sample sequence, the first width of the sample sequence, and the first number of channels; determining a second number of samples, a second length of a sample sequence, a second width of a sample sequence, and a second number of channels input to the second model embedded after the multilayer perceptron module; and determining the second feature based on the first number of samples, the second length of the sample sequence, and the second number of channels.
[0064] In the above embodiments, the first feature can be determined by the following formula: Cascade -> CRF: out2 = (N, H, W, C), reshape(out2) = (N, H × W, C), where N is the number of the first samples, H is the first length of the sample sequence, W is the first width of the sample sequence, and C is the number of the first channels. The second feature can be determined by the following formula: MLP -> CRF: out1 = (N1, H1 × W1, C1), where N1 is the number of the second samples, H1 is the second length of the sample sequence, W1 is the second width of the sample sequence, and C1 is the number of the second channels. After determining the first and second features, the first and second features can be fused using the following formula: CRF fusion: out_CRF = reshape(out2) & out1, where reshape can be understood as reshaping the dimensions, & can be understood as fusion, and the CRF module can also be composed of multiple CRF fusions.
[0065] Example: When there are two LayerNorm layers in the decoding layer, the output of each LayerNorm, in addition to being passed to the next layer in the DecoderLayer, is also passed to an independently trained CRF module. The outputs of each CRF are concatenated by addition. Finally, the output of the MLP is passed to the CRF and concatenated with the channels of the concatenated outputs. Then, the second feature MLP->CRF: out1=(32, 25×25, 192); the first feature concatenation->CRF: out2=(32, 25, 25, 64), reshape(out2)=(32, 25×25, 64); the fusion feature CRF fusion: out_CRF=mlp((32, 25×25, 192), (32, 25×25, 64))=(32, 25×25, 192+64), where mlp is a fully connected layer.
[0066] Example: When multiple CRFs are fused in parallel in the second model module, where each CRF does not share weight parameters, and the parallel fusion method is channel splicing, then each CRF module includes three CRFs: CRF1, CRF2, and CRF3. CRF1: out1 = (32, 25×25, 64); CRF2: out2 = (32, 25×25, 64); CRF3: out3 = (32, 25×25, 64); CRF fusion: out = (32, 25×25, 64×3).
[0067] In an exemplary embodiment, determining the target response data based on the target layer includes: when the target layer is an output layer and the second model is embedded in a normalized exponential function layer included in the first model, inputting the features output by the normalized exponential function layer into the second model to obtain the target response data.
[0068] In the above embodiments, the output layer may include a linear layer, an activation function (Act), and a softmax layer (normalized exponential function layer). Unlike BERT, which is a transformer-based decoder, BERT typically uses an encoder architecture. BERT's output layer usually has a task-specific layer, with different network layers designed for different tasks, such as classification, named entity recognition, and question answering. The output layer of the first model is a vector the same size as the vocabulary, representing the probability distribution of the next word. A schematic diagram of the second model embedded in the output layer can be found [link to diagram]. Figure 6 , Figure 6 This is a schematic diagram illustrating the fusion of the output layer and the second model according to an embodiment of the present invention, as shown below. Figure 6 As shown, the features output by the normalized exponential function layer can be input into the second model to obtain the target corresponding data through the second model.
[0069] In one exemplary embodiment, when there are multiple second models, inputting the features output by the normalized exponential function layer into the second model to obtain the target response data includes: inputting the features output by the normalized exponential function layer into each of the second models respectively to obtain the second response data output by each of the second models; and fusing multiple second response data to obtain the target response data.
[0070] In the above embodiments, when there are multiple second models (i.e., multiple CRF modules are cascaded and fused in parallel to form a second model pool, and each CRF block is optimized independently), the features output by the normalized exponential function layer can be input into each second model to obtain multiple second response data. The second response data output by each CRF are then fused to obtain the target response data. For example, if there are three second models, and the three CRFs are connected in parallel, see [reference needed]. Figure 7 , Figure 7 This is a schematic diagram of the fusion of the output layer and the second model according to a specific embodiment of the present invention, as shown below. Figure 7 As shown, the features output by the softmax normalized exponential function layer can be input into each second model, and finally the three second response data are fused to output the final target response data.
[0071] In one exemplary embodiment, the method further includes one of the following: when the connection relationship indicates that the second model is embedded in the first model, optimizing the first model using a first loss function and optimizing the second model using a second loss function, wherein the first loss function and the second loss function are different; when the connection relationship indicates that the second model is embedded in the first model, determining the loss value of the target model using multiple loss functions, obtaining multiple loss values, fusing the multiple loss values to obtain a target loss value, and optimizing the target model based on the target loss value.
[0072] In the above embodiments, since the second model can be used as an independent tool in the target model, both independent fine-tuning and joint fine-tuning methods can be used during optimization.
[0073] In the case of independent fine-tuning, the loss can be calculated using cross-entropy loss (i.e., the first loss function mentioned above) to guide the optimization of the first model. Since the second model is embedded in the first model, a more refined loss function (i.e., the second loss function mentioned above) can be used to optimize the second model, such as MSE (mean squared error), RMSE (root mean squared error), MAE (mean absolute error), or a combination of the three.
[0074] In the case of joint fine-tuning, since the optimization objectives of the first and second models are consistent, and considering that the optimization of the second model can be calculated by introducing a second loss function on the basis of the first loss function, multiple loss values can be obtained and weighted and fused for calculation, so as to optimize the target model based on the weighted target loss value.
[0075] The language response method will be explained below with reference to specific implementation methods:
[0076] Figure 8 This is a schematic diagram of a language response method according to a specific embodiment of the present invention, such as... Figure 8 As shown:
[0077] The first model may include a tokenizer, an embedding layer, a decoding layer, a regularization layer, and an output layer. The tokenizer can convert the input raw text into a numerical representation that the model can process; the embedding layer can convert the integer IDs generated by the tokenizer into vector representations of fixed dimensions; the decoding layer can process the vectors generated by the embedding layer to generate the final output; the regularization layer can process the vectors generated by the embedding layer to generate the final output; and the output layer can convert the vectors generated by the decoding layer into the final output, such as a probability distribution or a label.
[0078] The second model can be a discriminative model used to predict the output sequence given an input sequence. It directly models the conditional probability distribution P(y|x) of the output sequence, where x is the input sequence and y is the output sequence. In the network framework, it is represented by a learnable transition matrix parameter.
[0079] The mechanism by which the first model invokes the second model can include: instruction invocation and adaptive invocation. Instruction invocation can be understood as specifying the use of the second model through user instructions; adaptive invocation can be understood as analyzing the text, setting an adaptive mechanism, and autonomously choosing whether to use the second model.
[0080] The embedding methods of the second model can include: decoding layer embedding and output layer embedding. Decoding layer embedding can be understood as feeding the structured vectors after decoding into the second model for calculation. The second model can calculate the most likely label sequence based on these vectors and the transition probabilities between labels. Output layer embedding can be understood as embedding the second model into the linear layer, which generally includes a linear layer and an activation function, so that the probability of the label sequence can be effectively calculated.
[0081] In the aforementioned embodiments, the LLM technique, which combines dynamic linkage with CRF modules, leverages the LLM's ability to effectively capture long-distance dependencies. The CRF module is independently trained and embedded into the LLM, and then dynamically invoked to rationally utilize its capabilities, improving entity recognition in long sentences. In other words, CRF can function as an independent tool, allowing users to choose whether to use it, or the model to determine its use, thus enhancing the overall inference ability of the LLM model. Furthermore, by employing different embedding methods (decoding layer embedding and output layer embedding), the possibilities for embedding the CRF module in various network layers within the LLM can be fully considered. A cascaded approach allows network layers to learn progressively, improving the model's generalization ability.
[0082] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0083] This embodiment also provides a language response device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, hardware implementations, or a combination of software and hardware, are also possible and contemplated.
[0084] Figure 9 This is a structural block diagram of a language response device according to an embodiment of the present invention, such as... Figure 9 As shown, the device includes:
[0085] The receiving module 92 is used to receive natural language input by the target user through the input interface of the target model, wherein the target model includes a first model and a second model, the first model includes a large language model, and the second model includes a probability model.
[0086] The first determining module 94 is used to determine a calling pattern based on the natural language, wherein the calling pattern is used to indicate whether the first model calls the second model;
[0087] The second determining module 96 is used to determine the connection relationship between the first model and the second model;
[0088] Output module 98 is used to control the target model to output target response data to the natural language based on the calling mode and the connection relationship.
[0089] In an exemplary embodiment, the first determining module 94 may determine the calling mode based on the natural language in the following manner: if the natural language includes a calling instruction, determine that the calling mode is to call the second model; if the natural language does not include the calling instruction, determine that the calling mode is not to call the second model; determine the character length of the natural language, and if the character length is greater than a first predetermined threshold, determine that the calling mode is to call the second model; if the character length is less than or equal to the first predetermined threshold, determine that the calling mode is not to call the second model.
[0090] In an exemplary embodiment, the output module 98 can control the target model to output target response data to the natural language based on the calling mode and the connection relationship in the following manner: when the calling mode is calling the second model and the connection relationship indicates that the second model is embedded in the first model, the second model is determined to be embedded in the target layer of the first model, and the target response data is determined based on the target layer; when the calling mode is calling the second model and the connection relationship indicates that the second model is not embedded in the first model, the first model is controlled to output the target response data based on the first response data of the second model to the natural language.
[0091] In an exemplary embodiment, the output module 98 can determine the target response data based on the target layer in the following manner: when the target layer is a decoding layer, and the second model is embedded after a regularization module included in the decoding layer, and the second model is embedded after a multilayer perceptron module included in the decoding layer, a first feature output by the second model embedded after the regularization module and a second feature output by the multilayer perceptron module are determined; the second model embedded after the multilayer perceptron module is controlled to fuse the first feature and the second feature to obtain a fused feature; and the fused feature is sent to a sub-model located after the multilayer perceptron module included in the first model to instruct the sub-model to output the target response data; when the target layer is a decoding layer, and the second model is embedded after the multilayer perceptron module included in the decoding layer, the feature output by the multilayer perceptron module is input to the second model, and the feature output by the second model is sent to a sub-model located after the multilayer perceptron module included in the first model to instruct the sub-model to output the target response data.
[0092] In an exemplary embodiment, the output module 98 can determine the target response data based on the target layer in the following manner: when the target layer is an output layer and the second model is embedded in the normalized exponential function layer included in the first model, the features output by the normalized exponential function layer are input into the second model to obtain the target response data.
[0093] In an exemplary embodiment, the apparatus can obtain the target response data by inputting the features output by the normalized exponential function layer into the second model when there are multiple second models: inputting the features output by the normalized exponential function layer into each of the second models respectively to obtain the second response data output by each of the second models; and fusing multiple second response data to obtain the target response data.
[0094] In one exemplary embodiment, the apparatus is further configured to: optimize the first model using a first loss function and optimize the second model using a second loss function when the connection relationship indicates that the second model is embedded in the first model, wherein the first loss function and the second loss function are different; and determine the loss value of the target model using multiple loss functions when the connection relationship indicates that the second model is embedded in the first model, obtain multiple loss values, fuse the multiple loss values to obtain a target loss value, and optimize the target model based on the target loss value.
[0095] It should be noted that the above modules can be implemented by software or hardware. For the latter, they can be implemented in the following ways, but are not limited to: all the above modules are located in the same processor; or, the above modules are located in different processors in any combination.
[0096] Embodiments of the present invention also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to perform the steps in any of the above method embodiments when executed.
[0097] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.
[0098] Embodiments of the present invention also provide an electronic device including a memory and a processor, the memory storing a computer program and the processor being configured to run the computer program to perform the steps in any of the above method embodiments.
[0099] In one exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.
[0100] Embodiments of the present invention also provide a computer program product, including a computer program that, when executed by a processor, implements the steps of the methods in various embodiments of the present application.
[0101] Specific examples in this embodiment can be found in the examples described in the above embodiments and exemplary implementations, and will not be repeated here.
[0102] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0103] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A language response method, characterized in that, include: The system receives natural language input from a target user through the input interface of a target model, wherein the target model includes a first model and a second model, the first model including a large language model and the second model including a probability model. The invocation pattern is determined based on the natural language, wherein the invocation pattern is used to indicate whether the first model invokes the second model; Determine the connection relationship between the first model and the second model; Based on the invocation pattern and the connection relationship, the target model is controlled to output target response data to the natural language.
2. The method according to claim 1, characterized in that, Determining the invocation pattern based on the natural language includes: If the natural language includes a calling instruction, the calling pattern is determined to be calling the second model; if the natural language does not include the calling instruction, the calling pattern is determined to be not calling the second model. The character length of the natural language is determined. If the character length is greater than a first predetermined threshold, the calling mode is determined to be calling the second model. If the character length is less than or equal to the first predetermined threshold, the calling mode is determined to be not calling the second model.
3. The method according to claim 1, characterized in that, Controlling the target model's output of target response data to the natural language based on the invocation pattern and the connection relationship includes: When the invocation mode is to invoke the second model and the connection relationship indicates that the second model is embedded in the first model, the target layer of the second model is determined to be embedded in the first model, and the target response data is determined based on the target layer. When the invocation mode is to invoke the second model and the connection relationship indicates that the second model is not embedded in the first model, the first model is controlled to output the target response data based on the first response data of the natural language from the second model.
4. The method according to claim 3, characterized in that, Determining the target response data based on the target layer includes: When the target layer is a decoding layer, and the second model is embedded after the regularization module included in the decoding layer, and the second model is embedded after the multilayer perceptron module included in the decoding layer, the first feature output by the second model embedded after the regularization module and the second feature output by the multilayer perceptron module are determined. The second model embedded after the multilayer perceptron module is controlled to fuse the first feature and the second feature to obtain a fused feature. The fused feature is then sent to the sub-model located after the multilayer perceptron module included in the first model to instruct the sub-model to output the target response data. When the target layer is a decoding layer, and the second model is embedded after the multilayer perceptron module included in the decoding layer, the features output by the multilayer perceptron module are input to the second model, and the features output by the second model are sent to the sub-model located after the multilayer perceptron module included in the first model, so as to instruct the sub-model to output the target response data.
5. The method according to claim 3, characterized in that, Determining the target response data based on the target layer includes: When the target layer is the output layer and the second model is embedded in the normalized exponential function layer included in the first model, the features output by the normalized exponential function layer are input into the second model to obtain the target response data.
6. The method according to claim 5, characterized in that, When there are multiple second models, the features output by the normalized exponential function layer are input into the second model to obtain the target response data, including: The features output by the normalized exponential function layer are respectively input into each of the second models to obtain the second response data output by each of the second models; The target response data is obtained by fusing multiple sets of the second response data.
7. The method according to claim 1, characterized in that, The method also includes one of the following: When the connection relationship indicates that the second model is embedded in the first model, the first model is optimized using a first loss function, and the second model is optimized using a second loss function, wherein the first loss function and the second loss function are different; When the connection relationship indicates that the second model is embedded in the first model, the loss value of the target model is determined by using multiple loss functions to obtain multiple loss values. The multiple loss values are then fused to obtain a target loss value, and the target model is optimized based on the target loss value.
8. A language response device, characterized in that, include: A receiving module is used to receive natural language input by a target user through the input interface of a target model, wherein the target model includes a first model and a second model, the first model includes a large language model, and the second model includes a probability model; The first determining module is configured to determine a calling pattern based on the natural language, wherein the calling pattern is used to indicate whether the first model calls the second model; The second determining module is used to determine the connection relationship between the first model and the second model; The output module is used to control the target model to output target response data to the natural language based on the calling mode and the connection relationship.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program is configured to perform the method described in any one of claims 1 to 7 when executed.
10. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method as described in any one of claims 1 to 7.