Model temperature self-adaption fine-tuning method for smart breeding question answering
By combining the temperature-adaptive fine-tuning method with the LoRA module, the problems of task diversity and data imbalance in smart aquaculture models are solved, enabling efficient and flexible model fine-tuning and answer generation, and improving the model's performance and generalization ability in smart aquaculture question-and-answer systems.
Patent Information
- Application Number
- CN202410126688.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-30
- Publication Date
- 2025-11-07
- Estimated Expiration
- 2044-01-30
AI Technical Summary
In smart farming applications, existing technologies suffer from problems such as task diversity, data imbalance, high fine-tuning costs, catastrophic amnesia, and the inability of fixed temperature parameters to adapt to different levels of task creativity, which affect the generalization performance and efficiency of the model.
A temperature-adaptive fine-tuning method is adopted, which combines the LoRA module and the task-aware self-attention adjustment layer. Through creativity assessment, BERT model representation and low-rank matrix factorization, the temperature parameters and weight allocation are dynamically adjusted to improve the model's performance and generalization ability on different tasks.
It enables more efficient and resource-saving model fine-tuning in the smart aquaculture question-and-answer system, avoids catastrophic forgetting, generates more creative and diverse answers, and improves the model's task adaptability and answer quality.
Smart Images

Figure CN117951276B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of intelligent breeding, and particularly relates to a model temperature self-adaptive fine-tuning method for intelligent breeding question answering. BACKGROUND
[0002] The recent surge in large language model (LLM) has attracted a lot of attention in many fields. In order to make LLM suitable for specific fields (such as intelligent breeding system), it is necessary to fine-tune it with domain knowledge. However, there are two problems in the process of fine-tuning LLM for intelligent breeding applications. The first is the problem of task diversity. There are many different tasks in the real-world intelligent breeding scenario, such as adjusting the breeding environment according to sensor data to provide the most suitable conditions, and making production plans and predictions based on historical data and market demand to ensure that production matches market demand, etc. The second is the problem of data imbalance. This diversity often leads to suboptimal fine-tuning. In addition, the high cost of fine-tuning may deter people from applying LLM.
[0003] Traditional multi-task learning performs heuristic sampling (heuristic sampling is a sample selection method based on experience and intuition, rather than strict statistical or mathematical rules. This sampling strategy usually uses domain expertise or experience to guide the selection of samples to improve the performance or training effect of the model) on multiple different task datasets. By heuristic sampling, the model can avoid overfitting and underfitting to certain tasks. By passing a fixed number of samples from different datasets as a batch to the model, the model can learn on different tasks. However, one disadvantage of this method is that if a new task needs to be added after training is complete, the new task and the old task need to be fine-tuned on the pre-trained model again.
[0004] In the Temperature parameter setting of the model (in large language models, the Temperature parameter is a parameter that regulates the randomness of generated text. It is used to adjust the probability distribution of the model's generation, thereby affecting the diversity of generated text), the traditional method is to set it manually. However, in the context of multi-task learning, different tasks require different levels of creativity in their answers (in the context of multi-task learning, the level of creativity in generated text may vary depending on the task. The level of creativity refers to the novelty and uniqueness of the features generated by the model when generating text, as well as the diversity of the text), so setting a fixed temperature for multi-task scenarios does not perform well.
[0005] 1. Traditional multi-task learning methods often need to rely on human selection of appropriate heuristic sampling methods to adapt to the characteristics of different task data sets. Such selection processes can affect the learning effect of the model, because different sampling methods can introduce different biases, affecting the generalization performance of the model.
[0006] 2. When the pre-trained model is trained on certain data sets, if it is necessary to learn new tasks based on the model, the traditional method may face the problem of catastrophic forgetting. Re-learning the previously learned knowledge and new knowledge together on the pre-trained model is less efficient, limiting the application range of the model in multi-task learning.
[0007] 3. The process of full-parameter fine-tuning of the pre-trained model requires more time and computing resources. Because full-parameter fine-tuning involves adjusting the parameters of the entire model, for large-scale models, this process can become quite time-consuming, limiting the training efficiency of the model.
[0008] 4. Using a fixed temperature parameter may not make the model perform ideally when answering questions. The fixed temperature parameter may not be well adapted to the needs of different tasks for the creative level of text generation, so a more flexible method is needed to dynamically adjust the temperature parameter to improve the diversity and quality of the generated text by the model. SUMMARY
[0009] The main purpose of the present application is to overcome the shortcomings and deficiencies of the prior art, and to provide a model temperature self-adaptive fine-tuning method for smart farming Q&A, which uses the output of the temperature self-adaptive model and uses the attention mechanism to adaptively distribute the weights of multiple efficient fine-tuning LoRA modules for a single task, to improve the performance and generalization ability of the model on different tasks.
[0010] In order to achieve the above purpose, the technical scheme adopted by the present application is as follows:
[0011] In a first aspect, the present application provides a model temperature self-adaptive fine-tuning method for smart farming Q&A, comprising the following steps:
[0012] Based on a pre-set large language model, the original Q&A data set is processed to obtain the creativity evaluation value of each sample; based on the question of each sample and its corresponding creativity evaluation value, a new data set is constructed;
[0013] The Bert model is used to represent the question, a new data set is used to train the temperature model, and the task-specific layer is trained; the target of the temperature model is to train the processed data set through supervised learning, so that the temperature model can learn the pattern in the data and creatively evaluate the text; the task-specific layer selects the output of one neuron according to the question after the task-specific LoRA module is adjusted through task-aware self-attention;
[0014] The LoRA parameters of the new data set under different tasks are fine-tuned, and different LoRA modules of different tasks are obtained;
[0015] The output of each task-specific LoRA module is fused using the task-aware self-attention adjustment layer.
[0016] As a preferred technical solution, the preset large language model processes the original question and answer data set to obtain the creativity of each sample, specifically:
[0017] Based on the preset large language model, each sample in the original question and answer data set is analyzed, and the large language model is questioned using the set prompt word to obtain the creativity and conservatism of the sample considered by the large language model.
[0018] As a preferred technical solution, the creativity evaluation value represents the evaluation of the creativity and conservatism of the sample considered by the large language model, and the value range is between 0 and 1, wherein 0 represents the most conservative degree, 1 represents the most creative degree, and the intermediate value represents a certain trade-off between creativity and conservatism.
[0019] As a preferred technical solution, the Bert model is used to represent the question, specifically:
[0020] When processing the user input text, the Bert model is used to represent each token in the text, and the token is the smallest unit of the text, and the Bert model generates a context-related embedding vector for each token by learning the context of the text; the smallest unit is a word, a subword, or a character.
[0021] As a preferred technical solution, the task-specific layer is trained, specifically:
[0022] A unique one-hot code is assigned to each task for the order of its corresponding LoRA module;
[0023] Combine the question of each sample in the original data set with the one-hot code corresponding to the sample task to form a new data set;
[0024] The task-specific layer is supervisedly trained using the new data set.
[0025] As a preferred technical solution, the LoRA parameter fine-tuning is performed on the new data set under different tasks, and different task-specific LoRA modules are obtained, specifically:
[0026] For the pre-trained weight matrix W0∈R d×k , d represents the number of rows of the weight matrix W0, k represents the number of columns of the weight matrix W0, R d×k represents the dimension of the matrix, that is, d rows and k columns, and the update is represented by low-rank decomposition W0+ΔW=W0+BA, A and B are both low-rank matrices, wherein B∈R d×r , A∈R r×k , and rank r « min(d, k), during training, W0 is frozen and does not receive gradient updates, while A and B contain trainable parameters; at the same time, W0 and ΔW=BA both receive the same input, and the output vectors of them are summed by position;
[0027] By optimizing the cross-entropy loss function, the two low-rank matrices can adapt to the requirements of the downstream task. During the fine-tuning process, the weight matrix of the original model is frozen, and only the low-rank matrices A and B need to be trained.
[0028] As a preferred technical solution, the task-aware self-attention adjustment layer is used to fuse the outputs of the task-specific LoRA modules, specifically:
[0029] Before training, the order of the LoRA modules for different tasks corresponds to the one-hot encoding of the task-specific layers for different tasks;
[0030] A set of independent linear projection matrices W Q , W K , W V are used for each Encoder layer, which are used to map the outputs of the LoRA modules as inputs X to three different subspaces, thereby obtaining multiple sets of query, key and value vectors for specific LoRA modules; in the self-attention mechanism, given the query, key and value vectors, the attention scores are calculated, and the values are weighted and summed using these scores; so that the model learns different attention degrees for each LoRA module to more effectively capture respective features; finally, by weighting and summing the outputs of multiple attention mechanisms, a comprehensive attention representation of the outputs of multiple LoRA modules is obtained; the comprehensive attention representation is multiplied by the task-specific weight matrix to select the fusion features of the specific task, so that the model can more flexibly focus on relevant semantic information when dealing with different tasks. Given a query vector q, a key vector k and a value vector v, the calculation process of the scaled dot-product attention is:
[0031]
[0032] wherein · denotes a dot product operation, d k is the dimension of the query and the key;
[0033] By training the task-specific layer, the task-specific layer is enabled to accept the vector representation of the user input question and output the one-hot encoding for the specific task, in the process, the vector representation of the user input question respectively passes through the task-aware self-attention adjustment layer and the task-specific layer; by multiplying the output feature fusion representation of the task-aware self-attention adjustment layer and the one-hot encoding for the task of the task-specific layer, the feature fusion representation for the current task is obtained.
[0034] In a second aspect, the present application provides a model temperature adaptive fine-tuning system for smart breeding question answering, which is applied to the model temperature adaptive fine-tuning method for smart breeding question answering, and includes an originality degree evaluation module, a model training module, a parameter fine-tuning module and a feature fusion module.
[0035] The originality degree evaluation module is configured to process an original question and answer data set based on a preset large language model, and obtain an originality degree evaluation value of each sample; and construct a new data set based on the question of each sample and the corresponding originality degree evaluation value.
[0036] The model training module is configured to represent the question by using a Bert model, train a temperature model by using the new data set, and train a task-specific layer; the target of the temperature model is to train the temperature model by using the processed data set through supervised learning, so that the temperature model can learn the pattern in the data and evaluate the text creatively; and the task-specific layer selects the output of one neuron according to the question after the task-specific LoRA module is adjusted by the task-aware self-attention.
[0037] The parameter fine-tuning module is configured to fine-tune the LoRA parameters of the new data set under different tasks, and obtain the LoRA module of each task.
[0038] The feature fusion module is configured to use the task-aware self-attention adjustment layer to fuse the outputs of the task-specific LoRA modules.
[0039] In a third aspect, the present application provides an electronic device, which includes:
[0040] at least one processor; and
[0041] a memory communicatively connected to the at least one processor; wherein
[0042] The memory stores computer program instructions executable by the at least one processor, and the computer program instructions are executed by the at least one processor to enable the at least one processor to perform the model temperature adaptive fine-tuning method for smart aquaculture question answering.
[0043] In a fourth aspect, the present application provides a computer-readable storage medium storing a program, which, when executed by a processor, implements the model temperature adaptive fine-tuning method for smart aquaculture question answering.
[0044] Compared with the prior art, the present application has the following advantages and beneficial effects:
[0045] 1. The present application uses the data sets of different tasks in the aquaculture field to fine-tune the large language model in the form of LoRA fine-tuning, which saves time and computing resources.
[0046] 2. The present application uses the task-aware self-attention adjustment layer to fuse the features of different tasks, uses the weights of other task LoRA modules to improve the answer quality of the current task, can promote the model to learn some correlations between tasks, and thus improve the performance; and uses the task-specific layer to select the specific task feature fusion representation.
[0047] 3. The present application obtains the temperature prediction of the temperature model for user input, so that the large model can generate more satisfactory answers according to the creativity of different questions.
[0048] 4. The present application can avoid the problem of catastrophic forgetting in traditional multi-task learning by training a single LoRA module with a single task data set, and can also eliminate the need for researchers to consider heuristic sampling strategies. DETAILED DESCRIPTION
[0049] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0050] Figure 1 The flowchart of the present application embodiment data set processing and training the processed data set to the temperature model;
[0051] Figure 2 The flowchart of the present application embodiment question answering for smart aquaculture;
[0052] Figure 3 The schematic diagram of the model fine-tuning of the present application embodiment;
[0053] Figure 4 A processing flowchart for simulating a task-specific layer for an embodiment of the present application is shown in FIG. 1.
[0054] Figure 5 A block diagram of a model temperature adaptive fine-tuning system for a smart farming question and answer for an embodiment of the present application is shown in FIG. 2.
[0055] Figure 6 A structural diagram of an electronic device for an embodiment of the present application is shown in FIG. 3. DETAILED DESCRIPTION
[0056] In order to enable persons skilled in the art to better understand the schemes of the present application, the technical schemes in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by persons skilled in the art without creative labor are within the scope of protection of the present application.
[0057] In the present application, the phrase "embodiment" means that the specific features, structures or characteristics described in conjunction with the embodiment can be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily mean the same embodiment, nor is it an independent or alternative embodiment to other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described in the present application can be combined with other embodiments.
[0058] The present application discloses a model temperature adaptive fine-tuning method for a smart farming question and answer, the method comprising the following steps:
[0059] S1, making a new data set: first, using an existing large language model to process the original question and answer data set, obtaining the creativity of each sample, the creativity range is 0-1.0; then, combining the question of each question and answer sample and its corresponding creativity to form a processed data set.
[0060] In a specific embodiment, the process of forming the processed data set is specifically:
[0061] The prompt word is as follows:
[0062] Please evaluate the creativity of the following sentence pair, output 0-1, which represents the creativity of the question and answer pair, 0 represents the most conservative degree, 1 represents the most creative degree, and the values between 0 and 1 represent the trade-off between creativity and conservatism, the numerical value is only allowed to output with an interval of 0.1, increasing from 0 to 1 step by step.
[0063] Sentence pair: {input}
[0064] By using the sentence pair to replace {input} in the prompt word template, the Figure 1 model 1 is given to the model 1 to perform the creativity degree evaluation. Then the question in the sentence pair and the evaluation of the large model together constitute a new data set.
[0065] Further, the "creativity degree evaluation" refers to analyzing each sample of the question and answer pair by using the existing large language model, and obtaining a numerical value representing the evaluation of the creativity and conservatism of the sample considered by the model. The numerical value ranges from 0 to 1, where 0 represents the most conservative degree, 1 represents the most creative degree, and the intermediate value represents a certain trade-off between creativity and conservatism; the formula is represented as:
[0066] Creativity∈{0,0.1,0.2,…,1}
[0067] Where Creativity represents the evaluation of the creativity degree.
[0068] The creativity degree evaluation value can be obtained by Figure 1 model 1 (i.e. general large language model) under the given prompt word, for each question and answer pair. The model outputs a creativity degree evaluation value according to the previously trained knowledge combined with the prompt word. The change of the creativity degree evaluation value reflects the different views of the model on the creativity and conservatism of the question and answer pair, thereby constructing a new data set containing the evaluation information of the creativity degree.
[0069] S2, using the processed data set for training: first, training the temperature model to better adapt to the creativity degree distribution of each sample. Secondly, training the task-specific layer to enable the task-specific layer to distinguish the task to which the question belongs;
[0070] Further, the step S2 is specifically: using the Bert model to represent the question; using the processed data set to train the temperature model; and training the task-specific layer, specifically:
[0071] When processing the user input text, first use the Bert model to represent each token in the text. Here "token" refers to the smallest unit of text, which can be a word, a subword, or a character. The Bert model generates a context-related embedding vector for each token by learning the context of the text.
[0072] On the basis of this data representation, there are two tasks, namely the training of the temperature model and the task-specific layer. Figure 2The goal of the mid-temperature model is to predict the creativity of a sentence using the BERT model's representation vectors as input through supervised learning using the processed dataset for training. This enables the model to evaluate the creativity of the text by learning the patterns in the data.
[0073] Regarding the training of the task-specific layer, first, a unique one-hot encoding is assigned to each task for its corresponding order of LoRA modules. Then, the question of each sample in the original dataset is combined with the one-hot encoding corresponding to the task of the sample to form a new dataset. Subsequently, the task-specific layer is supervised trained using this new dataset.
[0074] The task-specific layer also plays another role. As shown in Figure 4 , it selects the output of one neuron according to the question after the task-aware self-attention adjustment layer of multiple task-specific LoRA modules. This means that the task-specific layer selects the most relevant representation by judging the task to which the question belongs.
[0075] S3, in order to improve the performance of the model on different tasks, the method of LoRA (Low Rank Adaptation) parameter efficient fine-tuning is introduced: this method enables different task-specific LoRA modules to be trained on different task datasets to better capture the differences between tasks, as shown in Figure 3 .
[0076] The step S3 is specifically:
[0077] For different datasets, the method of LoRA parameter efficient fine-tuning is used to learn task-specific LoRA modules. The newly introduced low-rank matrices A and B are trained using the data of the downstream task.
[0078] For the pre-trained weight matrix W0∈R d×k , d represents the number of rows of the weight matrix W0, k represents the number of columns of the weight matrix W0, R d×k represents the dimension of the matrix, i.e. d rows and k columns, by using the low-rank decomposition W0+ΔW=W0+BA to represent the update, A and B are both low-rank matrices, where B∈R d×r , A∈R r×k , and rank r<<min(d,k), during training, W0 is frozen and does not receive gradient updates, while A and B contain trainable parameters; at the same time, W0 and ΔW=BA both receive the same input and sum their respective output vectors by position.
[0079] By optimizing the cross-entropy loss function, the two low-rank matrices can adapt to the needs of downstream tasks. During fine-tuning, the weight matrices of the original model are frozen, and only the low-rank matrices A and B need to be trained. This greatly reduces the parameter quantity and computational cost during fine-tuning.
[0080] For the placement position of the LoRA module, the strategy adopted by the method is to place the LoRA module in parallel in the linear projection matrix W Q and W V above the attention layer of the pre-trained model.
[0081] S4, training the task-aware self-attention adjustment layer after the LoRA module: using the original question and answer data set for training, so that the model can adaptively assign different weights to different LoRA modules in different inputs. Such a design aims to retain the rich information in the original data set while fully utilizing the learning ability of the LoRA module to further improve the performance and generalization ability of the model in the smart breeding question and answer task. The method uses the output of the temperature self-adaptive model and uses the attention mechanism to adaptively assign weights to multiple efficient fine-tuning LoRA modules for a single task, improving the performance and generalization ability of the model on different tasks.
[0082] Further, the step S4 is specifically:
[0083] First, use a set of independent linear projection matrices W Q ,W K ,W V for each Encoder layer. These matrices are used to map the output of each LoRA module as input X to three different subspaces, resulting in multiple sets of query, key, and value vectors for specific LoRA modules. In the self-attention mechanism, given the query, key, and value vectors, the attention scores are calculated, and the values are weighted and summed using these scores. This means that the model can learn different attention degrees for each LoRA module to more effectively capture their respective features. Finally, we obtain a comprehensive attention representation of the outputs of multiple LoRA modules by weighting and summing the outputs of multiple attention mechanisms. This comprehensive representation is multiplied by a task-specific weight matrix to select the fused features for a specific task, allowing the model to more flexibly focus on relevant semantic information when dealing with different tasks. Given a query vector q, key vector k, and value vector v, the calculation process of the scaled dot-product attention is as follows:
[0084]
[0085] where · denotes the dot product operation, d k is the dimension of the query and key.
[0086] Secondly, by training the task-specific layer, the task-specific layer can accept the vector representation of the user input question and output the one-hot encoding for the specific task. In this process, the vector representation of the user input question passes through the task-aware self-attention adjustment layer and the task-specific layer respectively. As shown in Figure 4 The feature fusion representation for the current task is obtained by multiplying the output feature fusion representation of the task-aware self-attention adjustment layer and the one-hot encoding for the task of the task-specific layer. The purpose of this design is to improve the performance of the model for the specific task by fusing the semantic information learned by the attention mechanism and the information of the specific task.
[0087] The present application uses the task-aware self-attention adjustment layer to fuse the features of different tasks LoRA modules, uses the weights of other task LoRA modules to improve the answer quality of the current task, which can promote the model to learn some correlations between tasks, thereby improving the performance, and uses the task-specific layer to select the specific task feature fusion representation.
[0088] It should be noted that for the foregoing method embodiments, in order to facilitate description, they are all described as a series of action combinations, but those skilled in the art should know that the present application is not limited to the action sequence described, because according to the present application, certain steps can be performed in other sequences or simultaneously.
[0089] Based on the same idea as the model temperature adaptive fine-tuning method for smart breeding question answering in the above embodiment, the present application also provides a model temperature adaptive fine-tuning system for smart breeding question answering, which can be used to execute the above-mentioned model temperature adaptive fine-tuning method for smart breeding question answering. For the convenience of description, in the structural schematic diagram of the embodiment of the model temperature adaptive fine-tuning system for smart breeding question answering, only the part related to the embodiment of the present application is shown, and those skilled in the art can understand that the illustrated structure does not constitute a limitation on the device, which can include more or fewer components than the illustrated, or combine certain components, or different component arrangements.
[0090] Please refer to Figure 5 In another embodiment of the present application, a model temperature adaptive fine-tuning system for smart breeding question answering 100 is provided, which includes a creativity evaluation module 101, a model training module 102, a parameter fine-tuning module 103, and a feature fusion module 104;
[0091] The creativity evaluation module 101 is configured to process the original question and answer data set based on a pre-set large language model to obtain a creativity evaluation value of each sample; and construct a new data set based on the question of each sample and the corresponding creativity evaluation value thereof.
[0092] The model training module 102 is configured to represent the question sentence by using a Bert model, train a temperature model by using a new data set, and train a task-specific layer; the temperature model is trained by using the processed data set through supervised learning, so that the temperature model can evaluate the text creatively by learning the pattern in the data; the task-specific layer selects the output of one neuron according to the question sentence after the task-specific LoRA module is adjusted by task-aware self-attention;
[0093] The parameter fine-tuning module 103 is configured to fine-tune the LoRA parameters of the new data set under different tasks, and obtain different LoRA modules of different tasks respectively.
[0094] The feature fusion module 104 is configured to use a task-aware self-attention adjustment layer to fuse the outputs of the task-specific LoRA modules.
[0095] It should be noted that the model temperature self-adaptive fine-tuning system for smart breeding question answering of the present application corresponds to the model temperature self-adaptive fine-tuning method for smart breeding question answering of the present application. The technical features and advantages described in the embodiment of the model temperature self-adaptive fine-tuning method for smart breeding question answering are applicable to the embodiment of the model temperature self-adaptive fine-tuning for smart breeding question answering. For specific content, please refer to the description in the method embodiment. Here, no further description is given, and this is hereby declared.
[0096] In addition, in the embodiment of the model temperature self-adaptive fine-tuning system for smart breeding question answering of the above embodiment, the logical division of each program module is only an example. In actual application, the above functions can be completed by different program modules according to the needs, for example, the configuration requirements of the corresponding hardware or the convenience of software implementation. That is, the internal structure of the model temperature self-adaptive fine-tuning system for smart breeding question answering is divided into different program modules to complete all or part of the functions described above.
[0097] Please refer to Figure 6 In one embodiment, an electronic device implementing the model temperature self-adaptive fine-tuning method for smart breeding question answering is provided. The electronic device 200 can include a first processor 201, a first memory 202, and a bus. It can also include a computer program stored in the first memory 202 and executable on the first processor 201, such as a model temperature self-adaptive fine-tuning program 203 for smart breeding question answering.
[0098] The first memory 202 includes at least one type of readable storage medium, such as flash memory, a mobile hard disk, a multimedia card, a card-type memory (e.g., an SD or DX memory, etc.), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the first memory 202 can be an internal storage unit of the electronic device 200, such as a mobile hard disk of the electronic device 200. In other embodiments, the first memory 202 can also be an external storage device of the electronic device 200, such as a plug-in mobile hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. Further, the first memory 202 can include both an internal storage unit and an external storage device of the electronic device 200. The first memory 202 can be used to store application software and various data installed in the electronic device 200, such as the code of the model temperature adaptive fine-tuning program 203 for smart farming question answering, and can also be used to temporarily store data that has been output or will be output.
[0099] The first processor 201 can be composed of an integrated circuit in some embodiments, such as a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same function or different functions, including one or more combinations of a central processing unit (CPU), a microprocessor, a digital processing chip, a graphics processor, and various control chips, etc. The first processor 201 is the control unit of the electronic device, which connects various components of the entire electronic device through various interfaces and lines, and executes various functions and processes data of the electronic device 200 by running or executing programs or modules stored in the first memory 202 and calling data stored in the first memory 202.
[0100] Figure 6 Only the electronic device with components is shown, and those skilled in the art can understand that, Figure 6 The structure shown does not constitute a limitation on the electronic device 200, and can include fewer or more components than shown, or combine certain components, or different component arrangements.
[0101] The model temperature adaptive fine-tuning program 203 for smart farming question answering stored in the first memory 202 of the electronic device 200 is a combination of a plurality of instructions, which, when running in the first processor 201, can achieve:
[0102] The original question and answer data set is processed based on a preset large language model to obtain a creativity evaluation value of each sample; and a new data set is constructed based on a question of each sample and the corresponding creativity evaluation value;
[0103] The question is represented by using the Bert model, the temperature model is trained by using the new data set, and the task-specific layer is trained; the target of the temperature model is to train the temperature model by using the processed data set through supervised learning, so that the temperature model can evaluate the text creatively by learning the mode in the data; the task-specific layer selects the output of one neuron according to the question after the task-specific LoRA module is adjusted by the task-aware self-attention;
[0104] The LoRA parameters of the new data set under different tasks are fine-tuned to obtain LoRA modules of different tasks respectively;
[0105] The outputs of the task-specific LoRA modules are fused by using the task-aware self-attention adjustment layer.
[0106] Further, the modules / units of the electronic device 200 are stored in a nonvolatile computer readable storage medium if they are realized in the form of software function units and sold or used as independent products. The computer readable medium can include any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory).
[0107] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by a computer program instructing relevant hardware. The program can be stored in a non-volatile computer readable storage medium, and when executed, can include the processes of the above-mentioned embodiment methods. Any reference to memory, storage, database or other medium used in the embodiments provided by the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0108] Any combination of the technical features of the above embodiments can be made. In order to make the description simple, all possible combinations of the technical features in the above embodiments are not described, however, as long as the combination of the technical features does not exist, it should be considered as the scope of the present application.
[0109] The above embodiments are the preferred embodiments of the present application, but the embodiments of the present application are not limited to the above embodiments, and any changes, modifications, substitutions, combinations and simplifications made without departing from the spirit and principles of the present application shall be equivalent replacement methods and shall be within the scope of protection of the present application.
Claims
1. A model temperature self-adaption fine-tuning method for smart farming question answering, characterized in that, Comprising the following steps: Based on the preset large language model, the original question and answer data set is processed to obtain the creativity evaluation value of each sample; based on the question of each sample and the corresponding creativity evaluation value, a new data set is constructed; The Bert model is used to represent the question, the temperature model is trained using the new data set, and the task-specific layer is trained; the target of the temperature model is to train the data set through supervised learning, so that the temperature model can learn the pattern in the data and evaluate the creativity of the text; the task-specific layer selects the output of one neuron according to the question after the task-aware self-attention adjustment of multiple task-specific LoRA modules; LoRA parameter fine-tuning is performed on the new data set under different tasks to obtain different task LoRA modules; The output of each task-specific LoRA module is fused using a task-aware self-attention adjustment layer; The preset large language model is used to process the original question and answer data set to obtain the creativity of each sample, specifically: Based on the preset large language model, each sample in the original question and answer data set is analyzed, and the large language model is questioned using the set prompt word to obtain the creativity and conservatism degree considered by the large language model; The creativity evaluation value represents the evaluation of the creativity and conservatism degree considered by the large language model, with a value range of 0 to 1, where 0 represents the most conservative degree and 1 represents the most creative degree, and the intermediate value represents a certain trade-off between creativity and conservatism; The output of each task-specific LoRA module is fused using a task-aware self-attention adjustment layer, specifically: Before training, the order of the LoRA module for different tasks corresponds to the one-hot encoding of the task-specific layer for different tasks; use a set of independent linear projection matrices W for each Encoder layer Q ,W K ,W V These matrices are used to map the output of each LoRA module as input X to three different subspaces, resulting in multiple sets of query, key, and value vectors specific to a LoRA module; in the self-attention mechanism, given the query, key, and value vectors, the attention scores are calculated, and the values are weighted and summed using these scores; so that the model learns different degrees of attention for each LoRA module to more effectively capture the respective features; finally, by weighting and summing the outputs of multiple sets of attention mechanisms, a comprehensive attention representation of the outputs of multiple LoRA modules is obtained; the comprehensive attention representation is multiplied by a weight matrix specific to the task to select the fused features of the specific task, so that the model can more flexibly focus on relevant semantic information when dealing with different tasks; given a query vector q, a key vector k, and a value vector v, the calculation process of the scaled dot-product attention is: where • denotes the dot product operation, d k is the dimension of the query and key; Through training the task-specific layer, the task-specific layer can accept the vector representation of the user input question and output the one-hot encoding for the specific task. In this process, the vector representation of the user input question passes through the task-aware self-attention adjustment layer and the task-specific layer; by multiplying the output feature fusion representation of the task-aware self-attention adjustment layer and the one-hot encoding of the task-specific layer for the task, the feature fusion representation for the current task is obtained.
2. The model temperature self-adaptive fine-tuning method for smart aquaculture question answering according to claim 1, characterized in that, The Bert model is used to represent the question, specifically: When processing user input text, the Bert model is used to represent each token in the text, where the token is the smallest unit of text segmentation. The Bert model generates a context-dependent embedding vector for each token by learning the context of the text; the smallest unit is a word, subword, or a character.
3. The model temperature self-tuning method for smart farming question answering according to claim 1, wherein, The task-specific layer is trained, specifically: A unique one-hot encoding is assigned to each task for the order of its corresponding LoRA module; The question of each sample in the original data set is combined with the one-hot encoding of the corresponding task of the sample to form a new data set; The task-specific layers are supervised trained using this new dataset.
4. The model temperature self-adaptive fine-tuning method for smart farming question answering according to claim 1, characterized in that, The LoRA parameters of the new dataset under different tasks are fine-tuned to obtain different task-specific LoRA modules, specifically: For a pretrained weight matrix W0∈R d×k , d denotes the number of rows of the weight matrix W0, k denotes the number of columns of the weight matrix W0, R d×k denotes the dimension of a matrix, i.e., d rows k columns, the update is represented by W0+AW = W0+BA, both A and B are low-rank matrices, where B ∈ R d×r , A ∈ R r×k , and rank r « min(d, k), during training, W0is frozen and does not receive gradient updates, while A and B contain trainable parameters; meanwhile, both W0and AW = BA receive the same input and sum their respective output vectors by position; By optimizing the cross-entropy loss function, the two low-rank matrices can adapt to the needs of downstream tasks. During the fine-tuning process, the weight matrix of the original model is frozen, and only the low-rank matrices A and B need to be trained.
5. A model temperature self-adaptive fine-tuning system for smart farming question answering, characterized in that, The model temperature adaptive fine-tuning method for smart breeding question answering according to any one of claims 1-4 comprises an originality evaluation module, a model training module, a parameter fine-tuning module, and a feature fusion module. The originality evaluation module is configured to process an original question and answer dataset based on a preset large language model to obtain an originality evaluation value of each sample, and construct a new dataset based on a question of each sample and the corresponding originality evaluation value. The model training module is configured to represent the question using a Bert model, train a temperature model using the new dataset, and train task-specific layers. The goal of the temperature model is to train the temperature model using the processed dataset through supervised learning, so that the temperature model can learn the pattern in the data and evaluate the text creatively. The task-specific layers select the output of one neuron according to the question after the task-aware self-attention adjustment of multiple task-specific LoRA modules. The parameter fine-tuning module is configured to fine-tune the LoRA parameters of the new dataset under different tasks to obtain different LoRA modules for different tasks. The feature fusion module is configured to use a task-aware self-attention adjustment layer to fuse the outputs of the task-specific LoRA modules.
6. An electronic device, comprising: The electronic device comprises: at least one processor; and a memory connected to the at least one processor in communication; wherein The memory stores computer program instructions executable by the at least one processor, and the computer program instructions are executed by the at least one processor to enable the at least one processor to execute the model temperature adaptive fine-tuning method for smart breeding question answering according to any one of claims 1-4.
7. A computer-readable storage medium storing a program, characterized in that, The program is executed by the processor to implement the model temperature adaptive fine-tuning method for smart breeding question answering according to any one of claims 1-4.
Citation Information
Patent Citations
Traffic light control method and system based on multi-agent reinforcement learning in control area
CN115631638A
Knowledge graph construction and dynamic extension method and device, equipment and medium
CN116502711A