# Continuous online sequence learning with an unsupervised neural network model

Yuwei Cui, Subutai Ahmad, Jeff Hawkins · arXiv · 2015-12-17

- **Problem** Streaming sequence learners must keep adapting while the data changes, yet batch-trained models need buffered data and periodic retraining.
- **Method** The study applies HTM sequence memory, which uses sparse distributed codes and a Hebbian-style online rule, to artificial high-order sequence streams and to New York City taxi demand, and compares it with ARIMA, ELM, ESN and LSTM.
- **Results** Reached perfect prediction accuracy on the single-prediction high-order task and on both the 2-prediction and 4-prediction tasks, while LSTM was not accurate in the 4-prediction case.

## Why streaming sequence learning needs more than accuracy

Sequence prediction on data streams is hard for reasons a benchmark accuracy score does not capture. Streams often have changing statistics, so a learner has to keep learning and adapt quickly when they shift. A batch-trained model handles this by keeping a buffered dataset of past records and retraining at regular intervals. That costs storage and computation, and the cost grows when the data arrives quickly.

The authors turn these demands into five criteria: continuous learning, high-order predictions, multiple simultaneous predictions, noise robustness with fault tolerance, and no task-specific hyperparameter tuning. ARIMA is limited to maximum-likelihood point predictions, so it lacks the multiple-prediction property that HMMs and generative recurrent networks have.

## How HTM sequence memory holds context

Each HTM neuron has a proximal zone with one dendritic segment and a distal zone with several independent segments. Proximal synapses carry feedforward input, while distal synapses carry lateral connections within the layer. A distal segment becomes active when enough of its connections are active at once. Its cell is then placed in a predictive state, which is not the same as firing.

Each neuron is active, predictive or inactive, and its output is always binary.

The network represents the current input through columns. The top 2% of columns, ranked by their feedforward input, become active at each step. Within the active columns, the cells encode the learned temporal context. A predicted cell suppresses the other cells in its column when the column later receives enough feedforward input, so the active cells reflect the context and not only the current input.

The model is illustrated with the sequences A-B-C-D and X-B-C-Y. The columns for B and C are the same in both sequences, but different cells in them are active, so the correct element after C can be chosen. Because several cells can be predicted together, presenting B without context activates cells that predict both C' and C''. The distributed storage also gives robustness to input noise and to loss of neurons and synapses.

## Predictions, activation and Hebbian-style updates

A cell enters the predictive state when one of its distal segments has more connected synapses active in the previous step than the segment threshold. The authors use this threshold rule in place of a weighted sum over inputs.

In a winning column, a cell becomes active if it was predicted in the preceding step. If no cell in the column was predicted, all cells in that column become active. Lateral learning is Hebbian-like. A segment that caused a correct depolarization is reinforced. If no cell in an active column was predicted, the cell with the most activated segment has its segment reinforced instead.

Reinforcing a segment lowers the permanence of its inactive synapses by a small amount and raises the permanence of its active synapses by a larger amount. Segments that did not lead to activation receive a very small decay, which the authors link to long-term depression. The authors did not derive this rule from gradient descent on a cost function.

Synapses start at a permanence of 0.21, below the connection threshold of 0.5.

## From symbols to SDRs and back to predictions

A random SDR encoder maps categorical symbols to sparse codes. For the taxi task, scalar and date-time encoders were used instead. Each categorical symbol is a random code with 40 active bits in a 2048-bit vector, which matches the 2048 columns with 40 active at any time in the HTM network.

For discrete sequences, a simple classifier scores each possible symbol by the overlap between its code and the predicted cells, then picks the highest. For continuous values, the range is split into 22 disjoint buckets. A single-layer classifier with a softmax output estimates the probability of each bucket from the active cells. Its weights move in proportion to the gap between the estimated and observed distributions, scaled by the input, and the update is cheap because the input is highly sparse.

## A continuous stream of high-order sequences

Sequences are streamed one after another, with a single noise element after each sequence. The noise elements come from a set of 50,000 noise symbols that are not used in the sequences. The start and end of each sequence are not marked, and the set of noise symbols is too large for a learner to memorize every noise transition. Each sequence must be predicted from its first two elements, so context has to be held over several steps.

The authors used two LSTM variants. One is retrained at regular intervals on a buffer of past elements, and the other is trained online with truncated back-propagation through time over the last 100 elements. ELM is trained sequentially online.

Accuracy is measured by whether the actual last element is among the top K predictions, with K equal to 1 in the single-prediction case and 2 or 4 in the multiple-prediction case. Because the tasks are online, there is no separate training and test phase. Each sequence's ending is scored before the model has seen it.

## Single and multiple possible endings

With one ending per context, HTM quickly reached perfect prediction accuracy. Given a large enough learning window, LSTM also learned the high-order sequences. The authors contrast the data use: LSTM makes many passes over the window at each retraining, whereas HTM sees each element once.

LSTM took longer than HTM to reach perfect accuracy, and the authors speculate that it overfit the random transitions between sequences early on. Online LSTM scored best at the start but did not reach perfect accuracy. ELM learned more slowly than HTM and never reached perfect performance. Among these learners, only HTM and LSTM reached perfect accuracy on this task.

