Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do machine learning when the inputs are of different sizes?

In standard cookbook machine learning, we operate on a rectangular matrix; that is, all of our data points have the same number of features. How do we cope with situations in which all of our data points have different numbers of features? For example, if we want to do visual classification but all of our pictures are of different dimensions, or if we want to do sentiment analysis but all of our sentences have different amounts of words, or if we want to do stellar classification but all of the stars have been observed a different number of times, etc.

I think the normal way would be to extract features of regular size from these irregularly sized data. But I attended a talk on deep learning recently where the speaker emphasized that instead of hand-crafting features from data, deep learners are able to learn the appropriate features themselves. But how do we use e.g. a neural network if the input layer is not of a fixed size?

like image 521
rhombidodecahedron Avatar asked Mar 02 '15 20:03

rhombidodecahedron


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 do you prepare the varied size input in CNN prediction?

There is a way to include both image sizes. You can preprocess your images so that they are re-sized to the same dimensions. This uses the Keras image flow API for data augmentation on the fly, and the data generators at the bottom of the code will adjust your images to whatever dimensions you specify at the top.

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).

Does the dataset size influence a machine learning algorithm?

Yes, it all depends on what is inside the dataset. For me, the only rule of thumb is to go with cross-validation. If you are in the situation in which you think that you will use 20,000 or 30,000 samples you're often in a case where cross-validation is not a problem.


2 Answers

Since you are asking about deep learning, I assume you are more interested in end-to-end systems, rather then feature design. Neural networks that can handle variable data inputs are:

1) Convolutional neural networks with pooling layers. They are usually used in image recognition context, but recently were applied to modeling sentences as well. ( I think they should also be good at classifiying stars ).

2) Recurrent neural networks. (Good for sequential data, like time series,sequence labeling tasks, also good for machine translation).

3) Tree-based autoencoders (also called recursive autoencoders) for data arranged in tree-like structures (can be applied to sentence parse trees)

Lot of papers describing example applications can readily be found by googling.

For uncommon tasks you can select one of these based on the structure of your data, or you can design some variants and combinations of these systems.

like image 59
Denis Tarasov Avatar answered Oct 04 '22 21:10

Denis Tarasov


You can usually make the number of features the same for all instances quite easily:

if we want to do visual classification but all of our pictures are of different dimensions

Resize them all to a certain dimension / number of pixels.

if we want to do sentiment analysis but all of our sentences have different amounts of words

Keep a dictionary of the k words in all of your text data. Each instance will consist of a boolean vector of size k where the i-th entry is true if word i from the dictionary appears in that instance (this is not the best representation, but many are based on it). See the bag of words model.

if we want to do stellar classification but all of the stars have been observed a different number of times

Take the features that have been observed for all the stars.

But I attended a talk on deep learning recently where the speaker emphasized that instead of hand-crafting features from data deep learners are able to learn the appropriate features themselves.

I think the speaker probably referred to higher level features. For example, you shouldn't manually extract the feature "contains a nose" if you want to detect faces in an image. You should feed it the raw pixels, and the deep learner will learn the "contains a nose" feature somewhere in the deeper layers.

like image 39
IVlad Avatar answered Oct 04 '22 19:10

IVlad