Large language model construction method and device for sheep disease diagnosis
By constructing a sheep disease diagnosis model based on pre-trained models, combining field fine-tuning and knowledge graph enhancement, the problems of small coverage and low diagnostic efficiency of traditional sheep disease diagnosis methods are solved, and the diagnosis of high accuracy and high recall is achieved As a result, the health management level of sheep breeding industry has been improved.
Patent Information
- Application Number
- CN202411876934.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-19
- Publication Date
- 2025-01-17
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Traditional sheep disease diagnosis methods have small veterinary coverage, low diagnostic efficiency, complex diagnostic process, and limited public awareness of sheep diseases, making it difficult to obtain effective disease prevention and control information and technology, especially in emergencies, which are difficult to provide timely accuracy. Diagnostic results.
A sheep disease diagnosis model based on pre-trained models is constructed, and a large language model with high accuracy and recall is formed through domain fine-tuning and knowledge graph strengthening, and is used for the diagnosis of sheep disease. Specific methods include constructing a data set of questions and answers for goat diseases and a knowledge graph, fine-tuning the model using a low-rank adaptation method, and strengthening the model's answering ability through the knowledge graph to improve the accuracy and reliability of the model.
It has achieved the improvement of the efficiency and intelligence of diagnosis and treatment work in the diagnosis of sheep diseases, provided high accuracy and high recall diagnostic results, and improved the health management level of the sheep breeding industry.
Smart Images

