A processing method and device for generating a molecular sequence based on a chemical large model

By conducting three-stage training on the large chemical model, its chemical knowledge and reasoning ability are enhanced, solving the problems of accuracy and rationality in generating molecular sequences in the general large language model, and realizing more efficient generation of chemical laws.

CN122392713APending Publication Date: 2026-07-14BEIJING DP TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING DP TECH CO LTD
Filing Date
2026-04-13
Publication Date
2026-07-14

AI Technical Summary

Technical Problem

The general-purpose large language model suffers from insufficient specialized chemical knowledge when generating molecular sequences, resulting in inaccurate molecular sequence structures and insufficient chemical rationality.

Method used

By employing a large chemical model, configuring chemical question-and-answer instruction templates and molecular generation instruction templates, and constructing question-and-answer datasets, reasoning datasets, and molecular datasets, the large chemical model is trained in three stages to enhance its chemical knowledge understanding, reasoning ability, and sequence generation ability.

Benefits of technology

This improved the model's ability to understand and analyze specialized chemical knowledge, and enhanced the chemical accuracy and rationality of the generated molecular sequences.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122392713A_ABST
    Figure CN122392713A_ABST
Patent Text Reader

Abstract

Embodiments of the present application relate to a kind of processing method and device for generating molecular sequence based on chemical large model, the method comprises: selecting general large language model as chemical large model, configure chemical question and answer instruction template, molecular generation instruction template for it, and build question and answer data set, inference data set, molecular data set;First, according to chemical question and answer instruction template and question and answer data set, the model is carried out chemical knowledge enhancement training;Again, according to molecular generation instruction template and inference data set, the model is carried out chemical inference ability enhancement training;Finally, according to molecular generation instruction template and molecular data set, the model is carried out sequence generation ability enhancement training;After training, the molecular description input by user is configured into molecular generation instruction template, and the molecular generation instruction generated by configuration is input into chemical large model for processing to obtain corresponding molecular sequence to current user feedback.The present application can improve the chemical accuracy and rationality of generating molecular sequence.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and in particular to a processing method and apparatus for generating molecular sequences based on a large chemical model. Background Technology

[0002] Text-based molecular generation is the process of generating SELFIES-formatted molecular sequences from natural language descriptions. This technology has significant application value in fields such as drug design and materials design. Currently, general-purpose Large Language Models (LLMs), such as Qwen, GPT, and DeepSeek, have made significant progress in a series of general Natural Language Processing (NLP) tasks (such as text generation, translation, question answering, and chain of thought derivation). However, some problems still exist in handling molecular generation tasks in specialized chemical fields: 1) The pre-training corpora and fine-tuning corpora of general-purpose LLMs do not contain sufficient specialized chemical knowledge, making the generated molecular sequences prone to structural inaccuracies; 2) The chain of thought (CoT) reasoning ability of general-purpose LLMs only possesses general knowledge reasoning capabilities and lacks specialized chemical knowledge reasoning capabilities, making the generated molecular sequences prone to insufficient chemical rationality. Summary of the Invention

[0003] The purpose of this invention is to address the shortcomings of existing technologies by providing a method, apparatus, electronic device, and computer-readable storage medium for generating molecular sequences based on a large chemical model. This invention selects a general-purpose large language model as the large chemical model, configures corresponding chemical question-and-answer instruction templates and molecular generation instruction templates for it, and constructs corresponding question-and-answer datasets, inference datasets, and molecular datasets. First, the large chemical model undergoes a first-stage chemical knowledge enhancement training based on the chemical question-and-answer instruction templates and the question-and-answer dataset. Then, a second-stage chemical reasoning ability enhancement training is conducted based on the molecular generation instruction templates and the inference dataset. Finally, a third-stage sequence generation ability enhancement training is conducted based on the molecular generation instruction templates and the molecular dataset. After the three-stage training is completed, the end-to-end large chemical model processes the user's molecular generation task. Based on this invention, the model's ability to understand and analyze specialized chemical knowledge can be improved, its chemical knowledge reasoning ability can be enhanced, and the chemical accuracy and rationality of the generated molecular sequences can be improved.

[0004] To achieve the above objectives, a first aspect of the present invention provides a method for generating molecular sequences based on a large chemical model, the method comprising: Select a general-purpose language model that has completed pre-training for both large language models and general NLP tasks as the corresponding chemical large model; the general-purpose language model includes at least the Qwen series models, GPT series models, and DeepSeek series models; the general-purpose NLP tasks include at least text generation tasks, translation tasks, question answering tasks, and thought chain deduction tasks; Configure corresponding chemical question-and-answer instruction templates and molecular generation instruction templates for the aforementioned large chemical model; A question-and-answer dataset is constructed by collecting big data from publicly available knowledge media in the field of chemistry; a molecular sequence dataset is constructed by collecting big data from publicly available molecular libraries, and molecular descriptions of each collected sequence are obtained by querying the molecular libraries. Inference chain tags from each molecular description to its corresponding molecular sequence are labeled, and an inference dataset is constructed based on all molecular descriptions and their corresponding inference chain tags. A molecular dataset is constructed based on all molecular descriptions and their corresponding molecular sequences. First, the chemical large model undergoes a first-stage chemical knowledge enhancement training based on the chemical question-and-answer instruction template and the question-and-answer dataset; then, the chemical large model undergoes a second-stage chemical reasoning ability enhancement training based on the molecular generation instruction template and the reasoning dataset; finally, the chemical large model undergoes a third-stage sequence generation ability enhancement training based on the molecular generation instruction template and the molecular dataset. After the three-stage training is completed, the molecular description input by the user is received as the current description; the current description is then substituted into the molecular generation instruction template, and the molecular description text of the template's molecular description segment is configured to obtain the corresponding current molecular generation instruction; the current molecular generation instruction is then input into the large chemical model for molecular generation task processing; and the molecular sequence output by the model in this processing is fed back to the current user.

[0005] Preferably, the chemical question-and-answer instruction template consists of a question-and-answer instruction requirement text and a question text; The question-and-answer instruction requires the text to be a fixed natural language text, which is used to prompt the chemical big model to generate a corresponding answer based on the given question in the question text; The question segment consists of a fixed question segment title and configurable question text; the question segment title defaults to the string "Question:"; the question text is initialized to empty; when the question text is not empty, it is a piece of natural language text used to ask questions about the basic chemical concepts given in the text or a piece of natural language text used to ask questions about one or more types of molecular features given the molecular name or SELFIES molecular sequence in the text. The knowledge scope corresponding to basic chemical concepts includes at least the atomic model and quantum numbers, the principle of electron configuration and structure, the periodic table, the atomic structure and periodic properties of the periodic law, various chemical bond structures and their corresponding force and energy theories, intermolecular forces, chemical thermodynamics theory, chemical reaction theory, acid-base theory, redox theory, functional group theory, polymer theory, organic matter theory, inorganic matter theory, stereochemistry theory, physicochemical property theory, chemical nomenclature rules, quantum chemistry theory, and biological and pharmaceutical chemistry theory. The knowledge scope corresponding to molecular characteristics includes at least basic constituent characteristics, two-dimensional structural characteristics, three-dimensional structural characteristics, physicochemical property characteristics, spectroscopic characteristics, crystallographic characteristics, biological activity characteristics, material performance characteristics, and reaction characteristics; the basic constituent characteristics include at least molecular formula, molecular mass, chemical formula, and isotopic composition; the two-dimensional structural characteristics include at least atomic connection sequence characteristics, chemical bond characteristics, functional group characteristics, and atomic skeleton characteristics; the three-dimensional structural characteristics include at least spatial geometric characteristics, rotational conformation characteristics, chiral characteristics, and geometric isomerism characteristics; the physicochemical property characteristics include at least melting point, boiling point, flash point, solubility, partition coefficient, vapor pressure, polarity, dipole moment, ionization energy, electron affinity, color, optical rotation, chemical stability, and acid / base dissociation constant; the spectroscopic characteristics include at least spectral characteristics and mass spectrometry characteristics. The molecule generation instruction template consists of a generation instruction requirement section, a molecule description section, a reasoning step description section, and a formatting requirement section; The generation instruction requires the text segment to be a fixed natural language text, which is used to prompt the chemical big model to perform step-by-step analysis and reasoning based on the molecular description information given in the molecular description text segment, the step sequence given in the reasoning step description text segment, and generate a SELFIES molecular sequence that conforms to chemical laws based on the reasoning context. The molecular description segment consists of a fixed description segment title and configurable molecular description text; the description segment title defaults to the string "Molecular description:"; the molecular description text is initialized to empty; The inference step description is a fixed natural language text consisting of N inference step texts, where N is the preset total number of inference steps. Each inference step text is a step description text for one step of inference, used to prompt the chemical macro-model to perform analysis and inference according to the requirements of this step and the current inference context, and to take the result of this step as the corresponding single-step inference text C. i And output, 1≤index i≤N; the current inference context includes the molecular description information given by the molecular description text, the inference results of all historical steps before the current inference step; the single-step inference text C corresponding to the Nth step. i=N SELFIES molecular sequences generated for the model; The formatting requirement text is a fixed natural language text used to prompt the chemical model to encapsulate and output the generated SELFIES molecular sequences in a preset molecular sequence output format. The molecular sequence output format is formed by connecting the preset start marker text, the model-generated SELFIES molecular sequences, and the preset end marker text in sequence. The publicly available knowledge media in the field of chemistry include at least publicly available textbooks or theoretical books in the field of chemistry, publicly available journals or papers in the field of chemistry, and publicly available databases or molecular libraries in the field of chemistry. The publicly available molecular databases include at least the PubChem database and the PDB database; The question-and-answer dataset includes a first subset and a second subset; both the first subset and the second subset consist of multiple first data records; the first data records include a first training question and a first labeled answer; the first training question of the first subset is a piece of natural language text used to ask questions about a given basic chemical concept within the text; the first training question of the second subset is a piece of natural language text used to ask questions about one or more types of molecular features given a molecular name or SELFIES molecular sequence within the text; The inference dataset includes multiple second data records; each second data record includes a first molecule description and a first label inference chain; the first label inference chain includes N single-step inference labels. ; The molecular dataset includes multiple third data records; each third data record includes a second molecular description and a first tag sequence; the first tag sequence is a SELFIES molecular sequence.

