seq2seq icon indicating copy to clipboard operation
seq2seq copied to clipboard

Tests fail with TypeError on updated keras / theano

Open ohadle opened this issue 9 years ago • 1 comments

Seq2seq installed from github: pip install --upgrade --no-deps git+https://github.com/farizrahman4u/seq2seq.git Keras 1.2.0, Theano 0.8.2.

SimpleSeq2Seq test fails, full traceback below (excuse my copy-pasting tests.py)`. Perhaps related to https://github.com/farizrahman4u/seq2seq/issues/151, just a different backend?

➜  ~ ipython
Python 2.7.13 |Anaconda custom (x86_64)| (default, Dec 20 2016, 23:05:08)
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: %paste
from seq2seq import SimpleSeq2Seq, Seq2Seq, AttentionSeq2Seq
import numpy as np
from keras.utils.test_utils import keras_test


input_length = 10
input_dim = 2

output_length = 8
output_dim = 3

samples = 100

@keras_test
def test_SimpleSeq2Seq():
        x = np.random.random((samples, input_length, input_dim))
        y = np.random.random((samples, output_length, output_dim))

        models = []
        models += [SimpleSeq2Seq(output_dim=output_dim, output_length=output_length, input_shape=(input_length, input_dim))]
        models += [SimpleSeq2Seq(output_dim=output_dim, output_length=output_length, input_shape=(input_length, input_dim), depth=2)]

        for model in models:
                model.compile(loss='mse', optimizer='sgd')
                model.fit(x, y, nb_epoch=1)

@keras_test
def test_Seq2Seq():
        x = np.random.random((samples, input_length, input_dim))
        y = np.random.random((samples, output_length, output_dim))

        models = []
        models += [Seq2Seq(output_dim=output_dim, output_length=output_length, input_shape=(input_length, input_dim))]
        models += [Seq2Seq(output_dim=output_dim, output_length=output_length, input_shape=(input_length, input_dim), peek=True)]
        models += [Seq2Seq(output_dim=output_dim, output_length=output_length, input_shape=(input_length, input_dim), depth=2)]
        models += [Seq2Seq(output_dim=output_dim, output_length=output_length, input_shape=(input_length, input_dim), peek=True, depth=2)]

        for model in models:
                model.compile(loss='mse', optimizer='sgd')
                model.fit(x, y, nb_epoch=1)

        model = Seq2Seq(output_dim=output_dim, output_length=output_length, input_shape=(input_length, input_dim), peek=True, depth=2, teacher_force=True)
        model.compile(loss='mse', optimizer='sgd')
        model.fit([x, y], y, nb_epoch=1)


@keras_test
def test_AttentionSeq2Seq():
        x = np.random.random((samples, input_length, input_dim))
        y = np.random.random((samples, output_length, output_dim))

        models = []
        models += [AttentionSeq2Seq(output_dim=output_dim, output_length=output_length, input_shape=(input_length, input_dim))]
        models += [AttentionSeq2Seq(output_dim=output_dim, output_length=output_length, input_shape=(input_length, input_dim), depth=2)]
        models += [AttentionSeq2Seq(output_dim=output_dim, output_length=output_length, input_shape=(input_length, input_dim), depth=3)]

        for model in models:
                model.compile(loss='mse', optimizer='sgd')
                model.fit(x, y, nb_epoch=1)

## -- End pasted text --
Using Theano backend.
Using gpu device 0: GeForce GT 750M (CNMeM is disabled, cuDNN 5105)
/Users/olevinkr/anaconda/lib/python2.7/site-packages/theano/sandbox/cuda/__init__.py:600: UserWarning: Your cuDNN version is more recent than the one Theano officially supports. If you see any problems, try updating Theano or downgrading cuDNN to version 5.
  warnings.warn(warn)

In [2]: test_SimpleSeq2Seq()
/Users/olevinkr/anaconda/lib/python2.7/site-packages/keras/engine/topology.py:376: UserWarning: The `regularizers` property of layers/models is deprecated. Regularization losses are now managed via the `losses` layer/model property.
  warnings.warn('The `regularizers` property of layers/models '
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-876b58b53df4> in <module>()
----> 1 test_SimpleSeq2Seq()

/Users/olevinkr/anaconda/lib/python2.7/site-packages/keras/utils/test_utils.pyc in wrapper(*args, **kwargs)
    126     @six.wraps(func)
    127     def wrapper(*args, **kwargs):
--> 128         output = func(*args, **kwargs)
    129         if K._BACKEND == 'tensorflow':
    130             K.clear_session()

<ipython-input-1-983cd492c8bd> in test_SimpleSeq2Seq()
     23         for model in models:
     24                 model.compile(loss='mse', optimizer='sgd')
---> 25                 model.fit(x, y, nb_epoch=1)
     26
     27 @keras_test

/Users/olevinkr/anaconda/lib/python2.7/site-packages/keras/models.pyc in fit(self, x, y, batch_size, nb_epoch, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, **kwargs)
    662                               shuffle=shuffle,
    663                               class_weight=class_weight,
--> 664                               sample_weight=sample_weight)
    665
    666     def evaluate(self, x, y, batch_size=32, verbose=1,

/Users/olevinkr/anaconda/lib/python2.7/site-packages/keras/engine/training.pyc in fit(self, x, y, batch_size, nb_epoch, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch)
   1113         else:
   1114             ins = x + y + sample_weights
-> 1115         self._make_train_function()
   1116         f = self.train_function
   1117

/Users/olevinkr/anaconda/lib/python2.7/site-packages/keras/engine/training.pyc in _make_train_function(self)
    718                                              [self.total_loss] + self.metrics_tensors,
    719                                              updates=updates,
--> 720                                              **self._function_kwargs)
    721
    722     def _make_test_function(self):

/Users/olevinkr/anaconda/lib/python2.7/site-packages/keras/backend/theano_backend.pyc in function(inputs, outputs, updates, **kwargs)
    927                 msg = 'Invalid argument "%s" passed to K.function' % key
    928                 raise ValueError(msg)
--> 929     return Function(inputs, outputs, updates=updates, **kwargs)
    930
    931

/Users/olevinkr/anaconda/lib/python2.7/site-packages/keras/backend/theano_backend.pyc in __init__(self, inputs, outputs, updates, **kwargs)
    906     def __init__(self, inputs, outputs, updates=[], **kwargs):
    907         unique_variables_to_update = {}
--> 908         for v, nv in updates:
    909             if v not in unique_variables_to_update:
    910                 unique_variables_to_update[v] = nv

/Users/olevinkr/anaconda/lib/python2.7/site-packages/theano/tensor/var.pyc in __iter__(self)
    551         except TypeError:
    552             # This prevents accidental iteration via builtin.sum(self)
--> 553             raise TypeError(('TensorType does not support iteration. '
    554                              'Maybe you are using builtin.sum instead of '
    555                              'theano.tensor.sum? (Maybe .max?)'))

TypeError: TensorType does not support iteration. Maybe you are using builtin.sum instead of theano.tensor.sum? (Maybe .max?)

ohadle avatar Jan 12 '17 13:01 ohadle

I meet the same error , did u fix up it ?

leecodedog avatar Feb 06 '17 06:02 leecodedog