A large language model training method based on context-aware triple instruction fine-tuning

CN123014166APending Publication Date: 2026-10-30苏州力升智能科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611121370.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-27
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

针对现有技术的不足,本发明提供了一种基于上下文感知三元组指令微调的大语言模型训练方法,具备生成高质量零噪声领域训练样本、实现双模态混合知识库的多跳逻辑检索、建立外部证据优先的推理机制以抑制事实性幻觉,以及实现专业知识注入与学术化风格双重对齐的优点,解决了现有技术中垂直领域训练样本构建成本高且噪声大、传统RAG检索上下文语义割裂且缺乏逻辑链条,以及大语言模型在微调过程中参数记忆与检索知识竞争冲突导致事实性幻觉频发的技术问题

Benefits of technology

1、本发明通过数据构建与知识库的双重创新,为垂直领域大模型微调提供了高质量、强逻辑的训练基础,一方面,通过利用大规模教师模型从领域原典中自动化蒸馏基准真值,并结合检索上下文进行语义融合重写,构建出“指令-检索上下文-输出”三元组微调数据集,有效解决了传统方法中人工标注成本高、覆盖不全及数据噪声大的问题,为模型提供一个高质量、零噪声的训练样本;另一方面,创新性地将向量语义检索与知识图谱多跳遍历相融合,构建高维语义向量索引与实体关系图谱的双模态混合知识库,在检索时不仅能召回语义相似的文本片段,还能通过图谱遍历获取包含多跳逻辑关系的完整子图上下文,从而大幅度提升本发明方法检索上下文的连贯性与推理支撑能力。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123014166A_ABST
    Figure CN123014166A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of artificial intelligence and natural language processing, and discloses a large language model training method based on context-aware triple instruction fine-tuning, which aims at the problem that a general large model is prone to fact hallucination in a vertical field and parameter knowledge and retrieval knowledge conflict with each other, and comprises the following training steps: first, performing multi-modal structured analysis on a field original; then, automatically distilling field benchmark true values by using a teacher large language model; a double-modal mixed knowledge base containing a vector index and an entity relationship graph is constructed; a triple fine-tuning sample of instruction, retrieval context and output format is synthesized by taking a question as an instruction to trigger retrieval; finally, a base model is fine-tuned in double alignment by using a parameter efficient fine-tuning technology, an external evidence priority reasoning mechanism is established by forcing the model, competition and conflict between parameter memory and retrieval knowledge are relieved, fact error rate is reduced, and academic language style alignment in a vertical field is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of artificial intelligence and natural language processing, specifically to a method for training large language models based on context-aware triple instruction fine-tuning. Background Technology

[0002] Large Language Models (LLMs) have demonstrated outstanding capabilities in general natural language processing tasks, but they still face many technical challenges in applications in vertical professional fields such as transportation, law, and healthcare.

[0003] First, vertical domains typically possess a large number of unstructured professional documents (such as textbooks, national standards, and industry norms). These documents have complex layouts, including multi-column tables, mathematical formulas, and hierarchical chapters, making them difficult for large language models to directly and efficiently understand and utilize. Second, traditional manual annotation methods for constructing domain-specific question-answering datasets are costly, incomplete, and struggle to guarantee consistency and accuracy in annotation. Third, existing Retrieval-Augmented Generation (RAG) techniques often employ fixed-length segmentation based on text vectors, which easily leads to semantic fragmentation of knowledge units and fails to capture multi-hop logical relationships between professional entities, resulting in a lack of coherence and reasoning support in the retrieval context. More critically, during fine-tuning, current large language models often experience competition and conflict between their internal parameter memory (parameter knowledge) and the context provided by external retrieval (retrieval knowledge). When a model over-relies on the general knowledge in its pre-trained parameters, it often ignores or contradicts the retrieved original professional norms, creating a "factual illusion" and generating seemingly coherent but incorrect answers that contradict the original domain text. Furthermore, the output style of general models is colloquial and redundant, making it difficult to meet the professional needs of vertical fields for academic, standardized, and concise language expression.

[0004] Therefore, how to construct a high-quality, strongly guided domain fine-tuning dataset and design a fine-tuning method that enables the model to establish an "external evidence-first" reasoning mechanism has become a technical problem that urgently needs to be solved in this field. Summary of the Invention

[0005] (a) Technical problems to be solved To address the shortcomings of existing technologies, this invention provides a large language model training method based on context-aware triple instruction fine-tuning. This method boasts advantages such as generating high-quality, zero-noise domain training samples, enabling multi-hop logical retrieval of a bimodal hybrid knowledge base, establishing an external evidence-priority reasoning mechanism to suppress factual illusions, and achieving dual alignment of professional knowledge injection and academic style. It solves the technical problems of existing technologies, including high cost and noise in constructing vertical domain training samples, fragmented contextual semantics and lack of logical chains in traditional RAG retrieval, and frequent occurrences of factual illusions due to conflicts between parameter memory and retrieval knowledge competition during the fine-tuning process of large language models.

