ObjectiveThis work conducts a comparative study on the effect of neural networks of different architectures on the detection of paroxysmal atrial fibrillation (PAF) events from dynamic electrocardiography (ECG) recordings, a problem raised in the 4th China Physiological Signal Challenge 2021 (CPSC2021). ApproachWe proposed 3 neural network models and an auxiliary one for QRS detection to tackle the problem. A convolutional recurrent neural network (CRNN) model and a U-Net model that accepts ECG waveform input make sample-wise predictions. This regards the PAF events detection as a segmentation task. A stacked bidirectional long short-term memory (LSTM) model takes the sequence of RR intervals, which is derived from the output of the QRS detection model and makes beat-wise predictions. The QRS detection model also has a CRNN architecture, which is slightly different from the model for the AF segmentation task. Final predictions are merged by outputs from models making sample-wise predictions and making beat-wise predictions. Finally, the locations of QRS complexes are used to filter out segments (both normal and AF) shorter than 5 beats.In order to make the neural network models more sensitive to the critical sample points (onsets and offsets) of the AF events, we proposed a novel masked binary cross-entropy (MaskedBCE) loss function for training the models. This loss function is the conventional BCE loss multiplied by a mask, whose values in a neighbourhood of critical sample points are significantly larger than elsewhere. Main resultsOur method received a score of 1.9972 on the first part of the hidden test set of CPSC2021 and a score of 3.0907 on the second part. The average score was 2.5440, ranked 5th out of 17 teams with successful official entries. SignificanceThis work proposed an effective solution to the problem of the detection of PAF events from dynamic ECGs and validated the efficacy of several neural network architectures on this problem.