Domain knowledge based large language model optimization method and device and storage medium

CN122735807APending Publication Date: 2026-09-11RESEARCH INSTITUTE OF ADVANCED MATERIALS (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611044085.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-14
Publication Date
2026-09-11

AI Technical Summary

Technical Problem

[0005]有鉴于此,本发明的目的在于提供基于领域知识的大语言模型优化方法、装置及存储介质,旨在解决现有的大语言模型在专业领域微调中泛化能力不足、数据质量低、知识碎片化、代码生成可解释性差、微调资源消耗高的问题

Benefits of technology

本申请通过基座-领域大模型的协同演进框架和多任务训练方式,打破单一任务微调的局限,实现模型在领域内多任务的知识迁移,解决了知识碎片化问题;通过构建场景化代码-描述对数据集,将材料科学中的业务逻辑转化为可执行代码与自然语言描述的对应关系,使模型直接内化领域算法逻辑,显著提升代码生成与调试任务的准确性;针对非结构化数据采用定制化的清洗流水线,通过大语言模型的语义级理解与关联分析实现核心知识的高效提取;采用思维链增强的双轨并行方案构建代码 - 场景映射数据集,将专家的推理过程注入数据中,引导模型理解领域的物理原理与代码逻辑,使模型从 “机械代码生成器” 升维为具备领域思维的专业智能体;采用 LoRA 低秩适配的参数优化范式,仅训练原始模型少量的增量参数,大幅降低显存占用和计算开销,同时避免灾难性遗忘,适用于资源受限场景下的领域微调。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122735807A_ABST
    Figure CN122735807A_ABST
Patent Text Reader

Abstract

This invention relates to a method, apparatus, and storage medium for optimizing large language models based on domain knowledge, and is applied in the fields of artificial intelligence and large language model technology. The invention includes: constructing a scenario-based code-description pair dataset to transform business logic in materials science into a correspondence between executable code and natural language descriptions; constructing a code-scenario mapping dataset using a dual-track parallel scheme enhanced by thought chain analysis; employing a customized cleaning pipeline for unstructured data; and achieving efficient extraction of core knowledge through semantic-level understanding and association analysis of the large language model; injecting expert reasoning processes into the data to guide the model in understanding the physical principles and code logic of the domain, thus elevating the model from a "mechanical code generator" to a professional intelligent agent with domain-specific thinking; and adopting a LoRA low-rank adaptation parameter optimization paradigm to train only a small number of incremental parameters on the original model, significantly reducing memory usage and computational overhead.
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 large language model technology, specifically to a method, apparatus, and storage medium for optimizing large language models based on domain knowledge. Background Technology

[0002] Large language models (LLMs) demonstrate excellent capabilities in general natural language processing tasks, but for applications in specialized fields such as materials science, fine-tuning is required to achieve domain adaptation. Current fine-tuning methods for large language models mostly employ single-task-oriented strategies, which have the following main drawbacks:

[0003] The model's generalization ability is severely insufficient: the single-task learning mode only optimizes the model for specific domain tasks, which makes it impossible for the model to transfer the learning results to other related tasks. It is prone to generating erroneous responses when faced with changes in task form or expansion of knowledge scope. The data processing has a fundamental flaw: it only uses general cleaning rules for multi-source heterogeneous data in the domain, without customizing the processing for professional terms and structured features, resulting in incomplete, inaccurate, and poorly correlated data, and incomplete knowledge coverage of the model. Multi-source heterogeneous data cannot be uniformly encoded: There is a lack of effective encoding mechanisms to map domain data from different sources to a unified semantic framework, resulting in severe knowledge fragmentation and high uncertainty when the model processes complex domain queries; Low efficiency and quality of data cleaning: Original domain documents (software manuals, journal articles) have problems such as complex format, semantic fragmentation, and high noise. Traditional rule-based template cleaning cannot achieve efficient extraction of core knowledge. Poor generalization and interpretability of code generation: Traditional "problem-code" data pairs only achieve surface pattern matching. The model cannot internalize the physical principles and code logic of the domain, and its code generation ability deteriorates sharply when facing new scenarios outside the training set. Fine-tuning consumes a lot of resources: The full-parameter fine-tuning method has a large memory footprint and high computational cost, and is prone to catastrophic forgetting problems, making it unsuitable for domain adaptation in resource-constrained scenarios.

[0004] The aforementioned deficiencies result in insufficient accuracy, reliability, and scalability of existing optimized large language models in specialized fields, failing to meet the intelligent R&D needs of fields such as materials science. Summary of the Invention

[0005] In view of this, the purpose of this invention is to provide a method, apparatus and storage medium for optimizing large language models based on domain knowledge, aiming to solve the problems of insufficient generalization ability, low data quality, knowledge fragmentation, poor interpretability of code generation and high resource consumption in fine-tuning of existing large language models in professional domains.

[0006] According to a first aspect of the present invention, a method for optimizing a large language model based on domain knowledge is provided, the method comprising: Generate code-description pairs for specific scenarios within the target professional field; The code-description pair for the specific scenario is enhanced using a standard mind chain, and a first training dataset is constructed based on the standard mind chain and the enhanced code-description pair. The pre-built LLM large language model is trained using the first training dataset to obtain the trained LLM large language model. Acquire multi-source heterogeneous data within the target professional field, including structured data and unstructured data, wherein the structured data consists of expert question-and-answer pairs; The unstructured data is subjected to pre-defined automated processing, and structured question-answer pairs are generated through the trained LLM large language model. A second training dataset is constructed based on the structured question-answer pairs and expert question-answer pairs. The low-rank adaptation LoRA method is used to train the target base large model using the second training set to obtain the target domain large language model.

[0007] Preferably, The unstructured data includes: professional software manuals and academic journal articles; The process of performing pre-defined automated processing on the professional software manual and generating structured question-answer pairs using the trained LLM large language model includes: Extract all text information from professional software manuals in PDF format and perform preliminary separation by page number; The system uses regular expressions to accurately identify and remove redundant page markers and isolated page number lines generated during the text information extraction process; it extracts code blocks from the text information and uses Markdown syntax for standardized encapsulation. During the standardized encapsulation process, while compressing consecutive whitespace characters, it preserves the paragraph's logical structure through a blank line control algorithm. The continuous text stream is restored to the original page unit by regular expressions, and key metadata is retained to obtain a standardized data package. The key metadata includes: original page number location, cleaned and standardized content, and word count based on space segmentation algorithm. The standardized data packet is input into a pre-trained LLM large language model, which generates structured question-answer pairs through a standardization process.

[0008] Preferably, The pre-trained LLM large language model generates structured question-answer pairs through a standardization process, including: Before the standardized data packets are input into the pre-trained LLM large language model, the standardized data packets are automatically identified and formatted using regular expressions and Markdown format is applied to achieve formatting processing. The pre-trained LLM large language model selects core technical content according to preset instructions; The pre-trained LLM large language model retrieves adjacent pages of the core technical content according to preset instructions, and obtains the relevant context of the core technical content from the adjacent pages; The pre-trained LLM large language model will select and supplement the core technical content with context, and under the guidance of preset instructions, generate technical questions and answers from different cognitive levels around the syntax, function usage, parameter role and underlying principle of the phase diagram calculation software code, and parse the output technical questions and answers into structured JSON format question and answer pairs.

[0009] Preferably, The pre-defined automated processing of the academic journal articles includes: Construct a terminology database and associate different expressions of the same term in the database; The terminology database also includes a new term capture mechanism, which includes: The text describes how to capture material science-specific word formation patterns in academic journal articles using pre-defined regular expressions, and how to filter out common vocabulary interference by setting length filtering conditions to obtain target terms. Deep semantic screening is implemented based on the SciBERT model. When the cosine similarity between the target term and an existing term in the terminology database is lower than a preset threshold, the target term is added to the terminology database. The dynamic updating of the terminology base enables the injection of external knowledge into the pre-trained LLM large language model, driving the pre-trained LLM large language model to generate more standardized question-answer pairs.

[0010] Preferably, The code-description pairs generated for specific scenarios within the target professional field include: Define a scenario within a target professional field, set up multi-dimensional natural language user input for the scenario, generate an executable code script for the scenario, set structured system prompts for the scenario and the executable code script, and obtain code-description pairs.

[0011] Preferably, The structured system prompts include: Define the functional roles and specific operation steps of the LLM large model; And define the output format of the LLM large model, as well as the rules to be followed during the output generation process; A standard input-output learning template is embedded in the structured system prompts to guide the LLM large model in generating code-description pairs.

[0012] Preferably, The code-description pair for the specific scenario is used to enhance the thought chain through a standard thought chain. Constructing the first training dataset based on the standard thought chain and the enhanced code-description pair includes: Standard thought chains are generated in advance for classic questions in the target professional field. The original questions in the code-description pairs are classified and categorized by the second major language model. Then, the original questions in the code-description pairs are guided by the standard thought chains of the corresponding types through Few-shot to generate the initial thought chains of the original questions. The initial thought chains are iteratively updated by the human-computer collaborative verification loop to obtain the enhanced code-description pairs. The first training dataset is constructed based on the standard thought chains and the enhanced code-description pairs.

[0013] According to a second aspect of the present invention, a large language model optimization apparatus based on domain knowledge is provided, the apparatus comprising: Description pair generation module: Used to generate code-description pairs for specific scenarios in the target professional field; The thought enhancement module is used to enhance the thought chain of the code-description pair for the specific scenario through the standard thought chain, and to construct the first training dataset based on the standard thought chain and the thought chain enhancement code-description pair. LLM Large Language Model Training Module: Used to train the pre-built LLM large language model using the first training dataset to obtain the trained LLM large language model; Multi-source heterogeneous data acquisition module: used to acquire multi-source heterogeneous data within the target professional field, the multi-source heterogeneous data including structured data and unstructured data, the structured data being expert question-and-answer pairs; Question-answer pair generation module: used to perform preset automated processing on the unstructured data, and generate structured question-answer pairs through the trained LLM large language model, and construct a second training dataset based on the structured question-answer pairs and expert question-answer pairs; Base large model training module: Used to train the target base large model using the low-rank adaptation LoRA method, through the second training set, to obtain the target domain large language model.

[0014] According to a third aspect of the present invention, a storage medium is provided, the storage medium storing a computer program, which, when executed by a host controller, implements the steps of the above-described method.

[0015] The technical solutions provided by the embodiments of the present invention may include the following beneficial effects: This application overcomes the limitations of single-task fine-tuning by employing a co-evolution framework of a base-domain large model and a multi-task training method, enabling knowledge transfer across multiple tasks within the domain and addressing the problem of knowledge fragmentation. By constructing a scenario-based code-description pair dataset, it transforms business logic in materials science into a correspondence between executable code and natural language descriptions, allowing the model to directly internalize domain algorithm logic and significantly improving the accuracy of code generation and debugging tasks. For unstructured data, a customized cleaning pipeline is used, achieving efficient extraction of core knowledge through semantic-level understanding and association analysis of the large language model. A dual-track parallel scheme with enhanced thinking chains is employed to construct a code-scenario mapping dataset, injecting expert reasoning processes into the data to guide the model in understanding the physical principles and code logic of the domain, elevating the model from a "mechanical code generator" to a professional intelligent agent with domain-specific thinking. The LoRA low-rank adaptation parameter optimization paradigm trains only a small number of incremental parameters on the original model, significantly reducing memory usage and computational overhead while avoiding catastrophic forgetting, making it suitable for domain fine-tuning in resource-constrained scenarios.

[0016] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit the invention. Attached Figure Description

[0017] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0018] Figure 1 This is a flowchart illustrating a domain knowledge-based large language model optimization method according to an exemplary embodiment; Figure 2 This is a system schematic diagram of a domain-knowledge-based large language model optimization apparatus according to another exemplary embodiment; In the attached diagram: 1- Description pair generation module, 2- Thinking enhancement module, 3- LLM large language model training module, 4- Multi-source heterogeneous data acquisition module, 5- Question answer pair generation module, 6- Base large model training module. Detailed Implementation

