Method and system for detecting abnormal conditions in a synthesis reaction process for pharmaceutical intermediates

By dividing the drug intermediate synthesis reaction process into stages and modeling the variable coupling, dynamic time warping, and combining multi-scale dilated convolution and stage-aware feature aggregation, the problem of misjudgment of abnormal states in the drug intermediate synthesis reaction process is solved, and more accurate anomaly detection is achieved.

CN122135828BActive Publication Date: 2026-07-14SHANDONG INST FOR FOOD & DRUG CONTROL

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHANDONG INST FOR FOOD & DRUG CONTROL
Filing Date
2026-05-07
Publication Date
2026-07-14

AI Technical Summary

Technical Problem

Existing technologies struggle to distinguish between normal control and regulation and actual abnormal reactions during the synthesis of drug intermediates, resulting in a high false alarm rate and failing to effectively provide early warnings of multivariate linkages in the early stages of abnormalities.

Method used

By dividing the reaction process into different stages, variable coupling modeling and dynamic time warping are performed. After alignment, feature decoupling is performed, and abnormal patterns are extracted using multi-scale dilated convolution. Classification is then performed through stage-aware feature aggregation and global temporal aggregation.

Benefits of technology

It improves the ability to distinguish subtle anomalies, reduces the false positive rate, and enables real-time and accurate detection of abnormal states in the synthesis reaction process of drug intermediates.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122135828B_ABST
    Figure CN122135828B_ABST
Patent Text Reader

Abstract

The application relates to an abnormal state detection method and system for a drug intermediate synthesis reaction process, and belongs to the technical field of abnormal state detection. The method comprises the following steps: collecting reaction process data, marking, and constructing a data set; dividing a process stage according to stage coding, completing variable coupling modeling, dynamic time warping alignment and feature decoupling in the stage, and obtaining a reconstructed feature matrix; extracting different time span abnormal patterns through time sequence convolution and multi-scale hollow convolution, combining channel attention to enhance key features to obtain an encoding feature matrix, performing stage perception feature aggregation and global time sequence aggregation to obtain a final classification feature vector, inputting the classification feature vector into four stage independent classification heads to output a classification result; and in the training process, jointly optimizing through a cross-entropy loss with label smoothing and a focal loss. The application can eliminate batch process rhythm differences, distinguish normal regulation and real abnormalities, and accurately capture early weak abnormalities.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of abnormal state detection technology, specifically relating to an abnormal state detection method and system for the synthesis reaction process of drug intermediates. Background Technology

[0002] The synthesis of pharmaceutical intermediates is a crucial step in the pharmaceutical industry, and its reaction processes are typically multi-stage, nonlinear, and strongly coupled. A complete synthesis reaction often follows a pre-set process schedule, sequentially undergoing multiple process stages, such as heating, dropping, curing, and cooling. In each stage, multiple process parameters within the reactor, such as temperature, pressure, pH, stirring current, dropping rate, and cooling water flow rate, are coupled and change synergistically, jointly determining the course of the reaction and the quality of the final product. Any abnormal deviation from these critical parameters can lead to increased side reactions, decreased product yield, excessive impurities, or even runaway reactions and safety incidents. Therefore, real-time and accurate anomaly detection in the synthesis of pharmaceutical intermediates is of great significance for ensuring production safety, improving product quality, and reducing production costs.

[0003] Existing technologies suffer from the following problems: First, they typically model the entire time window uniformly, neglecting the phased characteristics of the reaction process. This leads to normal fluctuations in variables during phase transitions being easily misjudged as anomalies, and the true anomalous signals within a phase may be masked by averaging effects. Second, when processing multiple batches of data, existing technologies often directly align the time axis without fully considering the differences in the progress speed of different batches within the same process phase. This results in temporal misalignment of variable trajectories between batches, reducing the accuracy and comparability of model training. Third, when modeling process variables, existing technologies often treat all variables equally, failing to effectively distinguish between conditional variables as control inputs and outcome variables as state responses. This makes it difficult for the model to differentiate between normal control adjustments and true reaction anomalies, easily leading to false alarms. Fourth, when extracting time-series features, existing technologies often perform independent convolutions on each variable channel, lacking explicit modeling of the dynamic collaborative relationships between variables when anomalies occur. This results in the model being insufficiently sensitive to early, weak anomalies involving multiple variables, making it difficult to achieve early warning. Summary of the Invention

[0004] To achieve the above objectives, the present invention employs the following technical solution:

[0005] This invention provides a method for detecting abnormal states in the synthesis reaction process of pharmaceutical intermediates, comprising the following steps:

[0006] S1. Collect reaction process data, label it, and construct a dataset;

[0007] S2. The reaction process is divided into stages using the current stage encoding. Within each stage, variable coupling modeling, dynamic time warping alignment, and feature decoupling are completed to obtain the reconstructed feature matrix. This improves the model's ability to distinguish weak anomalies and reduces the interference of stage switching on classification results.

[0008] S3. Perform temporal convolutional encoding on the reconstructed feature matrix, and extract abnormal patterns at different time spans through multi-scale dilated convolution to obtain an encoded feature matrix that is more sensitive to abnormal states.

[0009] S4. Perform stage-aware feature aggregation and global temporal aggregation on the encoded feature matrix to obtain the final classification feature vector; input the final classification feature vector into the four stage classification heads and output the final classification category score vector.

[0010] S5. During training, joint optimization is performed using labeled smooth cross-entropy loss and focus loss.

[0011] Furthermore, the reaction process data includes reactor temperature, jacket temperature, pressure, stirring current, pH value, dropping rate, cumulative dropping amount, reflux condenser outlet temperature, and cooling water flow rate; during the acquisition process, the current process stage code of the reaction is recorded synchronously, with a value range of 1 to 4, corresponding to the four consecutive process stages in the synthesis reaction of drug intermediates; the labeling categories are divided into three types: normal, early abnormal, and abnormal outbreak; after labeling, the dataset is divided into training set, validation set, and test set.

[0012] Furthermore, in step S2, the original reaction process matrix is ​​constructed. The original reaction process matrix It includes 9 monitored variables and 1 current stage code. To avoid the current stage code directly participating in variable coupling calculations and introducing spurious correlations, the current stage code is removed from the original reaction process matrix. The data is separated from the data, and then the nine monitored variables are divided into stages, coupled modeled, and dynamically warped and aligned to obtain an aligned stage sub-matrix. This sub-matrix is ​​used to characterize the variable trajectory within a stage under a unified process progress coordinate system, which can improve the comparability between different batches.