[0006] Preferably, the step of constructing a question-and-answer dataset by collecting big data from publicly available knowledge media in the field of chemistry specifically includes: Multiple knowledge entries are obtained by collecting big data from the publicly available chemical professional knowledge media; and each knowledge entry is configured with a corresponding first training question and a first tag answer through manual or machine question-and-answer configuration; the first training question and the first tag answer corresponding to each knowledge entry form a corresponding first data record; and through manual or machine classification, all the first data records corresponding to basic chemical concept questions and answers form a corresponding first subset, and all the first data records corresponding to molecular feature questions and answers form a corresponding second subset; and the obtained first subset and the second subset form a corresponding question-and-answer dataset. Among them, the knowledge domain of all knowledge items obtained through big data collection is greater than or equal to the preset knowledge domain of basic chemical concepts and molecular characteristics; the knowledge domain of basic chemical concepts and molecular characteristics is the combination of the knowledge domain corresponding to the basic chemical concepts and the knowledge domain corresponding to the molecular characteristics.

[0007] Preferably, the step of collecting molecular sequences from publicly available molecular libraries, obtaining molecular descriptions for each collected sequence by querying the molecular library, labeling the inference chain tags from each molecular description to its corresponding molecular sequence, constructing an inference dataset based on all molecular descriptions and their corresponding inference chain tags, and constructing a molecular dataset based on all molecular descriptions and their corresponding molecular sequences specifically includes: A first sequence set is formed by collecting multiple sequences from the SMILES and SELFIES molecular sequences in the publicly available molecular library; the first sequence set includes multiple first sequences; each first sequence is a SMILES molecular sequence or a SELFIES molecular sequence. Each of the first sequences is taken as the current sequence; a molecular summary or comprehensive description corresponding to the current sequence is obtained by querying the molecular library and used as a set of corresponding first molecular descriptions and second molecular descriptions; the sequence format of the current sequence is identified as SELFIES sequence format. If it is, the current sequence is taken as a corresponding first tag sequence; otherwise, a preset cheminformatics tool is used to convert the current sequence into a SELFIES molecular sequence and the conversion result is taken as a corresponding first tag sequence; all the step description texts of the reasoning step description section of the molecular generation instruction template are sequentially traversed; at the beginning of this round of traversal, the corresponding reasoning context is initialized to empty; during this round of traversal, the step description text of the current traversal is taken as the current step description, and a corresponding current question is formed by the current sequence, the current step description, and the reasoning context according to the preset question construction rules. The current question is processed through a preset professional chemical question-and-answer interface, and the answer text obtained in this processing is taken as a corresponding single-step reasoning tag. The current question and answer are combined to form a corresponding question-and-answer text pair, which is then added to the reasoning context. At the end of this round of traversal, the N single-step reasoning tags obtained from this round of traversal are... A corresponding first tag inference chain is formed; wherein, the cheminformatics tool includes at least the RDKit tool; the question construction rule is used to set the analysis question with the current sequence and the inference context as reference context and the current step description as the current analysis target; the professional chemistry question answering interface is a type of human question answering task processing interface for professional chemistry experts, a type of system question answering task processing interface for professional chemistry question answering system, or a type of model question answering task processing interface for professional chemistry large model; Each of the first molecular descriptions and their corresponding first tag inference chains forms a corresponding second data record; each of the second molecular descriptions and their corresponding first tag sequences forms a corresponding third data record; all the obtained second data records form the corresponding inference dataset; and all the obtained third data records form the corresponding molecular dataset.

[0008] Preferably, the step of performing a first-stage chemical knowledge enhancement training on the large chemical model based on the chemical question-and-answer instruction template and the question-and-answer dataset specifically includes: Step 51: Take the first subset of the question-and-answer dataset as the current dataset; Step 52: Divide the current dataset into multiple first data batches based on a preset batch size B1; and take the first first data batch of the current dataset as the current data batch; Each first data batch includes B1 first data records; the first tag answer of each first data record in each first data batch is denoted as the corresponding tag answer. , 1 ≤ index j ≤ B1; each of the stated label answers The total number of word segments is denoted as n. j Each of the aforementioned tagged answers Each word segment is recorded as the corresponding 1 ≤ index k ≤ n j ; Step 53: Substitute the first training question of each first data record in the current data batch into the chemical question-and-answer instruction template, and configure the question text of the question segment in the template to obtain the corresponding current chemical question-and-answer instruction Q. j ; and the current chemical question-and-answer command Q j The chemical model is input for question-answering task processing; the autoregressive text generation process of the chemical model during this processing is recorded; and after completing B1 model processing iterations, the first model loss function L is used as the basis for the calculation. M1 Calculate the corresponding first loss value; Wherein, the first model loss function LM1 It is implemented based on the cross-entropy loss function, specifically as follows: ; For the tagged answer The word segmentation sequence preceding the kth word; For the model in the autoregressive text generation process, the current chemical question-answering instruction Q is used. j and word segmentation sequence The k-th word generated for the context is the corresponding word. The probability of; Step 54: Identify whether the first loss value meets the preset first loss value range; if not, then based on the preset first model optimizer, move towards making the first model loss function L... M1 The model parameters of the large chemical model are fine-tuned in the direction that reaches the minimum value, and the process returns to step 53 after this round of fine-tuning is completed; if the condition is met, proceed to step 55. The first model optimizer includes the Adam optimizer, the SGD optimizer, and the AdamW optimizer. Step 55: Identify whether the current data batch is the last first data batch of the current dataset; if not, take the next first data batch of the current dataset as the new current data batch and return to step 53; if yes, identify whether the current dataset is the first subset; if yes, take the second subset of the question-and-answer dataset as the new current dataset and return to step 52; otherwise, stop training and confirm the end of the first stage of training.

[0009] Preferably, the step of performing a two-stage chemical reasoning capability enhancement training on the large chemical model based on the molecular generation instruction template and the reasoning dataset specifically includes: Step 61: Divide the inference dataset into multiple second data batches based on a preset batch size B2; and use the first second data batch as the current data batch; Each second data batch includes B2 second data records; the first tag inference chain of each second data record in each second data batch is denoted as the corresponding tag chain. , 1 ≤ index q ≤ B2; each of the said tag chains Each of the aforementioned single-step reasoning tags Record as the corresponding single-step label Each of the aforementioned single-step labels The total number of word segments is denoted as n. q,i Each of the aforementioned single-step labels Each word segment is recorded as the corresponding 1 ≤ index s ≤ n q,i ; Step 62: Substitute the first molecular description of each second data record in the current data batch into the molecular generation instruction template, and configure the molecular description text of the molecular description segment in the template to obtain the corresponding current molecular generation instruction X. q ; and the current molecule generation instruction X q The input chemical model is processed; the autoregressive text generation process of the chemical model during this processing is recorded; and after completing B2 model processing iterations, the second model loss function L is used as the basis for the processing. M2 Calculate the corresponding second loss value; Wherein, the second model loss function L M2 It is implemented based on the cross-entropy loss function, specifically as follows: ; It is a sequence of single-step labels formed by concatenating the first i-1 single-step labels in sequence; For the single-step label The word segmentation sequence preceding the s-th word; For the model in the autoregressive generation step of the inference text at step i, the corresponding molecular generation instruction X is used. q Single-step label sequence and word segmentation sequence The s-th word generated for the context is the corresponding word. The probability of; Step 63: Identify whether the second loss value meets the preset second loss value range; if not, then based on the preset second model optimizer, move towards making the second model loss function L... M2 The model parameters of the chemical model are fine-tuned in the direction of reaching the minimum value, and the process returns to step 62 after the fine-tuning is completed. If the condition is met, it is identified whether the current data batch is the last second data batch. If not, the next second data batch is taken as the new current data batch and the process returns to step 62. If the condition is met, training is stopped and the end of the second stage training is confirmed. The second model optimizer includes the Adam optimizer, the SGD optimizer, and the AdamW optimizer.

