Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with running tutorial #20

Open
sdwfrost opened this issue Feb 2, 2016 · 2 comments
Open

Issue with running tutorial #20

sdwfrost opened this issue Feb 2, 2016 · 2 comments

Comments

@sdwfrost
Copy link

sdwfrost commented Feb 2, 2016

Everything goes fine until the very end

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/usr/local/lib/python3.4/dist-packages/theano/compile/function_module.py in __call__(self, *args, **kwargs)
    858         try:
--> 859             outputs = self.fn()
    860         except Exception:

ValueError: softmaxes.shape[0] (100) != y_lengths.shape[0] (0)

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-13-8890488df5a1> in <module>()
      1 # train:
      2 for i in range(10000):
----> 3     error = model.update_fun(numerical_lines, numerical_lengths)
      4     if i % 100 == 0:
      5         print("epoch %(epoch)d, error=%(error).2f" % ({"epoch": i, "error": error}))

/usr/local/lib/python3.4/dist-packages/theano/compile/function_module.py in __call__(self, *args, **kwargs)
    869                     node=self.fn.nodes[self.fn.position_of_error],
    870                     thunk=thunk,
--> 871                     storage_map=getattr(self.fn, 'storage_map', None))
    872             else:
    873                 # old-style linkers raise their own exceptions

/usr/local/lib/python3.4/dist-packages/theano/gof/link.py in raise_with_op(node, thunk, exc_info, storage_map)
    312         # extra long error message in that case.
    313         pass
--> 314     reraise(exc_type, exc_value, exc_trace)
    315 
    316 

/usr/local/lib/python3.4/dist-packages/six.py in reraise(tp, value, tb)
    683             value = tp()
    684         if value.__traceback__ is not tb:
--> 685             raise value.with_traceback(tb)
    686         raise value
    687 

/usr/local/lib/python3.4/dist-packages/theano/compile/function_module.py in __call__(self, *args, **kwargs)
    857         t0_fn = time.time()
    858         try:
--> 859             outputs = self.fn()
    860         except Exception:
    861             if hasattr(self.fn, 'position_of_error'):

ValueError: softmaxes.shape[0] (100) != y_lengths.shape[0] (0)
Apply node that caused the error: <theano_lstm.masked_loss.MaskedLoss object at 0x7f374891eb70>(InplaceDimShuffle{2,0,1}.0, Subtensor{::, int64::}.0, Elemwise{add,no_inplace}.0, Alloc.0)
Toposort index: 145
Inputs types: [TensorType(float64, 3D), TensorType(int32, matrix), TensorType(int32, vector), TensorType(int32, vector)]
Inputs shapes: [(100, 55, 51), (100, 55), (0,), (0,)]
Inputs strides: [(8, 40800, 800), (224, 4), (4,), (4,)]
Inputs values: ['not shown', 'not shown', array([], dtype=int32), array([], dtype=int32)]
Outputs clients: [[Sum{acc_dtype=float64}(<theano_lstm.masked_loss.MaskedLoss object at 0x7f374891eb70>.0), Shape_i{0}(<theano_lstm.masked_loss.MaskedLoss object at 0x7f374891eb70>.0)]]

Backtrace when the node is created:
  File "/home/simon/Programs/theano_lstm/theano_lstm/masked_loss.py", line 327, in make_node
    T.Tensor(dtype=softmaxes.dtype, broadcastable=[False])()])

HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.

Versions of software below

numpy==1.10.4
scipy==0.17.0
Theano==0.7.0
theano-lstm==0.0.14
@MLRules
Copy link

MLRules commented Sep 1, 2016

Same Error here.

numpy==1.11.1
scipy==0.18.0
Theano==0.9.0.dev2

Traceback (most recent call last):
File "\Anaconda3\envs\p34\lib\site-packages\theano-0.9.0.dev2-py3.4.egg\theano\compile\function_module.py", line 866, in call
self.fn() if output_subset is None else
ValueError: softmaxes.shape0 != y_lengths.shape0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/TheanoLSTM.py", line 248, in
error = model.update_fun(numerical_lines, numerical_lengths)
File "\Anaconda3\envs\p34\lib\site-packages\theano-0.9.0.dev2-py3.4.egg\theano\compile\function_module.py", line 879, in call
storage_map=getattr(self.fn, 'storage_map', None))
File "\Anaconda3\envs\p34\lib\site-packages\theano-0.9.0.dev2-py3.4.egg\theano\gof\link.py", line 325, in raise_with_op
reraise(exc_type, exc_value, exc_trace)
File "\Anaconda3\envs\p34\lib\site-packages\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "\Anaconda3\envs\p34\lib\site-packages\theano-0.9.0.dev2-py3.4.egg\theano\compile\function_module.py", line 866, in call
self.fn() if output_subset is None else
ValueError: softmaxes.shape0 != y_lengths.shape0
Apply node that caused the error: <theano_lstm.masked_loss.MaskedLoss object at 0x0000000006029B38>(InplaceDimShuffle{2,0,1}.0, Subtensor{::, int64::}.0, Elemwise{add,no_inplace}.0, Alloc.0)
Toposort index: 149
Inputs types: [TensorType(float64, 3D), TensorType(int32, matrix), TensorType(int32, vector), TensorType(int32, vector)]
Inputs shapes: [(100, 37, 57), (100, 37), (0,), (0,)]
Inputs strides: [(8, 45600, 800), (152, 4), (4,), (4,)]
Inputs values: ['not shown', 'not shown', array([], dtype=int32), array([], dtype=int32)]
Outputs clients: [[Sum{acc_dtype=float64}(<theano_lstm.masked_loss.MaskedLoss object at 0x0000000006029B38>.0), Shape_i{0}(<theano_lstm.masked_loss.MaskedLoss object at 0x0000000006029B38>.0)]]

Backtrace when the node is created(use Theano flag traceback.limit=N to make it longer):
File "/TheanoLSTM.py", line 242, in
celltype=RNN # use RNN or LSTM
File "/TheanoLSTM.py", line 73, in init
self.create_cost_fun()
File "/TheanoLSTM.py", line 145, in create_cost_fun
starting_when).sum()
File "\Anaconda3\envs\p34\lib\site-packages\theano-0.9.0.dev2-py3.4.egg\theano\gof\op.py", line 602, in call
node = self.make_node(_inputs, *_kwargs)
File "D:\Dev\Machine Learning\Theano\TheanoLSTM\theano_lstm\masked_loss.py", line 327, in make_node
T.Tensor(dtype=softmaxes.dtype, broadcastable=[False])()])

HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.

Process finished with exit code 1

@gkennos
Copy link

gkennos commented Aug 22, 2019

I had that error and fixed it by changing the function pad_into_matrix as follows (notice moving the list(lengths) earlier because the call to max consumes the iterator object so list(lengths) returns [] if applied after max()):

def pad_into_matrix(rows, padding = 0):
    if len(rows) == 0:
        return np.array([0, 0], dtype=np.int32)
    lengths = list(map(len, rows))
    width = max(lengths)
    height = len(rows)
    mat = np.empty([height, width], dtype=rows[0].dtype)
    mat.fill(padding)
    for i, row in enumerate(rows):
        mat[i, 0:len(row)] = row
    return mat, lengths

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants