Lasagne / Lasagne

Lightweight library to build and train neural networks in Theano

Home Page:http://lasagne.readthedocs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LSTMLayer should check input dimensionality

f0k opened this issue · comments

When passing a two-dimensional input layer to LSTMLayer, it will break with an uninterpretable error message:

>>> lasagne.layers.LSTMLayer((10, 20), 30)
[...]
TypeError: 'numpy.float64' object cannot be interpreted as an index

The reason is that np.prod(()) returns 1.0 as a numpy.float64 instance when computing num_units: https://github.com/Lasagne/Lasagne/blob/master/lasagne/layers/recurrent.py#L863

We should check the input dimensionality and bail out earlier (both in LSTMLayer and GRULayer, maybe in others as well -- would be good to grep for np.prod and see if there are other instances that can fail in a similar fashion). Fixing this entails raising a ValueError for too small dimensionalities, and adding a test that checks whether the exception is raised correctly.

@f0k I am working on this. We need to raise ValueError when the input dimension is less than 3 right?