[0010] Preferably, the step of performing a three-stage sequence generation capability enhancement training on the large chemical model based on the molecular generation instruction template and the molecular dataset specifically includes: Step 7-1: The chemical macro model is replicated to obtain two replicated models, and the current chemical macro model is denoted as the corresponding new strategy model M. new The two replication models are denoted as the corresponding old policy models M. old Reference Model M ref and the reference model M ref The model parameters are solidified; and the molecular dataset is divided into multiple third data batches based on a preset batch size B3; and the first third data batch is taken as the current data batch. Among them, the new strategy model M new The old strategy model M old The reference model M ref The model parameters are denoted as the corresponding model parameters θ. new Model parameters θ old Model parameters θ ref ; Each data batch includes B3 third data records; the first tag sequence of each third data record in each data batch is denoted as the corresponding tag sequence. , 1 ≤ index l ≤ B3; Step 7-2: Take each of the third data records in the current data batch as the current record; substitute the second molecular description of the current record into the molecular generation instruction template, set the molecular description text of the molecular description segment in the template to obtain the corresponding current molecular generation instruction; and continuously input the current molecular generation instruction into the old strategy model M G times. old The processing yields G corresponding predicted texts. ; and according to the formatting requirements of the molecular generation instruction template, the molecular sequence output format is obtained from each of the predicted texts. Extract the corresponding SELFIES molecular sequences as the corresponding predicted sequences. ; Wherein, the number of repeated operations G is a preset positive integer, 1≤index g≤G; Each of the predicted texts The total number of word segments is recorded as the corresponding Each of the predicted texts Each word segment is recorded as the corresponding , 1≤index t≤ Each segmentation The corresponding predicted probability is denoted as ; Step 7-3, for each of the predicted texts The system identifies whether the text format meets the molecular sequence output format of the molecular generation instruction template; if it does, the corresponding format check result f is set. l,g Set the value to 1; if the condition is not met, set the corresponding format check result f. l,g =0; Step 7-4: Use preset cheminformatics tools to analyze each of the stated tag sequences. The predicted sequence The corresponding tag fingerprints are obtained by calculating the three types of molecular fingerprints. , , fingerprint prediction , , ; and using the cheminformatics tools to analyze each of the tag sequences. The predicted sequence The molecular side chains and functional groups are identified to obtain the corresponding tag side chain set. , collection of tagged functional groups Predictive sidechain set Predictive functional group set ; The three types of molecular fingerprints include Morgan fingerprints, MACCS fingerprints, and RDKit fingerprints; The cheminformatics tools include at least the RDKit tool; The tag sidechain set or the predicted sidechain set When not empty, it consists of one or more sidechain fragments; the tag functional group set or the set of predictive functional groups When not empty, it consists of one or more functional group segments, and each functional group segment corresponds to a functional group type; Step 7-5, for each of the predicted sequences The corresponding tag sequence The similarity of the four types of sequences is calculated, and the average of the four types of sequence similarity is used as the corresponding structural reward. ; and check the result f according to the stated format. l,g and the structural reward Calculate the corresponding generated reward R l,g ; Among them, the four types of sequence similarity include sequence similarity Fingerprint similarity Fragment similarity Functional group similarity ; sequence similarity The calculation method is as follows: ; BLEU() is the BLEU evaluation function; fingerprint similarity The calculation method is as follows: , f s () represents a preset fingerprint similarity function, f. s Including the Jaccard similarity function and the cosine similarity function; The similarity of the segments The calculation method is as follows: ; For the predicted sidechain set With the tag sidechain set The total number of overlapping segments; For the predicted sidechain set With the set of tag sidechains The total number of segments in the collection; For the set of tag sidechains The total number of segments; when confirming overlapping segments, the similarity of the segment molecular fingerprint is calculated to determine if the predicted sidechain set... One of the sidechain fragments and the tag sidechain set If the molecular fingerprint similarity of a side chain fragment exceeds a preset fingerprint similarity threshold, the two are considered as overlapping fragments; when counting the total number of fragments in the set, overlapping fragments are only counted once; The functional group similarity The calculation method is as follows: ; U is the total number of preset functional group types, where 1 ≤ index u ≤ U; The set of predictable functional groups The statistical number of class u functional groups; The set of tag functional groups The statistical number of class u functional groups; A preset small constant that is greater than zero; The structural reward The calculation method is as follows: ; The generated reward R l,g The calculation method is as follows: ; Step 7-6, The tag sequences of the current data batch are... The corresponding G predicted sequences Cluster them into groups; and generate an average reward µ for each group. l and standard deviation σ l Perform calculations; and based on each of the predicted sequences in each group. The corresponding generated reward R l,g The average value µ l and the standard deviation σ l Calculate the corresponding within-group advantage V l,g ; Wherein, the average value µ l The standard deviation σ l and the aforementioned intra-group advantage V l,g The calculation method is as follows: , ; ; λ1 is a preset small constant used to prevent the denominator from being zero, and its value is greater than zero; Step 7-7: Substitute the second molecular description of each of the third data records in the current data batch into the molecular generation instruction template, set the molecular description text of the molecular description segment in the template to obtain the corresponding current molecular generation instruction; and continuously input the current molecular generation instruction into the reference model M G times. ref Processing is performed; and in the g-th processing corresponding to the l-th third data record, the word probability vector corresponding to the t-th word segment generated by the model in this processing is compared with the corresponding predicted text. The t-th segmentation The corresponding word segmentation prediction probability is extracted as the corresponding prediction probability. ; Steps 7-8: Substitute the second molecular description of each of the third data records in the current data batch into the molecular generation instruction template, set the molecular description text of the molecular description segment in the template to obtain the corresponding current molecular generation instruction; and continuously input the current molecular generation instruction into the new strategy model M G times. new Processing is performed; and in the g-th processing corresponding to the l-th third data record, the word probability vector corresponding to the t-th word segment generated by the model in this processing is compared with the corresponding predicted text. The t-th segmentation The corresponding word segmentation prediction probability is extracted as the corresponding prediction probability. ; Steps 7-9: For each of the predicted texts Each of the aforementioned words Importance sampling ratio r l,g,t And truncation sampling ratio Perform calculations; Wherein, the importance sampling ratio r l,g,t and the truncation sampling ratio The calculation method is as follows: , ; λ2 is the preset truncation threshold, and Clip() is the Clip truncation function; Steps 7-10: Based on the preset third model loss function L M3 Calculate the corresponding third loss value; Wherein, the third model loss function L M3 The objective function J based on the group relative strategy optimization algorithm GRPO To achieve this, the objective function J of the group relative strategy optimization algorithm is... GRPO By strategy function term J policy , divergence function term J KL The composition is as follows: , , ; β is the preset divergence coefficient; Steps 7-11 involve identifying whether the third loss value meets a preset range; if the third loss value does not meet the preset range, the third model optimizer is then used to optimize the third model loss function L. M3 The direction for reaching the minimum value corresponds to the new strategy model M. new The model parameters θ new Perform one round of modulation, and return to step 7-2 at the end of this round of modulation; if the third loss value meets the range of the third loss value, then based on the model parameter θ new For the old strategy model M old The model parameters θ old Perform a reset and identify whether the current data batch is the last of the third data batch. If not, use the next third data batch as the new current data batch and return to step 7-2. If yes, stop training, confirm the end of the three-stage training, and set the new policy model M. new As the latest version of the aforementioned large chemical model; The third model optimizer includes the Adam optimizer and the AdamW optimizer.

[0011] A second aspect of the present invention provides an apparatus for implementing the processing method for generating molecular sequences based on a large chemical model as described in the first aspect above. The apparatus includes: a model selection module, a template customization module, a dataset construction module, a model training module, and a model application module. The model selection module is used to select a general-purpose language model that has completed pre-training for both large language models and general NLP tasks as the corresponding chemical large model; the general-purpose language model includes at least the Qwen series models, GPT series models, and DeepSeek series models; the general-purpose NLP tasks include at least text generation tasks, translation tasks, question answering tasks, and thought chain derivation tasks; The template customization module is used to configure corresponding chemical question-and-answer instruction templates and molecular generation instruction templates for the large chemical model. The dataset construction module is used to construct a question-and-answer dataset by collecting big data from publicly available chemical professional knowledge media; and to collect big data from molecular sequences in publicly available molecular libraries, obtain molecular descriptions of each collected sequence by querying the molecular library, and label the inference chain tags from each molecular description to its corresponding molecular sequence, and construct an inference dataset based on all molecular descriptions and their corresponding inference chain tags, and construct a molecular dataset based on all molecular descriptions and their corresponding molecular sequences. The model training module is used to first perform a first-stage chemical knowledge enhancement training on the large chemical model based on the chemical question-and-answer instruction template and the question-and-answer dataset; then perform a second-stage chemical reasoning ability enhancement training on the large chemical model based on the molecular generation instruction template and the reasoning dataset; and finally perform a third-stage sequence generation ability enhancement training on the large chemical model based on the molecular generation instruction template and the molecular dataset. The model application module is used to receive the molecular description input by the user as the current description after the three-stage training is completed; substitute the current description into the molecular generation instruction template, configure the molecular description text of the molecular description segment of the template to obtain the corresponding current molecular generation instruction; input the current molecular generation instruction into the chemical large model for molecular generation task processing; and feed back the molecular sequence output by the model in this processing to the current user.

[0012] A third aspect of the present invention provides an electronic device, including: a memory, a processor, and a transceiver; The processor is used to couple with the memory, read and execute instructions in the memory to implement the steps of the method described in the first aspect above; The transceiver is coupled to the processor, and the processor controls the transceiver to send and receive messages.

[0013] A fourth aspect of the present invention provides a computer-readable storage medium storing computer instructions that, when executed by a computer, cause the computer to perform the instructions described in the first aspect.

[0014] This invention provides a method, apparatus, electronic device, and computer-readable storage medium for generating molecular sequences based on a large chemical model. As described above, this invention selects a general-purpose large language model as the large chemical model, configures corresponding chemical question-and-answer instruction templates and molecular generation instruction templates for it, and constructs corresponding question-and-answer datasets, inference datasets, and molecular datasets. First, the large chemical model undergoes a first-stage chemical knowledge enhancement training based on the chemical question-and-answer instruction templates and the question-and-answer dataset. Then, a second-stage chemical reasoning ability enhancement training is conducted based on the molecular generation instruction templates and the inference dataset. Finally, a third-stage sequence generation ability enhancement training is conducted based on the molecular generation instruction templates and the molecular dataset. After the three-stage training, the user's molecular generation task is processed based on the end-to-end large chemical model. This invention improves the model's understanding and parsing ability of specialized chemical knowledge, enhances the model's chemical knowledge reasoning ability, and improves the chemical accuracy and rationality of the generated molecular sequences. Attached Figure Description

[0015] Figure 1 This is a schematic diagram of a method for generating molecular sequences based on a large chemical model, provided in Embodiment 1 of the present invention. Figure 2 This is a module structure diagram of a processing device for generating molecular sequences based on a large chemical model, provided in Embodiment 2 of the present invention; Figure 3 This is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present invention. Detailed Implementation

[0016] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of this invention, and not all embodiments. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.

[0017] Embodiment 1 of this invention provides a method for generating molecular sequences based on a large chemical model, such as... Figure 1 The schematic diagram shows a method for generating molecular sequences based on a large chemical model, as provided in Embodiment 1 of the present invention. This method mainly includes the following steps: Step 1: Select a general-purpose large language model that has completed pre-training for both large language models and general NLP tasks as the corresponding chemical large model.

[0018] Here, the general large language model in this embodiment of the invention includes at least the Qwen series model, the GPT series model, and the DeepSeek series model; the general NLP tasks include at least text generation tasks, translation tasks, question answering tasks, and thought chain derivation tasks.

[0019] Step 2: Configure the corresponding chemical question-and-answer instruction template and molecular generation instruction template for the large chemical model.

[0020] Here, the chemical question-and-answer instruction template of this invention consists of a question-and-answer instruction requirement text and a question text. Wherein: 1) The question-and-answer instruction requires the text to be a fixed natural language text, which is used to prompt the chemical big model to generate the corresponding answer based on the given question in the question text.

[0021] It should be noted that the specific text content of the question-and-answer instruction in this embodiment of the invention can be customized based on application requirements or the developer's language habits. For example, "Provide accurate, detailed answers that conform to chemical principles based on the following questions."

[0022] 2) A question segment consists of a fixed question segment title and configurable question text. The question segment title defaults to the string "Question:". The question text is initialized to empty; if the question text is not empty, it is a piece of natural language text used to ask questions about the basic chemical concepts given in the text, or a piece of natural language text used to ask questions about one or more types of molecular characteristics given the molecular name or SELFIES molecular sequence in the text.

[0023] It should be noted that the knowledge scope corresponding to the basic chemical concepts in the embodiments of this invention includes at least the atomic model and quantum number, the principle of electron configuration and structure, the periodic table, the atomic structure and periodic properties of the periodic law, various chemical bond structures and their corresponding force and energy theories, intermolecular forces, chemical thermodynamics theory, chemical reaction theory, acid-base theory, redox theory, functional group theory, polymer theory, organic matter theory, inorganic matter theory, stereochemistry theory, physicochemical property theory, chemical nomenclature rules, quantum chemistry theory, and biological and pharmaceutical chemistry theory.

[0024] It should be noted that the knowledge scope corresponding to the molecular features in the embodiments of the present invention includes at least basic constituent features, two-dimensional structural features, three-dimensional structural features, physicochemical property features, spectroscopic features, crystallographic features, biological activity features, material performance features, and reaction features; basic constituent features include at least molecular formula, molecular mass, chemical formula, and isotopic composition; two-dimensional structural features include at least atomic connection sequence features, chemical bond features, functional group features, and atomic skeleton features; three-dimensional structural features include at least spatial geometric features, rotational conformation features, chiral features, and geometric isomerism features; physicochemical property features include at least melting point, boiling point, flash point, solubility, partition coefficient, vapor pressure, polarity, dipole moment, ionization energy, electron affinity, color, optical rotation, chemical stability, and acid / base dissociation constant; spectroscopic features include at least spectral features and mass spectrometry features.

