System operating safe conversation method of large model fine-tuning and two-stage retrieval generation
By employing a method of large-scale model fine-tuning and two-stage retrieval generation, the problems of retrieval accuracy and response speed in the knowledge management system for the safety of complex system operation are solved, enabling fast and accurate knowledge management and decision support, and improving user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHONGQING UNIV
- Filing Date
- 2025-05-13
- Publication Date
- 2026-07-03
AI Technical Summary
Existing knowledge management systems for the safety of complex systems suffer from limited retrieval accuracy, slow response speed, lack of intelligent decision support, and poor user experience. In particular, they are unable to provide accurate answers and rapid responses when faced with multi-condition and logically complex query requirements.
We employ a large model fine-tuning and two-stage retrieval generation method. We construct question-answer pair data using GPT-4, combine the XTuner framework and QLoRA method for lightweight fine-tuning, build a knowledge base for the safety of complex system operation, and use Dual-Encoder and Cross-Encoder architectures for two-stage retrieval to achieve rapid recall and accurate filtering.
It improves the retrieval accuracy and response speed of the knowledge management system for the safety of complex systems, supports multi-condition combined queries, enhances user experience, and can provide accurate structured answers and rapid responses in complex scenarios.
Smart Images

Figure CN120471172B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of complex system operation safety technology, and in particular to a system operation safety dialogue method generated by large model fine-tuning and two-stage retrieval. Background Technology
[0002] In today's society, complex systems are widely used in infrastructure fields such as transportation, energy, and communications. These infrastructures are the cornerstone of the normal operation of modern society. With the continuous advancement of technology, the scale and complexity of various systems are increasing day by day. The current state of technological development is as follows: 1. Digitization of knowledge resources: Knowledge resources in the field of complex system operation safety, such as laws and regulations, operating procedures, and technical documents, have been gradually digitized into electronic documents, databases, etc., facilitating storage and preliminary retrieval; 2. Simple search functions: Some systems provide basic search functions, enabling keyword searches of digitized knowledge resources, helping users quickly locate documents or fragments containing specific keywords; 3. Preliminary classification and organization: Preliminary classification of complex system operation safety knowledge has been carried out, such as categorization by professional field, business process, etc., so that users can find the information they need more effectively; 4. Application of expert systems: In some complex scenarios, such as accident handling and emergency decision-making, expert systems are used. These systems incorporate the experience and knowledge of domain experts, providing guidance and advice to novices.
[0003] At the same time, there are also some defects and shortcomings:
[0004] 1. Limited search accuracy: (1) Limitations of keyword matching: The search method that relies on keyword matching is difficult to understand the user's true intention and the semantic content of the document, resulting in a large amount of irrelevant or low-quality information in the search results, and users need to spend extra time and effort to filter it; (2) Inability to handle complex queries: For query requirements involving multiple conditions and complex logical relationships, simple search functions often cannot accurately understand and respond, and cannot provide accurate answers.
[0005] 2. Lack of intelligent decision support: (1) Insufficient information integration: When faced with complex security issues, it is unable to automatically integrate knowledge resources from multiple sources and of multiple types to provide decision-makers with comprehensive and in-depth analysis and suggestions; (2) Inability to make predictions and inferences: It lacks the ability to predict and analyze potential risks and trends, and is unable to make inferences and simulations based on existing knowledge to support preventive and forward-looking decisions.
[0006] 3. Poor user experience: (1) Simple interaction method: The human-computer interaction method is relatively primitive, mainly relying on text input and simple commands. It lacks natural language processing capabilities, cannot understand the user's natural language questions, and affects the query efficiency; (2) Slow response speed: When processing large-scale knowledge bases or complex queries, the system's response speed is slow, which cannot meet the real-time requirements and delays the decision-making opportunity. Summary of the Invention
[0007] The purpose of this invention is to provide a system operation safety dialogue method based on large model fine-tuning and two-stage retrieval. It adopts a two-stage retrieval architecture based on large model enhancement and lightweight fine-tuning technology, which overcomes the difficulties of traditional complex system operation safety knowledge management systems in terms of retrieval accuracy, response speed and model deployment cost.
[0008] To achieve the above objectives, this invention provides a system operation security dialogue method for large model fine-tuning and two-stage retrieval generation, comprising the following steps:
[0009] S1. Data Acquisition and Preprocessing: Acquire data in the field of complex system operation safety and preprocess the data;
[0010] S2. Question-answer pair dataset construction: Based on the preprocessed data in S1, a question-answer pair dataset is constructed using the GPT-4 large model;
[0011] S3. Base Model Fine-tuning: The InternLM2.5-Chat-7B model was selected as the base model. Based on the question-answer pair dataset in S2, the XTuner framework was used in combination with the QLoRA method to perform lightweight fine-tuning of the base model.
[0012] S4. Knowledge Base Construction: Based on the llamaindex framework and using the bce-embedding-base_v1 embedding model, a knowledge base for the security of complex system operation is constructed.
[0013] S5, Vector Recall: Based on the Dual-Encoder architecture embedding model and HNSW algorithm, the knowledge base built in S4 is used for the first stage of fast retrieval to recall knowledge blocks;
[0014] S6. Refinement and Re-ranking: Based on the knowledge blocks retrieved from the vectors in S5, the bce-reranker-base_v1 semantic fine ranking model is used for the second stage of precise screening.
[0015] S7. Answer Generation: Combine the fine-tuned base model from S3 with the search results from S6 to generate the answer.
[0016] Preferably, the specific steps of S1 are as follows:
[0017] S11. Collect data in the field of complex system operation safety: The data includes professional literature, laws and regulations and standards, academic resources and industry knowledge bases. Professional literature includes books and authoritative works. Laws and regulations and standards include relevant laws and regulations, operating procedures and technical standards issued by the state and industry. Academic resources include papers and patents. Industry knowledge bases include examination question banks for practitioners and typical accident case databases.
[0018] S12. Preprocess the data: Preprocessing includes data cleaning, data deduplication, and text formatting. Data cleaning includes removing redundancy and format standardization.
[0019] Preferably, the specific steps of S2 are as follows:
[0020] S21. Prompt word design: Templates are used to guide GPT-4 to extract questions from the preprocessed data in S1. One answer data corresponds to five questions.
[0021] S22. Semantic consistency verification: By calculating the cosine similarity between the question and the answer, question-answer pairs with a similarity > 0.8 are filtered out.
[0022] S23. Format Conversion: Convert the question and answer data into JSON format.
[0023] Preferably, the specific formula for the cosine similarity in S22 is as follows:
[0024]
[0025] Here, Q and A are the word vector representations of the question and the answer, respectively.
[0026] Preferably, the specific steps of S3 are as follows:
[0027] S31. Efficient parameter fine-tuning: Freeze the backbone parameters of the base model and adjust only the low-rank matrix of the adapter module. QLoRA quantizes the weight matrix.
[0028] S32. Prompt word design: Design prompt word templates based on the security requirements of complex system operation scenarios;
[0029] S33. Loss Function Design: The cross-entropy loss function is adopted to optimize the ability of the base model to generate knowledge in the security domain of complex systems;
[0030] S34. Training strategy: Use the AdamW optimizer, set the learning rate to 2e-4, batch size to 16, and perform early stopping using the validation set in the domain. During training, evaluate the base model using the validation set in the domain. If the validation set performance does not improve for several consecutive epochs, stop training early to prevent the base model from overfitting.
[0031] S35. Model Conversion: Use the xtuner convert pth_to_hf command to convert the model weight file originally trained using PyTorch into the currently common HuggingFace format file;
[0032] S36. Model Merging: Based on the additional layers fine-tuned by QLoRA, use the xtuner convert merge command to merge the trained layers with the original base model.
[0033] Preferably, the cross-entropy loss function in S33 is as follows:
[0034]
[0035] Where T is the sequence length, θ is the adapter parameter, P is the conditional probability distribution, and y1,…,y t-1 This refers to the historical output elements in the sequence.
[0036] Preferably, the specific steps of S4 are as follows:
[0037] S41. Knowledge Blocking: Divide long texts into blocks of 200 characters each, based on punctuation marks.
[0038] S42. Vector Generation: Using the bce-embedding-base_v1 model, each knowledge block is encoded into a 768-dimensional semantic vector p. i ;
[0039] S43. Storage and Indexing: The vector storage of the llamaindex framework uses the Chroma database to store text vectors. It performs similarity searches on large-scale datasets through the core HNSW algorithm of the Chroma vector database.
[0040] Preferably, the specific steps of S5 are as follows:
[0041] S51. Query Vectorization: Use the bce-embedding-base_v1 model to convert user questions into query vectors q;
[0042] S52. Similarity Calculation: In the vector database, the cosine similarity formula from S22 is used to calculate the similarity between q and all semantic vectors p in the knowledge base. i Based on the similarity, the top-N knowledge blocks are recalled according to the similarity, where N=10.
[0043] Preferably, the specific steps of S6 are as follows:
[0044] S61, Cross-encoding: Concatenate the Query and Passage and input them into the bce-reranker-base_v1 model to capture the semantic interaction features between the Query and Passage;
[0045] S62. Semantic Score: Based on the semantic interaction features between the Query and Passage, a semantic relevance score s is calculated between the Query and Passage using the Transformer model. i Then, the sigmoid function in torch is called to normalize the scores and then sort them;
[0046] S63. Result Filtering: After reordering the scores, filter out the relevance scores s. i For segments with a score >0.6, low-quality segments are filtered out, and the Top-M highly relevant knowledge blocks are selected as the basis for answer generation, where M=5.
[0047] Preferably, the specific steps of S7 are as follows:
[0048] S71, Context Fusion: Concatenates the selected M knowledge blocks with the user query to form a model input sequence;
[0049] S72. Hint Project: Design hint templates to guide the generation of structured answers from the finely tuned base model.
[0050] Therefore, the system operation security dialogue method generated by the above-mentioned large model fine-tuning and two-stage retrieval in this invention has the following beneficial effects:
[0051] (1) Deep Integration of Domain Knowledge: By integrating multi-source heterogeneous data such as professional literature, regulations and standards, and accident cases, a knowledge system covering different scenarios of complex system operation safety is constructed, solving the data fragmentation problem of traditional methods. Using GPT-4 to generate question-answer pairs and combining them with semantic verification, the bottleneck of high cost and narrow coverage of manual annotation is overcome, significantly improving the diversity and accuracy of training data. Furthermore, the generated question-answer pairs are improved from one answer data corresponding to one question to one answer data corresponding to five questions, expanding the semantic coverage of the training data and enabling the model to learn multi-dimensional linguistic expressions of the same knowledge, thus improving its generalization ability for complex queries.
[0052] (2) Lightweight Model Fine-Tuning Technology: Based on the QLoRA quantization technology of the XTuner framework, efficient domain adaptation of large models is achieved with limited computing power, avoiding the hardware resource consumption of full parameter fine-tuning. By freezing the backbone parameters and only fine-tuning the adapter layer, the general capabilities of the base model are preserved, while also endowing it with the ability to accurately generate professional terminology and safety procedures in the field of complex system operation safety. Prompt words are designed according to actual application needs to guide the model to learn specific expression patterns and knowledge structures.
[0053] (3) Combining rapid coarse screening with precise fine ranking: The first stage (vector recall) uses a dual encoder model to independently encode user questions and knowledge bases into semantic vectors. By performing vector similarity retrieval on the offline vector library, it achieves rapid recall of semantically similar knowledge fragments. The second stage (semantic fine ranking) uses a cross-encoder model to perform deep semantic interaction analysis on candidate fragments, effectively identifying the implicit relationship between user intent and knowledge fragments, filtering low-quality content, and improving the accuracy of relevant content retrieval. The two-stage division of labor balances speed and accuracy, avoiding the drawbacks of "missed detection" or "false detection" in a single retrieval mode.
[0054] (4) Dynamic semantic understanding capability: Automatically associates fuzzy expressions (such as "train suddenly loses power") with technical terms (such as "traction power supply system failure") to improve the robustness of intent parsing in complex scenarios; supports multi-condition combined queries (such as "track circuit failure handling process in rainy weather") to accurately match composite knowledge fragments containing environmental factors, equipment types, and operation steps.
[0055] (5) Multi-scenario adaptive capability: Emergency command: Quickly generate structured solutions containing handling steps, responsible departments, and technical basis to assist on-site decision-making; Personnel training: Improve training efficiency by simulating scenarios such as fault diagnosis and procedure learning through dialogue interaction; Hazard warning: Match potential risk patterns based on historical case database to achieve proactive safety warning.
[0056] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0057] Figure 1 This is a framework diagram of a complex system operation security real-time dialogue method, as exemplified by the system operation security dialogue method generated by large model fine-tuning and two-stage retrieval in this invention.
[0058] Figure 2 This is a two-stage retrieval generation framework diagram for an embodiment of the system operation security dialogue method for large model fine-tuning and two-stage retrieval generation of the present invention. Detailed Implementation
[0059] The technical solution of the present invention will be further described below with reference to the accompanying drawings and embodiments.
[0060] Unless otherwise defined, the technical or scientific terms used in this invention shall have the ordinary meaning understood by one of ordinary skill in the art to which this invention pertains. The terms "first," "second," and similar terms used in this invention do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed following the word and their equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are used only to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0061] Example
[0062] Please see Figure 1-2 This invention provides a system operation safety dialogue method generated by large model fine-tuning and two-stage retrieval. The following is a detailed solution for the high-speed rail operation safety scenario in complex system operation safety, to better illustrate the dialogue method proposed in this invention.
[0063] This invention provides a system operation security dialogue method for large model fine-tuning and two-stage retrieval generation, including the following steps:
[0064] S1. Data Acquisition and Preprocessing: Acquire data related to the operational security of complex systems, and preprocess the data. The specific steps are as follows:
[0065] S11. This invention collects real-world data on high-speed rail operation safety through multiple channels:
[0066] (1) Professional literature: Collected 52 books published in the past 20 years on high-speed rail transportation organization, operation safety assurance, traction power supply system and other fields, including authoritative works such as "High-speed Railway Operation Safety Management" and "Technical Regulations for High-speed Rail Traction Power Supply System";
[0067] (2) Laws and Standards: We have compiled 101 laws, regulations, operating procedures and technical standards related to high-speed rail operation safety issued by the state and industry, including the "Regulations on Safety Management of High-speed Railways" and the "Regulations on Railway Technical Management".
[0068] (3) Academic resources: 500 papers and patents on high-speed rail track circuits, turnout switching machines, and safety accident analysis were retrieved from platforms such as IEEE and CNKI;
[0069] (4) Industry knowledge base: Includes the question bank for the high-speed rail personnel entry examination and the typical accident case database;
[0070] S12. Preprocess the data: Preprocessing includes data cleaning (removing redundancy and standardizing the format), data deduplication, and text formatting.
[0071] S2. Question-answer pair dataset construction: Based on the preprocessed data in S1, question-answer pairs are constructed using the GPT-4 large model for model fine-tuning in the field of high-speed rail operation safety. The specific steps are as follows:
[0072] S21. Prompt Design: The template "Please design five questions based on the following content I will provide\n{input_value}\n. Each answer to these five questions must be the complete content I have provided, and these questions must accurately correspond to the content, ensuring the answers are presented completely. There should be no partial answers or questions requiring additional information. Answering any question should directly output the original content I have provided.\nThe format of the five output questions is:\nque1:\nque2:\nque3:\nque4:\nque5:\n}" guides GPT-4 to extract questions from the preprocessed data in S1. One answer data point corresponds to five questions, expanding the semantic coverage of the training data and enabling the model to learn multi-dimensional linguistic expressions of the same knowledge, thus improving its generalization ability for complex queries.
[0073] S22. Semantic Consistency Verification: By calculating the cosine similarity between the question and the answer, question-answer pairs with a similarity > 0.8 are filtered out. The specific formula for cosine similarity is:
[0074]
[0075] Where Q (question) and A (answer) are the word vector representations of the question and answer, respectively;
[0076] S23. Format Conversion: Convert the question-and-answer data to JSON format, as follows:
[0077]
[0078]
[0079] Unlike existing technologies that rely on a single data source and single-round question-answer pairs, this invention uses a "one data, five questions" question-answer pair expansion strategy generated by GPT-4, combined with a cosine similarity verification mechanism, to improve the semantic coverage of the training data. This multi-dimensional semantic representation construction method enables the model to learn different linguistic expressions of the same knowledge, enhances the model's generalization ability to complex queries, and solves the problem of redundant retrieval results caused by insufficient semantic understanding in traditional systems.
[0080] S3. Base Model Fine-tuning: The InternLM2.5-Chat-7B model was selected as the base model. Based on the question-answer pair dataset in S2, the XTuner framework combined with the QLoRA method was used to perform lightweight fine-tuning of the base model. The specific steps are as follows:
[0081] S31. Efficient parameter fine-tuning: Freeze the backbone parameters of the base model and adjust only the low-rank matrix of the adapter module to reduce the amount of computation. QLoRA reduces memory usage and improves inference efficiency by quantizing the weight matrix (4-bit quantization).
[0082] S32. Prompt Design: Based on the needs of high-speed rail operation safety scenarios, design a prompt template: You are a professional assistant in the field of high-speed rail operation safety. Your task is to answer user questions {input} based on your professional knowledge in the field of high-speed rail safety. Answers must be accurate, comprehensive, logically clear, and conform to industry standards. If the user's question involves multiple aspects, please answer them one by one;
[0083] S33. Loss Function Design: The cross-entropy loss function is adopted to optimize the model's ability to generate knowledge in the field of high-speed rail safety. The cross-entropy loss function is as follows:
[0084]
[0085] Where T is the sequence length, θ is the adapter parameter, P is the conditional probability distribution, and y1,…,y t-1 For historical output elements in the sequence;
[0086] S34. Training strategy: Use the AdamW optimizer, set the learning rate to 2e-4, batch size to 16, and perform early stopping using the validation set in the domain. That is, during training, the model is evaluated using the validation set in the domain. If the performance on the validation set does not improve for several consecutive epochs, training is stopped early to prevent the model from overfitting.
[0087] S35. Model Conversion: Use the xtuner convert pth_to_hf command to convert the model weight file originally trained using PyTorch into the currently common HuggingFace format file;
[0088] S36. Model Merging: Based on the additional layers (Adapters) fine-tuned by QLoRA, use the xtuner convertmerge command to merge the trained layers (Adapters) with the original model.
[0089] This invention utilizes the XTuner framework combined with the QLoRA method. By freezing the backbone parameters of the base model (adjusting only <1% of the adapter parameters) and employing 4-bit quantization, it reduces model memory usage while maintaining excellent model performance. During fine-tuning, this invention designs prompts based on practical application needs to guide the model in learning specific expression patterns and knowledge structures. This technology enables rapid deployment of the model on ordinary hardware, significantly improving system scalability and real-time response capabilities. It meets the timeliness requirements of emergency scenarios for complex system operation security and further enhances the model's understanding of complex queries through optimized prompt design, improving the accuracy and professionalism of the responses.
[0090] S4. Knowledge Base Construction: Based on the llamaindex framework and using the bce-embedding-base_v1 embedding model, a high-speed rail operation safety knowledge vector base is constructed. The specific steps are as follows:
[0091] S41. Knowledge Blocking: Divide long texts into 200-word blocks according to punctuation marks to ensure that each knowledge block contains complete technical points, balancing semantic integrity and retrieval efficiency;
[0092] S42. Vector Generation: Each knowledge block is encoded into a 768-dimensional semantic vector p using the bce-embedding-base_v1 model (dual-encoder architecture). i ;
[0093] S43. Storage and Indexing: llamaindex's vector storage uses the Chroma database to store text vectors. The Chroma database supports 768-dimensional vector storage. With the help of the core HNSW (Hierarchical Navigable Small World) algorithm of the Chroma vector database (which uses a pre-built navigation graph to achieve approximate nearest neighbor search (ANN)), it can achieve fast and efficient similarity search in large-scale datasets.
[0094] S5. Vector Recall: Based on the Dual-Encoder architecture embedding model and the HNSW algorithm, the first stage of fast retrieval of knowledge blocks is performed on the knowledge base built in S4. The specific steps are as follows:
[0095] S51. Query Vectorization: The bce-embedding-base_v1 model is used to convert user questions into query vectors q. The bce-embedding-base_v1 model uses dual encoders to independently encode the query and passage into 768-dimensional vectors.
[0096] S52. Similarity Calculation: In the vector database, the cosine similarity formula from S22 is used to calculate the similarity between q and all semantic vectors p in the knowledge base. i Based on the similarity, the Top-N (N=10) knowledge blocks are recalled according to the similarity score.
[0097] S6. Refinement and Re-ranking: Based on the knowledge blocks retrieved from the vectors in S5, the bce-reranker-base_v1 semantic fine-ranking model (based on the Cross-Encoder architecture) is used for the second stage of precise filtering. The specific steps are as follows:
[0098] S61. Cross-coding: Concatenate Query and Passage into "Query". <sep>The data is in the format "Passage" and input into the bce-reranker-base_v1 model (based on Transformer architecture), which uses multi-head attention to capture the semantic interaction features between Query and Passage.
[0099] S62. Semantic Score: Based on the semantic interaction features of the Query and Passage, the Transformer model calculates the semantic relevance score s between the Query and Passage. i Then, the sigmoid function in torch is called to normalize the scores and then sort them;
[0100] S63. Result Filtering: After reordering the scores, filter out the relevance scores s. i For segments with a score >0.6, low-quality segments are filtered out, and the Top-M (M=5) highly relevant knowledge blocks are selected as the basis for answer generation, which improves accuracy compared to single-stage retrieval.
[0101] This invention employs a two-stage retrieval and generation technology, utilizing the embedding model bce-embedding-base_v1 and the semantic ranking model bce-reranker-base_v1. The two-stage retrieval and generation architecture comprises two main stages. First, offline preprocessing involves processing knowledge blocks through the embedding model to generate semantic vectors, which are then stored in a vector database, completing the vectorization of the knowledge base and providing foundational support for subsequent retrieval. In the online user interaction stage, after a user asks a question, the embedding model first generates a query vector. Through retrieval and recall, the embedding model, based on a Dual-Encoder architecture, uses a dual-encoder structure, inputting the query (user question) and the passage (knowledge base text fragment) into separate encoders to generate their respective semantic vectors. There is no information exchange between the two during the encoding process. Vector similarity retrieval is then performed in the vector database to quickly recall semantically similar knowledge fragments. Subsequently, the scoring re-ranking module uses the Reranker model with a Cross-Encoder architecture. The cross-encoder structure concatenates the Query and Passage and inputs them into the model, allowing them to fully interact with each other during the encoding process. The Transformer model extracts semantic relationships from the recalled fragments, calculates the semantic relevance between the Query and Passage, and prioritizes highly relevant fragments while filtering out low-quality content.
[0102] Unlike traditional single-stage retrieval methods which suffer from low accuracy, this invention employs a two-stage architecture combining a Dual Encoder and a Cross Encoder. The first stage uses the Dual Encoder to perform vector similarity retrieval on an offline vector library, enabling rapid recall of semantically similar knowledge fragments. The second stage utilizes the Cross Encoder to capture semantic interaction features for precise reordering. This hierarchical retrieval strategy significantly improves retrieval accuracy and effectively filters low-quality content through threshold filtering (relevance score > 0.6). Furthermore, the synergistic effect of the dual encoder and the cross encoder allows the system to handle complex semantic relationships, such as accurately identifying the potential connection between "switching machine malfunction" and "track circuit failure," which is impossible with traditional keyword matching techniques.
[0103] S7. Answer Generation: Combine the fine-tuned InternLM2.5-Chat-7B model from S3 with the search results from S6 to generate the answer. The specific steps are as follows:
[0104] S71, Context Fusion: Concatenates the selected M knowledge blocks with the user's query to form the model input sequence "Query". <sep>Context1 <sep>Context2 <sep>...”;
[0105] By designing "Query" <sep>The "Contexts" context fusion prompt template constructs context-aware input. <sep>As a separator, it guides the model to distinguish between the question and background knowledge, and integrates search results with user queries to generate structured answers that conform to the standards of the complex system operation safety domain. This prompting strategy, combined with domain-specific terms, ensures the professionalism and accuracy of the answers, such as automatically associating legal provisions and technical standards, whereas existing technologies often lack the ability to integrate knowledge in the complex system operation safety domain.
[0106] S72, Prompt Project: Design a prompt template "Based on professional knowledge in the field of high-speed rail operation safety, answer the following questions: {Query}. Relevant knowledge is as follows: {Contexts}", to guide the finely tuned InternLM2.5-Chat-7B model to generate structured answers.
[0107] The variables {Query} and {Contexts} are dynamically populated with content. Combined with the domain qualifier "based on knowledge of the security domain of complex system operation", the finely tuned InternLM2.5-Chat-7B model generates and outputs a structured answer that conforms to industry standards based on the high-quality knowledge fragments after score re-ranking.
[0108] This real-time dialogue method for complex system operation safety first collects and preprocesses multi-source data, including professional literature, regulations, and standards in the field of complex system operation safety. It then uses GPT-4 to generate question-answer pairs and constructs a dataset through cosine similarity verification. Based on InternLM2.5-Chat-7B, it fine-tunes the model using XTuner combined with the QLoRA method (freezing backbone parameters, 4-bit quantization, etc.) and completes model transformation and merging. Based on the Llamaindex framework, the preprocessed data is divided into blocks and embedded into a model to generate semantic vectors stored in the Chroma database. Highly relevant text blocks are selected through a two-stage retrieval process and finally integrated into the query question to construct prompt words. These are then input into the fine-tuned model to generate structured answers.
[0109] Therefore, this invention adopts the system operation safety dialogue method generated by the above-mentioned large model fine-tuning and two-stage retrieval. It adopts a two-stage retrieval architecture based on large model enhancement and lightweight fine-tuning technology, which breaks through the difficulties of traditional complex system operation safety knowledge management systems in terms of retrieval accuracy, response speed and model deployment cost. It realizes an automated question answering and fast retrieval mechanism based on knowledge model in complex system operation safety, and is committed to promoting the intelligence, efficiency and accuracy of the field of complex system operation safety.
[0110] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the technical solutions of the present invention, and these modifications or equivalent substitutions cannot cause the modified technical solutions to deviate from the spirit and scope of the technical solutions of the present invention.< / sep> < / sep> < / sep> < / sep> < / sep> < / sep>
Claims
1. A system operation safety dialogue method of large model fine-tuning and two-stage retrieval generation, characterized in that, Includes the following steps: S1. Data Acquisition and Preprocessing: Acquire data in the field of complex system operation safety and preprocess the data; S2. Question-answer pair dataset construction: Based on the preprocessed data in S1, a question-answer pair dataset is constructed using the GPT-4 large model; S3. Base Model Fine-tuning: The InternLM2.5-Chat-7B model was selected as the base model. Based on the question-answer pair dataset in S2, the XTuner framework was used in combination with the QLoRA method to perform lightweight fine-tuning of the base model. S4. Knowledge Base Construction: Based on the llamaindex framework and using the bce-embedding-base_v1 embedding model, a knowledge base for the security of complex system operation is constructed. S5, Vector Recall: Based on the Dual-Encoder architecture embedding model and HNSW algorithm, the knowledge base built in S4 is used for the first stage of fast retrieval to recall knowledge blocks; S6. Refinement and Re-ranking: Based on the knowledge blocks retrieved from the vectors in S5, the bce-reranker-base_v1 semantic fine ranking model is used for the second stage of precise screening. S7. Answer Generation: Combine the fine-tuned base model from S3 with the search results from S6 to generate the answer; The specific steps of S3 are as follows: S31. Efficient parameter fine-tuning: Freeze the backbone parameters of the base model and adjust only the low-rank matrix of the adapter module. QLoRA quantizes the weight matrix. S32. Prompt word design: Design prompt word templates based on the security requirements of complex system operation scenarios; S33. Loss Function Design: The cross-entropy loss function is adopted to optimize the ability of the base model to generate knowledge in the security domain of complex systems; S34. Training strategy: Use the AdamW optimizer, set the learning rate to 2e-4, batch size to 16, and perform early stopping using the validation set in the domain. During training, evaluate the base model using the validation set in the domain. If the validation set performance does not improve for several consecutive epochs, stop training early to prevent the base model from overfitting. S35. Model Conversion: Use the xtuner convert pth_to_hf command to convert the model weight file originally trained using PyTorch into the currently common HuggingFace format file; S36. Model merging: Based on the additional layers fine-tuned by QLoRA, use the xtuner convert merge command to merge the trained layers with the original base model; The specific steps of S5 are as follows: S51. Query Vectorization: Use the bce-embedding-base_v1 model to convert user questions into query vectors q; S52. Similarity Calculation: In the vector database, the cosine similarity formula is used to calculate the similarity between q and all semantic vectors in the knowledge base. Based on the similarity, the top-N knowledge blocks are recalled according to the similarity, where N=10; The specific steps of S6 are as follows: S61, Cross-encoding: Concatenate the Query and Passage and input them into the bce-reranker-base_v1 model to capture the semantic interaction features between the Query and Passage; S62. Semantic Score: Based on the semantic interaction features of the Query and Passage, a semantic relevance score between the Query and Passage is calculated using a Transformer model. Then, the sigmoid function in torch is called to normalize the scores and then sort them; S63. Result Filtering: After reordering the scores, filter out the relevance scores. For segments with a score >0.6, low-quality segments are filtered out, and the Top-M highly relevant knowledge blocks are selected as the basis for answer generation, where M=5.
2. The system operation security dialogue method for large model fine-tuning and two-stage retrieval as described in claim 1, characterized in that, The specific steps of S1 are as follows: S11. Collect data in the field of complex system operation safety: The data includes professional literature, laws and regulations and standards, academic resources and industry knowledge bases. Professional literature includes books and authoritative works. Laws and regulations and standards include relevant laws and regulations, operating procedures and technical standards issued by the state and industry. Academic resources include papers and patents. Industry knowledge bases include examination question banks for practitioners and typical accident case databases. S12. Preprocess the data: Preprocessing includes data cleaning, data deduplication, and text formatting. Data cleaning includes removing redundancy and format standardization.
3. The system operation security dialogue method for large model fine-tuning and two-stage retrieval as described in claim 2, characterized in that, The specific steps of S2 are as follows: S21. Prompt word design: Templates are used to guide GPT-4 to extract questions from the preprocessed data in S1. One answer data corresponds to five questions. S22. Semantic consistency verification: By calculating the cosine similarity between the question and the answer, question-answer pairs with a similarity > 0.8 are filtered out. S23. Format Conversion: Convert the question and answer data into JSON format.
4. The system operation security dialogue method for large model fine-tuning and two-stage retrieval as described in claim 3, is characterized in that, The specific formula for cosine similarity in S22 is as follows: ; in, Q and A These are word vector representations of the question and the answer, respectively.
5. The system operation security dialogue method for large model fine-tuning and two-stage retrieval as described in claim 4, characterized in that, The cross-entropy loss function in S33 is as follows: ; in, T For sequence length, For adapter parameters, P For conditional probability distribution, This refers to the historical output elements in the sequence.
6. The system operation security dialogue method for large model fine-tuning and two-stage retrieval as described in claim 5, is characterized in that, The specific steps of S4 are as follows: S41. Knowledge Blocking: Divide long texts into blocks of 200 characters each, based on punctuation marks. S42. Vector Generation: Encode each knowledge block into a 768-dimensional semantic vector using the bce-embedding-base_v1 model. ; S43. Storage and Indexing: The vector storage of the llamaindex framework uses the Chroma database to store text vectors. It performs similarity searches on large-scale datasets through the core HNSW algorithm of the Chroma vector database.
7. The system operation security dialogue method for large model fine-tuning and two-stage retrieval as described in claim 6, characterized in that, The specific steps of S7 are as follows: S71, Context Fusion: Concatenates the selected M knowledge blocks with the user query to form a model input sequence; S72. Hint Project: Design hint templates to guide the generation of structured answers from the finely tuned base model.