Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are neural networks used when the number of inputs could be variable?

All the examples I have seen of neural networks are for a fixed set of inputs which works well for images and fixed length data. How do you deal with variable length data such sentences, queries or source code? Is there a way to encode variable length data into fixed length inputs and still get the generalization properties of neural networks?

like image 639
Jeremy E Avatar asked Nov 19 '09 20:11

Jeremy E


People also ask

How can neural networks deal with varying input sizes?

For variable sized inputs where there is no particular ordering among the inputs, one can design networks which: use a repetition of the same subnetwork for each of the groups of inputs (i.e. with shared weights). This repeated subnetwork learns a representation of the (groups of) inputs.

How does neural network determine number of input neurons?

Every network has a single input layer and a single output layer. The number of neurons in the input layer equals the number of input variables in the data being processed. The number of neurons in the output layer equals the number of outputs associated with each input.

How many inputs can a neural network handle?

In popular nets the length and height of input images are usually less than three hundred which makes the number of input features 90000 . Also you can employ max-pooling after some convolution layers, if you are using convolutional nets, to reduce the number of parameters.

Which neural network layer helps in handling variable size inputs?

Fully convolutional neural network is able to do that. Parameters of conv layers are convolutional kernels. Convolutional kernel not so much care about input size(yes there are certain limitations related to stride, padding input and kernel size).


4 Answers

I have been there, and I faced this problem. The ANN was made for fixed feature vector length, and so are many other classifiers such as KNN, SVM, Bayesian, etc. i.e. the input layer should be well defined and not varied, this is a design problem. However, some researchers opt for adding zeros to fill the missing gap, I personally think that this is not a good solution because those zeros (unreal values) will affect the weights that the net will converge to. in addition there might be a real signal ending with zeros.

ANN is not the only classifier, there are more and even better such as the random forest. this classifier is considered the best among researchers, it uses a small number of random features, creating hundreds of decision trees using bootstrapping an bagging, this might work well, the number of the chosen features normally the sqrt of the feature vector size. those features are random. each decision tree converges to a solution, using majority rules the most likely class will chosen then.

Another solution is to use the dynamic time warping DTW, or even better to use Hidden Markov models HMM.

Another solution is the interpolation, interpolate (compensate for missing values along the small signal) all the small signals to be with the same size as the max signal, interpolation methods include and not limited to averaging, B-spline, cubic.....

Another solution is to use feature extraction method to use the best features (the most distinctive), this time make them fixed size, those method include PCA, LDA, etc.

another solution is to use feature selection (normally after feature extraction) an easy way to select the best features that give the best accuracy.

that's all for now, if non of those worked for you, please contact me.

like image 136
Ahmad Hassanat Avatar answered Oct 15 '22 10:10

Ahmad Hassanat


You would usually extract features from the data and feed those to the network. It is not advisable to take just some data and feed it to net. In practice, pre-processing and choosing the right features will decide over your success and the performance of the neural net. Unfortunately, IMHO it takes experience to develop a sense for that and it's nothing one can learn from a book.

Summing up: "Garbage in, garbage out"

like image 28
f3lix Avatar answered Oct 15 '22 10:10

f3lix


Some problems could be solved by a recurrent neural network. For example, it is good for calculating parity over a sequence of inputs.

The recurrent neural network for calculating parity would have just one input feature. The bits could be fed into it over time. Its output is also fed back to the hidden layer. That allows to learn the parity with just two hidden units.

A normal feed-forward two-layer neural network would require 2**sequence_length hidden units to represent the parity. This limitation holds for any architecture with just 2 layers (e.g., SVM).

like image 39
Ivo Danihelka Avatar answered Oct 15 '22 08:10

Ivo Danihelka


I guess one way to do it is to add a temporal component to the input (recurrent neural net) and stream the input to the net a chunk at a time (basically creating the neural network equivalent of a lexer and parser) this would allow the input to be quite large but would have the disadvantage that there would not necessarily be a stop symbol to seperate different sequences of input from each other (the equivalent of a period in sentances)

like image 39
Jeremy E Avatar answered Oct 15 '22 08:10

Jeremy E