With two or four possible endings per context, HTM reached perfect accuracy in both cases. LSTM was accurate for the 2-prediction case when given a large learning window, but was not accurate when the number of predictions reached 4 or more.

The authors attribute this to SDRs: a union of many random codes can be read out with a low false-positive rate. The dense encoding used for LSTM averages poorly when many targets are predicted at once, and one-hot codes have limited capacity. They suggest that LSTMs using SDRs might perform better on this task.

## Recovery after the endings are swapped

After the models reached stable performance, the last elements of pairs of high-order sequences were swapped. The change follows the point at which 10,000 elements had been seen. HTM and online LSTM recovered quickly. Batch LSTM and ELM took a long time, because their buffers held both the old and the new contradictory endings.

A smaller learning window speeds up recovery for the batch models, but it lowers the final accuracy because it leaves fewer training samples. The authors describe a tradeoff between accuracy and flexibility. HTM reached the best final accuracy with a small number of samples and recovered faster than batch-trained ELM and LSTM after the change.

## Scaling to longer Markov orders

The Markov order was varied through the length of the shared subsequences. HTM reached perfect prediction on sequences up to 100th order. The number of sequences needed for perfect prediction grows, according to the authors, linearly with the sequence order. Early accuracy reaches 50% quickly, because a first-order model suffices for that level.

## Temporal noise and loss of cells

Temporal noise replaced the second, third or fourth element of each sequence with a random symbol. In one setting the noise was present throughout training, and in the other it was introduced after 12000 elements. With noise throughout training, neither HTM nor LSTM made perfect predictions. LSTM was slightly better, and HTM behaved like a first-order model with accuracy of about 0.5.

When noise was injected after clean training, HTM accuracy dropped to 0.5, the first-order level, and LSTM performed worse. The authors read this as HTM robustly behaving as a low-order model once its high-order context is disrupted, while LSTM depends on its training history.

For cell death, the authors removed a fraction of the cells and their synapses after stable performance, then measured accuracy over a further 5000 steps without learning. HTM showed no impact up to 30% cell death. ELM and LSTM accuracy declined rapidly with a small fraction of cell death. The authors note that redundancy or dropout might improve LSTM fault tolerance, and they attribute HTM's tolerance to the properties of sparse distributed representations.

## Taxi passenger demand

New York City taxi rides were aggregated into passenger counts at 30-minute intervals. The task is to predict the passenger demand 5 steps, or 2.5 hours, ahead. The authors report that HTM reached performance comparable to ESN and ARIMA with single-pass training, whereas LSTM required multiple passes over a buffered dataset.

Prediction error is reported as mean absolute percentage error and as negative log-likelihood. The data were then changed by decreasing weekday morning traffic from 7am to 11am by 20% and increasing weekday night traffic from 9pm to 11pm by 20%, starting from April 1st. Both HTM and LSTM showed an immediate increase in prediction error.

HTM's prediction error dropped back in about two weeks, while LSTM's stayed high for a much longer time. The authors report that HTM had better prediction accuracy than LSTM and the other models after the modification, on both metrics.

## Limits of the model and of the evidence

As a strict one-pass algorithm, HTM may take longer than history-buffer algorithms to learn very long-term dependencies. Replaying a history buffer through HTM several times could speed this up. HTM is robust to spatial noise but sensitive to temporal noise, and it loses high-order context when elements are replaced by random symbols. The authors suggest a hierarchy of sequence memories at different time scales as a way to improve this, but do not test it.

On the Reber grammar task, HTM reached 98.4% accuracy, ELM reached 86.7% after online training on 500 sequences, and LSTM reached 100%. The authors say HTM approximately learns these grammars by memorizing example sentences, which may need more samples for recursive grammars.

All HTM experiments here use low-dimensional categorical or scalar streams. Whether HTM handles high-dimensional data such as speech or video was not tested, and the authors suggest pre-processing might be needed. The ELM and LSTM comparisons use commonly used training methods, and the ELM and LSTM settings are given in the appendix, so results depend on those choices.

## Paper info

