9

I've recently been delving into artificial neural networks again, both evolved and trained. I had a question regarding what methods, if any, to solve for inputs that would result in a target output set. Is there a name for this? Everything I try to look for leads me to backpropagation which isn't necessarily what I need. In my search, the closest thing I've come to expressing my question is

Is it possible to run a neural network in reverse?

Which told me that there, indeed, would be many solutions for networks that had varying numbers of nodes for the layers and they would not be trivial to solve for. I had the idea of just marching toward an ideal set of inputs using the weights that have been established during learning. Does anyone else have experience doing something like this?

In order to elaborate: Say you have a network with 401 input nodes which represents a 20x20 grayscale image and a bias, two hidden layers consisting of 100+25 nodes, as well as 6 output nodes representing a classification (symbols, roman numerals, etc). After training a neural network so that it can classify with an acceptable error, I would like to run the network backwards. This would mean I would input a classification in the output that I would like to see, and the network would imagine a set of inputs that would result in the expected output. So for the roman numeral example, this could mean that I would request it to run the net in reverse for the symbol 'X' and it would generate an image that would resemble what the net thought an 'X' looked like. In this way, I could get a good idea of the features it learned to separate the classifications. I feel as it would be very beneficial in understanding how ANNs function and learn in the grand scheme of things.

Community
  • 1
  • 1
Jonathan Pearl
  • 711
  • 8
  • 21
  • It is not clear what you mean by "what methods, if any, to solve for inputs that would result in a target output set." Can you be more specific in explaining your problem? – Greg Dec 28 '14 at 05:32
  • @Greg Thank you. I appended the original question with an edited example. I hope this clears up the ambiguity. – Jonathan Pearl Dec 28 '14 at 05:54
  • I don't understand. What does '7' look like to addition? '3+4', '1+6', '-100+107'? The letter 'X' should look like the 'X' you trained it with, right? The fact that it is composited in the memory network with all the other letters shouldn't change that notion. – dwn Dec 28 '14 at 06:02
  • Yes, exactly that. I realize this has little practical use, it would be merely an educational thing. I'm intrigued by what features it picks up on the most. In theory, the letter 'X' would be the same as it was trained with. But say your network was a bit hairy when it came to classifying one group, it would be fun to see what it thought what that classification would ideally look like. Or say you cripple your network by having a bottleneck in your hidden layer -- what features would it cling on to the most and how would it try to remedy its lack of resources. Impractical, but I'm curious. – Jonathan Pearl Dec 28 '14 at 06:08
  • 1
    I used to really like this guy Tony Plate's work. Never understood this particular paper very well, but maybe you'll get something out of it http://d-reps.org/papers/nc2000.pdf – dwn Dec 28 '14 at 06:09
  • One other thing you might like to look up is the TODAM2 model of human memory, just for the heck of it. It's a correlation approach, so it, like Hopfield or Kohonen networks, may have some visualizable qualities in the signals and structures. – dwn Dec 28 '14 at 06:22
  • I have read through Plate's paper, and although the models that are expressed are very interesting, I feel like it would only point to inputs that are "hot" or are swaying the classification. Which isn't necessarily the same as correlating inputs. I mean, in most cases it takes an orchestration of many inputs to determine features that lead to the output desired. Take the letter 'a' for example: there is one we see here, and there is the one that looks like an 'o' with a tail to the right. Both are symbolically recognized as an a, but graphing those models might result in them superimposed. – Jonathan Pearl Dec 28 '14 at 06:56
  • Possible duplicate of [Clarification on a Neural Net that plays Snake](http://stackoverflow.com/questions/42099814/clarification-on-a-neural-net-that-plays-snake) – devinbost Feb 15 '17 at 20:35
  • @devinbost again you are flagging this a dup of the other question – tom redfern Feb 15 '17 at 21:10

3 Answers3

6

For a simple feed-forward fully connected NN, it is possible to project hidden unit activation into pixel space by taking inverse of activation function (for example Logit for sigmoid units), dividing it by sum of incoming weights and then multiplying that value by weight of each pixel. That will give visualization of average pattern, recognized by this hidden unit. Summing up these patterns for each hidden unit will result in average pattern, that corresponds to this particular set of hidden unit activities.Same procedure can be in principle be applied to to project output activations into hidden unit activity patterns.

This is indeed useful for analyzing what features NN learned in image recognition. For more complex methods you can take a look at this paper (besides everything it contains examples of patterns that NN can learn).

You can not exactly run NN in reverse, because it does not remember all information from source image - only patterns that it learned to detect. So network cannot "imagine a set inputs". However, it possible to sample probability distribution (taking weight as probability of activation of each pixel) and produce a set of patterns that can be recognized by particular neuron.

Denis Tarasov
  • 1,051
  • 6
  • 8
  • I tried your formula above, and got scarily close here: https://jsfiddle.net/jn0n4xn4/12/ however it seems that the values are a bit skewed. Would you mind taking a look and seeing how this can actually be solved? It'd be awesome to see this solved in a simple way. What spurred the conversation: https://github.com/harthur-org/brain.js/issues/5 – Robert Plummer May 28 '16 at 19:18
3

I know that you can, and I am working on a solution now. I have some code on my github here for imagining the inputs of a neural network that classifies the handwritten digits of the MNIST dataset, but I don't think it is entirely correct. Right now, I simply take a trained network and my desired output and multiply backwards by the learned weights at each layer until I have a value for inputs. This is skipping over the activation function and may have some other errors, but I am getting pretty reasonable images out of it. For example, this is the result of the trained network imagining a 3: number 3

  • Your 3 looks great! So you are not doing Sigmoid activation or the inverse of it? – Nitzan Wilnai May 07 '17 at 04:16
  • I use sigmoid activation functions to train on the images, but when imagining the inputs of a given output, i just pass it backwards without doing the inverse of the activation function. Not entirely sure why it works so well. But, when I did try to pass through inverse sigmoid it made the image really fuzzy and wasn't clear at all what the number was. Kind of a mystery to me. – Nathan Egan May 16 '17 at 17:46
2

Yes, you can run a probabilistic NN in reverse to get it to 'imagine' inputs that would match an output it's been trained to categorise.

I highly recommend Geoffrey Hinton's coursera course on NN's here: https://www.coursera.org/course/neuralnets

He demonstrates in his introductory video a NN imagining various "2"s that it would recognise having been trained to identify the numerals 0 through 9. It's very impressive!

I think it's basically doing exactly what you're looking to do.

Gruff

Gruff
  • 524
  • 5
  • 13