[0013] From the original reaction process matrix Extract the first 9 columns to form the process variable matrix. From the original reaction process matrix The 10th column extracts the current stage code, forming a stage code sequence. According to the stage coding sequence For process variable matrix Divide the time into four sub-matrices, and define them as follows: Indicates the first Each stage submatrix is ​​calculated; for each stage submatrix, the stage-specific variable coupling strength matrix is ​​calculated separately. This is used to describe the correlation between variables and the prior relationships of the process at this stage; for sample trajectories belonging to the same stage in the training set, they are first resampled to a standard length according to the time length. Then take the median at the same time position to get the first... Reference matrix for each stage Using the current sample's stage submatrix as input and the reference matrix as the target, time distance matrices are established for each of the nine monitored variables. Dynamic programming is then used to find the alignment path with the minimum cumulative cost, yielding the optimal alignment path. Following the optimal alignment path, the current sample's stage submatrix is ​​remapped to a standard length, resulting in the aligned stage submatrix. The four aligned stage sub-matrices are concatenated in stage order to obtain the complete alignment process matrix. .

[0014] Further, in step S2, the monitoring variables in the aligned stage submatrix are split into process condition variables and process response variables, and stage transition information and aligned original variable information are introduced to obtain the reconstructed feature matrix:

[0015] In each aligned stage submatrix, the nine monitoring variables are split into four process condition variables and five process response variables. The process condition variables mainly reflect the control input or environmental boundary, while the process response variables mainly reflect the change in reaction state. A linear regression model from the process condition variables to the process response variables is established for each stage, and the least squares method is used to fit the linear mapping relationship to obtain the stage regression coefficient matrix. and stage bias vector Using the stage regression coefficient matrix and stage bias vector, the current sample is... The process response variables in each stage are predicted, and then the predicted results are subtracted from the actual process response variables to obtain the decoupling feature matrix within each stage. Construct a transition feature matrix between stages for each stage. The intra-stage decoupling feature matrices of the four stages are concatenated in stage order to obtain the intra-stage decoupling feature matrix of the complete window. The inter-stage transition feature matrices of the four stages are concatenated in stage order to obtain the complete window's inter-stage transition feature matrix. The intra-stage decoupling feature matrix, inter-stage transition feature matrix, and complete alignment process matrix of the complete window are concatenated along their feature dimensions to obtain the initial reconstructed feature matrix. A time-step linear projection is then performed on the initial reconstructed feature matrix to obtain the reconstructed feature matrix. .

[0016] Furthermore, in step S3, the feature matrix will be reconstructed. Grouping by channel, the features in each group are simultaneously extracted for intra-group time dependence and inter-group activation information. This allows a particular group of features to dynamically receive supplementary information from other related groups during encoding, resulting in a mutually activated convolutional output.

[0017] Reconstruct the feature matrix The target feature group is divided into 8 feature groups along the feature dimension. A one-dimensional temporal convolution is performed on each target feature group to extract the temporal dependent features within the group, thus obtaining the intra-group convolution result. For each pair of target feature groups and source feature groups Calculate the dynamic excitation coefficients of the source feature set on the target feature set. ; Group feature matrix of the target feature group Group feature matrix of source feature group Global average pooling is performed in the time dimension to obtain two sets of description vectors; the two sets of description vectors are concatenated and then input into the fully connected layer to obtain the activation coefficient vector. , characterizing the The feature group pair of the first Channel-level excitation intensity for each feature group; perform independent cross-group one-dimensional temporal convolution on each source feature group to obtain the cross-group convolution result. Apply the activation coefficient vector channel-wise to the cross-group convolution result to obtain the first... The feature group pair of the first The target feature group is given activation features; the intra-group convolution result is added element-wise to all activation features from the other 7 source feature groups to obtain the mutual activation convolution output. Repeat the above process for the 8 feature groups to obtain 8 mutually stimulated convolution outputs, thus completing variable grouping and dynamic mutually stimulated convolution.

[0018] Furthermore, short-term and long-term features are extracted from the output of the mutual-stimulated convolution through multi-scale dilated convolution, and the encoding channels that are more critical for classification are enhanced through a channel attention mechanism, forming an encoding feature matrix:

[0019] For each mutually stimulated convolution output, perform three parallel 1D dilated convolution branches. Concatenate the outputs of the three parallel 1D dilated convolution branches along the feature dimension to obtain the first... Multi-scale temporal feature matrix of feature groups The multi-scale temporal feature matrix of 8 feature groups arrive By concatenating along the feature dimensions, the original multi-scale temporal feature matrix is ​​obtained. Channel attention is calculated on the original multi-scale temporal feature matrix to obtain the channel attention vector. Combine the original multi-scale temporal feature matrix with the channel attention vector. Channel-by-channel multiplication yields the attention-enhanced fusion temporal feature matrix. The fused temporal feature matrix is ​​further processed by two layers of one-dimensional temporal convolutional coding to obtain the encoded feature matrix. .

[0020] Furthermore, the three parallel 1D dilated convolution branches have dilation rates of 1, 2, and 4, respectively, a kernel size of 3, and an output channel number of 8.

[0021] Furthermore, step S4 specifically includes:

[0022] Based on the determined standard lengths of the four stages, the encoded feature matrix is ​​divided into four standard stage segments in the time dimension; stage-aware pooling is then performed on each standard stage segment to obtain a stage-representative feature vector. The representative feature vectors of the four stages are concatenated along the feature dimension to obtain the stage fusion feature vector. ; For the encoded feature matrix Perform global temporal attention aggregation to obtain global feature vectors. The stage-fused feature vector and the global feature vector are concatenated along the feature dimension to obtain the final classification feature vector. The final classification feature vector is input into four independent stage classification heads to obtain the classification category score vector for each stage. Calculate the stage fusion weights by summing the classification score vectors output from the four stage classification heads according to the stage fusion weights to obtain the final classification score vector. .

[0023] Furthermore, in calculating the labeled smooth cross-entropy loss... At the same time, smoothing is applied to the true class labels to reduce the model's overconfidence in the training samples; when calculating the focus loss... At that time, an additional focus loss is calculated on the training samples with the true label of early abnormality to increase the class weight of the early abnormality category.

[0024] The present invention also provides an abnormal state detection system for a pharmaceutical intermediate synthesis reaction process, comprising the above-described abnormal state detection method for a pharmaceutical intermediate synthesis reaction process, including:

[0025] Data acquisition module: used to collect reaction process data;

[0026] Feature reconstruction module: used to divide the reaction process into stages using the current stage encoding, and complete variable coupling modeling, dynamic time warping and alignment, and feature decoupling within each stage to obtain the reconstructed feature matrix;

[0027] Feature encoding module: used to perform temporal convolutional encoding on the reconstructed feature matrix, extracting abnormal patterns at different time spans through multi-scale dilated convolution to obtain the encoded feature matrix;

[0028] The recognition module is used to perform stage-aware feature aggregation and global temporal aggregation on the encoded feature matrix to obtain the final classification feature vector; the final classification feature vector is input into the four stage classification heads and the final classification category score vector is output.

[0029] Training module: During training, joint optimization is performed using labeled smooth cross-entropy loss and focus loss.

[0030] The advantages of this invention are:

[0031] This invention divides the reaction process into different stages and uses multivariate dynamic time warping guided by the coupling strength matrix to align the trajectory within each stage, eliminating progress deviations caused by differences in process rhythm between batches and making data from the same stage of different batches comparable. It decouples monitoring variables into process condition variables and process response variables, and establishes a linear regression model for each stage to remove the linear influence of condition variables, extracting the response residuals that purely reflect deviations in reaction kinetics as decoupling features within each stage, thus avoiding misjudging normal control input changes as anomalies. A dynamic mutual excitation mechanism between variable groups is introduced during temporal convolutional encoding. By calculating the dynamic excitation coefficients of the source feature group on the target feature group, the collaborative change relationship of multiple variables when anomalies occur is explicitly modeled, overcoming the shortcomings of traditional convolutional networks that process each channel independently and lack deep fusion. Independent classification heads are set for different process stages, and the classification results are weighted and fused according to the actual proportion of each stage in the samples, allowing the boundary of anomaly discrimination to adaptively adjust with the reaction stage, solving the problem that a single classification model cannot adapt to the differences in variable distribution at different stages. Attached Figure Description

[0032] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used together with the embodiments of the invention to explain the invention and do not constitute a limitation thereof.

[0033] Figure 1 This is a flowchart of the steps of the method of the present invention;

[0034] Figure 2 This is a coding diagram of the process stage corresponding to each time step within the current 30-second window.

[0035] Figure 3The graphs show the changes of key process parameters over time within a 30-second time window, where (a) is the change of reactor temperature over time, (b) is the change of jacket temperature over time, (c) is the change of pressure over time, (d) is the change of stirring current over time, (e) is the change of pH value over time, (f) is the change of dropping rate over time, (g) is the change of cumulative dropping amount over time, (h) is the change of reflux condenser outlet temperature over time, and (i) is the change of cooling water flow rate over time.

[0036] Figure 4 This is a diagram of the variable coupling strength matrix for stage 1. Detailed Implementation

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

[0038] Example 1

[0039] In this embodiment, as Figure 1 As shown, this invention provides a method for detecting abnormal states in the synthesis reaction process of pharmaceutical intermediates, the specific steps of which include:

[0040] S1. Data Acquisition and Sample Construction for Reaction Process

[0041] A data acquisition system was established for the synthesis of pharmaceutical intermediates. Various sensors were installed on the reactor and its associated pipelines to monitor key process parameters in real time. Specifically, temperature sensors collected the reactor's internal temperature and jacket temperature, pressure transmitters collected the reactor's internal pressure, current transformers monitored the stirring current of the agitator motor, pH meters acquired the pH value of the reactants in real time, flow meters monitored the dropping rate and cumulative dropping volume in the dropping pipeline, temperature sensors collected the reflux condenser outlet temperature, and flow meters monitored the cooling water flow rate. All sensors collected data at a uniform sampling frequency with a sampling interval of 1 second, meaning a complete set of monitoring variable data was recorded every second.

[0042] The collected raw data, after analog-to-digital conversion, is transmitted to the data storage module in the industrial control system to form continuous time-series data. Simultaneously with data acquisition, the process control system records the current process stage code of the reaction. This code is automatically generated according to preset process stage division rules, with values ​​ranging from 1 to 4, corresponding to the four consecutive process stages in the synthesis of drug intermediates.

[0043] In one embodiment, such as Figure 2 As shown, the process stage codes (1 to 4) corresponding to each time step within the current 30-second window are displayed. The horizontal axis represents the time step (unit: seconds), and the vertical axis represents the stage code (dimensionless). The reaction process proceeds in a preset four-stage sequence.

[0044] To construct a dataset for model training, this invention selects several batches from historical production batches. For each batch, a time period is selected where the reaction process is stable and the process operation conforms to standard specifications. Samples are extracted in 30-second windows with 15-second steps. Each sample corresponds to complete reaction process data within a 30-second time window, including data from 9 monitored variables across 30 time steps within that window, as well as the corresponding stage coding sequence, which together constitute the original reaction process matrix.

[0045] Regarding sample labeling, this invention employs manual labeling, classifying each sample based on the final product quality of its batch, intermediate control analysis results, and real-time process curve records. The labeling categories are divided into three types: Label 0 indicates normal, meaning all monitored variables within this window are within the normal process control range, the reaction process is stable, and no subsequent abnormal events occur; Label 1 indicates early abnormality, meaning some variables within this window have shown signs of deviating from the normal process range, but have not yet caused significant process fluctuations or product quality deviations, representing an early warning state of an abnormality; Label 2 indicates an abnormal outbreak, meaning multiple monitored variables within this window have deviated significantly, and the reaction process exhibits obvious signs of loss of control, such as a rapid temperature increase, sudden pressure change, or violent fluctuations in stirring current.

[0046] After annotation, all samples are divided into training, validation and test sets according to a preset ratio for subsequent model training, parameter tuning and performance evaluation.

[0047] In one embodiment, such as Figure 3 As shown, the curves of nine key process parameters during the synthesis reaction of the drug intermediate are displayed within a 30-second time window. The horizontal axis represents time (seconds), and the vertical axis represents the measured values ​​of each variable. Each variable has a dynamic trend during the reaction.

[0048] S2. Decoupling and Dynamic Alignment of Stage-Sensitive Characteristics of Reaction Process Variables

[0049] The synthesis process of drug intermediates has obvious stages. The coupling relationship, rate of change and abnormal manifestation of each process variable are different in different stages. If all variables within the time window are modeled uniformly, normal fluctuations caused by stage switching are easily misjudged as abnormalities, and real abnormalities are easily masked by stage averaging effects.

[0050] This invention first divides the reaction process into stages using the current stage encoding, then completes variable coupling modeling, dynamic time warping alignment, and feature decoupling within each stage, and finally reconstructs a unified feature matrix suitable for deep neural network input, thereby improving the model's ability to distinguish weak anomalies and reducing the interference of stage switching on classification results. The specific steps are as follows:

[0051] S201, Stage-Specific Variable Coupling Modeling and Intra-Stage Dynamic Time Warping Alignment

[0052] Original reaction process matrix It contains 9 monitoring variables and 1 current stage code. To avoid the current stage code directly participating in variable coupling calculations and introducing spurious correlations, this invention first extracts the current stage code from the original reaction process matrix. The data is separated from the data, and then the nine monitored variables are divided into stages, coupled modeled, and dynamically warped and aligned to obtain an aligned stage sub-matrix. This sub-matrix is ​​used to characterize the variable trajectory within a stage under a unified process progress coordinate system, which can improve the comparability between different batches. The specific steps are as follows:

[0053] 1) Define one training sample as corresponding to a complete reaction process data within a 30-second time window, and denote the original reaction process matrix as follows: The size is Where 30 represents the number of time steps and 10 represents the number of variables, the 10 variables are as follows: in-vessel temperature (°C), jacket temperature (°C), pressure (kPa), stirring current (A), pH value (dimensionless), dropping rate (mL / min), cumulative dropping volume (mL), reflux condenser outlet temperature (°C), cooling water flow rate (L / min), and current stage code (dimensionless).

