If you have ever worked with real-world sequential data you know that they are rarely clean. Real-world datasets are notoriously plagued by irregular sampling intervals, missing data points and scale heterogeneity, while standard Machine Learning models typically rely on dense, uniformly sampled time series data.
The traditional data science workflow attempts to force messy data into a neat, uniform grid, usually via interpolation, or by synthetic data generation. Unfortunately, these methods often introduce bias, alter genuine underlying signal dynamics, or invent events that simply didn’t happen.
A study by P. Rodis (2026), published in the International Journal of Data Science and Analytics, offers a powerful alternative. It introduces a Transformer Autoencoder with Local Attention engineered to learn structural patterns directly from sparse and irregular time series, circumventing the need for synthetic interpolation. Here is how it completely rethinks data normalization and how it performs on a massive, highly imbalanced real-world dataset.
The core philosophy of the autoencoder is to bypass imputation by leveraging unsupervised latent space representations. During training, the model generates an encoded representation of the dataset within its latent space. During inference, the model reconstructs the input based on the generated representation and uses the Mean Squared Error of the reconstruction as an anomaly score. Familiar patterns yield low errors, while structural anomalies yield high errors. The specialized features of the architecture increase the discriminative capabilities of this method.
Transformers are renowned for their self-attention mechanism, which computes dot-product interactions across all element pairs in a sequence.
However, full self-attention poses two distinct problems for sparse time series:
Noise from Distant Dependencies. In highly irregular data, forcing the model to calculate attention across distant temporal points can introduce unnecessary noise, underestimating the localized structural anomalies that actually matter.
Computational Overhead. Full self-attention incurs \(O(N^2)\) computational complexity, which is heavily taxing on long sequences.
Local attention models solve these by restricting the self-attention computation to a predefined local temporal window $w$ around each sequence index $i$. To handle the edges of the time series, the window boundaries are dynamically scaled. The attention window starts at \(\max(0, i - \lfloor w/2 \rfloor)\) and ends at \(\min(\vert{}x\vert{}, i + \lfloor w/2 \rfloor + 1)\).
By applying a mask that zeros out the attention scores (\(QK^T\)) outside this local window before the softmax operation, the model is forced to focus on immediate temporal neighbors. This acts as a highly discriminative feature extractor.
For data generated by heterogeneous entities the absolute scales differ drastically. The study introduces a two-step normalization strategy to prevent the autoencoder from simply memorizing magnitudes.
Row-wise Normalization. First, the absolute measurements within each individual time series are transformed into relative proportions:
\[x_{i,j}' = \frac{x_{i,j}}{\sum_z x_{i,z}} \text{, for each row $i$ and sample $j$}\]This step equalizes scale disparities. The model stops looking at how much volume is present and starts analyzing the proportional shape and behavioral fluctuations of the sequence.
Global MinMax Scaler. Next, the feature proportions are rescaled globally across the entire dataset to the $[0, 1]$ interval, ensuring numerical stability for the transformer layers.
Standard Transformer blocks rely heavily on Layer Normalization. Nevertheless, the two-step normalization procedure applied in this framework eliminates the need for this internal Normalization. Applying both techniques would cause over-normalization.
The model was deployed on a massive, real-world dataset provided by the Hellenic Electricity Distribution Network Operator (HEDNO) to estimate the risk of Non-Technical Losses (NTL), or else electricity theft. This dataset is a nightmare in many ways:
Large Scale. Includes 1,234,509 consumer accounts and over 9.2 million measurements collected between 2018 and 2022.
Severe Heterogeneity. Data was collected via human manual readings and two different types of automated telemeters.
Extreme Irregularity. Intervals ranged from monthly to quarterly to completely arbitrary periods.
Extreme Imbalance. NTL in Greece is estimated to be less than 5% of total consumption. Out of the final pre-processed dataset of 347,546 normalized sequences (padded to 58 time-steps), only 891 were labeled as confirmed theft.
The model consisted of four Transformer encoder blocks, four Transformer decoders and a latent space of dimension equal to 10 in between. Training required 2 minutes on an NVIDIA Tesla T4 GPU and 2 hours on standard CPU equipment.
During inference, the time series were sorted in descending order by reconstruction error and subsequently clustered. The cluster containing the highest errors (with a fixed size set to 15% of the dataset) was designated as the high-risk cluster.
The high-risk cluster successfully captured approximately 50% of the known NTL cases, which is evaluated as an impressive feature given the extreme irregularity of the dataset. Furthermore, the proposed model exhibited notable robustness as it managed to maintain highly consistent clustering results even when trained on different subsets of the dataset. This result demonstrates the model’s ability to extract critical structural features and underlying relationships without overfitting to small-scale relationships that vary on different training samples.
Transformers are not only useful in LLMs; they offer significant potential in Autoencoder models for data analysis, due to their enhanced discriminatory capabilities. They manage to identify critical features even when trained on a representative subset of the total dataset. Moreover, local attention enables the model to focus on neighboring features discriminating them from noise.
Ultimately, the presented framework shows that when dealing with sparse, irregular and heterogeneous temporal data, it is not necessary to invent missing data points. Combining local attention with appropriate normalization, empowers Transformers to detect the hidden anomalies within the messy reality of the data itself.