[0006] (II) Technical Solution To achieve the above objectives, the present invention provides the following technical solution: a method for training a large language model based on context-aware triple instruction fine-tuning, comprising the following steps: S1. Multimodal document preprocessing: By calling the OCR engine and deep learning layout analysis model, based on the consistency of document structure logic, feature extraction is performed on the input unstructured text image, and the final output is a machine-readable standardized structured data object. S2. Automated distillation of baseline truth values: Combining prompt word engineering, the teacher's large language model is used to perform machine reading comprehension on the structured knowledge blocks obtained in step S1, automatically batch extracting independent and clear domain concept question-answer pairs, and generating absolutely correct answers that are faithful to the original documents as baseline truth values. S3. Enhanced Knowledge Base Construction for Domain Retrieval: The structured knowledge blocks obtained in step S1 are vectorized and graphed to construct a dual-modal hybrid knowledge base containing a high-dimensional semantic vector index and an entity relationship graph for context-aware retrieval. S4. Context-aware triplet fine-tuning sample synthesis: The questions in the question-answer pairs generated in step S2 are used as query instructions and retrieved in the bimodal hybrid knowledge base constructed in step S3. Relevant document fragments are retrieved as retrieval context. The teacher's large language model is guided to semantically fuse the retrieval context with the corresponding benchmark truth value to generate a rewritten output that must explicitly cite the retrieval context to deduce the answer, thus constructing a triplet fine-tuning dataset. S5. Domain Knowledge Injection and Dual Alignment Fine-tuning: Using the triplet fine-tuning dataset constructed in step S4, the base large language model is trained with parameter-efficient fine-tuning techniques to reshape the model's output distribution to achieve vertical domain academic language style alignment; at the same time, the attention weight of the model to the retrieval context in the input prompt words is adjusted through context enhancement to establish an external evidence-first reasoning mechanism.

[0007] Preferably, the unstructured documents in S1 specifically include subject textbooks, national standards, and industry norms documents in the vertical field.

[0008] Preferably, the specific tools for multimodal parsing in S1 include an OCR tool based on a visual parsing model and a layout analysis algorithm, which are used to perform lossless structured restoration of complex multi-column tables, mathematical formulas and hierarchical chapters in the document, and output them as structured knowledge blocks in JSON format.

[0009] Preferably, the automated distillation process of the benchmark truth value in S2 is as follows: using the teacher's large language model, by designing prompt word templates, professional concept question-and-answer pairs are extracted in batches from the structured data parsed in step S1.

[0010] Preferably, in step S3, the construction of the bimodal hybrid knowledge base specifically includes the following sub-steps: S3.1 Dynamic Semantic Block Processing: A dynamic segmentation strategy based on the semantic integrity of chapters or paragraphs is adopted, so that each segmentation block contains a knowledge unit; S3.2 Entity Relationship Extraction and Global Graph Construction: Deploy a localized information extraction model, design vertical domain-specific prompt words, guide the model to identify professional entities and logical relationships between entities from text blocks, adopt a bottom-up approach to transform text into structured subject, relation and object triples, and merge synonyms through an entity alignment mechanism to finally construct a unified entity relationship knowledge graph across the entire domain; S3.3 High-dimensional vector index construction: Using a dedicated semantic embedding model, the text slices and graph node descriptions are mapped into high-dimensional dense vectors using vectorization formulas, and a high-performance vector index is built based on the vector database; S3.4, Dual-channel hybrid indexing mechanism establishment: First, it integrates basic retrieval based on vector matching with advanced retrieval based on graph traversal. When a user query arrives, the system executes the basic vector retrieval: the user query command is... Mapped to a high-dimensional vector And compared with the high-dimensional vectors of all text blocks or graph nodes in the hybrid knowledge base. Calculate similarity Cosine similarity is used as the metric, and its calculation formula is as follows:

[0011] This formula can filter out entity nodes that are closest to the query semantics and obtain the subgraph context containing neighbor nodes and relationships.

[0012] Preferably, in step S3.3, a vectorization formula is used to map the text slices and graph node descriptions into high-dimensional dense vectors. The vectorization formula is as follows:

[0013] In the formula, Given the input text sequence, For semantic embedding models, This is the output high-dimensional dense vector.