[0054] The status labels are defined into three categories: label 0 indicates normal, label 1 indicates early stage of abnormality, and label 2 indicates outbreak of abnormality.

[0055] From the original reaction process matrix Extract the first 9 columns to form the process variable matrix. It is a process variable matrix containing only the monitored variables, with a size of Meanwhile, from the original reaction process matrix The 10th column extracts the current stage code, forming a stage code sequence. Stage coding sequence This represents the reaction stage label corresponding to 30 time steps. The label is 30 in length and has a value of 1, 2, 3, or 4, which correspond to 4 process stages.

[0056] 2) According to the stage coding sequence For process variable matrix By dividing the time into steps, four stage sub-matrices are obtained. , , , ,definition Indicates the first The stage submatrix of each stage has a size of [size missing]. , This represents the stage index, with values ​​of 1, 2, 3, and 4. Indicates the first The number of time steps contained in each stage within the current 30-second window, and satisfying the following conditions: If a certain stage does not appear in the current window, then the corresponding stage... Set the value to 0 and mark the stage as missing.

[0057] Furthermore, for each stage submatrix Calculate the coupling strength matrix of stage-specific variables respectively , Characterizing the first The coupling strength matrix among the nine monitored variables within each stage has a size of [value missing]. This is used to describe the correlation between variables and the prior technological relationships at this stage. The matrix elements are calculated as follows: ;

[0058] in, Coupling strength matrix The Line number The elements of the column represent the first... The first stage The monitoring variable and the first The coupling strength between the monitored variables; Indicates the first Pearson correlation coefficients of the two monitored variables at each stage; Indicates the index of the first monitored variable. This indicates the index of the second monitored variable, with a value ranging from 1 to 9; Represents the natural exponential function; This represents the index distance between two monitored variables in terms of their order of appearance.

[0059] It should be noted that relying solely on statistical correlation is easily affected by noise, while introducing the process prior corresponding to the variable index distance into the coupling calculation can enable variables that are closer in process to obtain a more stable coupled expression.

[0060] In one embodiment, such as Figure 4 As shown, based on the variable coupling strength matrix of Phase 1, the coupling strength among the nine monitored variables in the first phase is displayed. The horizontal and vertical axes are the names of the monitored variables (dimensionless).

[0061] 3) Establish standard reference trajectories for each stage in advance based on the training set. Specifically, resample the sample trajectories belonging to the same stage in the training set to the standard length according to the time length. Then take the median at the same time position to get the first... Reference matrix for each stage The size is ,in, Indicates the first The standard length of each stage, and the standard length of the four stages satisfies This ensures that the complete window after subsequent reconstruction still maintains 30 time steps. In an easy-to-implement approach, this can be determined based on the average duration ratio of the four stages of the training set. , , , For example, take 8, 7, 8, 7.

[0062] 4) Perform dynamic temporal warping and alignment within each non-missing stage. Specifically, based on the stage submatrix of the current sample... As input, with reference matrix To achieve the goal, a time distance matrix is ​​established for each of the nine monitored variables, and then dynamic programming is used to find the alignment path with the minimum cumulative cost.

[0063] In practical implementation, since multiple variables in the synthesis reaction of drug intermediates often respond jointly to the same process change, aligning only according to a single variable trajectory can easily lead to local mismatches. Therefore, to ensure that the alignment process reflects the coupling relationship between variables within a stage, the calculation of the first... When calculating the distance cost of a monitoring variable, not only is the difference between the monitoring variable itself and the reference trajectory calculated, but also the synchronization differences of several monitoring variables with the strongest coupling strength are superimposed; if two auxiliary coupling variables are used, the distance cost can be calculated from the matrix. The two variables with the highest coupling strength besides themselves are selected to participate in the distance calculation. By introducing coupling variables, the alignment results can be made more consistent with the actual process.

[0064] 5) According to the obtained optimal alignment path, divide the current sample's stage submatrix. Remapping to standard length The above yields the aligned stage submatrix. , Characterizing the first The aligned stage submatrix under a unified process schedule coordinate system has a size of [missing information]. .

[0065] In practical implementation, if multiple original time points in the optimal alignment path correspond to the same standard position, the variable values ​​of these original time points are averaged; if a standard position does not have a directly corresponding original time point, linear interpolation of adjacent positions is used to fill in the gaps; if the first... If a stage is missing, then... Set directly to size A zero matrix is ​​generated, and the presence of a stage is recorded synchronously as 0; for non-missing stages, the presence of a stage is recorded as 1.

[0066] 6) Concatenate the four aligned stage sub-matrices in stage order to obtain the complete alignment process matrix. , The complete process matrix after stage division and dynamic time warping is represented by a size of [missing information]. It is used for feature decoupling and feature reconstruction in subsequent stages.

[0067] S202. Intra- and inter-stage feature decoupling and reconstruction

[0068] After alignment, the stage submatrix has eliminated the main process schedule offset, but there are still significant control input effects between different monitoring variables. If all variables are directly input into the subsequent network, the model is prone to misidentifying controlled changes as abnormal changes.

[0069] This invention decomposes the monitored variables into process condition variables and process response variables. First, it removes the linear influence of process condition variables on process response variables, and then introduces stage transition information and aligned original variable information to construct a reconstructed feature matrix for deep neural network training. The specific steps are as follows:

[0070] 1) Submatrix in each alignment stage In this study, the nine monitored variables were broken down into four process condition variables and five process response variables. The process condition variables primarily reflect the control input or environmental boundary conditions, while the process response variables primarily reflect changes in the reaction state.

[0071] The fixed process condition variables are defined as the reactor temperature, jacket temperature, pressure, and cooling water flow rate; the fixed process response variables are defined as the stirring current, pH value, dropping rate, cumulative dropping amount, and reflux condenser outlet temperature.

[0072] Furthermore, a linear regression model from process condition variables to process response variables is established for each stage. Specifically, this is achieved by aligning the stage submatrix with all training samples for that stage. Based on this, four process condition variables are taken as inputs and five process response variables are taken as outputs. The least squares method is used to fit the linear mapping relationship to obtain the stage regression coefficient matrix. and stage bias vector ,in, Characterizing the first The linear influence coefficient matrix (non-trainable parameters) of process condition variables on process response variables at each stage has a size of [value missing]. , Characterizing the first The linear regression bias vector (non-trainable parameter) for each stage has a length of 5.

[0073] Furthermore, using the stage regression coefficient matrix and stage bias vector For the current sample, the first The process response variables in each stage are predicted, and then the predicted results are subtracted from the actual process response variables to obtain the decoupling feature matrix within each stage. , Characterizing the first The intra-stage decoupling characteristic matrix after removing the linear influence of process condition variables at each stage, with size [missing information]. This process can be represented as ;

