Pass through encoder example?

encoders
pass-through-encoder

#1

Hi, are there any examples of pass through encoder model params? I’m trying to pass in my encoded categorical values right into the temporal memory. The rows of the input file are encoding bit strings instead of raw values, such as: [1,1,1,1,1,0,0,0,0,0,0,0,0,0,…] of length 40, and I’m currently getting this.

TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’

Here’s where I feed the inputs into NuPIC, each ‘row’ is a binary vector like the one shown above:

for row in csvReader:

  counter += 1
  if (counter % 100 == 0):
     print "Read %i lines..." % counter
  letter = row 
  result = model.run({
  "passThruSeq": letter
})

Here is my model params file too:
https://pastebin.com/n1wF7E7Z

Thanks!!


#2

Try converting your array of strings into integers with a list comprehension:

"passThruSeq": [int(bit) for bit in letters]

#3

Hey Matt, thanks again for your attention! So I did that and got this:

File “run_passthru.py”, line 102, in runIoThroughNupic
“passThruSeq”: [int(bit) for bit in letter]
ValueError: invalid literal for int() with base 10: ‘[1’

Here are the first few lines from the data file itself, maybe there’s something wrong with my format?

passThruSeq
[1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0]


#4

Looks like letter is not an array of strings, but a string itself. You’ll have to parse it. Remove the [,] from the string and split on the comma before calling int(). You should google it, this is a little out of scope.


#5

Ok its all one big string, thats a huge help I’ll resolve it


#6

Ok so I got that resolved, and ‘letter’ is now an numpy array of length 40 with each bit an int. I’m now getting this however;

ValueError: could not broadcast input array from shape (40) into shape (1)

This seems to suggest that it can’t handle an array, or something with shape > 1. Is this possible?


#7

I don’t think your numpy array is the shape you want. Can you just send in an array of ints instead?


#8

I believe it is an array ints, here’s the code now:

for row in csvReader:

counter += 1
if (counter % 100 == 0):
  print "Read %i lines..." % counter
letter = np.array([int(bit) for bit in row])
result = model.run({
  "passThruSeq": letter
})

Here are data types of ‘letter’ and ‘bit’
<type ‘numpy.ndarray’>
<type ‘numpy.int64’>

When I set letter = [int(bit) for bit in row] – without the np.array() around it here’s the error I got:

ValueError: cannot copy sequence with size 40 to array axis with dimension 1


#9

I think it is expecting an array of arrays. Try:

"passThruSeq": [letter]

I know someone has used this encoder before, but I have not.


#10

That seems to trigger another issue:

TypeError: init() takes at least 2 arguments (3 given)

My point in all this is to bypass the SP, is there another way to do this without using the PassThru?


#11

Sure, you can bypass the OPF completely. See the algorithm quick start. Just ignore the SP and pass bits straight into the TM. All you need is an array of active mini-column indices.