[0014] Preferably, in step S4, the specific process of synthesizing context-aware triplet fine-tuning samples is as follows: S4.1 Retrieval process simulation: Using the question generated in step S2 as the query statement, the dual-channel hybrid index retrieval mechanism described in step S34 is automatically triggered to recall the target number of retrieval contexts containing graph structure information. S4.2 Semantic Fusion and Sample Synthesis: Guide the teacher's big language model to perform semantic fusion between the retrieved retrieval context and the baseline truth value established in step S2, and rewrite it through specific prompt words to generate new training samples; S4.3 Sample logical feature reshaping: Ensure that the synthesized sample format is a triple of instruction, retrieval context and output, wherein the output part is required to include explicit references and logical deductions to the retrieval context information.

[0015] Preferably, in step S5, the specific content of domain knowledge injection and dual alignment fine-tuning includes: S5.1 Reshaping the Model Output Distribution: A low-rank matrix is ​​injected into the attention layer and multilayer perceptron layer of the base large language model using a parameter-efficient fine-tuning technique. The calculation formula is as follows:

[0016] In the formula, The original pre-trained weight matrix of the base large language model, and The injected low-rank matrix is ​​used to transform domain-specific knowledge into weight updates. ; S5.2 Establish an external evidence-first reasoning mechanism: Through context-aware fine-tuning, strengthen the model's dependence on the retrieval context during the training phase, and design a hierarchical loss function to achieve evidence priority and style alignment.

[0017] Preferably, in S5.1, based on the low-rank injection mechanism, the large language model training method reshapes the model's output distribution in the following two aspects: (1) Knowledge injection: The model is fitted with professional concepts and logical links in the vertical field by fine-tuning the dataset through triples; (2) Style alignment: By optimizing the loss function, colloquial expressions and redundant formats are penalized.

[0018] Preferably, the reasoning mechanism that prioritizes external evidence in S5.2 is specifically divided into the following two sub-steps: (1) Evidence Dependency Constraint: After the embedding layer of the input data, the attention score of the retrieval context is scaled to make the model prioritize external knowledge. When the model's internal parameter memory conflicts with the external retrieval context, the model is forced to suppress internal illusions and prioritize generating answers based on external information. The basic total loss function is defined as follows:

[0019] In the formula, Generate loss for the standard. For evidence-dependent penalties, This is the penalty coefficient; (2) Style alignment extension: Based on the evidence dependency constraint, an additional style penalty term is designed. And add it to the total loss, at which point the total loss expands to:

[0020] in, ∈[0.2,0.5] represents the evidence dependency penalty coefficient. Style penalty item The weighting coefficients range from 0.1 to 0.3.

[0021] Compared with existing technologies, this invention provides a method for training large language models based on context-aware triple instruction fine-tuning, which has the following beneficial effects: 1. This invention provides a high-quality, logically robust training foundation for fine-tuning large-scale models in vertical domains through dual innovations in data construction and knowledge base. On the one hand, by utilizing a large-scale teacher model to automatically distill benchmark truth values ​​from domain classics and combining them with semantic fusion rewriting based on retrieval context, a fine-tuning dataset of "instruction-retrieval context-output" triples is constructed. This effectively solves the problems of high cost, incomplete coverage, and high data noise in traditional methods, providing the model with a high-quality, noise-free training sample. On the other hand, it innovatively integrates vector semantic retrieval with multi-hop traversal of knowledge graphs to construct a dual-modal hybrid knowledge base of high-dimensional semantic vector index and entity relationship graph. During retrieval, it can not only recall semantically similar text fragments but also obtain complete subgraph contexts containing multi-hop logical relationships through graph traversal, thereby significantly improving the coherence of retrieval context and reasoning support capability of the method of this invention.

[0022] 3. Based on efficient parameter fine-tuning, this invention designs a hierarchical loss function to achieve dual alignment between the "external evidence priority" reasoning mechanism and the academic language style. In LoRA fine-tuning, a hierarchical loss function containing evidence dependence penalty and style penalty is introduced. By strengthening the model's attention weight to the retrieval context and constraining its output logic, the model is forced to prioritize external evidence when parameter memory conflicts with external evidence. This fundamentally suppresses the "factual illusion" problem in vertical domain applications. Experimental results from embodiments show that models trained using this invention can reduce the factual error rate by more than 60%, and the style penalty effectively suppresses colloquial expressions and redundant formats in general models, making the fine-tuned model output concise, academic, and standardized, fully meeting the needs of professionals. Attached Figure Description

[0023] Figure 1 This is a diagram illustrating the execution steps of the method of the present invention; Figure 2 This is a flowchart illustrating the construction process of the dual-modal hybrid knowledge base of this invention. Figure 3 This is a diagram illustrating the process of synthesizing ternary fine-tuning samples in this invention. Detailed Implementation