[0025] The molecular generation instruction template of this invention consists of a generation instruction requirement section, a molecular description section, a reasoning step description section, and a formatting requirement section. Wherein: 1) The generation instruction requires a fixed natural language text to prompt the chemical large model to perform step-by-step analysis and reasoning based on the molecular description information given in the molecular description text, the step sequence given in the reasoning step description text, and to generate a SELFIES molecular sequence that conforms to chemical laws based on the reasoning context.

[0026] It should be noted that the specific text content of the instruction to generate the text in this embodiment of the invention can be customized based on application requirements or the developer's language habits. For example, "Based on the molecular description information provided below, perform step-by-step analysis according to the given reasoning steps, and finally generate a SELFIES molecular sequence that conforms to chemical laws, and output the obtained SELFIES molecular sequence based on the formatting requirements."

[0027] 2) A molecular description segment consists of a fixed description segment title and configurable molecular description text. The default description segment title is the string "Molecular Description:"; the molecular description text is initialized to empty. When the molecular description text is not empty, it is a natural language description of the molecular properties, which may include chemical symbols, molecular formulas, chemical equations and expressions, and may also include fragment sequence information in SELFIES format.

[0028] In practical applications, molecular description text is usually set based on the molecular description information input by the user, such as "This molecule is an aromatic compound containing a benzene ring, with the molecular formula C6H6, all atoms being carbon and hydrogen, and all hydrogen atoms on the benzene ring being saturated".

[0029] 3) The description text of the reasoning steps is a fixed natural language text, consisting of N reasoning step texts, where N is the total number of preset reasoning steps. Each reasoning step text is the step description text for one-step reasoning, used to prompt the chemical large model to perform analysis and reasoning according to the requirements of this step of reasoning based on the current reasoning context and use the result of this step of reasoning as the corresponding single-step reasoning text C i and output, where 1 ≤ index i ≤ N. The current reasoning context mentioned here includes: the molecular description information given by the molecular description text, and the reasoning results of all historical steps before the current reasoning step. The single-step reasoning text C corresponding to the Nth step i=N is the SELFIES molecular sequence generated by the model.

[0030] It should be noted that the specific text content of the reasoning step description text in the embodiments of the present invention can be customized based on application requirements or the developer's language habits. For example: The total number of reasoning steps N = 3, and the reasoning step description text is set as: "Step 1: Carefully read the molecular description, identify the types and quantities of atoms, the atomic skeleton, and key structural units (such as skeletons, side chain fragments, rings, functional groups, etc.) in the molecule; Step 2: Based on the analysis in Step 1, construct the two-dimensional structure of the molecule, including the connection relationships between atoms and the types of bonds; Step 3: Convert the molecular structure obtained in Step 2 into a SELFIES string, ensuring that the string can be correctly parsed and conforms to chemical rules".

[0031] 4) The formatting requirement text is a fixed natural language text, used to prompt the chemical large model to perform text encapsulation and output on the generated SELFIES molecular sequence according to the preset molecular sequence output format.

[0032] Here, the molecular sequence output format of the embodiments of the present invention is defaultly formed by sequentially connecting the preset start marker text, the SELFIES molecular sequence generated by the model, and the preset end marker text.

[0033] It should be noted that the specific text content of the formatting requirement text in the embodiments of the present invention can be customized based on application requirements or the developer's language habits.

[0034] For example, if the start marker text is "<molecular sequence>" and the end marker text is "< / molecular sequence>", the formatting requirement text is "Molecular description formatting requirement: The generated molecular description text must be output in the following format: <molecular sequence>... < / molecular sequence>".

[0035] Step 3: Construct a question-and-answer dataset by collecting big data from publicly available knowledge media in the field of chemistry; collect molecular sequences from publicly available molecular libraries, obtain molecular descriptions of each collected sequence by querying the molecular libraries, label the inference chain tags from each molecular description to its corresponding molecular sequence, construct an inference dataset based on all molecular descriptions and their corresponding inference chain tags, and construct a molecular dataset based on all molecular descriptions and their corresponding molecular sequences.

[0036] Specifically, it includes: Step 31: Construct a question-and-answer dataset by collecting big data from publicly available knowledge media in the field of chemistry.

[0037] Specifically, this includes: acquiring multiple knowledge entries through big data collection from publicly available knowledge media in the field of chemistry; configuring corresponding first training questions and first-label answers for each knowledge entry through manual or machine question-and-answer configuration; forming corresponding first data records from the first training questions and first-label answers for each knowledge entry; forming a corresponding first subset from all first data records corresponding to basic chemistry concept questions and answers through manual or machine classification operations, and forming a corresponding second subset from all first data records corresponding to molecular feature questions and answers; and forming a corresponding question-and-answer dataset from the obtained first subset and second subset.

[0038] Here, publicly available knowledge media in the field of chemistry include at least publicly available textbooks or theoretical books in the field of chemistry, publicly available journals or papers in the field of chemistry, and publicly available databases or molecular libraries in the field of chemistry. The knowledge domain scope of all knowledge entries obtained through big data collection is greater than or equal to the preset knowledge scope of basic chemical concepts and molecular characteristics; the knowledge scope of basic chemical concepts and molecular characteristics is the sum of the knowledge scope corresponding to the basic chemical concepts and the knowledge scope corresponding to the molecular characteristics.

[0039] The question-answering dataset of this invention includes a first subset and a second subset; both the first subset and the second subset consist of multiple first data records; the first data records include a first training question and a first labeled answer; the first training question of the first subset is a piece of natural language text used to ask questions about a given basic chemical concept in the text; the first training question of the second subset is a piece of natural language text used to ask questions about one or more types of molecular features given a molecular name or SELFIES molecular sequence in the text.

[0040] Step 32: Collect molecular sequences from the public molecular library, obtain molecular descriptions for each collected sequence by querying the molecular library, label the inference chain tags from each molecular description to its corresponding molecular sequence, construct an inference dataset based on all molecular descriptions and their corresponding inference chain tags, and construct a molecular dataset based on all molecular descriptions and their corresponding molecular sequences.

[0041] Specifically, it includes: Step 321: Perform big data collection on the SMILES and SELFIES molecular sequences in the publicly available molecular library to obtain multiple collected sequences that form the corresponding first sequence set.

[0042] The publicly available molecular databases include at least the PubChem database and the PDB database. The first sequence set includes multiple first sequences; each first sequence is a SMILES molecular sequence or a SELFIES molecular sequence.

[0043] Step 322: Each first sequence is used as the current sequence; a molecular summary or comprehensive description corresponding to the current sequence is obtained by querying the molecular library and used as a set of corresponding first and second molecular descriptions; the sequence format of the current sequence is identified as SELFIES sequence format. If it is, the current sequence is used as a corresponding first tag sequence; otherwise, a preset cheminformatics tool is used to convert the current sequence to SELFIES molecular sequence and the conversion result is used as a corresponding first tag sequence; a sequential traversal of all step description texts in the reasoning step description section of the molecular generation instruction template is performed; at the beginning of this traversal, the corresponding reasoning context is initialized to empty; during this traversal, the currently traversed step description text is used as the current step description, and according to the preset question construction rules, the current sequence, the current step description, and the reasoning context are combined to form a corresponding current question. The current question is then processed through a preset professional chemical question-and-answer interface, and the answer text obtained in this processing is used as a corresponding single-step reasoning tag. The current question and answer are combined to form a corresponding question-and-answer text context for inference; and at the end of this round of traversal, the N single-step inference tags obtained from this round of traversal are added. Form a corresponding first-label inference chain.

[0044] Here, the cheminformatics tools in this embodiment of the invention include at least the RDKit tool.

[0045] The problem-building rules in this embodiment of the invention are used to set analysis problems with the current sequence and reasoning context as reference contexts and the current step description as the current analysis target.

[0046] The professional chemistry question-and-answer interface in this invention is a type of human question-and-answer task processing interface for professional chemistry experts, a type of system question-and-answer task processing interface for professional chemistry question-and-answer systems, or a type of model question-and-answer task processing interface for large professional chemistry models.

[0047] Step 323, and each first molecular description and its corresponding first label inference chain form a corresponding second data record; each second molecular description and its corresponding first label sequence form a corresponding third data record; all the obtained second data records form a corresponding inference dataset; and all the obtained third data records form a corresponding molecular dataset.

[0048] The inference dataset of this embodiment includes multiple second data records; each second data record includes a first molecule description and a first label inference chain; the first label inference chain includes N single-step inference labels. .

[0049] The molecular dataset of this invention includes multiple third data records; the third data records include a second molecular description and a first tag sequence; the first tag sequence is a SELFIES molecular sequence.

[0050] Step 4: First, perform a first-stage chemical knowledge enhancement training on the large chemical model based on the chemical question-and-answer instruction template and question-and-answer dataset; then, perform a second-stage chemical reasoning ability enhancement training on the large chemical model based on the molecular generation instruction template and reasoning dataset; finally, perform a third-stage sequence generation ability enhancement training on the large chemical model based on the molecular generation instruction template and molecular dataset.

[0051] Specifically, it includes: Step 41: First, perform a phase of chemical knowledge enhancement training on the large chemical model based on the chemical question-and-answer instruction template and question-and-answer dataset.

[0052] Specifically, it includes: Step 411: Use the first subset of the question-and-answer dataset as the current dataset.

[0053] Step 412: Divide the current dataset into multiple first data batches based on the preset batch size B1; and take the first first data batch of the current dataset as the current data batch.

[0054] Here, the batch size B1 in this embodiment of the invention is a pre-set positive integer. Each first data batch includes B1 first data records; the first label answer of each first data record in each first data batch is denoted as the corresponding label answer. 1 ≤ index j ≤ B1; answers for each label The total number of word segments is denoted as n. j Answers under various tags Each word segment is recorded as the corresponding 1 ≤ index k ≤ n j .

[0055] Step 413: Substitute the first training question of each first data record in the current data batch into the chemical question-and-answer instruction template, and configure the question text of the template's question segment to obtain the corresponding current chemical question-and-answer instruction Q. j ; and will the current chemical question-and-answer command Q j The chemical large-scale model is input for question-answering task processing; the autoregressive text generation process of the chemical large-scale model is recorded during this processing; and after completing B1 model processing iterations, the first model loss function L is used as the basis for the calculation. M1 Calculate the corresponding first loss value.

[0056] Here, the first model loss function L in this embodiment of the invention M1 It is implemented based on the cross-entropy loss function, specifically as follows: .

