我很好奇有没有人有什么见解。即使你不能弄清楚这个问题,我怎么开始调试它呢?我必须说,我在西亚诺并不强大。
输入数据是形状(10,15,10)的数值张量
这就是了。当我将输入连接到密集层时,它就会运行。
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.发布于 2015-09-04 23:26:39
ResultsBatch是否可能包含1到10之间的数字?
如果是这样的话,您可以尝试使用
train_fn(TextBatch,ResultsBatch - 1)将目标转换为0,1,2,..,9。
发布于 2016-03-19 08:00:31
这里面有几个错误:
您的输入是一个向量。您的输出批中的每个条目都有10个单位:
target_var = T.ivector('targets')
l_out = lasagne.layers.DenseLayer(l_shp, num_units=10)您的输出形状是(150,10),您希望将其与标签输入(10,)进行比较:
l_shp =lasagne.layers.ReshapeLayer(l_lstm, (10*15, 10))
print 'l_shp shape:', l_shp.output_shape
l_out = lasagne.layers.DenseLayer(l_shp, num_units=10)您可能希望对标签使用(10,10)矩阵。这样,对于批处理大小为10的类,您将使用10个类
target_var = T.matrix('targets')您还需要更改您的网络,使其输出(10,10)形状的结果。您可以通过直接重塑为(10,某物)来以不同的方式重塑您的l_shp来做到这一点。还有很多其他的选择。
顺便说一句,你可以用它们的'output_shape‘属性来查看图层形状。
https://stackoverflow.com/questions/32283364
复制相似问题