[0019] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Rather, they are merely examples of apparatuses and methods consistent with some aspects of the invention as detailed in the appended claims.

[0020] Example 1 Figure 1 This is a flowchart illustrating a domain knowledge-based large language model optimization method according to an exemplary embodiment, such as... Figure 1 As shown, the method includes: S1 generates code-description pairs for specific scenarios within the target professional field; S2, enhance the code-description pair of the specific scenario through the standard thinking chain, and construct the first training dataset based on the standard thinking chain and the enhanced code-description pair; S3, train the pre-built LLM large language model using the first training dataset to obtain the trained LLM large language model; S4, acquire multi-source heterogeneous data within the target professional field, the multi-source heterogeneous data including structured data and unstructured data, the structured data being expert question-and-answer pairs; S5, perform preset automated processing on the unstructured data, and generate structured question-answer pairs through the trained LLM large language model, and construct a second training dataset based on the structured question-answer pairs and expert question-answer pairs; S6. The low-rank adaptation LoRA method is used to train the target base large model through the second training set to obtain the target domain large language model. Understandably, to significantly enhance the capabilities of Large Language Models (LLMs) in key downstream tasks such as computational code generation in materials science, enabling them to accurately adapt to the complex professional needs of materials simulation, computation, and design, and laying a solid foundation for the subsequent development of intelligent agents with autonomous coding capabilities, this embodiment specifically constructs a high-quality, scenario-based code generation fine-tuning dataset, which includes: Scenario-Based Code-Description Pair Construction: Employing a proven text-to-code paradigm, this construction focuses on high-frequency, core physics simulation scenarios in the field of materials computation (such as materials binding energy calculation, structural relaxation, and molecular dynamics simulation). Chain-of-Thought Code Generation: Introduces a step-by-step reasoning mechanism to guide the model to understand the logical chain of complex tasks and generate more robust and interpretable code; Scenario-based code-description pair construction: Scenario Focus and Definition: Prioritize high-frequency, critical, and clearly defined physical simulation scenarios in materials calculations (e.g., "calculating the binding energy of two elements under a specific lattice structure"). Clearly define the scenario's computational objectives, input parameters, and expected outputs.