[0057] in, For tagged answers The word segmentation sequence preceding the kth word; For the model in the autoregressive text generation process, the current chemical question-answering instruction Q is used. j and word segmentation sequence The k-th word generated for the context is the corresponding word. The probability of.

[0058] Step 414: Identify whether the first loss value meets the preset first loss value range; if not, then based on the preset first model optimizer, move towards making the first model loss function L... M1 The direction that reaches the minimum value is used to fine-tune the model parameters of the large chemical model, and after this round of fine-tuning is completed, return to step 413; if satisfied, proceed to step 415.

[0059] Here, the first loss value range in this embodiment of the invention is a pre-set numerical range. The first model optimizer includes the Adam optimizer, the SGD optimizer, and the AdamW optimizer.

[0060] Step 415: Identify whether the current data batch is the last first data batch of the current dataset; if not, take the next first data batch of the current dataset as the new current data batch and return to step 413; if yes, identify whether the current dataset is the first subset; if yes, take the second subset of the question-and-answer dataset as the new current dataset and return to step 412; otherwise, stop training and confirm the end of the first stage of training.

[0061] Step 42: Then, based on the molecular generation instruction template and the reasoning dataset, perform a second-stage chemical reasoning ability enhancement training on the large chemical model.

[0062] Specifically, it includes: Step 421: Divide the inference dataset into multiple second data batches based on the preset batch size B2; and take the first second data batch as the current data batch.

[0063] Here, the batch size B2 in this embodiment of the invention is a pre-set positive integer. Each second data batch includes B2 second data records; the first tag inference chain of each second data record in each second data batch is denoted as the corresponding tag chain. 1 ≤ index q ≤ B2; each tag chain Each single-step reasoning label Record as the corresponding single-step label Each single-step label The total number of word segments is denoted as n. q,i Each single-step label Each word segment is recorded as the corresponding 1 ≤ index s ≤ n q,i .

[0064] Step 422: Substitute the first molecular description of each second data record in the current data batch into the molecular generation instruction template, and configure the molecular description text of the template's molecular description segment to obtain the corresponding current molecular generation instruction X. q ; and the current molecule generation instruction X q The input is processed using a large-scale chemical model; the autoregressive text generation process of the large-scale chemical model is recorded during this processing; and after completing B2 iterations of model processing, the second model loss function L is used as the basis for the calculation. M2 Calculate the corresponding second loss value.

[0065] Here, the second model loss function L in this embodiment of the invention M2 It is implemented based on the cross-entropy loss function, specifically as follows: .

[0066] in, It is a sequence of single-step labels formed by concatenating the first i-1 single-step labels in sequence; Single-step label The word segmentation sequence preceding the s-th word; For the model in the autoregressive generation step of the inference text at step i, the corresponding molecular generation instruction X is used. qSingle-step label sequence and word segmentation sequence The s-th word generated for the context is the corresponding word. The probability of.

[0067] Step 423: Identify whether the second loss value meets the preset range of the second loss value; if not, then based on the preset second model optimizer, move towards making the second model loss function L... M2 The direction that reaches the minimum value is used to fine-tune the model parameters of the large chemical model in one round, and the process returns to step 422 after this round of fine-tuning. If the condition is met, it is determined whether the current data batch is the last second data batch. If not, the next second data batch is taken as the new current data batch and the process returns to step 422. If the condition is met, training is stopped and the end of the second stage of training is confirmed.

[0068] Here, the second loss value range in this embodiment of the invention is a pre-set numerical range. The second model optimizer includes the Adam optimizer, the SGD optimizer, and the AdamW optimizer.

[0069] Step 43: Finally, the chemical large model is trained in three stages to enhance its sequence generation capabilities based on the molecular generation instruction template and the molecular dataset.

[0070] Specifically, it includes: Step 43-1: The large chemical model is replicated to obtain two replicated models, and the current large chemical model is denoted as the corresponding new strategy model M. new The two replication models are denoted as the corresponding old policy models M. old Reference Model M ref and the reference model M ref The model parameters are solidified; the molecular dataset is divided into multiple third data batches based on the preset batch size B3; and the first third data batch is used as the current data batch.

[0071] Here, the new strategy model M of this invention embodiment new Old strategy model M old Reference Model M ref The model parameters are denoted as the corresponding model parameters θ. new Model parameters θ old Model parameters θ ref .

[0072] In this embodiment of the invention, the batch size B3 is a pre-set positive integer. Each data batch includes B3 third data records; the first tag sequence of each third data record in each data batch is denoted as the corresponding tag sequence. , 1≤index l≤B3.

[0073] Step 43-2: Take each third data record of the current data batch as the current record; substitute the second molecular description of the current record into the molecular generation instruction template, set the molecular description text of the template's molecular description segment to obtain the corresponding current molecular generation instruction; and continuously input the current molecular generation instruction into the old strategy model M G times. old The processing yields G corresponding predicted texts. And according to the formatting requirements of the molecular generation instruction template, the molecular sequence output format of the text segment is obtained from each predicted text. Extract the corresponding SELFIES molecular sequences as the corresponding predicted sequences. .

[0074] Here, the number of repeated operations G in this embodiment of the invention is a preset positive integer, where 1 ≤ index g ≤ G.

[0075] Various predicted texts in embodiments of the present invention The total number of word segments is recorded as the corresponding Each predicted text Each word segment is recorded as the corresponding , 1≤index t≤ Each segmentation The corresponding predicted probability is denoted as .

[0076] Step 43-3, for each predicted text The system identifies whether the text format meets the molecular sequence output format of the molecular generation instruction template; if it does, the corresponding format check result f is set. l,g Set the value to 1; if not satisfied, set the corresponding format check result f. l,g It is 0.

[0077] Step 43-4: Use cheminformatics tools to analyze each tag sequence. Predicted sequence The corresponding tag fingerprints are obtained by calculating the three types of molecular fingerprints. , , fingerprint prediction , , ; and used cheminformatics tools to analyze each tag sequence Predicted sequence The molecular side chains and functional groups are identified to obtain the corresponding tag side chain set. , collection of tagged functional groups Predictive sidechain set Predictive functional group set .

[0078] Here, the three types of molecular fingerprints in this embodiment of the invention include Morgan fingerprint, MACCS fingerprint, and RDKit fingerprint.

[0079] Tag sidechain set of embodiments of the present invention Or predict sidechain set When not empty, it consists of one or more sidechain segments.

[0080] Tag functional group set of embodiments of the present invention Or predict the collection of functional groups When not empty, it consists of one or more functional group segments, and each functional group segment corresponds to a functional group type.

[0081] Steps 43-5: For each predicted sequence Its corresponding label sequence The similarity of the four types of sequences is calculated, and the average of the four types of sequence similarity is used as the corresponding structural reward. ; and check the format results f l,g and structural rewards Calculate the corresponding generated reward R l,g .

[0082] Here, the four types of sequence similarity in this embodiment of the invention include sequence similarity. Fingerprint similarity Fragment similarity Functional group similarity .

[0083] Sequence similarity in embodiments of the present invention The calculation method is as follows: ; Here, BLEU() is the BLEU evaluation function.

[0084] Fingerprint similarity in embodiments of the present invention The calculation method is as follows: .

[0085] Among them, f s () represents a preset fingerprint similarity function, f. s This includes the Jaccard similarity function and the cosine similarity function.

[0086] Fragment similarity in embodiments of the present invention The calculation method is as follows: .

[0087] in, For predicting sidechain sets With tag sidechain collection The total number of overlapping segments; For predicting sidechain sets With tag sidechain collection The total number of segments in the collection; For tag sidechain collection The total number of segments.

[0088] It should be noted that when identifying overlapping segments, the similarity of the segment's molecular fingerprint is used to determine this. If the predicted sidechain set... A sidechain fragment and a set of tag sidechains If the molecular fingerprint similarity of a side chain fragment exceeds a preset fingerprint similarity threshold, the two are considered as overlapping fragments; when counting the total number of fragments in the set, overlapping fragments are only counted once.

[0089] It should also be noted that if predicting the sidechain set... With tag sidechain collection If all are empty, then The similarity is 0, at which point the segment similarity is zero. If predicting the sidechain set Empty, tag sidechain set If not empty, then the total number of fragments. , At this point, the similarity of the segments If predicting the sidechain set Non-empty, tag sidechain set If empty, then the total number of fragments , At this point, the similarity of the segments .

[0090] Functional group similarity in embodiments of the present invention The calculation method is as follows: .

[0091] Where U is the total number of preset functional group types, and 1 ≤ index u ≤ U.

[0092] For predicting functional group sets The statistical number of class u functional groups.

[0093] For tag functional groups collection The statistical number of class u functional groups.

[0094] It is a preset small constant that is greater than zero.

[0095] Structural rewards in embodiments of the present invention The calculation method is as follows: .

[0096] The generation reward R in this embodiment of the invention l,g The calculation method is as follows: .

[0097] Steps 43-6: Extract the label sequences from each data batch. The corresponding G prediction sequences Cluster them into groups; and generate an average reward µ for each group. l and standard deviation σ l Perform calculations; and based on each predicted sequence in each group. The corresponding generation reward R l,g Average value µ l and standard deviation σ l Calculate the corresponding within-group advantage V l,g .

[0098] Here, the average value µ in the embodiments of the present invention l Standard deviation σ l and group advantages V l,g The calculation method is as follows: , ; .

[0099] Wherein, λ1 is a preset small constant used to prevent the denominator from being zero, and its value is greater than zero.

[0100] Steps 43-7 involve substituting the second molecular description of each third data record in the current data batch into the molecular generation instruction template, setting the molecular description text of the template's molecular description segment to obtain the corresponding current molecular generation instruction, and then continuously inputting the current molecular generation instruction into the reference model M G times. ref Processing is performed; and in the g-th processing corresponding to the l-th third data record, the word probability vector corresponding to the t-th word segment generated by the model in this processing is compared with the corresponding predicted text. The t-th word The corresponding word segmentation prediction probability is extracted as the corresponding prediction probability. .

[0101] Steps 43-8 involve substituting the second molecular description of each third data record in the current data batch into the molecular generation instruction template, setting the molecular description text of the template's molecular description segment to obtain the corresponding current molecular generation instruction, and then continuously inputting the current molecular generation instruction into the new strategy model M G times. newProcessing is performed; and in the g-th processing corresponding to the l-th third data record, the word probability vector corresponding to the t-th word segment generated by the model in this processing is compared with the corresponding predicted text. The t-th word The corresponding word segmentation prediction probability is extracted as the corresponding prediction probability. .

[0102] Steps 43-9: For each predicted text Each word Importance sampling ratio r l,g,t And truncation sampling ratio Perform the calculation.

