Pantelis Rodis

Analyzing Sparse and Irregular Time Series using Transformers

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.

AI generated image

The Local Attention Autoencoder Framework: Architecture Breakdown

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.

The Local Attention Mechanism

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:

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.

Normalization Strategy

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.

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.

Real-World Case Study: Estimating Non-Technical Losses in Power Systems

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:

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.

Takeaways

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.

P. Rodis. Transformer autoencoder with local attention for sparse and irregu- lar time series with application on risk estimation. International Journal of Data Science and Analytics 22(1), 201 (2026).