[0021] Natural Language Description Construction: For each selected scenario, diverse natural language user queries are carefully designed. These queries clearly and unambiguously describe the computational objective and cover typical parameter combinations (such as specifying material composition / chemical formula, crystal structure type, lattice constant, computational accuracy, boundary conditions, functionals used, etc.).

[0022] Executable script writing: Based on the above description and the business logic and API specifications of the specific material calculation software (such as VASP, LAMMPS, Quantum ESPRESSO, etc.), accurately write the corresponding, fully functional and executable input script code.

[0023] Structured System Prompt Design: A highly structured System Prompt is built around the scenario and its target code. This Prompt serves as the model's "task instruction manual." It is clearly stipulated that: Role definition: The role played by the model (e.g., "materials calculation code generation assistant"); Core task requirements: Specific operations that the model needs to perform (such as "generating input scripts for specific material calculation software based on user queries"). Output format specifications: Code format requirements (such as language, indentation, and placement of key instructions); Key constraints and specifications: Rules that must be followed (such as using specific software versions, required input file blocks, parameter units, and avoiding the use of outdated instructions, etc.). 1-Shot Example Embedding: A complete, well-designed (user query example, target code example) pair is embedded within the System Prompt. This example visually illustrates the expected input-output mapping, providing the model with an explicit learning template to guide its understanding of task requirements and code structure. Preliminary optimization and verification: Use the initially constructed samples to fine-tune and test the model to ensure that the model can accurately understand the user's description of the target scenario based on the designed System Prompt and generate code that conforms to the specifications and functions correctly.