[0103] Here, the importance sampling ratio r of the embodiments of the present invention l,g,t And truncation sampling ratio The calculation method is as follows: , .

[0104] Where λ2 is the preset truncation threshold, and Clip() is the Clip truncation function.

[0105] Step 43-10, based on the preset third model loss function L M3 Calculate the corresponding third loss value.

[0106] Here, the third model loss function L in this embodiment of the invention M3 The objective function J based on the group relative strategy optimization algorithm GRPO The objective function J of the group relative strategy optimization algorithm is implemented. GRPO By strategy function term J policy , divergence function term J KL The composition is as follows: , , .

[0107] Where β is the preset divergence term coefficient.

[0108] Step 43-11: Identify whether the third loss value meets the preset range of the third loss value; if the third loss value does not meet the range of the third loss value, then based on the preset third model optimizer, move towards making the third model loss function L... M3 The direction that reaches the minimum value corresponds to the new strategy model M new Model parameters θ new Perform one round of modulation and return to step 43-2 at the end of this round of modulation; if the third loss value meets the range of the third loss value, then based on the model parameter θnew For the old strategy model M old Model parameters θ old Perform a reset and identify whether the current data batch is the last third data batch. If not, use the next third data batch as the new current data batch and return to step 43-2. ​​If it is, stop training, confirm the end of the three-stage training, and set the new policy model M. new As the latest large-scale chemical model.

[0109] Here, the third loss value range in this embodiment of the invention is a pre-set numerical range. The third model optimizer includes the Adam optimizer and the AdamW optimizer.

[0110] Step 5: After the three-stage training is completed, the molecular description input by the user is received as the current description; the current description is substituted into the molecular generation instruction template, and the molecular description text of the template's molecular description segment is configured to obtain the corresponding current molecular generation instruction; the current molecular generation instruction is input into the chemical large model for molecular generation task processing; and the molecular sequence output by the model in this processing is fed back to the current user.

[0111] Figure 2 This is a module structure diagram of a processing device for generating molecular sequences based on a large chemical model, provided in Embodiment 2 of the present invention. This device can be a terminal device or server implementing the aforementioned method embodiments, or it can be a device that enables the aforementioned terminal device or server to implement the aforementioned method embodiments. For example, the device can be a device or chip system of the aforementioned terminal device or server. Figure 2 As shown, the device includes: a model selection module 201, a template customization module 202, a dataset construction module 203, a model training module 204, and a model application module 205.

[0112] The model selection module 201 is used to select a general-purpose large language model that has completed pre-training for both large language models and general NLP tasks as the corresponding chemical large model; the general-purpose large language models include at least the Qwen series models, GPT series models, and DeepSeek series models; the general-purpose NLP tasks include at least text generation tasks, translation tasks, question answering tasks, and thought chain derivation tasks.

[0113] The template customization module 202 is used to configure corresponding chemical question and answer instruction templates and molecular generation instruction templates for large chemical models.

[0114] The dataset construction module 203 is used to construct a question-and-answer dataset by collecting big data from publicly available chemical professional knowledge media; and to collect big data from molecular sequences in publicly available molecular libraries, obtain molecular descriptions of each collected sequence by querying the molecular library, and label the inference chain tags from each molecular description to its corresponding molecular sequence, and construct an inference dataset based on all molecular descriptions and their corresponding inference chain tags, and construct a molecular dataset based on all molecular descriptions and their corresponding molecular sequences.

[0115] The model training module 204 is used to first perform a first-stage chemical knowledge enhancement training on the large chemical model based on the chemical question-and-answer instruction template and the question-and-answer dataset; then perform a second-stage chemical reasoning ability enhancement training on the large chemical model based on the molecular generation instruction template and the reasoning dataset; and finally perform a third-stage sequence generation ability enhancement training on the large chemical model based on the molecular generation instruction template and the molecular dataset.

[0116] The model application module 205 is used to receive the molecular description input by the user as the current description after the three-stage training is completed; substitute the current description into the molecular generation instruction template, configure the molecular description text of the molecular description segment of the template to obtain the corresponding current molecular generation instruction; input the current molecular generation instruction into the chemical large model for molecular generation task processing; and feed back the molecular sequence output by the model in this processing to the current user.

[0117] The present invention provides a processing device for generating molecular sequences based on a large chemical model, which can execute the method steps in the above method embodiments. Its implementation principle and technical effect are similar, and will not be repeated here.

[0118] It should be noted that the division of the various modules in the above device is merely a logical functional division. In actual implementation, they can be fully or partially integrated into a single physical entity, or they can be physically separated. Furthermore, these modules can be implemented entirely in software via processing element calls; they can be fully implemented in hardware; or some modules can be implemented by processing element calls to software, while others are implemented in hardware. For example, the model selection module can be a separate processing element, or it can be integrated into a chip in the above device. Alternatively, it can be stored as program code in the memory of the above device, and called and executed by a processing element of the device. The implementation of other modules is similar. Moreover, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element described here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each of the above modules can be completed through integrated logic circuits in the hardware of the processor element or through software instructions.

[0119] For example, these modules can be one or more integrated circuits configured to implement the above methods, such as one or more Application Specific Integrated Circuits (ASICs), one or more Digital Signal Processors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs). As another example, when a module is implemented using processing element scheduler code, the processing element can be a general-purpose processor, such as a Central Processing Unit (CPU) or other processor capable of calling program code. Furthermore, these modules can be integrated together as a System-on-a-Chip (SOC).

[0120] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. This computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the foregoing method embodiments are generated. The computer described above can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The aforementioned computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the aforementioned computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, Bluetooth, microwave, etc.) means. The aforementioned computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The aforementioned available media can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state disks (SSDs)).

[0121] Figure 3 This is a schematic diagram of an electronic device provided in Embodiment 3 of the present invention. This electronic device can be a terminal device or server implementing the methods of the aforementioned embodiments, or it can be a terminal device or server connected to the aforementioned terminal device or server implementing the methods of the aforementioned embodiments. Figure 3As shown, the electronic device may include: a processor 301 (e.g., CPU), a memory 302, and a transceiver 303; the transceiver 303 is coupled to the processor 301, and the processor 301 controls the transmission and reception operations of the transceiver 303. The memory 302 may store various instructions for performing various processing functions and implementing the processing steps described in the foregoing embodiments. Preferably, the electronic device involved in the embodiments of the present invention further includes: a power supply 304, a system bus 305, and a communication port 306. The system bus 305 is used to realize communication connections between components. The communication port 306 is used for communication between the electronic device and other peripherals.

[0122] exist Figure 3 The system bus 305 mentioned can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This system bus can be divided into address bus, data bus, control bus, etc. For ease of representation, it is represented by only one thick line in the figure, but this does not indicate that there is only one bus or one type of bus. The communication interface is used to enable communication between the database access device and other devices (e.g., clients, read-write libraries, and read-only libraries). Memory may include Random Access Memory (RAM) and may also include Non-Volatile Memory, such as at least one disk storage device.

[0123] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), graphics processing units (GPUs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0124] It should be noted that the embodiments of the present invention also provide a computer-readable storage medium storing instructions that, when run on a computer, cause the computer to perform the methods and processes provided in the above embodiments.

[0125] This invention provides a method, apparatus, electronic device, and computer-readable storage medium for generating molecular sequences based on a large chemical model. As described above, this invention selects a general-purpose large language model as the large chemical model, configures corresponding chemical question-and-answer instruction templates and molecular generation instruction templates for it, and constructs corresponding question-and-answer datasets, inference datasets, and molecular datasets. First, the large chemical model undergoes a first-stage chemical knowledge enhancement training based on the chemical question-and-answer instruction templates and the question-and-answer dataset. Then, a second-stage chemical reasoning ability enhancement training is conducted based on the molecular generation instruction templates and the inference dataset. Finally, a third-stage sequence generation ability enhancement training is conducted based on the molecular generation instruction templates and the molecular dataset. After the three-stage training, the user's molecular generation task is processed based on the end-to-end large chemical model. This invention improves the model's understanding and parsing ability of specialized chemical knowledge, enhances the model's chemical knowledge reasoning ability, and improves the chemical accuracy and rationality of the generated molecular sequences.

[0126] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented in hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0127] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for generating molecular sequences based on a large chemical model, characterized in that, The method includes: Select a general-purpose language model that has completed pre-training for both large language models and general NLP tasks as the corresponding chemical large model; the general-purpose language model includes at least the Qwen series models, GPT series models, and DeepSeek series models; the general-purpose NLP tasks include at least text generation tasks, translation tasks, question answering tasks, and thought chain deduction tasks; Configure corresponding chemical question-and-answer instruction templates and molecular generation instruction templates for the aforementioned large chemical model; A question-and-answer dataset is constructed by collecting big data from publicly available knowledge media in the field of chemistry; a molecular sequence dataset is constructed by collecting big data from publicly available molecular libraries, and molecular descriptions of each collected sequence are obtained by querying the molecular libraries. Inference chain tags from each molecular description to its corresponding molecular sequence are labeled, and an inference dataset is constructed based on all molecular descriptions and their corresponding inference chain tags. A molecular dataset is constructed based on all molecular descriptions and their corresponding molecular sequences. First, the chemical large model undergoes a first-stage chemical knowledge enhancement training based on the chemical question-and-answer instruction template and the question-and-answer dataset; then, the chemical large model undergoes a second-stage chemical reasoning ability enhancement training based on the molecular generation instruction template and the reasoning dataset; finally, the chemical large model undergoes a third-stage sequence generation ability enhancement training based on the molecular generation instruction template and the molecular dataset. After the three-stage training is completed, the molecular description input by the user is received as the current description; the current description is then substituted into the molecular generation instruction template, and the molecular description text of the template's molecular description segment is configured to obtain the corresponding current molecular generation instruction; the current molecular generation instruction is then input into the large chemical model for molecular generation task processing; and the molecular sequence output by the model in this processing is fed back to the current user.

