我很好奇是否有人有任何见解。即使您无法弄清楚问题,我该如何开始调试它。我必须说,我在theano方面并不强。
输入数据是形状为 (10,15,10) 的 numpy 张量
这里是。它在我刚刚将输入连接到密集层时运行。
def MakeSentimentLSTM(input_var):
l_in = lasagne.layers.InputLayer(shape=(10,15,10),
input_var=input_var)
l_lstm = lasagne.layers.LSTMLayer(l_in, num_units=10,peepholes=False)
l_shp =lasagne.layers.ReshapeLayer(l_lstm, (10*15, 10))
l_out = lasagne.layers.DenseLayer(l_shp, num_units=10)
return l_out
# Prepare Theano variables for inputs and targets
input_var = T.tensor3('inputs')
target_var = T.ivector('targets')
# Create neural network model
network = MakeSentimentLSTM(input_var)
#The Network output or prediction
prediction = lasagne.layers.get_output(network)
# Set the Error Function
loss = lasagne.objectives.categorical_crossentropy(prediction, target_var)
loss = loss.mean()
#pool the numpy shared variables
params = lasagne.layers.get_all_params(network, trainable=True)
#using adagrad to train the weights
updates = lasagne.updates.adagrad(
loss, params)
#Initiate training.
#Just doing a single pass and not worring about epochs and mini batches now
train_fn = theano.function([input_var, target_var], loss, updates=updates)
train_fn(TextBatch,ResultsBatch)
这是错误。这有点笨拙。
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-73-49980235fbb7> in <module>()
----> 1 train_fn(TextBatch,ResultsBatch)
C:\Users\ellmi_000\Anaconda\lib\site-packages\theano\compile\function_module.pyc in __call__(self, *args, **kwargs)
616 self.fn.nodes[self.fn.position_of_error],
617 self.fn.thunks[self.fn.position_of_error],
--> 618 storage_map=self.fn.storage_map)
619 else:
620 # For the c linker We don't have access from
C:\Users\ellmi_000\Anaconda\lib\site-packages\theano\gof\link.pyc in raise_with_op(node, thunk, exc_info, storage_map)
295 exc_value = exc_type(str(exc_value) + detailed_err_msg +
296 '\n' + '\n'.join(hints))
--> 297 reraise(exc_type, exc_value, exc_trace)
298
299
C:\Users\ellmi_000\Anaconda\lib\site-packages\theano\compile\function_module.pyc in __call__(self, *args, **kwargs)
605 t0_fn = time.time()
606 try:
--> 607 outputs = self.fn()
608 except Exception:
609 if hasattr(self.fn, 'position_of_error'):
C:\Users\ellmi_000\Anaconda\lib\site-packages\theano\gof\op.pyc in rval(p, i, o, n)
759 # default arguments are stored in the closure of `rval`
760 def rval(p=p, i=node_input_storage, o=node_output_storage, n=node):
--> 761 r = p(n, [x[0] for x in i], o)
762 for o in node.outputs:
763 compute_map[o][0] = True
C:\Users\ellmi_000\Anaconda\lib\site-packages\theano\tensor\nnet\nnet.pyc in perform(self, node, inp, out)
1306 y = numpy.zeros_like(coding[:, 0])
1307 for i in xrange(len(y)):
-> 1308 y[i] = -numpy.log(coding[i, one_of_n[i]])
1309 y_out[0] = y
1310
IndexError: index 10 is out of bounds for axis 0 with size 10
Apply node that caused the error: CrossentropyCategorical1Hot(Elemwise{Composite{(i0 * (Abs(i1) + i2 + i3))}}[(0, 2)].0, targets)
Toposort index: 206
Inputs types: [TensorType(float64, matrix), TensorType(int32, vector)]
Inputs shapes: [(150L, 10L), (10L,)]
Inputs strides: [(80L, 8L), (4L,)]
Inputs values: ['not shown', 'not shown']
Outputs clients: [[Sum{acc_dtype=float64}(CrossentropyCategorical1Hot.0), Shape_i{0}(CrossentropyCategorical1Hot.0)]]
Backtrace when the node is created:
File "C:\Users\ellmi_000\Anaconda\lib\site-packages\lasagne\objectives.py", line 129, in categorical_crossentropy
return theano.tensor.nnet.categorical_crossentropy(predictions, targets)
HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.