Explainable XRF Element Detection with Embedding-Space KNN and Physics-Based Masks for the HARLOCK Lunar Rover
2026-11-02 –, Seminar Room 2

In astrophysics, Deep neural networks have achieved state-of-the-art performance in a variety of spectral analysis tasks. However, these models are often considered "black boxes", providing limited insight into predictions and requiring post-hoc tools for explanations. This lack of transparency can limit their adoption in scientific contexts, as in these environments interpretability is essential. This is one of the challenges in the development of RHEA, the Rare-earth \& Heavy Elements Analyzer of the HARLOCK project within the PRORIS program. It combines gamma-ray spectroscopy, multispectral imaging, ultraviolet fluorescence screening and X-ray fluorescence analysis to identify Rare-Earth Elements (REE) deposits and associated elemental and mineralogical signatures across different spatial scales.

In this work, we propose a model-agnostic framework that converts any Convolutional spectral classifier into an explainable predictor without hindering its performance on multiple metrics, demonstrating it on a complete model working with attention masks for additional insight and training stability. Our approach exploits the Neural Network's latent representation and preservation of spatial features: after training, the final regression layer of the backbone model is removed and replaced by a K-Nearest Neighbors (KNN) regressor operating directly on the learned embedding space; as a result, every prediction is accompanied by an explanation in the form of the most similar spectra observed during training. This works particularly well thanks to a custom loss function designed to optimize the quality of the learned embedding space, without hindering performances.

Furthermore, in our model, for each predicted element an associated attention mask is learned at training time starting from a physics-based initialization. This way, the framework provides, alongside instance-level explanations, easily readable heatmaps in the form of a mask-by-weights product, allowing users to trace model outputs back to representative examples in the training data and the relevant parts of the input used. Experimental results show that, in a regression task estimating the composition of soil samples, the average R2 score over the predicted elements stays around 0.9 for both the original approach and the explainable Deep kNN model (depending on the complexity of the task).

Our proposal offers a practical path toward trustworthy AI for spectroscopy, combining the representational power of deep learning with the transparency of example-based reasoning.

See also: Poster PDF (2.0 MB)

Ghulam Mustafa is a PhD candidate in Computer Science and Engineering at the University of Bologna. His research focuses on machine learning for gamma-ray astrophysics, particularly COSI background prediction, transient detection, and localization.

This speaker also appears in:

Computer Science PhD researcher at the University of Bologna, specializing in Artificial Intelligence. Master’s degree cum laude in AI from the University of Bologna and hands-on industry experience, including development work for Airbus and INAF. Enjoys tutoring and teaching assistant work.