Introduction

Ionization edges (core-loss edges) on the electron energy loss spectra (EELS) carry important information not only reflecting the elemental information but also allowing quantitative composition analysis. In addition, the edge onset shift and the near-edge fine structure can be used to deduce the bonding state1. Compared to Energy Dispersive X-ray Spectroscopy (EDS), EELS can deliver electronic state information of a material and has higher sensitivity in detecting light elements2,3. However, the core-loss region of EELS is also featured by the low signal–noise ratio (SNR). Thus, precisely recognizing the elemental edges is the first step before any advanced analysis.

The traditional way of edge recognition involves multiple steps. Preprocessing operations, including background removal and sometimes multiple-scattering effect deconvolution, are conducted to extract the edges from the spectrum. Afterward, these edges are classified by referring to the database generated by verified experimental data4. Therefore, this process requires significant manual labor and is experience based.

Automatically finding ionization peaks in Energy Dispersive X-ray Spectroscopy (EDS) is now routine in commercial software because the peaks are distinctively above the background and the shapes are almost universally gaussian. However, automatically identifying edges in the EELS spectrum has been traditionally difficult because the edges are sitting on a large background, and in most cases, the jump ratio is low. Due to this nature, it has been non-trivial to locating EELS edges automatically. A number of approaches have been proposed to extract edges of unknown components in the spectrum, such as the spatial variant difference approach, multivariate statistical analysis5 (independent components analysis (ICA)6,7, principal components analysis (PCA)24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,5b shows the architecture of our CNN-BiLSTM network, where the BiLSTM network is plotted in an unwrapped way. The real LSTM cell is described in Fig. 5c, and is constructed with 100 hidden units. In our case, the input layer carries the information of a spectrum that is a 1D vector (spectrum of energy loss range from 90 to 1000 eV with interval 0.2 eV). A filter of size 11 is implemented in each convolutional layer. Batch normalization operation66 is carried out following each convolutional layer, and 20% of node dropout regularization is utilized after each dense layer to avoid overfitting. Activation functions, ReLU and LeakyReLU of scale 0.01, are implemented to connect different layers as shown in the Fig. 5b. The network is built and trained using MATLAB. The training parameter settings are listed in Table 3. 80% of the spectra in the database are randomly picked for the training set, and the remaining 20% are for the validation set.

Figure 5
figure 5

CNN-BiLSTM network architecture. (a) The overview. (b) The CNN-BiLSTM network structure. (c) The structure of the LSTM cell.

Table 3 Network training setting.

Results and discussion

Prediction validation

The performance of the proposed CNN-BiLSTM network is validated using multiple metrics.

F1-score

To evaluate the performance of the network per spectrum, we calculate the F1-score for each predicted spectrum, which is defined as the harmonic mean of precision and recall. We use NEc, NEp, and NEr to represent the number of correctly predicted edges (true positive), the total number of predicted edges (predicted positive), and the number of real edges (actual positive) on the spectrum, respectively. Precision, recall, and F1-score can be calculated by using the following equations:

$$\begin{aligned}precision&=\frac{{NE}_{c}}{{NE}_{p}}\\ recall&=\frac{{NE}_{c}}{{NE}_{r}}\\ F1&=\frac{2}{{recall}^{-1}+{precision}^{-1}}\end{aligned}$$

Exact accuracy

We use exact accuracy (ACC) to check how our network can accurately recognize all the edges on a spectrum, i.e., the ratio of the number of spectra accurately predicted (Nexa) to the total number of spectra tested (N). This value also reflects the percentage of the spectra whose F1-score equals to 1.

$$Acc=\frac{{N}_{exa}}{N}$$

Recognition accuracy

The following equation shows the format of the recognition accuracy. Nrec represents the number of spectra that the network can recognize all the edges that appear on them. In other words, the percentage of the spectra whose recall is 1. This matric suggests how sensitive the network can detect the available edges.

$$Rec=\frac{{N}_{rec}}{N}$$

Network validation

Besides the synthesized validation dataset, we also use 177 real experimental spectra to examine the performance of our network. The real spectra are from EELS Atlas Database from EELS.info, EELS DB (EELS Data Base) and our own experimental data67. Detailed experimental conditions for each spectra, including spectrum acquisition instrument, energy resolution, etc. are listed in Table S2 of the supplementary material.

Figure 6a shows the values of validation metrics for both the real spectra dataset and the validation dataset (The precision, recall, and F1-score are the averaged values). Figure 6b presents the boxplots of the F1-scores of the two datasets, where only some outliers have F1-scores less than 1, which means that our network is highly accurate in recognizing the edges. The average F1-scores of the real spectra dataset and the validation dataset are as high as 0.99 and 0.98, respectively. The comparable high F1-scores of the two datasets further indicate that the network is well-trained without overfitting. The average precision of the real spectra dataset and the validation dataset are 0.98 and 0.99, respectively. The average recall of the real spectra dataset and the validation dataset are 0.99 and 0.97, respectively. The high values of the precision and recall indicate that false positive and false negative edges barely appear in a prediction.

Figure 6
figure 6

Performance of the well-trained CNN-BiLSTM network.

The exact accuracy and the recognition accuracy are two metrics describing the percentages of the desired spectra. For the real dataset, the exact accuracy reaches 94.9%. And the network sensitively detects all the edges presented on the spectra, which can be reflected by the recognition accuracy of 98.9%. In other words, only around 1% of the predicted spectra have edges that failed to be detected by our network. Indeed, among the 9 failed cases, almost all the false positive Edges are due to the misrecognition of the nitrogen edge and scandium edge. Because the edges of these two elements have similar shapes and onsets, they can look identical on a spectrum. The false negative edges appear when the jump ratio is too low to be visible. The exact accuracy and recognition accuracy of the validation set is relatively lower than those of the real spectra dataset, but they are still around 90%. This phenomenon could be caused by the higher diversity of the synthesized spectra, where we stretched the parameters’ ranges during data augmentation to create more extreme cases.

Considering that the same element presenting in different compounds or allotropes can generate edges with various fine structures, the capability of our network in recognizing these edges is further evaluated. Carbon, as one of the essential elements forming the most compounds on earth and has multiple allotropes, is chosen as an example in this section to test our network. Figure 7 shows the C-K edge prediction of our network compared with the ground truth. Our network precisely detected the existence of the C-K edges in different materials containing carbon element. In addition, those spectra are from experiments68,69 different from those in our edge library.

Figure 7
figure 7

Network prediction versus ground truth for C-K edges from different materials.

Evaluation of model’s sensitivity

Peak signal noise ratio (PSNR)

To further evaluate the sensitivity of the model in detecting the ionization edges for a specific element, we introduce the concept of Peak Signal Noise Ratio, which is the signal noise ratio at the peak of the edge. It is expressed by the ratio of the signal at the edge peak off the inverse power law background (shown in Fig. 2 as Ip) to the standard deviation of the noise (sd). In other words,

$$PSNR=\frac{{I}_{p}}{sd}$$

To make the value of PSNR for different elements comparable, we further synthesize one spectrum for each element with the value of the power r for the background set to be the same constant 1.88. We added different levels of the Gaussian noise (white noise) to the spectra to create more extreme situations to examine the sensitivity of our network. The standard deviation of the noise is set to be one-tenth of the minimum value of the background:

$$std= \frac{\underset{50\sim 1100}{\mathrm{min}}{J}_{n}\left(E\right)}{10}$$

Sensitivity evaluation

To quantify the sensitivity of our network, we searched for the minimum value of PSNR for each element that the network can correctly recognize by varying the scale of the peak. To avoid anomalous results, for each element, we test the minimum value of PSNR for each edge in the library for 100 times and use the arithmetic mean as the final detectable PSNR. Correspondingly, the value of the jump ratio can be captured simultaneously. The results are listed in Table 4.

Table 4 Detectable PSNR and jump ratio.

It is worth noting that the detectable jump ratios in Table 4 are much lower than the minimum value of 0.15 we set for building the training dataset. This result illustrates that our network can manage the situation when the jump ratios of the edges are lower than those commonly observed in experiments. In the meanwhile, the noise is not smoothed by the Savitzky–Golay filter at this stage. Still, our network can sensitively extract valuable information from the noisy spectra. Thus, the detectable PSNR and Jump ratio in Table 4 can also serve as a reference for researchers determining whether the edges obtained from their experiments can be recognized by our network. Higher detectable PSNRs for light elements are expected because these edges tend to appear in a relatively high-intensity lower energy loss region. Referring to the corresponding low jump ratios, the network performs well in recognizing these light elements’ ionization edges.

Conclusion

In this work, we built a CNN-BiLSTM network for automatically detecting the ionization edges on EELS spectra. We also created a forward model for synthesizing EELS spectra, which allows us to create a database containing 250,000 spectra with ground-truth labels for training and testing the network. The network is examined by using both the synthesized validation dataset and the real spectra dataset collected from experiments. Multiple validation metrics are calculated to evaluate the performance of the network regarding the two datasets, including exact accuracy, recognition accuracy, average precision, average recall, and average F1-score. The sensitivity of the network is explored by testing the lowest detectable PSNR and detectable jump ratio.

The average F1-score, recall, and precision for the real spectra dataset agree well with those for the validation dataset, which suggests that, for one thing, the synthesized spectra are comparable to real spectra, for the other, the network is well-trained without overfitting. The high values of these three metrics also illustrate the good performance of the network in respect to the low false positive or false negative rate. We find that for 98.9% of the real spectra, our network is able to recognize all the edges. For 94.9% of them, our network can accurately recognize all the edges without false positive edges, which means that only around 4% of the spectra have false positive edges, and around 1% of the spectra have false negative edges. What’s more, the low value of the detectable PSNRs and jump ratios further demonstrate the high sensitivity of our network.

Taken together, our CNN-BiLSTM network can automatically recognize the core-loss edges on a raw spectrum with high accuracy. It is also safe to be applied to EELS spectra where the SNR and jump ratio are extremely low. The success of the network in automatically recognizing core-loss edges on a raw spectrum further makes it possible to the automation of more advanced core-loss edge analysis.