[0024] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0025] Please see Figures 1-3 A method for training a large language model based on context-aware triple instruction fine-tuning includes the following steps: S1. Multimodal document preprocessing: The OCR engine and deep learning layout analysis model are called to extract features from the input unstructured text image. The key point of this step is to maintain the logical consistency of formulas, tables and table of contents in the document. The final output is a standardized structured data object that can be read by a machine. S2. Automated Distillation of Ground Truth: Combining prompt word engineering, the structured knowledge blocks obtained in step S1 are machine read-understanding using a larger teacher language model with a larger parameter scale. Independent and clear domain concept question-answer pairs are automatically extracted in batches to generate absolutely correct answers that are strictly faithful to the original documents, which serve as the ground truth. S3. Construction of Domain Retrieval Enhancement (RAG) Knowledge Base: The structured knowledge blocks obtained in step S1 are vectorized and graphed to construct a dual-modal hybrid knowledge base containing a high-dimensional semantic vector index and an entity relationship graph for subsequent context-aware retrieval. S4. Context-aware triplet fine-tuning sample synthesis: The questions in the question-answer pairs generated in step S2 are used as query instructions, and the relevant document fragments are retrieved in the bimodal hybrid knowledge base constructed in step S3 to retrieve the relevant document fragments as the retrieval context. The teacher's large language model is guided to semantically fuse the retrieval context with the corresponding benchmark truth value to generate a rewritten output that must explicitly cite the retrieval context to deduce the answer, thereby constructing a triplet fine-tuning dataset in the format of instruction, retrieval context and output. S5. Domain Knowledge Injection and Dual Alignment Fine-tuning: Using the triplet fine-tuning dataset constructed in step S4, the base large language model is trained with parameter-efficient fine-tuning techniques to reshape the model's output distribution to achieve alignment with academic language styles in the vertical domain. At the same time, the attention weight of the model to the retrieval context in the input prompt words is adjusted through context enhancement to establish an external evidence-first reasoning mechanism, thereby constructing a vertical domain large language model that alleviates the competition between parameter knowledge and retrieval knowledge.

[0026] Specifically, unstructured documents in S1 include subject textbooks, national standards, and industry specifications in vertical fields; the specific tools for multimodal parsing include OCR tools based on visual parsing models and layout analysis algorithms, which are used to maintain the logical consistency of complex multi-column tables, mathematical formulas, and hierarchical chapters in the documents, and output structured knowledge blocks in formats such as JSON. The above multimodal parsing steps ensure that the knowledge units processed subsequently have complete semantic structure and original accuracy, thereby providing a high-quality data foundation for benchmark truth distillation and knowledge base construction.

[0027] Specifically, in S2, the teacher's large language model is a general-purpose model with a large number of parameters that has strong reading comprehension capabilities, selected from the Qwen-72B or DeepSeek series models; the specific process of automated distillation of the benchmark truth is as follows: using the teacher's large language model, by designing prompt word templates (such as constraining the model not to mention the context, not to output explanatory content, and only to output question-answer pairs in JSON format), professional concept question-answer pairs are extracted in batches from the structured data parsed in step S1; This process defines the answers that the teacher model extracts directly from the original text as the absolutely correct baseline truth value, providing a zero-noise knowledge anchor for subsequent model training.

[0028] Specifically, in S3, the construction of a bimodal hybrid knowledge base includes the following sub-steps: S3.1 Dynamic Semantic Block Processing: A dynamic segmentation strategy based on the semantic integrity of chapters or paragraphs is adopted, so that each segmentation block contains a complete knowledge unit, avoiding the semantic fragmentation caused by traditional fixed-length segmentation, and providing a complete context window for subsequent entity extraction; S3.2 Entity Relationship Extraction and Global Graph Construction: Deploy localized information extraction models (such as Qwen2.5-14B-Instruct), design vertical domain-specific prompt words to guide the model to identify professional entities and logical relationships between entities (such as "determine", "constraint", "correction" etc.) from text blocks, adopt a bottom-up approach to transform text into structured subject, relation and object triples, and merge synonyms through entity alignment mechanism to finally construct a unified entity relationship knowledge graph across the entire domain; S3.3 High-dimensional vector index construction: Using a dedicated semantic embedding model (Embedding model, such as Qwen-Embedding), the text slices and graph node descriptions are mapped into high-dimensional dense vectors using vectorization formulas, and a high-performance vector index is built based on a vector database (such as Faiss). S3.4, Dual-channel hybrid indexing mechanism establishment: First, it integrates basic retrieval based on vector matching with advanced retrieval based on graph traversal. When a user query arrives, the system executes the basic vector retrieval: the user query command is... Mapped to a high-dimensional vector (the real-time vector of the user query). And compared with the high-dimensional vectors of all text blocks or graph nodes in the hybrid knowledge base. Calculate similarity Cosine similarity is used as the metric, and its calculation formula is as follows:

[0029] This formula can filter out several entity nodes that are most similar to the query semantics (usually the one with the highest similarity or the Top-K nodes); the system then enters the advanced retrieval stage: starting from these entity nodes, it performs N hops (e.g., 1 to 2 hops) of topological traversal in the knowledge graph to obtain the subgraph context containing neighbor nodes and relationships. In this way, the retrieval results not only contain directly matched entities, but also come with a complete logical chain, thereby greatly improving the coherence of the context and the reasoning ability.

[0030] Specifically, in S3.3, a vectorization formula is used to map text slices and graph node descriptions into high-dimensional dense vectors. The vectorization formula is as follows:

[0031] In the formula, The input is a sequence of text, such as a structured knowledge block or a graph node description. For semantic embedding models, such as Qwen-Embedding, The output is a high-dimensional dense vector, which is the static vector of each text block / node in the knowledge base. In this method, it is a 4096-dimensional semantic vector.

[0032] Through the above vectorization and similarity calculation, the system can efficiently recall the entity nodes most relevant to the user's question semantics from a massive knowledge base, providing an accurate retrieval starting point for subsequent multi-hop graph traversal.

[0033] Specifically, in S4, the process of synthesizing context-aware triplet fine-tuning samples is as follows: S4.1 Simulation of the retrieval process: Using the question generated in step S2 as the query statement, the dual-channel hybrid index retrieval mechanism in step S34 is automatically triggered to recall the target number (Top-k) of retrieval contexts containing graph structure information. S4.2 Semantic Fusion and Sample Synthesis: Guide the teacher's large language model (such as Qwen-72B) to perform semantic fusion with the retrieved retrieval context and the baseline truth value established in step S2, and rewrite it through specific prompt words (requiring the model to generate concise and direct answers based on reference materials) to generate new training samples; S4.3 Sample Logical Feature Reshaping: Ensure that the synthesized sample format is a triple of Instruction, Input, and Output. The output must contain explicit references and logical deductions to the retrieval context information, rather than simple factual statements.

[0034] Through the above sample synthesis process, the constructed triplet fine-tuning dataset teaches the model how to read and utilize retrieval results at the underlying logic level, enabling the model to establish a behavioral pattern of "generating answers based on external evidence" during the training phase.

[0035] Specifically, in S5, the details of domain knowledge injection and dual alignment fine-tuning include: S5.1 Reshaping the Model Output Distribution: Low-rank matrix injection is performed on the attention layer and multilayer perceptron layer of the base large language model using a parameter-efficient fine-tuning technique (such as LoRA). The calculation formula is as follows:

[0036] In the formula, The original pre-trained weight matrix of the base large language model (frozen during fine-tuning) and The injected low-rank matrix is ​​used to transform domain-specific knowledge into weight updates. ; Based on the low-rank injection mechanism, the large language model training method reshapes the model's output distribution in the following two aspects: (1) Knowledge injection: The model is fitted with professional concepts and logical links in the vertical field by fine-tuning the dataset through triples, so as to realize the parameterization and internalization of professional knowledge; (2) Style alignment: By optimizing the loss function, colloquial expressions and redundant formats are penalized, so that the fine-tuned model outputs concise, academic and standardized language; Through the aforementioned low-rank matrix injection and dual optimization, the model achieves both the internalization and absorption of professional knowledge and the academic alignment of language style while maintaining efficient parameter updates.

[0037] S5.2 Establishing an external evidence-first reasoning mechanism: Through context-aware fine-tuning, the model's dependence on the retrieval context is strengthened during the training phase, and a hierarchical loss function is designed to achieve evidence priority and style alignment. This is specifically divided into the following two sub-steps: (1) Evidence Dependency Constraint (Base Loss): After the embedding layer of the input data, the attention score of the retrieval context is scaled (the scaling factor is set to 1.2 to 1.8 times) to make the model prioritize external knowledge. When the model's internal parameter memory conflicts with the external retrieval context, the model is forced to suppress internal illusions and prioritize generating answers based on external information. For this purpose, the base total loss function is defined as follows:

[0038] In the formula, Generate a standard loss (such as cross-entropy loss). For evidence-dependent penalties, The penalty coefficient, ranging from 0.2 to 0.5, is applied when the generated output token sequence logically conflicts with the retrieval context or lacks a reference. This increases the complexity of the model, forcing its output to strictly adhere to the injected expertise. (2) Style alignment extension (extended loss): Based on the evidence dependency constraint, in order to further standardize the language style of the model output (such as penalizing colloquial expressions and redundant formats, and encouraging academic and structured expressions), an additional style penalty term is designed. And add it to the total loss, at which point the total loss expands to:

[0039] in, ∈[0.2,0.5] represents the evidence dependency penalty coefficient. Style penalty item The weighting coefficients are used to control the strength of language style alignment in the model output. They are set according to the style constraint strength (ranging from 0.1 to 0.3), and are achieved through joint optimization. Ensure that the generated content is consistent with the retrieved knowledge logic. Standardized language expression, together with other methods, achieves a professional and standardized question-and-answer effect, thereby mitigating the evidence-dependent penalty in the knowledge-injection section. Collaboration allows us to provide professional and standardized answers. Through the above sub-steps, the final vertical domain large language model fundamentally solves the problem that traditional models ignore retrieval evidence and generate factual illusions in professional applications, and can provide professionals with highly faithful and accurate intelligent services.

[0040] The large language model for vertical domains trained using the method of this invention can reduce the factual error rate in domain question answering tasks by more than 60%. Furthermore, through style alignment optimization, the model output is simplified, more academic, and standardized, fully meeting the needs of professionals in vertical domains such as transportation engineering.

[0041] The following examples illustrate in detail how to use the method described in this invention to construct a high-quality fine-tuning dataset for the transportation domain and complete the entire process of fine-tuning the base model.

[0042] Example (Construction of a Large Language Model in the Field of Traffic Engineering and Control) S1. Multimodal Document Preprocessing: Classic textbooks and national / industry standards in the field of traffic engineering and management are used as source texts for unsupervised learning. Specific documents include textbooks such as "Traffic Engineering", "Traffic Control", and "Traffic Safety", as well as authoritative standard documents such as "Urban Comprehensive Transportation System Planning Standard", "Urban Road Traffic Organization Design Specification", "Road Traffic Safety Law", "Road Traffic Signs and Markings" (Parts 1 to 4), and "Road Traffic Signal Light Setting and Installation Specification". Since most of the above documents are unstructured PDFs with complex layouts, this embodiment uses the DeepSeek-OCR model as a multimodal visual analysis tool to perform layout analysis and high-precision optical character recognition on the documents, and losslessly convert complex multi-column tables and mathematical formulas into structured knowledge blocks in JSON format while maintaining the logical consistency of the content. S2. Automated Distillation of Benchmark Truth: Deploy a large language model with 72 parameters (such as Qwen-72B) as the teacher model. For the structured document fragments parsed from S1, automatically extract independent and clear traffic-related professional concept question-and-answer pairs in batches by constructing specific prompt word templates. The prompt word construction program input into the teacher model is as follows: You are a traffic Q&A assistant, answering questions related to transportation. Please generate traffic knowledge Q&A pairs based on the document I provide, and output a strict JSON list. Each Q&A should be in the following format: (1) Only extract knowledge points such as concepts, methods, principles, and rules; (2) Do not mention book chapters, page numbers, historical years, or contexts such as "above," "Chapter Two," or "mentioned in the text"; (3) The problem should be an independent and clearly defined transportation-related problem; (4) Answers should be concise, accurate, and complete; (5) Formulas are allowed, but the original format must be retained (e.g., $...$); (6) [Chapter] {chapter_title}; (7) [Section] {section_title}; (8) Document content: {chapter_text}; (9) Please output a JSON list only, without any explanation or additional content.

[0043] Through the above instructions, the teacher's large model outputs an absolutely correct answer that is strictly faithful to the original traffic text, which is defined as the "ground truth".

[0044] S3. Construction of a dual-modal hybrid knowledge base based on the LightRAG architecture: To overcome the fragmentation problem of traditional RAG text slicing, this embodiment introduces the LightRAG architecture to construct a professional knowledge base. Specifically, after dynamically dividing the structured knowledge blocks output by S1, a fine-tuning model with a parameter scale of 14B (such as Qwen2.5-14B-Instruct) is deployed as an entity extraction model to automatically extract professional entities and their logical relationships in traffic text and construct a global knowledge graph. Then, a dedicated semantic vector model (such as the Qwen-Embedding model) is used to map the segmented text and graph nodes into high-dimensional dense vectors, and finally a dual-channel hybrid retrieval mechanism that integrates vector semantic retrieval and graph multi-hop reasoning is established.