2. The method for generating molecular sequences based on a large chemical model according to claim 1, characterized in that, The chemical Q&A instruction template consists of a Q&A instruction requirement text and a question text; The question-and-answer instruction requires the text to be a fixed natural language text, which is used to prompt the chemical big model to generate a corresponding answer based on the given question in the question text; The question segment consists of a fixed question segment title and configurable question text; the question segment title defaults to the string "Question:"; the question text is initialized to empty; when the question text is not empty, it is a piece of natural language text used to ask questions about the basic chemical concepts given in the text or a piece of natural language text used to ask questions about one or more types of molecular features given the molecular name or SELFIES molecular sequence in the text. The knowledge scope corresponding to basic chemical concepts includes at least the atomic model and quantum numbers, the principle of electron configuration and structure, the periodic table, the atomic structure and periodic properties of the periodic law, various chemical bond structures and their corresponding force and energy theories, intermolecular forces, chemical thermodynamics theory, chemical reaction theory, acid-base theory, redox theory, functional group theory, polymer theory, organic matter theory, inorganic matter theory, stereochemistry theory, physicochemical property theory, chemical nomenclature rules, quantum chemistry theory, and biological and pharmaceutical chemistry theory. The knowledge scope corresponding to molecular characteristics includes at least the basic composition characteristics, two-dimensional structural characteristics, three-dimensional structural characteristics, physicochemical property characteristics, spectroscopic characteristics, crystallographic characteristics, biological activity characteristics, material performance characteristics, and reaction characteristics; The basic structural features include at least molecular formula, molecular mass, chemical formula, and isotopic composition; the two-dimensional structural features include at least atomic connection sequence, chemical bond, functional group, and atomic skeleton features; the three-dimensional structural features include at least spatial geometric features, rotational conformation features, chiral features, and geometric isomerism features; the physicochemical properties include at least melting point, boiling point, flash point, solubility, partition coefficient, vapor pressure, polarity, dipole moment, ionization energy, electron affinity, color, optical rotation, chemical stability, and acid / base dissociation constant; the spectroscopic features include at least spectral features and mass spectrometry features. The molecule generation instruction template consists of a generation instruction requirement section, a molecule description section, a reasoning step description section, and a formatting requirement section; The generation instruction requires the text segment to be a fixed natural language text, which is used to prompt the chemical big model to perform step-by-step analysis and reasoning based on the molecular description information given in the molecular description text segment, the step sequence given in the reasoning step description text segment, and generate a SELFIES molecular sequence that conforms to chemical laws based on the reasoning context. The molecular description segment consists of a fixed description segment title and configurable molecular description text; the description segment title defaults to the string "Molecular Description:"; the molecular description text is initialized to empty; The inference step description is a fixed natural language text consisting of N inference step texts, where N is the preset total number of inference steps. Each inference step text is a step description text for one step of inference, used to prompt the chemical macro-model to perform analysis and inference according to the requirements of this step and the current inference context, and to take the result of this step as the corresponding single-step inference text C. i And output, 1≤index i≤N; the current inference context includes the molecular description information given by the molecular description text, the inference results of all historical steps before the current inference step; the single-step inference text C corresponding to the Nth step. i=N SELFIES molecular sequences generated for the model; The formatting requirement text is a fixed natural language text used to prompt the chemical model to encapsulate and output the generated SELFIES molecular sequences in a preset molecular sequence output format. The molecular sequence output format is formed by connecting the preset start marker text, the model-generated SELFIES molecular sequences, and the preset end marker text in sequence. The publicly available knowledge media in the field of chemistry include at least publicly available textbooks or theoretical books in the field of chemistry, publicly available journals or papers in the field of chemistry, and publicly available databases or molecular libraries in the field of chemistry. The publicly available molecular databases include at least the PubChem database and the PDB database; The question-and-answer dataset includes a first subset and a second subset; both the first subset and the second subset consist of multiple first data records; the first data records include a first training question and a first labeled answer; the first training question of the first subset is a piece of natural language text used to ask questions about a given basic chemical concept within the text; the first training question of the second subset is a piece of natural language text used to ask questions about one or more types of molecular features given a molecular name or SELFIES molecular sequence within the text; The inference dataset includes multiple second data records; each second data record includes a first molecule description and a first label inference chain; the first label inference chain includes N single-step inference labels. ; The molecular dataset includes multiple third data records; each third data record includes a second molecular description and a first tag sequence; the first tag sequence is a SELFIES molecular sequence.

3. The method for generating molecular sequences based on a large chemical model according to claim 2, characterized in that, The method of constructing a question-and-answer dataset by collecting big data from publicly available knowledge media in the field of chemistry specifically includes: Multiple knowledge entries are obtained by collecting big data from the publicly available chemical professional knowledge media; and each knowledge entry is configured with a corresponding first training question and a first tag answer through manual or machine question-and-answer configuration; the first training question and the first tag answer corresponding to each knowledge entry form a corresponding first data record; and through manual or machine classification, all the first data records corresponding to basic chemical concept questions and answers form a corresponding first subset, and all the first data records corresponding to molecular feature questions and answers form a corresponding second subset; and the obtained first subset and the second subset form a corresponding question-and-answer dataset. Among them, the knowledge domain of all knowledge items obtained through big data collection is greater than or equal to the preset knowledge domain of basic chemical concepts and molecular characteristics; the knowledge domain of basic chemical concepts and molecular characteristics is the combination of the knowledge domain corresponding to the basic chemical concepts and the knowledge domain corresponding to the molecular characteristics.

4. The method for generating molecular sequences based on a large chemical model according to claim 2, characterized in that, The process involves large-scale data collection of molecular sequences from publicly available molecular libraries, obtaining molecular descriptions for each collected sequence by querying the molecular libraries, labeling the inference chain tags from each molecular description to its corresponding molecular sequence, constructing an inference dataset based on all molecular descriptions and their corresponding inference chain tags, and constructing a molecular dataset based on all molecular descriptions and their corresponding molecular sequences. Specifically, this includes: A first sequence set is formed by collecting multiple sequences from the SMILES and SELFIES molecular sequences in the publicly available molecular library; the first sequence set includes multiple first sequences; each first sequence is a SMILES molecular sequence or a SELFIES molecular sequence. Each of the first sequences is taken as the current sequence; a molecular summary or comprehensive description corresponding to the current sequence is obtained by querying the molecular library and used as a set of corresponding first molecular descriptions and second molecular descriptions; the sequence format of the current sequence is identified as SELFIES sequence format. If it is, the current sequence is taken as a corresponding first tag sequence; otherwise, a preset cheminformatics tool is used to convert the current sequence into a SELFIES molecular sequence and the conversion result is taken as a corresponding first tag sequence; all the step description texts of the reasoning step description section of the molecular generation instruction template are sequentially traversed; at the beginning of this round of traversal, the corresponding reasoning context is initialized to empty; during this round of traversal, the step description text of the current traversal is taken as the current step description, and a corresponding current question is formed by the current sequence, the current step description, and the reasoning context according to the preset question construction rules. The current question is processed through a preset professional chemical question-and-answer interface, and the answer text obtained in this processing is taken as a corresponding single-step reasoning tag. The current question and answer are combined to form a corresponding question-and-answer text pair, which is then added to the reasoning context. At the end of this round of traversal, the N single-step reasoning tags obtained from this round of traversal are... A corresponding first tag inference chain is formed; wherein, the cheminformatics tool includes at least the RDKit tool; the question construction rule is used to set the analysis question with the current sequence and the inference context as reference context and the current step description as the current analysis target; the professional chemistry question answering interface is a type of human question answering task processing interface for professional chemistry experts, a type of system question answering task processing interface for professional chemistry question answering system, or a type of model question answering task processing interface for professional chemistry large model; Each of the first molecular descriptions and their corresponding first tag inference chains forms a corresponding second data record; each of the second molecular descriptions and their corresponding first tag sequences forms a corresponding third data record; all the obtained second data records form the corresponding inference dataset; and all the obtained third data records form the corresponding molecular dataset.

5. The method for generating molecular sequences based on a large chemical model according to claim 2, characterized in that, The step of performing a first-stage chemical knowledge enhancement training on the large chemical model based on the chemical question-and-answer instruction template and the question-and-answer dataset specifically includes: Step 51: Take the first subset of the question-and-answer dataset as the current dataset; Step 52: Divide the current dataset into multiple first data batches based on a preset batch size B1; and take the first first data batch of the current dataset as the current data batch; Each first data batch includes B1 first data records; the first tag answer of each first data record in each first data batch is denoted as the corresponding tag answer. , 1 ≤ index j ≤ B1; each of the stated label answers The total number of word segments is denoted as n. j Each of the aforementioned tagged answers Each word segment is recorded as the corresponding 1 ≤ index k ≤ n j ; Step 53: Substitute the first training question of each first data record in the current data batch into the chemical question-and-answer instruction template, and configure the question text of the question segment in the template to obtain the corresponding current chemical question-and-answer instruction Q. j ; and the current chemical question-and-answer command Q j The chemical model is input for question-answering task processing; the autoregressive text generation process of the chemical model during this processing is recorded; and after completing B1 model processing iterations, the first model loss function L is used as the basis for the calculation. M1 Calculate the corresponding first loss value; Wherein, the first model loss function L M1 It is implemented based on the cross-entropy loss function, specifically as follows: ; For the tagged answer The word segmentation sequence preceding the kth word; For the model in the autoregressive text generation process, the current chemical question-answering instruction Q is used. j and word segmentation sequence The k-th word generated for the context is the corresponding word. The probability of; Step 54: Identify whether the first loss value meets the preset first loss value range; if not, then based on the preset first model optimizer, move towards making the first model loss function L... M1 The model parameters of the large chemical model are fine-tuned in the direction that reaches the minimum value, and the process returns to step 53 after this round of fine-tuning is completed; if the condition is met, proceed to step 55. The first model optimizer includes the Adam optimizer, the SGD optimizer, and the AdamW optimizer. Step 55: Identify whether the current data batch is the last first data batch of the current dataset; if not, take the next first data batch of the current dataset as the new current data batch and return to step 53; if yes, identify whether the current dataset is the first subset; if yes, take the second subset of the question-and-answer dataset as the new current dataset and return to step 52; otherwise, stop training and confirm the end of the first stage of training.

6. The method for generating molecular sequences based on a large chemical model according to claim 2, characterized in that, The step of performing a two-stage chemical reasoning capability enhancement training on the large chemical model based on the molecular generation instruction template and the reasoning dataset specifically includes: Step 61: Divide the inference dataset into multiple second data batches based on a preset batch size B2; and use the first second data batch as the current data batch; Each second data batch includes B2 second data records; the first tag inference chain of each second data record in each second data batch is denoted as the corresponding tag chain. , 1 ≤ index q ≤ B2; each of the stated tag chains Each of the aforementioned single-step reasoning tags Record as the corresponding single-step label Each of the aforementioned single-step labels The total number of word segments is denoted as n. q,i Each of the aforementioned single-step labels Each word segment is recorded as the corresponding 1 ≤ index s ≤ n q,i ; Step 62: Substitute the first molecular description of each second data record in the current data batch into the molecular generation instruction template, and configure the molecular description text of the molecular description segment in the template to obtain the corresponding current molecular generation instruction X. q ; and the current molecule generation instruction X q The input chemical model is processed; the autoregressive text generation process of the chemical model during this processing is recorded; and after completing B2 model processing iterations, the second model loss function L is used as the basis for the processing. M2 Calculate the corresponding second loss value; Wherein, the second model loss function L M2 It is implemented based on the cross-entropy loss function, specifically as follows: ; It is a sequence of single-step labels formed by concatenating the first i-1 single-step labels in sequence; For the single-step label The word segmentation sequence preceding the s-th word; For the model in the autoregressive generation step of the inference text at step i, the corresponding molecular generation instruction X is used. q Single-step label sequence and word segmentation sequence The s-th word generated for the context is the corresponding word. The probability of; Step 63: Identify whether the second loss value meets the preset second loss value range; if not, then based on the preset second model optimizer, move towards making the second model loss function L... M2 The model parameters of the chemical model are fine-tuned in the direction of reaching the minimum value, and the process returns to step 62 after the fine-tuning is completed. If the condition is met, it is identified whether the current data batch is the last second data batch. If not, the next second data batch is taken as the new current data batch and the process returns to step 62. If the condition is met, training is stopped and the end of the second stage training is confirmed. The second model optimizer includes the Adam optimizer, the SGD optimizer, and the AdamW optimizer.

