A method and device for detecting fentanyl-like substances based on twin networks
Through the detection method of fentanyl-like substances based on the twin network, the shared weight feature extraction network and the classification network are used, combined with the contrast loss function, to solve the problem of poor detection performance of fentanyl-like substances in the existing technology and achieve high accuracy. rate detection effect.
Patent Information
- Application Number
- CN202210178048.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-25
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2042-02-25
AI Technical Summary
Due to insufficient sample data and reliance on supervised learning, existing methods for detecting fentanyl-like substances are difficult to effectively identify new structural chemicals, resulting in poor detection performance.
Adopt a detection method based on twin networks, preprocess and construct data sets through mass spectrometry data, use shared weight feature extraction networks and classification networks, and combine contrast loss functions and cross-entropy loss functions for model training to improve feature distinction and detection accuracy. .
It effectively solves the problem of small samples, improves the accuracy of detection of fentanyl-like substances, and performs better than traditional machine learning methods in data sets and practical application scenarios of different ion sources.
Smart Images

Figure CN114550840B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of novel psychoactive substance detection, and specifically relates to a fentanyl-like substance detection method and device based on a twin network. Technical Background
[0002] In recent years, the mortality rate caused by abuse of fentanyl-like substances has increased dramatically. The main way to solve this problem is to establish a rapid detection method to prevent fentanyl-like substances from entering the drug market.
[0003] Usually, researchers obtain the mass spectra of unknown substances through relevant instruments, and then identify these substances through existing spectral libraries. At present, most fentanyl spectral libraries contain spectra of fentanyl-like substances, but fentanyl and its analogs are easy to synthesize, and the required chemicals and equipment are not difficult to find, which is conducive to the smuggling and small-scale production of small-scale drug trafficking organizations, resulting in the continuous emergence of new structural chemicals. Therefore, the spectral library retrieval method is no longer suitable for the detection task of fentanyl-like substances. In recent years, traditional machine learning methods have also been widely used in classification scenarios based on mass spectrometry data, but most of these methods are based on supervised learning, and often require a large amount of known labeled data to train the classification model to achieve better performance. However, considering the particularity of fentanyl-like substances, the available mass spectrometry data samples of fentanyl-like substances are relatively small, and far less than the mass spectrometry data of non-fentanyl-like substances, so traditional supervised learning-based models are also difficult to achieve good classification performance.
[0004] Therefore, there is an urgent need to establish a detection model for fentanyl-like substances so that fentanyl-like substances can be effectively identified from seized controlled drugs. Summary of the invention
[0005] An object of the present invention is to provide a fentanyl-like substance detection method based on a twin network in view of the deficiencies in the prior art.
[0006] The present invention proposes a fentanyl-like substance detection method based on twin network, comprising the following steps:
[0007] Step 1: Preprocess mass spectrometry data and build a data set
[0008] 1-1 Obtain mass spectrometry data and pad them to the same length so that the step length of the mass-to-charge ratio is 1. By dividing by the base peak, the relative intensity value is normalized to the range of 0 to 1. The mass spectrometry data set is represented by L = {L1, L2, L3..., L N} indicates that L x =(m x ,a x ), 1≤x≤N, N represents the total mass spectrometry sample, mass-to-charge ratio m x={m1,m2,m3...,m n}, relative intensity a x ={a1,a2,a3...,a n}, n represents the mass spectrum sample L x The number of non-zero peaks;
[0009] 1-2 Each mass spectrum data L x Convert to standard format The details are as follows:
[0010] The mass-to-charge ratio is defined as:
[0011]
[0012] Where m max Indicates the maximum mass-to-charge ratio among all mass spectrometry samples L;
[0013] based on Update the relative intensity corresponding to each mass-to-charge ratio
[0014]
[0015] in express The i-th element in Relative strength in standard format The i-th element of x (j) means a x The jth element in m x (j) represents m x The jth element in ;
[0016] Relative Strength Divide by base peak Normalize:
[0017]
[0018] 1-3 assign labels to the standardized mass spectrometry data to construct a data set; then divide the data set into a training set and a test set; wherein the label is the category to which the substance corresponding to the current mass spectrometry data belongs, i.e., fentanyl substances or non-fentanyl substances;
[0019] Step 2: Build a detection model based on the twin network and train it using the training set
[0020] The input of the twin network-based detection model is composed of a pair of preprocessed mass spectrometry data, which includes a twin network and a classification network. The twin network includes two feature extraction networks with shared weights to extract the mass spectrometry features of each of the two mass spectra. The classification network is used to obtain the substance category to which the mass spectrum belongs, i.e., fentanyl substances or non-fentanyl substances, according to the output of the twin network.
[0021] 2-1 Build a feature extraction network to extract the features of input mass spectrometry data
[0022] The feature extraction network is composed of two one-dimensional convolutional neural networks with shared parameters and the same structure. In each feature extraction network, a first one-dimensional convolutional layer, a first maximum pooling layer, a second one-dimensional convolutional layer, a second maximum pooling layer, and a fully connected layer are sequentially cascaded, and finally the low-dimensional features corresponding to the input mass spectrometry data are output;
[0023] Preferably, in the feature extraction network, the size of the convolution kernel is set to 3, and the activation function is a nonlinear activation function;
[0024] 2-2 Build a classification network and output the category of the current detected substance based on the extracted mass spectrum features
[0025] The classification network includes a fully connected layer, an output layer, and a Softmax layer that are cascaded in sequence. The input is the low-dimensional mass spectrometry features output by the two feature extraction networks, and the output is the category probability of the currently detected unknown substance.
[0026] Among them, the specific formula of the Softmax function in the Softmax layer is:
[0027]
[0028] Where n is the total number of categories, g i represents the value of category i, g k represents the value of category k;
[0029] Preferably, the stochastic gradient descent (SGD) method is used for network training. During the training process, when the loss converges and does not change significantly within 5 consecutive iterations, the model training is stopped; the total loss function during training is specifically:
[0030] Loss = λ1Loss ctt +λ2Loss cls
[0031] Where λ1 and λ2 represent Loss ctt 、Loss cls The loss weight of
[0032] Loss cttrepresents the contrast loss, as follows:
[0033]
[0034]
[0035] Where J represents the total number of sample pairs input into the twin network for training in each batch; Y represents the label of the twin network input sample pair, the label of the positive sample pair (the sample pair contains the same substance) is 1, and the label of the negative sample pair (the sample pair contains different substances) is 0; margin is the set threshold, which represents the maximum distance between two mass spectrometry features in the negative sample, which is generally set to 1; D W represents the Euclidean distance between two mass spectral features; P is the data dimension of the mass spectral feature, X1 and X2 represent the mass spectral features output by two feature extraction networks with shared weights; Represents the i-th dimension data corresponding to the mass spectrum features of X1 and X2;
[0036] Loss cls Represents the classification loss, which is obtained by the binary cross entropy loss function:
[0037]
[0038] In the formula is the probability that the sample is detected as a fentanyl substance by the twin network-based detection model, and y is the true label of the substance to be detected; the label of fentanyl substances is 1, and the label of non-fentanyl substances is 0;
[0039] Step 3, removing any one of the two weight-sharing feature extraction networks in the trained twin network-based detection model, cascading the networks with the classification network to form a fentanyl-like substance detection model, and then testing the fentanyl-like substance detection model using the test set;
[0040] Step 4: Utilize the tested fentanyl-like substance detection model to realize fentanyl-like substance detection;
[0041] 4-1 Input the mass spectrum data of the substance to be detected into the feature extraction network to obtain its corresponding low-dimensional mass spectrum features;
[0042] 4-2 Input the low-dimensional mass spectrum features into the classification network and output the probability of the detected substance belonging to different categories;
[0043] 4-3 Select the category with the highest probability as the final category of the substance to be detected.
[0044] Another object of the present invention is to provide a fentanyl-like substance detection device, comprising
[0045] A mass spectrometry data acquisition module is used to acquire the mass spectrometry data of the substance to be detected and perform pre-processing and standardization processing;
[0046] The fentanyl-like substance detection model is used to predict the category of the substance to be detected based on the standardized mass spectrometry data.
[0047] The present invention has the following beneficial effects:
[0048] 1. Using sample pairs as the input of the twin network greatly increases the sample data used for model training, effectively solving the small sample problem of supervised learning methods in the detection of fentanyl-like substances.
[0049] 2. In the design of the loss function, a contrast loss function is added to maximize the inter-class differences and minimize the intra-class differences, making the extracted features more discriminative and improving the performance of the detection model.
[0050] 3. The proposed detection model is effective on the currently commonly used mass spectrometry data (EI source and ESI source), and has been verified in public data sets and actual application scenarios, achieving a high detection rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 This is the main technical route of the twin network-based fentanyl substance detection model described in the present invention;
[0052] Figure 2 It is the main structure of the feature extraction network in the detection model proposed by the present invention;
[0053] Figure 3 It is the main structure of the classification network in the detection model proposed by the present invention;
[0054] Figure 4 This is the detection model application process proposed by the present invention. DETAILED DESCRIPTION
[0055] The invention will be further described below with reference to the accompanying drawings.
[0056] A fentanyl-like substance detection model based on twin networks, the specific steps are as follows:
[0057] Step 1: Build a data set and divide it into a training set and a test set
[0058] 1-1 Obtain mass spectrometry data. The mass spectrometry data set is L = {L1, L2, L3..., L N} indicates that L x =(m x ,a x ), 1≤x≤N, N represents the total mass spectrometry sample, mass-to-charge ratio m x={m1,m2,m3...,m n}, relative intensity a x ={a1,a2,a3...,a n}, n represents the mass spectrum sample L x The number of non-zero peaks;
[0059] 1-2 Each mass spectrum data L x Convert to standard format The details are as follows:
[0060] The mass-to-charge ratio is defined as:
[0061]
[0062] Where m max Indicates the maximum mass-to-charge ratio among all mass spectrometry samples L;
[0063] based on Update the relative intensity corresponding to each mass-to-charge ratio
[0064]
[0065] in express The i-th element in Relative strength in standard format The i-th element of x (j) means a x The jth element in m x (j) represents m x The jth element in
[0066] Relative Strength Divide by base peak Normalize:
[0067]
[0068] 1-3 assign labels to the standardized mass spectrometry data to construct a data set; then divide the data set into a training set and a test set; wherein the label is the category to which the substance corresponding to the current mass spectrometry data belongs, i.e., fentanyl substances or non-fentanyl substances;
[0069] Step 2: Build a detection model based on the twin network and train it using the training set
[0070] like Figure 1As shown, the input of the twin network-based detection model is composed of a pair of preprocessed mass spectrometry data, which includes a twin network and a classification network. The twin network includes two feature extraction networks with shared weights to extract the mass spectrometry features of each of the two mass spectra. The classification network is used to obtain the substance category to which the mass spectrum belongs, i.e., fentanyl substances or non-fentanyl substances, according to the output of the twin network.
[0071] 2-1 Build a feature extraction network to extract the features of input mass spectrometry data
[0072] The feature extraction network is as follows Figure 2 As shown, it includes a first one-dimensional convolution layer, a first maximum pooling layer, a second one-dimensional convolution layer, a second maximum pooling layer, and a fully connected layer which are cascaded in sequence, and finally outputs low-dimensional features corresponding to the input mass spectrometry data;
[0073] In the feature extraction network, the size of the convolution kernel is set to 3, and the activation function is a nonlinear activation function;
[0074] 2-2 Build a classification network and output the category of the current detected substance based on the extracted mass spectrum features
[0075] Classification network such as Figure 3 As shown, it includes a fully connected layer, an output layer, and a Softmax layer that are cascaded in sequence, and the input is the low-dimensional mass spectrum features output by two feature extraction networks, and the output is the category probability of the current detected substance;
[0076] Among them, the specific formula of the Softmax function in the Softmax layer is:
[0077]
[0078] Where n is the total number of categories, g i represents the value of category i, g k represents the value of category k;
[0079] 2-3 Design loss function
[0080] The loss function used in training is Figure 1 As shown in , the overall loss function is designed as follows
[0081] Loss = λ1Loss ctt +λ2Loss cls
[0082] λ1 and λ2 represent two adjustable loss weights respectively.
[0083] Loss ctt represents the contrast loss, as follows:
[0084]
[0085]
[0086] Where J represents the total number of sample pairs input into the twin network for training in each batch; Y represents the label of the twin network input sample pair, the label of the positive sample pair (the sample pair contains the same substance) is 1, and the label of the negative sample pair (the sample pair contains different substances) is 0; margin is the set threshold, which represents the maximum distance between two mass spectrometry features in the negative sample, which is generally set to 1; D W represents the Euclidean distance between two mass spectral features; P is the data dimension of the mass spectral feature, X1 and X2 represent the mass spectral features output by two feature extraction networks with shared weights; Represents the i-th dimension data corresponding to the mass spectrum features of X1 and X2;
[0087] Loss cls Represents the classification loss, which is obtained by the binary cross entropy loss function:
[0088]
[0089] In the formula is the probability that the detection model based on the twin network detects that the sample is fentanyl, and y is the true label of the substance to be detected; the label of fentanyl substances is 1, and the label of non-fentanyl substances is 0;
[0090] 2-4 Use the stochastic gradient descent (SGD) method for network training. During the training process, when the loss converges and no longer changes significantly within 5 consecutive iterations, stop the model training.
[0091] Step 3: Apply the twin network-based detection model
[0092] The actual application process of the detection model based on the twin network is as follows Figure 4 As shown. After removing any one of the two shared-weight feature extraction networks in the trained twin network-based detection model, the two networks are cascaded with the classification network to form a fentanyl-like substance detection model, and then the fentanyl-like substance detection model is tested using the test set;
[0093] 3-1 Input the mass spectrum data of the substance to be detected into the feature extraction network to obtain its corresponding low-dimensional mass spectrum features;
[0094] 3-2 Input the low-dimensional mass spectrum features into the classification network and output the probability of the detected substance belonging to different categories;
[0095] 3-3 Select the category with the highest probability as the final category of the current substance to be detected.
[0096] The effect of the present invention is demonstrated below
[0097] 1. Dataset Selection
[0098] The twin network-based fentanyl-like substance detection model proposed in the present invention was verified on the public data sets of different existing ion sources, including the EI source and ESI source public data sets. The proposed detection model was applied to these data sets, cross-validation was performed, the detection accuracy of the detection model was statistically analyzed, and the effect was compared with some classical machine learning methods (KNN, SVM). Finally, the detection model was applied in the actual application scenario (133 mass spectrometry samples actually sampled), and a higher detection accuracy was achieved compared with the traditional machine learning method.
[0099] The detection accuracy ACC of the model is defined as follows:
[0100]
[0101] 2. Model verification results
[0102] 2-1EI source public dataset
[0103] The EI source mass spectrometry dataset comes from the SWGDRUG database and the NIST database, which contains a total of 267 fentanyl mass spectrometry data and 238 non-fentanyl substances. A 10-fold cross validation was performed on the dataset, and the experimental comparison results are as follows:
[0104] Table 1 Verification and comparison of this detection model on the EI source public dataset
[0105]
[0106] The above table verifies that the proposed detection model has achieved a high detection accuracy on the EI source public mass spectrometry dataset. Therefore, the model is credible in the fentanyl-like substance detection task based on EI source mass spectrometry and is superior to traditional machine learning methods.
[0107] 2-2ESI source public data set
[0108] The ESI source mass spectrometry data set is partly from the MassBank database, and the other part is generated by the CFM-ID tool, which contains a total of 88 fentanyl mass spectrometry data and 121 non-fentanyl substances. A 5-fold cross validation was performed on this data set, and the experimental comparison results are as follows:
[0109] Table 2 Verification and comparison of this detection model on the ESI source public dataset
[0110]
[0111] The above table verifies that the proposed detection model has achieved a high detection accuracy on the ESI source public mass spectrometry dataset. Therefore, the model is credible in the fentanyl-like substance detection task based on ESI source mass spectrometry and is superior to traditional machine learning methods.
[0112] 2-3ESI source actual data set
[0113] In order to further verify the effectiveness of the proposed detection model, in compliance with legal and ethical norms, 133 ESI source mass spectrometer samples were actually sampled using a portable mass spectrometer CRAIV-110. The collected original mass spectra were pre-processed to generate the actual data set, which included 41 fentanyl mass spectrometry data and 92 non-fentanyl substances. A 5-fold cross-validation was performed on the data set, and the experimental comparison results are as follows:
[0114] Table 3 Verification and comparison of the detection model on the actual ESI source data set
[0115]
[0116] The above table verifies that the proposed detection model has achieved a high detection accuracy on the actual ESI source mass spectrometry data set, thus further proving that the proposed detection model is credible in the practical application of fentanyl-like substance detection based on ESI source mass spectrometry, and is superior to traditional machine learning methods.
Claims
1. A fentanyl-like substance detection method based on twin networks, characterized in that The following steps are involved: Step 1: Build a data set and divide it into a training set and a test set 1-1 Obtain mass spectrometry data. The mass spectrometry data set is L = {L1, L2, L3..., L N } indicates that L x =(m x ,a x ), 1≤x≤N, N represents the total mass spectrometry sample, mass-to-charge ratio m x ={m1,m2,m3...,m n }, relative intensity a x ={a1,a2,a3...,a n }, n represents the mass spectrum sample L x The number of non-zero peaks; 1-2 Each mass spectrum data L x Convert to standard format The details are as follows: The mass-to-charge ratio is defined as: Where m max Represents the maximum mass-to-charge ratio among all mass spectrometry samples L; based on Update the relative intensity corresponding to each mass-to-charge ratio in express The i-th element in Relative strength in standard format The i-th element of x (j) means a x The jth element in m x (j) represents m x The jth element in ; Relative strength Divide by base peak Normalize: 1-3 assign labels to the standardized mass spectrometry data to construct a data set; then divide the data set into a training set and a test set; wherein the label is the category to which the substance corresponding to the current mass spectrometry data belongs, i.e., fentanyl substances or non-fentanyl substances; Step 2: Build a detection model based on the twin network and train it using the training set The input of the twin network-based detection model is composed of a pair of preprocessed mass spectrometry data, which includes a twin network and a classification network. The twin network includes two feature extraction networks with shared weights to extract the mass spectrometry features of each of the two mass spectra. The classification network is used to obtain the substance category to which the mass spectrum belongs, i.e., fentanyl substances or non-fentanyl substances, according to the output of the twin network. 2-1 Build a feature extraction network to extract the features of input mass spectrometry data The feature extraction network includes a first one-dimensional convolutional layer, a first maximum pooling layer, a second one-dimensional convolutional layer, a second maximum pooling layer, and a fully connected layer, which are cascaded in sequence, and finally outputs low-dimensional features corresponding to the input mass spectrometry data; In the feature extraction network, the size of the convolution kernel is set to 3, and the activation function is a nonlinear activation function; 2-2 Build a classification network and output the category of the current detected substance based on the extracted mass spectrum features The classification network includes a fully connected layer, an output layer, and a Softmax layer that are cascaded in sequence. The input is the low-dimensional mass spectrometry features output by the two feature extraction networks, and the output is the category probability of the current detected substance. Among them, the specific formula of the Softmax function in the Softmax layer is: Where n is the total number of categories, g i represents the value of category i, g k represents the value of category k; 2-3 Design loss function The loss function used in training is designed as follows: Loss=λ1Loss ctt +λ2Loss cls λ1 and λ2 represent two adjustable loss weights respectively; Loss ctt It represents the contrast loss, which is as follows: Where J represents the total number of sample pairs input into the twin network for training in each batch; Y represents the label of the twin network input sample pair, the label of the positive sample pair (the sample pair contains the same substance) is 1, and the label of the negative sample pair (the sample pair contains different substances) is 0; margin is the set threshold, which represents the maximum distance between two mass spectrometry features in the negative sample, which is generally set to 1; D W represents the Euclidean distance between two mass spectral features; P is the data dimension of the mass spectral feature, X1 and X2 represent the mass spectral features output by two feature extraction networks with shared weights; Represents the i-th dimension data corresponding to the mass spectrum features of X1 and X2; Loss cls Represents the classification loss, which is obtained by the binary cross entropy loss function: In the formula is the probability that the sample is detected as fentanyl by the detection model based on the twin network, and y is the true label of the substance to be detected; The label of fentanyl substances is 1, and the label of non-fentanyl substances is 0; 2-4 Use the stochastic gradient descent method to train the network. During the training process, when the loss converges and does not change significantly within 5 consecutive iterations, stop the model training; Step 3, removing any one of the two weight-sharing feature extraction networks in the trained twin network-based detection model, cascading the networks with the classification network to form a fentanyl-like substance detection model, and then testing the fentanyl-like substance detection model using the test set; Step 4: Utilize the tested fentanyl-like substance detection model to realize fentanyl-like substance detection.
2. A fentanyl-like substance detection method based on twin network as claimed in claim 1, characterized in that In the feature extraction network, the size of the convolution kernel is set to 3, and the activation function is a nonlinear activation function.
3. A fentanyl-like substance detection method based on twin network as claimed in claim 1, characterized in that Step (4) is specifically: 4-1 Input the mass spectrum data of the substance to be detected into the feature extraction network to obtain its corresponding low-dimensional mass spectrum features; 4-2 Input the low-dimensional mass spectrum features into the classification network and output the probability of the detected substance belonging to different categories; 4-3 Select the category with the highest probability as the final category of the substance to be detected.