[0045] S4. Context-Aware Triple Fine-Tuning Sample Synthesis: Using the "question" generated in S2 as the query command, the LightRAG dual-channel retrieval in S3 is triggered to recall relevant textbooks or standard texts as the "retrieval context". The teacher's large model (Qwen-72B) is then guided to semantically fuse and rewrite the retrieval context with the baseline truth value. The prompt words in the fusion and rewriting stage are designed as follows: (1) You are a data synthesis expert. Based on the [References] and [Original Answer], please generate a short and direct answer to a [User Question], [User Question]: {question}, {context_text}; [Original Answer]: {original_answer}; (2) [Requirements]: The style must be extremely concise, direct, and free of unnecessary words; the content must be based on the [References], and if the references are insufficient, refer to the [Original Answer]; the format must be plain text, without Markdown headings; the thought process is not allowed, please output the final answer directly.

[0046] After the above automated distillation and retrieval fusion process, a fine-tuning dataset with strong context-dependent "Instruction-Context-Output" triples is finally generated. An example of the structure of some real data samples in this dataset is shown below: [{“instruction”:“What objects’ traffic characteristics are primarily studied by traffic characteristic analysis technology?”; "input": "

References

[0047] In summary, the method of this invention addresses the problems of factual illusions and conflicts between parametric knowledge and retrieval knowledge that arise in general large models within vertical domains. It includes the following training steps: first, multimodal structured parsing of domain source texts; second, automated distillation of domain benchmark truth values ​​using a teacher's large language model; third, construction of a bimodal hybrid knowledge base containing vector indexes and entity relationship graphs; fourth, triggering retrieval with questions as instructions, synthesizing triplet fine-tuning samples of instructions, retrieval context, and output format; and finally, employing efficient parameter fine-tuning techniques to perform dual alignment fine-tuning of the base model. By forcing the model to establish a reasoning mechanism prioritizing external evidence, the competitive conflict between parametric memory and retrieval knowledge is alleviated, thereby reducing the factual error rate and simultaneously achieving alignment with the academic language style of the vertical domain.

[0048] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.

Claims

1. A method for training a large language model based on context-aware triple instruction fine-tuning, characterized in that, Includes the following steps: S1. Multimodal document preprocessing: By calling the OCR engine and deep learning layout analysis model, based on the consistency of document structure logic, feature extraction is performed on the input unstructured text image, and the final output is a machine-readable standardized structured data object. S2. Automated distillation of baseline truth values: Combining prompt word engineering, the teacher's large language model is used to perform machine reading comprehension on the structured knowledge blocks obtained in step S1, automatically batch extracting independent and clear domain concept question-answer pairs, and generating absolutely correct answers that are faithful to the original documents as baseline truth values. S3. Enhanced Knowledge Base Construction for Domain Retrieval: The structured knowledge blocks obtained in step S1 are vectorized and graphed to construct a dual-modal hybrid knowledge base containing a high-dimensional semantic vector index and an entity relationship graph for context-aware retrieval. S4. Context-aware triplet fine-tuning sample synthesis: The questions in the question-answer pairs generated in step S2 are used as query instructions and retrieved in the bimodal hybrid knowledge base constructed in step S3. Relevant document fragments are retrieved as retrieval context. The teacher's big language model is guided to semantically fuse the retrieval context with the corresponding benchmark truth value to generate a rewritten output that must explicitly cite the retrieval context to deduce the answer, thus constructing a triplet fine-tuning dataset. S5. Domain Knowledge Injection and Dual Alignment Fine-tuning: Using the triplet fine-tuning dataset constructed in step S4, the base large language model is trained with parameter-efficient fine-tuning techniques to reshape the model's output distribution to achieve vertical domain academic language style alignment; at the same time, the attention weight of the model to the retrieval context in the input prompt words is adjusted through context enhancement to establish an external evidence-first reasoning mechanism.

2. The method for training a large language model based on context-aware triple instruction fine-tuning according to claim 1, characterized in that, The unstructured documents in S1 specifically include subject textbooks, national standards, and industry norms documents in vertical fields.

3. The method for training a large language model based on context-aware triple instruction fine-tuning according to claim 1, characterized in that, The specific tools for multimodal parsing in S1 include an OCR tool based on a visual parsing model and a layout analysis algorithm, which are used to perform lossless structured restoration of complex multi-column tables, mathematical formulas and hierarchical chapters in the document, and output them as structured knowledge blocks in JSON format.

4. The method for training a large language model based on context-aware triple instruction fine-tuning according to claim 1, characterized in that, The specific process of automated distillation of the benchmark truth value in S2 is as follows: using the teacher's large language model, by designing prompt word templates, professional concept question-and-answer pairs are extracted in batches from the structured data parsed in step S1.

5. The method for training a large language model based on context-aware triple instruction fine-tuning according to claim 1, characterized in that, In step S3, the construction of the bimodal hybrid knowledge base specifically includes the following sub-steps: S3.1 Dynamic Semantic Block Processing: A dynamic segmentation strategy based on the semantic integrity of chapters or paragraphs is adopted, so that each segmentation block contains a knowledge unit; S3.2 Entity Relationship Extraction and Global Graph Construction: Deploy a localized information extraction model, design vertical domain-specific prompt words, guide the model to identify professional entities and logical relationships between entities from text blocks, adopt a bottom-up approach to transform text into structured subject, relation and object triples, and merge synonyms through an entity alignment mechanism to finally construct a unified entity relationship knowledge graph across the entire domain; S3.3 High-dimensional vector index construction: Using a dedicated semantic embedding model, the text slices and graph node descriptions are mapped into high-dimensional dense vectors using vectorization formulas, and a high-performance vector index is built based on the vector database; S3.4, Dual-channel hybrid indexing mechanism establishment: First, it integrates basic retrieval based on vector matching with advanced retrieval based on graph traversal. When a user query arrives, the system executes the basic vector retrieval: the user query command is... Mapped to a high-dimensional vector And compared with the high-dimensional vectors of all text blocks or graph nodes in the hybrid knowledge base. Calculate similarity Cosine similarity is used as the metric, and its calculation formula is as follows: This formula can filter out entity nodes that are closest to the query semantics and obtain the subgraph context containing neighbor nodes and relationships.

6. The method for training a large language model based on context-aware triple instruction fine-tuning according to claim 1, characterized in that, In step S3.3, a vectorization formula is used to map text slices and graph node descriptions into high-dimensional dense vectors. The vectorization formula is as follows: In the formula, Given the input text sequence, For semantic embedding models, This is the output high-dimensional dense vector.

7. The method for training a large language model based on context-aware triple instruction fine-tuning according to claim 1, characterized in that, In S4, the specific process of synthesizing context-aware triplet fine-tuning samples is as follows: S4.1 Retrieval process simulation: Using the question generated in step S2 as the query statement, the dual-channel hybrid index retrieval mechanism described in step S34 is automatically triggered to recall the target number of retrieval contexts containing graph structure information. S4.2 Semantic Fusion and Sample Synthesis: Guide the teacher's big language model to perform semantic fusion between the retrieved retrieval context and the baseline truth value established in step S2, and rewrite it through specific prompt words to generate new training samples; S4.3 Sample logical feature reshaping: Ensure that the synthesized sample format is a triple of instruction, retrieval context and output, wherein the output part is required to include explicit references and logical deductions to the retrieval context information.

8. The method for training a large language model based on context-aware triple instruction fine-tuning according to claim 1, characterized in that, In S5, the specific content of domain knowledge injection and dual alignment fine-tuning includes: S5.1 Reshaping the Model Output Distribution: A low-rank matrix is ​​injected into the attention layer and multilayer perceptron layer of the base large language model using a parameter-efficient fine-tuning technique. The calculation formula is as follows: In the formula, The original pre-trained weight matrix of the base large language model, and The injected low-rank matrix is ​​used to transform domain-specific knowledge into weight updates. ; S5.2 Establish an external evidence-first reasoning mechanism: Through context-aware fine-tuning, strengthen the model's dependence on the retrieval context during the training phase, and design a hierarchical loss function to achieve evidence priority and style alignment.

9. A method for training a large language model based on context-aware triple instruction fine-tuning according to claim 8, characterized in that, Based on the low-rank injection mechanism, the large language model training method in S5.1 reshapes the model's output distribution in the following two aspects: (1) Knowledge injection: The model is fitted with professional concepts and logical links in the vertical field by fine-tuning the dataset through triples; (2) Style alignment: By optimizing the loss function, colloquial expressions and redundant formats are penalized.

10. A method for training a large language model based on context-aware triple instruction fine-tuning according to claim 8, characterized in that, The reasoning mechanism that prioritizes external evidence, as described in S5.2, is specifically divided into the following two sub-steps: (1) Evidence Dependency Constraint: After the embedding layer of the input data, the attention score of the retrieval context is scaled to make the model prioritize external knowledge. When the model's internal parameter memory conflicts with the external retrieval context, the model is forced to suppress internal illusions and prioritize generating answers based on external information. The basic total loss function is defined as follows: In the formula, Generate loss for the standard. For evidence-dependent penalties, This is the penalty coefficient; (2) Style alignment extension: Based on the evidence dependency constraint, an additional style penalty term is designed. And add it to the total loss, at which point the total loss expands to: in, ∈[0.2,0.5] represents the evidence dependency penalty coefficient. Style penalty item The weighting coefficients range from 0.1 to 0.3.