The coding of longer sequences in HTM SDRs

My apologies for not replying sooner. I’ve been away from the forums for quite a while. It’s nice to see folks getting back to thinking about new ways to implement complex dynamical systems rather than just endlessly talking about AGI and its potential implications. I’ve always preferred the former over the latter. I still need to go over some of the previous threads for additional context, but I figured I could start here with something constructive.

  1. For early prototyping, you could probably get away with just about any reasonably sized text corpus. Recently I’ve been playing around with “War and Peace”, because I just happened to have a copy of the novel lying around in plain text downloaded from the Gutenberg project.

  2. I’ve written a number of encoders over the past few years. Lately, I’ve been using an ASCII encoder that is based on this idea I had for a Grid Cell Inspired Scalar Encoder. Here it is implemented in a JavaScript class, but the concept is fairly straight-forward. It should be easy to convert into another language if necessary.

class AsciiEncoder {
  constructor() {
    this.char = '';
    this.ascii = 0;
    this.numNodes = 16;
    this.sparsity = 0.50;
    this.data = new Uint8Array(16);
    this.encode(0);
  }
  encode(c) {
    this.char  = String(c).charAt(0);
    this.ascii = String(c).charCodeAt(0);
    this.data.fill(0);
    var val = parseInt(this.ascii);
    for (var i=0; i<8; ++i) {
      this.data[2*i+0] = (val%2 == 1 ? 0 : 1);
      this.data[2*i+1] = (val%2 == 1 ? 1 : 0);
      val = parseInt(val/2);
    }
  }
  print() {
    console.log(this.char, this.ascii);
    console.log(this.data);
  }
};
  1. If you prefer, you can think of the above as a column-level SDR encoding of an ASCII character. In that case, I would encode a sequence of letters in context as multiple adjacent columns. Each column acts as an encoder for an array of ASCII sensors. This should allow you to saccade along the input sequence with a variety of step sizes.
  • Example scenario: The agent saccades to the beginning of a word and the N-character sensor array encodes the leading space and the first N-1 characters in the word. It then attempts to form a representation of the current word and form a prediction of the next few characters in the sequence. If the prediction is unambiguous, then the agent can saccade forward in the sequence to verify its prediction, or simply move ahead to a region where it has less confidence in it’s prediction (i.e. multiple predictions are possible) and sample the text again to disambiguate it’s predictions.
  1. As @bitking alluded, there are a variety of inhibitory cells present in the cortex and each of them seem to be performing an important role in some aspect of feedback/control of local activations. The result is a level of activation that is typically at or near the critical point for the local network (i.e. approximately the same number of neurons firing at any moment in time). Too many neurons firing, and the network blows up (seizure). Too few firing and the network collapses (comatose). In the code provided above, the sparsity in the representation is explicit and fixed (at 50%) by the encoding scheme. Inhibition should not be necessary at this level, but should instead be applied to the layers downstream of the input encoder to ensure that the homeostatic equilibrium state for the neurons firing in those layers is at or near their critical point.

From this point, a temporal sequence memory would be appropriate to form the predictive states. There have been numerous discussions on this forum and elsewhere as to the practical limits on the capacity of the HTM model, both for representing certain types of sequences (e.g. involving repeating symbols or varying durations or intervals) and also being able to reliably store extended sequences. I working on a new approach that I hope will be able to resolve one or more of these shortcomings.

4 Likes