Figure CN119323252A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a method and a device for constructing a large language model for sheep disease diagnosis. Background Art
[0002] Sheep breeding occupies an important position in agriculture, but the diagnosis and prevention of sheep diseases have always been an important challenge faced by breeders and veterinarians. Traditional methods for diagnosing sheep diseases have problems such as small veterinary coverage and untimely treatment; limited professional knowledge of breeders and low diagnostic efficiency. Although sheep diseases themselves are less in variety than human diseases, the symptoms are more similar and are often affected by factors such as season and environment, which makes the diagnosis process somewhat complicated.
[0003] Traditional sheep disease diagnosis methods are unable to provide accurate diagnosis results in a timely manner in emergency situations, and the public's knowledge of sheep diseases is limited, making it difficult to obtain effective disease prevention and control information and technology. Summary of the invention
[0004] In order to overcome the shortcomings of the above-mentioned prior art, the present invention provides a method and device for constructing a large language model for sheep disease diagnosis. By constructing a sheep disease diagnosis model based on a pre-trained model, and sequentially performing domain fine-tuning and knowledge graph enhancement, a large language model with high accuracy and recall rate is achieved for sheep disease diagnosis.
[0005] According to one aspect of the present invention, a method for constructing a large language model for sheep disease diagnosis is provided, comprising: Build a sheep disease question-answering dataset and knowledge graph; A sheep disease diagnosis model was built based on the LLaMA2-13B-Chinese pre-trained model, and the sheep disease diagnosis model was fine-tuned in the field using a low-rank adaptation method combined with a constructed sheep disease question-answering dataset; Based on the constructed knowledge graph, the answering ability of the fine-tuned sheep disease diagnosis model is enhanced; The enhanced sheep disease diagnosis model was evaluated to ensure that the model recall rate and accuracy met the preset requirements.
[0006] As a further technical solution, a sheep disease question-answering dataset was constructed, including: Obtain text format data from the dataset, input it into the general large language model, and convert it into instruction format data; The flowchart format data in the data set is obtained and multiple rounds of question and answer data are generated based on the flowchart format data, the generated multiple rounds of question and answer data are input into a general large language model, and converted into text format data, and the text format data is input into the general large language model again, and converted into instruction format data.
[0007] As a further technical solution, a knowledge graph of sheep diseases is constructed in the form of triples, including several groups of corresponding head entities, tail entities and the relationship between the two.
[0008] As a further technical solution, the sheep disease diagnosis model is fine-tuned in the field, and further includes: Align and fine-tune the constructed sheep disease diagnosis model according to the Chinese instruction set; According to the instruction format data obtained by conversion, the aligned fine-tuned model is fine-tuned on the domain data in combination with the low-rank adaptation method.
[0009] As a further technical solution, based on the constructed knowledge graph, the fine-tuned sheep disease diagnosis model is enhanced in its ability to answer questions, including: Calculate the similarity between the question and the knowledge graph triples, and retrieve the triples most relevant to each question based on the calculated similarity.
[0010] As a further technical solution, the similarity between the question and the knowledge graph triples is calculated, including: Use the BERT model to represent each word in the entire input question or triple in vector form; Represent the vector of the entire sentence or triple by taking the average or the CLS token vector of the last layer; The L2 norm is used to calculate the length of the question vector and the triple vector, and then the cosine similarity of the angle between the vectors is calculated.
[0011] As a further technical solution, the calculated cosine similarity value is The closer it is to 1, the more the question matches the triple.
[0012] According to one aspect of the present invention, there is provided a large language model construction device for sheep disease diagnosis, comprising: Data construction module, used to build sheep disease question-answering dataset and knowledge graph; A pre-trained model fine-tuning module is used to build a sheep disease diagnosis model based on the LLaMA2-13B-Chinese pre-trained model, and to fine-tune the sheep disease diagnosis model in the field by combining a low-rank adaptation method with a constructed sheep disease question-answering dataset; The model enhancement module is used to enhance the answering ability of the fine-tuned sheep disease diagnosis model based on the constructed knowledge graph; The model evaluation module is used to evaluate the enhanced sheep disease diagnosis model so that the model recall rate and accuracy meet the preset requirements.
[0013] According to one aspect of the present specification, there is provided a large language model for sheep disease diagnosis, which is obtained by using the large language model construction method for sheep disease diagnosis.
[0014] According to one aspect of the present specification, a non-transitory computer-readable storage medium is provided, wherein the non-transitory computer-readable storage medium stores computer instructions, wherein the computer instructions enable the computer to execute the method for constructing a large language model for sheep disease diagnosis.
[0015] Compared with the prior art, the present invention has the following beneficial effects: The present invention first constructs a sheep disease question-answering dataset and a knowledge graph related to sheep diseases; secondly, based on the LLaMA2-13B-Chinese pre-training model, the LoRA technology is used to perform domain fine-tuning, and the model after domain fine-tuning is combined with the knowledge graph to strengthen the model's answering ability and improve the accuracy and reliability of the model's answers. Finally, by comparing the model provided by the present invention with the existing model, it is verified that the model of the present invention has a high accuracy and recall rate, and can be used to improve the work efficiency and intelligent level of sheep disease diagnosis and treatment. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, a brief introduction is given below to the drawings used in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0017] Figure 1 A schematic flow chart of a method for constructing a large language model for sheep disease diagnosis provided in an embodiment of the present invention.
[0018] Figure 2 A schematic diagram of the principles of a method for constructing a large language model for sheep disease diagnosis provided in an embodiment of the present invention.
[0019] Figure 3 A schematic diagram of the process of constructing sheep disease question and answer data provided by an embodiment of the present invention.
[0020] Figure 4 A schematic diagram of the actual diagnosis process of sheep diseases provided by an embodiment of the present invention.
[0021] Figure 5 A schematic diagram of the F1 value distribution of different models provided in an embodiment of the present invention.
[0022] Figure 6 A schematic diagram of the structure of a large language model construction device for sheep disease diagnosis provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0023] It should be noted that: Since the release of ChatGPT, the Large Language Model (LLM) has attracted widespread attention from all over the world. The LLM has powerful natural language understanding and generation capabilities. It can learn from massive amounts of text data and master rich language patterns and semantic information, so that it can understand and extract information from the sheep symptom descriptions or questions entered by users, providing effective semantic understanding and information extraction support for the diagnosis of sheep diseases.
[0024] LLM is a powerful emergent capability that is demonstrated by expanding the scale of the language model (LM), that is, increasing the model size or using a larger data set for training. In particular, the progress of LLM is particularly significant in the field of medical diagnosis. The combination of LLM and medical health data can provide valuable means for accelerating discovery and improving health. The performance of LLM, especially ChatGPT, in answering questions in the fields of ophthalmology, surgery, and genetics has exceeded the level of ordinary humans, and is even close to the level of human experts. The existing medical diagnosis system has three main functions: First, it can realize doctor-patient dialogue. For example, Xiong et al. used traditional Chinese medicine or human disease question and answer data to train the open source large model ChatGLM to obtain a large model of Chinese doctor-patient dialogue. Li et al. crawled real doctor-patient dialogue data from online medical websites to fine-tune LLaMA to construct an English doctor-patient dialogue model. HuaTuo GPT trained by Zhang et al. and BenTsao trained by Zhao et al. fine-tuned the LLaMA model to obtain a large model of Chinese doctor-patient dialogue. The second is diagnostic report generation. For example, Taiyi trained by Luo et al. realizes intelligent question and answer in the biomedical field and report generation by training bilingual biomedical data in Chinese and English. Finally, multimodal data is combined to achieve disease imaging diagnosis tasks. For example, Thawkar et al. combined X-ray images with English text data to achieve multimodal medical imaging diagnosis, which promoted the application of multimodal large models in the medical field.
[0025] Most of the above studies are based on human disease diagnosis, while the diagnostic methods for agricultural fields, including animal diseases, are mostly limited to traditional expert face-to-face consultations. There are also a few studies based on large models or knowledge graphs. For example, the Shennong large model developed by China Agricultural University includes four aspects: breeding, aquaculture, planting, and remote sensing meteorology. In order to solve problems such as seed screening, epidemic intervention, pest and disease identification, and natural disaster warning, large agricultural models are designed to solve problems in the agricultural field. Hoang et al. proposed a LiteralKG model that integrates multiple literal information and graph structures in the knowledge graph into a unified representation to improve the efficiency of animal disease question-and-answer diagnosis. Yang Zhe et al. constructed a knowledge graph of sheep diseases by crawling sheep disease data, and realized the retrieval and answering of sheep diseases based on the BERT model.
[0026] In the context of the lack of open source large-scale models in the vertical field of sheep diseases, this invention collects professional sheep disease information and constructs a sheep disease question-and-answer dataset and knowledge graph. Based on the sheep disease field dataset, fine-tuning and knowledge graph enhancement are performed based on the pre-trained model LLaMA2, so that the large model can be used to answer questions related to sheep diseases. The trained model is evaluated and compared with existing and popular large models such as ChatGPT-4o and Kimi. It is expected to explore and verify the actual application potential and effect of intelligent diagnosis technology in the field of sheep disease diagnosis, and provide new technical support and solutions for the healthy development of the sheep farming industry. Improve the efficiency and accuracy of sheep farming industry and veterinary diagnosis, and at the same time improve the level of sheep health management.
[0027] The terms "including" and "having" and any variations thereof in the specification and claims of the present invention and the above-mentioned drawings are intended to cover non-exclusive inclusions, for example, a process, method, system, product or apparatus comprising a series of steps or units is not necessarily limited to the steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products or apparatuses.
[0028] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. In addition, the technical features in the various embodiments or single embodiments provided by the present invention are arbitrarily combined with each other to form a new technical solution. This combination is not restricted by the sequence of steps and / or the structural composition mode, but must be based on the ability of ordinary technicians in this field to achieve. When the combination of technical solutions is contradictory or cannot be achieved, it should be considered that this combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0029] The embodiment of the present invention provides a method for constructing a large language model for sheep disease diagnosis, such as Figure 1 As shown, it includes: constructing a sheep disease question and answer dataset and a knowledge graph; constructing a sheep disease diagnosis model based on the LLaMA2-13B-Chinese pre-training model, and using a low-rank adaptation method combined with the constructed sheep disease question and answer dataset to fine-tune the sheep disease diagnosis model in the field; based on the constructed knowledge graph, enhancing the answering ability of the fine-tuned sheep disease diagnosis model; evaluating the enhanced sheep disease diagnosis model to ensure that the model recall and accuracy meet the preset requirements.
[0030] The implementation framework of the sheep disease diagnosis model designed in the embodiment of the present invention is as follows: Figure 2 As shown. This framework mainly shows the technical route for fine-tuning the sheep disease diagnosis model. The first step is to obtain data from relevant books, websites, real diagnosis cases and other sources, and pre-process the data. For text data, direct instructions are given to LLM, so that LLM gives the text content to simulate the real veterinarian-breeder dialogue to form single-round instructions-output format data and triple format data. For flowchart format data, because the flowchart diagnosis process is similar to the real doctor-patient multi-round consultation process, it is necessary to first convert the flowchart into text format and manually check it, and then give it to LLM in the form of instructions to simulate multi-round instructions-output format data and triple format data. Manual inspection is required during data processing to ensure data accuracy.
[0031] The preprocessed data is divided into two formats. One is the knowledge graph triple format, and the other is the instruction-output format that can be used to fine-tune the domain model. The domain data is then used to fine-tune the pre-trained model to obtain a large model with answers to sheep disease data. The triples are used as the key content of the enhanced model answer, and are matched with user questions to finally obtain a sheep disease diagnosis model with strong reliability and high accuracy. Finally, the model is evaluated with the existing mainstream model to verify the accuracy of the model designed by the present invention.
[0032] In the embodiments of the present invention, the methods for obtaining sheep disease data are generally divided into two types: one is to obtain it from the existing general LLM. LLM dialogue is fluent but lacks professional vertical field knowledge. The quality of the acquired sheep disease knowledge is not high compared with professional veterinary diagnosis, which affects the generalization and application of the model. The other is to obtain it from the real veterinary diagnosis data. Veterinary diagnosis data is highly subjective, but the response after model learning is concise and lacks details; compared with LLM, the veterinarian's reply is professional but the interaction is not friendly. Therefore, the present invention adopts a method combining real-world data with LLM to obtain sheep disease diagnosis data.
[0033] The real-world data of this invention comes from public books on sheep diseases, Sunshine Livestock Network (http: / / www.ygsite.cn / ) and unpublished expert diagnosis case records. The data content includes 207 real sheep diseases, divided into 10 types, and 1152 disease symptoms. There are 487 corresponding treatment drugs, and each drug contains information such as dosage and usage. The question-answering dataset construction process is as follows: Figure 2 As shown: The construction process of the sheep disease dataset provided by the embodiment of the present invention is as follows: Figure 3 shown.
[0034] The above real diagnosis data is given to ChatGPT in different ways to generate sheep disease instruction data similar to the format of the Alpaca dataset, so that the model can follow the user's instructions. Different prompt methods are designed for sheep disease introduction, treatment methods, drug dosage and other data to give roles or different questioning methods to make the data diverse. The output results are rewritten based on the original text, and the generated data format is shown in Table 1.
[0035] Table 1. Instruction data generated based on real sheep disease information
[0036] Judging diseases based on symptoms of sheep diseases, or providing symptom-related questions and answers based on diseases, is a complex process and usually requires multiple rounds of questions and answers between doctors and patients. Real-world data on judging diseases based on symptoms are usually given in the form of flow charts, such as Figure 4 shown.
[0037] It is difficult for current large models to understand such data, so humans need to first understand the specific diagnostic process, and then inform the large model of the diagnostic process to generate usable instructions. To ensure that the diagnostic process is consistent with the process of real veterinary diagnosis of diseases, the generated multi-round question and answer sample data format is shown in Table 2.
[0038] Table 2. Generating multi-round question-answering data based on flowchart information
[0039] By converting the original text and original flowchart into a usable format, large model training format data based on the real diagnostic process will be obtained, which will enable the model to generate detailed, rich, and structured conversation content.
[0040] In the training of the sheep disease diagnosis model described in the embodiment of the present invention, training the large model into a domain question-answering model generally requires four steps: pre-training, fine-tuning, reward model, and reinforcement learning. Reward models and reinforcement learning can be collectively referred to as reinforcement learning with human feedback (RLHF). The pre-trained model is a model that has been trained on a large amount of data, can capture the grammatical and semantic information of the language, and can provide rich feature representations for downstream tasks. Since training a large model from scratch requires a lot of computing resources and time, fine-tuning the pre-trained model can achieve good performance with less domain data and computing resources, and complete specific domain tasks.
[0041] When the present invention uses domain data fine-tuning, the pre-trained model used is LLaMA2-13B-Chinese. Because the Chinese alignment of LLaMA2 itself is relatively weak, and the data used in the present invention are all in Chinese format, the development of the Chinese sheep disease diagnosis model requires the use of the Chinese instruction set to fine-tune the model first, and then fine-tune the model obtained after fine-tuning the domain data. The advantage of this method is that it enables the model to better understand and process the Chinese language, and can master the professional terms and diagnostic logic in the domain data.
[0042] In the supervised fine-tuning stage (Supervised Fine-Tuning, SFT), 5903 previously collected and refined data are introduced, so that the model can simulate the question-and-answer interaction between veterinarians and breeders, while maintaining the original logic and coherence of the pre-trained model. The present invention uses the LoRA (Low-Rank Adaptation) fine-tuning method to efficiently fine-tune the model parameters. This method only updates a small part of the model's parameters (i.e., the parameters of the low-rank matrix), reducing the model's computing resource requirements and memory usage requirements. Since not all model parameters are updated, LoRA reduces the risk of overfitting on small data sets. It also improves the interpretability of model learning and adaptation to new tasks.
[0043] Traditional reinforcement learning methods further score the answers of pre-trained models to align human preferences by training reward models, reference models, and value models, so they are called RLHF, such as the PPO (Proximal Policy Optimization) algorithm proposed by OpenAI. In addition, there is the RLMF (Reinforcement Learning with Mixed Feedback) method that mixes human feedback with feedback from artificial intelligence (such as ChatGPT) and strengthens the model. The RLAIF (Reinforcement Learning with AIFeedback) method inputs artificial intelligence feedback into the model for reinforcement. The RRHF (Rank Responses to alignHuman Feedback) method scores responses based on the logarithmic probability provided by the trained language model. The scores are then matched with the scores in the human preference reward model or human preference labels through ranking losses.
[0044] In the answer of the knowledge graph enhanced model of the embodiment of the present invention, the knowledge graph is mainly presented in the form of triples, which contain a large number of entities and their relationships. This information can provide rich background knowledge for the model and help the model generate more accurate and detailed answers. The present invention constructs a knowledge graph containing 1934 triples. Examples of sheep disease triples are shown in Table 3.
[0045] Table 3 Examples of sheep disease triples
[0046] Relying solely on pre-trained models may not provide enough information. Triples can provide additional supporting information for these complex queries, helping the model to better understand and handle complex question-answering tasks, thereby improving the model's generalization ability on different types of questions in different fields. By calculating the similarity between the question and the knowledge graph triple, the most relevant triple for each question can be retrieved. This matching mechanism ensures that the model can reference the most relevant knowledge when answering questions, improving accuracy and reliability.
[0047] The method adopted by the present invention is to match the sheep disease triples with the user's questions, use the Jieba word segmentation library to segment the questions, ensure that the sheep disease related proper nouns are correctly segmented, and finally input the matched triples into the model together with the questions in the form of prompts to generate the final answer. The matching formula is shown in (1): The BERT model is used to represent each word in the entire question or triple in the input as a vector, and then the vector of the entire sentence or triple is represented by taking the average or the CLS token vector of the last layer. The question vector is represented as , is the vector representation of the i-th question, and the triple vector is represented as , is the vector representation of the jth triple. The L2 norm is used to calculate the length of the problem vector and the triple vector, and finally the cosine similarity of the angle between the vectors is calculated. The closer it is to 1, the more similar the two vectors are, that is, the more the question and the triple match. Examples of question and triple matching are shown in Table 4.
[0048] Table 4 Example of question and triple matching
[0049] After strengthening the model's answering ability through the knowledge graph, the embodiment of the present invention further evaluates and verifies the model.
[0050] The present invention uses the BertScore method to evaluate the quality of the model's answer results. BertScore calculates the recall rate by matching each token in the reference sentence with the token in the candidate sentence. At the same time, each token in the candidate sentence is matched with the token in the reference sentence to calculate the precision. A greedy matching strategy is used to maximize the matching similarity score. Finally, the recall rate (R, %) and the precision (P, %) are combined to generate the F1 value. The calculation of the recall rate is shown in formula (2), the calculation of the precision rate is shown in formula (3), and the calculation of F1 is shown in formula (4):
[0051] in For reference answer, The answer to the model is represents the vector representation of the i-th word in the reference answer, Represents the vector representation of the jth word in the model's answer. Transpose T is used to adjust the dimension of the vector so that it can be dot-producted with another vector. The calculation is to calculate the vector of the i-th word in the reference sentence and the vector of the j-th word in the candidate sentence, and then use the max function to find the word most similar to the i-th word in the reference sentence, and finally sum them up to get the total similarity score of the entire sentence.
[0052] The experimental operating system is Linux Ubuntu distribution, the processor used is Intel(R) Xeon(R) Gold6130 CPU @ 2.10GHz, the memory size is 25GB. The GPU model used is V100, and the video memory size is 32GB. The Python version used in the experiment is 3.8, the CUDA version is 11.8, and the corresponding PyTorch version is 2.0.0.
[0053] The model uses the LoRA fine-tuning method. The model training occupies about 26GB of video memory. The training parameters are shown in Table 5. Using a smaller learning rate helps to stably update the model parameters so that LLM can better retain the useful features learned previously. lora_alpha represents the alpha parameter that controls the scaling of the low-rank matrix. The value of 16 means that in the low-rank update of LoRA, the influence of the adjusted features is appropriately amplified, thereby enhancing the adaptability of the model. lora_rank represents the rank of the low-rank matrix in LoRA. The default value is 8, which can better balance the computational efficiency and model performance, making the fine-tuning process more efficient. lora_dropout is set to 0 to indicate that the Dropout technology is not used in the fine-tuning process, so that the model retains all information as much as possible.
[0054] Table 5 Model training parameter settings
[0055] Fine-tune the model under the above parameter settings, and set a test set to test the final performance of the model and the answer results. The test set consists of 2034 questions that have not been put into the model training. Give the fine-tuned model, ChatGPT-4o, and Kimi three models 2034 data to generate answers. Finally, use BertScore to match the similarity of each model answer with the corresponding correct answer to the question. For each model answer, the F1 distribution is as follows Figure 5 shown.
[0056] Depend on Figure 5 It can be seen that 73.68% of the F1 values of SheepDoctor provided by the present invention are concentrated between 0.6 and 0.8, and 64.25% and 60.29% of ChatGPT-4o and Kimi are concentrated between 0.6 and 0.8, respectively. Therefore, Sheep Doctor shows a more stable performance than ChatGPT-4o and Kimi, and the model can provide relatively consistent and reliable diagnosis results in most cases. In addition, 6.74% of the model's answer results are in the high score range of 0.8 to 1.0, while the other two models only have 2.02% and 1.73%, indicating that the model can achieve a high balance between accuracy and recall in some cases, and also indicating that the two models of ChatGPT-4o and Kimi perform relatively generally in the case of sheep disease diagnosis. In comparison, the sheep disease diagnosis model SheepDoctor performs more superiorly, and the model has stronger professionalism and reliability in the vertical field of sheep diseases.
[0057] The average accuracy, recall, and F1 value of different models for answering questions about sheep diseases are shown in Table 6.
[0058] Table 6 Average precision, recall, and F1 value of different models for answering questions about sheep diseases
[0059] From the data in the above table, we can see that the recall and precision of SheepDoctor, a sheep disease diagnosis model, are higher than those of the other two models. Higher precision means that the model can provide correct information more accurately when generating answers, while higher recall means that the model can cover a wider range of related questions. Therefore, SheepDoctor performs well in precision and recall, indicating that it can provide farmers with more accurate and useful disease diagnosis and treatment information.
[0060] The implementation basis of each embodiment of the present invention is to implement programmed processing through a device with a processor function. Therefore, in engineering practice, the technical solutions and functions of each embodiment of the present invention are encapsulated into various modules. Based on this reality, on the basis of the above embodiments, an embodiment of the present invention provides a large language model construction device for sheep disease diagnosis, which is used to execute the large language model construction method for sheep disease diagnosis in the above method embodiment.
[0061] See also Figure 6The device includes: a data construction module, which is used to construct a sheep disease question and answer dataset and a knowledge graph; a pre-trained model fine-tuning module, which is used to construct a sheep disease diagnosis model based on the LLaMA2-13B-Chinese pre-trained model, and adopt a low-rank adaptation method in combination with the constructed sheep disease question and answer dataset to perform domain fine-tuning on the sheep disease diagnosis model; a model enhancement module, which is used to enhance the answering ability of the fine-tuned sheep disease diagnosis model based on the constructed knowledge graph; and a model evaluation module, which is used to evaluate the enhanced sheep disease diagnosis model so that the model recall rate and accuracy meet the preset requirements.
[0062] The large language model construction device for sheep disease diagnosis provided by the embodiment of the present invention adopts Figure 6 By combining several modules in the pre-trained model, a sheep disease diagnosis model is constructed, and domain fine-tuning and knowledge graph enhancement are performed in turn to achieve a large language model with high accuracy and recall rate for sheep disease diagnosis.
[0063] It should be noted that the device embodiments provided by the present invention are used to implement the methods in the above method embodiments as well as the methods in other method embodiments provided by the present invention. The only difference is that the corresponding functional modules are set, and the principle is basically the same as the principle of the above device embodiments provided by the present invention. As long as the technical personnel in the field refer to the specific technical solutions in other method embodiments on the basis of the above device embodiments, obtain the corresponding technical means and the technical solutions composed of these technical means by combining the technical features, and on the premise of ensuring the practicality of the technical solutions, improve the modules in the above device embodiments to obtain the corresponding device class embodiments, which are used to implement the methods in other method class embodiments. For example: Based on the content of the above device embodiment, as a preferred embodiment, in the large language model construction device for sheep disease diagnosis provided in the embodiment of the present invention, the data construction module is also used to execute the following instructions: Obtain text format data from the dataset, input it into the general large language model, and convert it into instruction format data; The flowchart format data in the data set is obtained and multiple rounds of question and answer data are generated based on the flowchart format data, the generated multiple rounds of question and answer data are input into a general large language model, and converted into text format data, and the text format data is input into the general large language model again, and converted into instruction format data.
[0064] Based on the content of the above device embodiment, as a preferred embodiment, in the large language model construction device for sheep disease diagnosis provided in the embodiment of the present invention, the data construction module is also used to execute the following instructions: The sheep disease knowledge graph is constructed in the form of triples, including several groups of corresponding head entities, tail entities and the relationship between them.
[0065] Based on the content of the above device embodiment, as a preferred embodiment, in the large language model construction device for sheep disease diagnosis provided in the embodiment of the present invention, the pre-trained model fine-tuning module is also used to execute the following instructions: Align and fine-tune the constructed sheep disease diagnosis model according to the Chinese instruction set; According to the instruction format data obtained by conversion, the aligned fine-tuned model is fine-tuned on the domain data in combination with the low-rank adaptation method.
[0066] Based on the content of the above device embodiment, as a preferred embodiment, in the large language model construction device for sheep disease diagnosis provided in the embodiment of the present invention, the model enhancement module is also used to execute the following instructions: Calculate the similarity between the question and the knowledge graph triples, and retrieve the triples most relevant to each question based on the calculated similarity.
[0067] Based on the content of the above device embodiment, as a preferred embodiment, in the large language model construction device for sheep disease diagnosis provided in the embodiment of the present invention, the model enhancement module is also used to execute the following instructions: Use the BERT model to represent each word in the entire input question or triple in vector form; Represent the vector of the entire sentence or triple by taking the average or the CLS token vector of the last layer; The L2 norm is used to calculate the length of the question vector and the triple vector, and then the cosine similarity of the angle between the vectors is calculated.
[0068] Based on the content of the above device embodiment, as a preferred embodiment, the large language model construction device for sheep disease diagnosis provided in the embodiment of the present invention, the model enhancement module also includes: The calculated cosine similarity value is between [−1, 1]. The closer it is to 1, the more it matches the question and the triple.
[0069] Based on the same inventive concept as the above embodiment, the embodiment of the present invention further provides a large language model for sheep disease diagnosis, which is constructed by a large language model construction method for sheep disease diagnosis, and the method comprises the following steps: Build a sheep disease question-answering dataset and knowledge graph; A sheep disease diagnosis model was built based on the LLaMA2-13B-Chinese pre-trained model, and the sheep disease diagnosis model was fine-tuned in the field using a low-rank adaptation method combined with a constructed sheep disease question-answering dataset; Based on the constructed knowledge graph, the answering ability of the fine-tuned sheep disease diagnosis model is enhanced; The enhanced sheep disease diagnosis model was evaluated to ensure that the model recall rate and accuracy met the preset requirements.
[0070] Based on the same inventive concept as the above embodiment, the embodiment of the present invention further provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, wherein the computer instructions enable the computer to execute the method for constructing a large language model for sheep disease diagnosis, comprising the following steps: Build a sheep disease question-answering dataset and knowledge graph; A sheep disease diagnosis model was built based on the LLaMA2-13B-Chinese pre-trained model, and the sheep disease diagnosis model was fine-tuned in the field using a low-rank adaptation method combined with a constructed sheep disease question-answering dataset; Based on the constructed knowledge graph, the answering ability of the fine-tuned sheep disease diagnosis model is enhanced; The enhanced sheep disease diagnosis model was evaluated to ensure that the model recall rate and accuracy met the preset requirements.
[0071] In summary, the present invention constructs a sheep disease question-answering dataset and fine-tunes it based on the pre-trained model LLaMA2 to develop a large model SheepDoctor that can be used for sheep disease diagnosis. The model integrates the technology of knowledge graph and human feedback reinforcement learning, aiming to improve the accuracy and reliability of sheep disease diagnosis. The model training method includes fine-tuning the model from domain data and strengthening the model's answering ability through knowledge graph, thereby realizing a highly professional and interactive diagnosis system.
[0072] SheepDoctor outperforms existing general-purpose large models, such as ChatGPT-4o and Kimi, in multiple indicators. The answer effect was evaluated on 2034 data that the model had not seen. The proportion of SheepDoctor, ChatGPT-4o, and Kimi's answers with F1 values between 0.6 and 0.8 was 73.68%, 64.25%, and 60.29%, respectively, indicating that SheepDoctor can provide consistent and reliable diagnosis results in most cases. And in the proportion of low-segment answers, SheepDoctor only has 17.51%, and ChatGPT-4o and Kimi's low-segment answers are nearly twice that of SheepDoctor, at 33.45% and 37.80%, respectively. This further proves the advantages of the model of the present invention in processing tasks in specific fields, and its professionalism and efficiency in the field of sheep diseases.
[0073] Although the model performs well in sheep disease diagnosis, it still has some shortcomings. First, the model's training data sources are limited and the data diversity is insufficient, which affects the model's generalization ability. Second, due to the complexity of the model, the demand for computing resources during training and inference is high, which limits the model's application in resource-limited environments. Future research can further expand the diversity and timeliness of the dataset and optimize the efficiency of the model to achieve wider application.
[0074] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the technical solutions of the embodiments of the present invention.
Claims
1. A method for constructing a large language model for sheep disease diagnosis, characterized in that: include: Build a sheep disease question-answering dataset and knowledge graph; A sheep disease diagnosis model was built based on the LLaMA2-13B-Chinese pre-trained model, and the sheep disease diagnosis model was fine-tuned in the field using a low-rank adaptation method combined with a constructed sheep disease question-answering dataset; Based on the constructed knowledge graph, the answering ability of the fine-tuned sheep disease diagnosis model is enhanced; The enhanced sheep disease diagnosis model was evaluated to ensure that the model recall rate and accuracy met the preset requirements.
2. The method for constructing a large language model for sheep disease diagnosis according to claim 1, characterized in that: Construct a sheep disease question-answering dataset, including: Obtain text format data from the dataset, input it into the general large language model, and convert it into instruction format data; The flowchart format data in the data set is obtained and multiple rounds of question and answer data are generated based on the flowchart format data, the generated multiple rounds of question and answer data are input into a general large language model, and converted into text format data, and the text format data is input into the general large language model again, and converted into instruction format data.
3. The method for constructing a large language model for sheep disease diagnosis according to claim 1, characterized in that: The sheep disease knowledge graph is constructed in the form of triples, including several groups of corresponding head entities, tail entities and the relationship between them.
4. The method for constructing a large language model for sheep disease diagnosis according to claim 2, characterized in that: Fine-tuning the sheep disease diagnosis model in the field also includes: Align and fine-tune the constructed sheep disease diagnosis model according to the Chinese instruction set; According to the instruction format data obtained by conversion, the aligned fine-tuned model is fine-tuned on the domain data in combination with the low-rank adaptation method.
5. The method for constructing a large language model for sheep disease diagnosis according to claim 1, characterized in that: Based on the constructed knowledge graph, the fine-tuned sheep disease diagnosis model is enhanced in its ability to answer questions, including: Calculate the similarity between the question and the knowledge graph triples, and retrieve the triples most relevant to each question based on the calculated similarity.
6. The method for constructing a large language model for sheep disease diagnosis according to claim 5, characterized in that: Calculate the similarity between the question and the knowledge graph triple, including: Use the BERT model to represent each word in the entire input question or triple in vector form; Represent the vector of the entire sentence or triple by taking the average or the CLS token vector of the last layer; The L2 norm is used to calculate the length of the question vector and the triple vector, and then the cosine similarity of the angle between the vectors is calculated.
7. The method for constructing a large language model for sheep disease diagnosis according to claim 6, characterized in that: The calculated cosine similarity value is The closer it is to 1, the more the question matches the triple.
8. A large language model construction device for sheep disease diagnosis, characterized in that: include: Data construction module, used to build sheep disease question-answering dataset and knowledge graph; A pre-trained model fine-tuning module is used to build a sheep disease diagnosis model based on the LLaMA2-13B-Chinese pre-trained model, and to fine-tune the sheep disease diagnosis model in the field by combining a low-rank adaptation method with a constructed sheep disease question-answering dataset; The model enhancement module is used to enhance the answering ability of the fine-tuned sheep disease diagnosis model based on the constructed knowledge graph; The model evaluation module is used to evaluate the enhanced sheep disease diagnosis model so that the model recall rate and accuracy meet the preset requirements.
9. A large language model for sheep disease diagnosis, characterized in that: The large language model for sheep disease diagnosis is obtained by using the method for constructing a large language model for sheep disease diagnosis as described in any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions enable the computer to execute the large language model construction method for sheep disease diagnosis as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Knowledge graph generation type question answering method and system based on large language model
CN117033608A
Data knowledge dual-drive intelligent medical dialogue system and method based on knowledge graph
CN117077786A
Knowledge graph question-answering method for sub-graph retrieval optimization
CN117149974A
Large language model knowledge question-answering method and system fused with multi-modal knowledge graph
CN118627628A
Image-text fusion question and answer method, device and equipment based on large language model
CN118861229A