[0074] in, Indicates from The extracted five process response variable matrices have a size of [missing information]. ; Indicates from The four process condition variable matrices extracted have a size of [missing information]. ; Broadcast along the time direction during calculation One time step; Essentially, it is the residual of the response within a stage, which can more purely characterize whether the reaction kinetics deviate from the normal pattern.

[0075] 2) Construct the inter-stage transition feature matrix for each stage. , Characterizing the first Each stage corresponds to a stage transition feature matrix, with a size of [value missing]. The three features are: the difference between the current stage number and the previous standard time position stage number, the difference between the current stage number and the next standard time position stage number, and the actual proportion of the current stage within the original 30-second window. Furthermore, for the forward difference at the beginning of the stage and the backward difference at the end of the stage, the missing position is uniformly set to 0.

[0076] Furthermore, the intra-stage decoupling feature matrices of the four stages are... , , , By concatenating the features in stages sequentially, the complete window's intra-stage decoupling feature matrix is ​​obtained. , The in-stage decoupling feature matrix represents the entire 30-second window and has a size of [missing information]. Simultaneously, the inter-stage transition feature matrices of the four stages are concatenated in stage order to obtain the complete window's inter-stage transition feature matrix. The size is .

[0077] 3) Decouple the feature matrix within the complete window stage. The inter-stage transition feature matrix of the complete window and the complete alignment process matrix Concatenating the features along their respective dimensions yields an initial reconstructed feature matrix, which has a size of [missing value]. It consists of 5 decoupling features within the phase, 3 transition features between phases, and 9 aligned monitoring variables.

[0078] Furthermore, a linear projection is performed on the initial reconstructed feature matrix step by step, mapping the 17-dimensional features at each time step to 64 dimensions, thus obtaining the reconstructed feature matrix. , The reconstructed feature matrix used by the temporal convolutional encoder has a size of [size missing]. Optionally, after linear projection, batch normalization and ReLU activation can be performed to improve the stability of subsequent training.

[0079] It should be noted that by using stage-specific variable coupling modeling and dynamic time warping alignment within a stage, the process trajectories of different batches at the same stage are mapped to a comparable unified schedule space. Then, by stripping away the influence of conditional variables, the kinetic shift of the reaction itself is extracted. The combination of these two methods can significantly reduce the interference of stage switching, rhythm differences, and control input disturbances on anomaly identification.

[0080] S3. Temporal convolutional coding based on dynamic mutual activation mechanism between variables

[0081] Abnormalities in the synthesis process of drug intermediates are usually not isolated changes of a single variable, but rather multiple variables deviating from the normal cooperative relationship within a certain time range. Conventional temporal convolutional networks often default to independent convolution of each channel and only perform simple fusion in deeper layers, making it difficult to capture the real-time mutual influence between multiple variables.

[0082] This invention introduces a dynamic mutual activation mechanism between variable groups in the temporal convolutional coding stage, and extracts abnormal patterns across different time spans through multi-scale dilated convolution to obtain a coding feature matrix that is more sensitive to abnormal states. The specific steps are as follows:

[0083] S301, Variable Grouping and Dynamically Interactive Convolution

[0084] Anomalies in the reaction process often manifest as linked shifts between multiple variable groups. For example, temperature, pressure, and reflux-related variables may change synchronously before and after the anomaly occurs. This invention will reconstruct the feature matrix. Grouping by channel, the features in each group are simultaneously extracted for intra-group time dependence and inter-group activation information. This allows a particular feature group to dynamically receive supplementary information from other related feature groups during encoding. The specific steps are as follows:

[0085] 1) Reconstruct the feature matrix Divide into 8 feature groups along the feature dimension, and obtain , , , , , , , The size of each feature group is The order of the 8 feature groups is consistent with the order of the linear projection output channels, and the same partitioning method is used in the training and inference phases.

[0086] Furthermore, for each target feature group Performing a single one-dimensional temporal convolution extracts intra-group temporal dependency features, yielding the intra-group convolution result. ,in,

[0087] This represents the target feature group index, with a value ranging from 1 to 8; Indicates the first The intra-group convolution result of each feature group has a size of [size missing]. Preferably, the kernel size within the group is 3, the stride is 1, and zero padding is used to keep the time length constant at 30.

[0088] 2) For each pair of target feature groups and source feature groups ( ), calculate the dynamic excitation coefficients of the source feature set on the target feature set, and define Indicates the first Group feature matrix of feature groups Indicates the first The group feature matrix of each feature group, specifically...

[0089] First, respectively and Global average pooling is performed in the time dimension to obtain two sets of description vectors of length 8; these two sets of description vectors are then concatenated and fed into the fully connected layer, outputting an activation coefficient vector of length 8. , Characterizing the first The feature group pair of the first The channel-level excitation intensity of each feature group is 8 in length. The greater the excitation intensity, the more important the source feature group is to the target feature group. Finally, Sigmoid activation is used to... Compress it to between 0 and 1.

[0090] 3) Perform independent cross-group one-dimensional temporal convolution on each source feature group to obtain the cross-group convolution result. Then convert the excitation coefficient vector Channel-based operation (achieved through channel-level multiplication) to cross-group convolution results Up, get the first The feature group pair of the first The incentive features of each feature group are used to make the influence strength of different source feature groups on the target feature group change dynamically with the actual relevance of the current sample, rather than remaining fixed.

[0091] 4) The convolution results within the target feature group The cross-stimulated convolution output is obtained by adding the excitation features from the remaining 7 source feature groups element-wise. , Characterizing the first The feature groups are fused with the mutual-stimulated convolution output after in-group time dependence and inter-group dynamic activation, with a size of [size missing]. Optionally, after element-wise addition, batch normalization and ReLU activation can be performed to enhance nonlinear expressive power.

[0092] 5) Repeat the above process for the 8 feature groups to obtain the mutually excited convolution output. This completes variable grouping and dynamic mutual-stimulation convolution.

[0093] S302, Multi-scale dilated convolutional pyramid and channel attention fusion

[0094] The output of the mutual-stimulation convolution already contains dynamic collaborative information between variable groups, but the anomalous patterns still show significant differences in time span. Early anomalous patterns usually manifest as slow shifts lasting several seconds, while anomalous bursts often manifest as local mutations within a short period of time.

[0095] This invention extracts features from both short and long time scales simultaneously through multi-scale dilated convolution, and then enhances the encoding channels that are more critical for classification through a channel attention mechanism to form an encoding feature matrix. The specific steps are as follows:

[0096] 1) For each mutually excited convolution output Three parallel 1D dilated convolution branches are executed, with dilation rates of 1, 2, and 4 for the three branches, respectively. The kernel size is uniformly set to 3, and the number of output channels is 8 for all branches. , , ,in, , , They represent the first The convolutional outputs of each feature group at three time scales (dilation rate) have a size of [size missing]. When the void ratio is 1, more attention is paid to local short-term fluctuations, while when the void ratio is 2 and 4, more attention is paid to the changing trends on medium and long time scales.

