Explainable Transformer-Based Deep Learning for Lung Nodule Classification in Computed Tomography Imaging
Abstract
Accurate classification of pulmonary nodules in computed tomography (CT) images is essential for early lung cancer detection. However, many conventional deep-learning models provide limited explanations for their predictions, restricting their acceptance in clinical practice and compliance with regulatory frameworks such as the EU AI Act and FDA Software as a Medical Device guidance. This study proposes XTransLung, an explainable transformer-based framework for classifying pulmonary nodules as benign, indeterminate, or malignant while generating clinically meaningful visual explanations. XTransLung uses a hybrid CNN–Vision Transformer architecture. A lightweight convolutional stem extracts local textural features from (224 \times 224 \times 3) CT images, while a 12-layer transformer encoder with 12 attention heads learns global and contextual relationships. The explainability pipeline combines Grad-CAM and transformer attention rollout. Grad-CAM identifies important patterns within the nodule core, whereas attention rollout captures surrounding characteristics such as spiculation, pleural tethering, and perinodular tissue changes. Their normalized outputs are fused to produce a unified saliency map showing the image regions that contributed most strongly to each prediction. The model was fine-tuned on the LIDC-IDRI dataset using nodules labelled according to consensus radiologist malignancy scores. The dataset included 912 benign, 681 indeterminate, and 594 malignant nodules. On a stratified test partition of 1,247 nodules, XTransLung achieved 94.7% accuracy, 93.2% sensitivity, 95.1% specificity, and a macro-average AUC-ROC of 0.971. It significantly outperformed ResNet-50, DenseNet-121, and a standard Vision Transformer baseline, with (p<0.01) after Bonferroni correction. The model obtained F1-scores of 0.952 for benign, 0.904 for indeterminate, and 0.961 for malignant nodules. No benign nodules were incorrectly classified as malignant, helping to reduce unnecessary clinical escalation. The fused explainability maps were evaluated against radiologist consensus segmentations for 120 manually annotated test cases. They achieved a mean Dice Similarity Coefficient of 0.824, compared with 0.728 for Grad-CAM and 0.754 for attention rollout used independently. This result demonstrates that combining local convolutional explanations with global transformer attention produces more spatially coherent and clinically relevant visual evidence. XTransLung also achieved an Expected Calibration Error of 0.028, indicating reliable probability estimates for clinical decision-making. With an inference speed of 18.3 nodules per second on an NVIDIA A100 GPU, the model is suitable for high-volume radiology workflows. Overall, XTransLung demonstrates that hybrid CNN–transformer models with radiologist-validated explainability can improve diagnostic accuracy, transparency, and clinical trust in AI-assisted lung cancer screening.