[0024] This process generates scenario-based code-description pairs that meet the criteria. Enhance code-description pairs using thought chains: Traditional problem-code data pairs have a fundamental flaw: this paradigm simplifies code generation to superficial pattern matching, causing the model to mechanically memorize input-output mapping relationships, but fails to internalize the two core knowledge systems of materials computation. Physical principles (such as the role of energy minimization criteria in structural optimization, and the correlation mechanism between electron density functional theory and material properties). Code logic layer (such as the dependency relationship between potential function parameters and calculation commands in LAMMPS, and the physical parameter constraint chain of VASP input files); This cognitive gap directly leads to a sharp decline in the model's generalization ability when faced with new scenarios outside the training set (such as thermodynamic simulation of novel two-dimensional materials), manifesting as parameter mismatch, physical logic contradictions, or missing key computational steps.

[0025] To overcome this limitation, this embodiment introduces an expert-level chain of thought as a cognitive scaffold in the fine-tuning data construction. Its core is to inject expert reasoning processes into the data, guiding the model not only to know "what" ("what code to generate"), but also "why" ("why the code is designed this way"). This method aims to elevate the model from a simple "code generator" to a "computational materials scientist." Through explicit modeling of expert problem-solving paths, this application can systematically improve the model's core capabilities in task decomposition (how to transform physical problems into computational steps), parameter decision-making (why choose a specific potential function or convergence threshold), and code architecture design, thereby fundamentally enhancing its generalization ability and ability to solve complex problems. Specifically, this embodiment constructs an automated thought chain (CoT) synthesis framework driven by a large language model, aiming to generate code efficiently. This framework, by calling the Deepseek-R1 large model API and combining it with a sophisticated generation and optimization process, achieves the continuous expansion and iteration of high-quality thought chains.

[0026] The overall framework's operational process mainly includes two core paths: High-quality template construction: Experts manually write gold standard thought chains for classic core problems (such as material energy calculation) to form high-quality examples; Automated generation process: First, the massive amount of original questions will be sorted by type. Then, high-quality templates will be used for Few-shot guidance to generate an initial thought chain from the model. Then, the logical rigor will be optimized through a human-machine collaborative verification loop to output qualified CoT data. Finally, the human templates will be merged with the optimized automated data to form a complete high-quality fine-tuning dataset. The pre-built Large Language Model (LLM) is trained using this dataset (i.e., the first training dataset mentioned above); Next, we will acquire multi-source heterogeneous data in the target domain, including: domain software manuals (unstructured data), core academic journal articles (unstructured data), structured data, and 6,000 expert question-and-answer pairs; In the process of fine-tuning large-scale models in the field of materials science, constructing high-quality foundational knowledge learning modules is crucial. Since the initial structured question-and-answer pairs provided are limited in scale and cannot fully cover the vast knowledge system of this field, this embodiment adopts a multi-source data fusion strategy to enrich the training corpus. These sources include, but are not limited to: carefully crafted question-and-answer pairs by materials science experts, authoritative software operation manuals, and core academic journal articles. Integrating these heterogeneous data aims to enable the model to draw upon a broader and more solid foundation of prior knowledge.

[0027] However, directly using these raw data sources for model fine-tuning faces significant challenges, mainly in the following three aspects: Format recognition and processing obstacles: The original corpus has a complex and diverse layout format (such as containing formulas, charts, special symbols, columns, etc.), making it difficult for the model to directly recognize and effectively parse the knowledge structure it contains.

[0028] Contextualization barrier: If traditional corpus learning methods are used to slice and process the original corpus, there may be a certain degree of semantic separation between the slices, which may destroy the original knowledge structure.

[0029] Knowledge content bias and noise: More importantly, some content in the original corpus deviates from the core knowledge graph that we expect the model to focus on learning. Software manuals and journal articles are designed for human readers' systematic learning or research reference, inevitably containing a large amount of background information, historical development, version introductions, table of contents, and non-core derivative knowledge or specific research details. If these are directly incorporated into fine-tuning, the model will not only struggle to efficiently extract key knowledge points but may also absorb a large amount of "noise" information irrelevant to the target application scenario, leading to low learning efficiency or even knowledge representation deviating from the expected direction.

[0030] To address the aforementioned challenges and ensure the high quality and relevance of the fine-tuning data, this application designed and implemented a data cleaning process specifically for software manuals and journal articles, including: The software manual relates to data cleaning: Given the aforementioned inability to directly supervise and fine-tune large models using software manuals to enhance their code generation capabilities, the core process is extracted as follows: Text extraction: The process starts with the PDF file of the software manual. First, the PyMuPDF library is used to extract all text information from the file and then it is initially separated by page number.

[0031] Paragraph refinement and optimization: To efficiently extract valuable information from the original text, a multi-layered, refined processing workflow was constructed: (1) Intelligent text cleaning: Use regular expressions to accurately identify and remove redundant page markers (such as "--- Page X ---") and isolated page number lines generated during PDF extraction; at the same time, design an intelligent format protection mechanism to automatically detect code blocks (such as the subroutine / function structure of Fortran) in technical documents, use Markdown syntax for standardized encapsulation, compress continuous whitespace characters to optimize storage efficiency, and retain the paragraph logical structure through blank line control algorithm to ensure the readability and semantic integrity of technical documents.