[0097] Furthermore, , , By splicing along the feature dimension, we obtain the first... Multi-scale temporal feature matrix of feature groups The size is .

[0098] Furthermore, the multi-scale temporal feature matrix of the eight feature groups is... arrive By concatenating along the feature dimensions, the original multi-scale temporal feature matrix is ​​obtained. , The original multi-scale temporal feature matrix, representing the concatenation of all feature groups, has a size of [size missing]. .

[0099] 2) For the original multi-scale time series feature matrix Perform channel attention calculations; specifically, first, in the time dimension... Global average pooling is performed to obtain a channel statistics vector of length 192. This vector is then input into a two-layer fully connected network. The first layer reduces the 192-dimensionality to 48-dimensionality, and the second layer increases the 48-dimensionality back to 192-dimensionality. ReLU activation is used between the two layers, and finally, Sigmoid activation is used to obtain the channel attention vector. The length is 192, and each element corresponds to the importance weight of an encoding channel.

[0100] Furthermore, the original multi-scale temporal feature matrix With channel attention vector Channel-by-channel multiplication yields the attention-enhanced fusion temporal feature matrix. , The fused temporal feature matrix after channel attention weighting has a size of In the specific calculation, the channel attention vector is... Copy along the time dimension for 30 time steps, then... Multiply element by element.

[0101] 3) For the fused temporal feature matrix Continue executing two layers of one-dimensional temporal convolutional coding, where,

[0102] The first convolutional layer has a kernel size of 5 and 64 output channels; the second convolutional layer has a kernel size of 3 and 128 output channels. Each convolutional layer is followed by batch normalization and ReLU activation, with zero padding to maintain the same time length. The final encoded feature matrix is ​​obtained. , The encoded feature matrix, representing the result of dynamic mutual activation mechanism and multi-scale temporal convolutional encoding, has a size of [size missing]. .

[0103] It should be noted that this invention allows the encoding results of the target feature group to dynamically receive the excitation signals of other feature groups, thereby explicitly modeling multivariate collaborative anomalies. At the same time, multi-scale dilated convolution is used to cover anomaly patterns of different durations, and channel attention is used to suppress redundant channels and highlight effective channels. Based on this, the ability to jointly identify weak patterns in the early stage of anomalies and strong patterns in the outbreak of anomalies can be significantly improved.

[0104] S4. Stage-guided abnormal state classification and model parameter optimization

[0105] This invention further incorporates stage information during the classification phase. First, stage-aware feature aggregation is performed, then a stage-guided multi-head classification structure is adopted, and the model is optimized using a joint loss function, enabling the classification boundary to adaptively adjust with each reaction stage. The specific steps are as follows:

[0106] S401, Stage-aware Feature Aggregation and Global Temporal Aggregation

[0107] This invention extracts representative features within a specific stage and key global temporal features from the encoded feature matrix, and then concatenates them to form the final classification feature vector. Representative features within a specific stage are better suited to characterize whether a particular process stage is abnormal, while key global temporal features are better suited to characterize the overall trend of abnormal development within a time window. The complementarity of these two features improves classification stability. The specific steps are as follows:

[0108] 1) Based on the four standard lengths predetermined in S201 , , , Encode the feature matrix Dividing the time dimension into 4 standard stage segments, defining the first... The length of each standard stage segment is , corresponding to the encoded feature matrix continuous Each time step.

[0109] 2) Perform stage-aware pooling on each standard stage segment to obtain a stage-representative feature vector. Specifically,

[0110] For this stage segment, first perform element-wise max pooling in the time dimension, then perform element-wise average pooling, then add the two together and divide by 2 to obtain a representative feature vector of length 128. , Characterizing the first The stage representative feature vector of each stage has a length of 128;

[0111] If the current sample is missing at this stage in the original window, then directly... Set it to an all-zero vector to avoid missing stages interfering with classification.

[0112] 3) Representative feature vectors of the four stages , , , By concatenating along the feature dimension, we obtain the stage-fused feature vector. , The stage fusion feature vector, which represents the aggregation of information from four process stages, has a length of 512.

[0113] Furthermore, the encoded feature matrix Perform global temporal attention aggregation to obtain global feature vectors. Specifically, for the encoded feature matrix Each time step is mapped to a scalar attention score through a fully connected layer. Softmax normalization is then performed over 30 time steps to obtain attention weights for those 30 time steps. Finally, these attention weights are used to perform a weighted summation of the 128-dimensional encoded features from the 30 time steps to obtain the global feature vector. , The global temporal feature vector, with a length of 128, represents the most critical feature vector for anomaly classification within a 30-second window.

[0114] 4) Fuse the feature vectors of each stage With global feature vectors By concatenating along the feature dimension, the final classification feature vector is obtained. , is the final classification feature vector that enters the classification module, with a length of 640.

[0115] S402, Phase-guided multi-head classification and joint loss optimization

[0116] The same variable deviation pattern may have different process meanings at different process stages. This invention sets independent classification heads for each of the four process stages, and then combines the actual proportion of each stage in the original window of the current sample to perform weighted fusion of the classification results of each stage to obtain the final classification output. Through the stage-guided multi-head classification method, the model can automatically adjust the discrimination boundaries of normal, early abnormal, and abnormal outbreak according to the current stage. The specific steps are as follows:

[0117] 1) Establish four independent stage classification heads, each corresponding to one of the four process stages. Each stage classification head receives the final classification feature vector. As input, it consists of two fully connected layers, where,

[0118] The first layer maps 640 dimensions to 128 dimensions and uses ReLU activation; the second layer maps 128 dimensions to 3 dimensions and outputs the classification score vector corresponding to this stage. , Characterizing the first The classification score vector output by the stage classification head has a length of 3, and the 3 components correspond to normal, early abnormality, and abnormal outbreak, respectively.

[0119] 2) Calculate the stage fusion weight based on the actual proportion of the four process stages in the original 30-second window. Specifically, first, calculate the stage fusion weight based on the stage coding sequence. Count the number of time steps in the original window for each stage. Then calculate the stage proportion. ,in, Characterizing the first The actual proportion of each stage in the current original window, with a value ranging from 0 to 1; then, the proportions of the four stages are input into the temperature-weighted normalization function to obtain the stage fusion weights. , represented as When a certain stage is missing in the original window, Take 0, the corresponding Automatically decrease;

[0120] in, Indicates the first Stage fusion weights for each stage; This represents the temperature coefficient, used to amplify the differences in proportion between different stages; a value of 2.0 is acceptable. This represents the stage index during summation, with values ​​ranging from 1 to 4.

[0121] 3) Calculate the classification category score vectors output by the four-stage classification heads. , , , The final classification category score vector is obtained by weighting and summing the results according to the stage fusion weights. , The final classification score vector representing the current sample, with a length of 3;

[0122] Furthermore, the final classification category score vector Perform Softmax normalization to obtain the predicted probabilities of the three types of abnormal states, and take the category corresponding to the highest probability as the abnormal state classification result of the current sample.