7. The method for generating molecular sequences based on a large chemical model according to claim 2, characterized in that, The three-stage sequence generation capability enhancement training of the large chemical model based on the molecular generation instruction template and the molecular dataset specifically includes: Step 7-1: The chemical macro model is replicated to obtain two replicated models, and the current chemical macro model is denoted as the corresponding new strategy model M. new The two replication models are denoted as the corresponding old policy models M. old Reference Model M ref and the reference model M ref The model parameters are solidified; and the molecular dataset is divided into multiple third data batches based on a preset batch size B3; and the first third data batch is taken as the current data batch. Among them, the new strategy model M new The old strategy model M old The reference model M ref The model parameters are denoted as the corresponding model parameters θ. new Model parameters θ old Model parameters θ ref ; Each data batch includes B3 third data records; the first tag sequence of each third data record in each data batch is denoted as the corresponding tag sequence. , 1 ≤ index l ≤ B3; Step 7-2: Take each of the third data records in the current data batch as the current record; substitute the second molecular description of the current record into the molecular generation instruction template, set the molecular description text of the molecular description segment in the template to obtain the corresponding current molecular generation instruction; and continuously input the current molecular generation instruction into the old strategy model M G times. old The processing yields G corresponding predicted texts. ; and according to the formatting requirements of the molecular generation instruction template, the molecular sequence output format is obtained from each of the predicted texts. Extract the corresponding SELFIES molecular sequences as the corresponding predicted sequences. ; Wherein, the number of repeated operations G is a preset positive integer, 1≤index g≤G; Each of the predicted texts The total number of word segments is recorded as the corresponding Each of the predicted texts Each word segment is recorded as the corresponding 1≤index t≤ Each word segmentation The corresponding predicted probability is denoted as ; Step 7-3, for each of the predicted texts The system identifies whether the text format meets the molecular sequence output format of the molecular generation instruction template; if it does, the corresponding format check result f is set. l,g Set the value to 1; if the condition is not met, set the corresponding format check result f. l,g =0; Step 7-4: Use preset cheminformatics tools to analyze each of the stated tag sequences. The predicted sequence The corresponding tag fingerprints are obtained by calculating the three types of molecular fingerprints. , , fingerprint prediction , , ; and using the cheminformatics tools to analyze each of the tag sequences. The predicted sequence The molecular side chains and functional groups are identified to obtain the corresponding tag side chain set. , collection of tagged functional groups Predictive sidechain set Predictive functional group set ; The three types of molecular fingerprints include Morgan fingerprints, MACCS fingerprints, and RDKit fingerprints; The cheminformatics tools include at least the RDKit tool; The tag sidechain set or the predicted sidechain set When not empty, it consists of one or more sidechain fragments; the tag functional group set or the set of predictive functional groups When not empty, it consists of one or more functional group segments, and each functional group segment corresponds to a functional group type; Step 7-5, for each of the predicted sequences The corresponding tag sequence The similarity of the four types of sequences is calculated, and the average of the four types of sequence similarity is used as the corresponding structural reward. ; and check the result f according to the stated format. l,g and the structural reward Calculate the corresponding generated reward R l,g ; Among them, the four types of sequence similarity include sequence similarity fingerprint similarity Fragment similarity Functional group similarity ; sequence similarity The calculation method is as follows: ; BLEU() is the BLEU evaluation function; fingerprint similarity The calculation method is as follows: , f s () represents a preset fingerprint similarity function, f. s Including the Jaccard similarity function and the cosine similarity function; The similarity of the segments The calculation method is as follows: ; For the predicted sidechain set With the set of tag sidechains The total number of overlapping segments; For the predicted sidechain set With the set of tag sidechains The total number of segments in the collection; For the set of tag sidechains The total number of segments; when confirming overlapping segments, the similarity of the segment molecular fingerprint is calculated to determine if the predicted sidechain set... One of the sidechain fragments and the tag sidechain set If the molecular fingerprint similarity of a side chain fragment exceeds a preset fingerprint similarity threshold, the two are considered as overlapping fragments; when counting the total number of fragments in the set, overlapping fragments are only counted once; The functional group similarity The calculation method is as follows: ; U is the total number of preset functional group types, where 1 ≤ index u ≤ U; The set of predictable functional groups The statistical number of class u functional groups; The set of tag functional groups The statistical number of class u functional groups; A preset small constant that is greater than zero; The structural reward The calculation method is as follows: ; The generated reward R l,g The calculation method is as follows: ; Step 7-6, The tag sequences of the current data batch are... The corresponding G predicted sequences Cluster them into groups; and generate an average reward µ for each group. l and standard deviation σ l Perform calculations; and based on each of the predicted sequences in each group. The corresponding generated reward R l,g The average value µ l and the standard deviation σ l Calculate the corresponding within-group advantage V l,g ; Wherein, the average value µ l The standard deviation σ l and the aforementioned intra-group advantage V l,g The calculation method is as follows: , ; ; λ1 is a preset small constant used to prevent the denominator from being zero, and its value is greater than zero; Step 7-7: Substitute the second molecular description of each of the third data records in the current data batch into the molecular generation instruction template, set the molecular description text of the molecular description segment in the template to obtain the corresponding current molecular generation instruction; and continuously input the current molecular generation instruction into the reference model M G times. ref Processing is performed; and in the g-th processing corresponding to the l-th third data record, the word probability vector corresponding to the t-th word segment generated by the model in this processing is compared with the corresponding predicted text. The t-th segmentation The corresponding word segmentation prediction probability is extracted as the corresponding prediction probability. ; Steps 7-8: Substitute the second molecular description of each of the third data records in the current data batch into the molecular generation instruction template, set the molecular description text of the molecular description segment in the template to obtain the corresponding current molecular generation instruction; and continuously input the current molecular generation instruction into the new strategy model M G times. new Processing is performed; and in the g-th processing corresponding to the l-th third data record, the word probability vector corresponding to the t-th word segment generated by the model in this processing is compared with the corresponding predicted text. The t-th segmentation The corresponding word segmentation prediction probability is extracted as the corresponding prediction probability. ; Steps 7-9: For each of the predicted texts Each of the aforementioned words Importance of sampling ratio r l,g,t And truncation sampling ratio Perform calculations; Wherein, the importance sampling ratio r l,g,t and the truncation sampling ratio The calculation method is as follows: , ; λ2 is the preset truncation threshold, and Clip() is the Clip truncation function; Steps 7-10: Based on the preset third model loss function L M3 Calculate the corresponding third loss value; Wherein, the third model loss function L M3 The objective function J based on the group relative strategy optimization algorithm GRPO To achieve this, the objective function J of the group relative strategy optimization algorithm is... GRPO By strategy function term J policy , divergence function term J KL The composition is as follows: , , ; β is the preset divergence coefficient; Steps 7-11 involve identifying whether the third loss value meets a preset range; if the third loss value does not meet the preset range, the third model optimizer is then used to optimize the third model loss function L. M3 The direction for reaching the minimum value corresponds to the new strategy model M. new The model parameters θ new Perform one round of modulation, and return to step 7-2 at the end of this round of modulation; if the third loss value meets the range of the third loss value, then based on the model parameter θ new For the old strategy model M old The model parameters θ old Perform a reset and identify whether the current data batch is the last of the third data batch. If not, use the next third data batch as the new current data batch and return to step 7-2. If yes, stop training, confirm the end of the three-stage training, and set the new policy model M. new As the latest version of the aforementioned large chemical model; The third model optimizer includes the Adam optimizer and the AdamW optimizer.

8. An apparatus for performing the processing method for generating molecular sequences based on a large chemical model as described in any one of claims 1-7, characterized in that, The device includes: a model selection module, a template customization module, a dataset construction module, a model training module, and a model application module; The model selection module is used to select a general-purpose language model that has completed pre-training for both large language models and general NLP tasks as the corresponding chemical large model; the general-purpose language model includes at least the Qwen series models, GPT series models, and DeepSeek series models; the general-purpose NLP tasks include at least text generation tasks, translation tasks, question answering tasks, and thought chain derivation tasks; The template customization module is used to configure corresponding chemical question-and-answer instruction templates and molecular generation instruction templates for the large chemical model. The dataset construction module is used to construct a question-and-answer dataset by collecting big data from publicly available chemical professional knowledge media; and to collect big data from molecular sequences in publicly available molecular libraries, obtain molecular descriptions of each collected sequence by querying the molecular library, and label the inference chain tags from each molecular description to its corresponding molecular sequence, and construct an inference dataset based on all molecular descriptions and their corresponding inference chain tags, and construct a molecular dataset based on all molecular descriptions and their corresponding molecular sequences. The model training module is used to first perform a first-stage chemical knowledge enhancement training on the large chemical model based on the chemical question-and-answer instruction template and the question-and-answer dataset; then perform a second-stage chemical reasoning ability enhancement training on the large chemical model based on the molecular generation instruction template and the reasoning dataset; and finally perform a third-stage sequence generation ability enhancement training on the large chemical model based on the molecular generation instruction template and the molecular dataset. The model application module is used to receive the molecular description input by the user as the current description after the three-stage training is completed; substitute the current description into the molecular generation instruction template, configure the molecular description text of the molecular description segment of the template to obtain the corresponding current molecular generation instruction; input the current molecular generation instruction into the chemical large model for molecular generation task processing; and feed back the molecular sequence output by the model in this processing to the current user.

9. An electronic device, characterized in that, include: Memory, processor, and transceiver; The processor is configured to be coupled to the memory, read and execute instructions in the memory to implement the method according to any one of claims 1-7; The transceiver is coupled to the processor, and the processor controls the transceiver to send and receive messages.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a computer, cause the computer to perform the method described in any one of claims 1-7.