[0032] (2) Structured pagination processing: A dynamic block model is built based on page delimiters, and the continuous text stream is restored to the original page unit through regular expressions, retaining key metadata including: Precise original page number positioning (1-based index); Standardized content after cleaning; Word count based on space segmentation algorithm; This forms independent knowledge units with complete contextual information, establishing a basic framework for subsequent semantic analysis.

[0033] (3) Batch file conversion: An end-to-end automated pipeline is implemented. The directory traversal engine automatically captures all PDFs in the input directory to extract text. An exception capture mechanism is used to ensure that single file processing errors do not affect the overall process. Through standardized JSON serialization output, an object structure containing an array of pages is generated. Each object encapsulates a triplet of page number, content, and word count to form a standardized data package that can be directly processed. This process supports distributed expansion to meet the needs of large-scale document processing.

[0034] Question-Answer Pair Generation: This application utilizes LLM to manually construct a fully automated knowledge processing and dataset construction workflow based on Large Language Models (LLM). This workflow aims to efficiently and intelligently transform the processed professional materials science software (OC) manual into a high-quality question-and-answer (Q&A) dataset for model fine-tuning. Through a series of sophisticated automated steps, including content preprocessing, intelligent filtering, contextual analysis, and deep question-and-answer generation, it ultimately produces structured, high-precision technical knowledge pairs, laying a solid data foundation for training domain-specific AI expert models. The core functionality of this code mainly consists of the following closely cooperating modules, which work together to complete the transformation from raw documents to high-quality datasets. We will now detail the parameters of each major module: Automated document content preprocessing and formatting: This module is responsible for the initial cleaning and structuring of the raw text extracted from the PDF. Since the raw text blocks may lack formatting, the code uses regular expressions (the `re` module) to automatically identify and apply Markdown formatting, such as adding `#` symbols to chapter titles and adding dedicated ```fortran code block markers to Fortran code snippets. This step not only enhances the readability of the content but also provides standardized input for the subsequent accurate understanding and analysis of large language models.

[0035] Intelligent content analysis and filtering based on a large model: This is a crucial step in achieving data quality control. The code submits the formatted content of each page to the pre-trained LLM large language model (via the `analyze_page` function), assigning it the role of a "materials science software expert." The model, based on preset instructions, determines the importance of the page content for learning OC software code knowledge, automatically filtering out irrelevant or low-value pages such as covers, tables of contents, and references. Only core technical content deemed "necessary" (such as function definitions, parameter descriptions, and key concepts) is retained and proceeds to subsequent processes, ensuring a high signal-to-noise ratio in the final dataset.

[0036] Context Awareness and Relevant Knowledge Extraction: To overcome the limitations of incomplete information on a single page, this application designs a context association module (find_relevant_context function). When processing an important page, the code automatically retrieves the content of its adjacent pages and again calls the large language model to analyze the relationships between them. The model intelligently identifies and extracts relevant context that can supplement and expand the knowledge points of the current page, such as related function calls and parameter explanations. This allows the generated question-answer pairs to transcend page boundaries and contain more complete and in-depth knowledge.

[0037] High-quality technical Q&A generation: As the final output of the process, this module (the `generate_qa_pairs` function) is responsible for generating core data for model fine-tuning. It submits the filtered and context-enhanced content to the LLM large language model, which acts as the "chief technical expert." Guided by detailed instructions, the model creates accurate and in-depth technical Q&As from different cognitive levels (conceptual understanding, code implementation, practical application, etc.) regarding the syntax, function usage, parameter roles, and underlying principles of Objective-C code. Finally, the `parse_qa_pairs` function parses the model's output into structured JSON format for direct use.

[0038] Meanwhile, similar to the previous approach, the entire solution is encapsulated in a batch-execution framework (the `process_pdf_text_files` function). It automatically iterates through all raw data files in the specified directory, performs all the aforementioned processing steps on each file, and finally generates the corresponding output file. The code also includes an API call retry mechanism with an exponential backoff strategy (the `call_llm` function), ensuring the stability and reliability of the process in the face of network fluctuations or temporary API service anomalies. The example prompt for this section is as follows: "Analyze the page content and format it." system_prompt = ( "You are an expert in the field of materials science software (OC). Your task is to analyze the OC software documentation pages." "Assess its importance for learning Objective-C coding knowledge, and format the content to make it easier to read." "Focus on: function definitions, parameter descriptions, code examples, and explanations of key concepts." ) user_prompt = ( Please analyze the following content from the Objective-C documentation page:\n f"Page number: {page_data['page_number']}\n" f"Content:\n{page_data['content']}\n\n" 1. Determine whether the content on this page is necessary for learning Objective-C code knowledge during fine-tuning of the large model. Necessary knowledge should be helpful for future code generation tasks; otherwise, it is considered unnecessary knowledge (return 'necessary' or 'unnecessary')\n 2. If necessary, please format the content to make it easier to read (use Markdown formatting, add headings, code blocks, etc.)\n 3. Briefly explain why the content on this page is important (no more than 50 words)\n\n Output format:\n Importance: [Necessary / Unnecessary]\n The edited content: [Edited Markdown content]\n Importance Note: [Brief Description] ) """Find contextual relevance""" system_prompt = ( "You are an expert in the field of materials science software (OC). Your task is to analyze the relationships between OC document pages." "Find contextual information related to the knowledge on the current page." ) user_prompt = ( Current analysis page:\n f"Page number: {current_page['page_number']}\n" f"Content:\n{current_page['content']}\n\n" Context page:\n f"{context_str}\n\n" Please find the content in the context page that is related to the knowledge on the current page:\n 1. Which functions, parameters, or concepts are mentioned in both the current page and the context page? 2. How can context pages supplement or expand the knowledge on the current page? 3. Return to the revised context (preserving the original technical details)\n\n Output format:\n Relevant context: [Related content after editing] ) "Generate high-quality question-answer pairs" system_prompt = ( "You are a lead technical expert in the field of Materials Science Software (OC). Your task is to..." "Create the highest quality technical question-and-answer pairs, which will be used to fine-tune a specialized large language model to enhance it." "The ability to understand Objective-C code syntax, function usage, and underlying principles." ### Core Task Requirements:\n 1. The Q&A session focuses on the core concepts and calling methods of Objective-C code. 2. The question-and-answer format covers different cognitive levels: concept understanding, code implementation, parameter function, and practical application. 3. For complex concepts, it is necessary to break them down into multiple related question-answer pairs. ### Quality Requirements:\n 1. The problem should accurately pinpoint the key technical points in the Objective-C code. 2. Answers must be based on the document content and include precise technical details. 3. Include necessary code snippets to demonstrate the specific implementation. 4. Explain the function, range of values, and use cases of the parameters. ) user_prompt = ( Please generate high-quality question-and-answer pairs based on the following Objective-C document content:\n Core content:\n f"{page_data['formatted_content']}\n\n" Relevant context:\n f"{context}\n\n" Requirements:\n 1. The question should be specific and clear, focusing on Objective-C code syntax and the use of \n. 2. Answers should be accurate and complete, based on the document content. 3. Includes actual code examples\n 4. Provide clear explanations for complex concepts. Output format:\n Question 1: [Question content]\n" Answer 1: [Answer content]\n" Question 2: [Question content]\n" Answer 2: [Answer content]\n" "..." ) Final output: After the above process, the final output is a standardized QA question-answering pair dataset that can be directly used for pedestal model fine-tuning (SFT); Data cleaning for materials science journals: To address the cutting-edge and data-intensive nature of materials science journal articles, this application constructs a three-level cleaning-knowledge transformation pipeline. Its core technology lies in the intelligent evolution mechanism of a dynamic terminology database. The system's core architecture is driven collaboratively by a dynamic terminology database engine and a new terminology discovery engine, forming a closed-loop knowledge transformation system. The core technologies include: Dynamic Terminology Database Intelligent Hub: During initialization, a predefined terminology library containing 5000+ core terms (format: DFT|Density Functional Theory) is loaded. The architecture achieves dynamic evolution through a three-layer data container: • Basic Terminology Database: A pre-structured core concept system for materials science; • New Terminology Pool: Real-time capture of emerging concepts in the field (such as MXene@MoS2 heterojunction); • Thesaurus: Automatically builds multilingual / multi-expression associations for terms (e.g., mapping "transmission electron microscope" to "TEM"); Two-stage funnel-shaped term discovery engine: The new term capture will employ a dual filtering mechanism of morphology and semantics: 1. Morphological detection layer Using the regular expression \b([AZ][az]?[\d-) )+([AZ][az] [\d-] )+\b Accurately captures word formation patterns unique to materials science, for example: o-element combination type: Fe3O4@C core-shell structure o Composite Modification: Two-Dimensional Perovskite Quantum Dots Setting hard filter conditions with a length of ≥3 effectively eliminates interference from common vocabulary. 2. Contextual semantic analysis layer At this point, deep semantic screening will be implemented based on the SciBERT model. When the cosine similarity between the target term and the known term library is less than 0.65 (novelty > 0.35), the new term capture process will be triggered. Knowledge transformation closed loop: After being standardized by LSTM-CRF, the academic validity of newly coined terms is verified by a domain knowledge filter and then incorporated into the knowledge graph relation extraction engine. The continuous evolution of the terminology base directly enhances the accuracy of LaTeX formula parsing and drives the LLM large language model to produce more accurate academic questions and answers.

[0039] Based on the above three-level operation process, a materials science corpus dataset containing professional materials terminology and accurate materials data is formed, which is used for fine-tuning of large-scale materials models.

[0040] By training the base model with the question-answer pair dataset generated by the LLM large language model (i.e., the second training set mentioned above), the final target domain (materials) large language model can be obtained. It is worth noting that during the critical decision-making stage of model development, this embodiment systematically evaluated multi-dimensional constraints such as computational overhead, memory usage, training speed, and final performance. After comparative experiments and ablation analysis of various fine-tuning strategies, Qwen3-14B-Base was finally selected as the base model, laying the architectural foundation for subsequent efficient fine-tuning.

[0041] Regarding the parameter optimization paradigm, this application abandons the high memory consumption of traditional full fine-tuning schemes and instead adopts LoRA (Low-Rank Adaptation), a currently recognized efficient adaptation technique. Its core idea is to inject a lightweight adaptation matrix next to the original model parameters through low-rank decomposition. Specifically, all parameters of the pre-trained model are frozen, and only two small matrices (denoted as BB and AA, where B∈Rd×r and A∈Rr×k, rank r) are added next to the weight matrix of the Transformer layer. dr d) During training, only these low-rank matrices are updated, making the parameter update amount ΔW=BA approximate the effect of full parameter fine-tuning. This method only requires training 0.1%-1% of the original parameters as incremental parameters to achieve performance similar to full parameter fine-tuning. This design not only significantly reduces memory requirements but also avoids catastrophic forgetting, making it particularly suitable for domain adaptation in resource-constrained scenarios.

[0042] This training focuses on the Supervised Fine-Tuning (SFT) stage. The training data comes from the multiple high-quality professional domain question-answering (QA) datasets that were integrated and constructed above, which mainly include the domain knowledge question-answer pairs extracted from professional books as mentioned earlier.

[0043] In selecting the fine-tuning parameters, our key hyperparameter configurations have been meticulously optimized to balance performance, efficiency, and stability: LoRA parameters: Rank (lora_rank): Set to 64. The rank determines the expressive power of the adaptation matrix. This value is a classic choice that seeks a balance between model capacity and computational / memory overhead, and has a broad practical validation basis.

[0044] Scaling factor (lora_alpha): Also set to 128. lora_alpha controls the scaling intensity of low-rank updates ΔW. Setting alpha to equal rank (alpha / rank=2) is a common configuration strategy that helps to improve training.

[0045] Training cycle and learning rate scheduling: Training epochs: A total of 2 full epochs are performed to ensure that the model has good generalization ability.

[0046] Optimizer: The AdamW optimizer was selected, as it exhibits good robustness in deep learning training.

[0047] Initial learning rate: set to 3.0e-5, which is a typical starting point for fine-tuning large language models.

[0048] Learning rate scheduler: Employs a cosine annealing strategy. This strategy allows the learning rate to decay smoothly from its initial value to near zero, effectively promoting stable convergence of the model in the later stages of training and helping to find better local minima.

[0049] Sequence length (cutoff_len): To fully capture and utilize the long-distance contextual dependencies contained in professional book corpora, the maximum sequence length is significantly extended to 8400 tokens, which is much higher than the common configuration.

[0050] Batch processing and computation optimization: Batch size (batch_size): Due to the limitations of hardware memory capacity, the single-step batch size is set to 2.

[0051] Gradient accumulation steps: Combining a 4-step gradient accumulation strategy, an effective batch size of 8 is achieved under memory-constrained conditions, which helps stabilize the optimization process and improve hardware utilization.

[0052] Accuracy: Enable BF16 Mixed Precision training. This technique significantly improves training speed and greatly saves memory overhead by performing some computations (especially matrix multiplication) in BFloat16 (BF16) format, while generally maintaining the numerical stability of the model training.

[0053] Example 2 Figure 2 This is a system schematic diagram of a domain-knowledge-based large language model optimization apparatus according to another exemplary embodiment, the apparatus comprising: Description Pair Generation Module 1: Used to generate code-description pairs for specific scenarios within the target professional domain; Mind Enhancement Module 2: Used to enhance the code-description pairs of the specific scenario through the standard mind chain, and to construct the first training dataset based on the standard mind chain and the code-description pairs of the enhanced mind chain; LLM Large Language Model Training Module 3: Used to train the pre-built LLM large language model using the first training dataset to obtain the trained LLM large language model; Multi-source heterogeneous data acquisition module 4: used to acquire multi-source heterogeneous data within the target professional field, the multi-source heterogeneous data including structured data and unstructured data, the structured data being expert question-and-answer pairs; Question-answer pair generation module 5: used to perform preset automated processing on the unstructured data, and generate structured question-answer pairs through the trained LLM large language model, and construct a second training dataset based on the structured question-answer pairs and expert question-answer pairs; Base Large Model Training Module 6: Used to train the target base large model using the low-rank adaptation LoRA method through the second training set to obtain the target domain large language model.

[0054] Example 3 This embodiment provides a storage medium storing a computer program, which, when executed by a host controller, implements the steps of the above method. It is understood that the storage medium mentioned above can be a read-only memory, a hard disk, or an optical disk, etc.

[0055] It is understood that the same or similar parts in the above embodiments can be referred to each other, and the contents not described in detail in some embodiments can be referred to the same or similar contents in other embodiments.

[0056] It should be noted that in the description of this invention, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Furthermore, in the description of this invention, unless otherwise stated, "a plurality of" means at least two.

[0057] Any process or method description in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing a particular logical function or process, and the scope of the preferred embodiments of the invention includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as will be understood by those skilled in the art to which embodiments of the invention pertain.

[0058] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0059] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.

[0060] Furthermore, the functional units in the various embodiments of the present invention can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.

[0061] The storage media mentioned above can be read-only memory, disk, or optical disk, etc.

[0062] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0063] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.

Claims

1. A method for optimizing large language models based on domain knowledge, characterized in that, The method includes: Generate code-description pairs for specific scenarios within the target professional field; The code-description pair for the specific scenario is enhanced using a standard mind chain, and a first training dataset is constructed based on the standard mind chain and the enhanced code-description pair. The pre-built LLM large language model is trained using the first training dataset to obtain the trained LLM large language model. Acquire multi-source heterogeneous data within the target professional field, including structured data and unstructured data, wherein the structured data consists of expert question-and-answer pairs; The unstructured data is subjected to pre-defined automated processing, and structured question-answer pairs are generated through the trained LLM large language model. A second training dataset is constructed based on the structured question-answer pairs and expert question-answer pairs. The low-rank adaptation LoRA method is used to train the target base large model using the second training set to obtain the target domain large language model.

2. The method according to claim 1, characterized in that, The unstructured data includes: professional software manuals and academic journal articles; The process of performing pre-defined automated processing on the professional software manual and generating structured question-answer pairs using the trained LLM large language model includes: Extract all text information from professional software manuals in PDF format and perform preliminary separation by page number; The system uses regular expressions to accurately identify and remove redundant page markers and isolated page number lines generated during the text information extraction process; it extracts code blocks from the text information and uses Markdown syntax for standardized encapsulation. During the standardized encapsulation process, while compressing consecutive whitespace characters, it preserves the paragraph's logical structure through a blank line control algorithm. The continuous text stream is restored to the original page unit by regular expressions, and key metadata is retained to obtain a standardized data package. The key metadata includes: original page number location, cleaned and standardized content, and word count based on space segmentation algorithm. The standardized data packet is input into a pre-trained LLM large language model, which generates structured question-answer pairs through a standardization process.

3. The method according to claim 2, characterized in that, The pre-trained LLM large language model generates structured question-answer pairs through a standardization process, including: Before the standardized data packets are input into the pre-trained LLM large language model, the standardized data packets are automatically identified and formatted using regular expressions and Markdown format is applied to achieve formatting processing. The pre-trained LLM large language model selects core technical content according to preset instructions; The pre-trained LLM large language model retrieves adjacent pages of the core technical content according to preset instructions, and obtains the relevant context of the core technical content from the adjacent pages; The pre-trained LLM large language model will select and supplement the core technical content with context, and under the guidance of preset instructions, generate technical questions and answers from different cognitive levels around the syntax, function usage, parameter role and underlying principle of the phase diagram calculation software code, and parse the output technical questions and answers into structured JSON format question and answer pairs.

4. The method according to claim 3, characterized in that, The pre-defined automated processing of the academic journal articles includes: Construct a terminology database and associate different expressions of the same term in the database; The terminology database also includes a new term capture mechanism, which includes: The text describes how to capture material science-specific word formation patterns in academic journal articles using pre-defined regular expressions, and how to filter out common vocabulary interference by setting length filtering conditions to obtain target terms. Deep semantic screening is implemented based on the SciBERT model. When the cosine similarity between the target term and an existing term in the terminology database is lower than a preset threshold, the target term is added to the terminology database. The dynamic updating of the terminology base enables the injection of external knowledge into the pre-trained LLM large language model, driving the pre-trained LLM large language model to generate more standardized question-answer pairs.

5. The method according to claim 4, characterized in that, The code-description pairs generated for specific scenarios within the target professional field include: Define a scenario within a target professional field, set up multi-dimensional natural language user input for the scenario, generate an executable code script for the scenario, set structured system prompts for the scenario and the executable code script, and obtain code-description pairs.

6. The method according to claim 5, characterized in that, The structured system prompts include: Define the functional roles and specific operation steps of the LLM large model; And define the output format of the LLM large model, as well as the rules to be followed during the output generation process; A standard input-output learning template is embedded in the structured system prompts to guide the LLM large model in generating code-description pairs.

7. The method according to claim 6, characterized in that, The code-description pair for the specific scenario is used to enhance the thought chain through a standard thought chain. Constructing the first training dataset based on the standard thought chain and the enhanced code-description pair includes: Standard thought chains are generated in advance for classic questions in the target professional field. The original questions in the code-description pairs are classified and categorized by the second major language model. Then, the original questions in the code-description pairs are guided by the standard thought chains of the corresponding types through Few-shot to generate the initial thought chains of the original questions. The initial thought chains are iteratively updated by the human-computer collaborative verification loop to obtain the enhanced code-description pairs. The first training dataset is constructed based on the standard thought chains and the enhanced code-description pairs.

8. A domain-knowledge-based large language model optimization device, characterized in that, The device includes: Description pair generation module: Used to generate code-description pairs for specific scenarios in the target professional field; The thought enhancement module is used to enhance the thought chain of the code-description pair for the specific scenario through the standard thought chain, and to construct the first training dataset based on the standard thought chain and the thought chain enhancement code-description pair. LLM Large Language Model Training Module: Used to train the pre-built LLM large language model using the first training dataset to obtain the trained LLM large language model; Multi-source heterogeneous data acquisition module: used to acquire multi-source heterogeneous data within the target professional field, the multi-source heterogeneous data including structured data and unstructured data, the structured data being expert question-and-answer pairs; Question-answer pair generation module: used to perform preset automated processing on the unstructured data, and generate structured question-answer pairs through the trained LLM large language model, and construct a second training dataset based on the structured question-answer pairs and expert question-answer pairs; Base large model training module: Used to train the target base large model using the low-rank adaptation LoRA method, through the second training set, to obtain the target domain large language model.

9. A storage medium, characterized in that, The storage medium stores a computer program, which, when executed by the main controller, implements the various steps of the domain knowledge-based large language model optimization method as described in any one of claims 1-7.