[0123] 4) During the model training phase, labeled smooth cross-entropy loss and focus loss are used for joint optimization, and the total loss function is denoted as... , represented as ;

[0124] in, This represents the total loss function used during model training; This represents the labeled, smoothed cross-entropy loss; Indicates focal loss; This represents the focus loss weight, which can be set to 0.5.

[0125] In practical implementation, there is often a blurred boundary between early-stage anomalies and normal conditions. Directly using hard labels can easily result in overly rigid classification boundaries. This invention addresses this by calculating labeled, smooth cross-entropy loss. When smoothing the true class labels, the model is made less confident in the training samples. The label smoothing coefficient is preferably 0.1.

[0126] In practical implementation, early abnormal samples are usually fewer, have weaker patterns, and are more similar to normal samples. Without additional reinforcement, the model is prone to bias towards the normal or abnormal outbreak category. This invention calculates the focus loss. At the same time, the focus is on enhancing the model's learning ability for early abnormal samples. Specifically, the focus loss is calculated additionally on the training samples with the true label of early abnormal, and the class weight of the early abnormal category is increased. The early abnormal category weight is preferably 2.0, the normal and abnormal outbreak category weights are both preferably 0.5, and the focus parameter is preferably 2.0.

[0127] 5) The Adam optimizer is used to perform end-to-end iterative updates on all learnable parameters from steps S2 to S4. The learning rate is preferably 0.0005, and the weight decay coefficient is preferably [missing value]. .

[0128] After each training round, the classification accuracy or macro-average F1 score is calculated on the validation set. When the validation metric does not improve for 10 consecutive rounds, training is stopped, and the model parameters at the optimal validation metric are saved to obtain the trained model.

[0129] S5. Detection of abnormal states in the synthesis reaction process of pharmaceutical intermediates.

[0130] Once the model has completed training and achieved the expected classification performance, this invention deploys it in a real-time monitoring system for the synthesis reaction process of drug intermediates, used for online detection of abnormal states in ongoing reaction batches. During the real-time detection phase, the industrial control system continuously collects nine monitoring variables and the current stage code during the reaction process, maintaining the same sampling frequency as the training phase, i.e., recording one set of data per second. The system dynamically constructs the samples to be detected using a sliding window, with a fixed window length of 30 seconds and a sliding step size of 15 seconds to ensure the real-time and continuous nature of the detection results. Whenever new window data is ready, the system first extracts the nine monitoring variables from the original reaction process matrix to form a process variable matrix, following the method described in step S201, and separates the stage code sequence. Then, using the stage division rules saved during the training phase and the standard reference trajectory for each stage, the system performs stage-specific variable coupling modeling and dynamic time warping alignment within the stage on the current window data, obtaining the aligned process matrix.

[0131] Then, based on the stage regression coefficient matrix and stage bias vector fitted during the training phase, the system removes the influence of process condition variables from the aligned process matrix to obtain the intra-stage decoupling feature matrix. Combining the inter-stage transition features and the original aligned variables, an initial reconstructed feature matrix is ​​constructed, which is then linearly projected to obtain the reconstructed feature matrix for use by the temporal convolutional encoder. Next, the system inputs the reconstructed feature matrix into the pre-trained temporal convolutional encoding module. This module extracts the encoded feature matrix according to the variable grouping and dynamic mutual activation mechanism in step S3, as well as the multi-scale dilated convolutional pyramid and channel attention fusion method. Finally, the system feeds the encoded feature matrix into the pre-trained stage-guided classification module. Following the stage-aware feature aggregation, global temporal aggregation, and stage-guided multi-head classification process in step S4, the system calculates the predicted probabilities of the current window sample corresponding to the three categories: normal, early abnormal, and abnormal outbreak. The category with the highest probability is output as the real-time abnormal state detection result for that window.

[0132] The test results are displayed in real time on the monitoring interface in a visual manner. When multiple windows are judged to be in the early stage of an abnormality or an abnormal outbreak, the system automatically issues an alarm signal of the corresponding level, prompting the operator to pay attention to the reaction status in time and take necessary process intervention measures, thereby realizing online identification and early warning of abnormal status in the synthesis reaction process of drug intermediates.

[0133] Example 2

[0134] This embodiment provides an abnormal state detection system for a drug intermediate synthesis reaction process, which executes the abnormal state detection method for a drug intermediate synthesis reaction process described in Embodiment 1, including:

[0135] Data acquisition module: used to collect reaction process data;

[0136] Feature reconstruction module: used to divide the reaction process into stages using the current stage encoding, and complete variable coupling modeling, dynamic time warping and alignment, and feature decoupling within each stage to obtain the reconstructed feature matrix;

[0137] Feature encoding module: used to perform temporal convolutional encoding on the reconstructed feature matrix, extracting abnormal patterns at different time spans through multi-scale dilated convolution to obtain the encoded feature matrix;

[0138] The recognition module is used to perform stage-aware feature aggregation and global temporal aggregation on the encoded feature matrix to obtain the final classification feature vector; the final classification feature vector is input into the four stage classification heads and the final classification category score vector is output.

[0139] Training module: During training, joint optimization is performed using labeled smooth cross-entropy loss and focus loss.

[0140] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for detecting abnormal states in the synthesis reaction process of pharmaceutical intermediates, characterized in that, Includes the following steps: S1. Collect reaction process data, label it, and construct a dataset; S2. Divide the reaction process into stages using the current stage encoding, and complete variable coupling modeling, dynamic time warping and alignment, and feature decoupling within each stage to obtain the reconstructed feature matrix; The specific process is as follows: From the original reaction process matrix Extract the first 9 columns to form the process variable matrix. From the original reaction process matrix The 10th column extracts the current stage code, forming a stage code sequence. According to the stage coding sequence For process variable matrix Divide the time into four sub-matrices, and define them as follows: Indicates the first Each stage submatrix is ​​calculated; for each stage submatrix, the stage-specific variable coupling strength matrix is ​​calculated separately. This is used to describe the correlation between variables and the prior relationships of the process at this stage; for sample trajectories belonging to the same stage in the training set, they are first resampled to a standard length according to the time length. Then take the median at the same time position to get the first... Reference matrix for each stage Using the current sample's stage submatrix as input and the reference matrix as the target, time distance matrices are established for the nine monitored variables respectively. Then, dynamic programming is used to find the alignment path with the minimum cumulative cost, thus obtaining the optimal alignment path. Following the optimal alignment path, the stage submatrix of the current sample is remapped to the standard length to obtain the aligned stage submatrix. The four aligned stage sub-matrices are concatenated in stage order to obtain the complete alignment process matrix. ; In each aligned stage submatrix, the nine monitoring variables are split into four process condition variables and five process response variables; For each stage, a linear regression model is established from the process condition variables to the process response variables. The least squares method is used to fit the linear mapping relationship to obtain the stage regression coefficient matrix. and stage bias vector ; Using the stage regression coefficient matrix and stage bias vector, the current sample is... The process response variables in each stage are predicted, and then the predicted results are subtracted from the actual process response variables to obtain the decoupling feature matrix within each stage. Construct a transition feature matrix between stages for each stage. The intra-stage decoupling feature matrices of the four stages are concatenated in stage order to obtain the intra-stage decoupling feature matrix of the complete window. The inter-stage transition feature matrices of the four stages are concatenated in stage order to obtain the complete window's inter-stage transition feature matrix. The intra-stage decoupling feature matrix, inter-stage transition feature matrix, and complete alignment process matrix of the complete window are concatenated along their feature dimensions to obtain the initial reconstructed feature matrix. A time-step linear projection is then performed on the initial reconstructed feature matrix to obtain the reconstructed feature matrix. ; S3. Perform temporal convolutional encoding on the reconstructed feature matrix, and extract abnormal patterns at different time spans through multi-scale dilated convolution to obtain the encoded feature matrix; S4. Perform stage-aware feature aggregation and global temporal aggregation on the encoded feature matrix to obtain the final classification feature vector; The final classification feature vector is input into the four-stage classification head, and the final classification category score vector is output. S5. During training, joint optimization is performed using labeled smooth cross-entropy loss and focus loss.