- **Authors**: Yuwei Cui, Subutai Ahmad, Jeff Hawkins
- **Venue**: arXiv · Preprint
- **First published**: 2015-12-17
- **Added**: 2026-11-6
- **Updated**: 2016-4-28
- **Version**: v2
- **arXiv**: 1512.05463
- **DOI**: 10.1162/neco\_a\_00893
- **Category**: cs.NE · q-bio.NC
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/1512.05463v2) · [PDF ↗](https://arxiv.org/pdf/1512.05463v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Abstract

The ability to recognize and predict temporal sequences of sensory inputs is vital for survival in natural environments. Based on many known properties of cortical neurons, hierarchical temporal memory (HTM) sequence memory is recently proposed as a theoretical framework for sequence learning in the cortex. In this paper, we analyze properties of HTM sequence memory and apply it to sequence learning and prediction problems with streaming data. We show the model is able to continuously learn a large number of variable-order temporal sequences using an unsupervised Hebbian-like learning rule. The sparse temporal codes formed by the model can robustly handle branching temporal sequences by maintaining multiple predictions until there is sufficient disambiguating evidence. We compare the HTM sequence memory with other sequence learning algorithms, including statistical methods: autoregressive integrated moving average (ARIMA), feedforward neural networks: online sequential extreme learning machine (ELM), and recurrent neural networks: long short-term memory (LSTM) and echo-state networks (ESN), on sequence prediction problems with both artificial and real-world data. The HTM model achieves comparable accuracy to other state-of-the-art algorithms. The model also exhibits properties that are critical for sequence learning, including continuous online learning, the ability to handle multiple predictions and branching sequences with high order statistics, robustness to sensor noise and fault tolerance, and good performance without task-specific hyper- parameters tuning. Therefore the HTM sequence memory not only advances our understanding of how the brain may solve the sequence learning problem, but is also applicable to a wide range of real-world problems such as discrete and continuous sequence prediction, anomaly detection, and sequence classification.

## Quote from the paper

Yuwei Cui, Subutai Ahmad, Jeff Hawkins (2015). Continuous online sequence learning with an unsupervised neural network model. arXiv:1512.05463v2. https://doi.org/10.1162/neco\_a\_00893

**BibTeX**

```
@article{cui2015continuous,
  title = {{Continuous online sequence learning with an unsupervised neural network model}},
  author = {Yuwei Cui and Subutai Ahmad and Jeff Hawkins},
  year = {2015},
  eprint = {1512.05463},
  archivePrefix = {arXiv},
  doi = {10.1162/neco_a_00893},
  url = {https://arxiv.org/abs/1512.05463v2}
}
```

## Other paper commentary

- [A Cost-Sensitive Deep Belief Network for Imbalanced Classification](https://refivu.com/en/papers/140fac18-43ea-4f02-a761-0549f84a0de3-a-cost-sensitive-deep-belief-network-for-imbalanced.md)
- [Weakly-Supervised Convolutional Neural Networks for Multimodal Image Registration](https://refivu.com/en/papers/bfc7dfd6-1596-4541-9723-c26ab0c5a3f5-weakly-supervised-convolutional-neural-networks-for.md)
- [A Deep Cascade of Convolutional Neural Networks for Dynamic MR Image Reconstruction](https://refivu.com/en/papers/c81adf70-889d-4a7a-93f1-14353887187b-a-deep-cascade-of-convolutional-neural-networks-for.md)
- [Learning to (Learn at Test Time): RNNs with Expressive Hidden States](https://refivu.com/en/papers/6a02f8bd-d757-4f00-9d97-6829bf6db29f-learning-to-learn-at-test-time-rnns-with.md)
- [GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints](https://refivu.com/en/papers/11792bcd-8c73-4a2d-8b43-c855c3d7ad48-gqa-training-generalized-multi-query-transformer-models-from.md)
- [Fast Transformer Decoding: One Write-Head is All You Need](https://refivu.com/en/papers/65f892e7-2a21-4ce7-9e89-c75f7ec6b23c-fast-transformer-decoding-one-write-head-is-all.md)
- [Multi-Temporal Land Cover Classification with Sequential Recurrent Encoders](https://refivu.com/en/papers/fbc752d9-1a2a-4b13-ac64-8967dd7bd971-multi-temporal-land-cover-classification-with-sequential.md)
- [StyleFlow: Attribute-conditioned Exploration of StyleGAN-Generated Images using Conditional Continuous Normalizing Flows](https://refivu.com/en/papers/49804159-5719-4639-92c6-0d48431420f2-styleflow-attribute-conditioned-exploration-of-stylegan.md)
- [Deep Reinforcement Learning for Stochastic Computation Offloading in Digital Twin Networks](https://refivu.com/en/papers/3abcd222-e3a8-4466-ab8d-04aeace1e847-deep-reinforcement-learning-for-stochastic-computation.md)
- [Federated Social Recommendation with Graph Neural Network](https://refivu.com/en/papers/ce54fcd7-f119-4f48-9809-3fe4f5cc05cd-federated-social-recommendation-with-graph-neural-network.md)
- [Machine learning-based network intrusion detection for big and imbalanced data using oversampling, stacking feature embedding and feature extraction](https://refivu.com/en/papers/ffcd2c90-0ecb-4bf2-968e-883dd5d0ec8e-machine-learning-based-network-intrusion-detection-for-big.md)
- [Mastering the Game of Stratego with Model-Free Multiagent Reinforcement Learning](https://refivu.com/en/papers/c8ba1a5f-8040-4096-92b0-d848951ca124-mastering-the-game-of-stratego-with-model-free.md)

## Terms in this paper

- [LSTM](https://refivu.com/en/terms/ba10547646d9-lstm)
- [negative log-likelihood](https://refivu.com/en/terms/e6d7135ed9ca-negative-log-likelihood)
- [ARIMA](https://refivu.com/en/terms/4c8179f83b57-arima)
- [prediction accuracy](https://refivu.com/en/terms/bc66df146189-prediction-accuracy)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/2850b462-149b-4637-8186-0e3a02a69df4-continuous-online-sequence-learning-with-an-unsupervised)