2. The method for detecting abnormal states in the synthesis reaction process of pharmaceutical intermediates according to claim 1, characterized in that, In step S3, the feature matrix will be reconstructed. Grouping by channel, the features in each group are simultaneously extracted for intra-group time dependence and inter-group activation information. This allows a particular group of features to dynamically receive supplementary information from other related groups during encoding, resulting in a mutually activated convolutional output. Reconstruct the feature matrix The target feature group is divided into 8 feature groups along the feature dimension. A one-dimensional temporal convolution is performed on each target feature group to extract the temporal dependent features within the group, thus obtaining the intra-group convolution result. For each pair of target feature groups and source feature groups Calculate the dynamic excitation coefficients of the source feature set on the target feature set. ; Group feature matrix of the target feature group Group feature matrix of source feature group Global average pooling is performed in the time dimension to obtain two sets of description vectors; the two sets of description vectors are concatenated and then input into the fully connected layer to obtain the activation coefficient vector. , characterizing the The feature group pair of the first Channel-level excitation intensity for each feature group; perform independent cross-group one-dimensional temporal convolution on each source feature group to obtain the cross-group convolution result. ; Applying the activation coefficient vector channel-wise to the cross-group convolution result yields the first... The feature group pair of the first The target feature group is given activation features; the intra-group convolution result is added element-wise to all activation features from the other 7 source feature groups to obtain the mutual activation convolution output. Repeat the above process for the 8 feature groups to obtain 8 mutually stimulated convolution outputs, thus completing variable grouping and dynamic mutually stimulated convolution.

3. The method for detecting abnormal states in the synthesis reaction process of pharmaceutical intermediates according to claim 2, characterized in that, Short-term and long-term features are extracted from the output of the mutual-stimulated convolution through multi-scale dilated convolution. Channel attention mechanism is used to enhance the encoding channels that are more critical for classification, forming an encoding feature matrix: For each mutually stimulated convolution output, perform three parallel 1D dilated convolution branches. Concatenate the outputs of the three parallel 1D dilated convolution branches along the feature dimension to obtain the first... Multi-scale temporal feature matrix of feature groups The multi-scale temporal feature matrix of 8 feature groups arrive By concatenating along the feature dimensions, the original multi-scale temporal feature matrix is ​​obtained. Channel attention is calculated on the original multi-scale temporal feature matrix to obtain the channel attention vector. Combine the original multi-scale temporal feature matrix with the channel attention vector. Channel-by-channel multiplication yields the attention-enhanced fusion temporal feature matrix. The fused temporal feature matrix is ​​further processed by two layers of one-dimensional temporal convolutional coding to obtain the encoded feature matrix. .

4. The method for detecting abnormal states in the synthesis reaction process of pharmaceutical intermediates according to claim 1, characterized in that, Step S4 specifically includes: Based on the determined standard lengths of the four stages, the encoded feature matrix is ​​divided into four standard stage segments in the time dimension; stage-aware pooling is then performed on each standard stage segment to obtain a stage-representative feature vector. The representative feature vectors of the four stages are concatenated along the feature dimension to obtain the stage fusion feature vector. ; For the encoded feature matrix Perform global temporal attention aggregation to obtain global feature vectors. The stage-fused feature vector and the global feature vector are concatenated along the feature dimension to obtain the final classification feature vector. The final classification feature vector is input into four independent stage classification heads to obtain the classification category score vector for each stage. Calculate the stage fusion weights by summing the classification score vectors output from the four stage classification heads according to the stage fusion weights to obtain the final classification score vector. .

5. The method for detecting abnormal states in the synthesis reaction process of pharmaceutical intermediates according to claim 3, characterized in that, The three parallel 1D dilated convolution branches have dilation rates of 1, 2, and 4, respectively, a kernel size of 3, and an output channel number of 8.

6. The method for detecting abnormal states in the synthesis reaction process of pharmaceutical intermediates according to claim 1, characterized in that, The reaction process data includes the reactor temperature, jacket temperature, pressure, stirring current, pH value, dropping rate, cumulative dropping amount, reflux condenser outlet temperature, and cooling water flow rate. During the data collection process, the current process stage code of the reaction is recorded synchronously, with a value range of 1 to 4, corresponding to the four consecutive process stages in the synthesis reaction of drug intermediates; the labeling categories are divided into three types: normal, early abnormality, and abnormal outbreak. After labeling, the dataset is divided into training, validation, and test sets.

7. The method for detecting abnormal states in the synthesis reaction process of pharmaceutical intermediates according to claim 1, characterized in that, Calculate the labeled smooth cross-entropy loss At the same time, smoothing is applied to the true class labels to reduce the model's overconfidence in the training samples; focus loss is calculated. At that time, an additional focus loss is calculated on the training samples with the true label of early abnormality to increase the class weight of the early abnormality category.

8. An abnormal state detection system for a pharmaceutical intermediate synthesis reaction process, comprising executing the abnormal state detection method for a pharmaceutical intermediate synthesis reaction process as described in claim 1, characterized in that, include: Data acquisition module: used to collect reaction process data; Feature reconstruction module: used to divide the reaction process into stages using the current stage encoding, and complete variable coupling modeling, dynamic time warping and alignment, and feature decoupling within each stage to obtain the reconstructed feature matrix; Feature encoding module: used to perform temporal convolutional encoding on the reconstructed feature matrix, extracting abnormal patterns at different time spans through multi-scale dilated convolution to obtain the encoded feature matrix; The recognition module is used to perform stage-aware feature aggregation and global temporal aggregation on the encoded feature matrix to obtain the final classification feature vector. Input the final classification feature vector into the four-stage classification head, and output the final classification category score vector; Training module: During training, joint optimization is performed using labeled smooth cross-entropy loss and focus loss.